From 60e7d06d82703f3a9d727e4788ba00b791277fd2 Mon Sep 17 00:00:00 2001 From: David Given Date: Sun, 6 Aug 2017 11:58:36 +0200 Subject: [PATCH] Ansification and warning fixes. --- lang/m2/comp/input.c | 4 +- modules/src/input/AtEoIF.c | 2 +- modules/src/input/AtEoIT.c | 2 +- modules/src/input/inp_pkg.body | 18 ++++---- modules/src/object/object.h | 2 +- modules/src/object/rd.c | 49 +++++++------------- util/led/memory.c | 8 ++-- util/led/memory.h | 2 + util/led/scan.c | 84 ++++++++++++++-------------------- util/led/scan.h | 9 ++++ 10 files changed, 79 insertions(+), 101 deletions(-) diff --git a/lang/m2/comp/input.c b/lang/m2/comp/input.c index ef8ee2982..ad53b50e8 100644 --- a/lang/m2/comp/input.c +++ b/lang/m2/comp/input.c @@ -19,7 +19,7 @@ struct f_info file_info; #include -AtEoIF() +int AtEoIF(void) { /* Make the unstacking of input streams noticable to the lexical analyzer @@ -28,7 +28,7 @@ AtEoIF() return 1; } -AtEoIT() +int AtEoIT(void) { /* Make the end of the text noticable */ diff --git a/modules/src/input/AtEoIF.c b/modules/src/input/AtEoIF.c index 4fbb4d556..5bf9a6000 100644 --- a/modules/src/input/AtEoIF.c +++ b/modules/src/input/AtEoIF.c @@ -8,7 +8,7 @@ inserted file. */ int -AtEoIF() +AtEoIF(void) { return 0; } diff --git a/modules/src/input/AtEoIT.c b/modules/src/input/AtEoIT.c index 977b0cc10..64b15ba7a 100644 --- a/modules/src/input/AtEoIT.c +++ b/modules/src/input/AtEoIT.c @@ -8,7 +8,7 @@ inserted text. */ int -AtEoIT() +AtEoIT(void) { return 0; } diff --git a/modules/src/input/inp_pkg.body b/modules/src/input/inp_pkg.body index 3cca88a17..6de4a5268 100644 --- a/modules/src/input/inp_pkg.body +++ b/modules/src/input/inp_pkg.body @@ -20,7 +20,7 @@ A default one is provided, which does nothing. AtEoIF() : this routine is called at the end of an inserted file. A default one is provided, which does nothing. - + Imported objects are: INP_NPUSHBACK, INP_READ_IN_ONE, INP_TYPE, INP_VAR, routines from the "alloc" package, routines from the "storage" @@ -110,7 +110,7 @@ INP_rdfile(fd, fn, size, pbuf) int rsize; if ( - (*size = sys_filesize(fn)) < 0 + ((*size = sys_filesize(fn))) < 0 || ((unsigned) (*size + 1) != (*size + 1)) || @@ -140,7 +140,7 @@ _PROTOTYPE(INP_PRIVATE char * INP_pbuf, (void)); INP_PRIVATE char * INP_pbuf() { - register struct INP_i_buf *ib = + register struct INP_i_buf *ib = (struct INP_i_buf *) malloc(sizeof(struct INP_i_buf)); if (!ib) return 0; @@ -164,7 +164,7 @@ INP_push_bh() { register struct INP_buffer_header *bh; - if (bh = INP_head) { + if ((bh = INP_head)) { bh->bh_ipp = _ipp; #ifdef INP_TYPE bh->bh_i = INP_VAR; @@ -247,10 +247,10 @@ INP_mk_filename(dir, file, newname) if (!dst) return 0; *newname = dst; if (*dir) { - while (*dst++ = *dir++) ; + while ((*dst++ = *dir++)) ; *(dst-1) = '/'; } - while (*dst++ = *file++); + while ((*dst++ = *file++)); return 1; } @@ -278,13 +278,13 @@ InsertFile(filnam, table, result) if (!sys_open(filnam, OP_READ, &fd)) return 0; } else { - while (*table) { + while (*table) { /* look in the directory table */ if (!INP_mk_filename(*table++, filnam, &newfn)) { return 0; } if (sys_open(newfn, OP_READ, &fd)) { - /* free filnam ??? NO we don't know + /* free filnam ??? NO we don't know where it comes from! */ filnam = newfn; @@ -378,7 +378,7 @@ loadbuf() *--de = *--so; } #endif - if ( INP_rdblock(bh->bh_fd, bh->bh_text, &(bh->bh_size)) + if ( INP_rdblock(bh->bh_fd, bh->bh_text, &(bh->bh_size)) && bh->bh_size > 0 ) { diff --git a/modules/src/object/object.h b/modules/src/object/object.h index d6c218a2a..54e20e26c 100644 --- a/modules/src/object/object.h +++ b/modules/src/object/object.h @@ -36,7 +36,7 @@ void rd_sect(struct outsect *s, unsigned int c); void rd_outsect(int sectno); void rd_emit(char *b, long c); void rd_relo(struct outrelo *r, unsigned int c); -void rd_rew_relo(struct outhead *head); +void rd_rew_relos(struct outhead *head); void rd_name(struct outname *n, unsigned int c); void rd_string(char *s, long c); int rd_arhdr(int fd, struct ar_hdr *a); diff --git a/modules/src/object/rd.c b/modules/src/object/rd.c index 7790a4720..54610a0dc 100644 --- a/modules/src/object/rd.c +++ b/modules/src/object/rd.c @@ -40,9 +40,7 @@ static long rd_base; static int sectionnr; static void -OUTREAD(p, b, n) - char *b; - long n; +OUTREAD(int p, char* b, long n) { register long l = outseek[p]; @@ -59,8 +57,7 @@ OUTREAD(p, b, n) * Open the output file according to the chosen strategy. */ int -rd_open(f) - char *f; +rd_open(char* f) { if ((outfile = open(f, 0)) < 0) @@ -71,7 +68,7 @@ rd_open(f) static int offcnt; int -rd_fdopen(fd) +rd_fdopen(int fd) { register int i; @@ -89,7 +86,7 @@ rd_fdopen(fd) } void -rd_close() +rd_close(void) { close(outfile); @@ -97,21 +94,20 @@ rd_close() } int -rd_fd() +rd_fd(void) { return outfile; } void -rd_ohead(head) - register struct outhead *head; +rd_ohead(struct outhead* head) { register long off; OUTREAD(PARTEMIT, (char *) head, (long) SZ_HEAD); { register char *c = (char *) head + (SZ_HEAD-4); - + head->oh_nchar = get4(c); c -= 4; head->oh_nemit = get4(c); c -= 2; head->oh_nname = uget2(c); @@ -134,8 +130,7 @@ rd_ohead(head) } void -rd_rew_relos(head) - register struct outhead *head; +rd_rew_relos(struct outhead* head) { register long off = OFF_RELO(*head) + rd_base; @@ -143,9 +138,7 @@ rd_rew_relos(head) } void -rd_sect(sect, cnt) - register struct outsect *sect; - register unsigned int cnt; +rd_sect(struct outsect* sect, unsigned int cnt) { register char *c = (char *) sect + cnt * SZ_SECT; @@ -166,7 +159,7 @@ rd_sect(sect, cnt) } void -rd_outsect(s) +rd_outsect(int s) { OUTSECT(s); sectionnr = s; @@ -176,18 +169,14 @@ rd_outsect(s) * We don't have to worry about byte order here. */ void -rd_emit(emit, cnt) - char *emit; - long cnt; +rd_emit(char* emit, long cnt) { OUTREAD(PARTEMIT, emit, cnt); offset[sectionnr] += cnt; } void -rd_relo(relo, cnt) - register struct outrelo *relo; - register unsigned int cnt; +rd_relo(struct outrelo* relo, unsigned int cnt) { OUTREAD(PARTRELO, (char *) relo, (long) cnt * SZ_RELO); @@ -206,9 +195,7 @@ rd_relo(relo, cnt) } void -rd_name(name, cnt) - register struct outname *name; - register unsigned int cnt; +rd_name(struct outname* name, unsigned int cnt) { OUTREAD(PARTNAME, (char *) name, (long) cnt * SZ_NAME); @@ -227,19 +214,15 @@ rd_name(name, cnt) } void -rd_string(addr, len) - char *addr; - long len; +rd_string(char* addr, long len) { - + OUTREAD(PARTCHAR, addr, len); } #ifdef SYMDBUG void -rd_dbug(buf, size) - char *buf; - long size; +rd_dbug(char* buf, long size) { OUTREAD(PARTDBUG, buf, size); } diff --git a/util/led/memory.c b/util/led/memory.c index df4ee99d9..40db843ba 100644 --- a/util/led/memory.c +++ b/util/led/memory.c @@ -473,8 +473,8 @@ free_saved_moduls() * The piece of memory with index `piece' is no longer needed. * We take care that it can be used by compact() later, if needed. */ -dealloc(piece) - register int piece; +void +dealloc(int piece) { /* * Some pieces need their memory throughout the program. @@ -499,9 +499,7 @@ core_alloc(piece, size) return address(piece, off); } -core_free(piece, p) - int piece; - char *p; +void core_free(int piece, char* p) { char *q = address(piece, mems[piece].mem_full); diff --git a/util/led/memory.h b/util/led/memory.h index 79d4c5266..2d2f33063 100644 --- a/util/led/memory.h +++ b/util/led/memory.h @@ -40,3 +40,5 @@ extern struct memory mems[]; extern ind_t core_position; extern ind_t hard_alloc(); extern ind_t alloc(); +extern void dealloc(int piece); +extern void core_free(int piece, char* p); diff --git a/util/led/scan.c b/util/led/scan.c index 1740a14de..d65a2c3cf 100644 --- a/util/led/scan.c +++ b/util/led/scan.c @@ -10,13 +10,17 @@ static char rcsid[] = "$Id$"; #include #include #include -#ifdef SYMDBUG +#include #include #include +#include +#include +#ifdef SYMDBUG #endif /* SYMDBUG */ #include "arch.h" #include "out.h" #include "ranlib.h" +#include "object.h" #include "const.h" #include "assert.h" #include "memory.h" @@ -42,20 +46,21 @@ char *modulname; /* Name of object module. */ long objectsize; #endif /* SYMDBUG */ -static long align(); +static long align(long size); static char *modulbase; -static long modulsize(); -static scan_modul(); -static bool all_alloc(); -static bool direct_alloc(); -static bool indirect_alloc(); -static bool putemitindex(); -static bool putreloindex(); +static long modulsize(struct outhead* head); +static void can_modul(void); +static bool all_alloc(void); +static bool direct_alloc(struct outhead* head); +static bool indirect_alloc(struct outhead* head); +static bool putemitindex(ind_t sectindex, ind_t emitoff, int allopiece); +static bool putreloindex(ind_t relooff, long nrelobytes); #ifdef SYMDBUG -static bool putdbugindex(); +static bool putdbugindex(ind_t dbugoff, long ndbugbytes); #endif /* SYMDBUG */ -static get_indirect(); -static read_modul(); +static void get_indirect(struct outhead* head, struct outsect* sect); +static void read_modul(void); +static void scan_modul(void); /* * Open the file with name `filename' (if necessary) and examine the first @@ -117,16 +122,13 @@ getfile(filename) /* NOTREACHED */ } -/* ARGSUSED */ -closefile(filename) - char *filename; +void closefile(char* filename) { if (passnumber == FIRST || !incore) close(infile); } -get_archive_header(archive_header) - register struct ar_hdr *archive_header; +void get_archive_header(struct ar_hdr* archive_header) { if (passnumber == FIRST || !incore) { rd_arhdr(infile, archive_header); @@ -141,7 +143,7 @@ get_archive_header(archive_header) #endif /* SYMDBUG */ } -get_modul() +void get_modul(void) { if (passnumber == FIRST) { rd_fdopen(infile); @@ -157,8 +159,8 @@ get_modul() * to keep everything in core is abandoned, but we will always put the header, * the section table, and the name and string table into core. */ -static -scan_modul() +static void +scan_modul(void) { bool space; struct outhead *head; @@ -190,7 +192,7 @@ scan_modul() * this was possible. */ static bool -all_alloc() +all_alloc(void) { struct outhead head; extern ind_t hard_alloc(); @@ -287,10 +289,7 @@ indirect_alloc(head) * `emitoff'. */ static bool -putemitindex(sectindex, emitoff, allopiece) - ind_t sectindex; - ind_t emitoff; - int allopiece; +putemitindex(ind_t sectindex, ind_t emitoff, int allopiece) { long flen; ind_t emitindex; @@ -330,9 +329,7 @@ putemitindex(sectindex, emitoff, allopiece) * offset at `relooff'. */ static bool -putreloindex(relooff, nrelobytes) - ind_t relooff; - long nrelobytes; +putreloindex(ind_t relooff, long nrelobytes) { ind_t reloindex; extern ind_t alloc(); @@ -348,9 +345,7 @@ putreloindex(relooff, nrelobytes) * Allocate space for debugging information and put the offset at `dbugoff'. */ static bool -putdbugindex(dbugoff, ndbugbytes) - ind_t relooff; - long ndbugbytes; +putdbugindex(ind_t dbugoff, long ndbugbytes) { ind_t dbugindex; extern ind_t alloc(); @@ -367,12 +362,8 @@ putdbugindex(dbugoff, ndbugbytes) * Compute addresses and read in. Remember that the contents of the sections * and also the relocation table are accessed indirectly. */ -static -get_indirect(head, sect) - struct outhead *head; /* not register! Won't compile on - SCO Xenix 386 if it is! - */ - register struct outsect *sect; +static void +get_indirect(struct outhead* head, struct outsect* sect) { register ind_t *emitindex; register int nsect; @@ -395,8 +386,7 @@ get_indirect(head, sect) /* * Set the file pointer at `pos'. */ -seek(pos) - long pos; +void seek(long pos) { if (passnumber == FIRST || !incore) lseek(infile, pos, 0); @@ -407,8 +397,7 @@ seek(pos) * is not. That's why we do it here. If we don't keep everything in core, * we give the space allocated for a module back. */ -skip_modul(head) - struct outhead *head; +void skip_modul(struct outhead* head) { register ind_t skip = modulsize(head); @@ -425,8 +414,8 @@ skip_modul(head) /* * Read in what we need in pass 2, because we couldn't keep it in core. */ -static -read_modul() +static void +read_modul(void) { struct outhead *head; register struct outsect *sects; @@ -524,8 +513,7 @@ static unsigned short cnt_relos; static unsigned short relind; #define _RELSIZ 64 -startrelo(head) - register struct outhead *head; +void startrelo(struct outhead* head) { ind_t reloindex; @@ -540,8 +528,7 @@ startrelo(head) } } -struct outrelo * -nextrelo() +struct outrelo* nextrelo(void) { static struct outrelo relobuf[_RELSIZ]; @@ -615,8 +602,7 @@ getblk(totalsz, pblksz, sectindex) return (char *) 0; } -endemit(emit) - char *emit; +void endemit(char* emit) { core_free(ALLOMODL, emit); } diff --git a/util/led/scan.h b/util/led/scan.h index 1ceb054f7..b8e55cfa9 100644 --- a/util/led/scan.h +++ b/util/led/scan.h @@ -15,3 +15,12 @@ #ifdef SYMDBUG #define OFF_DBUG(x) (OFF_CHAR(x) + (x).oh_nchar) #endif /* SYMDBUG */ + +extern void seek(long pos); +extern void closefile(char* filename); +extern void get_archive_header(struct ar_hdr* archive_header); +extern void get_modul(void); +extern void skip_modul(struct outhead* head); +extern void startrelo(struct outhead* head); +extern struct outrelo* nextrelo(void); +extern void endemit(char* emit);