<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/local/bin/perl
#################################################
# dbfileutil.pl Ver 1.2                         #
# By Po-Han Lin                                 #
# pohanl@yahoo.com                              #
#                                               #
# Export/Import between DB_File and SDBM_File   #
# from Windows and Unix platforms               #
#                                               #
# SDBM_Files can be ftp'ed across Unix/Windows  #
# platforms and work without a hitch. (pag and  #
# dir files).  DB_Files can't be ftp'ed across  #
# platform.  (something to do with edian)       #
# I like to use DB_File instead of SDBM_File    #
# This util will export a DB_File to SDBM_Files #
# for you to ftp.  Then you can import the      #
# files (after ftping) by coverting to DB_File  # 
# at destination workstation using this same    #
# util.  You can also clean up the SDBM_Files   #
# after you are done ftping (source side) and   #
# done importing (destination side)             #
# This same code will work on the unix or win   #
# side.  NOTE: be sure DB_File has less than    #
# 1024 bytes per entry, or it wont fit into a   #
# SDBM_File (unless you recompile the SDBM_File #
# to support bigger buckets.                    #
#                                               #
# By Po-Han Lin                                 #
# pohanl@yahoo.com                              #
# http://www.edepot.com/phl.html                #
# This program is free.  Donations accepted     #
#                                               #
# Send Cashiers Check to...                     #
# P.O. Box 1266                                 #
# Alhambra, CA 91802                            # 
# USA                                           #
#                                               #
# Ver 1.2                                       #
#################################################



# Modify these....
$maindomain = "www.yourhostname.com";
$mainwwwpath="/home/www/wwwdirectory";
$mainwwwurl="http://$maindomain";
$maincgiurl="$mainwwwurl/cgi-bin";

# RENAME THIS SCRIPT TO THE FOLLOWING
$scriptName = "$maincgiurl/dbfileutil.pl";



use DB_File;
use SDBM_File;
use Fcntl;

print "Content-type: text/html\n\n";
  # Get the input
  read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
  # Split the name-value pairs
  @pairs = split(/&amp;/, $buffer);
  foreach my $pairentry (@pairs) {
     my($name, $value) = split(/=/, $pairentry);

     # Un-Webify plus signs and %-encoding
     $value =~ tr/+/ /;
     $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
     $value =~ s/&lt;!--(.|\n)*--&gt;//g;
     if ($name =~ /term/i) {
       $value =~ s/^\s+//;
       $value =~ s/\s+$//;
     }
  $FORM{$name} = $value;
  }



  # Process GET requests
  $param=$FORM{'param'};

  if ($FORM{'action'} eq "Import") {
    print "Imported";
    $eGlossaryPath = "$mainwwwpath/$param";
    tie %oldhash, "SDBM_File", $eGlossaryPath, O_RDWR|O_CREAT, 0644;
    tie %newhash, "DB_File", $eGlossaryPath, O_RDWR|O_CREAT, 0644;
    %newhash = %oldhash;
    
  } elsif ($FORM{'action'} eq "Export") {
    print "Exported";
    $eGlossaryPath = "$mainwwwpath/$param";
    tie %oldhash, "DB_File", $eGlossaryPath, O_RDWR|O_CREAT, 0644;
    tie %newhash, "SDBM_File", $eGlossaryPath, O_RDWR|O_CREAT, 0644;
    %newhash = %oldhash;
  } elsif ($FORM{'action'} eq "CleanWindows") {
   print "Cleaned";
     $pathname = $mainwwwpath . "\\$param.pag";
   system("del \"$pathname\" ") == 0 or die "failed";
     $pathname = $mainwwwpath . "\\$param.dir";
   system("del \"$pathname\" ") == 0 or die "failed"; 
  } elsif ($FORM{'action'} eq "CleanUnix") {
     print "Cleaned";
     $pathname = $mainwwwpath . "/$param.pag";
   system("rm \"$pathname\" ") == 0 or die "failed";
     $pathname = $mainwwwpath . "/$param.dir";
   system("rm \"$pathname\" ") == 0 or die "failed"; 

  } else {
    &amp;printInputForm;
  }



sub printInputForm {

    print "&lt;form method=\"post\" action=\"$scriptName\"&gt;";
    print "&lt;select name=\"action\"&gt;";
    print "&lt;option selected value=\"Export\"&gt;Export";
    print "&lt;option value=\"Import\"&gt;Import";
    print "&lt;option value=\"CleanWindows\"&gt;CleanWindows";
    print "&lt;option value=\"CleanUnix\"&gt;CleanUnix";
    print "&lt;/select&gt;";
    print "&lt;input type=\"text\" name=\"param\" size=\"30\" value=\"FILENAME\"&gt;";
    print "&lt;input type=\"submit\" value=\"Convert\"&gt;";
    print "&lt;/form&gt;";

}

1;


=head1 NAME

dbfileutil.pl - Export/Import between DB_File and SDBM_File

=head1 DESCRIPTION (See README)

=head1 README
Export/Import between DB_File and SDBM_File
from Windows and Unix platforms

SDBM_Files can be ftp'ed across Unix/Windows
platforms and work without a hitch. (pag and
dir files).  DB_Files can't be ftp'ed across
platform.  (something to do with edian)
I like to use DB_File instead of SDBM_File
This util will export a DB_File to SDBM_Files
for you to ftp.  Then you can import the
files (after ftping) by coverting to DB_File
at destination workstation using this same
util.  You can also clean up the SDBM_Files
after you are done ftping (source side) and
done importing (destination side)
This same code will work on the unix or win
side.  NOTE: be sure DB_File has less than
1024 bytes per entry, or it wont fit into a
SDBM_File (unless you recompile the SDBM_File
to support bigger buckets.

=head1 Runs on the following OSs:

Windows and Unix

=head1 Author

Po-Han Lin, pohanl@yahoo.com

=head1 Copyright

This program is free.  Donations accepted

Send Cashiers Check to...
P.O. Box 1266
Alhambra, CA 91802
USA

=cut

=head1 CPAN Scripts Miscellanea:

=head1 SCRIPT CATEGORIES

Win32/Utilities
UNIX/System_administration
Networking

=head1 PREREQUISITES

This script requires the following modules: 

 DB_File

=head1 OSNAMES

C&lt;WinNT&gt;
C&lt;Win95&gt;
C&lt;Solaris&gt;
C&lt;Linux&gt;

=head1 Changes

 01.2 Email changes (POD)
 01.1 Documentation (POD)
 01.0 Initial Release

=cut
__END__


</pre></body></html>