home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume10 / cbar / cbar.c next >
Encoding:
C/C++ Source or Header  |  1987-07-29  |  2.0 KB  |  94 lines

  1. static char *RCSid = "$Header: cbar.c,v 1.1 87/04/22 10:31:51 alan Exp $";
  2. /* 
  3.  * cbar [bar-on bar-off]
  4.  *
  5.  * Inserts change bar commands around diff -e output.  
  6.  *
  7.  * Alan Crosswell, Columbia University
  8.  *
  9.  * Tacks on a "1,$p" at the end so that you can do something like this:
  10.  *
  11.  *  diff -b -e old.mss updated.mss | cbar | ed - old.mss >updated-bar.mss
  12.  *
  13.  * Input looks like this:
  14.  *------------------------------
  15.  * 746,747d
  16.  * 138a
  17.  * NOTE: Change this for LISTSERV.
  18.  * .
  19.  * 89c
  20.  * followed by a blank or hyphen (e.g. "220 ").
  21.  * .
  22.  *------------------------------
  23.  * Output looks like:
  24.  *------------------------------
  25.  * 746,747d
  26.  * 138,138a
  27.  * @CBON
  28.  * NOTE: Change this for LISTSERV.
  29.  * @CBOFF
  30.  * .
  31.  * 91,91c
  32.  * @CBON
  33.  * followed by a blank or hyphen (e.g. "220 ").
  34.  * @CBOFF
  35.  * .
  36.  * 1,$p
  37.  *------------------------------
  38.  *
  39.  * NOTE:  It is imperitave that the line numbers appear in highest-first
  40.  *  order since extra lines are being added.
  41.  *
  42.  * The default change bar commands are those used by Scribe (@CBON, @CBOFF).
  43.  * You may provide your own (e.g. cbar ".mc |" ".mc" for nroff).
  44.  *
  45.  * $Log:    cbar.c,v $
  46.  * Revision 1.1  87/04/22  10:31:51  alan
  47.  * Initial revision
  48.  * 
  49.  * 
  50.  */
  51. #include <stdio.h>
  52.  
  53. static char *cbon = "@CBON";
  54. static char *cboff = "@CBOFF";
  55.  
  56. main(argc,argv)
  57. int argc;
  58. char **argv;
  59. {
  60.     char buf[1024];
  61.     enum {ed_cmd, in_data} state = ed_cmd;
  62.     
  63.     if (argc == 3) {
  64.     cbon = argv[1];
  65.     cboff = argv[2];
  66.     } else if (argc != 1) {
  67.     fprintf(stderr,"Usage: cbar [bar_on bar_off]\n");
  68.     exit(1);
  69.     }
  70.  
  71.     while(gets(buf) != NULL) {
  72.     switch (state) {
  73.       case ed_cmd:
  74.         if (buf[strlen(buf)-1] == 'd') {
  75.         state = ed_cmd;    /* 'd' has no data */
  76.         puts(buf);
  77.         } else {
  78.         state = in_data; /* 'a' and 'c' do */
  79.         printf("%s\n%s\n", buf, cbon);
  80.         }
  81.         break;
  82.  
  83.       case in_data:
  84.         if (buf[0] == '.' && buf[1] == '\0') { /* end of data */
  85.         state = ed_cmd;
  86.         printf("%s\n.\n", cboff);
  87.         } else
  88.           puts(buf);
  89.         break;
  90.     } /* end switch(state) */
  91.     } /* end while */
  92.     puts("1,$p");
  93. }
  94.