home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume18 / changebar / chbar.lex < prev    next >
Encoding:
Text File  |  1989-03-12  |  3.5 KB  |  118 lines

  1. /* Compile this program using lex and cc, name the object file 'chbar'
  2.  * and install it somewhere that the system can get to it using the
  3.  * 'changebar' shell script.
  4.  */
  5. %{
  6. int stat=0;
  7. int bangstat=0;
  8. char txtbuf[256]=0;
  9. %}
  10. %%
  11. ^[^-\*\n\!].*$     {
  12.                 /* If already counting lines that have either a '- '
  13.                  * or a '! ' or a '*...' in the first columns, and encounter
  14.                  * a line that does NOT have that, put the closing
  15.                  * ^G.mc at the tail of the previous line and disable
  16.                  * the insertion of the .mc till the first line with
  17.                  * either of the two markers happens again.
  18.                  */
  19.                     if(stat == 1) {
  20.                         printf("%s\007.mc\n",txtbuf);
  21.                         stat = 0;
  22.                     }
  23.                     puts(yytext);
  24.                 }
  25.  
  26. ^---\ .*$       {   puts(yytext);  /* If in a '---' block in a context diff,
  27.                                 * then disable entry of .mc's in text lines.
  28.                                 */
  29.                     bangstat = 0;
  30.                 }
  31.  
  32. ^\*\*\*\ .*$    {   puts(yytext);  /* If in a '***' block in a context diff,
  33.                                 * then enable entry of .mc's in text lines.
  34.                                 */
  35.                     bangstat = 1;
  36.                 }
  37.  
  38. ^\*\*\*.*$    {   puts(yytext);
  39.         }
  40.  
  41. ^\-\ .*$        {
  42.                     /* If find a line that begins "- <anything>", and it
  43.                      * is the first line of its kind, then mark it.
  44.                      */
  45.                 if(stat == 0) {
  46.                     sprintf(txtbuf,"- .mc \\s+2\\(br\\s-2\007%s",&yytext[2]);
  47.                     stat = 1;
  48.                     }
  49.                 else {
  50.                     puts(txtbuf);
  51.                     sprintf(txtbuf,"%s",yytext);
  52.                     }
  53.                 }
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62. ^\!\ .*$        {
  63.                     /* If find a line that begins "! <anything>", and it
  64.                      * is the first line of its kind, then mark it.
  65.                      */
  66.                   if(bangstat==1) 
  67.                   {
  68.                         if(stat == 0) {
  69.                           sprintf(txtbuf,"! .mc \\s+2\\(br\\s-2\007%s",
  70.                                       &yytext[2]);
  71.                           stat = 1;
  72.                         }
  73.                         else {
  74.                           puts(txtbuf);
  75.                           sprintf(txtbuf,"%s",yytext);
  76.                           }
  77.                   }
  78.                   else {
  79.                     puts(yytext);
  80.                   }
  81.                 }
  82. \n          {
  83.                    ;
  84.            /* If there is nothing but a newline, do nothing, because
  85.                     * we are inserting our own newlines as needed.
  86.                     */
  87.         }
  88. %%
  89. yywrap()
  90. {
  91.     if (stat == 1)
  92.         printf("%s\007.mc\n",txtbuf);
  93.  
  94.     return (1);
  95. }
  96. /*
  97.     This LEX file adds change bars to the output of a 'diff -c'
  98.     to indicate to the reader where sections have been added
  99.     (no handling so far for lines that have been deleted).
  100.  
  101.     This allows the user to edit under SCCS to your heart's content,
  102.     then SCCS-extract the old version and the new version...
  103.     then:
  104.  
  105.     a. diff -c oldfile newfile > filediffs
  106.     b. addchgbars < filediffs > filemods
  107.     c. patch < filemods
  108.     
  109.     # oldfile is renamed to oldfile.orig
  110.     # oldfile becomes newfile, but with change bars installed
  111.  
  112.     d. tr '\007' '\012' oldfile > file.to.print
  113.  
  114.     # change bars have ^G installed, has to be changed into a ^J;
  115.     # makes patch program work unmodified.
  116.  
  117. */
  118.