36f16b0cb8
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".
129 lines
2.7 KiB
C
129 lines
2.7 KiB
C
/*
|
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
|
*
|
|
*/
|
|
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <ctype.h>
|
|
|
|
#ifndef NORCSID
|
|
static char rcs_id[] = "$Id$" ;
|
|
#endif
|
|
|
|
char *fname = 0 ;
|
|
char dname[200] ;
|
|
char *tail ;
|
|
|
|
FILE *intab ;
|
|
FILE *dmach ;
|
|
|
|
int offset ;
|
|
|
|
void start(const char *) ;
|
|
void stop(int) ;
|
|
void readm(void) ;
|
|
|
|
int main(int argc, char **argv) {
|
|
int i ;
|
|
|
|
start(argv[1]) ;
|
|
for ( i=2 ; i<argc ; i++ ) {
|
|
fname= argv[i] ;
|
|
readm() ;
|
|
}
|
|
stop(argc>2) ;
|
|
return 0 ;
|
|
}
|
|
|
|
void start(const char *dir) {
|
|
tail= dname ;
|
|
while ( *dir ) {
|
|
*tail++ = *dir ++ ;
|
|
}
|
|
if ( tail!=dname ) *tail++= '/' ;
|
|
offset=0 ;
|
|
intab= fopen("intable.c","w");
|
|
dmach= fopen("dmach.c","w");
|
|
if ( intab==NULL || dmach==NULL ) {
|
|
fprintf(stderr,"Couln't create output file(s)\n");
|
|
exit ( 1) ;
|
|
}
|
|
fprintf(dmach,"#include \"dmach.h\"\n\ndmach\tmassoc[] = {\n") ;
|
|
fprintf(intab,"char intable[] = {\n") ;
|
|
}
|
|
|
|
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(const char *file) {
|
|
FILE *fd;
|
|
|
|
strcpy(tail,file) ;
|
|
strcat(tail,"/");
|
|
strcat(tail,"descr");
|
|
if ((fd = fopen(dname,"r")) != NULL) return fd;
|
|
strcpy(tail,"descr/");
|
|
strcat(tail,file);
|
|
return fopen(dname,"r");
|
|
}
|
|
|
|
void
|
|
readm() {
|
|
register int i ;
|
|
register int token ;
|
|
register FILE *in ;
|
|
|
|
in=do_open(fname) ;
|
|
if ( in==NULL ) {
|
|
fprintf(stderr,"Cannot open %s\n",fname) ;
|
|
return ;
|
|
}
|
|
i=0 ;
|
|
fprintf(dmach,"\t{\"%s\",\t%d\t},\n",fname,offset) ;
|
|
fprintf(intab,"\n/* %s */\n\t",fname) ;
|
|
for (;;) {
|
|
token=getc(in) ;
|
|
offset++ ;
|
|
if ( ++i == 10 ) {
|
|
fprintf(intab,"\n\t") ;
|
|
i=0 ;
|
|
} else {
|
|
fprintf(intab," ") ;
|
|
}
|
|
if ( !isascii(token) || !(isprint(token) || isspace(token)) ){
|
|
if ( token!=EOF ) {
|
|
fprintf(stderr,"warning: non-ascii in %s\n",fname) ;
|
|
fprintf(intab,"%4d,",token) ;
|
|
} else {
|
|
fprintf(intab," 0,") ;
|
|
break ;
|
|
}
|
|
} else if ( isprint(token) ) {
|
|
switch ( token ) {
|
|
case '\'': fprintf(intab,"'\\''") ; break ;
|
|
case '\\': fprintf(intab,"'\\\\'") ; break ;
|
|
default: fprintf(intab," '%c'",token) ; break ;
|
|
}
|
|
} else switch ( token ) {
|
|
case '\n' : fprintf(intab,"'\\n'") ; break ;
|
|
case '\t' : fprintf(intab,"'\\t'") ; break ;
|
|
case '\r' : fprintf(intab,"'\\r'") ; break ;
|
|
case '\f' : fprintf(intab,"'\\f'") ; break ;
|
|
case ' ' : fprintf(intab," ' '") ; break ;
|
|
default : fprintf(stderr,"warning: unrec. %d\n",
|
|
token) ;
|
|
fprintf(intab,"%4d",token) ;
|
|
break ;
|
|
}
|
|
fprintf(intab,",") ;
|
|
}
|
|
fclose(in) ;
|
|
}
|