rs@uunet.UU.NET (Rich Salz) (07/31/87)
Submitted-by: Alan Crosswell <alan@columbia.edu> Posting-number: Volume 10, Issue 74 Archive-name: cbar [ Two similar programs in one day? Consider it a test of software Darwinism. I wrote the Makefile. --r$ ] #! /bin/sh # This is a shell archive, meaning: # 1. Remove everything above the #! /bin/sh line. # 2. Save the resulting text in a file. # 3. Execute the file with /bin/sh (not csh) to create: # Makefile # cbar.l # cbar.c export PATH; PATH=/bin:/usr/bin:$PATH if test -f 'Makefile' then echo shar: "will not over-write existing file 'Makefile'" else cat << \SHAR_EOF > 'Makefile' ## Makefile for cbar all: cbar cbar: cbar.c $(CC) $(CFLAGS) -o cbar cbar.c install: all @echo cp cbar and cbar.l into local directories as appropriate SHAR_EOF fi if test -f 'cbar.l' then echo shar: "will not over-write existing file 'cbar.l'" else cat << \SHAR_EOF > 'cbar.l' .TH CBAR LOCAL .SH NAME cbar \- add change bars to a document .SH SYNOPSIS .B cbar [ .I bar-on bar-off ] .SH DESCRIPTION .B Cbar inserts text-formatter commands into diff -e output to turn on and off change bars. This can then be fed back into .B ed(1) along with the original document to produce a new document that contains change bars wherever the new and old version of a document have differences. .I bar-on and .I bar-off may be specified as the commands to turn on and off change bars, respecively. If not specified, .B @CBON and .B @CBOFF (for Scribe) are used. .SH EXAMPLE .nf diff -b -e old.mss new.mss | cbar | ed - old.mss >bars.mss .fi .SH SEE ALSO diff(1), ed(1) .SH BUGS .B ed(1) commands on stdin must appear in decreasing line number order so that lines at the end of the file get edited first and lines at the beginning get edited last (diff -e does this). This restriction exists because additional lines are added to the file which will mess up the line numbering scheme if done in lowest-to-highest order. SHAR_EOF fi if test -f 'cbar.c' then echo shar: "will not over-write existing file 'cbar.c'" else cat << \SHAR_EOF > 'cbar.c' static char *RCSid = "$Header: cbar.c,v 1.1 87/04/22 10:31:51 alan Exp $"; /* * cbar [bar-on bar-off] * * Inserts change bar commands around diff -e output. * * Alan Crosswell, Columbia University * * Tacks on a "1,$p" at the end so that you can do something like this: * * diff -b -e old.mss updated.mss | cbar | ed - old.mss >updated-bar.mss * * Input looks like this: *------------------------------ * 746,747d * 138a * NOTE: Change this for LISTSERV. * . * 89c * followed by a blank or hyphen (e.g. "220 "). * . *------------------------------ * Output looks like: *------------------------------ * 746,747d * 138,138a * @CBON * NOTE: Change this for LISTSERV. * @CBOFF * . * 91,91c * @CBON * followed by a blank or hyphen (e.g. "220 "). * @CBOFF * . * 1,$p *------------------------------ * * NOTE: It is imperitave that the line numbers appear in highest-first * order since extra lines are being added. * * The default change bar commands are those used by Scribe (@CBON, @CBOFF). * You may provide your own (e.g. cbar ".mc |" ".mc" for nroff). * * $Log: cbar.c,v $ * Revision 1.1 87/04/22 10:31:51 alan * Initial revision * * */ #include <stdio.h> static char *cbon = "@CBON"; static char *cboff = "@CBOFF"; main(argc,argv) int argc; char **argv; { char buf[1024]; enum {ed_cmd, in_data} state = ed_cmd; if (argc == 3) { cbon = argv[1]; cboff = argv[2]; } else if (argc != 1) { fprintf(stderr,"Usage: cbar [bar_on bar_off]\n"); exit(1); } while(gets(buf) != NULL) { switch (state) { case ed_cmd: if (buf[strlen(buf)-1] == 'd') { state = ed_cmd; /* 'd' has no data */ puts(buf); } else { state = in_data; /* 'a' and 'c' do */ printf("%s\n%s\n", buf, cbon); } break; case in_data: if (buf[0] == '.' && buf[1] == '\0') { /* end of data */ state = ed_cmd; printf("%s\n.\n", cboff); } else puts(buf); break; } /* end switch(state) */ } /* end while */ puts("1,$p"); } SHAR_EOF fi exit 0 # End of shell archive -- Rich $alz "Anger is an energy" Cronus Project, BBN Labs rsalz@bbn.com Moderator, comp.sources.unix sources@uunet.uu.net