home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / qtawk / toc.exp < prev    next >
Text File  |  1990-04-23  |  1KB  |  42 lines

  1. # QTAwk utility to create line oriented Table-of-Contents
  2. #
  3. BEGIN {
  4.     dots = copies(".",78);
  5.     print "Contents";
  6.     print overlay(overlay(dots,"Para. #/Title",1)," Line",74);
  7.  
  8.     # set regular expression for looking for paragraph numbering
  9.     # un-comment regular expression desired for paragraph numbering utilized
  10.     ldr = "SECTION";
  11. #    para_num = /^([1-9]{_d}?\.)+{_d}{_d}?{_w}{_w}?/;
  12. #    para_num = /^({ldr} [1-9]\.|([1-9]{_d}?\.)+{_d}{_d}?){_w}{_w}/;
  13.     para_num = /^{_w}+([1-9]{_d}?\.)+{_d}{_d}?{_w}{2,3}/;
  14. }
  15.  
  16. # search for start line sline == 0 unless set on command line
  17. FNR < sline { next; }
  18.  
  19. # search for final line tline == 0 unless set on command line
  20. FNR > tline { endfile; }
  21.  
  22. # print input line number to let user know of activity
  23.     {
  24.     fprint("stderr",FNR);
  25. }
  26.  
  27. # find line with numbered paragraph
  28. para_num {
  29.     hdr = $$0;
  30.     jj = gsub(/\./,"",hdr);
  31.     oline = strim($$0) "  ";
  32.     for ( i = 2 ; i <= NF ; i++ ) {
  33.     oline ∩= $i ' ';
  34.     if ( $i ~~ /\.$/ ) break;
  35.     }
  36.     if ( length(oline) > 60 ) oline = substr(oline,1,60);
  37.     if ( jj == 1 ) print "";
  38.       else oline = copies(" ",2*(jj-1)) ∩ oline;
  39.     line = sprintf("%4u",FNR + line_off);
  40.     print overlay(overlay(dots,oline,1),line,75);
  41. }
  42.