Path: seismo!harvard!talcott!panda!sources-request From: sources-request@panda.UUCP Newsgroups: mod.sources Subject: shortc: sed output, and standard input Message-ID: <1599@panda.UUCP> Date: 4 Apr 86 14:40:06 GMT Sender: jpn@panda.UUCP Lines: 165 Approved: jpn@panda.UUCP Mod.sources: Volume 4, Issue 50 Submitted by: convex!smu!s100ms!marquez I have put some hacks into the shortc program recently posted to mod.sources. First, shortc can now take input from a pipe, as in: cat *.h *.c | shortc -p > global.h of course the same effect is gained by "shortc *.h *.c > global.h", but this allows for special applications. I also added a -s option so that a sed command file can be created instead of an include file. Remember, if the -s option is needed, then the -p option will probably be required too. This submission is in the form of a context diff, suitable for "patch"ing the original. manlio d marquez convex!smu!s100ms!marquez ------- start of diffs ------------- *** shortc.orig Fri Apr 4 09:15:15 1986 --- shortc.c Fri Apr 4 09:15:35 1986 *************** *** 14,17 they will cause (innocuous) redefinition messages. */ #include --- 14,20 ----- they will cause (innocuous) redefinition messages. */ + /* + hacked by m.d. marquez to allow pipe into stdin and add -s (sed) option + */ #include *************** *** 45,48 int symlen = SYMLEN; char parsepp; /* if set, parse preprocessor lines */ symbol *lookup(); --- 48,53 ----- int symlen = SYMLEN; char parsepp; /* if set, parse preprocessor lines */ + int sedout = 0; /* want sed output */ + int read_file = 0; /* flag if read file arguments */ symbol *lookup(); *************** *** 58,61 doarg(*++argv); dump(); exit(0); --- 63,69 ----- doarg(*++argv); + if( !read_file ) + process(); + dump(); exit(0); *************** *** 64,70 doarg (arg) char *arg; /*: process one file or flag arg */ { - register char *s; - register symbol *y; - if( *arg == '-' ) { arg++; --- 72,75 ----- doarg (arg) char *arg; /*: process one file or flag arg */ { if( *arg == '-' ) { arg++; *************** *** 73,76 else if( *arg == 'p' ) parsepp = 1; else fputs(Usage, stderr); return; --- 78,83 ----- else if( *arg == 'p' ) parsepp = 1; + else if( *arg == 's' ) + sedout = 1; else fputs(Usage, stderr); return; *************** *** 82,85 } while( s = token() ) if( (y = lookup(s))->flag < SEEN ) --- 89,102 ----- } + process(); + + read_file++; + } + + process() + { + register char *s; + register symbol *y; + while( s = token() ) if( (y = lookup(s))->flag < SEEN ) *************** *** 177,180 break; } if( strcmp(y->inname, s) == 0 ) break; --- 194,198 ----- break; } + if( strcmp(y->inname, s) == 0 ) break; *************** *** 191,196 for( n = HASHSIZ; --n >= 0; ) for( y = symtab[n]; y; y = y->link ) ! if( y->flag > SEEN ) ! printf("#define %s %s%s\n", y->inname, y->prefix, y->inname); } --- 209,215 ----- for( n = HASHSIZ; --n >= 0; ) for( y = symtab[n]; y; y = y->link ) ! if( y->flag > SEEN ) { ! if( sedout ) ! printf("/%s/s//%s%s/g\n", y->inname, y->prefix, y->inname); else *************** *** 194,197 printf("#define %s %s%s\n", y->inname, y->prefix, y->inname); } --- 213,220 ----- printf("/%s/s//%s%s/g\n", y->inname, y->prefix, y->inname); + else + printf("#define %s %s%s\n", y->inname, + y->prefix, y->inname); + } } ----------- end of diffs -------------------