home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / perl / scripts-osu / readabst < prev    next >
Encoding:
Internet Message Format  |  1989-11-01  |  3.5 KB

  1. Path: tut.cis.ohio-state.edu!cs.utexas.edu!milano!lad-shrike!ut-emx!think
  2. From: think@ut-emx.UUCP (s j moon)
  3. Newsgroups: alt.sources
  4. Subject: rdabst.pl -- read info-mac abstract file
  5. Keywords: perl mac info-mac abstract read
  6. Message-ID: <20436@ut-emx.UUCP>
  7. Date: 3 Nov 89 19:39:23 GMT
  8. Organization: The University of Texas at Austin, Austin, Texas
  9. Lines: 130
  10. Posted: Fri Nov  3 13:39:23 1989
  11.  
  12.  
  13.  
  14. Here is another small perl program.
  15. It is useful if you access info-mac macintosh archieve.
  16.  
  17. This can display the title/content of abstract file.
  18.     ex:   00da-abstracts.abs
  19. Sometimes the absract file is too long so I coded this program.
  20. It displays title of each .hqx file or its content from abstract.
  21.  
  22. 1:     #### BINHEX     abc-calculator.hqx   ************
  23. 2:     #### BINHEX     about-finder.hqx   **************
  24. 3:     #### BINHEX     aclock2.hqx   *******************
  25. 4:     #### BINHEX     amortization.hqx   **************
  26.  
  27. You can select any title by number and display its content.
  28.   type 'h' for help
  29.  
  30. q              Quit.
  31. c N            Change default no. of lines(20)
  32. m              Change mode titles/contents(toggle)
  33.  
  34. <cr>           List 20 lines from current pointer.
  35. N              change title pointer to title line N.
  36.  
  37.  
  38.   s j moon      <think@emx.utexas.edu>
  39.  
  40. ---------- cut here  --------------
  41. #!/usr/uns/perl
  42. # It is not in /bin  of my emx computer
  43.  
  44. #
  45. # Name:  rdabst.pl
  46. #        by   Sungjin Moon     think@emx.utexas.edu
  47.  
  48. # format:        perl rdabst file
  49. #           or   rdabst file  if edbh is executable
  50. # description:   read  info-mac abstract
  51.  
  52. $abstfile = shift;
  53. die "Usage: rd file" unless $abstfile;
  54. open(abstfile, "$abstfile") || die "Can't open $abstfile";
  55.  
  56. $mode = 1;  # title mode
  57. $cp = 1;    # current pointer to content buffer
  58. $tcp = 1;    # current pointer to title buffer
  59. $len = 20;  # default length of display lines
  60.  
  61. $first = 1;  # pointer to first text
  62. $last = 0;   # pointer to last text
  63. $tlast= 0;   # pointer to last title
  64.  
  65. # read in the file
  66.  
  67. while (<abstfile>) {
  68.     if(($buf[++$last] = $_) =~ /^\#\#\#\#/) {
  69.        $tbuf[++$tlast]=$buf[$last];      # header
  70.        $nbuf[$tlast]=$last;                 # line number of the header
  71.     }
  72. }
  73.  
  74. close abstfile;
  75. print "$last Lines Read In.\n";
  76. print "Type h for help.\n";
  77. do ED();
  78.  
  79. #
  80. #
  81. sub ED {
  82.     for (;;) {
  83.         print " rd -- ";
  84.         $cmd = <stdin>;
  85.  
  86.         if ($cmd =~ /^q$/) {
  87.         exit 0;
  88.         }
  89.  
  90.         if ($cmd =~ /^h$/) {
  91.         print "
  92. q        Quit.
  93. c N        Change default no. of lines(20)
  94. m        Change mode titles/contents(toggle)
  95.  
  96. <cr>        List 20 lines from current pointer.
  97. N        change title pointer to title line N.
  98.  
  99. ";
  100.         next;
  101.         }
  102.         if ($cmd =~ /^c (.*)/) {
  103.         $len = $1;
  104.         next;
  105.         }
  106.         if ($cmd =~ /^([0-9]+)$/) {
  107.         $tcp = $1;
  108.                 $cp = $nbuf[$tcp];
  109.         $mode = 1;
  110.         next;
  111.         }
  112.         if ($cmd =~ /^m/) {
  113.         $mode = ! $mode;
  114.         next;
  115.         }
  116.         if ($cmd =~ /^$/) {
  117.                 if($mode) {   # diplay title
  118.             $k = ($tlast-$tcp)<$len ? ($tlast-$tcp) : $len;
  119.             for($i=$tcp;$i < $tcp+$k;$i++) {
  120.               print "$i:\t", $tbuf[$i];
  121.             }
  122.             $tcp += $k - 1;
  123.                     $cp = $nbuf[$tcp];
  124.         }
  125.         else {     # display content
  126.             $k = ($last-$cp)<$len ? ($last-$tcp) : $len;
  127.             for($i=$cp;$i < $cp+$k;$i++) {
  128.               print " ", $buf[$i];
  129.                       if($buf[$i] =~ /^\#\#\#\#/) { $tmp = $i; }
  130.             }
  131.             # change current title pointer
  132.             for($i=1;$i < $tlast;$i++) {
  133.                        if($nbuf[$i] == $tmp) { $tcp = $i; }
  134.             }
  135.              $cp += $k - 1;
  136.                 }
  137.         next;
  138.         }
  139.          print "Syntax error: type h for help.\n";
  140.     }  # end of for
  141. }  # end of sub ED
  142.