"Fossies" - the Fresh Open Source Software Archive

Member "passwd_exp-1.2.11/mod/_termcap.reader" (21 Nov 2005, 2755 Bytes) of package /linux/privat/old/passwd_exp-1.2.11.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 #! /usr/bin/perl
    2 # PROGRAM   : _termcap.reader (passwd_exp 1.x helper)
    3 # PURPOSE   : termcap style file reader
    4 # AUTHOR    : Samuel Behan <samkob@gmail.com> (c) 2000-2006
    5 # HOMEPAGE  : http://devel.dob.sk/passwd_exp
    6 # LICENSE   : GNU GPL v2, NO WARRANTY VOID (see file LICENSE)
    7 ################################################################################
    8 #requirements
    9 use Text::Tokenizer qw(:all);
   10 #pragmas
   11 #use strict;
   12 use integer;
   13 use vars qw($VERSION $AUTHOR $AUTHOR_EMAIL $SCRIPT);
   14 
   15 #script info
   16 $AUTHOR     = 'Samuel Behan';
   17 $AUTHOR_EMAIL   = 'samkob@gmail.com';
   18 $VERSION    = '0.2.0';
   19 $SCRIPT     = '_termcap.reader';
   20 
   21 #print info
   22 sub cmd_print_info(;$)
   23 {   
   24     print STDERR <<__EOT__
   25 usage: $SCRIPT [command] [options] <filename> <key0> <key1> ... <keyN>
   26       -- $SCRIPT (passwd_exp helper) $VERSION by $AUTHOR
   27 [params]
   28     filename        file to read
   29     key0..keyN      key(s) to return from termcap file
   30 [command]
   31     -info           print module info
   32 [options]
   33     -all            will print all termcap entries
   34 [RESULT FORMAT]
   35   Script prints for every key one line from termcap file, sorted in order
   36 of key params passed to script. If key has not been found, empty line will
   37 be returned.
   38 __EOT__
   39 ;
   40     exit(defined($_[0]));
   41 }
   42 
   43 ################
   44 # MAIN PROGRAM #
   45 ################
   46 my ($file, $show_all, @KEYS, %RESULT, $tok);
   47 
   48 #parse command line
   49 $show_all = 0;
   50 foreach $cmd (@ARGV)
   51 {
   52     cmd_print_info() if($cmd eq '-info' || $cmd eq '--info' || $cmd eq '-h' ||
   53                 $cmd eq '-help' || $cmd eq '--help' || $file ne '');
   54     $show_all = 1, next if($cmd eq '-all' || $cmd eq '--all');
   55     #add search key
   56     push(@KEYS, $cmd);
   57 }
   58 
   59 #first param is filename to be read
   60 $file   = shift(@KEYS);
   61 
   62 #check if file is defined
   63 die("$SCRIPT: missing filename to read, try '-info' param\n")
   64     if(!defined($file) || $file eq '');
   65 
   66 
   67 #open termcap file
   68 warn("$SCRIPT: failed to open file '$file' ($!)\n")
   69     if(!open(TERMFILE, $file));
   70 
   71 #create tokenizer
   72 $tok    = tokenizer_new(TERMFILE);
   73 #tokenizer_options();
   74 
   75 #parse
   76 my ($str, $tok, $lin, $err, $errlin);
   77 my ($record);
   78 
   79 while(1)
   80 {
   81     ($str, $tok, $lin, $err, $errlin)   = tokenizer_scan();
   82 
   83     if($tok == TOK_TEXT || $tok == TOK_BLANK)
   84     {   $record .= $str;        }
   85     elsif($tok == TOK_EOL)
   86     {   #ignore empty lines
   87         next if($record eq '' || $record =~ /^\s+$/o);
   88         #check for escaped line
   89         next if($record =~ /\\$/o);
   90         #make record
   91         $record =~ s/\\\s*//og;
   92         $record =~ s/^(.+?):://o;
   93         #key it
   94         my $key = $1;
   95         while($key ne '' && $key =~ s/(.+?)($|\|)//o)
   96         {   $RESULT{$1} = $record;      }
   97         $record = undef;
   98     }
   99     elsif($tok == TOK_EOF)
  100     {   last;           }
  101 }
  102 
  103 tokenizer_delete($tok);
  104 close(TERMFILE);
  105 
  106 #print keys
  107 @KEYS = keys(%RESULT) if($show_all);
  108 foreach $cmd (@KEYS)
  109 {
  110     print $cmd."::".$RESULT{$cmd}   if(exists($RESULT{$cmd}));
  111     print "\n";
  112 }
  113 
  114 #EOF (c) by UN*X 1970-$EOD (End of Days) [ EOD (c) by God ]