Digital Research
This commit is contained in:
2020-11-06 18:50:37 +01:00
parent 621ed8ccaf
commit 31738079c4
8481 changed files with 1888323 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
mkver; c68 -r -L *.c -o c68.68 -l6 ; setstack68 c68.68 8192 8192
mkver; c68 -r -L -n *.c -o c68.st -l6 ; setstack68 c68.st 8192 8192
mkver; cc -n *.c -o c68.11 -lx

View File

@@ -0,0 +1,340 @@
/*
Copyright 1982
Alcyon Corporation
8716 Production Ave.
San Diego, Ca. 92121
*/
#include "preproc.h"
#define OPPRI 077
#define OPBIN 0100
#define STKLEN 64
int oprstk[STKLEN]; /*operator stack*/
int opnstk[STKLEN]; /*operand stack*/
int pristk[STKLEN]; /*operator priority stack*/
int *oprptr; /*pointer to operator stack*/
int *opnptr; /*pointer to operand stack*/
int *priptr; /*pointer to priority stack*/
int cvalue;
int opinfo[] {
0, /*EOF=0*/
16|OPBIN, /*SUB=1*/
16|OPBIN, /*ADD=2*/
20, /*NOT=3*/
20, /*NEG=4*/
22, /*LPAREN=5*/
2, /*RPAREN=6*/
6|OPBIN, /*QMARK=7*/
6|OPBIN, /*COLON=8*/
8|OPBIN, /*OR=9*/
10|OPBIN, /*AND=10*/
8|OPBIN, /*XOR=11*/
12|OPBIN, /*EQUAL=12*/
12|OPBIN, /*NEQUAL=13*/
14|OPBIN, /*LESS=14*/
14|OPBIN, /*LSEQUAL=15*/
14|OPBIN, /*GREAT=16*/
14|OPBIN, /*GREQUAL=17*/
4|OPBIN, /*LSHIFT=18*/
4|OPBIN, /*RSHIFT=19*/
18|OPBIN, /*MULT=20*/
18|OPBIN, /*DIV=21*/
18|OPBIN, /*MOD=22*/
20, /*COMPL=23*/
};
/* cexpr - constant expression evaluation*/
/* Does priority-driven operator/operand stack evaluation of*/
/* constant expressions.*/
cexpr() /* returns constant evaluated*/
{
register int lop, type;
oprptr = &oprstk[0];
opnptr = &opnstk[0];
priptr = &pristk[0];
*priptr = 0;
lop = -1;
while(1) {
switch( type = getctok() ) {
case CONST:
if( !lop ) /*last was not operator*/
goto syntax;
if( opnptr >= &opnstk[STKLEN] ) {
error("expression stack overflow");
cexit();
}
lop = FALSE;
*++opnptr = cvalue;
continue;
case SUB:
if( lop )
type = NEG; /*unary minus*/
break;
case ADD:
if( lop )
continue; /*ignore unary +*/
break;
case COMPL:
case LPAREN:
case NOT:
if( !lop )
goto syntax;
break;
case RPAREN:
if( lop )
goto syntax;
lop = FALSE;
if( !stkop(type) )
goto syntax;
continue;
case NEWL:
case EOF:
if( lop || !stkop(EOF) || opnptr != &opnstk[1] )
goto syntax;
type = opnstk[1];
putback('\n');
return(type);
default:
if( lop || type > LASTOP )
goto syntax;
break;
}
lop = TRUE;
if( !stkop(type) )
goto syntax;
}
syntax:
error("expression syntax");
if( type == NEWL )
putback('\n');
return(0);
}
/* getctok - get a constant expression token*/
/* Handles conversion of quoted character strings and numbers.*/
getctok()
{
register int type, c, count;
register char *p;
char token[TOKSIZE];
while( 1 ) {
switch( type = getntok(token) ) {
case DIGIT:
cvalue = const(token);
return(CONST);
case SQUOTE:
for( cvalue = 0, p = &token[1], count = 2; --count >= 0; ) {
if( (c= *p++) == '\'' )
break;
if( c == '\\' ) {
if( *p >= '0' && *p <= '7' ) {
for( c = 0; *p >= '0' && *p <= '7'; )
c = (c<<3) + (*p++ - '0');
}
else switch( c = *p++ ) {
case 'n':
c = '\n';
break;
case 't':
c = '\t';
break;
case 'b':
c = '\b';
break;
case 'r':
c = '\r';
break;
case 'f':
c = '\f';
break;
}
}
cvalue = (cvalue<<8) | c;
}
return(CONST);
case ALPHA:
if( p = lookup(token) )
expand(p);
else
return(ALPHA);
break;
default:
return(type);
}
}
}
/* stkop - stack an operator on the operand stack*/
/* Unstack all operators of lower priority, evaluating them as*/
/* they are unstacked.*/
stkop(opr) /* returns 1 if ok, 0 otherwise*/
int opr; /* operator to stack*/
{
register int i, j, op1, op2, pri;
for( pri = opinfo[opr]&OPPRI; pri < *priptr; ) {
if( *oprptr == LPAREN ) {
if( opr == RPAREN ) {
oprptr--;
priptr--;
return(1);
}
break;
}
op1 = *opnptr;
if( (i=opinfo[*oprptr]) & OPBIN ) {
op2 = op1;
op1 = *--opnptr;
}
switch(*oprptr) { /*operator*/
case ADD:
op1 =+ op2;
break;
case SUB:
op1 =- op2;
break;
case COLON:
priptr--;
if( *--oprptr != QMARK )
return(0);
op1 = (*--opnptr ? op1 : op2);
break;
case QMARK:
return(0);
case XOR:
op1 =^ op2;
break;
case OR:
op1 =| op2;
break;
case AND:
op1 =& op2;
break;
case EQUAL:
op1 = (op1 == op2);
break;
case NEQUAL:
op1 = (op1 != op2);
break;
case LESS:
op1 = (op1 < op2);
break;
case LSEQUAL:
op1 = (op1 <= op2);
break;
case GREAT:
op1 = (op1 > op2);
break;
case GREQUAL:
op1 = (op1 >= op2);
break;
case LSHIFT:
op1 = (op1 << op2);
break;
case RSHIFT:
op1 = (op1 >> op2);
break;
case NEG:
op1 = -op1;
break;
case NOT:
op1 = !op1;
break;
case COMPL:
op1 = ~ op1;
break;
case MULT:
op1 =* op2;
break;
case DIV:
op1 =/ op2;
break;
case MOD:
op1 =% op2;
break;
}
*opnptr = op1;
priptr--;
oprptr--;
}
if( priptr >= &pristk[STKLEN-1] ) {
error("expression operator stack overflow");
cexit();
}
*++oprptr = opr; /*operator value*/
*++priptr = pri; /*operator priority*/
return(1);
}
#define toupper(c) ((c) & ~32)
/* const - alpha to int conversion, handles octal and hexidecimal*/
/* Uses Horner's method to evaluate number.*/
const(str) /* returns number evaluated*/
char *str; /* pointer to string to convert*/
{
register int c, ch, i, radix;
i = 0;
radix = 10;
if( *str == '0' ) {
radix = 8;
if( *++str == 'x' || *str == 'X' ) {
radix = 16;
str++;
}
}
while( c = *str++ ) {
if( (ch=toupper(c)) >= 'A' && ch <= 'F' )
c = ch - ('A'-10);
else if( c >= '0' && c <= '9' )
c =- '0';
else
break;
if( c >= radix )
break;
i = i*radix + c;
}
return(i);
}

View File

@@ -0,0 +1,353 @@
/*
Copyright 1982
Alcyon Corporation
8716 Production Ave.
San Diego, Ca. 92121
*/
#include "preproc.h"
int Eflag;
char null[] "";
char ctype[] {
EOF, ANYC, ANYC, ANYC, ANYC, ANYC, ANYC, ANYC,
ANYC, WHITE, NEWL, ANYC, ANYC, ANYC, ANYC, ANYC,
ANYC, ANYC, ANYC, ANYC, NEWL, ANYC, ANYC, ANYC,
ANYC, ANYC, ANYC, ANYC, ANYC, ANYC, ANYC, ANYC,
WHITE, NOT, DQUOTE, POUND, ANYC, MOD, AND, SQUOTE,
LPAREN, RPAREN, MULT, ADD, COMMA, SUB, ANYC, DIV,
DIGIT, DIGIT, DIGIT, DIGIT, DIGIT, DIGIT, DIGIT, DIGIT,
DIGIT, DIGIT, COLON, ANYC, LESS, EQUAL, GREAT, QMARK,
ANYC, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA,
ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA,
ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA,
ALPHA, ALPHA, ALPHA, ANYC, BSLASH, ANYC, XOR, ALPHA,
ANYC, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA,
ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA,
ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA,
ALPHA, ALPHA, ALPHA, ANYC, OR, ANYC, COMPL, ANYC
}; /* BUG2 - ANYC */
/* symhash - compute hash value for symbol*/
/* Sums the symbols characters and takes that modulus the hash table*/
/* size.*/
symhash(sym) /* returns hash value for symbol*/
char *sym; /* pointer to symbol*/
{
register char *p;
register int hashval, i;
for( p = sym, i = SSIZE, hashval = 0; *p != '\0' && i > 0; i-- )
hashval =+ *p++;
return( hashval % HSIZE );
}
/* symequal - check for symbol equality*/
/* Does comparison between two symbols.*/
symequal(sym1,sym2) /* returns 1 if equal, 0 otherwise*/
char *sym1; /* pointer to first symbol*/
char *sym2; /* pointer to second symbol*/
{
register char *p, *q;
register int i;
q = sym2;
i = SSIZE;
for( p = sym1; *p == *q++; )
if( *p++ == '\0' || --i == 0 )
return(1);
return(0);
}
/* symcopy - symbol copy*/
/* Copies one symbol to another.*/
symcopy(sym1,sym2) /* returns - none*/
char *sym1; /* pointer to symbol to copy*/
char *sym2; /* pointer to area to copy to*/
{
register char *p, *q;
register int i;
for( p = sym1, q = sym2, i = SSIZE; --i >= 0; )
if( *p )
*q++ = *p++;
else
*q++ = '\0';
}
/* error - output error message*/
/* Outputs line number and error message and keeps track of errors.*/
error(s,x1,x2,x3,x4,x5,x6) /* returns - none*/
char *s; /* printf string*/
int x1, x2, x3, x4, x5, x6; /* printf args*/
{
if (filep == &filestack[0]) /* [vlh] 3.4 not in include */
printf("# %d: ",lineno);
else
printf("%s : # %d: ",(filep-1)->ifile,(filep-1)->lineno);
printf(s,x1,x2,x3,x4,x5,x6);
putchar('\n');
mfail++;
}
/* putback - puts back a single character*/
/* Checks for push back buffer overflow.*/
putback(c)
int c;
{
if( pbp >= &pbbuf[PBSIZE] ) {
error("too many characters pushed back");
cexit();
}
*pbp++ = c;
}
/* pbtok - push back a token*/
/* Reverses token as its pushing it back.*/
pbtok(s)
char *s;
{
register char *p;
for( p = s + strlen(s); p > s ; )
putback(*--p);
}
/* ngetch - get a (possibly) pushed back character*/
/* This handles the include file stack and incrementing the line*/
/* number for the lowest level file.*/
ngetch() /* returns character or EOF*/
{
register int c, i;
register char *p, *q;
if( pbp > &pbbuf[0] )
return(*--pbp);
pbflag = 0;
while( (c=getc(&inbuf)) < 0 ) {
if( filep == &filestack[0] )
return(EOF);
close(inbuf.fd);
filep--;
#ifdef NONEST
inbuf.fd = holdbuf.fd;
inbuf.nc = holdbuf.nc;
inbuf.bp = holdbuf.bp;
p = &inbuf.buffer[0];
q = &holdbuf.buffer[0];
for(i = 0; i<BUFSIZE; i++)
*p++ = *q++;
#else
inbuf.fd = filep->ifd;
inbuf.nc = 0;
inbuf.bp = &inbuf.buffer[0];
#endif
if( filep == &filestack[0] ) { /*need line for #include...*/
doputc('\n',&outbuf);
lineno++;
}
}
return( c );
}
/* getsp - get symbol pointer*/
/* Calculates the symbol table pointer for a given symbol, if symbol*/
/* is not defined, will point to appropriate place to insert symbol.*/
struct symbol *getsp(name)
char *name;
{
register int wrap;
register struct symbol *sp, *asp;
wrap = 0;
asp = 0;
for( sp = &symtab[symhash(name)]; sp->s_def != null; ) {
if( symequal(sp->s_name,name) )
return(sp);
if( !asp && sp->s_def == null )
asp = sp;
if( ++sp >= &symtab[HSIZE] ) {
if( wrap++ ) {
error("symbol table overflow");
cexit();
}
sp = &symtab[0];
}
}
return( asp ? asp : sp );
}
/* lookup - looks up a symbol to see if it is defined*/
/* Returns pointer to definition if found.*/
char *lookup(name) /* returns 0 or ptr to symbol*/
char *name; /* symbol name*/
{
register struct symbol *sp;
sp = getsp(name);
if( sp->s_def == 0 || sp->s_def == null )
return(0);
return(sp);
}
/* gettok - gets next token from input*/
/* Collects character string in token and handles special tokens for*/
/* the expression evaluator.*/
gettok(token) /* returns token type*/
char *token;
{
register char *p, c;
register int type, count, t, l;
p = token;
c = ngetch();
*p++ = c;
switch( type = ctype[c] ) {
case SQUOTE:
case DQUOTE:
getstr(token,TOKSIZE,c);
return(type);
case DIGIT:
case ALPHA:
for( ; p < &token[TOKSIZE]; p++ ) {
*p = ngetch();
if( (t=ctype[*p]) != ALPHA && t != DIGIT )
break;
}
putback(*p);
break;
case NOT:
if( peekis('=') ) {
type = NEQUAL;
*p++ = '=';
}
break;
case GREAT:
if( peekis('>') ) {
type = RSHIFT;
*p++ = '>';
}
else if( peekis('=') ) {
type = GREQUAL;
*p++ = '=';
}
break;
case LESS:
if( peekis('<') ) {
type = LSHIFT;
*p++ = '<';
}
else if( peekis('=') ) {
type = LSEQUAL;
*p++ = '=';
}
break;
case EQUAL:
if( peekis('=') )
*p++ = '=';
else
type = ANYC;
break;
case DIV:
if( peekis('*') ) {
l = lineno;
while( (c=ngetch()) != EOF )
if( c == '\n' ) {
if( filep == &filestack[0] && pbp == &pbbuf[0] ) {
lineno++;
doputc('\n',&outbuf);
}
}
else if( c == '*' && peekis('/') )
break;
if( c == EOF ) {
lineno = l;
error("no */ before EOF");
}
type = WHITE;
token[0] = ' ';
}
else if( peekis('/') ) {
while( (c=ngetch()) != EOF && c != '\n' )
;
type = NEWL;
token[0] = '\n';
}
break;
case BADC:
error("bad character 0%o",c);
break;
}
*p = '\0';
return(type);
}
/* getstr - get a quoted (single or double) character string*/
/* Gets specified number of characters, handling escapes.*/
getstr(str,nchars,endc) /* returns - none*/
char *str; /* pointer to string buffer*/
int nchars; /* max number of characters*/
char endc; /* ending string character*/
{
register char *p;
register int i;
register int c;
register int j;
p = str;
*p++ = endc;
for( i = nchars-2; (c=ngetch()) != endc; ) {
if( c == EOF || c == '\n' ) {
error("string cannot cross line");
break;
}
if( --i > 0 ) /*BUG 1*/
*p++ = c;
else if( !i )
error("string too long");
if( c == '\\' ) {
c = ngetch();
if( --i > 0 ) /*BUG 1*/
*p++ = c;
else if( !i )
error("string too long");
}
}
*p++ = endc;
*p = '\0';
}
/* peekis - peeks at next character for specific character*/
/* Gets next (possibly pushed back) character, if it matches*/
/* the given character 1 is returned, otherwise the character*/
/* is put back.*/
peekis(tc) /* returns 1 if match, 0 otherwise*/
int tc; /* test character*/
{
register int c;
if( (c=ngetch()) == tc )
return(1);
putback(c);
return(0);
}
doputc(ch,buffer)
char ch;
struct ibuf *buffer;
{
if (!Eflag)
putc(ch,buffer);
else
putchar(ch);
}

View File

@@ -0,0 +1,743 @@
/*
Copyright 1982
Alcyon Corporation
8716 Production Ave.
San Diego, Ca. 92121
*/
#include "preproc.h"
#define CSTKSIZE 20
#define FILESEP '/'
#define NINCL 10
char *stdincl "/usr/include/"; /*standard include directory*/
int clabel 1000;
int nlabel 1001;
int nincl;
int literal; /*[vlh] 4.0 lnum and file name specified using #line */
char *incl[10];
char tmp[6];
char ctype[];
struct builtin {
char *b_name;
int b_type;
} btab[] {
"define", DEFINE,
"include", INCLUDE,
"undef", UNDEF,
"ifdef", IFDEF,
"ifndef", IFNDEF,
"else", ELSE,
"endif", ENDIF,
"if", IF,
"line", LINE,
0,
};
char *getinclude();
char cstack[CSTKSIZE];
char *cstkptr, inclname[TOKSIZE];
/* domacro - do macro processing*/
/* Does the macro pre-processing on the input file and leaves the*/
/* result on the output file.*/
domacro(infile,outfile,nd) /* returns 1 if ok, 0 otherwise*/
char *infile; /* input file name*/
char *outfile; /* output file name*/
int nd; /* number of defines*/
{
register struct builtin *bp;
register char *l;
register struct symbol *sp;
register int x, nonewline; /* handle empty new lines with SOH */
register char *p;
filep = &filestack[0]; /* [vlh] 4.0 moved for error msgs */
lineno = 1; /* [vlh] 4.0 moved for error msgs */
if( fopen(infile,&inbuf,0) < 0 ) { /* 3rd arg for versados */
error("can't open source file %s\n",infile);
return(0);
}
if( fcreat(outfile,&outbuf,0) < 0 ) { /* 3rd arg for versados */
error("can't creat %s\n",outfile);
return(0);
}
for (sp= &symtab[0]; sp<= &symtab[HSIZE-1]; sp++) /*3.4*/
sp->s_def = null; /* clear out symbol table */
if( !defap ) {
defp = defap = sbrk(1024);
defmax = defcount = 1024;
}
else { /* multiple files, define area already exists */
defcount = defmax;
for (x = defmax, defp = defap; x>0; x--)
*defp++ = 0;
defp = defap;
}
nonewline = defused = mfail = 0;
pbp = &pbbuf[0];
cstkptr = &cstack[0];
install("Newlabel",NEWLABEL);
install("Label",LABEL);
while( --nd >= 0 )
dinstall(defs[nd].ptr,defs[nd].value);
while( getline(infile) ) {
l = line;
if( filep == &filestack[0] && pbp == &pbbuf[0] )
lineno++;
else if ( !pflag && !asflag && !literal ) { /*[vlh] include file*/
if (*l) {
putid((filep-1)->ifile,(filep-1)->lineno); /* 4.0 */
if (!(*l)) doputc(' ',&outbuf);
}
else nonewline++;
(filep-1)->lineno++;
}
while( *l )
doputc(*l++,&outbuf);
if (!nonewline) doputc('\n',&outbuf);
else nonewline = 0;
literal = 0;
}
if( cstkptr != &cstack[0] )
error("unmatched conditional");
if( defused > defmax )
defmax = defused;
v6flush(&outbuf);
close(outbuf.fd);
close(inbuf.fd);
return(mfail==0);
}
putid(fname,lnum) /* [vlh] 4.0 SOH line header */
char *fname;
int lnum;
{
register char *p;
if (asflag || pflag)
return;
doputc(SOH,&outbuf);
for (p = fname; *p; p++)
doputc(*p,&outbuf);
doputc(SOH,&outbuf);
itoa(lnum,tmp,5);
for (p = tmp; *p==' '; ) p++;
for ( ; *p; p++)
doputc(*p,&outbuf);
doputc(' ',&outbuf);
}
install(name,def)
char *name;
int def;
{
register struct symbol *sp;
sp = getsp(name);
symcopy(name,sp->s_name);
sp->s_def = defp;
putd(def);
putd('\0');
}
dinstall(name,def) /* returns - none*/
char *name; /* macro name*/
char *def; /* pointer to definition*/
{
register struct symbol *sp;
sp = getsp(name);
symcopy(name,sp->s_name);
sp->s_def = defp;
putd(NOARGS);
if (def) /* [vlh] character strings... */
while(*def) putd(*def++);
else putd('1'); /* [vlh] default define value */
putd('\0');
}
/* kwlook - look up the macro built-in names*/
/* Searches thru the built-in table for the name.*/
kwlook(name) /* returns keyword index or 0*/
char *name; /* keyword name to lookup*/
{
register struct builtin *bp;
for( bp = &btab[0]; bp->b_name; bp++ )
if( strcmp(bp->b_name,name) == 0 )
return(bp->b_type);
return(0);
}
/*
* getline - get input line handling macro statements
* Checks for a preprocessor statement on the line and if there
* is one there, it processes it. Note that most of the work is
* in determining whether we need to skip the current line or not.
* This is all handled with the condition stack and the skip variable.
* The skip variable is non-zero if any condition on the condition
* stack is SKIP.
*/
getline(infile) /* returns 0 for EOF, 1 otherwise*/
char *infile; /* [vlh] for quoted include files */
{
char token[TOKSIZE];
register int type, i;
register char *p;
initl();
if( (type=gettok(token)) == EOF )
return(0);
if( type == POUND ) {
if( (type=getntok(token)) == NEWL )
return(1);
switch( kwlook(token) ) {
case IFDEF:
if( getntok(token) == ALPHA && lookup(token) )
push(NOSKIP);
else {
push(SKIP);
skip++;
}
break;
case IFNDEF:
if( getntok(token) == ALPHA && lookup(token) ) {
push(SKIP);
skip++;
}
else
push(NOSKIP);
break;
case ENDIF:
if( (i=pop()) == SKIP )
skip--;
else if( i != NOSKIP )
error("invalid #endif");
break;
case ELSE:
if( (i=pop()) == SKIP ) {
skip--;
push(NOSKIP);
}
else if( i == NOSKIP ) {
skip++;
push(SKIP);
}
else
error("invalid #else");
break;
case DEFINE:
if( !skip ) /*if in skip, don't do define*/
dodefine();
break;
case UNDEF:
if( !skip ) { /*if in skip, don't undef*/
if( (type=getntok(token)) == ALPHA )
undefine(token);
}
break;
case INCLUDE:
if( !skip ) /*if in skip, don't do include*/
doinclude(infile);
break;
case IF:
if( cexpr() ) /*evaluate constant expression*/
push(NOSKIP); /*non-zero, so don't skip*/
else {
push(SKIP);
skip++;
}
break;
case LINE: /* [vlh] 4.0 */
doline(infile);
break;
default:
error("invalid preprocessor command");
break;
}
eatup();
}
else if( type == NEWL )
;
else if( skip ) {
eatup();
}
else {
for( ; type != NEWL && type != EOF ; type = gettok(token) ) {
if( type == ALPHA && (p=lookup(token)) )
expand(p);
else {
for( p = token; *p ; )
putl(*p++);
}
}
}
putl('\0');
return(1);
}
/* eatup - eat up the rest of the input line until a newline or EOF*/
/* Does gettok calls.*/
eatup() /* returns - none*/
{
register int type;
char etoken[TOKSIZE];
while( (type=gettok(etoken)) != NEWL && type != EOF )
;
}
/* putl - put a character to the current output line*/
/* Checks for line overflow.*/
putl(c) /* returns - none*/
int c; /* character to put on line*/
{
if( linep < &line[LINESIZE] )
*linep++ = c;
else if ( !loverflow ) {
loverflow++;
error("line overflow");
}
}
/* initl - initialize current line*/
/* Sets the line pointer and the line overflow flag.*/
initl() /* returns - none*/
{
*(linep= &line[0]) = '\0';
loverflow = 0;
}
/* putd - put a character to the define buffer*/
/* Does dynamic allocation for define buffer*/
putd(c) /* returns - none*/
int c; /* character to put in buffer*/
{
if( !defcount ) {
if( sbrk(DEFSIZE) == -1 ) {
error("define table overflow");
cexit();
}
defcount = DEFSIZE;
}
defused++;
defcount--;
*defp++ = c;
}
/* undefine - does undef command*/
/* Sets the symbols definition to the null pointer*/
undefine(name) /* returns - none*/
char *name; /* pointer to name to undef*/
{
register struct symbol *sp;
sp = getsp(name);
if( sp->s_def )
sp->s_def = null;
}
/* dodefine - do #define processing*/
/* Checks the define name, collects formal arguements and saves*/
/* macro definition, substituting for formal arguments as it goes.*/
dodefine() /* returns - none*/
{
char token[TOKSIZE], *args[MAXARGS], argbuf[ARGBSIZE];
register char *abp, *p;
register int type, nargs, i;
register struct symbol *sp;
if( (type=getntok(token)) != ALPHA ) {
error("bad define name: %s",token);
return;
}
sp = getsp(token);
symcopy(token,sp->s_name);
sp->s_def = defp;
nargs = 0;
abp = argbuf;
if( (type=gettok(token)) == LPAREN ) {
for( ; (type=getfarg(token)) != RPAREN; nargs++ ) {
if( nargs >= MAXARGS ) {
error("too many arguments");
break;
}
args[nargs] = abp;
for( p = token; *abp++ = *p++; ) {
if( abp >= &argbuf[ARGBSIZE] ) {
error("argument buffer overflow");
break;
}
}
}
putd(nargs);
}
else {
pbtok(token);
putd(NOARGS);
}
type = getntok(token); /*get next non-white token*/
for( ; type != NEWL && type != EOF; type = gettok(token) ) {
if( type == ALPHA ) {
for( i = 0; i < nargs; i++ ) {
if( strcmp(args[i],token) == 0 )
break;
}
if( i < nargs ) { /*sub ARG marker for formal arg*/
putd(i+1);
putd(ARG);
continue;
}
}
else if( type == BSLASH ) {
if( (i=ngetch()) == '\n' ) { /*multi-line macro?*/
if( filep == &filestack[0] && pbp == &pbbuf[0] ) {
lineno++;
doputc('\n',&outbuf);
}
}
putd(i);
continue;
}
for( p = token; *p ; )
putd(*p++);
}
pbtok(token);
putd('\0');
}
/* expand - expands the macro definition*/
/* Checks for define recursion and #define x x problems, collects*/
/* the actual arguments using getaarg, and then expands the macro*/
/* by pushing it onto the push back buffer, substituting arguments*/
/* as it goes.*/
expand(sp) /* returns - none*/
struct symbol *sp; /* pointer to macro to expand*/
{
char argbuf[ARGBSIZE], *args[MAXARGS], token[TOKSIZE];
register char *p, *abp, *mdef;
register int i, j, nargs, type;
if( pbflag++ > 100 ) {
error("define recursion");
return;
}
if( strcmp(sp->s_name,mdef=sp->s_def) == 0 ) { /*handle #define x x*/
while( *mdef )
putl(*mdef++);
return;
}
nargs = 0;
if( *mdef == NOARGS ) /*suppress grabbing of args*/
;
else if( gettok(token) != LPAREN )
pbtok(token);
else {
abp = &argbuf[0];
while( (type=getaarg(token)) != EOF ) {
if( nargs >= MAXARGS ) {
error("too many arguments");
return;
}
args[nargs++] = abp;
for( p = token; *abp++ = *p++; ) {
if( abp >= &argbuf[ARGBSIZE] ) {
error("argument buffer overflow");
return;
}
}
if( type == RPAREN )
break;
}
}
if( *mdef == NEWLABEL ) {
clabel = nlabel;
if( !nargs )
nlabel++;
else
nlabel =+ atoi(args[0]);
}
else if( *mdef == LABEL ) {
if( !nargs )
i = clabel;
else
i = clabel + atoi(args[0]);
pbnum(i);
pbtok("_L");
}
else {
mdef++; /*skip no. of args*/
for( p = mdef + strlen(mdef) - 1; p >= mdef; p-- ) {
if( *p == ARG ) {
if( (j= *--p) <= nargs )
pbtok(args[j-1]);
}
else
putback(*p);
}
}
}
/* getfarg - get macro formal parameters*/
/* Skips blanks and handles "," and ")".*/
getfarg(token) /* returns token type*/
char *token; /* token returned*/
{
register int type;
if( (type=getntok(token)) == RPAREN || type == ALPHA )
return(type);
if( type != COMMA || (type=getntok(token)) != ALPHA )
error("bad argument:%s",token);
return(type);
}
/* getntok - get next token, suppressing white space*/
/* Merely gettok's until non-white space is there*/
getntok(token) /* returns token type*/
char *token; /* token returned*/
{
register int type;
while( (type=gettok(token)) == WHITE )
;
return(type);
}
/* getaarg - get macro actual argument*/
/* This handles the collecting of the macro's call arguments.*/
/* Note that you may have parenthesis as part of the macro argument,*/
/* hence you need to keep track of them.*/
getaarg(argp) /* returns token type*/
char *argp; /* argument returned*/
{
int type, plevel, i;
register char *p, *ap;
char token[TOKSIZE];
ap = argp;
*ap = '\0';
plevel = 0;
i = TOKSIZE;
while( ((type=gettok(token)) != COMMA && type != RPAREN) || plevel ) {
for( p = token; *ap = *p++; ap++ )
if( --i <= 0 ) {
error("macro argument too long");
return(EOF);
}
if( type == LPAREN )
plevel++;
else if( type == RPAREN )
plevel--;
else if( type == EOF ) {
error("unexpected EOF");
cexit();
}
}
if( ap == argp )
type = EOF;
return(type);
}
/* push - push a #ifdef condition value on condition stack*/
/* Checks for stack overflow.*/
push(val) /* returns - none*/
int val; /* value to push*/
{
if( cstkptr >= &cstack[CSTKSIZE] ) {
error("condition stack overflow");
cexit();
}
*cstkptr++ = val;
}
/* pop - pop the #ifdef, etc. condition stack*/
/* Checks for stack undeflow.*/
pop() /* returns - top of condition stack*/
{
if( cstkptr <= &cstack[0] )
return(-1);
return( *--cstkptr );
}
/* doinclude - handle #include command*/
/* Checks for file name or library file name and pushes file on*/
/* include file stack.*/
doinclude(infile) /* returns - none*/
char *infile; /* [vlh] for quoted include files */
{
register int type, fd;
char token[TOKSIZE], fname[TOKSIZE];
register char *p, *q, c, *ptr1, *ptr2;
int i, j;
p = fname;
if( (type=getntok(token)) == SQUOTE || type == DQUOTE ) {
for( c = token[0], q = &token[1]; *q != c; )
*p++ = *q++;
*p = '\0';
p = getinclude(fname,infile);
}
else if( type != LESS ) {
error("bad include file");
return;
}
else {
while( (type=gettok(token))!=GREAT && type!=NEWL && type!=EOF )
for( q = token; *p = *q++; p++ )
;
if( type != GREAT ) {
error("bad include file name");
pbtok(token);
return;
}
p = getinclude(fname,0L);
}
eatup(); /*need here...*/
if( filep >= &filestack[FSTACK] )
error("includes nested too deeply");
else {
#ifdef NONEST
if (filep != &filestack[0]) { /* in main file ?? */
error("can not nest include files");
putback('\n');
return;
}
holdbuf.fd = inbuf.fd;
holdbuf.nc = inbuf.nc;
holdbuf.bp = inbuf.bp;
ptr1 = &holdbuf.buffer[0];
ptr2 = &inbuf.buffer[0];
for(i=0; i<BUFSIZE; i++)
*ptr1++ = *ptr2++;
#else
fd = inbuf.fd;
seek(fd,-inbuf.nc,1); /*back up file ptr*/
#endif
inbuf.nc = 0;
if( fopen(p,&inbuf,0) < 0 ) /* 3rd arg for versados */
error("can't open include file %s\n",p);
else {
filep->ifd = fd;
filep->lineno = 0; /* [vlh] */
doifile(p);
filep++;
}
}
putback('\n'); /*for eatup in domacro*/
}
doifile(p) /* [vlh] */
char *p;
{
register char *iptr;
register int ndx;
while ((ndx = index(p,FILESEP)) >= 0) p =+ ndx+1;
for( iptr = filep->ifile; *p; ) *iptr++ = *p++;
*iptr = 0;
}
/* getinclude - get include file full pathname */
char *
getinclude(fname,parent) /* [vlh] */
char *fname;
char *parent; /* search parent-file home directory ? */
{
register char *q, *t;
register int i, fd, ndx;
if (parent) { /* include filename surrounded by quotes */
q = (filep == &filestack[0]) ? parent : (filep-1)->ifile;
t = &inclname;
while ((ndx = index(q,FILESEP)) >= 0) {
ndx++;
while (ndx--) *t++ = *q++;
}
for (q=fname; *t++ = *q++; );
*t = 0;
if ((fd = open(inclname,0)) >= 0) { /* found it */
close(fd);
return(&inclname);
}
}
for (i=0; i<nincl; i++) {
for(t=inclname, q=incl[i]; *t++ = *q++; ) ;
for(q=fname, --t; *t++ = *q++; ) ;
*t = 0;
if ((fd = open(inclname,0)) >= 0) {
close(fd);
return(&inclname);
}
}
for(t=inclname, q=stdincl; *t++ = *q++; ) ;
for(q=fname, --t; *t++ = *q++; ) ;
*t = 0;
return(&inclname);
}
doline(infile) /* [vlh] 4.0 : returns - none */
char *infile;
{
register char *ptr;
char token[TOKSIZE];
register int ch, lnum, type;
while ((type = gettok(token)) == WHITE); /* skip white space */
if (type != DIGIT) {
error("invalid #line args");
return;
}
lnum = atoi(token);
do {
ch = ngetch();
} while (ctype[ch] == WHITE);
if (ctype[ch] != NEWL && ctype[ch] != EOF) {
ptr = &token;
do {
*ptr++ = ch;
ch = ngetch();
} while (ctype[ch]!=NEWL && ctype[ch]!=EOF && ctype[ch]!=WHITE);
*ptr = 0;
putid(token,lnum);
}
else {
if (filep == &filestack[0] && pbp == &pbbuf[0])
putid(infile,lnum);
else
putid((filep-1)->ifile,lnum);
}
literal = 1;
for( ; ctype[ch]!=NEWL && ctype[ch]!=EOF; )
ch = ngetch();
if (ctype[ch] != EOF)
while ( ctype[ ch = ngetch() ] != NEWL && ctype[ch] != EOF)
putl(ch);
putback('\n');
}
pbnum(num) /* returns - none*/
int num;
{
register int digit;
do {
digit = num % 10;
num =/ 10;
putback(digit+'0');
} while( num > 0 );
}

View File

@@ -0,0 +1,659 @@
/*
Copyright 1982
Alcyon Corporation
8716 Production Ave.
San Diego, Ca. 92121
*/
char *version "@(#) c68 preprocessor 4.0 - Mar 18, 1983";
#include "preproc.h"
#define NARGS 64
#define NINCL 10
#define ARGSIZE 1024
#define ICODE 0
#define STRINGS 1
#define MTEMP 2
#define ASTEMP 3
#define NTEMPS 4
char *fargs[NARGS+1];
char **fargp;
char argbuf[ARGSIZE];
char *cfiles[NARGS+1];
char *loadargs[NARGS+1];
char *fns[NTEMPS];
char *tfns[NTEMPS];
int ndefs;
char *incl[NINCL];
int nincl;
char *argp &argbuf[0];
int cflag;
int nflag;
int fflag; /* [vlh] 3.4 fast floating point format and library */
int eflag; /* [vlh] 3.4 ieee floating point format and library */
int lflag;
int oflag;
int pflag;
int Eflag; /* [vlh] 4.0 flag, Preprocessor only to stdout */
int sflag;
int wflag; /* [vlh] turn on warning messages */
int verbose; /* [vlh] 3.4 force printing of file being processed */
int xflag;
int v6flag; /* [vlh] 3.4 compile for version 6 */
int v7flag; /* [vlh] 3.4 */
int s3flag; /* [vlh] 3.4 */
int s5flag; /* [vlh] 3.4 */
int optimize; /* [vlh] 3.4 recognize optimization flag '-O' */
int status;
int oneflag;
int errno;
char *cptrone 1;
char *parser "/lib/c068";
char *cgen "/lib/c168";
char *onepass "/lib/c0168";
char *pref "/lib/c680.o";
char *loader "/bin/lo68";
char *asmprog "/bin/as68";
char *deflib "/lib/lib7.a";
char *deflibfp "/lib/libF.a"; /* [vlh] 3.4 */
char *deflibep "/lib/libE.a"; /* [vlh] 3.4 */
char *v6lib "/lib/libv6.a"; /* [vlh] 3.4 */
char *v7lib "/lib/libv7.a"; /* [vlh] 3.4 */
char *s3lib "/lib/libs3.a"; /* [vlh] 3.4 */
char *s5lib "/lib/libs5.a"; /* [vlh] 3.4 */
char *v6incl "/usr/include/v6/\0"; /* [vlh] 3.4 */
char *v7incl "/usr/include/v7/\0"; /* [vlh] 3.4 */
char *s3incl "/usr/include/sys3/\0"; /* [vlh] 3.4 */
char *s5incl "/usr/include/sys5/\0"; /* [vlh] 3.4 */
char *ldflg "-r";
int mmuflag; /*[vlh]replace nommu #ifdef'd var*/
/* cexit - exit from C compiler driver*/
/* This deletes any existing temps and exits with the error status.*/
cexit() /* returns - none*/
{
register int i;
if( !pflag )
for( i = 0; i < NTEMPS; i++ )
if( fns[i] )
unlink(fns[i]);
exit(status);
}
/*
* main - main routine for c68 Compiler system
* Handles the C68 arguments. For each C file given, the macro
* pre-processor is called, then the parser, code generator and
* assember are fexec'd. The loader arguments are collected and
* the loader is fexec'd.
*/
main(argc,argv)
int argc;
char **argv;
{
register char *arg, **p, **cfilep, **loadp, *sp;
register int nloadfiles, c, i, j, x;
#ifdef NOFORKS
if (argc != 3) {
error("usage: c68 inputfile outputfile");
exit(-1);
}
pflag++;
domacro(argv[1],argv[2],ndefs);
#else
cfilep = &cfiles[0];
loadp = &loadargs[0];
nloadfiles = 0;
sysinfo(0,&mmuflag); /*[vlh] mmu system ??*/
if (!mmuflag) { /*[vlh] default args*/
*loadp = ldflg;
lflag++;
}
for( p = argv, j = argc; --j > 0; ) { /*process arguments*/
if( *(arg= *++p) == '-' ) {
arg++;
for( i = 0; c = *arg++; i++ ) {
switch( c ) {
case 'c':
cflag++;
continue;
case '1':
oneflag++;
parser = onepass;
continue;
case 'D':
defs[ndefs].ptr = arg;
if ((x=index(arg,'=')) != -1) {
defs[ndefs++].value = (arg+x+1);
arg[x] = 0; /* get rid of value */
}
else defs[ndefs++].value = 0;
i++;
break;
case 'I':
incl[nincl++] = arg;
i++;
break;
case 'N':
nflag++;
continue;
case 'e': /* [vlh] 3.4 */
eflag++;
if (fflag)
ferror("incompatible flags : '-f' and '-e'");
continue;
case 'f': /* [vlh] 3.4 */
fflag++;
if (eflag)
ferror("incompatible flags : '-f' and '-e'");
continue;
case 'L':
lflag++;
continue;
case 'o':
if( --j <= 0 )
ferror("bad -o option");
*loadp++ = *p++;
if( strend(*p,".c") || strend(*p,".s") ||
strend(*p,".o") ) {
sp = makecopy(*p);
sp[strlen(sp)-2] = '\0';
*loadp++ = sp;
*loadp++ = setend(*p,'o');
nloadfiles++;
if( !strend(*p,".o") )
*cfilep++ = *p;
}
else
*loadp++ = *p;
continue;
case 'E': /* [vlh] 4.0 Preprocessor to stdout */
Eflag++;
case 'P':
pflag++;
cflag++;
continue;
case 'S':
sflag++;
cflag++;
nflag++;
continue;
case 't':
if( (c= *arg++) == '0' )
parser = "/usr/c68/c068";
else if( c == '1' )
cgen = "/usr/c68/c168";
else if( c == '\0' )
arg--;
continue;
case 'w': /* [vlh] */
wflag++;
continue;
case 'O': /* [vlh] 3.4 */
optimize++;
continue;
case 'v': /* [vlh] 3.4 print file name */
verbose++;
continue;
case '6': /* [vlh] 3.4 v6 compatibility */
v6flag++;
incl[nincl++] = v6incl;
continue;
case '7': /* [vlh] 3.4 v7 compatibility */
v7flag++;
incl[nincl++] = v7incl;
continue;
case '3': /* [vlh] 3.4 s3 compatibility */
s3flag++;
incl[nincl++] = s3incl;
continue;
case '5': /* [vlh] 3.4 s5 compatiblity */
s5flag++;
incl[nincl++] = s5incl;
continue;
default:
if( loadp >= &loadargs[NARGS] )
ferror("too many loader args");
*loadp++ = *p;
i++;
break;
}
break;
}
if( i )
continue;
}
if( strend(arg,".c") || strend(arg,".s") ) {
/*C or Assembler files to process*/
if( cfilep >= &cfiles[NARGS] )
ferror("too many files");
*cfilep++ = arg;
nloadfiles++;
if( !chkdup(arg) ) {
if( loadp >= &loadargs[NARGS] )
ferror("too many loader args");
*loadp++ = setend(arg,'o');
}
}
else if( !chkdup(arg) ) { /*check for loader args*/
if( loadp >= &loadargs[NARGS] )
ferror("too many loader args");
*loadp++ = arg;
if( strend(arg,".o") )
nloadfiles++;
}
}
if( cfilep != &cfiles[0] ) { /*had a C file?*/
if( signal(2,cexit) == cptrone ) /*catch rubouts, check ignore*/
signal(2,cptrone);
for( i = 0; i < NTEMPS; i++ ) /*allocate temps*/
fns[i] = maketemp(i);
for( p = &cfiles[0]; arg = *p++; ) { /*handle each C file*/
for( i = 0; i < NTEMPS; i++ )
tfns[i] = fns[i];
if( cfilep != &cfiles[1] || verbose )
printf("%s:\n",arg);
/*
* the following sets things up for the parser, the macro pre-processor
* is called (not forked), then the parser is fexec'd.
*/
asflag = strend(arg,".s");
if( pflag || asflag )
tfns[MTEMP] = setend(arg,'i');
if( domacro(arg,tfns[MTEMP],ndefs) == 0 || pflag ) {
cflag++;
status =+ mfail; /* preprocessor failure */
continue;
}
if( !asflag ) {
tfns[ASTEMP] = setend(arg,'s');
initfargs();
addfarg(parser);
addfarg(tfns[MTEMP]);
if( oneflag ) {
addfarg(tfns[ASTEMP]);
addfarg(tfns[STRINGS]);
if( lflag )
addfarg("-L");
if( sflag || nflag )
addfarg("-D");
addfarg("-1");
}
else {
addfarg(tfns[ICODE]);
addfarg(tfns[STRINGS]);
if ( fflag ) /* [vlh] 3.4 */
addfarg("-f");
else if ( eflag ) /* [vlh] 3.4 */
addfarg("-e");
if ( wflag )
addfarg("-w");
}
endfargs();
if( fexec(parser,fargs) ) {
status++;
cflag++;
continue;
}
/*this sets things up for the code generator*/
if( !oneflag ) {
initfargs();
addfarg(cgen);
addfarg(tfns[ICODE]);
addfarg(tfns[ASTEMP]);
if( !sflag )
fns[ASTEMP] = tfns[ASTEMP];
if( lflag )
addfarg("-L");
if( nflag || sflag )
addfarg("-D");
endfargs();
if( fexec(cgen,fargs) ) {
status++;
cflag++;
continue;
}
}
if( sflag )
continue;
}
else
tfns[ASTEMP] = tfns[MTEMP];
/*this sets things up for the assembler*/
initfargs();
addfarg(asmprog);
if( !asflag )
addfarg("-u");
if( lflag )
addfarg("-L");
addfarg(tfns[ASTEMP]);
endfargs();
if( fexec(asmprog,fargs) ) {
cflag++;
status++;
}
unlink(tfns[ASTEMP]);
}
}
if( !cflag && (loadp != &loadargs[0] || cfilep != &cfiles[0] )) {
/*
* set things up for the loader, this means that we need to add the
* C preface at the beginning of the program which has the jsr to
* main and then exits after return from main.
*/
initfargs();
addfarg(loader);
addfarg("-X");
i = 1;
for( p = loadargs; *p ; p++ ) {
if( i && strend(*p,".o") ) { //insert pref before 1st .o
i = 0;
addfarg(pref);
}
addfarg(*p);
}
if (fflag) /* [vlh] 3.4 */
addfarg(deflibfp);
if (eflag) /* [vlh] 3.4 */
addfarg(deflibep);
if (v6flag) /* [vlh] 3.4 */
addfarg(v6lib);
if (v7flag) /* [vlh] 3.4 */
addfarg(v7lib);
if (s3flag) /* [vlh] 3.4 */
addfarg(s3lib);
if (s5flag) /* [vlh] 3.4 */
addfarg(s5lib);
addfarg(deflib);
endfargs();
status =| fexec(loader,fargs);
/*
* if we were given one C file and there is one ".o" file, we remove
* the ".o" file.
*/
if( cfilep == &cfiles[1] && nloadfiles == 1 )
unlink(setend(cfiles[0],'o'));
}
#endif
cexit();
}
/* fexec - fork and exec*/
/* This forks a new task, then does an execv to execute the given*/
/* program with the given arguements.*/
fexec(fname,args) /* returns 1 if error, 0 otherwise*/
char *fname; /* file to execute*/
char **args; /* arguments to pass*/
{
register int pid, i;
int fstat;
/* if( (pid=fork()) == 0 ) { //child process*/
/* execv(fname,args);*/
/* printf("can't execv %s errno=%d\n",fname,errno);*/
/* exit(1);*/
/* }*/
pid = maketask(fname,0,0,args); /*do fork & exec*/
if( pid < 0 ) {
printf("can't maketask %s err=%o\n",fname,errno);
return(1);
}
while( pid != wait(&fstat) ) /*wait for child*/
;
if( (i=fstat&0377) != 0 && i != 14 ) {
if( i != 2 )
printf("%s error terminated, status $%x\n",fname,i);
status++;
cexit();
}
return( (fstat>>8) & 0377 );
}
/* setend - set the end character of a string*/
/* This grabs a copy of the string and sets the last character to*/
/* the given character. This is used to generate ".o", ".i" and*/
/* ".s" file names.*/
char *setend(s,c) /* returns pointer to string*/
char *s; /* pointer to old string*/
int c; /* character to end string with*/
{
register char *p;
p = makecopy(s);
p[strlen(p)-1] = c;
return(p);
}
/* chkdup - checks for duplicate ".o" files in file list*/
/* Goes thru the loader argument list checking for the given*/
/* ".o" file name.*/
chkdup(s) /* returns 1 if found, 0 otherwise*/
char *s; /* pointer to argument*/
{
register char **l;
if( strend(s,".o") ) {
for( l = &loadargs[0]; *l; )
if( !strcmp(*l++,s) )
return(1);
}
return(0);
}
/* makecopy - makes a copy of a string*/
/* This allows for manipulating the file name, while allowing the*/
/* saving of the old file name.*/
char *makecopy(s) /* returns pointer to string*/
char *s; /* string to copy*/
{
register char *p;
register int ndx;
if (strncmp("/tmp/",s,5) != 0) /* don't truncate tmp file names */
while ((ndx = index(s,'/')) != -1) s =+ ndx+1; /* [vlh] */
for( p = argp; *argp++ = *s++; )
;
return(p);
}
/* initfargs - initialize fexec arg block*/
/* This sets the arg block pointer to the beginning of the block.*/
initfargs() /* returns - none*/
{
fargp = &fargs[0];
}
/* addfarg - add fexec argument*/
/* This takes the given arguement and adds it to the argment block*/
addfarg(s)
char *s;
{
if( fargp >= &fargs[NARGS] )
ferror("too many args");
*fargp++ = s;
}
/* endfargs - end fexec argument block*/
/* This ends the argument block with a zero pointer.*/
endfargs() /* returns - none*/
{
*fargp = 0;
}
/* ferror - fatal error*/
/* Outputs error message and exits with error status.*/
ferror(s,x1,x2,x3,x4,x5,x6) /* returns - none*/
char *s; /* printf string*/
int x1, x2, x3, x4, x5, x6; /* printf args*/
{
printf(s,x1,x2,x3,x4,x5,x6);
printf("\n");
status++;
cexit();
}
/* maketemp - make a temporary file name*/
/* Generates unique file name with process id*/
char *maketemp(arb) /* returns file name*/
int arb; /* arbitrary number*/
{
#ifndef NOFORKS
char *p, tmp[6];
p = makecopy("/tmp/ct6");
argp--;
itoa(getpid(),tmp,1);
makecopy(tmp);
argp--;
makecopy(".");
argp--;
itoa(arb,tmp,1);
makecopy(tmp);
return(p);
#endif
}
/* strcmp - string comparison*/
/* Compares two strings for equality, less or greater.*/
strcmp(s,t) /* returns 0 for equality,*/
/* neg for < and pos for >.*/
char *s; /* first string*/
char *t; /* second string*/
{
for( ; *s == *t; s++, t++ )
if( *s == '\0' )
return(0);
return( *s - *t );
}
/* strncmp - string comparison*/
/* Compares two strings for equality, less or greater.*/
strncmp(s,t,n) /* neg for < and pos for >.*/
char *s; /* first string*/
char *t; /* second string*/
{
for( ; *s == *t && n; s++, t++, n--)
if( *s == '\0' )
return(0);
return((n) ? *s - *t : 0);
}
/* strlen - string length*/
/* Computes number of bytes in string.*/
strlen(s) /* returns string length*/
char *s; /* string to compute length*/
{
register int n;
for( n = 0; *s++ != '\0'; )
n++;
return(n);
}
/* itoa - integer to ASCII conversion*/
/* Converts integer to ASCII string, handles '-'.*/
itoa(n,s,w) /* returns - none*/
int n; /* number to convert*/
char *s; /* resulting string*/
int w; /* minimum width of string*/
{
register char *tp;
register int sign, i;
char temp[6];
if( (sign=n) < 0 )
n = -n;
i = 0;
tp = &temp;
do {
i++;
*tp++ = n % 10 + '0';
} while( (n =/ 10) > 0 );
if( sign < 0 ) {
i++;
*tp++ = '-';
}
while( --w >= i ) /*pad on left with blanks*/
*s++ = ' ';
while( --i >= 0 ) /*move chars reversed*/
*s++ = *--tp;
*s = '\0';
}
/* strend - set string end*/
/* This is used to compare the endings of file names for ".c", etc.*/
strend(s,t) /* returns 1 if match, 0 otherwise*/
char *s; /* string to compare*/
char *t; /* string ending*/
{
int ls, lt;
if( (ls=strlen(s)) < (lt=strlen(t)) )
return(0);
if( !strcmp(&s[ls-lt],t) )
return(1);
return(0);
}
v6flush(v6buf)
struct iobuf *v6buf;
{
register i;
i = BLEN - v6buf->nunused;
v6buf->nunused = BLEN;
v6buf->xfree = &(v6buf->buff[0]);
if(write(v6buf->fildes,v6buf->xfree,i) != i)
return(-1);
return(0);
}
/* index - find the index of a character in a string*/
/* This is identical to Software Tools index.*/
index(str,chr) /* returns index of c in str or -1*/
char *str; /* pointer to string to search*/
char chr; /* character to search for*/
{
register char *s;
register int i;
for( s = str, i = 0; *s != '\0'; i++ )
if( *s++ == chr )
return(i);
return(-1);
}

View File

@@ -0,0 +1,26 @@
// maketask call for unix
int maketask(fname,flags,priority,argptrs)
char *fname;
int flags,priority;
char **argptrs;
{
register int pid;
if(flags==0) { //fork and exec
if((pid=fork()) == 0) { //child process
doexecv:
execv(fname,argptrs);
printf("execv failed\n");
exit(-1);
}
return(pid); //return child process id
}
if(flags==2) { //fork only
return(fork());
}
if(flags==4) { //exec only
goto doexecv;
}
return(-1);
}

View File

@@ -0,0 +1,147 @@
/*
Copyright 1982
Alcyon Corporation
8716 Production Ave.
San Diego, Ca. 92121
*/
#include "../icode.h"
/*cexpr operators*/
#define EOF 0
#define SUB 1
#define ADD 2
#define NOT 3
#define NEG 4
#define LPAREN 5
#define RPAREN 6
#define QMARK 7
#define COLON 8
#define OR 9
#define AND 10
#define XOR 11
#define EQUAL 12
#define NEQUAL 13
#define LESS 14
#define LSEQUAL 15
#define GREAT 16
#define GREQUAL 17
#define LSHIFT 18
#define RSHIFT 19
#define MULT 20
#define DIV 21
#define MOD 22
#define COMPL 23
#define CONST 24
#define LASTOP COMPL /*up to here used by cexpr*/
#define SQUOTE 25
#define DQUOTE 26
#define ANYC 27
#define BADC 28
#define COMMA 29
#define NEWL 30
#define POUND 31
#define ALPHA 32
#define DIGIT 33
#define BSLASH 34
#define WHITE 35
#define BUFSIZE 512
#define LINESIZE 512
#define ARG -1
#define NEWLABEL -2
#define LABEL -3
#define NOARGS -4
#define MAXARGS 60
#define ARGBSIZE 1000
#define TOKSIZE 300 /*BUG 4/20/82 was 128*/
#define DEFSIZE 1024
#define PBSIZE 1000
#define DEFINE 1
#define UNDEF 2
#define INCLUDE 3
#define IFDEF 4
#define IFNDEF 5
#define ELSE 6
#define ENDIF 7
#define IF 8
#define LINE 9
#define SKIP 0
#define NOSKIP 1
#define SOH '\01'
#define SSIZE 8
#define HSIZE 517 /* 3.4 made prime */
#define FSTACK 10
#define TRUE 1
#define FALSE 0
#define NDEFS 20
struct symbol {
char s_name[SSIZE];
char *s_def;
} symtab[HSIZE];
/*buffered I/O structure*/
struct ibuf {
int fd;
int nc;
char *bp;
char buffer[BUFSIZE];
} inbuf, outbuf;
/* command line define structure */
struct defstruc {
char *ptr;
char *value;
} defs[NDEFS];
struct stackstruc { /* [vlh] */
int ifd;
char ifile[13];
int lineno;
} filestack[FSTACK], *filep; /* stack of incl files, ptr to... */
#ifdef VERSADOS
#define NONEST 1
#define NOFORKS 1
#endif
#ifdef VMS
#define NONEST 1
#endif
#ifdef NONEST
struct ibuf holdbuf; /* alternate buffer, hold main file info */
#endif
int mfail; /*macro error flag*/
int skip; /*skipping current line*/
char *defap; /*pointer to available define area*/
char *defp; /*pointer to next avail define byte*/
int defcount; /*bytes left in define area*/
int defused; /*number of bytes used in define area*/
int defmax; /*maximum define area used*/
int pflag;
int asflag;
/*line to output after macro substitution*/
char line[LINESIZE+2]; /*line buffer*/
char *linep; /*current line pointer*/
int loverflow; /*line overflow flag*/
int lineno;
/*push back buffer*/
char pbbuf[PBSIZE]; /*push back buffer*/
char *pbp; /*push back pointer*/
int pbflag; /*checks for recursive definition*/
char null[]; /*used for undef'd symbols*/
char *lookup();
char *setend();
char *makecopy();
char *makecopy();
char *maketemp();
char *sbrk();
struct symbol *getsp();

View File

@@ -0,0 +1,6 @@
/* fake sysinfo call for PDP-11, returns as if MMU system */
sysinfo(flag,addr)
int flag, *addr;
{
*addr = 1;
}

View File

@@ -0,0 +1,16 @@
atoi(as)
char *as;
{
register int n, sign;
register char *s;
s = as;
while( *s==' ' || *s=='\n' || *s == '\t')
s++;
sign = 1;
if( *s == '+' || *s == '-' )
sign = (*s++=='+') ? 1 : -1;
for( n = 0; *s >= '0' && *s <= '9'; s++ )
n = (n * 10) + (*s - '0');
return( sign * n );
}

View File

@@ -0,0 +1 @@
char *compiled "@(#) preprocessor - Fri Mar 18 12:37 1983";