think@ut-emx.UUCP (s j moon) (11/04/89)
Here is another small perl program. It is useful if you access info-mac macintosh archieve. This can display the title/content of abstract file. ex: 00da-abstracts.abs Sometimes the absract file is too long so I coded this program. It displays title of each .hqx file or its content from abstract. 1: #### BINHEX abc-calculator.hqx ************ 2: #### BINHEX about-finder.hqx ************** 3: #### BINHEX aclock2.hqx ******************* 4: #### BINHEX amortization.hqx ************** You can select any title by number and display its content. type 'h' for help q Quit. c N Change default no. of lines(20) m Change mode titles/contents(toggle) <cr> List 20 lines from current pointer. N change title pointer to title line N. s j moon <think@emx.utexas.edu> ---------- cut here -------------- #!/usr/uns/perl # It is not in /bin of my emx computer # # Name: rdabst.pl # by Sungjin Moon think@emx.utexas.edu # format: perl rdabst file # or rdabst file if edbh is executable # description: read info-mac abstract $abstfile = shift; die "Usage: rd file" unless $abstfile; open(abstfile, "$abstfile") || die "Can't open $abstfile"; $mode = 1; # title mode $cp = 1; # current pointer to content buffer $tcp = 1; # current pointer to title buffer $len = 20; # default length of display lines $first = 1; # pointer to first text $last = 0; # pointer to last text $tlast= 0; # pointer to last title # read in the file while (<abstfile>) { if(($buf[++$last] = $_) =~ /^\#\#\#\#/) { $tbuf[++$tlast]=$buf[$last]; # header $nbuf[$tlast]=$last; # line number of the header } } close abstfile; print "$last Lines Read In.\n"; print "Type h for help.\n"; do ED(); # # sub ED { for (;;) { print " rd -- "; $cmd = <stdin>; if ($cmd =~ /^q$/) { exit 0; } if ($cmd =~ /^h$/) { print " q Quit. c N Change default no. of lines(20) m Change mode titles/contents(toggle) <cr> List 20 lines from current pointer. N change title pointer to title line N. "; next; } if ($cmd =~ /^c (.*)/) { $len = $1; next; } if ($cmd =~ /^([0-9]+)$/) { $tcp = $1; $cp = $nbuf[$tcp]; $mode = 1; next; } if ($cmd =~ /^m/) { $mode = ! $mode; next; } if ($cmd =~ /^$/) { if($mode) { # diplay title $k = ($tlast-$tcp)<$len ? ($tlast-$tcp) : $len; for($i=$tcp;$i < $tcp+$k;$i++) { print "$i:\t", $tbuf[$i]; } $tcp += $k - 1; $cp = $nbuf[$tcp]; } else { # display content $k = ($last-$cp)<$len ? ($last-$tcp) : $len; for($i=$cp;$i < $cp+$k;$i++) { print " ", $buf[$i]; if($buf[$i] =~ /^\#\#\#\#/) { $tmp = $i; } } # change current title pointer for($i=1;$i < $tlast;$i++) { if($nbuf[$i] == $tmp) { $tcp = $i; } } $cp += $k - 1; } next; } print "Syntax error: type h for help.\n"; } # end of for } # end of sub ED