home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / vim53os2.zip / vim-5.3 / doc / maketags.awk < prev    next >
Text File  |  1998-08-30  |  2KB  |  74 lines

  1. BEGIN   {
  2.     t=1;
  3.     }
  4.  
  5. NR == 1 { print "<HTML>";
  6.     print "<HEAD>";
  7.     print "<A NAME=\"top\"></A>";
  8.     print "<H1>" FILENAME " - html version </H1>";
  9.     print "<TITLE>" FILENAME " - html version </TITLE>";
  10.     print "</HEAD>";
  11.     print "<BODY>";
  12.     print "<PRE>";
  13.     }
  14.  
  15.     {
  16.     # from htmlchek, metachar.awk, protects special chars.
  17.     gsub(/&/,"\\&");
  18.     gsub(/>/,"\\>");
  19.     gsub(/</,"\\<");
  20.        gsub(/"/,"\\"");
  21.        gsub(/%/,"\\&\#37;");
  22.     nf=split($0,tag,"    ");
  23.     if ( nf >= 2 )
  24.         {
  25.         tagkey[t]=tag[1];tagref[t]=tag[2];tagnum[t]=NR;
  26.         # print t " " tagkey[t] " " tagref[t];
  27.         t++;
  28.         }
  29.     }
  30.     {
  31.     ntags = split($0,e,"    ");
  32.     n2=split(e[2],w,".");
  33.     printf \
  34.  ("<A HREF=\"%s.html\#%s\">\|%s\|</A>    %s\n",w[1],e[1],e[1],e[2]);
  35.     next;
  36.     }
  37.  
  38. END     {
  39.     topback();
  40.     print "</PRE>\n</BODY>\n\n\n</HTML>";
  41.     # tags sorted with a simple but inefficient sorting algorithm
  42.     # Knuth, Sorting and Searching, p. 81 (Straight insertion sort)
  43.     # there are t-1 tags
  44.     # tagkey is the key
  45.     # tagref is the reference
  46.     for ( j=2; j < t; j++ ) {
  47.         i=j-1; k=tagkey[j]; r=tagref[j]; s=tagnum[j];
  48.         while ( i > 0 ) {
  49.         if ( k >= tagkey[i] ) {
  50.             break;
  51.             }
  52.         tagref[i+1]=tagref[i];
  53.         tagkey[i+1]=tagkey[i];
  54.         tagnum[i+1]=tagnum[i];
  55.         i--;
  56.         if ( i == 0 ) { break; }
  57.         }
  58.     tagkey[i+1]=k;
  59.     tagref[i+1]=r;
  60.     tagnum[i+1]=s;
  61.     #loop++;print "loop number: " loop ", i=" i ", j=" j
  62.     }
  63.     for ( j=1; j < t; j++ ) {
  64.     print tagkey[j] "    " tagref[j] "    line " tagnum[j] >"tags.ref"
  65.     }
  66.     }
  67.  
  68. # as main we better keep help.txt
  69. # other candidate, intro.txt
  70. function topback () {
  71.     printf("<A HREF=\"\#top\">top</A> - ");
  72.     printf("<A HREF=\"help.html\">back to help</A>\n");
  73. }
  74.