From ba2a45180cf5286c381597bcd493539db56241a6 Mon Sep 17 00:00:00 2001 From: George Koehler Date: Sun, 12 Nov 2017 11:25:18 -0500 Subject: [PATCH] Prototypes for string functions. More static. --- mach/proto/ncg/codegen.c | 1 - mach/proto/ncg/compute.c | 12 ++-- mach/proto/ncg/equiv.c | 23 +++--- mach/proto/ncg/fillem.c | 147 +++++++++++++++++++-------------------- mach/proto/ncg/gencode.c | 3 - mach/proto/ncg/glosym.c | 4 +- mach/proto/ncg/label.c | 1 - mach/proto/ncg/main.c | 4 ++ mach/proto/ncg/nextem.c | 3 + mach/proto/ncg/regvar.c | 3 +- mach/proto/ncg/regvar.h | 1 - mach/proto/ncg/salloc.c | 27 ++++--- mach/proto/ncg/subr.c | 1 - mach/proto/ncg/types.h | 10 +++ 14 files changed, 117 insertions(+), 123 deletions(-) diff --git a/mach/proto/ncg/codegen.c b/mach/proto/ncg/codegen.c index c003d8a5d..7e65590ee 100644 --- a/mach/proto/ncg/codegen.c +++ b/mach/proto/ncg/codegen.c @@ -1114,7 +1114,6 @@ readcodebytes() #ifdef TABLEDEBUG initlset(f) char* f; { - extern char* myalloc(); set_flag = f; if ((set_fd = open(f + 1, 2)) < 0) diff --git a/mach/proto/ncg/compute.c b/mach/proto/ncg/compute.c index 6adc21941..30d129cef 100644 --- a/mach/proto/ncg/compute.c +++ b/mach/proto/ncg/compute.c @@ -87,10 +87,8 @@ char opdesc[] = { #endif }; -string salloc(),strcpy(),strcat(); - -string mycat(s1,s2) register string s1,s2; { - register string s; +static string mycat(string s1, string s2) { + string s; if (s1==0 || *s1=='\0') return(s2); if (s2==0 || *s2=='\0') return(s1); @@ -101,7 +99,7 @@ string mycat(s1,s2) register string s1,s2; { return(s); } -string mystrcpy(s) register string s; { +string mystrcpy(string s) { register string r; r=salloc(strlen(s)); @@ -109,9 +107,9 @@ string mystrcpy(s) register string s; { return(r); } -char digstr[21][15]; +static char digstr[21][15]; -string tostring(n) register word n; { +string tostring(word n) { char buf[25]; if (n>=-20 && n<=20 && (n&1)==0) { diff --git a/mach/proto/ncg/equiv.c b/mach/proto/ncg/equiv.c index 9a18b08bb..9057aa211 100644 --- a/mach/proto/ncg/equiv.c +++ b/mach/proto/ncg/equiv.c @@ -21,15 +21,13 @@ static char rcsid[] = "$Id$"; * Author: Hans van Staveren */ -extern string myalloc(); +static int rar[MAXCREG]; +static rl_p *lar; +static int maxindex; +static int regclass[NREGS]; +static struct perm *perms; -int rar[MAXCREG]; -rl_p *lar; -int maxindex; -int regclass[NREGS]; -struct perm *perms; - -void permute(); +static void permute(int); struct perm * tuples(regls,nregneeded) rl_p *regls; { @@ -66,11 +64,10 @@ tuples(regls,nregneeded) rl_p *regls; { return(perms); } -void -permute(index) { - register struct perm *pp; - register rl_p rlp; - register i,j; +static void permute(int index) { + struct perm *pp; + rl_p rlp; + int i,j; if (index == maxindex) { for (pp=perms; pp != 0; pp=pp->p_next) { diff --git a/mach/proto/ncg/fillem.c b/mach/proto/ncg/fillem.c index f7f5ffcc9..1306b91fd 100644 --- a/mach/proto/ncg/fillem.c +++ b/mach/proto/ncg/fillem.c @@ -55,50 +55,57 @@ Read the documentation. #define SEGROM 2 #define SEGBSS 3 -long con(); - #define get8() getc(emfile) -FILE *emfile; +static FILE *emfile; -int nextispseu,savetab1; -int opcode; -int offtyp; -long argval; -int dlbval; -char *str,argstr[128],labstr[128]; -unsigned int maxstrsiz; -int strsiz; -int holno=0; -int procno=0; -int curseg= -1; -int part_size=0; -word part_word=0; +static int nextispseu,savetab1; +static int opcode; +static int offtyp; +static long argval; +static int dlbval; +static char *str,argstr[128],labstr[128]; +static unsigned int maxstrsiz; +static int strsiz; +static int holno=0; +static int procno=0; +static int curseg= -1; +static int part_size=0; +static word part_word=0; #ifdef REGVARS -int regallowed=0; +static int regallowed=0; #endif extern char em_flag[]; extern short em_ptyp[]; -extern double atof(); +/* machine dependent */ void prolog(full nlocals); -void mes(); -void bss(); -void savelab(); -void dumplab(); -void part_flush(); -void xdumplab(); -void switchseg(); +void mes(word); + +static int getarg(int); +static int table1(void); +static int table2(void); +static int table3(int); +static int get16(void); +static long get32(void); +static void getstring(void); +static string strarg(int); +static void bss(full, int, int); +static long con(int); +static void switchseg(int); +static void savelab(void); +static void dumplab(void); +static void xdumplab(void); +static void part_flush(void); +static string holstr(word); /* Own version of atol that continues computing on overflow. We don't know that about the ANSI C one. */ -long our_atol(s) -register char *s; -{ - register long total = 0; - register unsigned digit; +long our_atol(char *s) { + long total = 0; + unsigned digit; int minus = 0; while (*s == ' ' || *s == '\t') s++; @@ -117,14 +124,7 @@ register char *s; #define sp_cstx sp_cst2 -string tostring(); -string holstr(); -string strarg(); -string mystrcpy(); -string myalloc(); -long get32(); - -in_init(filename) char *filename; { +void in_init(char *filename) { emfile = stdin; if (filename && (emfile=freopen(filename,"r",stdin))==NULL) @@ -134,19 +134,18 @@ in_init(filename) char *filename; { str = myalloc(maxstrsiz=256); } -in_start() { +void in_start(void) { #ifdef modhead fprintf(codefile,"%s",modhead) ; #endif } -in_finish() { +static void in_finish(void) { } -void -fillemlines() { - register int t,i; - register struct emline *lp; +void fillemlines(void) { + int t,i; + struct emline *lp; while ((emlines+nemlines)-emp= sp_fmnem) { @@ -471,8 +470,8 @@ int table1() { return(table3(i)); } -int table2() { - register i; +static int table2(void) { + int i; i = get8(); if (i < sp_fcst0+sp_ncst0 && i >= sp_fcst0) { @@ -482,7 +481,7 @@ int table2() { return(table3(i)); } -int table3(i) { +static int table3(int i) { word consiz; switch(i) { @@ -525,8 +524,8 @@ int table3(i) { return(i); } -int get16() { - register int l_byte, h_byte; +static int get16(void) { + int l_byte, h_byte; l_byte = get8(); h_byte = get8(); @@ -534,9 +533,9 @@ int get16() { return l_byte | (h_byte*256) ; } -long get32() { - register long l; - register int h_byte; +static long get32(void) { + long l; + int h_byte; l = get8(); l |= ((unsigned) get8())*256 ; @@ -546,9 +545,9 @@ long get32() { return l | (h_byte*256L*256*256L) ; } -getstring() { - register char *p; - register n; +static void getstring(void) { + char *p; + int n; getarg(cst_ptyp); if (argval < 0) @@ -565,8 +564,8 @@ getstring() { *p++ = '\0'; } -char *strarg(t) { - register char *p; +static string strarg(int t) { + char *p; switch (t) { case sp_ilb1: @@ -613,9 +612,8 @@ char *strarg(t) { return(mystrcpy(argstr)); } -void -bss(n,t,b) full n; { - register long s = 0; +static void bss(full n, int t, int b) { + long s = 0; if (n % TEM_WSIZE) fatal("bad BSS size"); @@ -637,8 +635,8 @@ bss(n,t,b) full n; { fatal("bad BSS initializer"); } -long con(t) { - register i; +static long con(int t) { + int i; strarg(t); switch (t) { @@ -686,8 +684,7 @@ swtxt() { switchseg(SEGTXT); } -void -switchseg(s) { +static void switchseg(int s) { if (s == curseg) return; @@ -696,8 +693,7 @@ switchseg(s) { fprintf(codefile,"%s\n",segname[s]); } -void -savelab() { +static void savelab(void) { register char *p,*q; part_flush(); @@ -711,8 +707,7 @@ savelab() { ; } -void -dumplab() { +static void dumplab(void) { if (labstr[0] == 0) return; @@ -721,8 +716,7 @@ dumplab() { labstr[0] = 0; } -void -xdumplab() { +static void xdumplab(void) { if (labstr[0] == 0) return; @@ -730,8 +724,7 @@ xdumplab() { newdlb(labstr); } -void -part_flush() { +static void part_flush(void) { /* * Each new data fragment and each data label starts at @@ -744,7 +737,7 @@ part_flush() { part_word = 0; } -string holstr(n) word n; { +static string holstr(word n) { sprintf(str,hol_off,n,holno); return(mystrcpy(str)); diff --git a/mach/proto/ncg/gencode.c b/mach/proto/ncg/gencode.c index 9cc10778f..d3018b057 100644 --- a/mach/proto/ncg/gencode.c +++ b/mach/proto/ncg/gencode.c @@ -22,10 +22,7 @@ static char rcsid[] = "$Id$"; * Author: Hans van Staveren */ -string mystrcpy(); - FILE *codefile; -extern FILE *freopen(); out_init(filename) char *filename; { diff --git a/mach/proto/ncg/glosym.c b/mach/proto/ncg/glosym.c index 4052c1bfe..fa88895af 100644 --- a/mach/proto/ncg/glosym.c +++ b/mach/proto/ncg/glosym.c @@ -16,9 +16,7 @@ static char rcsid[] = "$Id$"; * Author: Hans van Staveren */ -extern string myalloc(); - -glosym_p glolist= (glosym_p) 0; +static glosym_p glolist= (glosym_p) 0; enterglo(name,romp) string name; word *romp; { register glosym_p gp; diff --git a/mach/proto/ncg/label.c b/mach/proto/ncg/label.c index 0c192589c..ed88a8dc7 100644 --- a/mach/proto/ncg/label.c +++ b/mach/proto/ncg/label.c @@ -5,7 +5,6 @@ #include "label.h" static label_p label_list = (label_p)0; -extern char *myalloc(); void add_label(num, height, flth) diff --git a/mach/proto/ncg/main.c b/mach/proto/ncg/main.c index 7f214f349..096b470f2 100644 --- a/mach/proto/ncg/main.c +++ b/mach/proto/ncg/main.c @@ -22,6 +22,10 @@ int Debug=0; char *strtdebug=""; #endif +/* fillem.c */ +void in_init(char *); +void in_start(void); + main(argc,argv) char **argv; { register unsigned n; extern unsigned cc1,cc2,cc3,cc4; diff --git a/mach/proto/ncg/nextem.c b/mach/proto/ncg/nextem.c index 0e8446b3f..daad8223c 100644 --- a/mach/proto/ncg/nextem.c +++ b/mach/proto/ncg/nextem.c @@ -27,6 +27,9 @@ static char rcsid[] = "$Id$"; extern char em_mnem[][4]; #endif +/* fillem.c */ +void fillemlines(void); + byte *trypat(bp,len) register byte *bp; { register patlen,i; result_t result; diff --git a/mach/proto/ncg/regvar.c b/mach/proto/ncg/regvar.c index b863bffd5..2c2650086 100644 --- a/mach/proto/ncg/regvar.c +++ b/mach/proto/ncg/regvar.c @@ -24,8 +24,7 @@ static char rcsid[] = "$Id$"; * * Author: Hans van Staveren */ -extern string myalloc(); -struct regvar *rvlist; +static struct regvar *rvlist; struct regvar * linkreg(long of, int sz, int tp, int sc) { diff --git a/mach/proto/ncg/regvar.h b/mach/proto/ncg/regvar.h index 089bd72b1..2f3bfecd0 100644 --- a/mach/proto/ncg/regvar.h +++ b/mach/proto/ncg/regvar.h @@ -18,7 +18,6 @@ struct regassigned { int ra_score; }; -extern struct regvar *rvlist; extern int nregvar[]; extern struct regassigned *regassigned[]; diff --git a/mach/proto/ncg/salloc.c b/mach/proto/ncg/salloc.c index a261a5a09..7a7dd189c 100644 --- a/mach/proto/ncg/salloc.c +++ b/mach/proto/ncg/salloc.c @@ -32,7 +32,7 @@ static char rcsid[] = "$Id$"; char *stab[MAXSTAB]; int nstab=0; -void chkstr(); +static void chkstr(string, char *); string myalloc(size) { register string p; @@ -43,21 +43,21 @@ string myalloc(size) { return(p); } -myfree(p) string p; { +void myfree(string p) { free(p); } -popstr(nnstab) { - register i; +void popstr(int nnstab) { + int i; for (i=nnstab;ilow) { diff --git a/mach/proto/ncg/subr.c b/mach/proto/ncg/subr.c index 6e57ed18d..08861274d 100644 --- a/mach/proto/ncg/subr.c +++ b/mach/proto/ncg/subr.c @@ -24,7 +24,6 @@ static char rcsid[] = "$Id$"; * Author: Hans van Staveren */ -string myalloc(); unsigned codegen(); match(tp,tep,optexp) register token_p tp; register set_p tep; { diff --git a/mach/proto/ncg/types.h b/mach/proto/ncg/types.h index 50fc1aecd..91625557d 100644 --- a/mach/proto/ncg/types.h +++ b/mach/proto/ncg/types.h @@ -28,3 +28,13 @@ typedef char * string; #ifndef WRD_FMT #define WRD_FMT "%ld" #endif /* WRD_FMT */ + +/* compute.c */ +string mystrcpy(string); +string tostring(word); +/* salloc.c */ +string myalloc(int); +void myfree(string); +void popstr(int); +char *salloc(int); +void garbage_collect(void);