diff --new-file -ur orig/bcc/Makefile bcc/Makefile --- orig/bcc/Makefile Tue Jul 25 19:26:43 1995 +++ bcc/Makefile Mon Jan 8 09:09:00 1996 @@ -1,27 +1,48 @@ # -# Build bcc +# bcc Makefile +# $Id$ # +WFLAGS=-Wall +WALL =-Wall -Wtraditional -Wshadow -Wid-clash-14 -Wpointer-arith \ + -Wcast-qual -Wcast-align -Wconversion -Waggregate-return \ + -Wstrict-prototypes -Wmissing-prototypes -Wredundant-decls \ + -Wnested-externs -Winline + +CFLAGS = $(WFLAGS) -fno-strength-reduce -O2 \ + -DLOCALPREFIX="\"/usr\"" -DANSI_SUPPORT \ + -DDEFARCH=0 \ + -b i486-linuxaout +# Uncomment below for Electric Fence malloc debugger. +#LDFLAGS = -L/usr/local/lib -lefence +LDFLAGS = -N -s -static +CC = gcc +OBJS = bcc-cc1.o codefrag.o debug.o declare.o express.o exptree.o floatop.o \ + function.o gencode.o genloads.o glogcode.o hardop.o input.o label.o \ + loadexp.o longop.o output.o preproc.o preserve.o scan.o softop.o \ + state.o table.o type.o assign.o + + +all: bcc bcc-cc1 + +bcc: bcc.o + $(CC) $(CFLAGS) bcc.o $(LDFLAGS) -o $@ + +bcc09: bcc.o + $(CC) -DMC6809 $(CFLAGS) bcc.o $(LDFLAGS) -o $@ -all: bcc bcc-cc1 +ccc: bcc.o + $(CC) -DCCC $(CFLAGS bcc.o ) $(LDFLAGS) -o $@ -CFLAGS = -DLOCALPREFIX="\"/usr/local\"" -O2 +bcc-cc1: $(OBJS) + $(CC) $(CFLAGS) $(LDFLAGS) $(OBJS) -o bcc-cc1 -SRCS =assign.c declare.c gencode.c label.c preserve.c type.c \ - bcc-cc1.c express.c genloads.c loadexp.c scan.c \ - exptree.c glogcode.c longop.c softop.c codefrag.c \ - floatop.c hardop.c output.c state.c debug.c function.c \ - input.c preproc.c table.c +clean: + rm -f bcc bcc-cc1 bcc09 ccc bcc.o $(OBJS) -OBJS =assign.o declare.o gencode.o label.o preserve.o type.o \ - bcc-cc1.o express.o genloads.o loadexp.o scan.o \ - exptree.o glogcode.o longop.o softop.o codefrag.o \ - floatop.o hardop.o output.o state.o debug.o function.o \ - input.o preproc.o table.o -bcc: bcc.c - $(CC) $(CFLAGS) -o bcc bcc.c -bcc-cc1: $(OBJS) - $(CC) $(CFLAGS) -o bcc-cc1 $(OBJS) + + + Only in orig/bcc: Makefile.orig diff --new-file -ur orig/bcc/assign.c bcc/assign.c --- orig/bcc/assign.c Mon Jun 21 23:51:12 1993 +++ bcc/assign.c Sat Dec 30 09:30:40 1995 @@ -26,23 +26,23 @@ if (target->type->constructor & (ARRAY | FUNCTION) || target->flags == TEMP || target->flags == (LABELLED | STRING) || - target->indcount == 0 && target->flags != REGVAR) + (target->indcount == 0 && target->flags != REGVAR)) { bugerror("botched lvalue"); return; } if (source->storage != target->storage - || source->indcount != target->indcount - || source->level != target->level - || source->offset.offi != target->offset.offi /* kludge union cmp */ - || source->type != target->type - || (source->storage & (LOCAL | GLOBAL) - || source->level == OFFKLUDGELEVEL) - && ((source->flags ^ target->flags) & LABELLED - || source->flags & LABELLED - && source->name.label != target->name.label - || !(source->flags & LABELLED) - && strcmp(source->name.namep, target->name.namep) != 0)) + || source->indcount != target->indcount + || source->level != target->level + || source->offset.offi != target->offset.offi /* kludge union cmp */ + || source->type != target->type + || ((source->storage & (LOCAL | GLOBAL) + || source->level == OFFKLUDGELEVEL) + && ((source->flags ^ target->flags) & LABELLED + || (source->flags & LABELLED + && source->name.label != target->name.label) + || (!(source->flags & LABELLED) + && strcmp(source->name.namep, target->name.namep) != 0)))) { tscalar = target->type->scalar; if (tscalar & CHAR && source->storage == CONSTANT) @@ -210,7 +210,7 @@ store_pt targreg; if (type->constructor & (ARRAY | FUNCTION) - || type->constructor & STRUCTU && target->type != type) + || (type->constructor & STRUCTU && target->type != type)) { bugerror("botched implicit cast"); return; @@ -262,7 +262,7 @@ target->storage = BREG; } } - else if (newscalar & (SHORT | INT | LONG) && !(newscalar & DLONG) + else if ((newscalar & (SHORT | INT | LONG) && !(newscalar & DLONG)) || type->constructor & POINTER) { if (oldscalar & RSCALAR) diff --new-file -ur orig/bcc/bcc.c bcc/bcc.c --- orig/bcc/bcc.c Tue Jul 25 19:17:57 1995 +++ bcc/bcc.c Mon Jan 8 15:20:47 1996 @@ -14,14 +14,12 @@ #define FALSE 0 #define FORWARD static -#ifndef NULL -#define NULL 0 -#endif +#define NUL_PTR ((void*)0) #define PRIVATE static #define PUBLIC #define TRUE 1 -#if __STDC__ +#ifdef __STDC__ #define P(x) x #else #define P(x) () @@ -37,10 +35,17 @@ #define CRT0 "crt0.o" #define GCC "gcc" #define LD "ld86" +#ifdef ANSI_SUPPORT +#define UNPROTO "unprotoize" +#define CP "/bin/cp" +#endif #define STANDARD_CRT0_0_PREFIX LOCALPREFIX "/lib/bcc/i86/" #define STANDARD_CRT0_3_PREFIX LOCALPREFIX "/lib/bcc/i386/" #define STANDARD_EXEC_PREFIX LOCALPREFIX "/lib/bcc/" #define STANDARD_EXEC_PREFIX_2 LOCALPREFIX "/bin/" +#define DEFAULT_INCLUDE "-I" LOCALPREFIX "/include" +#define DEFAULT_LIBDIR0 "-L" LOCALPREFIX "/lib/bcc/i86/" +#define DEFAULT_LIBDIR3 "-L" LOCALPREFIX "/lib/bcc/i386/" #ifdef CCC #undef BCC86 @@ -88,6 +93,9 @@ PRIVATE struct arg_s asargs = { AS, }; PRIVATE struct arg_s ccargs = { CC1, CC1_MINUS_O_BROKEN, }; PRIVATE struct arg_s cppargs = { CPP, }; +#ifdef ANSI_SUPPORT +PRIVATE struct arg_s unprotoargs = { UNPROTO, }; +#endif #ifdef STANDARD_CRT0_PREFIX PRIVATE struct prefix_s crt0_prefix = { STANDARD_CRT0_PREFIX, }; #endif @@ -137,7 +145,7 @@ FORWARD char *fixpath P((char *path, struct prefix_s *prefix, int mode)); FORWARD void killtemps P((void)); FORWARD void *my_malloc P((unsigned size, char *where)); -FORWARD char *my_mktemp P((void)); +FORWARD char *my_mktemp P((int c_extension)); FORWARD void my_unlink P((char *name)); FORWARD void outofmemory P((char *where)); FORWARD int run P((char *in_name, char *out_name, struct arg_s *argp)); @@ -157,15 +165,25 @@ char **argv; { char *arg; + int add_default_inc = 1; + int add_default_lib = 1; int argcount = argc; bool_T *argdone = my_malloc((unsigned) argc * sizeof *argdone, "argdone"); bool_T as_only = FALSE; char *basename; #ifdef BCC86 +#ifdef DEFARCH + bool_T bits32 = (DEFARCH != 0); +#else bool_T bits32 = sizeof (char *) >= 4; +#endif char *bits_arg; #endif bool_T cc_only = FALSE; +#ifdef ANSI_SUPPORT + bool_T ansi_pass = FALSE; + bool_T quiet_ansi = TRUE; +#endif #ifdef CCC bool_T cpp_pass = TRUE; #else @@ -178,7 +196,7 @@ bool_T echo = FALSE; unsigned errcount = 0; char ext; - char *f_out = NULL; + char *f_out = NUL_PTR; bool_T float_emulation = FALSE; #ifdef BAS86 bool_T gnu_objects = FALSE; @@ -269,7 +287,7 @@ } else { - if (f_out != NULL) + if (f_out != NUL_PTR) show_who("more than one output file\n"); f_out = *++argv; *++argdone = TRUE; @@ -282,6 +300,15 @@ break; case 'v': ++verbosity; +#ifdef ANSI_SUPPORT + quiet_ansi=FALSE; +#endif + break; + case 'I': + add_default_inc = 0; + break; + case 'L': + add_default_lib = 0; break; default: *argdone = FALSE; @@ -290,6 +317,20 @@ else if (arg[0] == '-') switch (arg[1]) { +#ifdef ANSI_SUPPORT + case 'a': + if (!strcmp(arg, "-ansi")) + { + ansi_pass=TRUE; +#if 0 +#ifndef CCC + addarg(&ccargs, "-D__STDC__=1"); +#endif + addarg(&cppargs, "-D__STDC__=1"); +#endif + } + break; +#endif case 'A': addarg(&asargs, arg + 2); break; @@ -307,9 +348,12 @@ #endif addarg(&cppargs, arg); break; - case 'L': + case 'X': addarg(&ldargs, arg + 2); break; + case 'L': + addarg(&ldargs, arg); + break; case 'P': addarg(&cppargs, arg + 2); break; @@ -348,7 +392,7 @@ ++errcount; show_who("more than 1 option from -E -P -S -c\n"); } - if (f_out != NULL && ncisfiles > 1) + if (f_out != NUL_PTR && ncisfiles > 1) { ++errcount; show_who("cannot have more than 1 input with non-linked output\n"); @@ -362,8 +406,24 @@ if (errcount != 0) exit(1); - if ((temp = getenv("BCC_EXEC_PREFIX")) != NULL) + if ((temp = getenv("BCC_EXEC_PREFIX")) != NUL_PTR) addprefix(&exec_prefix, temp); + if( add_default_inc ) + { +#ifndef CCC + addarg(&ccargs, DEFAULT_INCLUDE); +#endif + addarg(&cppargs, DEFAULT_INCLUDE); + } + if( add_default_lib ) + { +#ifdef BCC86 + if( bits32 ) + addarg(&ldargs, DEFAULT_LIBDIR3); + else +#endif + addarg(&ldargs, DEFAULT_LIBDIR0); + } addprefix(&exec_prefix, STANDARD_EXEC_PREFIX); addprefix(&exec_prefix, STANDARD_EXEC_PREFIX_2); cppargs.prog = fixpath(cppargs.prog, &exec_prefix, X_OK); @@ -371,7 +431,10 @@ asargs.prog = fixpath(asargs.prog, &exec_prefix, X_OK); ldargs.prog = fixpath(ldargs.prog, &exec_prefix, X_OK); ldrargs.prog = fixpath(ldrargs.prog, &exec_prefix, X_OK); - if (tmpdir == NULL && (tmpdir = getenv("TMPDIR")) == NULL) +#ifdef ANSI_SUPPORT + unprotoargs.prog=fixpath(unprotoargs.prog, &exec_prefix, X_OK); +#endif + if (tmpdir == NUL_PTR && (tmpdir = getenv("TMPDIR")) == NUL_PTR) tmpdir = "/tmp"; if (prep_only && !prep_line_numbers) @@ -395,7 +458,8 @@ { addarg(&ldargs, bits_arg); addarg(&ldrargs, bits_arg); - addarg(&ldargs, crt0); + /* addarg(&ldargs, crt0);*/ + addarg(&ldargs, "-C0"); } #endif /* BAS86 */ #endif /* BCC86 */ @@ -423,19 +487,42 @@ writes(arg); writesn(":"); } - if ((basename = strrchr(arg, DIRCHAR)) == NULL) + if ((basename = strrchr(arg, DIRCHAR)) == NUL_PTR) basename = arg; else ++basename; in_name = arg; if (ext == 'c') { +#ifdef ANSI_SUPPORT + /* If this was done between CPP and CC1 then + * we could define __STDC__ + */ + if (ansi_pass) + { + char *old_tmpdir; + struct arg_s cpargs = { CP, TRUE, }; + + old_tmpdir=tmpdir; + tmpdir="."; + out_name=my_mktemp(TRUE); + tmpdir=old_tmpdir; + run(in_name, out_name, &cpargs); + + addarg(&unprotoargs, out_name); + addarg(&unprotoargs, "-N"); + if (quiet_ansi) + addarg(&unprotoargs, "-q"); + run(NUL_PTR, NUL_PTR, &unprotoargs); + in_name=out_name; + } +#endif if (cpp_pass) { if (prep_only) out_name = f_out; else - out_name = my_mktemp(); + out_name = my_mktemp(FALSE); if (run(in_name, out_name, &cppargs) != 0) continue; in_name = out_name; @@ -448,7 +535,7 @@ continue; if (cc_only) { - if (f_out != NULL) + if (f_out != NUL_PTR) out_name = f_out; else { @@ -457,7 +544,7 @@ } } else - out_name = my_mktemp(); + out_name = my_mktemp(FALSE); if (run(in_name, out_name, &ccargs) != 0) continue; in_name = out_name; @@ -469,7 +556,7 @@ out_name = f_out; else if (cc_only) { - if (f_out != NULL) + if (f_out != NUL_PTR) out_name = f_out; else { @@ -478,7 +565,7 @@ } } else - out_name = my_mktemp(); + out_name = my_mktemp(FALSE); if (run(in_name, out_name, &cppargs) != 0) continue; in_name = out_name; @@ -492,7 +579,7 @@ out_name[strlen(out_name) - 1] = 'o'; if (as_only) { - if (f_out != NULL) + if (f_out != NUL_PTR) out_name = f_out; else { @@ -501,7 +588,7 @@ } } else - out_name = my_mktemp(); + out_name = my_mktemp(FALSE); addarg(&asargs, "-n"); arg[length - 1] = 's'; addarg(&asargs, arg); @@ -510,7 +597,7 @@ { char *tmp_out_name; - tmp_out_name = my_mktemp(); + tmp_out_name = my_mktemp(FALSE); status = run(in_name, tmp_out_name, &asargs); asargs.argc -= 2; if (status != 0) @@ -543,7 +630,7 @@ if (!prep_only && !cc_only && !as_only && !runerror) { - if (f_out == NULL) + if (f_out == NUL_PTR) f_out = "a.out"; #ifdef BAS86 if (gnu_objects) @@ -553,23 +640,23 @@ { arg = ldargs.argv[argc]; if (arg[0] == '-' && arg[1] == 'i' - && (arg[2] == 0 || arg[2] == '-' && arg[3] == 0)) + && (arg[2] == 0 || (arg[2] == '-' && arg[3] == 0))) { --ldargs.argc; memmove(ldargs.argv + argc, ldargs.argv + argc + 1, (ldargs.argc - argc) * sizeof ldargs.argv[0]); - ldargs.argv[ldargs.argc] = NULL; + ldargs.argv[ldargs.argc] = NUL_PTR; } } ldargs.prog = fixpath(GCC, &exec_prefix, X_OK); - run((char *) NULL, f_out, &ldargs); + run((char *) NUL_PTR, f_out, &ldargs); } else #endif { addarg(&ldargs, "-lc"); - run((char *) NULL, f_out, &ldargs); + run((char *) NUL_PTR, f_out, &ldargs); } } killtemps(); @@ -590,12 +677,12 @@ { argp->nr_allocated += ALLOC_UNIT; new_argv = realloc(argp->argv, argp->nr_allocated * sizeof *argp->argv); - if (new_argv == NULL) + if (new_argv == NUL_PTR) outofmemory("addarg"); argp->argv = new_argv; } argp->argv[argp->argc] = arg; - argp->argv[argp->argc = new_argc] = NULL; + argp->argv[argp->argc = new_argc] = NUL_PTR; } PRIVATE void addprefix(prefix, name) @@ -604,14 +691,14 @@ { struct prefix_s *new_prefix; - if (prefix->name == NULL) + if (prefix->name == NUL_PTR) prefix->name = name; else { new_prefix = my_malloc(sizeof *new_prefix, "addprefix"); new_prefix->name = name; - new_prefix->next = NULL; - while (prefix->next != NULL) + new_prefix->next = NUL_PTR; + while (prefix->next != NUL_PTR) prefix = prefix->next; prefix->next = new_prefix; } @@ -632,7 +719,7 @@ { char *ppath; - for (; prefix != NULL; prefix = prefix->next) + for (; prefix != NUL_PTR; prefix = prefix->next) { if (verbosity > 2) { @@ -665,12 +752,13 @@ { void *block; - if ((block = malloc(size)) == NULL) + if ((block = malloc(size)) == NUL_PTR) outofmemory(where); return block; } -PRIVATE char *my_mktemp() +PRIVATE char *my_mktemp(c_extension) +int c_extension; { char *p; unsigned digit; @@ -678,8 +766,17 @@ char *template; static unsigned tmpnum; - p = template = stralloc2(tmpdir, "/bccYYYYXXXX"); - p += strlen(p); + if (c_extension) + { + p = template = stralloc2(tmpdir, "/bccYYYYXXXX.c"); + p += strlen(p) - 2; + } + else + { + p = template = stralloc2(tmpdir, "/bccYYYYXXXX"); + p += strlen(p); + } + digits = getpid(); while (*--p == 'X') { @@ -733,9 +830,9 @@ int status; arg0 = 0; - if (in_name == NULL) + if (in_name == NUL_PTR) ++arg0; - if (out_name == NULL) + if (out_name == NUL_PTR) arg0 += 2; else if (argp->minus_O_broken) ++arg0; @@ -743,9 +840,9 @@ startarg(argp); argp->argv[arg0] = argp->prog; i = arg0 + 1; - if (in_name != NULL) + if (in_name != NUL_PTR) argp->argv[i++] = in_name; - if (out_name != NULL) + if (out_name != NUL_PTR) { if (!argp->minus_O_broken) argp->argv[i++] = "-o"; @@ -779,7 +876,7 @@ --tmpargs.argc; memmove(tmpargs.argv + i, tmpargs.argv + i + 1, (tmpargs.argc - i) * sizeof tmpargs.argv[0]); - tmpargs.argv[tmpargs.argc] = NULL; + tmpargs.argv[tmpargs.argc] = NUL_PTR; break; } if (status != 0) @@ -793,17 +890,28 @@ PRIVATE void set_trap() { - int signum; +#ifndef NORDB +#ifdef SIGINT + signal(SIGINT, trap); +#endif +#ifdef SIGQUIT + signal(SIGQUIT, trap); +#endif +#else + /* This is being too trap happy! */ #ifndef _NSIG #define _NSIG NSIG #endif + int signum; + for (signum = 0; signum <= _NSIG; ++signum) #ifdef SIGCHLD if (signum != SIGCHLD) #endif if (signal(signum, SIG_IGN) != SIG_IGN) signal(signum, trap); +#endif } PRIVATE void show_who(message) @@ -820,7 +928,7 @@ argp->argv = my_malloc((argp->nr_allocated = ALLOC_UNIT) * sizeof *argp->argv, "startarg"); argp->argc = START_ARGS; - argp->argv[START_ARGS] = NULL; + argp->argv[START_ARGS] = NUL_PTR; } PRIVATE char *stralloc(s) Only in orig/bcc: bcc.c.orig diff --new-file -ur orig/bcc/bcc.doc bcc/bcc.doc --- orig/bcc/bcc.doc Mon Jul 12 05:37:54 1993 +++ bcc/bcc.doc Mon Jan 8 09:38:11 1996 @@ -15,6 +15,7 @@ somewhere/file.[cis] -> file.o for assembler output a.out for ld output +-ansi Pass the source through '/usr/bin/unprotoize' first -0 8086 target (works even on 80386 host) -3 80386 target (works even on 8086 host) -A pass remainder of option to assembler (e.g. -A-l -Alistfile for a listing) @@ -26,8 +27,11 @@ -D define (as usual) -E produce preprocessor output (as usual) -G produce gnu-Minix objects (link with gnu ld) --I include search path (as usual) --L pass remainder of option to linker +-Ix include search path (as usual) +-I don't add default include to search list +-Lx add dir name x to the head of the list of library dirs searched +-L don't add default library to search list +-X pass remainder of option to linker -O optimize (does nothing) -P produce preprocessor output with no line numbers (as usual) -Q pass full option to c386 diff --new-file -ur orig/bcc/codefrag.c bcc/codefrag.c --- orig/bcc/codefrag.c Sat Nov 14 15:12:18 1992 +++ bcc/codefrag.c Sat Dec 30 09:30:40 1995 @@ -616,8 +616,8 @@ store_pt reg; { #ifdef I8088 - if (i386_32 && (uoffset_t) offset + 1 <= 2 /* do -1 to 1 by dec/inc */ - || !i386_32 && (uoffset_t) offset + 2 <= 4) /* do -2 to 2 */ + if ((i386_32 && (uoffset_t) offset + 1 <= 2) /* do -1 to 1 by dec/inc */ + || (!i386_32 && (uoffset_t) offset + 2 <= 4)) /* do -2 to 2 */ { if (reg == ALREG) reg = AXREG; /* shorter and faster */ @@ -1325,7 +1325,7 @@ { for (lastcount = single1skip; (factor & 1) == 0; factor >>= 1) ++lastcount; - mulstack[++mulsp] = lastcount; + mulstack[(int)++mulsp] = lastcount; /* first time bumps mulsp to 0 even if an unsigned char */ for (count = 0; (factor & 1) != 0; factor >>= 1) ++count; @@ -1333,14 +1333,14 @@ if (count == 2 && factor == 0) /* 3 = 2 + 1 better than 3 = 4 - 1 */ /* but rest of algorithm messed up unless factor now 0 */ - mulstack[++mulsp] = 1; + mulstack[(int)++mulsp] = 1; else if (count > 1) { single1skip = 0; if (lastcount == 1 && mulsp != 0) - mulstack[mulsp] = -1 - count; + mulstack[(int)mulsp] = -1 - count; else - mulstack[++mulsp] = -count; + mulstack[(int)++mulsp] = -count; } } if (mulsp > 3) @@ -1351,7 +1351,7 @@ do { finishfactor(); /* finish save/add/subfactor() if nec */ - stackentry = mulstack[mulsp--]; + stackentry = mulstack[(int)mulsp--]; if (stackentry < 0) { #ifdef I8088 diff --new-file -ur orig/bcc/declare.c bcc/declare.c --- orig/bcc/declare.c Sat Jul 10 10:33:59 1993 +++ bcc/declare.c Sat Dec 30 09:30:40 1995 @@ -322,7 +322,7 @@ value_t fieldwidth; value_t fwidth; offset_t offset; - scalar_t scalar; + scalar_t scalar=0; offset = *psoffset; declspec(); @@ -713,8 +713,8 @@ } else if (gvarsymptr != NULL && (gvarsymptr->level == level || gvartype->constructor == FUNCTION || - gvarsc == EXTERNDECL && - gvarsymptr->level == GLBLEVEL)) + (gvarsc == EXTERNDECL && + gvarsymptr->level == GLBLEVEL))) { if (gvarsymptr->level != GLBLEVEL || gvarsymptr->flags == KEYWORD) multidecl(gvarname); @@ -723,8 +723,8 @@ if (gvartype->constructor != ARRAY || gvarsymptr->type->constructor != ARRAY || gvartype->nexttype != gvarsymptr->type->nexttype || - gvartype->typesize != 0 && - gvarsymptr->type->typesize != 0) + (gvartype->typesize != 0 && + gvarsymptr->type->typesize != 0)) multidecl(gvarname); else if (gvartype->typesize != 0) gvarsymptr->type = gvartype; diff --new-file -ur orig/bcc/exptree.c bcc/exptree.c --- orig/bcc/exptree.c Sat Nov 14 15:12:19 1992 +++ bcc/exptree.c Sat Jan 6 14:19:57 1996 @@ -62,15 +62,15 @@ if (!(rscalar & DOUBLE)) nodeptr->right = castnode(dtype, right); } - else if (!(bothscalar & DLONG) && (nodeptr->tag == ANDOP && - (redscalar(nodeptr->left.nodeptr) | redscalar(right)) & CHAR || - (nodeptr->tag == EOROP || nodeptr->tag == OROP) && - redscalar(nodeptr->left.nodeptr) & redscalar(right) & CHAR || - nodeptr->tag == MODOP && right->tag == LEAF && + else if (!(bothscalar & DLONG) && ((nodeptr->tag == ANDOP && + (redscalar(nodeptr->left.nodeptr) | redscalar(right)) & CHAR) || + ((nodeptr->tag == EOROP || nodeptr->tag == OROP) && + redscalar(nodeptr->left.nodeptr) & redscalar(right) & CHAR) || + (nodeptr->tag == MODOP && right->tag == LEAF && right->left.symptr->storage == CONSTANT && (divisor = right->left.symptr->offset.offv, (uvalue_t) divisor <= MAXUCHTO + 1) && - bitcount((uvalue_t) divisor) <= 1)) + bitcount((uvalue_t) divisor) <= 1))) { /* result fits in char and extends correctly */ if (bothscalar & UNSIGNED) @@ -237,17 +237,17 @@ #if MAXREGS != 1 weight_t rightweight; #endif - double dsourceval; - double dtargval; + double dsourceval = 0; /* for -Wall */ + double dtargval = 0 ; /* for -Wall */ bool_t lflag; scalar_t lscalar; struct nodestruct *pswap; - struct symstruct *source; - value_t sourceval; + struct symstruct *source = NULL; /* for -Wall */ + value_t sourceval = 0 ; /* for -Wall */ struct symstruct *target; offset_t targszdelta; - value_t targval; - scalar_t rscalar; + value_t targval = 0; /* for -Wall */ + scalar_t rscalar = 0; /* for -Wall */ bool_t uflag; switch ((op_t) t) @@ -367,10 +367,11 @@ if (lscalar & RSCALAR && !(rscalar & RSCALAR)) { double val; + static double MAXULONG = (double)0xFFFFFFFFL +1; val = *target->offset.offd; if (val > maxlongto) - val -= (double) (unsigned long) 0xFFFFFFFF + 1; /* XXX */ + val -= MAXULONG; target->offset.offv = (value_t) val; } if (!(lscalar & RSCALAR) && rscalar & RSCALAR) @@ -479,8 +480,8 @@ case COMMAOP: return p2; case CONDOP: - if (lscalar & RSCALAR && dtargval != FALSE - || !(lscalar & RSCALAR) && targval != FALSE) + if ((lscalar & RSCALAR && dtargval != FALSE) + || (!(lscalar & RSCALAR) && targval != FALSE)) { p2->left.nodeptr->nodetype = p2->nodetype; return p2->left.nodeptr; @@ -488,14 +489,14 @@ p2->right->nodetype = p2->nodetype; return p2->right; case LOGANDOP: - if (lscalar & RSCALAR && dtargval != FALSE - || !(lscalar & RSCALAR) && targval != FALSE) + if ((lscalar & RSCALAR && dtargval != FALSE) + || (!(lscalar & RSCALAR) && targval != FALSE)) break; p1->nodetype = target->type = itype; return p1; case LOGOROP: - if (lscalar & RSCALAR && dtargval == FALSE - || !(lscalar & RSCALAR) && targval == FALSE) + if ((lscalar & RSCALAR && dtargval == FALSE) + || (!(lscalar & RSCALAR) && targval == FALSE)) break; target->offset.offv = TRUE; p1->nodetype = target->type = itype; @@ -521,11 +522,11 @@ } } if (target->storage != CONSTANT || - !(lscalar & (ISCALAR | RSCALAR)) && (op_t) t != PTRSUBOP || - p2 != NULL && + !((lscalar & (ISCALAR | RSCALAR)) && (op_t) t != PTRSUBOP) || + (p2 != NULL && (p2->tag != LEAF || (source = p2->left.symptr)->storage != CONSTANT || - !((rscalar = source->type->scalar) & (ISCALAR | RSCALAR)) - && (op_t) t != PTRSUBOP)) + (!((rscalar = source->type->scalar) & (ISCALAR | RSCALAR)) + && (op_t) t != PTRSUBOP)))) goto node1; lflag = lscalar & LONG; uflag = lscalar & UNSIGNED; @@ -540,7 +541,7 @@ uflag |= rscalar & UNSIGNED; } } - if (lscalar & RSCALAR || p2 != NULL && rscalar & RSCALAR) + if (lscalar & RSCALAR || (p2 != NULL && rscalar & RSCALAR)) { if (!(lscalar & RSCALAR)) { @@ -950,8 +951,8 @@ targtype = ctype; if (bothscalar & UNSIGNED) targtype = tounsigned(targtype); - if (!(bothscalar & INT) || left->tag == LEAF && lscalar & INT || - right->tag == LEAF && rscalar & INT) + if ((!(bothscalar & INT) || (left->tag == LEAF && lscalar & INT)) || + (right->tag == LEAF && rscalar & INT)) { /* this is correct even when the if fails (the casts have to */ /* be considered at a lower level) but gives worse code */ @@ -963,12 +964,12 @@ return targtype; /* XXX - reduced from promote(targtype) */ } if (targtype->constructor & POINTER && - (isconst0(right) || right->nodetype->constructor & POINTER && - right->nodetype->nexttype->constructor & VOID)) + (isconst0(right) || (right->nodetype->constructor & POINTER && + right->nodetype->nexttype->constructor & VOID))) return targtype; if (right->nodetype->constructor & POINTER && - (isconst0(left) || targtype->constructor & POINTER && - targtype->nexttype->constructor & VOID)) + (isconst0(left) || (targtype->constructor & POINTER && + targtype->nexttype->constructor & VOID))) return right->nodetype; error("mismatched types"); fixnode(left); /* XXX - better to fix the CONDOP */ diff --new-file -ur orig/bcc/gencode.c bcc/gencode.c --- orig/bcc/gencode.c Sat Nov 14 15:51:04 1992 +++ bcc/gencode.c Sat Dec 30 09:30:40 1995 @@ -3,7 +3,7 @@ /* Copyright (C) 1992 Bruce Evans */ #define islvalop(op) \ - ((op) >= ASSIGNOP && (op) <= SUBABOP || (op) == PTRADDABOP) + (((op) >= ASSIGNOP && (op) <= SUBABOP) || (op) == PTRADDABOP) #include "const.h" #include "types.h" @@ -291,7 +291,7 @@ } if (source->storage & allindregs && source->indcount == 0 && (source->type->scalar & (DLONG | RSCALAR) || - left->tag == FUNCOP && source->flags != REGVAR)) + (left->tag == FUNCOP && source->flags != REGVAR))) push(source); /* XXX - perhaps not float */ else preserve(source); @@ -351,11 +351,11 @@ debug(exp); #endif if (commutop - && (target->storage == CONSTANT - && !(target->type->scalar & (DLONG | RSCALAR)) + && ((target->storage == CONSTANT + && !(target->type->scalar & (DLONG | RSCALAR))) || source->storage & ALLDATREGS - || source->type->scalar & (DLONG | RSCALAR) - && source->indcount == 0 && target->indcount != 0)) + || (source->type->scalar & (DLONG | RSCALAR) + && source->indcount == 0 && target->indcount != 0))) { exp->left.nodeptr = right; exp->right = left; @@ -471,12 +471,12 @@ ccode_t condtrue; op_pt op; store_t regmark; - offset_t saveargsp; - store_t savelist; - offset_t saveoffset; + offset_t saveargsp = 0; /* for -Wall */ + store_t savelist = 0; /* for -Wall */ + offset_t saveoffset = 0; /* for -Wall */ struct symstruct *source; offset_t spmark; - struct symstruct *structarg; + struct symstruct *structarg = 0; /* for -Wall */ struct symstruct *target; if ((op_t) (op = exp->tag) == LEAF) diff --new-file -ur orig/bcc/genloads.c bcc/genloads.c --- orig/bcc/genloads.c Sat Nov 14 15:48:33 1992 +++ bcc/genloads.c Sat Dec 30 09:30:41 1995 @@ -434,15 +434,16 @@ { if (source->type->scalar & RSCALAR) load(source, doubleregs & ~DREG); - else if (source->storage == CONSTANT && !(source->type->scalar & DLONG) + else if ((source->storage == CONSTANT && + !(source->type->scalar & DLONG)) || source->type->scalar & CHAR) load(source, DREG); else if (source->storage & ~reguse & allregs) load(source, source->storage); else if (((reguse & allindregs) == allindregs || - !(source->type->constructor & (ARRAY | POINTER)) && + ((!(source->type->constructor & (ARRAY | POINTER)) && source->indcount != 0) && - !(source->type->scalar & DLONG)) + !(source->type->scalar & DLONG)))) load(source, DREG); else load(source, getindexreg()); @@ -1011,10 +1012,10 @@ } } #ifdef I8088 - else if (source->indcount == 1 && + else if ((source->indcount == 1 && (sscalar & (SHORT | INT | LONG | FLOAT) || - source->type->constructor & POINTER) || - source->storage == CONSTANT && i386_32) + source->type->constructor & POINTER)) || + (source->storage == CONSTANT && i386_32)) { size = source->type->typesize; if (size == 1) diff --new-file -ur orig/bcc/glogcode.c bcc/glogcode.c --- orig/bcc/glogcode.c Sat Nov 14 15:48:40 1992 +++ bcc/glogcode.c Sat Dec 30 09:30:41 1995 @@ -90,7 +90,7 @@ } #endif #endif - sbranch(oppcc[*pcondtrue], falselab = getlabel()); + sbranch(oppcc[(int)*pcondtrue], falselab = getlabel()); loadlogical(target, falselab); } @@ -107,25 +107,25 @@ reduceconst(target); sscalar = source->type->scalar; tscalar = target->type->scalar; - if (source->storage != CONSTANT && + if ((source->storage != CONSTANT && (target->storage == CONSTANT || - sscalar & CHAR && !(tscalar & CHAR) || - (sscalar & CHAR || !(tscalar & CHAR)) && - source->indcount == 0 && target->indcount != 0) || - tscalar & DLONG && target->indcount != 0) + (sscalar & CHAR && !(tscalar & CHAR)) || + ((sscalar & CHAR || !(tscalar & CHAR)) && + source->indcount == 0 && target->indcount != 0))) || + (tscalar & DLONG && target->indcount != 0)) { swapsym(target, source); - *pcondtrue = reverscc[*pcondtrue]; + *pcondtrue = reverscc[(int)*pcondtrue]; tempscalar = sscalar; sscalar = tscalar; tscalar = tempscalar; } - if (sscalar & CHAR && tscalar & CHAR && - (source->type != sctype || target->type != sctype) || + if ((sscalar & CHAR && tscalar & CHAR && + (source->type != sctype || target->type != sctype)) || (sscalar | tscalar) & UNSIGNED || (source->type->constructor | target->type->constructor) & (ARRAY | POINTER)) - *pcondtrue = unsigncc[*pcondtrue]; + *pcondtrue = unsigncc[(int)*pcondtrue]; if (source->type->scalar & DLONG) { longop(EQOP, source, target); @@ -141,7 +141,7 @@ if (sscalar & CHAR) { if (tscalar & CHAR) - *pcondtrue = unsigncc[*pcondtrue]; + *pcondtrue = unsigncc[(int)*pcondtrue]; else { source->type = iscalartotype(sscalar); @@ -271,7 +271,7 @@ changesp(spmark, FALSE); reguse = regmark; if ((bool_t) nojump) - lbranch(oppcc[condtrue], falselab); + lbranch(oppcc[(int)condtrue], falselab); else lbranch(condtrue, truelab); } @@ -452,7 +452,7 @@ store_t targreg; #endif - *pcondtrue = testcc[*pcondtrue]; + *pcondtrue = testcc[(int)*pcondtrue]; if (target->type->scalar & DLONG) { long1op(EQOP, target); @@ -465,7 +465,7 @@ } #ifdef I8088 if (target->indcount != 0 || - target->storage == LOCAL && target->offset.offi != sp) + (target->storage == LOCAL && target->offset.offi != sp)) load(target, DREG); if (target->storage == GLOBAL) load(target, getindexreg()); @@ -546,7 +546,7 @@ condtrue = NE; test(source, &condtrue); if ((bool_t) nojump) - lbranch(oppcc[condtrue], falselab); + lbranch(oppcc[(int)condtrue], falselab); else lbranch(condtrue, truelab); } diff --new-file -ur orig/bcc/hardop.c bcc/hardop.c --- orig/bcc/hardop.c Sat Nov 14 15:48:56 1992 +++ bcc/hardop.c Sat Dec 30 09:30:41 1995 @@ -286,8 +286,8 @@ sscalar = source->type->scalar; } if (target->indcount != 0 && - (tscalar & CHAR && !(sscalar & CHAR) && - op != ANDOP || source->indcount == 0 && source->storage != CONSTANT)) + ((tscalar & CHAR && !(sscalar & CHAR) && + op != ANDOP) || (source->indcount == 0 && source->storage != CONSTANT))) { swapsym(target, source); sscalar = tscalar; diff --new-file -ur orig/bcc/input.c bcc/input.c --- orig/bcc/input.c Sat Nov 14 15:12:19 1992 +++ bcc/input.c Sun Jan 7 22:07:52 1996 @@ -47,7 +47,9 @@ /* between first and last */ PRIVATE struct inclist inclast = { +#ifdef DEFAULT_INCLUDE_DIR DEFAULT_INCLUDE_DIR, +#endif NULL, }; PRIVATE fastin_t inclevel; /* nest level of include files */ @@ -331,7 +333,13 @@ ourfree(fullnameptr); } while ((incptr = incptr->incnext) != NULL); - error("cannot find include file"); + + fullnameptr = ourmalloc(strlen(fnameptr) + 40); + strcpy(fullnameptr, "cannot find include file "); + strcat(fullnameptr, fnameptr); + error(fullnameptr); + ourfree(fullnameptr); + #ifdef TS ts_s_filename_tot -= charptr - fnameptr; #endif @@ -462,9 +470,9 @@ case 't': /* print source code in asm output */ case 'w': /* watch location counter */ if (arg[2] == 0) - flag[arg[1]] = TRUE; + flag[(int)arg[1]] = TRUE; else if (arg[2] == '-' && arg[3] == 0) - flag[arg[1]] = FALSE; + flag[(int)arg[1]] = FALSE; else usage(); if (arg[1] == '0') /* flag 0 is negative logic flag 3 */ diff --new-file -ur orig/bcc/label.c bcc/label.c --- orig/bcc/label.c Sat Nov 14 15:49:05 1992 +++ bcc/label.c Sat Dec 30 09:30:41 1995 @@ -78,7 +78,7 @@ { register struct labdatstruct *labptr; - labptr = &vislab[nextvislab]; + labptr = &vislab[(int)nextvislab]; labptr->labcond = cond; labptr->labnum = label; labptr->lablc = lc; @@ -184,7 +184,7 @@ labmin = &vislab[0]; labmax = &vislab[MAXVISLAB]; - labptr = labmid = &vislab[nextvislab]; + labptr = labmid = &vislab[(int)nextvislab]; if (!watchlc) do { @@ -199,7 +199,7 @@ #ifdef I8088 /* patch "bcc(c) to j(c)(c)( ) */ *labpatch = 'j'; *(labpatch + 1) = - *(cnameptr = scondnames[labptr->labcond]); + *(cnameptr = scondnames[(int)labptr->labcond]); #endif #ifdef MC6809 # ifdef NEW_MC6809 /* patch JMP\t> or LBCC\t to BCC \t */ @@ -308,7 +308,7 @@ { outlbranch(); #ifdef I8088 - outbyte(*(cnameptr = lcondnames[(ccode_t) cond])); + outbyte(*(cnameptr = lcondnames[(int) cond])); outbyte(*(cnameptr + 1)); if ((ccode_t) cond == LS || (ccode_t) cond == HS) outbyte('s'); /* "blos" or "bhis" */ @@ -406,7 +406,7 @@ if ((ccode_t) cond != RN) { outsbranch(); - outbyte(*(cnameptr = scondnames[(ccode_t) cond])); + outbyte(*(cnameptr = scondnames[(int) cond])); outbyte(*(cnameptr + 1)); outtab(); outlabel(label); diff --new-file -ur orig/bcc/loadexp.c bcc/loadexp.c --- orig/bcc/loadexp.c Sat Nov 14 15:49:11 1992 +++ bcc/loadexp.c Sat Dec 30 09:30:41 1995 @@ -56,9 +56,9 @@ makeleaf(node(ASSIGNOP, lhs, exp)); } else if (exp->tag != LEAF || - (symptr = exp->left.symptr)->storage != CONSTANT && + ((symptr = exp->left.symptr)->storage != CONSTANT && (symptr->storage != GLOBAL || symptr->indcount != 0 || - type->scalar & DLONG) || + type->scalar & DLONG)) || (type->constructor | (symptr->type->constructor & ~FUNCTION)) & ~(ARRAY | POINTER)) error("initializer too complicated"); diff --new-file -ur orig/bcc/longop.c bcc/longop.c --- orig/bcc/longop.c Sat Nov 14 15:49:18 1992 +++ bcc/longop.c Sat Dec 30 09:30:41 1995 @@ -39,7 +39,7 @@ shiftflag = TRUE; else scalar |= source->type->scalar; - if (source->indcount == 0 && !shiftflag || + if ((source->indcount == 0 && !shiftflag) || source->storage & (DREG | OPREG | OPWORKREG)) { pres2(source, target); diff --new-file -ur orig/bcc/make.bat bcc/make.bat --- orig/bcc/make.bat Thu Jan 1 01:00:00 1970 +++ bcc/make.bat Mon Jan 8 13:23:57 1996 @@ -0,0 +1,38 @@ +cl -nologo -O -DLOCALPREFIX=\"/linux86\" -o bcc.exe bcc.c + +cl -nologo -O -c -Mm -Deof=xxeof assign.c +cl -nologo -O -c -Mm -Deof=xxeof bcc-cc1.c +cl -nologo -O -c -Mm -Deof=xxeof codefrag.c +cl -nologo -O -c -Mm -Deof=xxeof debug.c +cl -nologo -O -c -Mm -Deof=xxeof declare.c +cl -nologo -O -c -Mm -Deof=xxeof express.c +cl -nologo -O -c -Mm -Deof=xxeof exptree.c +cl -nologo -O -c -Mm -Deof=xxeof floatop.c +cl -nologo -O -c -Mm -Deof=xxeof function.c +cl -nologo -O -c -Mm -Deof=xxeof gencode.c +cl -nologo -O -c -Mm -Deof=xxeof genloads.c +cl -nologo -O -c -Mm -Deof=xxeof glogcode.c +cl -nologo -O -c -Mm -Deof=xxeof hardop.c +cl -nologo -O -c -Mm -Deof=xxeof input.c +cl -nologo -O -c -Mm -Deof=xxeof label.c +cl -nologo -O -c -Mm -Deof=xxeof loadexp.c +cl -nologo -O -c -Mm -Deof=xxeof longop.c +cl -nologo -O -c -Mm -Deof=xxeof output.c +cl -nologo -O -c -Mm -Deof=xxeof preproc.c +cl -nologo -O -c -Mm -Deof=xxeof preserve.c +cl -nologo -O -c -Mm -Deof=xxeof scan.c +cl -nologo -O -c -Mm -Deof=xxeof softop.c +cl -nologo -O -c -Mm -Deof=xxeof state.c +cl -nologo -O -c -Mm -Deof=xxeof table.c +cl -nologo -O -c -Mm -Deof=xxeof type.c + +del bcc_lib.lib +lib bcc_lib.lib +assign.obj +declare.obj +gencode.obj +label.obj ; +lib bcc_lib.lib +preserve.obj +type.obj +express.obj +genloads.obj ; +lib bcc_lib.lib +loadexp.obj +scan.obj +exptree.obj +glogcode.obj ; +lib bcc_lib.lib +longop.obj +softop.obj +codefrag.obj +floatop.obj ; +lib bcc_lib.lib +hardop.obj +output.obj +state.obj +debug.obj ; +lib bcc_lib.lib +function.obj +input.obj +preproc.obj +table.obj ; + +cl -nologo -O -Mm -o bcc-cc1.exe bcc-cc1.obj bcc_lib.lib +del *.obj diff --new-file -ur orig/bcc/mk.bat bcc/mk.bat --- orig/bcc/mk.bat Thu Jan 1 01:00:00 1970 +++ bcc/mk.bat Mon Jan 8 13:30:30 1996 @@ -0,0 +1,37 @@ +del xx.out +cl -W3 -nologo -O -c -Mm -Deof=xxeof assign.c >>xx.out +cl -W3 -nologo -O -c -Mm -Deof=xxeof bcc-cc1.c >>xx.out +cl -W3 -nologo -O -c -Mm -Deof=xxeof codefrag.c >>xx.out +cl -W3 -nologo -O -c -Mm -Deof=xxeof debug.c >>xx.out +cl -W3 -nologo -O -c -Mm -Deof=xxeof declare.c >>xx.out +cl -W3 -nologo -O -c -Mm -Deof=xxeof express.c >>xx.out +cl -W3 -nologo -O -c -Mm -Deof=xxeof exptree.c >>xx.out +cl -W3 -nologo -O -c -Mm -Deof=xxeof floatop.c >>xx.out +cl -W3 -nologo -O -c -Mm -Deof=xxeof function.c >>xx.out +cl -W3 -nologo -O -c -Mm -Deof=xxeof gencode.c >>xx.out +cl -W3 -nologo -O -c -Mm -Deof=xxeof genloads.c >>xx.out +cl -W3 -nologo -O -c -Mm -Deof=xxeof glogcode.c >>xx.out +cl -W3 -nologo -O -c -Mm -Deof=xxeof hardop.c >>xx.out +cl -W3 -nologo -O -c -Mm -Deof=xxeof input.c >>xx.out +cl -W3 -nologo -O -c -Mm -Deof=xxeof label.c >>xx.out +cl -W3 -nologo -O -c -Mm -Deof=xxeof loadexp.c >>xx.out +cl -W3 -nologo -O -c -Mm -Deof=xxeof longop.c >>xx.out +cl -W3 -nologo -O -c -Mm -Deof=xxeof output.c >>xx.out +cl -W3 -nologo -O -c -Mm -Deof=xxeof preproc.c >>xx.out +cl -W3 -nologo -O -c -Mm -Deof=xxeof preserve.c >>xx.out +cl -W3 -nologo -O -c -Mm -Deof=xxeof scan.c >>xx.out +cl -W3 -nologo -O -c -Mm -Deof=xxeof softop.c >>xx.out +cl -W3 -nologo -O -c -Mm -Deof=xxeof state.c >>xx.out +cl -W3 -nologo -O -c -Mm -Deof=xxeof table.c >>xx.out +cl -W3 -nologo -O -c -Mm -Deof=xxeof type.c >>xx.out + +del bcc_lib.lib +lib bcc_lib.lib +assign.obj +decl -W3are.obj +gencode.obj +label.obj ; +lib bcc_lib.lib +preserve.obj +type.obj +express.obj +genloads.obj ; +lib bcc_lib.lib +loadexp.obj +scan.obj +exptree.obj +glogcode.obj ; +lib bcc_lib.lib +longop.obj +softop.obj +codefrag.obj +floatop.obj ; +lib bcc_lib.lib +hardop.obj +output.obj +state.obj +debug.obj ; +lib bcc_lib.lib +function.obj +input.obj +preproc.obj +table.obj ; + +cl -W3 -nologo -O -Mm -o bcc-cc1.exe bcc-cc1.obj bcc_lib.lib +del *.obj diff --new-file -ur orig/bcc/os.h bcc/os.h --- orig/bcc/os.h Sat Nov 14 15:12:16 1992 +++ bcc/os.h Sat Jan 6 18:54:51 1996 @@ -26,7 +26,6 @@ #define EOLTO 10 /* target newline */ #define DIRCHAR '/' #define DIRSTRING "/" -#define DEFAULT_INCLUDE_DIR "/usr/include" #define isabspath(fnameptr, tempcptr) \ ((*(tempcptr) = *(fnameptr)) == DIRCHAR) diff --new-file -ur orig/bcc/output.c bcc/output.c --- orig/bcc/output.c Sat Nov 14 15:12:20 1992 +++ bcc/output.c Sat Dec 30 09:30:41 1995 @@ -378,7 +378,7 @@ outhexdigs(num / 0x10); num %= 0x10; } - outbyte(hexdigits[(fastin_t) num]); + outbyte(hexdigits[(int) num]); } /* print string terminated by EOL */ diff --new-file -ur orig/bcc/preproc.c bcc/preproc.c --- orig/bcc/preproc.c Fri Dec 4 21:44:46 1992 +++ bcc/preproc.c Sat Dec 30 09:30:41 1995 @@ -230,7 +230,7 @@ char sname[NAMESIZE]; char quote; struct symstruct **hashptr; - struct symstruct *locmark; + struct symstruct *locmark = NULL; /* for -Wall */ char *macstring; fastin_t nparnames; char *oldstring; @@ -492,7 +492,7 @@ { register struct ifstruct *ifptr; - ifptr = &ifstack[--iflevel]; + ifptr = &ifstack[(int)--iflevel]; ifstate.elseflag = ifptr->elseflag; ifstate.ifflag = ifptr->ifflag; } @@ -586,8 +586,8 @@ } else if (ch == '(') ++lpcount; - else if (ch == ')' && --lpcount == 0 || - ch == ',' && lpcount == 1) + else if ((ch == ')' && --lpcount == 0) || + (ch == ',' && lpcount == 1)) break; if (ch == EOL) ch = ' '; @@ -757,7 +757,7 @@ { register struct ifstruct *ifptr; - ifptr = &ifstack[iflevel++]; + ifptr = &ifstack[(int)iflevel++]; ifptr->elseflag = ifstate.elseflag; ifptr->ifflag = ifstate.ifflag; ifstate.elseflag = FALSE; /* prepare for !(if now)||(if future)*/ @@ -778,8 +778,8 @@ iftrue = constexpression() != 0; incppexpr = FALSE; } - if (!iftrue && (sym_t) ifcase != IFNDEFCNTL || - iftrue && (sym_t) ifcase == IFNDEFCNTL) + if ((!iftrue && (sym_t) ifcase != IFNDEFCNTL) || + (iftrue && (sym_t) ifcase == IFNDEFCNTL)) { ifstate.elseflag = TRUE; ifstate.ifflag = FALSE; diff --new-file -ur orig/bcc/preserve.c bcc/preserve.c --- orig/bcc/preserve.c Sat Nov 14 15:49:38 1992 +++ bcc/preserve.c Sat Dec 30 09:30:41 1995 @@ -14,10 +14,10 @@ offset_t newsp; bool_pt absflag; { - if (newsp != sp || (bool_t) absflag && switchnow != NULL) + if (newsp != sp || ((bool_t) absflag && switchnow != NULL)) { #ifdef FRAMEPOINTER - if (newsp != framep || !(bool_t) absflag && switchnow != NULL) + if (newsp != framep || (!(bool_t) absflag && switchnow != NULL)) { outleasp(); if (!(bool_t) absflag && switchnow != NULL) @@ -106,7 +106,8 @@ if (target->storage & allregs) { if (target->storage & (allregs - allindregs) /* XXX */ || - target->indcount == 0 && target->type->scalar & (DLONG | RSCALAR)) + (target->indcount == 0 && + target->type->scalar & (DLONG | RSCALAR))) push(target); /* XXX - perhaps not float */ else if (((target->storage | reguse) & allindregs) == allindregs) { diff --new-file -ur orig/bcc/proto.h bcc/proto.h --- orig/bcc/proto.h Sat Nov 14 15:12:17 1992 +++ bcc/proto.h Mon Jan 8 13:30:40 1996 @@ -2,7 +2,7 @@ /* Copyright (C) 1992 Bruce Evans */ -#if __STDC__ +#ifdef __STDC__ #define P(x) x #else #define P(x) () diff --new-file -ur orig/bcc/softop.c bcc/softop.c --- orig/bcc/softop.c Sat Nov 14 15:49:45 1992 +++ bcc/softop.c Sat Dec 30 09:30:41 1995 @@ -124,14 +124,17 @@ regpushed = (regmark = reguse) & OPREG; workreg = OPREG; - if (sscalar & CHAR && target->storage & WORKDATREGS && - source->storage == OPREG && source->indcount != 0 || - (sscalar & CHAR || source->storage & WORKDATREGS) && - target->storage == OPREG && target->indcount != 0 || - source->storage == OPREG && - target->storage == GLOBAL && target->indcount == 0 + if ((sscalar & CHAR && target->storage & WORKDATREGS && + source->storage == OPREG && source->indcount != 0) || + ((sscalar & CHAR || source->storage & WORKDATREGS) && + target->storage == OPREG && target->indcount != 0) || +#ifdef MC6809 /* for -Wall */ + ( +#endif + (source->storage == OPREG && + target->storage == GLOBAL && target->indcount == 0) #ifdef MC6809 - && posindependent + && posindependent) #endif ) { diff --new-file -ur orig/bcc/state.c bcc/state.c --- orig/bcc/state.c Sat Nov 14 15:49:50 1992 +++ bcc/state.c Sat Dec 30 09:30:41 1995 @@ -128,8 +128,8 @@ register struct nodestruct *exp; { return exp == NULL || - exp->tag == LEAF && exp->left.symptr->storage == CONSTANT && - exp->left.symptr->offset.offv != 0; + (exp->tag == LEAF && exp->left.symptr->storage == CONSTANT && + exp->left.symptr->offset.offv != 0); } PRIVATE void sort(caselist, count) /* shell sort */ @@ -370,7 +370,7 @@ { struct loopstruct forloop; label_t forstatlab; - label_t fortestlab; + label_t fortestlab = 0; /* for -Wall */ struct nodestruct *testexp; struct nodestruct *loopexp; @@ -469,7 +469,7 @@ { struct switchstruct *sw; struct loopstruct switchloop; - offset_t spmark; + offset_t spmark = 0; /* for -Wall */ label_t sdecidelab; sw = (struct switchstruct *) ourmalloc(sizeof *sw); diff --new-file -ur orig/bcc/table.c bcc/table.c --- orig/bcc/table.c Sat Nov 14 15:12:21 1992 +++ bcc/table.c Sat Dec 30 09:30:41 1995 @@ -145,7 +145,7 @@ struct typestruct *type; { struct symstruct **hashptr; - struct symstruct *oldsymptr; + struct symstruct *oldsymptr = NULL; /* for -Wall */ register struct symstruct *symptr; hashptr = gethashptr(name); diff --new-file -ur orig/bcc/types.h bcc/types.h --- orig/bcc/types.h Sat Nov 14 15:12:18 1992 +++ bcc/types.h Mon Jan 8 13:31:53 1996 @@ -34,7 +34,7 @@ typedef unsigned store_t; /* storage class flags */ #endif #ifdef MC6809 -# if __STDC__ +#ifdef __STDC__ typedef int store_pt; # else typedef unsigned store_pt; @@ -71,7 +71,7 @@ /* change to fastin_t if this is not true */ /* or if char has < 8 bits */ /* or if space is not a limiting factor */ -#if __STDC__ +#ifdef __STDC__ typedef int smalu_pt; #else typedef unsigned smalu_pt; diff --new-file -ur orig/as/Makefile as/Makefile --- orig/as/Makefile Thu Apr 23 05:04:26 1992 +++ as/Makefile Mon Jan 8 11:55:13 1996 @@ -1,6 +1,13 @@ -CFLAGS =-O -LDFLAGS = +WFLAGS=-Wall +WALL =-Wall -Wtraditional -Wshadow -Wid-clash-14 -Wpointer-arith \ + -Wcast-qual -Wcast-align -Wconversion -Waggregate-return \ + -Wstrict-prototypes -Wmissing-prototypes -Wredundant-decls \ + -Wnested-externs -Winline + +CFLAGS =$(WFLAGS) -O -b i486-linuxaout +LDFLAGS =-s -N -static -b i486-linuxaout + OBJS =as.o assemble.o error.o express.o \ genbin.o genlist.o genobj.o gensym.o \ macro.o mops.o pops.o readsrc.o \ @@ -8,7 +15,7 @@ as: $(OBJS) $(CC) $(LDFLAGS) $(OBJS) -o as - chmem =182000 as + # chmem =182000 as as.o: const.h type.h byteord.h macro.h file.h flag.h globvar.h assemble.o: const.h type.h address.h globvar.h opcode.h scan.h @@ -25,3 +32,4 @@ readsrc.o: const.h type.h flag.h file.h globvar.h macro.h scan.h source.h scan.o: const.h type.h globvar.h scan.h table.o: const.h type.h globvar.h opcode.h scan.h + diff --new-file -ur orig/as/as.c as/as.c --- orig/as/as.c Sat Jul 10 20:03:34 1993 +++ as/as.c Mon Jan 8 11:47:22 1996 @@ -21,7 +21,6 @@ char *strcpy P((char *s1, const char *s2)); unsigned strlen P((const char *s)); #else -#undef NULL #include #include #endif @@ -31,7 +30,6 @@ int creat P((const char *path, int mode)); int write P((int fd, const void *buf, unsigned nbytes)); #else -#undef NULL #include #include #include @@ -53,7 +51,9 @@ FORWARD void summ_number P((unsigned num)); FORWARD void usage P((void)); +#ifndef USERMEM #define USERMEM (sizeof(int) <= 2 ? (unsigned) 0xAC00 : (unsigned) 0x28000L) +#endif PUBLIC int main(argc, argv) int argc; @@ -146,7 +146,11 @@ { int fd; +#ifdef O_BINARY + if ((fd = open(name, O_RDWR|O_BINARY|O_CREAT|O_TRUNC, CREAT_PERMS)) < 0 || fd > 255) +#else if ((fd = creat(name, CREAT_PERMS)) < 0 || fd > 255) +#endif as_abort(message); return fd; } @@ -157,7 +161,7 @@ { char *arg; bool_t isnextarg; - char *nextarg; + char *nextarg = 0; if (argc <= 1) usage(); diff --new-file -ur orig/as/assemble.c as/assemble.c --- orig/as/assemble.c Wed Mar 25 09:37:43 1992 +++ as/assemble.c Mon Jan 8 11:17:37 1996 @@ -155,7 +155,7 @@ while (TRUE) { asline(); - if (label != NULL) /* must be confirmed if still set */ + if (label != NUL_PTR) /* must be confirmed if still set */ { /* it is nulled by EQU, COMM and SET */ #ifndef MC6809 #define NEEDENDLABEL ILLAB @@ -172,7 +172,7 @@ if ((mcount | popflags) == 0) /* unaccompanied label, display adr like EQU and SET */ showlabel(); - label = NULL; /* reset for next line */ + label = NUL_PTR; /* reset for next line */ } skipline(); listline(); @@ -210,7 +210,7 @@ if (!ifflag) /* not assembling, just test for IF/ELSE/ELSEIF/ENDIF */ { - if (symptr == NULL || !(symptr->type & MNREGBIT) || + if (symptr == NUL_PTR || !(symptr->type & MNREGBIT) || symptr->data & REGBIT || symptr->value_reg_or_op.op.routine >= MIN_NONCOND) return; diff --new-file -ur orig/as/const.h as/const.h --- orig/as/const.h Sat Jul 10 17:04:30 1993 +++ as/const.h Mon Jan 8 11:17:55 1996 @@ -41,7 +41,7 @@ #define FORWARD static #define PRIVATE static #define PUBLIC -#define NULL 0 +#define NUL_PTR ((void*)0) /* O/S constants */ diff --new-file -ur orig/as/error.c as/error.c --- orig/as/error.c Sat Jul 10 19:55:14 1993 +++ as/error.c Mon Jan 8 11:18:03 1996 @@ -6,7 +6,6 @@ #ifdef STDC_HEADERS_MISSING char *strcpy P((char *s1, const char *s2)); #else -#undef NULL #include #endif diff --new-file -ur orig/as/genlist.c as/genlist.c --- orig/as/genlist.c Sat Jul 10 20:37:04 1993 +++ as/genlist.c Mon Jan 8 11:33:50 1996 @@ -14,14 +14,12 @@ void *memset P((void *s, int c, unsigned n)); unsigned strlen P((const char *s)); #else -#undef NULL #include #endif #ifdef POSIX_HEADERS_MISSING int write P((int fd, const void *buf, unsigned nbytes)); #else -#undef NULL #include #include #endif @@ -186,8 +184,8 @@ { if (!listpre) { - if (errcount || list.current && (!macflag || mcount != 0) || - macflag && maclist.current) + if (errcount || (list.current && (!macflag || mcount != 0)) || + (macflag && maclist.current)) list1(lstfil); if (errcount) { diff --new-file -ur orig/as/genobj.c as/genobj.c --- orig/as/genobj.c Sat Jul 10 20:10:35 1993 +++ as/genobj.c Mon Jan 8 11:34:45 1996 @@ -11,14 +11,12 @@ char *strrchr P((const char *s, int c)); unsigned strlen P((const char *s)); #else -#undef NULL #include #endif #ifdef POSIX_HEADERS_MISSING int write P((int fd, const void *buf, unsigned nbytes)); #else -#undef NULL #include #include #endif @@ -371,22 +369,22 @@ /* build array of imported/exported symbols */ symosiz = 0; - if (truefilename == NULL) + if (truefilename == NUL_PTR) truefilename = filnamptr; nameptr = strrchr(truefilename, DIRCHAR); - strcpy(module_name, nameptr != NULL ? nameptr + 1 : truefilename); - if ((nameptr = strrchr(module_name, '.')) != NULL) + strcpy(module_name, nameptr != NUL_PTR ? nameptr + 1 : truefilename); + if ((nameptr = strrchr(module_name, '.')) != NUL_PTR) *nameptr = 0; strsiz = strlen(module_name) + 1; align(heapptr); for (hashptr = spt, arrext = copyptr = (struct sym_s **) heapptr; hashptr < spt_top;) - if ((symptr = *hashptr++) != NULL) + if ((symptr = *hashptr++) != NUL_PTR) do { if ((symptr->type & EXPBIT || symptr->data & IMPBIT) || - !globals_only_in_obj && symptr->name[0] != '.' && - !(symptr->type & (MNREGBIT | MACBIT | VARBIT))) + (!globals_only_in_obj && symptr->name[0] != '.' && + !(symptr->type & (MNREGBIT | MACBIT | VARBIT)))) { if (copyptr >= (struct sym_s **) heapend) { @@ -412,7 +410,7 @@ ++numext; } } - while ((symptr = symptr->next) != NULL); + while ((symptr = symptr->next) != NUL_PTR); heapptr = (char *) (copytop = copyptr); /* calculate length of text, and number of seg size bytes in header */ diff --new-file -ur orig/as/gensym.c as/gensym.c --- orig/as/gensym.c Sat Jul 10 20:11:20 1993 +++ as/gensym.c Mon Jan 8 11:19:05 1996 @@ -10,14 +10,12 @@ void *memset P((void *s, int c, unsigned n)); int strcmp P((const char *s1, const char *s2)); #else -#undef NULL #include #endif #ifdef POSIX_HEADERS_MISSING int write P((int fd, const void *buf, unsigned nbytes)); #else -#undef NULL #include #include #endif @@ -51,7 +49,7 @@ align(heapptr); for (hashptr = spt, symlptr = copyptr = (struct sym_s **) heapptr; hashptr < spt_top;) - if ((symptr = *hashptr++) != NULL) + if ((symptr = *hashptr++) != NUL_PTR) do if (!(symptr->type & (MACBIT | MNREGBIT | VARBIT))) { @@ -66,7 +64,7 @@ ++label_count; labels_length += symptr->length + 3; /* 3 for type, value */ } - while ((symptr = symptr->next) != NULL); + while ((symptr = symptr->next) != NUL_PTR); sort_symbols: sort(symlptr, copyptr, TRUE); /* sort on name */ diff --new-file -ur orig/as/macro.c as/macro.c --- orig/as/macro.c Sat Jul 10 20:08:05 1993 +++ as/macro.c Mon Jan 8 11:35:58 1996 @@ -11,7 +11,6 @@ #ifdef STDC_HEADERS_MISSING int strncmp P((const char *s1, const char *s2, unsigned n)); #else -#undef NULL #include #endif @@ -39,7 +38,7 @@ ++maclevel; (--macstak)->text = (char *) symptr->value_reg_or_op.value; macstak->parameters = param1 = macpar; - param1->next = NULL; + param1->next = NUL_PTR; *(stringptr = build_number(++macnum, 3, param1->string)) = 0; macpar = (struct schain_s *) (stringptr + 1); /* TODO: alignment */ @@ -70,7 +69,7 @@ } *stringptr = 0; param1->next = macpar; /* ptr from previous */ - (param1 = macpar)->next = NULL; + (param1 = macpar)->next = NUL_PTR; /* this goes nowhere */ macpar = (struct schain_s *) (stringptr + 1); /* but is finished OK - TODO align */ @@ -95,12 +94,12 @@ { bool_t saving; bool_t savingc; - struct sym_s *symptr; + struct sym_s *symptr=0; saving = /* prepare for bad macro */ savingc = FALSE; /* normally don't save comments */ macload = TRUE; /* show loading */ - if (label != NULL) + if (label != NUL_PTR) error(ILLAB); else if (sym != IDENT) error(LABEXP); diff --new-file -ur orig/as/make.bat as/make.bat --- orig/as/make.bat Thu Jan 1 01:00:00 1970 +++ as/make.bat Mon Jan 8 13:07:28 1996 @@ -0,0 +1,24 @@ +cl -nologo -c -DPOSIX_HEADERS_MISSING -O as.c +cl -nologo -c -DPOSIX_HEADERS_MISSING -O assemble.c +cl -nologo -c -DPOSIX_HEADERS_MISSING -O error.c +cl -nologo -c -DPOSIX_HEADERS_MISSING -O express.c +cl -nologo -c -DPOSIX_HEADERS_MISSING -O genbin.c +cl -nologo -c -DPOSIX_HEADERS_MISSING -O genlist.c +cl -nologo -c -DPOSIX_HEADERS_MISSING -O genobj.c +cl -nologo -c -DPOSIX_HEADERS_MISSING -O gensym.c +cl -nologo -c -DPOSIX_HEADERS_MISSING -O macro.c +cl -nologo -c -DPOSIX_HEADERS_MISSING -O mops.c +cl -nologo -c -DPOSIX_HEADERS_MISSING -O pops.c +cl -nologo -c -DPOSIX_HEADERS_MISSING -O readsrc.c +cl -nologo -c -DPOSIX_HEADERS_MISSING -O scan.c +cl -nologo -c -DPOSIX_HEADERS_MISSING -O table.c +cd ..\ld +cl -nologo -c -DPOSIX_HEADERS_MISSING -O typeconv.c +cd ..\as +del as.lib +lib as.lib +..\ld\typeconv.obj; +del ..\ld\typeconv.obj +lib as.lib +assemble.obj +error.obj +express.obj +genbin.obj +genlist.obj +genobj.obj; +lib as.lib +gensym.obj +macro.obj +mops.obj +pops.obj +readsrc.obj +scan.obj +table.obj; +del *.obj +cl -o as.exe as.obj as.lib diff --new-file -ur orig/as/mops.c as/mops.c --- orig/as/mops.c Sat Jul 10 19:36:37 1993 +++ as/mops.c Mon Jan 8 13:03:27 1996 @@ -547,7 +547,7 @@ mcount += asize; } else if (lastexp.offset != 0x0 || - eap->base == BPREG && eap->index == NOREG || + (eap->base == BPREG && eap->index == NOREG) || eap->base == EBPREG) { postb |= MEM1_MOD; @@ -917,8 +917,8 @@ if (!(lastexp.data & UNDBIT) && lastexp.offset != 0x1) { if (eap->base <= MAX16BITINDREG || - lastexp.offset != 0x2 && lastexp.offset != 0x4 && - lastexp.offset != 0x8) + (lastexp.offset != 0x2 && lastexp.offset != 0x4 && + lastexp.offset != 0x8)) error(ILL_SCALE); else { @@ -1107,16 +1107,16 @@ PUBLIC void mcall() { - opcode_pt far; + opcode_pt far_diff; bool_t indirect; register struct sym_s *symptr; - far = 0x0; + far_diff = 0x0; if (sym == IDENT && (symptr = gsymptr)->type & MNREGBIT && symptr->data & SIZEBIT && symptr->value_reg_or_op.op.routine == FAROP) { - far = 0x8; + far_diff = 0x8; getsym(); } indirect = FALSE; @@ -1174,7 +1174,7 @@ opcode = 0x20; else opcode = 0x10; - postb |= opcode + far; + postb |= opcode + far_diff; opcode = 0xFF; } } @@ -1589,9 +1589,9 @@ { if (target.indcount == 0x0 && (target.base == ALREG || target.base == AXREG || - target.base == EAXREG && + (target.base == EAXREG && (source.displ.data & (FORBIT | RELBIT | UNDBIT) || - !is8bitsignedoffset(source.displ.offset)))) + !is8bitsignedoffset(source.displ.offset))))) { opcode |= 0x04 | segword; buildimm(&source, FALSE); diff --new-file -ur orig/as/pops.c as/pops.c --- orig/as/pops.c Sun Jul 11 13:43:21 1993 +++ as/pops.c Mon Jan 8 11:40:14 1996 @@ -72,7 +72,7 @@ register struct sym_s *symptr; { if ((symptr->type & LABIT || - symptr->data & IMPBIT && !(symptr->data & UNDBIT)) && + (symptr->data & IMPBIT && !(symptr->data & UNDBIT))) && ((symptr->data ^ lcdata) & (RELBIT | SEGM))) { error(SEGREL); @@ -220,7 +220,7 @@ while (TRUE) { - if ((symptr = needlabel()) != NULL) + if ((symptr = needlabel()) != NUL_PTR) { if (symptr->type & COMMBIT) error(ALREADY); @@ -428,7 +428,7 @@ lineptr = oldlineptr; sym = oldsym; symname = oldsymname; - label = NULL; + label = NUL_PTR; } PRIVATE struct sym_s *needlabel() @@ -439,7 +439,7 @@ (symptr = gsymptr)->type & (MACBIT | MNREGBIT | VARBIT)) { error(LABEXP); - return NULL; + return NUL_PTR; } return symptr; } @@ -506,7 +506,7 @@ PUBLIC void pcomm() { - if (label == NULL) + if (label == NUL_PTR) labelerror(MISLAB); else if (label->type & VARBIT) labelerror(VARLAB); /* variable cannot be COMM'd */ @@ -520,11 +520,11 @@ { unsigned oldseg; - if (label != NULL) + if (label != NUL_PTR) labelerror(ILLAB); oldseg = lcdata & SEGM; setloc(BSSLOC); - if ((label = needlabel()) != NULL && checksegrel(label)) + if ((label = needlabel()) != NUL_PTR && checksegrel(label)) { /* Like import. */ if (label->type & (EXPBIT | LABIT)) @@ -583,7 +583,7 @@ PUBLIC void pendb() { - if (label != NULL) + if (label != NUL_PTR) labelerror(ILLAB); if (blocklevel == 0) error(ENDBBAD); @@ -645,7 +645,7 @@ { register struct sym_s *labptr; - if ((labptr = label) == NULL) + if ((labptr = label) == NUL_PTR) labelerror(MISLAB); else if (labptr->type & COMMBIT) showredefinedlabel(); /* common cannot be EQU'd */ @@ -812,7 +812,7 @@ error(NOIMPORT); while (TRUE) { - if ((symptr = needlabel()) != NULL && checksegrel(symptr)) + if ((symptr = needlabel()) != NUL_PTR && checksegrel(symptr)) { if (symptr->type & (COMMBIT | EXPBIT | LABIT)) /* IMPORT is null if label (to be) declared */ @@ -855,7 +855,7 @@ PUBLIC void ploc() { - if (label != NULL) + if (label != NUL_PTR) labelerror(ILLAB); absexpres(); if (!(lastexp.data & UNDBIT)) @@ -892,7 +892,7 @@ PUBLIC void porg() { - if (label != NULL) + if (label != NUL_PTR) labelerror(ILLAB); absexpres(); if (!((lcdata = lastexp.data) & UNDBIT)) @@ -914,7 +914,7 @@ PUBLIC void psect() { - if (label != NULL) + if (label != NUL_PTR) labelerror(ILLAB); while (sym == IDENT) { @@ -947,7 +947,7 @@ { register struct sym_s *labptr; - if ((labptr = label) == NULL) + if ((labptr = label) == NUL_PTR) labelerror(MISLAB); else if (labptr->type & COMMBIT) labelerror(RELAB); /* common cannot be SET'd */ @@ -1024,7 +1024,7 @@ lastexp.data = labptr->data; lastexp.offset = labptr->value_reg_or_op.value; popflags = POPLONG | POPHI | POPLO; - label = NULL; /* show handled by COMM, EQU or SET */ + label = NUL_PTR; /* show handled by COMM, EQU or SET */ } /* set location segment */ diff --new-file -ur orig/as/readsrc.c as/readsrc.c --- orig/as/readsrc.c Sat Jul 10 20:06:34 1993 +++ as/readsrc.c Mon Jan 8 11:23:24 1996 @@ -23,7 +23,6 @@ int open P((const char *path, int oflag, ...)); int read P((int fd, void *buf, unsigned nbytes)); #else -#undef NULL #include #include #include @@ -220,7 +219,7 @@ char *oldbufptr; struct schain_s *parameters; char paramnum; - unsigned char remaining; /* space remaining in line + 2 */ + unsigned int remaining; /* space remaining in line + 2 */ /* value 0 not used except for temp predec */ /* value 1 means error already gen */ /* values 1 and 2 mean no space */ @@ -244,9 +243,9 @@ { parameters = macstak->parameters; for (paramnum = *bufptr++; paramnum-- != '0';) - if ((parameters = parameters->next) == NULL) + if ((parameters = parameters->next) == NUL_PTR) break; - if (parameters != NULL) + if (parameters != NUL_PTR) { for (oldbufptr = bufptr, bufptr = parameters->string; *bufptr++ != 0;) diff --new-file -ur orig/as/table.c as/table.c --- orig/as/table.c Sat Jul 10 20:08:14 1993 +++ as/table.c Mon Jan 8 11:20:14 1996 @@ -9,7 +9,6 @@ #ifdef STDC_HEADERS_MISSING int memcmp P((const void *s1, const void *s2, unsigned n)); #else -#undef NULL #include #endif @@ -809,7 +808,7 @@ * If string is not found and ifflag is TRUE, string is added to table, with * type = 0 * data = inidata (RELBIT | UNDBIT, possibly with IMPBIT | SEGM) - * Returns pointer to symbol entry (NULL if not found and not installed) + * Returns pointer to symbol entry (NUL_PTR if not found and not installed) * unless symbol table overflows, when routine aborts. */ @@ -855,7 +854,7 @@ nameptr = symname; if ((symptr = *(hashptr = spt + (hashval ^ (hconv(nameptr[0]) << 1)) % SPTSIZ)) - != NULL) + != NUL_PTR) { do { @@ -873,9 +872,9 @@ if (memcmp(symptr->name, nameptr, length) == 0) return symptr; } - while ((symptr = symptr->next) != NULL); + while ((symptr = symptr->next) != NUL_PTR); - /* Calculate last non-NULL hash ptr. + /* Calculate last non-NUL_PTR hash ptr. * This is faster than keeping hashptr up to date in previous loop * since most lookups are successful and hash ptr is not needed. */ @@ -884,10 +883,10 @@ symptr = *hashptr; hashptr = &symptr->next; } - while (symptr->next != NULL); + while (symptr->next != NUL_PTR); } if (!ifflag) - return NULL; + return NUL_PTR; align(heapptr); if (heapptr >= heapend) fatalerror(SYMOV); @@ -900,7 +899,7 @@ symptr->type = 0; symptr->data = inidata; symptr->length = length; - symptr->value_reg_or_op.value = (unsigned) (symptr->next = NULL); + symptr->value_reg_or_op.value = (unsigned) (symptr->next = NUL_PTR); heapptr = symptr->name; do *heapptr++ = *nameptr++; @@ -917,7 +916,7 @@ register struct sym_s *symptr; printf("%04x ", hashval); - for (symptr = spt[hashval]; symptr != NULL; symptr = symptr->next) + for (symptr = spt[hashval]; symptr != NUL_PTR; symptr = symptr->next) printf("%s ", symptr->name); printf("\n"); } diff --new-file -ur orig/as/type.h as/type.h --- orig/as/type.h Sat Jul 10 18:50:14 1993 +++ as/type.h Mon Jan 8 11:20:21 1996 @@ -46,7 +46,7 @@ struct sym_s { - struct sym_s *next; /* next symbol in hash chain (NULL if none) */ + struct sym_s *next; /* next symbol in hash chain (NUL_PTR if none) */ /* zero offset because it is accessed most */ unsigned char type; unsigned char data; /* flags valid for expressions as well as syms*/ diff --new-file -ur orig/ld/Makefile ld/Makefile --- orig/ld/Makefile Sat Feb 19 22:31:54 1994 +++ ld/Makefile Mon Jan 8 11:52:56 1996 @@ -1,5 +1,11 @@ -CFLAGS =-O -DBSD_A_OUT -DSTANDARD_GNU_A_OUT -LDFLAGS =-N -s +WFLAGS=-Wall +WALL =-Wall -Wtraditional -Wshadow -Wid-clash-14 -Wpointer-arith \ + -Wcast-qual -Wcast-align -Wconversion -Waggregate-return \ + -Wstrict-prototypes -Wmissing-prototypes -Wredundant-decls \ + -Wnested-externs -Winline + +CFLAGS =$(WALL) -O -b i486-linuxaout +LDFLAGS =-s -N -static -b i486-linuxaout OBJS =dumps.o io.o ld.o readobj.o table.o typeconv.o writebin.o diff --new-file -ur orig/ld/a.out.h ld/a.out.h --- orig/ld/a.out.h Thu Jan 1 01:00:00 1970 +++ ld/a.out.h Fri Jan 5 18:13:07 1996 @@ -0,0 +1,110 @@ +/* The header file describes the format of executable files. */ + +#ifndef _AOUT_H +#define _AOUT_H + +struct exec { /* a.out header */ + unsigned char a_magic[2]; /* magic number */ + unsigned char a_flags; /* flags, see below */ + unsigned char a_cpu; /* cpu id */ + unsigned char a_hdrlen; /* length of header */ + unsigned char a_unused; /* reserved for future use */ + unsigned short a_version; /* version stamp (not used at present) */ + long a_text; /* size of text segement in bytes */ + long a_data; /* size of data segment in bytes */ + long a_bss; /* size of bss segment in bytes */ + long a_entry; /* entry point */ + long a_total; /* total memory allocated */ + long a_syms; /* size of symbol table */ + + /* SHORT FORM ENDS HERE */ + long a_trsize; /* text relocation size */ + long a_drsize; /* data relocation size */ + long a_tbase; /* text relocation base */ + long a_dbase; /* data relocation base */ +}; + +#define A_MAGIC0 (unsigned char) 0x01 +#define A_MAGIC1 (unsigned char) 0x03 +#define BADMAG(X) ((X).a_magic[0] != A_MAGIC0 ||(X).a_magic[1] != A_MAGIC1) + +/* CPU Id of TARGET machine (byte order coded in low order two bits) */ +#define A_NONE 0x00 /* unknown */ +#define A_I8086 0x04 /* intel i8086/8088 */ +#define A_M68K 0x0B /* motorola m68000 */ +#define A_NS16K 0x0C /* national semiconductor 16032 */ +#define A_I80386 0x10 /* intel i80386 */ +#define A_SPARC 0x17 /* Sun SPARC */ + +#define A_BLR(cputype) ((cputype&0x01)!=0) /* TRUE if bytes left-to-right */ +#define A_WLR(cputype) ((cputype&0x02)!=0) /* TRUE if words left-to-right */ + +/* Flags. */ +#define A_UZP 0x01 /* unmapped zero page (pages) */ +#define A_PAL 0x02 /* page aligned executable */ +#define A_NSYM 0x04 /* new style symbol table */ +#define A_EXEC 0x10 /* executable */ +#define A_SEP 0x20 /* separate I/D */ +#define A_PURE 0x40 /* pure text */ /* not used */ +#define A_TOVLY 0x80 /* text overlay */ /* not used */ + +/* Offsets of various things. */ +#define A_MINHDR 32 +#define A_TEXTPOS(X) ((long)(X).a_hdrlen) +#define A_DATAPOS(X) (A_TEXTPOS(X) + (X).a_text) +#define A_HASRELS(X) ((X).a_hdrlen > (unsigned char) A_MINHDR) +#define A_HASEXT(X) ((X).a_hdrlen > (unsigned char) (A_MINHDR + 8)) +#define A_HASLNS(X) ((X).a_hdrlen > (unsigned char) (A_MINHDR + 16)) +#define A_HASTOFF(X) ((X).a_hdrlen > (unsigned char) (A_MINHDR + 24)) +#define A_TRELPOS(X) (A_DATAPOS(X) + (X).a_data) +#define A_DRELPOS(X) (A_TRELPOS(X) + (X).a_trsize) +#define A_SYMPOS(X) (A_TRELPOS(X) + (A_HASRELS(X) ? \ + ((X).a_trsize + (X).a_drsize) : 0)) + +struct reloc { + long r_vaddr; /* virtual address of reference */ + unsigned short r_symndx; /* internal segnum or extern symbol num */ + unsigned short r_type; /* relocation type */ +}; + +/* r_tyep values: */ +#define R_ABBS 0 +#define R_RELLBYTE 2 +#define R_PCRBYTE 3 +#define R_RELWORD 4 +#define R_PCRWORD 5 +#define R_RELLONG 6 +#define R_PCRLONG 7 +#define R_REL3BYTE 8 +#define R_KBRANCHE 9 + +/* r_symndx for internal segments */ +#define S_ABS ((unsigned short)-1) +#define S_TEXT ((unsigned short)-2) +#define S_DATA ((unsigned short)-3) +#define S_BSS ((unsigned short)-4) + +struct nlist { /* symbol table entry */ + char n_name[8]; /* symbol name */ + long n_value; /* value */ + unsigned char n_sclass; /* storage class */ + unsigned char n_numaux; /* number of auxiliary entries (not used) */ + unsigned short n_type; /* language base and derived type (not used) */ +}; + +/* Low bits of storage class (section). */ +#define N_SECT 07 /* section mask */ +#define N_UNDF 00 /* undefined */ +#define N_ABS 01 /* absolute */ +#define N_TEXT 02 /* text */ +#define N_DATA 03 /* data */ +#define N_BSS 04 /* bss */ +#define N_COMM 05 /* (common) */ + +/* High bits of storage class. */ +#define N_CLASS 0370 /* storage class mask */ +#define C_NULL +#define C_EXT 0020 /* external symbol */ +#define C_STAT 0030 /* static */ + +#endif /* _AOUT_H */ diff --new-file -ur orig/ld/a_out.h ld/a_out.h --- orig/ld/a_out.h Thu Jan 1 01:00:00 1970 +++ ld/a_out.h Fri Jan 5 18:13:07 1996 @@ -0,0 +1,110 @@ +/* The header file describes the format of executable files. */ + +#ifndef _AOUT_H +#define _AOUT_H + +struct exec { /* a.out header */ + unsigned char a_magic[2]; /* magic number */ + unsigned char a_flags; /* flags, see below */ + unsigned char a_cpu; /* cpu id */ + unsigned char a_hdrlen; /* length of header */ + unsigned char a_unused; /* reserved for future use */ + unsigned short a_version; /* version stamp (not used at present) */ + long a_text; /* size of text segement in bytes */ + long a_data; /* size of data segment in bytes */ + long a_bss; /* size of bss segment in bytes */ + long a_entry; /* entry point */ + long a_total; /* total memory allocated */ + long a_syms; /* size of symbol table */ + + /* SHORT FORM ENDS HERE */ + long a_trsize; /* text relocation size */ + long a_drsize; /* data relocation size */ + long a_tbase; /* text relocation base */ + long a_dbase; /* data relocation base */ +}; + +#define A_MAGIC0 (unsigned char) 0x01 +#define A_MAGIC1 (unsigned char) 0x03 +#define BADMAG(X) ((X).a_magic[0] != A_MAGIC0 ||(X).a_magic[1] != A_MAGIC1) + +/* CPU Id of TARGET machine (byte order coded in low order two bits) */ +#define A_NONE 0x00 /* unknown */ +#define A_I8086 0x04 /* intel i8086/8088 */ +#define A_M68K 0x0B /* motorola m68000 */ +#define A_NS16K 0x0C /* national semiconductor 16032 */ +#define A_I80386 0x10 /* intel i80386 */ +#define A_SPARC 0x17 /* Sun SPARC */ + +#define A_BLR(cputype) ((cputype&0x01)!=0) /* TRUE if bytes left-to-right */ +#define A_WLR(cputype) ((cputype&0x02)!=0) /* TRUE if words left-to-right */ + +/* Flags. */ +#define A_UZP 0x01 /* unmapped zero page (pages) */ +#define A_PAL 0x02 /* page aligned executable */ +#define A_NSYM 0x04 /* new style symbol table */ +#define A_EXEC 0x10 /* executable */ +#define A_SEP 0x20 /* separate I/D */ +#define A_PURE 0x40 /* pure text */ /* not used */ +#define A_TOVLY 0x80 /* text overlay */ /* not used */ + +/* Offsets of various things. */ +#define A_MINHDR 32 +#define A_TEXTPOS(X) ((long)(X).a_hdrlen) +#define A_DATAPOS(X) (A_TEXTPOS(X) + (X).a_text) +#define A_HASRELS(X) ((X).a_hdrlen > (unsigned char) A_MINHDR) +#define A_HASEXT(X) ((X).a_hdrlen > (unsigned char) (A_MINHDR + 8)) +#define A_HASLNS(X) ((X).a_hdrlen > (unsigned char) (A_MINHDR + 16)) +#define A_HASTOFF(X) ((X).a_hdrlen > (unsigned char) (A_MINHDR + 24)) +#define A_TRELPOS(X) (A_DATAPOS(X) + (X).a_data) +#define A_DRELPOS(X) (A_TRELPOS(X) + (X).a_trsize) +#define A_SYMPOS(X) (A_TRELPOS(X) + (A_HASRELS(X) ? \ + ((X).a_trsize + (X).a_drsize) : 0)) + +struct reloc { + long r_vaddr; /* virtual address of reference */ + unsigned short r_symndx; /* internal segnum or extern symbol num */ + unsigned short r_type; /* relocation type */ +}; + +/* r_tyep values: */ +#define R_ABBS 0 +#define R_RELLBYTE 2 +#define R_PCRBYTE 3 +#define R_RELWORD 4 +#define R_PCRWORD 5 +#define R_RELLONG 6 +#define R_PCRLONG 7 +#define R_REL3BYTE 8 +#define R_KBRANCHE 9 + +/* r_symndx for internal segments */ +#define S_ABS ((unsigned short)-1) +#define S_TEXT ((unsigned short)-2) +#define S_DATA ((unsigned short)-3) +#define S_BSS ((unsigned short)-4) + +struct nlist { /* symbol table entry */ + char n_name[8]; /* symbol name */ + long n_value; /* value */ + unsigned char n_sclass; /* storage class */ + unsigned char n_numaux; /* number of auxiliary entries (not used) */ + unsigned short n_type; /* language base and derived type (not used) */ +}; + +/* Low bits of storage class (section). */ +#define N_SECT 07 /* section mask */ +#define N_UNDF 00 /* undefined */ +#define N_ABS 01 /* absolute */ +#define N_TEXT 02 /* text */ +#define N_DATA 03 /* data */ +#define N_BSS 04 /* bss */ +#define N_COMM 05 /* (common) */ + +/* High bits of storage class. */ +#define N_CLASS 0370 /* storage class mask */ +#define C_NULL +#define C_EXT 0020 /* external symbol */ +#define C_STAT 0030 /* static */ + +#endif /* _AOUT_H */ diff --new-file -ur orig/ld/const.h ld/const.h --- orig/ld/const.h Sat Feb 19 22:35:46 1994 +++ ld/const.h Mon Jan 8 11:49:11 1996 @@ -3,7 +3,7 @@ /* Copyright (C) 1994 Bruce Evans */ #define FALSE 0 -#define NULL 0 +#define NUL_PTR ((void*)0) #define TRUE 1 #define EXTERN extern diff --new-file -ur orig/ld/dumps.c ld/dumps.c --- orig/ld/dumps.c Sat Feb 19 22:35:46 1994 +++ ld/dumps.c Mon Jan 8 11:49:22 1996 @@ -13,7 +13,7 @@ { struct modstruct *modptr; - for (modptr = modfirst; modptr != NULL; modptr = modptr->modnext) + for (modptr = modfirst; modptr != NUL_PTR; modptr = modptr->modnext) { putstr(modptr->loadflag ? "L " : " "); putbstr(20, modptr->modname); @@ -31,11 +31,11 @@ struct symstruct *symptr; char uflag; - for (modptr = modfirst; modptr != NULL; modptr = modptr->modnext) + for (modptr = modfirst; modptr != NUL_PTR; modptr = modptr->modnext) if (modptr->loadflag) { for (symparray = modptr->symparray; - (symptr = *symparray) != NULL; ++symparray) + (symptr = *symparray) != NUL_PTR; ++symparray) if (symptr->modptr == modptr) { uflag = FALSE; diff --new-file -ur orig/ld/include/fcntl.h ld/include/fcntl.h --- orig/ld/include/fcntl.h Thu Jan 1 01:00:00 1970 +++ ld/include/fcntl.h Sat Jan 6 13:35:44 1996 @@ -0,0 +1,2 @@ +#define O_RDONLY 0 +#define O_WRONLY 1 diff --new-file -ur orig/ld/io.c ld/io.c --- orig/ld/io.c Sun Apr 17 22:59:35 1994 +++ ld/io.c Mon Jan 8 12:32:43 1996 @@ -6,20 +6,19 @@ #include "obj.h" /* needed for LONG_OFFSETS and offset_t */ #include "type.h" #include "globvar.h" +#include #ifdef STDC_HEADERS_MISSING void exit P((int status)); void *malloc P((unsigned size)); #else -#undef NULL #include #endif #ifdef POSIX_HEADERS_MISSING -#define O_RDONLY 0 -#define O_WRONLY 1 #define SEEK_SET 0 #define STDOUT_FILENO 0 +#include #include #define mode_t unsigned short #define off_t long @@ -33,7 +32,6 @@ mode_t umask P((int oldmask)); int write P((int fd, const void *buf, unsigned nbytes)); #else -#undef NULL #include #include #include @@ -46,6 +44,9 @@ #define INBUFSIZE 1024 #define OUTBUFSIZE 2048 #define TRELBUFSIZE 1024 +#ifndef O_BINARY +#define O_BINARY 0 +#endif #ifdef BSD_A_OUT PRIVATE char *drelbuf; /* extra output buffer for data relocations */ @@ -197,7 +198,7 @@ { closein(); inputname = filename; /* this relies on filename being static */ - if ((infd = open(filename, O_RDONLY)) < 0) + if ((infd = open(filename, O_BINARY|O_RDONLY)) < 0) inputerror("cannot open"); inbufptr = inbufend = inbuf; } @@ -209,7 +210,7 @@ struct stat statbuf; outputname = filename; - if ((outfd = creat(filename, CREAT_PERMS)) == ERR) + if ((outfd = open(filename, O_BINARY|O_RDWR|O_CREAT|O_TRUNC, CREAT_PERMS)) == ERR) outputerror("cannot open"); if (fstat(outfd, &statbuf) != 0) outputerror("cannot stat"); @@ -220,7 +221,7 @@ #endif outbufptr = outbuf; #ifdef BSD_A_OUT - if ((trelfd = open(filename, O_WRONLY)) == ERR) + if ((trelfd = open(filename, O_BINARY|O_WRONLY|O_CREAT|O_TRUNC, CREAT_PERMS)) == ERR) outputerror("cannot reopen"); trelbufptr = trelbuf; #endif @@ -528,7 +529,7 @@ putstr(message); putstr(" in file "); putstr(inputname); - if (archentry != NULL) + if (archentry != NUL_PTR) { putbyte('('); putstr(archentry); @@ -536,7 +537,7 @@ } putstr("; using definition in "); putstr(deffilename); - if (defarchentry != NULL) + if (defarchentry != NUL_PTR) { putbyte('('); putstr(defarchentry); @@ -560,7 +561,7 @@ } PUBLIC void size_error(seg, count, size) -char seg; +int seg; offset_t count; offset_t size; { diff --new-file -ur orig/ld/ld.c ld/ld.c --- orig/ld/ld.c Sat Feb 19 22:35:47 1994 +++ ld/ld.c Mon Jan 8 11:49:46 1996 @@ -12,7 +12,6 @@ char *strcat P((char *dest, const char *src)); unsigned long strtoul P((const char *s, char **endptr, int base)); #else -#undef NULL #include #include #include @@ -22,23 +21,23 @@ #define R_OK 0 int access P((const char *path, int amode)); #else -#undef NULL #include #endif #define MAX_LIBS (NR_STDLIBS + 5) +#ifdef MC6809 #define NR_STDLIBS 1 +#else +#define NR_STDLIBS 0 +#endif PUBLIC long text_base_address; /* XXX */ +PUBLIC int doscomfile = 0; PRIVATE bool_t flag[128]; PRIVATE char *libs[MAX_LIBS] = { #ifdef MC6809 "/usr/local/lib/m09/", -#else - /* One of the following values will be inserted at run time. */ -# define std386lib "/usr/local/lib/i386/" -# define std86lib "/usr/local/lib/i86/" #endif 0 }; @@ -67,10 +66,6 @@ char *path; int i; -#ifndef MC6809 - libs[0] = flag['3'] ? std386lib : std86lib; -#endif - for (i = lastlib - 1; i >= 0; --i) { path = ourmalloc(strlen(libs[i]) + strlen(fn) + 1); @@ -80,7 +75,7 @@ return path; ourfree(path); } - return NULL; + return NUL_PTR; } PUBLIC int main(argc, argv) @@ -104,7 +99,7 @@ #ifndef MC6809 flag['z'] = flag['3'] = sizeof(char *) >= 4; #endif - outfilename = NULL; + outfilename = NUL_PTR; for (argn = 1; argn < argc; ++argn) { arg = argv[argn]; @@ -133,9 +128,17 @@ if (arg[1] == '0') /* flag 0 is negative logic flag 3 */ flag['3'] = !flag['0']; break; + case 'd': /* Make DOS com file */ + flag['3'] = FALSE; + flag['z'] = FALSE; + flag['0'] = TRUE; + flag['s'] = TRUE; + flag['d'] = TRUE; + text_base_address = 0x100; + break; case 'C': /* startfile name */ tfn = buildname(crtprefix, arg + 2, crtsuffix); - if ((infilename = expandlib(tfn)) == NULL) + if ((infilename = expandlib(tfn)) == NUL_PTR) fatalerror(tfn); /* XXX - need to describe failure */ readsyms(infilename, flag['t']); break; @@ -146,7 +149,7 @@ fatalerror("too many library paths"); break; case 'O': /* library file name */ - if ((infilename = expandlib(arg + 2)) == NULL) + if ((infilename = expandlib(arg + 2)) == NUL_PTR) fatalerror(arg); /* XXX */ readsyms(infilename, flag['t']); break; @@ -154,18 +157,18 @@ if (arg[2] != 0 || ++argn >= argc) usage(); errno = 0; - text_base_address = strtoul(argv[argn], (char **) NULL, 16); + text_base_address = strtoul(argv[argn], (char **) NUL_PTR, 16); if (errno != 0) use_error("invalid text address"); break; case 'l': /* library name */ tfn = buildname(libprefix, arg + 2, libsuffix); - if ((infilename = expandlib(tfn)) == NULL) + if ((infilename = expandlib(tfn)) == NUL_PTR) fatalerror(tfn); /* XXX */ readsyms(infilename, flag['t']); break; case 'o': /* output file name */ - if (arg[2] != 0 || ++argn >= argc || outfilename != NULL) + if (arg[2] != 0 || ++argn >= argc || outfilename != NUL_PTR) usage(); outfilename = argv[argn]; break; @@ -173,8 +176,9 @@ usage(); } } + doscomfile = flag['d']; linksyms(flag['r']); - if (outfilename == NULL) + if (outfilename == NUL_PTR) outfilename = "a.out"; writebin(outfilename, flag['i'], flag['3'], flag['s'], flag['z'] & flag['3']); diff --new-file -ur orig/ld/make.bat ld/make.bat --- orig/ld/make.bat Thu Jan 1 01:00:00 1970 +++ ld/make.bat Mon Jan 8 13:07:56 1996 @@ -0,0 +1,2 @@ +cl -nologo -O -DPOSIX_HEADERS_MISSING -o ld.exe dumps.c io.c ld.c readobj.c table.c typeconv.c writebin.c +del *.obj diff --new-file -ur orig/ld/readobj.c ld/readobj.c --- orig/ld/readobj.c Sat Feb 19 22:35:47 1994 +++ ld/readobj.c Mon Jan 8 11:50:02 1996 @@ -14,7 +14,6 @@ char *strncpy P((char *dest, const char *src, unsigned n)); unsigned long strtoul P((const char *s, char **endptr, int base)); #else -#undef NULL #include #include #endif @@ -51,9 +50,9 @@ PUBLIC void objinit() { - modfirst = modlast = NULL; - entryfirst = entrylast = NULL; - redfirst = redlast = NULL; + modfirst = modlast = NUL_PTR; + entryfirst = entrylast = NUL_PTR; + redfirst = redlast = NUL_PTR; } /* read all symbol definitions in an object file */ @@ -76,7 +75,7 @@ case OMAGIC: seekin((unsigned long) 0); for (modcount = readfileheader(); modcount-- != 0;) - readmodule(filename, (char *) NULL); + readmodule(filename, (char *) NUL_PTR); break; default: seekin((unsigned long) 0); @@ -118,7 +117,7 @@ do *endptr = 0; while (endptr > nameptr && *--endptr == ' '); - return strtoul(arheader.ar_size, (char **) NULL, 0); + return strtoul(arheader.ar_size, (char **) NUL_PTR, 0); } /* read and check file header of the object file just opened */ @@ -185,7 +184,7 @@ { symname = readstring(); if ((flags = symdptr->dflags) & (E_MASK | I_MASK) && - (symptr = findsym(symname)) != NULL) + (symptr = findsym(symname)) != NUL_PTR) { /* weaken segment-checking by letting the maximum segment @@ -220,7 +219,7 @@ if (flags & N_MASK) entrysym(symptr); } - *symparray = NULL; + *symparray = NUL_PTR; } /* put symbol on entry symbol list if it is not already */ @@ -230,13 +229,13 @@ { register struct entrylist *elptr; - for (elptr = entryfirst; elptr != NULL; elptr = elptr->elnext) + for (elptr = entryfirst; elptr != NUL_PTR; elptr = elptr->elnext) if (symptr == elptr->elsymptr) return; elptr = (struct entrylist *) ourmalloc(sizeof(struct entrylist)); - elptr->elnext = NULL; + elptr->elnext = NUL_PTR; elptr->elsymptr = symptr; - if (entryfirst == NULL) + if (entryfirst == NUL_PTR) entryfirst = elptr; else entrylast->elnext = elptr; @@ -263,7 +262,7 @@ readin((char *) &modheader, sizeof modheader); modptr = (struct modstruct *) ourmalloc(sizeof(struct modstruct)); - modptr->modnext = NULL; + modptr->modnext = NUL_PTR; modptr->textoffset = c4u4(modheader.htextoffset); modptr->class = modheader.hclass; readin(modptr->segmaxsize, sizeof modptr->segmaxsize); @@ -281,7 +280,7 @@ cptr += count; } } - if (modfirst == NULL) + if (modfirst == NUL_PTR) modfirst = modptr; else modlast->modnext = modptr; @@ -298,11 +297,11 @@ if (symptr->modptr->class != (class = modlast->class)) for (rlptr = redfirst;; rlptr = rlptr->rlnext) { - if (rlptr == NULL) + if (rlptr == NUL_PTR) { rlptr = (struct redlist *) ourmalloc(sizeof(struct redlist)); - rlptr->rlnext = NULL; + rlptr->rlnext = NUL_PTR; rlptr->rlsymptr = symptr; if (symptr->modptr->class < class) /* prefer lower class - put other on redlist */ @@ -317,7 +316,7 @@ rlptr->rlvalue = symptr->value; symptr->value = value; } - if (redfirst == NULL) + if (redfirst == NUL_PTR) redfirst = rlptr; else redlast->rlnext = rlptr; diff --new-file -ur orig/ld/table.c ld/table.c --- orig/ld/table.c Sat Feb 19 22:35:47 1994 +++ ld/table.c Mon Jan 8 12:31:29 1996 @@ -10,9 +10,10 @@ #ifdef STDC_HEADERS_MISSING void *malloc P((unsigned size)); +char * strcpy P((char* dest, char* src)); #else -#undef NULL #include +#include #endif #define GOLDEN 157 /* GOLDEN/HASHTABSIZE approx golden ratio */ @@ -32,13 +33,13 @@ for (i = sizeof(int) <= 2 ? 0xE000 : (unsigned) 0x38000; i != 0; i -= 512) - if ((tableptr = malloc(i)) != NULL) + if ((tableptr = malloc(i)) != NUL_PTR) break; - if (tableptr == NULL) + if (tableptr == NUL_PTR) outofmemory(); tableend = tableptr + i; for (i = 0; i < HASHTABSIZE; i++) - hashtab[i] = NULL; + hashtab[i] = NUL_PTR; } /* add named symbol to end of table - initialise only name and next fields */ @@ -48,12 +49,12 @@ char *name; { struct symstruct **hashptr; - struct symstruct *oldsymptr; + struct symstruct *oldsymptr = 0; struct symstruct *symptr; hashptr = gethashptr(name); symptr = *hashptr; - while (symptr != NULL) + while (symptr != NUL_PTR) { oldsymptr = symptr; symptr = symptr->next; @@ -62,11 +63,11 @@ symptr = (struct symstruct *) tableptr; if ((tableptr = symptr->name + (strlen(name) + 1)) > tableend) outofmemory(); - symptr->modptr = NULL; - symptr->next = NULL; + symptr->modptr = NUL_PTR; + symptr->next = NUL_PTR; if (name != symptr->name) strcpy(symptr->name, name); /* should't happen */ - if (*hashptr == NULL) + if (*hashptr == NUL_PTR) *hashptr = symptr; else oldsymptr->next = symptr; @@ -81,7 +82,7 @@ struct symstruct *symptr; symptr = *gethashptr(name); - while (symptr != NULL && (!(symptr->flags & (E_MASK | I_MASK)) || + while (symptr != NUL_PTR && (!(symptr->flags & (E_MASK | I_MASK)) || strcmp(symptr->name, name) != 0)) symptr = symptr->next; return symptr; diff --new-file -ur orig/ld/writebin.c ld/writebin.c --- orig/ld/writebin.c Sat Feb 19 22:37:05 1994 +++ ld/writebin.c Mon Jan 8 12:36:14 1996 @@ -27,7 +27,11 @@ # define n_was_strx n_un.n_strx # define n_was_type n_desc # else /* not BSD_A_OUT */ -# include "a.out.h" /* maybe local copy of for X-link */ +# ifdef MSDOS +# include "a_out.h" +# else +# include "a.out.h" /* maybe local copy of for X-link */ +# endif # define n_was_name n_name # define n_was_numaux n_numaux # define n_was_other n_other @@ -46,7 +50,6 @@ #ifdef STDC_HEADERS_MISSING void *memset P((void *s, int c, unsigned n)); #else -#undef NULL #include #endif @@ -58,10 +61,10 @@ # ifdef STANDARD_GNU_A_OUT # define FILEHEADERLENGTH 32 # else -# define FILEHEADERLENGTH 48 +# define FILEHEADERLENGTH (doscomfile?0:48) # endif # else -# define FILEHEADERLENGTH A_MINHDR +# define FILEHEADERLENGTH (doscomfile?0:A_MINHDR) /* part of header not counted in offsets */ # endif #endif @@ -139,6 +142,8 @@ #endif FORWARD void writenulls P((offset_t count)); +extern int doscomfile; + /* link all symbols connected to entry symbols */ PUBLIC void linksyms(argreloc_output) @@ -153,31 +158,31 @@ reloc_output = argreloc_output; if (argreloc_output) { - if (modfirst->modnext != NULL) + if (modfirst->modnext != NUL_PTR) fatalerror("relocatable output only works for one input file"); - for (modptr = modfirst; modptr != NULL; modptr = modptr->modnext) + for (modptr = modfirst; modptr != NUL_PTR; modptr = modptr->modnext) modptr->loadflag = TRUE; return; } #endif - if ((symptr = findsym("_main")) != NULL) + if ((symptr = findsym("_main")) != NUL_PTR) entrysym(symptr); do { - if ((elptr = entryfirst) == NULL) + if ((elptr = entryfirst) == NUL_PTR) fatalerror("no start symbol"); - for (modptr = modfirst; modptr != NULL; modptr = modptr->modnext) + for (modptr = modfirst; modptr != NUL_PTR; modptr = modptr->modnext) modptr->loadflag = FALSE; - for (; elptr != NULL; elptr = elptr->elnext) + for (; elptr != NUL_PTR; elptr = elptr->elnext) linkrefs(elptr->elsymptr->modptr); - if ((symptr = findsym("start")) != NULL) + if ((symptr = findsym("start")) != NUL_PTR) linkrefs(symptr->modptr); needlink = FALSE; { - struct redlist *prlptr; + struct redlist *prlptr = 0; struct redlist *rlptr; - for (rlptr = redfirst; rlptr != NULL; + for (rlptr = redfirst; rlptr != NUL_PTR; rlptr = (prlptr = rlptr)->rlnext) if (rlptr->rlmodptr->loadflag && rlptr->rlmodptr->class > rlptr->rlsymptr->modptr->class) @@ -233,9 +238,9 @@ } #ifdef EDOS commandname = stralloc(outfilename); - if ((cptr = strchr(commandname, ':')) != NULL) + if ((cptr = strchr(commandname, ':')) != NUL_PTR) commandname = cptr + 1; - if ((cptr = strrchr(commandname, '.')) != NULL) + if ((cptr = strrchr(commandname, '.')) != NUL_PTR) *cptr = 0; #endif @@ -261,18 +266,19 @@ symres("__end"); curseg = 0; /* text seg, s.b. variable */ symres("__etext"); + symres("__segoff"); /* calculate segment and common sizes (sum over loaded modules) */ /* use zero init of segsz[] */ /* also relocate symbols relative to starts of their segments */ - for (modptr = modfirst; modptr != NULL; modptr = modptr->modnext) + for (modptr = modfirst; modptr != NUL_PTR; modptr = modptr->modnext) if (modptr->loadflag) { register struct symstruct **symparray; register struct symstruct *symptr; for (symparray = modptr->symparray; - (symptr = *symparray) != NULL; ++symparray) + (symptr = *symparray) != NUL_PTR; ++symparray) if (symptr->modptr == modptr && !(symptr->flags & A_MASK)) { if (!(symptr->flags & (I_MASK | SA_MASK))) @@ -363,14 +369,14 @@ } /* relocate symbols by offsets of segments in memory */ - for (modptr = modfirst; modptr != NULL; modptr = modptr->modnext) + for (modptr = modfirst; modptr != NUL_PTR; modptr = modptr->modnext) if (modptr->loadflag) { register struct symstruct **symparray; register struct symstruct *symptr; for (symparray = modptr->symparray; - (symptr = *symparray) != NULL; ++symparray) + (symptr = *symparray) != NUL_PTR; ++symparray) if (symptr->modptr == modptr && !(symptr->flags & A_MASK)) { if (symptr->flags & (C_MASK | SA_MASK)) @@ -414,6 +420,7 @@ setsym("__etext", etextoffset); setsym("__edata", edataoffset); setsym("__end", endoffset = combase[NSEG - 1] + comsz[NSEG - 1]); + setsym("__segoff", (offset_t)(segadj[1]-segadj[0])/0x10); openout(outfilename); #ifdef BSD_A_OUT @@ -427,7 +434,7 @@ #else writeheader(); #endif - for (modptr = modfirst; modptr != NULL; modptr = modptr->modnext) + for (modptr = modfirst; modptr != NUL_PTR; modptr = modptr->modnext) if (modptr->loadflag) { linkmod(modptr); @@ -453,21 +460,21 @@ #ifdef BSD_A_OUT stringoff = 4; #endif - for (modptr = modfirst; modptr != NULL; modptr = modptr->modnext) + for (modptr = modfirst; modptr != NUL_PTR; modptr = modptr->modnext) if (modptr->loadflag) { register struct symstruct **symparray; register struct symstruct *symptr; for (symparray = modptr->symparray; - (symptr = *symparray) != NULL; ++symparray) + (symptr = *symparray) != NUL_PTR; ++symparray) if (symptr->modptr == modptr) { #ifdef BSD_A_OUT offtocn((char *) &extsym.n_was_strx, (offset_t) stringoff, 4); #else - strncpy((char *) &extsym.n_was_name, symptr->name, + strncpy((char *) extsym.n_was_name, symptr->name, sizeof extsym.n_was_name); #endif u4cn((char *) &extsym.n_value, (u4_t) symptr->value, @@ -506,14 +513,14 @@ #ifdef BSD_A_OUT offtocn((char *) &extsym.n_was_strx, (offset_t) stringoff, 4); writeout((char *) &extsym.n_was_strx, 4); - for (modptr = modfirst; modptr != NULL; modptr = modptr->modnext) + for (modptr = modfirst; modptr != NUL_PTR; modptr = modptr->modnext) if (modptr->loadflag) { register struct symstruct **symparray; register struct symstruct *symptr; for (symparray = modptr->symparray; - (symptr = *symparray) != NULL; ++symparray) + (symptr = *symparray) != NUL_PTR; ++symparray) if (symptr->modptr == modptr) writeout(symptr->name, strlen(symptr->name) + 1); } @@ -553,12 +560,12 @@ count = 2 + 2 + 1; /* len len nul */ startptr = findsym("start"); - for (elptr = entryfirst; elptr != NULL; elptr = elptr->elnext) + for (elptr = entryfirst; elptr != NUL_PTR; elptr = elptr->elnext) { name = idconvert(elptr, commandname); count += strlen(name) + 1 + 2 + 1; /* nul off flg */ ourfree(name); - if (startptr != NULL) + if (startptr != NUL_PTR) count += 6; /* LBSR $xxxx and LBRA $xxxx */ } return count; @@ -772,7 +779,7 @@ modptr->loadflag = TRUE; for (symparray = modptr->symparray; - (symptr = *symparray) != NULL; ++symparray) + (symptr = *symparray) != NUL_PTR; ++symparray) if (symptr->modptr->loadflag == FALSE) linkrefs(symptr->modptr); } @@ -815,7 +822,7 @@ #ifdef BSD_A_OUT if (!reloc_output) #endif - if ((symptr = findsym(name)) != NULL) + if ((symptr = findsym(name)) != NUL_PTR) symptr->value = value; } @@ -824,7 +831,7 @@ { register struct symstruct *symptr; - if ((symptr = findsym(name)) != NULL) + if ((symptr = findsym(name)) != NUL_PTR) { if ((symptr->flags & SEGM_MASK) == SEGM_MASK) symptr->flags &= ~SEGM_MASK | curseg; @@ -870,7 +877,7 @@ struct symstruct *startptr; headlength = binheaderlength(commandname); - for (elptr = entryfirst; elptr != NULL; elptr = elptr->elnext) + for (elptr = entryfirst; elptr != NUL_PTR; elptr = elptr->elnext) headlength -= 6; offset = headlength; startptr = findsym("start"); @@ -878,21 +885,21 @@ writeout(buf, 2); writechar(0xFF); /* dummy data length 0xFFFF takes everything */ writechar(0xFF); - for (elptr = entryfirst; elptr != NULL; elptr = elptr->elnext) + for (elptr = entryfirst; elptr != NUL_PTR; elptr = elptr->elnext) { name = idconvert(elptr, commandname); writeout(name, (unsigned) strlen(name) + 1); ourfree(name); - offtocn(buf, startptr == NULL ? elptr->elsymptr->value : offset, 2); + offtocn(buf, startptr == NUL_PTR ? elptr->elsymptr->value : offset, 2); writeout(buf, 2); writechar(0x82); /* 8 = set flags from here, 2 = cmd line */ offset += 6; /* LBSR $xxxx and LBRA $xxxx */ } writechar(0); - if (startptr != NULL) + if (startptr != NUL_PTR) { offset = headlength + 3; /* over 1st LBSR */ - for (elptr = entryfirst; elptr != NULL; elptr = elptr->elnext) + for (elptr = entryfirst; elptr != NUL_PTR; elptr = elptr->elnext) { writechar(0x17); /* LBSR */ offtocn(buf, startptr->value - offset, 2); @@ -975,7 +982,8 @@ sizeof header.a_total); #endif } - writeout((char *) &header, FILEHEADERLENGTH); + if( FILEHEADERLENGTH ) + writeout((char *) &header, FILEHEADERLENGTH); } #endif /* MINIX */