Annotation of loncom/debugging_tools/dump_db.pl, revision 1.2

1.1       matthew     1: #!/usr/bin/perl -w
                      2: #
                      3: # The LearningOnline Network
                      4: #
                      5: # dump_db.pl - dump a GDBM database to standard output, unescaping if asked to.
                      6: #
1.2     ! matthew     7: # $Id: dump_db.pl,v 1.1 2002/08/19 14:37:14 matthew Exp $
1.1       matthew     8: #
                      9: # Copyright Michigan State University Board of Trustees
                     10: #
                     11: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                     12: #
                     13: # LON-CAPA is free software; you can redistribute it and/or modify
                     14: # it under the terms of the GNU General Public License as published by
                     15: # the Free Software Foundation; either version 2 of the License, or
                     16: # (at your option) any later version.
                     17: #
                     18: # LON-CAPA is distributed in the hope that it will be useful,
                     19: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     20: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     21: # GNU General Public License for more details.
                     22: #
                     23: # You should have received a copy of the GNU General Public License
                     24: # along with LON-CAPA; if not, write to the Free Software
                     25: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     26: #
                     27: # /home/httpd/html/adm/gpl.txt
                     28: #
                     29: # http://www.lon-capa.org/
                     30: #
                     31: #################################################
                     32: use strict;
                     33: use Getopt::Long;
                     34: use GDBM_File;
                     35: 
                     36: #
                     37: # Options
                     38: my $unesc = 0;
                     39: my $help = 0;
                     40: GetOptions("unescape" => \$unesc,
1.2     ! matthew    41:            "u"        => \$unesc,
        !            42:            "help"     => \$help);
1.1       matthew    43: 
                     44: #
                     45: # Help them out if they ask for it
                     46: if ($help) {
                     47:     print <<END;
                     48: dump_db.pl - dump GDBM_File databases to stdout.  
                     49: Specify the database filenames on the command line.
                     50: Specify --unescape to have all the keys and values unescaped from every
                     51: database.
                     52: Options:
                     53:    --help     Display this help.
                     54:    --unescape Unescape the keys and values before printing them out.
1.2     ! matthew    55:    --u        Same as --unescape
1.1       matthew    56: Examples: 
                     57:     dump_db.pl mydata.db
                     58:     dump_db.pl mydata.db yourdata.db ourdata.db theirdata.db
                     59:     dump_db.pl --unescape \*db
                     60: END
                     61:     exit;
                     62: }
                     63: 
                     64: #
                     65: # Loop through ARGV getting files.
                     66: while (my $fname = shift) {
                     67:     my %db;
                     68:     if (! tie(%db,'GDBM_File',$fname,&GDBM_READER,0640)) {
                     69:         warn "Unable to tie to $fname";
                     70:         next;
                     71:     }
                     72:     while (my ($key,$value) = each(%db)) {
                     73:         if ($unesc) {
                     74:             $key = &unescape($key);
                     75:             $value = &unescape($value);
                     76:         }
                     77:         print "$key = $value\n";
                     78:     }
                     79:     untie %db;
                     80: }
                     81: exit;
                     82: 
                     83: ######################################
                     84: sub unescape {
                     85:     my $str=shift;
                     86:     $str =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
                     87:     return $str;
                     88: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>