Path: utzoo!utgpu!water!watmath!uunet!umix!mailrus!ames!killer!loci From: loci@killer.UUCP (loci!clb) Newsgroups: unix-pc.sources Subject: cppp (c pre-pre-processor) fix 8-char symbol limit. Keywords: symbol name length limit = 8 char Message-ID: <3552@killer.UUCP> Date: 3 Mar 88 07:03:58 GMT Organization: The Unix(R) Connection, Dallas, Texas Lines: 328 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 #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