Subject: 'shortc' can not handle tcsh6.00 sources (+fix) Index: new/shortc/shortc.c 2.11BSD Description: The 'shortc' program runs out of memory when processing overlarge programs such as 'tcsh6.0X'. Repeat-By: cd tcsh6.00 shortc *.c *.h Fix: Several changes were made to shortc.c which make available about 6kb of additional data space: 1) The hash table size was reduced from 2048 to 512 entries saving 2kb of space (2 bytes per entry in symtab[]). 2) An 'auto' buffer is assigned to "stdout" and "stderr", saving 2kb of space. 3) Replacing the reference to perror() with a 'fprintf' of "errno", this saves about 1.5kb of strings by not including sym_errlist[]. 4) ifdef'ing the sccs header at the front of the file Also, the file name on which 'shortc' runs out of memory is now printed out. ========================================================================== *** /usr/src/new/shortc/shortc.c.old Tue Sep 6 19:47:45 1988 --- /usr/src/new/shortc/shortc.c Sat Apr 11 20:36:34 1992 *************** *** 15,22 **** --- 15,24 ---- * Hacked by m.d. marquez to allow pipe into stdin and add -s (sed) option. */ + #if !defined(lint) && !defined(pdp11) static char rcsid[] = "$Header: shortc.c,v 1.2 88/09/06 01:30:58 bin Exp Locker: bin $"; + #endif #include #include *************** *** 24,30 **** #define SYMLEN 7 /* symbols must be unique within ... chars */ #define MAXLEN 128 /* need a limit for tokenizing */ ! #define HASHSIZ 2048 /* power of 2; not an upper limit */ typedef struct Symbol symbol; struct Symbol { --- 26,32 ---- #define SYMLEN 7 /* symbols must be unique within ... chars */ #define MAXLEN 128 /* need a limit for tokenizing */ ! #define HASHSIZ 512 /* power of 2; not an upper limit */ typedef struct Symbol symbol; struct Symbol { *************** *** 53,62 **** int read_file = 0; /* flag if read file arguments */ symbol *lookup(); ! char *token(), *truncname(); char *myalloc(); extern char *malloc(); /* * entry point --- 55,65 ---- int read_file = 0; /* flag if read file arguments */ symbol *lookup(); ! char *token(), *truncname(), *curarg = "stdin"; char *myalloc(); extern char *malloc(); + extern int errno; /* * entry point *************** *** 65,70 **** --- 68,77 ---- register argc; register char **argv; { + char obuf[BUFSIZ]; + + setbuf(stdout, obuf); + while (--argc > 0) doarg(*++argv); *************** *** 81,86 **** --- 88,95 ---- doarg(arg) char *arg; { + char ibuf[BUFSIZ]; + if (*arg == '-') { arg++; if (isdigit(*arg)) *************** *** 97,106 **** } if (freopen(arg, "r", stdin) == NULL) { ! perror(arg); return; } process(); read_file++; --- 106,117 ---- } if (freopen(arg, "r", stdin) == NULL) { ! fprintf(stderr, "freopen(%s) err: %d\n", errno); return; } + setbuf(stdin, ibuf); + curarg = arg; process(); read_file++; *************** *** 328,334 **** register char *p; if (!(p = malloc((unsigned)n))) { ! fprintf(stderr, "Out of space\n"); exit(1); } return p; --- 339,345 ---- register char *p; if (!(p = malloc((unsigned)n))) { ! fprintf(stderr, "Out of space in %s\n", curarg); exit(1); } return p;