[Discuss] need a data-base organizer program (like the old DBase III &c.)

Cy Schubert Cy.Schubert at komquats.com
Tue Jun 10 00:34:58 PDT 2014


In message <53967CEA.5090009 at shaw.ca>, Gordon Craig writes:
> Hi guys:
> I'm looking for a data-base organizer to set up a simple address file 
> for Linux (specifically LM 17. (I've lost the one in Thunderbird too 
> often to count!) You old timers will recall the DBase series in Windows 
> long, long ago. Easy to set up, easy to modify, and especially, easy to 
> save and to move when/if I change OS.
> Anybody with ideas?

This isn't a database application but it does maintain an address list. 
It's old-school. I've been using this for over 20 years. To use it set the 
environment variable UINFOPATH to point to the filename containing your 
address list.

The address list file has the format:

\
:last=Person
:first=Some
:telephone=403-497-5110
:street=10020 - 100 St.
:city=Edmonton
:province=AB
:organization=AGT, aka Tellus Corp.
\

The script was originally developed at UBC to keep track of their UNIX user 
community in the '80s and '90s. You can modify it to include company name 
or other information you'd like -- I've made few mods myself for my own 
needs. As far as Perl programs go it's poorly written but very easy to 
understand.

The output:

slippy$ uinfo AGT

Organization: AGT, aka Tellus Corp.
Name: Person, Some 
Tel: 403-497-5110
Address: 10020 - 100 St., Edmonton
______________________
slippy$ 



-------------- next part --------------
#!/usr/local/bin/perl

use v5.6;

# require "getopts.pl" ;
use Getopt::Std;
getopts('cD:df:g:n:prs:u:') ;
if ("$opt_c" ne "") {
   $check = 1;
}
if ("$opt_D" ne "") {
   $domain = $opt_D;
}
if ("$opt_d" ne "") {
   $debug = 1;
}
if ("$opt_f" ne "") {
   $path = $opt_f ;
} 
if ("$opt_g" ne "") {
   $gid = $opt_g ;
} 
if ("$opt_n" ne "") {
   $gcos = $opt_n ;
} 
if ("$opt_p" ne "") {
   $pw = 1;
}
if ("$opt_r" ne "") {
   $raw = 1;
}
if ("$opt_s" ne "") {
   $server = $opt_s;
}
if ("$opt_u" ne "") {
   $uid = $opt_u ;
} 
$pattern = $ARGV[0] ;

if ("$pw") {
  if (!("$uid" && "$gid" && "$server")) {
     print "usage: -p option requires -g, -s and -u\n" ; exit ;
  }
  $pattern = ":login="
}
$recsep = "\\\\" ;

# chop($pattern) ; # nuke trailing space introduced during construction of pattern
$pattern = "\'" . $pattern . "\'" ;
print "## DEBUG --\n debug = $debug\n raw= $raw\n pattern= $pattern\n" if $debug ;

$infofiles="" ;

# parse info file search path

if ("$path") {    # search path passed on command line
   foreach $item (split(/:/,$path)) {
     $infofiles = "$infofiles $item" ;
   }
} else {          # parse environment variable
   foreach $item (split(/:/, $ENV{UINFOPATH})) {
     $infofiles = "$infofiles $item" ;
   }
}

sub usage { die "usage: [cD [-d | -k] [pattern]\n"; }

# define record separator character
$/ = "\\";  

# RNM CHANGE
#foreach $file ( $infofiles ) {
#   print "$file\n" ;
#   open(F, "cat $file | egrep  '^$' | ") || die "failed open: $file\n" ;
#   @defines = <F> ;
#   print @defines ;

#   foreach $rec (@defines) {
#      print $rec ; eval "$rec" ;
#   }
#}
#   exit ;
#   open(F, "cat $file | agrep -i -d '$recsep' $pattern | ") || die "failed open: $file\n" ;

# RNM END CHANGE

# grep for matching records
open(F, "cat $infofiles | agrep -i -d '$recsep' $pattern | ") || die "bye-bye\n" ;

# Lines beginning with '#' are comments
# XXX $* = 1;

#result is an array of matching records
@result = sort <F> ;
close(F) ;

print "## DEBUG -- Matching records:\n @result \n" if $debug ;
if ($raw) {
   # nuke trailing "empty" record
   pop(@result) ;
   print @result ;
   exit 0 ;
}

if ($pw) {
   open(PASSWD, ">./uinfo.passwd") || die "open failed: uinfo.passwd\n" ;
   open(AUTOHOME, ">./uinfo.auto_home") || die "open failed: uinfo.auto_home\n" ;
   open(CRED, ">./uinfo.cred") || die "open failed: uinfo.cred\n" ;
   open(SCRIPT, ">./uinfo.script") || die "open failed: uinfo.script\n" ;

   print SCRIPT "#!/bin/sh\n" ;
   print SCRIPT "for i in " ;
   pop(@result) ;
   foreach $rec (@result) {
      undef $e;
     $z = "=" . $rec; # add separator to start pairing with correct parity
# split record into associative array: :keyword=value
     %e = split(/=|^:/m, $z);
     $t=$e{'first'} ; $name = $t ; chop($name) ;
     $t = $e{'last'} ; $name = $name . " " . $t ; chop($name) ;
     $login = $e{'login'} ; chop($login) ;
     if (length($login)) {
        $login=substr($login,0,8) ;
     }
     $server = $e{'server'} ; chop($server) ;
     print PASSWD "$login::$uid:$gid:$name, $gcos:/home/$login:/bin/bash\n" ; $uid++ ;
     print AUTOHOME "$login  $server:/$login\n" ;
     print CRED "nisaddcred -p $uid -P $login.$domain. local\n" ;
     print CRED "nisaddcred -p unix.$uid@$domain -P $login.$domain. DES $domain\n" ;
     print SCRIPT "$login \\\n " ;
   }
   print SCRIPT "\ndo\n" ;
   print SCRIPT "(mkdir ./\$i ; cp  /usr/common/template/README ./\$i ; cp /usr/common/template/generic/.??* ./\$i ; chown -R \$i ./\$i ; chgrp -R $gid ./\$i)\n" ;
   print SCRIPT "done\n" ;
   print SCRIPT "exit\n" ;
   close(P) ; close(H) ;
   exit ;
} 

# nuke leading "empty" record
#shift(@result) ;
# nuke trailing "empty" record
pop(@result) ;

foreach $rec (@result) {
   undef $e;
   #chop($rec);  # nuke trailing \n
   $z = "=" . $rec; # add separator to start pairing with correct parity
print "## DEBUG -- Record: $z\n" if $debug ;
# split record into associative array: :keyword=value
   %e = split(/=|^:/m, $z);
   if (($t = $e{'organization'}) ne "") {
     chop($t) ; print "\nOrganization: $t" ;
   }
   if (($t = $e{'product'}) ne "") {
     chop($t) ; print "   Product: $t" ;
   }
   if (($t = $e{'version'}) ne "") {
     chop($t) ; print "   Version: $t" ;
   }
   if (($t = $e{'department'}) ne "") {
      chop($t) ; print "\nDepartment: $t" ;
   }
   $name = $e{'last'} . $e{'first'};
   if ($name ne "") {
       print "\nName: " ;
       if (($t = $e{'last'}) ne "") {
          chop($t) ; print "$t, " ;
       }
       if (($t = $e{'first'}) ne "") {
          chop($t) ; print "$t" ;
       }
   }
   if (($t = $e{'login'}) ne "") {
      chop($t) ; print "    Login: $t" ;
   }
   if (($t = $e{'host'}) ne "") {
      chop($t) ; print "    Host: $t" ;
   }
   if (($t = $e{'position'}) ne "") {
      chop($t) ; print "    Position: $t" ;
   }
#   print "\n";
   $phone = $e{'office'} . $e{'work'} . $e{'local'} . $e{'home'};
   if ($phone ne "") {
      print "\n" ;
      if (($t = $e{'office'}) ne "") {
        chop($t) ; print "Office: $t    " ;
      }
      if (($t = $e{'work'}) ne "") {
         chop($t) ; print "Work: $t    "  ;
      }
      if (($t = $e{'local'}) ne "") {
        chop($t) ; print "Local: $t    " ;
      }
      if (($t = $e{'home'}) ne "") {
        chop($t) ;print "Home: $t" ;
      }
   }
   if (($t = $e{'telephone'}) ne "") {
      chop($t) ; print "\nTel: $t" ;
   }
   if (($t = $e{'cell'}) ne "") {
      chop($t) ; print "\nCell: $t" ;
   }
   if (($t = $e{'fax'}) ne "") {
      chop($t) ; print "    Fax: $t" ;
   }
   if (($t = $e{'email'}) ne "") {
       chop($t) ;   print "\nEmail: $t" ;
   }
   if (($t = $e{'email-work'}) ne "") {
       chop($t) ;   print "\nEmail (work): $t" ;
   }
   if (($t = $e{'email-home'}) ne "") {
       chop($t) ;   print "\nEmail (home): $t" ;
   }
   if (($t = $e{'city'}) ne "") {
        chop($t) ; $city = $t;
   } else {
       $city = "Vancouver" ;
   }
   $provstate = $e{'province'}.$e{'state'} ;
   if (($t = $provstate) ne "") {
     chop($t) ;
     if (${t} ne "n/a") {
       $provstate = ", $t" ;
     } else {
       $provstate = "" ;
     }
   } else {
       $provstate = ", B.C." ;
   }
   $country = $e{'country'} ;
   if (($t = $country) ne "") {
       chop($t) ; $country = ", $t" ;
   } else {
       $country = "" ;
   }
   $address = $e{'street'} . $e{'city'} . $e{'provstate'} . $e{'country'} .
    $e{'postalcode'} . $e{'attention'};
   if (($t = $address) ne "") {
   	print "\nAddress: " ;
   }
   if (($t = $e{'street'}) ne "") {
       chop($t) ; print "$t, " ;
   }
   if (($t = $e{'city'}) ne "") {
   	print $city ;
   }
   if (($t = $e{'provstate'}) ne "") {
   	print $provstate ;
   }
   if (($t = $e{'country'}) ne "") {
   	print $country ;
   }
   if (($t = $e{'postalcode'}) ne "") {
       chop($t) ; print ", $t" ;
   }
   if (($t = $e{'attention'}) ne "") {
       chop($t) ; print "\nAttention: $t" ;
   }
   if (($t = $e{'comment'}) ne "") {
       chop($t) ; print "\nComment: $t" ;
   }
   print "\n______________________\n";
}
-------------- next part --------------
Cheers,
Cy Schubert <Cy.Schubert at komquats.com>
FreeBSD UNIX:  <cy at FreeBSD.org>   Web:  http://www.FreeBSD.org


More information about the Discuss mailing list