Cut down some clang warnings

Edit C code to reduce warnings from clang.  Most warnings are for
implicit declarations of functions, but some warnings want me to add
parentheses or curly braces, or to cast arguments for printf().

Make a few other changes, like declaring float_cst() in h/con_float to
be static, and using C99 bool in ego/ra/makeitems.c and
ego/share/makecldef.c.  Such changes don't silence warnings; I make
such changes while I silence warnings in the same file.  In
float_cst(), rename parameter `str` to `float_str`, so it doesn't
share a name with the global variable `str`.

Remove `const` from `newmodule(const char *)` in mach/proto/as to
silence a warning.  I wrongly added the `const` in d347207.

For warnings about implicit declarations of functions, the fix is to
declare the function before calling it.  For example, my OpenBSD
system needs <sys/wait.h> to declare wait().

In util/int, add "whatever.h" to declare more functions.  Remove old
declarations from "mem.h", to prefer the newer declarations of the
same functions in "data.h" and "stack.h".
This commit is contained in:
George Koehler 2019-10-23 16:06:36 -04:00
parent 8bb395b147
commit 36f16b0cb8
43 changed files with 189 additions and 127 deletions

View file

@ -97,8 +97,7 @@ int sz;
#include <ctype.h>
#include <flt_arith.h>
int float_cst(str, sz, buf) char *str, *buf;
int sz;
static int float_cst(const char *float_str, int sz, char *buf)
{
int overflow = 0;
flt_arith e;
@ -107,7 +106,7 @@ int sz;
{
return 1;
}
flt_str2flt(str, &e);
flt_str2flt(float_str, &e);
#ifdef IEEEFLOAT
if (sz == 4)
{
@ -115,7 +114,7 @@ int sz;
#ifdef PDPFLOAT
e.flt_exp += 129;
#else
e.flt_exp += 127;
e.flt_exp += 127;
#endif
if (e.flt_mantissa.flt_h_32 == 0)
e.flt_exp = 0;

View file

@ -25,7 +25,7 @@ Something very wrong here!
#define SYNTAX_68020 1
#endif
/* #define FANCY_MODES 1
/* #define FANCY_MODES 1 */
/* On the M68020, there are some real fancy addressing modes.
Their use makes the code a bit shorter, but also much slower.
The FANCY_MODES #define enables the use of these addressing

View file

@ -106,7 +106,7 @@ extern int curr_token;
int yyparse(void);
/* comm4.c */
void stop(void);
void newmodule(const char *);
void newmodule(char *);
/* comm5.c */
int yylex(void);
void putval(int);

View file

@ -35,6 +35,10 @@ void stop(void) {
exit(nerrors != 0);
}
static void stop_on_signal(int sig) {
stop();
}
int
main(int argc, char **argv)
{
@ -54,9 +58,9 @@ main(int argc, char **argv)
}
progname = *argv++; argc--;
for (p = sigs; i = *p++; )
for (p = sigs; (i = *p++) != 0; )
if (signal(i, SIG_IGN) != SIG_IGN)
signal(i, stop);
signal(i, stop_on_signal);
for (i = 0; i < argc; i++) {
p = argv[i];
if (*p++ != '-')
@ -433,7 +437,7 @@ pass_23(int n)
}
void
newmodule(const char *s)
newmodule(char *s)
{
static char nmbuf[STRINGMAX];

View file

@ -78,7 +78,7 @@ int flt_cmp(flt_arith *e1, flt_arith *e2);
* digits. They may not both be missing. The decimal point, the e and the
* exponent may be missing.
*/
void flt_str2flt(char *s, flt_arith *e);
void flt_str2flt(const char *s, flt_arith *e);
/** Converts the number indicated by `e` into a string, in a scientific
* notation acceptable for EM. The result is stored in `buf`. At most
* `bufsize` characters are stored. The maximum length needed is

View file

@ -216,7 +216,7 @@ static void add_exponent(register flt_arith *e, int exp)
flt_status = status;
}
void flt_str2flt(char *s, flt_arith *e)
void flt_str2flt(const char *s, flt_arith *e)
{
register int c;
int dotseen = 0;

View file

@ -4,6 +4,7 @@
*/
/* $Id$ */
#include <unistd.h>
#include "system.h"
int

View file

@ -64,6 +64,9 @@ typedef struct
/* Own routines */
/* files.h */
extern void rmtemps(void);
/* rmach.c */
extern void setlist(char*);
@ -80,6 +83,7 @@ extern void fatal(const char*, ...);
extern void vprint(const char*, ...);
extern void fuerror(const char*, ...);
extern void werror(const char*, ...);
extern void error(const char*, ...);
extern void quit(int);
extern char* keeps(const char*);
#define throws(str) free(str)

View file

@ -169,7 +169,7 @@ static void varinit(void)
register char* envstr;
extern char* em_dir;
if (envstr = getenv("ACKDIR"))
if ((envstr = getenv("ACKDIR")) != NULL)
{
em_dir = keeps(envstr);
}

View file

@ -22,10 +22,12 @@ FILE *dmach ;
int offset ;
void readm();
void start(const char *) ;
void stop(int) ;
void readm(void) ;
main(argc,argv) char **argv ; {
register i ;
int main(int argc, char **argv) {
int i ;
start(argv[1]) ;
for ( i=2 ; i<argc ; i++ ) {
@ -36,7 +38,7 @@ main(argc,argv) char **argv ; {
return 0 ;
}
start(dir) char *dir ; {
void start(const char *dir) {
tail= dname ;
while ( *dir ) {
*tail++ = *dir ++ ;
@ -53,14 +55,14 @@ start(dir) char *dir ; {
fprintf(intab,"char intable[] = {\n") ;
}
stop(filled) {
void stop(int filled) {
fprintf(dmach,"\t{\"\",\t-1\t}\n} ;\n") ;
if ( !filled ) fprintf(intab,"\t0\n") ;
fprintf(intab,"\n} ;\n") ;
fclose(dmach); fclose(intab) ;
}
FILE *do_open(file) char *file ; {
FILE *do_open(const char *file) {
FILE *fd;
strcpy(tail,file) ;
@ -100,7 +102,7 @@ readm() {
fprintf(stderr,"warning: non-ascii in %s\n",fname) ;
fprintf(intab,"%4d,",token) ;
} else {
fprintf(intab," 0,",token) ;
fprintf(intab," 0,") ;
break ;
}
} else if ( isprint(token) ) {

View file

@ -4,6 +4,7 @@
*
*/
#include <sys/wait.h>
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>

View file

@ -113,12 +113,12 @@ static void try(list_elem *f_scan, const char *suffix) {
*/
register trf *sneak ;
sneak= trafo ;
while( sneak=sneak->t_next ) {
while( (sneak=sneak->t_next) ) {
sneak->t_scan=YES ;
}
scan_found() ;
sneak= trafo ;
while( sneak=sneak->t_next ) {
while( (sneak=sneak->t_next) ) {
sneak->t_scan=NO ;
}
return ;

View file

@ -317,7 +317,8 @@ static growstring scanvars(const char* line)
{
case A_VAR:
gr_add(&name, 0);
if (tr = getvar(gr_start(name)))
tr = getvar(gr_start(name));
if (tr != NULL)
{
while (*tr)
{
@ -333,7 +334,8 @@ static growstring scanvars(const char* line)
break;
case C_VAR:
gr_add(&name, 0);
if (tr = getvar(gr_start(name)))
tr = getvar(gr_start(name));
if (tr != NULL)
{
while (*tr)
{

View file

@ -50,7 +50,6 @@ int setfiles(trf *);
void disc_files(trf *);
void disc_inputs(trf *);
void rmfile(path *);
void rmtemps(void);
void add_input(path *, trf *);
/* run.c */

View file

@ -785,7 +785,7 @@ static void verbose(void)
fprintf(stderr, "Sets %d(%d)\n", nmachsets, MAXSETS);
fprintf(stderr, "Tokeninstances %d(%d)\n", narinstance, MAXINSTANCE);
fprintf(stderr, "Strings %d(%d)\n", ncodestrings, MAXSTRINGS);
fprintf(stderr, "Enodes %d(%d)\n", lastnode - nodes, MAXNODES);
fprintf(stderr, "Enodes %d(%d)\n", (int)(lastnode - nodes), MAXNODES);
fprintf(stderr, "Patbytes %d(%d)\n", npatbytes, MAXPATTERN);
}

View file

@ -4,6 +4,7 @@
optimizer itself one day ...
*/
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
@ -121,14 +122,15 @@ cleanup()
}
/*VARARGS1*/
static void
fatal(s, s2) char* s;
char* s2;
static void fatal(const char *s, ...)
{
/* A fatal error occurred; exit gracefully */
va_list ap;
va_start(ap, s);
fprint(STDERR, "%s: ", prog_name);
fprint(STDERR, s, s2);
doprnt(STDERR, s, ap);
fprint(STDERR, "\n");
cleanup();
sys_stop(S_EXIT);

View file

@ -3,7 +3,8 @@
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@ -20,16 +21,20 @@
*/
#define TRUE 1
#define FALSE 0
void error(const char *s)
{
fprintf(stderr,"%s\n",s);
exit(-1);
}
convert(mnemfile,itemfile)
FILE *mnemfile, *itemfile;
void convert(FILE *mnemfile, FILE *itemfile)
{
char mnem1[20], mnem2[20],def[20],itemtype[20];
int newcl,opc,index;
int opc,index;
bool newcl;
newcl = TRUE;
newcl = true;
printf("struct item_descr itemtab[] = {\n");
for (;;) {
fscanf(mnemfile,"%19s%19s%d",def,mnem1,&opc);
@ -47,28 +52,17 @@ convert(mnemfile,itemfile)
* it has no type.
*/
printf("{NO_ITEM,0}, /* %s */\n", mnem1);
newcl = FALSE;
newcl = false;
} else {
printf("{%s,%d}, /* %s */\n",itemtype,index, mnem1);
newcl = TRUE;
newcl = true;
}
}
printf("};\n");
}
error(s)
char *s;
{
fprintf(stderr,"%s\n",s);
exit(-1);
}
main(argc,argv)
int argc;
char *argv[];
int main(int argc, char *argv[])
{
FILE *f1,*f2;

View file

@ -136,7 +136,7 @@ STATIC lset getlset(void *(*p)(short))
int id;
s = Lempty_set();
while (id = getshort()) {
while ((id = getshort()) != 0) {
Ladd( (*p) (id), &s);
}
return s;

View file

@ -3,7 +3,8 @@
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@ -23,16 +24,20 @@
*/
#define TRUE 1
#define FALSE 0
void error(const char *s)
{
fprintf(stderr,"%s\n",s);
exit(-1);
}
convert(mnemfile,classfile)
FILE *mnemfile, *classfile;
void convert(FILE *mnemfile, FILE *classfile)
{
char mnem1[10], mnem2[10],def[10];
int src,res,newcl,opc;
int src,res,opc;
bool newcl;
newcl = TRUE;
newcl = true;
printf("struct class classtab[] = {\n");
printf("\tNOCLASS,\tNOCLASS,\n");
/* EM mnemonics start at 1, arrays in C at 0 */
@ -52,29 +57,18 @@ convert(mnemfile,classfile)
* it has no class.
*/
printf("\tNOCLASS,\tNOCLASS,\n");
newcl = FALSE;
newcl = false;
} else {
printf("\tCLASS%d,\t\tCLASS%d,\n",src,res);
/* print a line like "CLASS8, CLASS1," */
newcl = TRUE;
newcl = true;
}
}
printf("};\n");
}
error(s)
char *s;
{
fprintf(stderr,"%s\n",s);
exit(-1);
}
main(argc,argv)
int argc;
char *argv[];
int main(int argc, char *argv[])
{
FILE *f1,*f2;

View file

@ -9,5 +9,10 @@ sed '
s/.*"/#define /
'
echo
echo 'void init_wmsg(void);'
echo 'void do_warn(int, int, const char *);'
echo 'void set_wmask(int);'
echo
echo '#define warning(n) do_warn((n), __LINE__, __FILE__)'

View file

@ -9,6 +9,7 @@
#include "memdirect.h"
#include "proctab.h"
#include "alloc.h"
#include "whatever.h"
PRIVATE ptr TC;
PRIVATE void do_pr_instr(unsigned int);

View file

@ -22,6 +22,7 @@
#include "rsb.h"
#include "io.h"
#include "linfil.h"
#include "whatever.h"
extern int running; /* from main.c */
@ -32,13 +33,9 @@ ptr FIL;
PRIVATE void index_jump(size), range_check(size), search_jump(size);
PRIVATE void gto(ptr);
void putLIN(long);
void putFIL(ptr);
#define asp(l) newSP(SP + arg_f(l))
extern void moncall(void);
/** ASP f: Adjust the stack pointer by f */
void DoASP(register long l)
{

View file

@ -19,12 +19,12 @@
#include "fra.h"
#include "rsb.h"
#include "linfil.h"
#include "whatever.h"
extern int running; /* from main.c */
/* Forward declarations */
PRIVATE void lfr(size), ret(size);
void call(long, int);
/** CAI -: Call procedure (procedure identifier on stack) */
void DoCAI(void) /* proc identifier on top of stack */

View file

@ -21,10 +21,12 @@
#include "alloc.h"
#include "warn.h"
#include "mem.h"
#include "m_sigtrp.h"
#include "io.h"
#include "shadow.h"
#include "trap.h"
#include "read.h"
#include "whatever.h"
/****************************************************************

View file

@ -16,6 +16,7 @@
#include "warn.h"
#include "log.h"
#include "linfil.h"
#include "whatever.h"
extern int running; /* from main.c */
extern char *prog_name; /* from main.c */

View file

@ -2,3 +2,7 @@
#define LOGGING 1 /* Includes logging when defined */
#ifdef LOGGING
/* warn.c */
void warningcont(int);
#endif /* LOGGING */

View file

@ -9,6 +9,7 @@
#include "global.h"
#include "mem.h"
#include "warn.h"
#include "whatever.h"
#ifdef WANT_SGTTY
#include <sgtty.h>
@ -42,9 +43,7 @@
* (0 for success, -1 for failure) *
***********************************************************************/
int do_ioctl(fd, req, addr)
int fd, req;
ptr addr;
int do_ioctl(int fd, int req, ptr addr)
{
register long e;
#ifdef WANT_SGTTY

View file

@ -12,6 +12,7 @@
#include "trap.h"
#include "m_sigtrp.h"
#include "io.h"
#include "whatever.h"
/*************************** SIGTRP *************************************
* The monitor call "sigtrp()" is handled by "do_sigtrp()". The first *

View file

@ -23,6 +23,7 @@
#include "opcode.h"
#include "m_sigtrp.h"
#include "rsb.h"
#include "whatever.h"
char mess_file[64] = "int.mess"; /* name of message file */
@ -39,12 +40,6 @@ extern long inr; /* from log.c */
PRIVATE char *dflt_av[] = {"e.out", 0}; /* default arguments */
/* External definitions - too lazy to create a header file for each. */
extern void init(int , char **);
extern void disassemble(void);
extern void tally(void);
extern void out_tally(void);
/** Check dynamically that the interpreter can run on the target machine. */
static void check_requirements(char *name)
{

View file

@ -4,6 +4,7 @@
/* $Id$ */
#include "data.h"
#include "stack.h"
/******** Memory address & location defines ********/
@ -65,12 +66,3 @@
#define st_inc(n) newSP(SP - (n)) /* stack grows */
#define st_dec(n) newSP(SP + (n)) /* stack shrinks */
/******** Function return types ********/
extern ptr st_ldip(), dt_ldip();
extern ptr st_lddp(), dt_lddp(), dppop();
extern long st_lds(), st_ldsw(), dt_lds(), dt_ldsw(), spop(), swpop(), wpop();
extern unsigned long st_ldu(), st_lduw(), dt_ldu(), dt_lduw(), upop(), uwpop();

View file

@ -5,16 +5,24 @@
/* $Id$ */
#include "sysidf.h"
#include "io.h"
#include "log.h"
#include "alloc.h"
#include "shadow.h"
#include "m_sigtrp.h"
#include "monstruct.h"
#include "whatever.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/times.h>
#include <sys/wait.h>
#include <errno.h>
#include <signal.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <utime.h>
extern int running; /* from main.c */
extern int fd_limit; /* from io.c */
@ -1091,7 +1099,7 @@ PRIVATE int vec(n1, n2, addr, vecvec)
/* copy the elements */
for ( cp1 = buf[n1], n_ent = 0, p = addr;
ldp = mem_lddp(p);
(ldp = mem_lddp(p)) != 0;
p += psize, n_ent++
) {
if (!savestr(n2, ldp)) {
@ -1099,7 +1107,7 @@ PRIVATE int vec(n1, n2, addr, vecvec)
}
(*vecvec)[n_ent] = cp1;
cp2 = buf[n2];
while (*cp1++ = *cp2++) {
while ((*cp1++ = *cp2++) != '\0') {
/* nothing */
}
}
@ -1107,9 +1115,7 @@ PRIVATE int vec(n1, n2, addr, vecvec)
return 1;
}
int memfault(addr, length)
ptr addr;
size length;
int memfault(ptr addr, size length)
{
/* centralizes (almost) all memory access tests in MON */
if (!is_in_mem(addr, length)) {
@ -1119,17 +1125,14 @@ int memfault(addr, length)
return 0;
}
efault(wrn)
int wrn; /* warning number */
void efault(int wrn /* warning number */)
{
warning(wrn);
errno = 14; /* EFAULT */
}
einval(wrn)
int wrn; /* warning number */
void einval(int wrn /* warning number */)
{
warning(wrn);
errno = 22; /* EINVAL */
}

View file

@ -9,6 +9,7 @@
#include "global.h"
#include "mem.h"
#include "monstruct.h"
#include "whatever.h"
#include <sys/types.h>
#include <sys/stat.h>
@ -42,9 +43,7 @@ PRIVATE mem_stfld(addr, offset, length, val)
mem_stn(addr + offset, val, length);
}
int stat2mem(addr, statb)
ptr addr;
struct stat *statb;
int stat2mem(ptr addr, struct stat *statb)
{
if (memfault(addr, V7st_sz))
return 0;
@ -62,9 +61,7 @@ int stat2mem(addr, statb)
return 1;
}
int timeb2mem(addr, timebb)
ptr addr;
struct timeb *timebb;
int timeb2mem(ptr addr, struct timeb *timebb)
{
if (memfault(addr, V7tb_sz))
return 0;
@ -75,9 +72,7 @@ int timeb2mem(addr, timebb)
return 1;
}
int tms2mem(addr, tmsb)
ptr addr;
struct tms *tmsb;
int tms2mem(ptr addr, struct tms *tmsb)
{
if (memfault(addr, V7tms_sz))
return 0;

View file

@ -12,6 +12,8 @@
/* $Id$ */
#include "global.h" /* ptr */
/* struct stat */
#define V7st_dev 0L, 2L /* short */
#define V7st_ino 2L, 2L /* unsigned short */
@ -67,3 +69,10 @@
#define V7t_lnextc 5L, 1L /* char */
#define V7t_sz_ltch 6L
struct stat;
struct timeb;
struct tms;
int stat2mem(ptr, struct stat *);
int timeb2mem(ptr, struct timeb *);
int tms2mem(ptr, struct tms *);

View file

@ -14,6 +14,7 @@
#include "segment.h"
#include "text.h"
#include "warn.h"
#include "whatever.h"
/* offsets to be added to a local base */
int rsb_rsbcode;

View file

@ -9,6 +9,7 @@
#include "global.h"
#include "linfil.h"
#include "alloc.h"
#include "whatever.h"
struct line_tally
{ /* one for each line */

View file

@ -18,6 +18,7 @@
#include "linfil.h"
#include "rsb.h"
#include "fra.h"
#include "whatever.h"
extern jmp_buf trapbuf; /* from main.c */

View file

@ -94,7 +94,7 @@ PRIVATE long count_wrn(int nr)
PRIVATE int latest_warning_printed; /* set if ... */
/*ARGSUSED*/
void do_warn(int nr, int L, char *F)
void do_warn(int nr, int L, const char *F)
{
latest_warning_printed = 0;
if (nr < WMSG) {

43
util/int/whatever.h Normal file
View file

@ -0,0 +1,43 @@
/* Copyright (c) 2019 ACK Project.
* See the copyright notice in the ACK home directory,
* in the file "Copyright".
*
* Created on: 2019-10-23
*
*/
#ifndef WHATEVER_H_
#define WHATEVER_H_
#include "global.h" /* ptr, size */
/*
* This header is for _whatever_ isn't in another header.
*/
/* disassemble.c */
void disassemble(void);
/* do_misc.c */
void putLIN(long);
void putFIL(ptr);
/* do_proc.c */
void call(long, int);
/* init.c */
void init(int , char **);
/* m_ioctl.c */
int do_ioctl(int, int, ptr);
/* moncalls.c */
void moncall(void);
int memfault(ptr, size);
void efault(int);
void einval(int);
/* tally.c */
void tally(void);
void out_tally(void);
#endif /* WHATEVER_H_ */

View file

@ -11,7 +11,7 @@ g/^#/d
.r tokendefs
a
enterkeyw() {
void enterkeyw(void) {
register symbol *sy_p;
.

View file

@ -38,8 +38,23 @@ extern int maxtokensize;
extern int nprocargs, maxprocargs;
extern int use_tes;
extern void error(const char* s, ...);
/* genenerated files */
extern void enterkeyw(void);
extern int yyparse(void);
/* emlookup.c */
extern void initemhash(void);
/* error.c */
extern void fatal(const char* s, ...);
extern void error(const char* s, ...);
extern int tabovf(char *string);
extern int strlookup(char *str);
/* output.c */
extern void errorexit(void);
extern void initio(void);
extern void finishio(void);
extern void statistics(void);
/* strlookup.c */
extern int strlookup(char *str);

View file

@ -174,11 +174,12 @@ iocc_t descr_iocc(char *ident)
default:
assert(0);
case TYPINT:
if (tp->tk_att[i].ta_type != -1)
if (tp->tk_att[i].ta_type != -1) {
if (tp->tk_att[i].ta_type == -2)
arexp[i] = iextoaddr(arexp[i]);
else
typerr++;
}
break;
case TYPBOOL:
typerr++;

View file

@ -12,16 +12,10 @@ static char rcsid[] = "$Id$";
#include "hall.h"
#include "expr.h"
#include "extern.h"
#include "lookup.h"
char *filename;
extern void enterkeyw(void);
extern void initio(void);
extern void initemhash(void);
extern void finishio(void);
extern void statistics(void);
extern int yyparse(void);
int main(int argc, char **argv)
{
extern int nerrors;

View file

@ -349,7 +349,7 @@ void printnodes(void)
printf("};\n\nshort lastind = %d;\n\nexpr_t enodes[] = {\n",prevind);
for (p=nodes;p<lastnode;p++)
printf("/* %3d */\t{%3d,%6u,%6u},\n",
p-nodes,p->ex_operator,p->ex_lnode,p->ex_rnode);
(int)(p-nodes),p->ex_operator,p->ex_lnode,p->ex_rnode);
printf("};\n\niarg_t iargs[%d];\n", (maxpatlen>0 ? maxpatlen : 1));
if (patid[0])
printf("static char rcsid[] = %s;\n",patid);