clb) (03/03/88)
Here is a simple program to remedy the 8-character name problem on the earlier c compilers. Cppp scans the files named as args and prepares ed(1) or sed(1) scripts to fix long-name conflicts. Typical usage might be as follows ... cppp *.[hcly] ;# list conflicts for inspection cppp -e *.[hcly] > script.ed ;# make "ed" script for i in *.[hcly] ;# loop through all files, substitute do ;# shorter names ed $i < script.ed done This program is new and may contain bugs. If you find any, or make interesting changes, let me know at killer!loci!clb CLBrunow #___________________________________________ # CUT EVERYTHING ABOVE THIS LINE # Shell archive created: Thu Mar 3 04:45:37 TBD 1988 # by Loci Products, 32 56 N, 96 41 W # mail to: ihnp4!killer!loci!clb (administrator) # To unpack the enclosed files, use this file as input # to the Bourne shell (/bin/sh) # This can be most easily done by the command; # sh < thisfilename # This archive contains; # ---------- file list---------- echo Files: cppp.1 cppp.l cppp.mk filename=cppp.1 if [ -f $filename ] then echo "$filename" exists. Skipping. filename=/dev/null else echo extracting file $filename fi cat << END_OF_FILE > $filename .TH cppp 1 .UC 1 .SH NAME .B cppp \- A c-program compactifier .SH SYNOPSIS .B cppp .B \[-flag] [ .B file ... ] .br .SH DESCRIPTION .PP .B Cppp scans the named files (stdin default) and collects a list of long words (more than 8 characters), test for conflicts and prints the list on stdout. The optional .B flag specifies the output format, choices are: .B \-l list, .B \-s command script suitable for sed(1), .B \-e command script suitable for ed(1). .B \-v verbosely list words, skip test for conflicts. .PP Words listed are specified as beginning with an alphabetic (a-zA-Z) or underscore ('_') character, followed by enough alphabetic, numeric (0-9), or '_' characters to exceed the maximum allowable length of eight characters. C-program comments and strings protected by double quotes ("string") are exempted from the list. .PP If either the -e or -s flags are specified, the output format will be a command script suitable for the indicated editor. When the editor is invoked with this file as command input, the long words are replaced by a short, sequentially generated word and the original long word inside comment delimiters. In this way, the readability of the file is not jeopardized. For example ... .PP #define SUPER_LONG_WORD 22 .br becomes something like ... .br #define xxx143/*SUPER_LONG_WORD*/ 22 .SH FILES cppp.l The 'lex' source script. .SH AUTHOR CLBrunow, Loci Products, Richardson, Tx. .SH BUGS .PP Mail complaints to killer!loci!clb . END_OF_FILE if [ "$filename" != "/dev/null" ] then size=`wc -c < $filename` if [ $size != 1464 ] then echo $filename should be 1464 bytes, is $size fi chmod 644 $filename fi filename=cppp.l if [ -f $filename ] then echo "$filename" exists. Skipping. filename=/dev/null else echo extracting file $filename fi cat << END_OF_FILE > $filename %{ #include <stdio.h> #define MAXLENGTH 8 #define USE_ED 1 #define USE_SED 2 #define USE_VERB 4 extern char *calloc(); struct tnode{ char *word; short count, number; struct tnode *left, *right; } *root; int use, /* ed or sed marker */ dun, /* flg indicates string printed */ nextid = 1; /* used for consecutive numbering */ struct tnode *pot; /* pointer to old tnode */ extern struct tnode *tree(), *talloc(); /* Lex source script */ %} F [a-zA-Z_] P [a-zA-Z0-9_] %% \/\*[^/]* { /* ignore comments */ if(yytext[yyleng-1] != '*') yymore(); else input(); } \"[^"]* { /* exempt text enclosed in "s */ if(yytext[yyleng-1] == '\\') yymore(); else input(); } {F}{P}+ if(yyleng > MAXLENGTH) root = tree(root, yytext); "\n" ; . ; /* ignore everything (\n excepted) */ %% main(argc, argv) char *argv[]; { int i; char flgs[8]; FILE *ifp; root = NULL; use = 0; /* define default editor format */ if(argc == 1) yylex(); else { i = 1; /* number of first filename */ if(*argv[1] == '-') { strncpy(flgs, argv[1], 7); switch(flgs[1]) { case 'e': use = USE_ED; break; case 's': use = USE_SED; break; case 'v': use = USE_VERB; break; case 'l': use = 0; break; default: printf("%s: unknown flag %s\n", argv[0], argv[1]); printf("usage: %s -[elsv] file ...\n", argv[0]); exit(1); } i = 2; } if(i == argc) yylex(); else { fclose(stdin); while(i < argc) { ifp = fopen(argv[i], "r"); if(ifp == NULL) { fprintf(stderr, "%s: can't open %s\n", argv[0], argv[i]); continue; } yylex(); fclose(ifp); i++; } } } treeprint(root); if(use == USE_ED) printf("w\nq\n"); exit(0); } struct tnode *tree(p, w) struct tnode *p; char *w; { extern struct tnode *talloc(); extern char *strsave(); int cond; if(p == NULL) { p = talloc(); p->word = strsave(w); p->number= nextid++; p->left = p->right = NULL; } else if((cond= strcmp(w, p->word)) < 0) p->left = tree(p->left, w); else if(cond > 0) p->right = tree(p->right, w); else p->count++; return(p); } treeprint(p) struct tnode *p; { if(p != NULL) { treeprint(p->right); if(use == USE_VERB) printf("%d\t%s\n", ++p->count, p->word); else if(p->count) cmp_strs(p); treeprint(p->left); } } cmp_strs(p) struct tnode *p; { if(p && pot) { if(strncmp(pot->word, p->word, MAXLENGTH) == 0) { if( !dun) use_fmt(pot); use_fmt(p); dun++; } else dun = 0; } pot = p; } use_fmt(p) struct tnode *p; { if(use == USE_ED) printf("g,%s,s,,xxx%d/*&*/,g\n", p->word, p->number); else if(use == USE_SED) printf("s,%s,xxx%d/*&*/,g\n", p->word, p->number); else printf("%d\t%s\n", ++p->count, p->word); } struct tnode *talloc() { char *alloc; return((struct tnode *) calloc(sizeof(struct tnode), 1)); } char *strsave(s) char *s; { char *p; p= calloc(strlen(s) + 1, 1); strcpy(p, s); return(p); } yywrap(){} END_OF_FILE if [ "$filename" != "/dev/null" ] then size=`wc -c < $filename` if [ $size != 3263 ] then echo $filename should be 3263 bytes, is $size fi chmod 644 $filename fi filename=cppp.mk if [ -f $filename ] then echo "$filename" exists. Skipping. filename=/dev/null else echo extracting file $filename fi cat << END_OF_FILE > $filename cppp : cppp.l lex cppp.l cc -g lex.yy.c -o cppp rm lex.yy.c END_OF_FILE if [ "$filename" != "/dev/null" ] then size=`wc -c < $filename` if [ $size != 64 ] then echo $filename should be 64 bytes, is $size fi chmod 644 $filename fi echo done exit 0
clb) (03/08/88)
#! /bin/sh # This is a shell archive. Remove anything before this line, then unpack # it by saving it into a file and typing "sh file". To overwrite existing # files, type "sh file -c". You can also feed this as standard input via # unshar, or by typing "sh <file", e.g.. If this archive is complete, you # will see the following message at the end: # "End of shell archive." # Contents: cppp.1 cppp.l cppp.mk # Wrapped by loci@killer on Mon Mar 7 16:07:33 1988 PATH=/bin:/usr/bin:/usr/ucb ; export PATH if test -f cppp.1 -a "${1}" != "-c" ; then echo shar: Will not over-write existing file \"cppp.1\" else echo shar: Extracting \"cppp.1\" \(1464 characters\) sed "s/^X//" >cppp.1 <<'END_OF_cppp.1' X.TH cppp 1 X.UC 1 X.SH NAME X.B cppp X\- A c-program compactifier X.SH SYNOPSIS X.B cppp X.B \[-flag] X[ X.B file ... X] X.br X.SH DESCRIPTION X.PP X.B Cppp Xscans the named files (stdin default) and collects a list of long words X(more than 8 characters), test for conflicts and prints the list on stdout. The optional X.B flag Xspecifies the output format, choices are: X.B \-l Xlist, X.B \-s Xcommand script suitable for sed(1), X.B \-e Xcommand script suitable for ed(1). X.B \-v Xverbosely list words, skip test for conflicts. X.PP XWords listed are specified as beginning with an alphabetic (a-zA-Z) Xor underscore ('_') character, followed Xby enough alphabetic, numeric (0-9), or '_' characters to exceed the maximum Xallowable length of eight characters. C-program comments and strings Xprotected by double quotes ("string") are exempted from the list. X.PP XIf either the -e or -s flags are specified, the output format will be Xa command script suitable for the indicated editor. When the editor is Xinvoked with this file as command input, the long words are replaced by Xa short, sequentially generated word and the original long word inside Xcomment delimiters. In this way, the readability of the file is not Xjeopardized. For example ... X.PP X#define SUPER_LONG_WORD 22 X.br X becomes something like ... X.br X#define xxx143/*SUPER_LONG_WORD*/ 22 X.SH FILES Xcppp.l The 'lex' source script. X.SH AUTHOR XCLBrunow, Loci Products, Richardson, Tx. X.SH BUGS X.PP XMail complaints to killer!loci!clb . END_OF_cppp.1 if test 1464 -ne `wc -c <cppp.1`; then echo shar: \"cppp.1\" unpacked with wrong size! fi # end of overwriting check fi if test -f cppp.l -a "${1}" != "-c" ; then echo shar: Will not over-write existing file \"cppp.l\" else echo shar: Extracting \"cppp.l\" \(3263 characters\) sed "s/^X//" >cppp.l <<'END_OF_cppp.l' X%{ X#include <stdio.h> X X#define MAXLENGTH 8 X#define USE_ED 1 X#define USE_SED 2 X#define USE_VERB 4 X Xextern char *calloc(); X Xstruct tnode{ X char *word; X short count, number; X struct tnode *left, *right; X} *root; X Xint use, /* ed or sed marker */ X dun, /* flg indicates string printed */ X nextid = 1; /* used for consecutive numbering */ X Xstruct tnode *pot; /* pointer to old tnode */ X Xextern struct tnode *tree(), *talloc(); X X/* Lex source script */ X%} XF [a-zA-Z_] XP [a-zA-Z0-9_] X%% X\/\*[^/]* { /* ignore comments */ X if(yytext[yyleng-1] != '*') X yymore(); X else X input(); X } X\"[^"]* { /* exempt text enclosed in "s */ X if(yytext[yyleng-1] == '\\') X yymore(); X else X input(); X } X{F}{P}+ if(yyleng > MAXLENGTH) root = tree(root, yytext); X"\n" ; X. ; /* ignore everything (\n excepted) */ X%% X Xmain(argc, argv) Xchar *argv[]; X{ X int i; X char flgs[8]; X FILE *ifp; X X root = NULL; X use = 0; /* define default editor format */ X X if(argc == 1) X yylex(); X else { X i = 1; /* number of first filename */ X if(*argv[1] == '-') X { X strncpy(flgs, argv[1], 7); X switch(flgs[1]) X { X case 'e': use = USE_ED; break; X case 's': use = USE_SED; break; X case 'v': use = USE_VERB; break; X case 'l': use = 0; break; X default: X printf("%s: unknown flag %s\n", X argv[0], argv[1]); X printf("usage: %s -[elsv] file ...\n", X argv[0]); X exit(1); X } X i = 2; X } X if(i == argc) X yylex(); X else X { X fclose(stdin); X while(i < argc) X { X ifp = fopen(argv[i], "r"); X if(ifp == NULL) X { X fprintf(stderr, "%s: can't open %s\n", X argv[0], argv[i]); X continue; X } X yylex(); X fclose(ifp); X i++; X } X } X } X treeprint(root); X if(use == USE_ED) X printf("w\nq\n"); X exit(0); X} X Xstruct tnode *tree(p, w) Xstruct tnode *p; char *w; X{ X extern struct tnode *talloc(); X extern char *strsave(); X int cond; X X if(p == NULL) { X p = talloc(); X p->word = strsave(w); X p->number= nextid++; X p->left = p->right = NULL; X } else if((cond= strcmp(w, p->word)) < 0) X p->left = tree(p->left, w); X else if(cond > 0) X p->right = tree(p->right, w); X else p->count++; X return(p); X} X Xtreeprint(p) Xstruct tnode *p; X{ X if(p != NULL) { X treeprint(p->right); X if(use == USE_VERB) X printf("%d\t%s\n", ++p->count, p->word); X else if(p->count) X cmp_strs(p); X treeprint(p->left); X } X} X Xcmp_strs(p) Xstruct tnode *p; X{ X if(p && pot) { X if(strncmp(pot->word, p->word, MAXLENGTH) == 0) { X if( !dun) X use_fmt(pot); X use_fmt(p); X dun++; X } else dun = 0; X } X pot = p; X} X Xuse_fmt(p) Xstruct tnode *p; X{ X if(use == USE_ED) X printf("g,%s,s,,xxx%d/*&*/,g\n", X p->word, p->number); X else if(use == USE_SED) X printf("s,%s,xxx%d/*&*/,g\n", X p->word, p->number); X else printf("%d\t%s\n", ++p->count, p->word); X} X Xstruct tnode *talloc() { X char *alloc; X X return((struct tnode *) calloc(sizeof(struct tnode), 1)); X} X Xchar *strsave(s) char *s; { X char *p; X X p= calloc(strlen(s) + 1, 1); X strcpy(p, s); X return(p); X} X Xyywrap(){} END_OF_cppp.l if test 3263 -ne `wc -c <cppp.l`; then echo shar: \"cppp.l\" unpacked with wrong size! fi # end of overwriting check fi if test -f cppp.mk -a "${1}" != "-c" ; then echo shar: Will not over-write existing file \"cppp.mk\" else echo shar: Extracting \"cppp.mk\" \(64 characters\) sed "s/^X//" >cppp.mk <<'END_OF_cppp.mk' Xcppp : cppp.l X lex cppp.l X cc -g lex.yy.c -o cppp X rm lex.yy.c X END_OF_cppp.mk if test 64 -ne `wc -c <cppp.mk`; then echo shar: \"cppp.mk\" unpacked with wrong size! fi # end of overwriting check fi echo shar: End of shell archive. exit 0