adapted to the system(3L) interface

This commit is contained in:
erikb 1986-03-25 10:39:23 +00:00
parent 0e39681621
commit 1afbf0e20f
12 changed files with 137 additions and 140 deletions

View file

@ -86,8 +86,6 @@ struct.c
struct.str
switch.c
switch.str
system.c
system.h
tab.c
tokenname.c
tokenname.h

View file

@ -7,6 +7,11 @@ EM = /usr/em# # where to find the ACK tree
ACK = $(EM)/bin/ack# # old ACK C compiler
EM_INCLUDES =$(EM)/h# # directory containing EM interface definition
# Libraries
SYSLIB = /user1/erikb/em/lib/libsystem.a
LIBS = $(SYSLIB)
LIB_INCLUDES = /user1/erikb/em/h
# Where to install the compiler and its driver
CEMCOM = $(BIN)/cemcom
DRIVER = $(BIN)/cem
@ -22,7 +27,7 @@ GEN = /user0/ceriel/bin/LLgen
GENOPTIONS = -vv
# Special #defines during compilation
CDEFS = $(MAP) -I$(EM_INCLUDES)
CDEFS = $(MAP) -I$(EM_INCLUDES) -I$(LIB_INCLUDES)
CFLAGS = $(CDEFS) $(COPTIONS) -O# # we cannot pass the COPTIONS to lint!
# Grammar files and their objects
@ -37,7 +42,7 @@ COBJ = main.o idf.o declarator.o decspecs.o struct.o \
input.o domacro.o replace.o init.o options.o \
scan.o skip.o stack.o type.o ch7mon.o label.o eval.o \
switch.o storage.o ival.o conversion.o \
em.o blocks.o dataflow.o system.o string.o
em.o blocks.o dataflow.o string.o
# Objects of other generated C files
GOBJ = char.o symbol2str.o next.o writeem.o
@ -54,7 +59,7 @@ GHSRC = botch_free.h dataflow.h debug.h density.h errout.h \
maxincl.h myalloc.h nobitfield.h nopp.h \
nparams.h numsize.h parbufsize.h pathlength.h predefine.h \
proc_intf.h strsize.h target_sizes.h textsize.h use_tmp.h \
bufsiz.h str_params.h spec_arith.h
str_params.h spec_arith.h
# Other generated files, for 'make clean' only
GENERATED = tab tokenfile.g Lpars.h LLfiles LL.output lint.out \
@ -76,7 +81,7 @@ cc:
make main
cem: cem.c string.o
$(CC) -O cem.c string.o -o cem
$(CC) -O cem.c string.o $(SYSLIB) -o cem
lint.cem: cem.c string.c
lint -abx cem.c
@ -124,7 +129,7 @@ writeem.h: make.emmac emcode.def
OBJ = $(COBJ) $(LOBJ) $(GOBJ)
main: $(OBJ) Makefile
$(CC) $(COPTIONS) $(LFLAGS) $(OBJ) -o main
$(CC) $(COPTIONS) $(LFLAGS) $(OBJ) $(LIBS) -o main
size main
cfiles: hfiles LLfiles $(GSRC)
@ -184,7 +189,7 @@ sim: cfiles
$(SIM) $(SIMFLAGS) `sources $(COBJ)` $(GSRC) $(LSRC)
#AUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTO
main.o: LLlex.h Lpars.h alloc.h arith.h bufsiz.h debug.h declar.h idf.h input.h inputtype.h level.h maxincl.h myalloc.h nobitfield.h nopp.h spec_arith.h specials.h system.h target_sizes.h tokenname.h type.h use_tmp.h
main.o: LLlex.h Lpars.h alloc.h arith.h debug.h declar.h idf.h input.h inputtype.h level.h maxincl.h myalloc.h nobitfield.h nopp.h spec_arith.h specials.h target_sizes.h tokenname.h type.h use_tmp.h
idf.o: LLlex.h Lpars.h align.h alloc.h arith.h assert.h botch_free.h debug.h declar.h decspecs.h def.h idf.h idfsize.h label.h level.h nobitfield.h nopp.h sizes.h spec_arith.h specials.h stack.h storage.h struct.h type.h
declarator.o: Lpars.h alloc.h arith.h botch_free.h declar.h expr.h idf.h label.h nobitfield.h nopp.h sizes.h spec_arith.h storage.h type.h
decspecs.o: Lpars.h arith.h decspecs.h def.h level.h nobitfield.h spec_arith.h type.h
@ -194,22 +199,22 @@ ch7.o: Lpars.h arith.h assert.h debug.h def.h expr.h idf.h label.h nobitfield.h
ch7bin.o: Lpars.h arith.h botch_free.h expr.h idf.h label.h nobitfield.h nopp.h spec_arith.h storage.h struct.h type.h
cstoper.o: Lpars.h arith.h expr.h idf.h label.h nobitfield.h nopp.h sizes.h spec_arith.h target_sizes.h type.h
arith.o: Lpars.h alloc.h arith.h botch_free.h expr.h field.h idf.h label.h mes.h nobitfield.h nopp.h spec_arith.h storage.h type.h
alloc.o: alloc.h assert.h debug.h myalloc.h system.h
alloc.o: alloc.h assert.h debug.h myalloc.h
code.o: LLlex.h Lpars.h alloc.h arith.h assert.h atw.h botch_free.h code.h dataflow.h debug.h declar.h decspecs.h def.h em.h expr.h idf.h label.h level.h mes.h nobitfield.h nopp.h proc_intf.h sizes.h spec_arith.h specials.h stack.h storage.h type.h use_tmp.h writeem.h
dumpidf.o: Lpars.h arith.h debug.h def.h expr.h field.h idf.h label.h nobitfield.h nopp.h spec_arith.h stack.h struct.h type.h
error.o: LLlex.h arith.h debug.h em.h errout.h expr.h label.h nopp.h proc_intf.h spec_arith.h string.h system.h tokenname.h use_tmp.h writeem.h
error.o: LLlex.h arith.h debug.h em.h errout.h expr.h label.h nopp.h proc_intf.h spec_arith.h string.h tokenname.h use_tmp.h writeem.h
field.o: Lpars.h arith.h assert.h code.h debug.h em.h expr.h field.h idf.h label.h nobitfield.h nopp.h proc_intf.h sizes.h spec_arith.h type.h writeem.h
tokenname.o: LLlex.h Lpars.h arith.h idf.h nopp.h spec_arith.h tokenname.h
LLlex.o: LLlex.h Lpars.h alloc.h arith.h assert.h class.h debug.h def.h idf.h idfsize.h input.h nopp.h numsize.h sizes.h spec_arith.h strsize.h
LLmessage.o: LLlex.h Lpars.h alloc.h arith.h idf.h nopp.h spec_arith.h
input.o: LLlex.h alloc.h arith.h assert.h bufsiz.h debug.h idepth.h input.h inputtype.h interface.h nopp.h pathlength.h spec_arith.h system.h
input.o: LLlex.h alloc.h arith.h assert.h debug.h idepth.h input.h inputtype.h interface.h nopp.h pathlength.h spec_arith.h
domacro.o: LLlex.h Lpars.h alloc.h arith.h assert.h botch_free.h class.h debug.h idf.h idfsize.h ifdepth.h input.h interface.h macro.h nopp.h nparams.h parbufsize.h spec_arith.h storage.h textsize.h
replace.o: LLlex.h alloc.h arith.h assert.h class.h debug.h idf.h input.h interface.h macro.h nopp.h pathlength.h spec_arith.h string.h strsize.h
init.o: alloc.h class.h idf.h interface.h macro.h nopp.h predefine.h string.h system.h
init.o: alloc.h class.h idf.h interface.h macro.h nopp.h predefine.h string.h
options.o: align.h arith.h class.h idf.h idfsize.h macro.h maxincl.h nobitfield.h nopp.h sizes.h spec_arith.h storage.h
scan.o: class.h idf.h input.h interface.h lapbuf.h macro.h nopp.h nparams.h
skip.o: LLlex.h arith.h class.h input.h interface.h nopp.h spec_arith.h
stack.o: Lpars.h alloc.h arith.h botch_free.h debug.h def.h em.h idf.h level.h mes.h nobitfield.h nopp.h proc_intf.h spec_arith.h stack.h storage.h struct.h system.h type.h use_tmp.h writeem.h
stack.o: Lpars.h alloc.h arith.h botch_free.h debug.h def.h em.h idf.h level.h mes.h nobitfield.h nopp.h proc_intf.h spec_arith.h stack.h storage.h struct.h type.h use_tmp.h writeem.h
type.o: Lpars.h align.h alloc.h arith.h def.h idf.h nobitfield.h nopp.h sizes.h spec_arith.h type.h
ch7mon.o: Lpars.h arith.h botch_free.h def.h expr.h idf.h label.h nobitfield.h nopp.h spec_arith.h storage.h type.h
label.o: Lpars.h arith.h def.h idf.h label.h level.h nobitfield.h nopp.h spec_arith.h type.h
@ -218,11 +223,10 @@ switch.o: arith.h assert.h botch_free.h code.h debug.h density.h em.h expr.h idf
storage.o: alloc.h assert.h botch_free.h debug.h storage.h
ival.o: Lpars.h align.h arith.h assert.h class.h debug.h def.h em.h expr.h field.h idf.h label.h level.h nobitfield.h nopp.h proc_intf.h sizes.h spec_arith.h string.h struct.h type.h writeem.h
conversion.o: Lpars.h arith.h em.h nobitfield.h proc_intf.h sizes.h spec_arith.h type.h writeem.h
em.o: arith.h bufsiz.h em.h label.h proc_intf.h spec_arith.h system.h writeem.h
em.o: arith.h em.h label.h proc_intf.h spec_arith.h writeem.h
blocks.o: arith.h atw.h em.h proc_intf.h sizes.h spec_arith.h writeem.h
dataflow.o: dataflow.h
system.o: inputtype.h system.h
string.o: arith.h nopp.h spec_arith.h str_params.h string.h system.h
string.o: arith.h nopp.h spec_arith.h str_params.h string.h
tokenfile.o: Lpars.h
declar.o: LLlex.h Lpars.h arith.h debug.h declar.h decspecs.h def.h expr.h field.h idf.h label.h nobitfield.h nopp.h sizes.h spec_arith.h struct.h type.h
statement.o: LLlex.h Lpars.h arith.h botch_free.h code.h debug.h def.h em.h expr.h idf.h label.h nobitfield.h nopp.h proc_intf.h spec_arith.h stack.h storage.h type.h writeem.h

View file

@ -13,7 +13,7 @@
!File: errout.h
#define ERROUT stderr /* file pointer for writing messages */
#define ERROUT STDERR /* file pointer for writing messages */
#define MAXERR_LINE 5 /* maximum number of error messages given
on the same input line. */
@ -134,10 +134,6 @@
#define SSIZE 1024 /* string-buffer size for print routines */
!File: bufsiz.h
#define BUFSIZ 1024 /* system block size */
!File: spec_arith.h
/* describes internal compiler arithmetics */
#undef SPECIAL_ARITHMETICS /* something different from native long */

View file

@ -23,21 +23,19 @@
Salloc(str, sz) : save string in malloc storage
*/
#include <system.h>
#include "myalloc.h" /* UF */
#include "debug.h" /* UF */
#include "alloc.h"
#include "assert.h"
#include "system.h"
#ifdef OWNALLOC
#define SBRK_ERROR ((char *) -1) /* errors during allocation */
char *sys_break();
/* the following variables are used for book-keeping */
static int nfreebytes = 0; /* # free bytes in sys_sbrk-ed space */
static int nfreebytes = 0; /* # free bytes in sys_break space */
static char *freeb; /* pointer to first free byte */
static char *lastalloc; /* pointer to last malloced sp */
static char *lastalloc; /* pointer to last malloced sp */
static int lastnbytes; /* nr of bytes in last allocated */
/* space */
static char *firstfreeb = 0;
@ -75,11 +73,11 @@ malloc(n)
register nbts = (n <= ALLOCSIZ) ? ALLOCSIZ : n;
if (!nfreebytes) {
if ((freeb = sys_sbrk(nbts)) == SBRK_ERROR)
if ((freeb = sys_break(nbts)) == ILL_BREAK)
fatal("out of memory");
}
else {
if (sys_sbrk(nbts) == SBRK_ERROR)
if (sys_break(nbts) == ILL_BREAK)
fatal("out of memory");
}
nfreebytes += nbts;
@ -118,7 +116,7 @@ realloc(ptr, n)
nbytes = ALIGN(nbytes);
if (nfreebytes < nbytes) {
register int nbts = (nbytes < ALLOCSIZ) ? ALLOCSIZ : nbytes;
if (sys_sbrk(nbts) == SBRK_ERROR)
if (sys_break(nbts) == ILL_BREAK)
fatal("out of memory");
nfreebytes += nbts;
}
@ -136,13 +134,13 @@ free(p)
init_mem()
{
firstfreeb = sys_sbrk(0);
firstfreeb = sys_break(0);
/* align the first memory unit to ALIGNSIZE ??? */
if ((long) firstfreeb % ALIGNSIZE != 0) {
register char *fb = firstfreeb;
fb = (char *)ALIGN((long)fb);
firstfreeb = sys_sbrk(fb - firstfreeb);
firstfreeb = sys_break(fb - firstfreeb);
firstfreeb = fb;
ASSERT((long)firstfreeb % ALIGNSIZE == 0);
}
@ -155,7 +153,7 @@ mem_stat()
if (options['m'])
printf("Total nr of bytes allocated: %d\n",
sys_sbrk(0) - firstfreeb);
sys_break(0) - firstfreeb);
}
#endif DEBUG
#endif OWNALLOC

View file

@ -78,7 +78,7 @@ prepend_scopes(dst_file)
struct stack_entry *se = local_level->sl_entry;
if (C_open(dst_file) == 0)
fatal("cannot create file %s", dst_file);
fatal("cannot create %s", dst_file ? dst_file : "stdout");
famous_first_words();
while (se != 0) {
struct idf *idf = se->se_idf;

View file

@ -5,8 +5,7 @@
#define MAX_ARG_CNT 32
#include "em.h"
#include "system.h"
#include "bufsiz.h"
#include <system.h>
#include "arith.h"
#include "label.h"
@ -21,17 +20,18 @@
*/
/* supply a kind of buffered output */
#define flush(x) sys_write(ofd, &obuf[0], x);
#define flush(x) sys_write(ofp, &obuf[0], x)
static char obuf[BUFSIZ];
static char *opp = &obuf[0];
int ofd = -1;
File *ofp = 0;
putbyte(b) /* shouldn't putbyte() be a macro ??? (EB) */
int b;
{
if (opp >= &obuf[BUFSIZ]) { /* flush if buffer overflows */
flush(BUFSIZ);
if (flush(BUFSIZ) == 0)
sys_stop(S_ABORT);
opp = &obuf[0];
}
*opp++ = (char) b;
@ -45,24 +45,26 @@ C_open(nm) /* open file for compact code output */
char *nm;
{
if (nm == 0)
ofd = 1; /* standard output */
ofp = STDOUT; /* standard output */
else
if ((ofd = sys_creat(nm, CMODE)) < 0)
if (sys_open(nm, OP_WRITE, &ofp) == 0)
return 0;
return 1;
}
C_close()
{
flush(opp - &obuf[0]);
if (flush(opp - &obuf[0]) == 0)
sys_stop(S_ABORT);
opp = obuf; /* reset opp */
sys_close(ofd);
ofd = -1;
if (ofp != STDOUT)
sys_close(ofp);
ofp = 0;
}
C_busy()
{
return ofd >= 0; /* true if code is being generated */
return ofp != 0; /* true if code is being generated */
}
/*** the compact code generating routines ***/

View file

@ -1,11 +1,11 @@
/* $Header$ */
/* E R R O R A N D D I A G N O S T I C R O U T I N E S */
#include <system.h>
#include "nopp.h"
#include "use_tmp.h"
#include "errout.h"
#include "debug.h"
#include "system.h"
#include "string.h"
#include "tokenname.h"
@ -96,9 +96,9 @@ crash(fmt, args)
_error(CRASH, NILEXPR, fmt, &args);
C_close();
#ifdef DEBUG
sys_stop(S_ABORT, 0);
sys_stop(S_ABORT);
#else DEBUG
sys_stop(S_EXIT, 1);
sys_stop(S_EXIT);
#endif DEBUG
}
@ -115,7 +115,7 @@ fatal(fmt, args)
#endif USE_TMP
_error(FATAL, NILEXPR, fmt, &args);
sys_stop(S_EXIT, 1);
sys_stop(S_EXIT);
}
_error(class, expr, fmt, argv)

View file

@ -4,13 +4,13 @@
#include "nopp.h"
#ifndef NOPP
#include <system.h>
#include "predefine.h" /* UF */
#include "alloc.h"
#include "class.h"
#include "macro.h"
#include "idf.h"
#include "interface.h"
#include "system.h"
#include "string.h"
PRIVATE struct mkey {
@ -33,7 +33,7 @@ PRIVATE struct mkey {
EXPORT
init_pp()
{
time_type clock;
long clock;
static char date[30];
char *ctime();
@ -62,7 +62,7 @@ init_pp()
"pdp" are predefined macros.
*/
/* __DATE__ */
clock = sys_time((time_type *) 0);
clock = sys_time();
strcpy(&date[1], ctime(&clock));
date[26] = '\0'; /* zap nl */
date[0] = date[25] = '"';

View file

@ -30,6 +30,7 @@
a fixed length input buffer
*/
#include <system.h>
#include "nopp.h"
#include "inputtype.h" /* UF */
#include "interface.h"
@ -37,8 +38,6 @@
#include "LLlex.h"
#include "input.h"
#include "alloc.h"
#include "system.h"
#include "bufsiz.h"
#ifndef NOPP
#include "idepth.h" /* UF */
@ -51,7 +50,7 @@ EXPORT char *ipp = 0; /* input pointer */
EXPORT int NoUnstack = 0; /* if 1: report EOF */
#ifndef READ_IN_ONE
PRIVATE int FilDes = -1; /* current input medium */
PRIVATE File *FilDes = 0; /* current input medium */
#endif READ_IN_ONE
#ifndef NOPP
@ -63,7 +62,7 @@ struct buffer_header {
char *bh_text; /* pointer to buffer containing text */
char *bh_ipp; /* current read pointer (= stacked ipp) */
char *bh_wdir; /* directory of current file */
int bh_fd; /* >= 0 (fd if !READ_IN_ONE) in case of file */
File *bh_fp; /* needed for files if !READ_IN_ONE */
};
PRIVATE struct buffer_header instack[IDEPTH]; /* stack of input media */
@ -91,27 +90,21 @@ readfile(filename, size)
char *filename;
long *size;
{
int fd; /* filedescriptor for `filename' */
File *fp; /* filedescriptor for `filename' */
char *cbuf; /* pointer to buffer to be returned */
register tmp;
int tmp;
long sys_filesize();
if ((fd = sys_open(filename, OP_RDONLY)) < 0) {
/* can't open this file */
if (sys_open(filename, OP_READ, &fp) == 0) /* can't open this file */
return (char *) 0;
}
if ((*size = sys_fsize(fd)) < 0)
if ((*size = sys_filesize(filename)) == -1L)
fatal("(readfile) cannot get size of file");
/* allocate enough space to store contents of the file */
cbuf = Malloc(*size + 2);
tmp = sys_read(fd, cbuf + 1, (int) *size); /* read the file */
if (tmp != *size)
fatal("(readfile) bad read count");
if (sys_read(fp, cbuf + 1, (int) *size, &tmp) == 0 || tmp != *size)
fatal("(readfile) bad read");
(*size)++; /* keep book of the size! */
sys_close(fd); /* filedes no longer needed */
sys_close(fp); /* filedes no longer needed */
cbuf[0] = '\0'; /* allow pushback of first char */
cbuf[*size] = '\0'; /* invoke loadbuf() at end */
return cbuf;
@ -173,7 +166,7 @@ push_bh()
PRIVATE int
pop_bh()
{
int pfd = head->bh_fd;
File *pfp = head->bh_fp;
if (NoUnstack) {
lexerror("unexpected EOF");
@ -186,9 +179,9 @@ pop_bh()
ipp = (--head)->bh_ipp; /* restore the previous input pointer */
if (pfd >= 0) { /* unstack a file */
if (pfp != 0) { /* unstack a file */
#ifndef READ_IN_ONE
closefile(pfd);
closefile(pfp);
popbuf(); /* free last buffer */
#endif READ_IN_ONE
LineNumber = head->bh_lineno;
@ -197,7 +190,7 @@ pop_bh()
}
#ifndef READ_IN_ONE
FilDes = head->bh_fd;
FilDes = head->bh_fp;
#endif READ_IN_ONE
return 1;
@ -208,32 +201,36 @@ pop_bh()
/* low level IO routines: openfile(), readblock() and closefile()
*/
PRIVATE int
PRIVATE File *
openfile(filename)
char *filename;
{
int fd; /* filedescriptor for `filename' */
File *fp;
if ((fd = sys_open(filename, OP_RDONLY)) < 0 && sys_errno == EMFILE)
fatal("too many files open");
return fd;
if (filename == 0)
return STDIN;
if (sys_open(filename, OP_READ, &fp) == 0)
return (File *)0;
return fp;
}
PRIVATE
closefile(fd)
closefile(fp)
File *fp;
{
sys_close(fd);
if (fp != STDIN)
sys_close(fp);
}
PRIVATE int
readblock(fd, buf)
readblock(fp, buf)
File *fp;
char buf[];
{
register n;
int n;
if ((n = sys_read(fd, &buf[1], BUFSIZ)) < 0) {
fatal("(readblock) bad read from file");
}
if (sys_read(fp, &buf[1], BUFSIZ, &n) == 0)
fatal("(readblock) bad read");
buf[0] = buf[n + 1] = '\0';
return n;
}
@ -249,16 +246,19 @@ InsertFile(filnam, table)
{
char *mk_filename(), *newfn;
char *strcpy();
File *openfile();
#ifdef READ_IN_ONE
char *readfile(), *text;
long size;
#else READ_IN_ONE
int fd = -1;
File *fp = 0;
#endif READ_IN_ONE
#ifdef READ_IN_ONE
if (!filnam)
return 0;
#endif READ_IN_ONE
#ifndef NOPP
if (table == 0 || filnam[0] == '/') { /* don't look in the table! */
@ -266,17 +266,20 @@ InsertFile(filnam, table)
#ifdef READ_IN_ONE
text = readfile(filnam, &size);
#else READ_IN_ONE
fd = openfile(filnam);
fp = openfile(filnam);
if (filnam == 0)
filnam = "standard input";
#endif READ_IN_ONE
#ifndef NOPP
}
else {
ASSERT(filnam != 0);
while (*table) { /* look in the directory table */
newfn = mk_filename(*table++, filnam);
#ifdef READ_IN_ONE
if (text = readfile(newfn, &size))
#else READ_IN_ONE
if ((fd = openfile(newfn)) >= 0)
if ((fp = openfile(newfn)) != 0)
#endif READ_IN_ONE
{
/* free filnam ??? */
@ -290,7 +293,7 @@ InsertFile(filnam, table)
#ifdef READ_IN_ONE
if (text)
#else READ_IN_ONE
if (fd >= 0)
if (fp != 0)
#endif READ_IN_ONE
#ifndef NOPP
{
@ -303,11 +306,11 @@ InsertFile(filnam, table)
bh->bh_wdir = *WorkingDir;
#ifdef READ_IN_ONE
bh->bh_size = size;
bh->bh_fd = 0; /* this is a file */
bh->bh_fp = STDIN; /* this is a file */
ipp = bh->bh_text = text;
#else READ_IN_ONE
bh->bh_size = readblock(fd, ipp = bh->bh_text = pushbuf()) + 1;
FilDes = bh->bh_fd = fd;
bh->bh_size = readblock(fp, ipp = bh->bh_text = pushbuf()) + 1;
FilDes = bh->bh_fp = fp;
#endif READ_IN_ONE
bh->bh_text[0] = '\n'; /* wake up pp if '#' comes first */
return 1;
@ -318,7 +321,7 @@ InsertFile(filnam, table)
isize = size;
ipp = text;
#else READ_IN_ONE
isize = readblock(FilDes = fd, ipp = &ibuf[0]) + 1;
isize = readblock(FilDes = fp, ipp = &ibuf[0]) + 1;
#endif READ_IN_ONE
ibuf[0] = '\n';
return 1;
@ -340,10 +343,10 @@ InsertText(text, length)
bh->bh_size = (long) length;
bh->bh_text = text;
bh->bh_wdir = *WorkingDir;
bh->bh_fd = -1; /* this is no file ! */
bh->bh_fp = 0; /* this is not a file ! */
ipp = text + 1;
#ifndef READ_IN_ONE
FilDes = -1;
FilDes = 0;
#endif READ_IN_ONE
}
#endif NOPP
@ -376,13 +379,13 @@ loadbuf()
#ifndef READ_IN_ONE
#ifndef NOPP
if ( FilDes >= 0
if ( FilDes != 0
&& (head->bh_size = readblock(FilDes, head->bh_text)) > 0
) {
return ipp = &(head->bh_text[1]), *ipp++;
}
#else NOPP
if (FilDes >= 0 && (isize = readblock(FilDes, &ibuf[0])) > 0)
if (FilDes != 0 && (isize = readblock(FilDes, &ibuf[0])) > 0)
return ipp = &ibuf[1], *ipp++;
#endif NOPP

View file

@ -1,15 +1,14 @@
/* $Header$ */
/* MAIN PROGRAM */
#include <system.h>
#include "nopp.h"
#include "target_sizes.h"
#include "debug.h"
#include "myalloc.h"
#include "use_tmp.h"
#include "maxincl.h"
#include "system.h"
#include "inputtype.h"
#include "bufsiz.h"
#include "input.h"
#include "level.h"
@ -134,10 +133,8 @@ compile(argc, argv)
int pp_only = options['E'] || options['P'];
#endif NOPP
source = argv[0];
source = strcmp(argv[0], "-") ? argv[0] : 0;
switch (argc) {
case 1:
#ifndef NOPP
if (!pp_only)
@ -147,7 +144,6 @@ compile(argc, argv)
case 2:
destination = argv[1];
break;
case 3:
nmlist = argv[2];
destination = argv[1];
@ -160,22 +156,18 @@ compile(argc, argv)
#ifdef USE_TMP
tmpfile = mktemp(tmpname);
#endif USE_TMP
if (!InsertFile(source, (char **) 0)) {
/* read the source file */
fatal("%s: no source file %s\n", prog_name, source);
}
if (strcmp(destination, "-") == 0)
destination = 0;
if (!InsertFile(source, (char **) 0)) /* read the source file */
fatal("%s: no source file %s\n", prog_name,
source ? source : "stdin");
init();
/* needed ??? */
FileName = source;
/* FileName = source; /* needed ??? */
PushLex();
#ifndef NOPP
if (pp_only) {
/* run the preprocessor as if it is stand-alone */
if (pp_only) /* run the preprocessor as if it is stand-alone */
preprocess();
}
else {
#endif NOPP
@ -365,20 +357,25 @@ preprocess()
AppendFile(src, dst)
char *src, *dst;
{
int fd_src, fd_dst;
File *fp_src, *fp_dst;
char buf[BUFSIZ];
int n;
if ((fd_src = sys_open(src, OP_RDONLY)) < 0) {
if (sys_open(src, OP_READ, &fp_src) == 0)
fatal("cannot read %s", src);
if (dst) {
if (sys_open(dst, OP_APPEND, &fp_dst) == 0)
fatal("cannot write to %s", src);
}
if ((fd_dst = sys_open(dst, OP_APPEND)) < 0) {
fatal("cannot write to %s", src);
}
while ((n = sys_read(fd_src, buf, BUFSIZ)) > 0) {
sys_write(fd_dst, buf, n);
}
sys_close(fd_src);
sys_close(fd_dst);
else
fp_dst = STDOUT;
while (sys_read(fp_src, buf, BUFSIZ, &n) != 0 && n > 0)
if (sys_write(fp_dst, buf, n) == 0)
fatal("(AppendFile) write error");
if (n != 0)
fatal("(AppendFile) read error");
sys_close(fp_src);
if (fp_dst != STDOUT)
sys_close(fp_dst);
}
#endif USE_TMP

View file

@ -5,7 +5,7 @@
#include "use_tmp.h"
#include "botch_free.h"
#include "system.h"
#include <system.h>
#include "alloc.h"
#include "Lpars.h"
#include "arith.h"
@ -267,22 +267,19 @@ unstack_world()
list is generated.
*/
extern char *nmlist; /* BAH! -- main.c */
static int nfd;
static File *nfp = 0;
open_name_list()
{
if (nmlist) {
if ((nfd = sys_creat(nmlist, 0644)) < 0) {
fatal("cannot create namelist %s", nmlist);
}
}
if (nmlist && sys_open(nmlist, OP_WRITE, &nfp) == 0)
fatal("cannot create namelist %s", nmlist);
}
namelist(nm)
char *nm;
{
if (nmlist) {
sys_write(nfd, nm, strlen(nm));
sys_write(nfd, "\n", 1);
sys_write(nfp, nm, strlen(nm));
sys_write(nfp, "\n", 1);
}
}

View file

@ -1,19 +1,20 @@
/* $Header$ */
/* STRING MANIPULATION AND PRINT ROUTINES */
#include <system.h>
#include "string.h"
#include "nopp.h"
#include "str_params.h"
#include "arith.h"
#include "system.h"
doprnt(fd, fmt, argp)
doprnt(fp, fmt, argp)
File *fp;
char *fmt;
int argp[];
{
char buf[SSIZE];
sys_write(fd, buf, format(buf, fmt, (char *)argp));
sys_write(fp, buf, format(buf, fmt, (char *)argp));
}
/*VARARGS1*/
@ -23,17 +24,18 @@ printf(fmt, args)
{
char buf[SSIZE];
sys_write(1, buf, format(buf, fmt, &args));
sys_write(STDOUT, buf, format(buf, fmt, &args));
}
/*VARARGS1*/
fprintf(fd, fmt, args)
fprintf(fp, fmt, args)
File *fp;
char *fmt;
char args;
{
char buf[SSIZE];
sys_write(fd, buf, format(buf, fmt, &args));
sys_write(fp, buf, format(buf, fmt, &args));
}
/*VARARGS1*/