cppp (c pre pre processor) resolves long symbol names
loci!clb
loci at killer.UUCP
Tue Mar 8 08:16:37 AEST 1988
#! /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 at 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
More information about the Unix-pc.sources
mailing list