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,340 @@
/*
Copyright 1982, 1983
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((struct symbol *)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 op1, op2, pri;
for( pri = opinfo[opr]&OPPRI; pri < *priptr; ) {
if( *oprptr == LPAREN ) {
if( opr == RPAREN ) {
oprptr--;
priptr--;
return(1);
}
break;
}
op1 = *opnptr;
if( 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,6 @@
$ diff/out=CEXPR.DIF CEXPR.C [-.orgcp68]CEXPR.C
$ diff/out=LEX.DIF LEX.C [-.orgcp68]LEX.C
$ diff/out=MACRO.DIF MACRO.C [-.orgcp68]MACRO.C
$ diff/out=MAIN.DIF MAIN.C [-.orgcp68]MAIN.C
$ diff/out=UTIL.DIF UTIL.C [-.orgcp68]UTIL.C
$ diff/out=PREPROC.DIF PREPROC.H [-.orgcp68]PREPROC.H

View File

@@ -0,0 +1,433 @@
/*
Copyright 1982, 1983
Alcyon Corporation
8716 Production Ave.
San Diego, Ca. 92121
*/
#include "preproc.h"
int status;
extern 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 - 2 )); /* [vlh] 4.1 added -2 */
}
/* 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';
*q = '\0'; /* [vlh] 4.1, force null terminator */
}
/* 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*/
{
#ifndef ALTER_PR
if (literal)
printf((char *)STDERR,"%s, # line %d: ",lit_file, lit_num);
else if (filep == &filestack[0]) /* [vlh] 3.4 not in include */
printf((char *)STDERR,"%s, # line %d: ",source, lineno);
else
printf((char *)STDERR,"%s, # line %d: ",(filep)->ifile,
(filep)->lineno);
printf((char *)STDERR,s,x1,x2,x3,x4,x5,x6);
cputc('\n',STDERR);
#else
if (literal)
printf("%s, # line %d: ",lit_file, lit_num);
else if (filep == &filestack[0]) /* [vlh] 3.4 not in include */
printf("%s, # line %d: ",source, lineno);
else
printf("%s, # line %d: ",(filep)->ifile,(filep)->lineno);
printf(s,x1,x2,x3,x4,x5,x6);
printf("\n");
#endif
status++;
}
/* 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(&(filep->inbuf))) < 0 ) {
if( filep == &filestack[0] )
return(EOF);
close(filep->inbuf.fd);
filep--;
#ifdef NONEST
inbuf.cc = filep->tcc;
inbuf.cp = filep->tcp;
p = &inbuf.cbuf[0];
q = &filep->tbuf[0];
for(i = 0; i<BSIZE; i++)
*p++ = *q++;
#else
/*sw This code no longer necessary ...
inbuf.cc = 0;
inbuf.cp = &inbuf.cbuf[0];
*/
#endif
/*sw filep->inbuf.fd = filep->ifd; */
if( filep == &filestack[0] ) { /*need line for #include...*/
lineno++;
putid(source,lineno); /* [vlh] 4.2 id line .... */
}
else {
(filep)->lineno++;
putid((filep)->ifile,(filep)->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((char *)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, *s;
register int type, t, l;
p = token;
c = ngetch();
*p++ = c;
switch( type = ctype[c] ) {
case SQUOTE:
case DQUOTE:
if(getstr(token,TOKSIZE,c))
return(type);
else { /*[vlh]4.3, ignore incomplete strings... could be asm comment*/
token[0] = '\n';
return(NEWL);
}
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('*') ) {
if (Cflag) {
putl((int)'/');
putl((int)'*');
}
l = 0; /* [vlh] 4.3, change in line counting technique */
while( (c=ngetch()) != EOF )
if( c == '\n' ) {
l++; /* [vlh] 4.3, keep line counter */
if (Cflag) { /* [vlh] 4.2 */
putl((int)'\0');
s = line;
while (*s)
doputc(*s++,&outbuf);
initl();
}
doputc(' ',&outbuf);
doputc('\n',&outbuf);
}
else if( c == '*' && peekis('/') ) {
if (Cflag) { /* [vlh] 4.2 */
putl((int)'*');
putl((int)'/');
}
break;
}
else if (Cflag) /* [vlh] 4.2.c */
putl((int)c);
if( c == EOF )
error("no */ before EOF");
if (filep == &filestack[0]) /* [vlh] 4.3 */
lineno += l;
else /* [vlh] 4.3, update include lineno */
(filep)->lineno += l;
type = WHITE;
token[0] = ' ';
}
else if( peekis('/') ) {
if (Cflag) {
putl((int)'/');
putl((int)'/');
}
while( (c=ngetch()) != EOF && c != '\n' )
if (Cflag)
putl(c);
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, c;
p = str;
*p++ = endc;
for( i = nchars-2; (c=ngetch()) != endc; ) {
if( c == EOF || c == '\n' ) { /* [vlh] 4.3, ignore non ended string */
*p = '\0';
p = str;
while(*p)
putl((int)*p++);
return(0);
} /* [vlh] 4.3, may be assembly language comment !!!! */
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';
return(1);
}
/* 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 iob *buffer;
{
if (!Eflag)
putc(ch,buffer);
else
putchar(ch);
}
#ifdef DECC /*sw You should really do this as a library...*/
getc(ibuf)
struct iob *ibuf;
{
if (ibuf->cc <= 0) {
ibuf->cp = &(ibuf->cbuf[0]);
ibuf->cc = read(ibuf->fd,ibuf->cp,BSIZE);
}
if (ibuf->cc <= 0)
return(-1);
ibuf->cc--;
return((int)(*(ibuf->cp)++)&0xff);
}
fopen(fname,ibuf)
char *fname;
register struct iob *ibuf;
{
ibuf->cc = 0; /* no chars */
ibuf->fd = open(fname,0);
return(ibuf->fd);
}
#endif

View File

@@ -0,0 +1,3 @@
$2lo68 -f $1 -s -r -u_nofloat -o cp68.rel 0$1s.o main.o lex.o macro.o cexpr.o util.o 0$2klib 0$2clib
era *.o
user 12!make $1 $2

View File

@@ -0,0 +1,21 @@
$ num
CEXPR.C
CEXPR.lis
$ num
LEX.C
LEX.lis
$ num
MACRO.C
MACRO.lis
$ num
MAIN.C
MAIN.lis
$ num
UTIL.C
UTIL.lis
$ num
VERSION.C
VERSION.lis
$ num
PREPROC.H
PREPROC.lst

View File

@@ -0,0 +1,10 @@
/*
* Use this file to determine what kind of machine you want the
* Alcyon stuff to run on ....
*/
#define MC68000 1 /* 68000 version */
/*#define VAX 1*/ /* VAX Version */
/*#define PDP11 1*/ /* PDP-11 Version*/
#define CPM 1 /* CP/M Operating System*/
/*#define UNIX 1*/ /* UNIX Operating System*/
/*#define VMS 1*/ /* VMS Operating System*/

View File

@@ -0,0 +1,10 @@
/*
* Use this file to determine what kind of machine you want the
* Alcyon stuff to run on ....
*/
#define MC68000 1 /* 68000 version */
/*#define VAX 1*/ /* VAX Version */
/*#define PDP11 1*/ /* PDP-11 Version*/
#define CPM 1 /* CP/M Operating System*/
/*#define UNIX 1*/ /* UNIX Operating System*/
/*#define VMS 1*/ /* VMS Operating System*/

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,361 @@
/*
Copyright 1982, 1983
Alcyon Corporation
8716 Production Ave.
San Diego, Ca. 92121
*/
char *version = "@(#)main.c 1.6 12/28/83";
#include "preproc.h"
#include <ctype.h>
#define NARGS 64
#define FLAGS "[-C] [-P] [-E] [-D] [-I] [-6] [-7] [-3]"
#define USAGE "usage: %s %s source [dest]\n"
#ifdef REGULUS /*sw not MC68000 */
char *v6incl = "/usr/include/v6";
char *v7incl = "/usr/include/v7";
char *s3incl = "/usr/include/sys3";
char *ucbincl = "/usr/include/ucb";
char *s5incl = "/usr/include/sys5";
#endif
#ifdef UNIX
char *v6incl = "/usr/include/c68/v6";
char *v7incl = "/usr/include/c68/v7";
char *s3incl = "/usr/include/c68/sys3";
char *ucbincl = "/usr/include/c68/ucb";
char *s5incl = "/usr/include/c68/sys5";
#endif
#ifdef VMS
# ifdef DECC
char *v6incl = "v6";
char *v7incl = "v7";
char *s3incl = "sys3";
char *ucbincl = "ucb";
char *s5incl = "sys5";
# else
char *v6incl = "lib:";
char *v7incl = "lib:";
char *s3incl = "lib:";
char *ucbincl = "lib:";
char *s5incl = "lib:";
# endif
#endif
#ifdef CPM
char *v6incl = "";
char *v7incl = "";
char *s3incl = "";
char *ucbincl = "";
char *s5incl = "";
#endif
char *stdincl; /*sw define it so i can clobber it ... */
char *incl[NINCL];
int ndefs, nincl;
int status = 0;
extern int errno;
/*
* 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;
register char **argv;
{
register char *arg, *calledby;
register int c, i, j, x;
register char *p;
calledby = *argv++;
#ifdef CPM
calledby = "cp68";
#endif
if (argc < 2) { /* cpp source */
printf(USAGE,calledby,FLAGS);
exit(-1);
}
for( ; --argc > 0 && **argv == '-'; ) { /*process arguments*/
*(arg = *argv++);
arg++;
for( i = 0; c = *arg++; ) {
switch( c ) {
case 'D':
case 'd': /*sw Make case-insensitive */
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++;
#ifdef CPM /*sw Up-case the argument */
p = defs[ndefs-1].ptr;
while(*p) {
*p = toupper(*p);
p++;
}
#endif
#ifdef WHITESM /*sw Up-case the argument */
p = defs[ndefs-1].ptr;
while(*p) {
*p = toupper(*p);
p++;
}
#endif
break;
case 'I':
case 'i':
#ifdef CPM
stdincl = *argv++; /*sw Compatible with our past...*/
--argc;
#endif
#ifdef WHITESM
stdincl = *argv++; /*sw Compatible with our past...*/
--argc;
#endif
#ifdef REGULUS
incl[nincl++] = arg;
i++;
#endif
#ifdef UNIX
incl[nincl++] = arg;
i++;
#endif
#ifdef VERSADOS /*sw ?Will this work? */
incl[nincl++] = arg;
i++;
#endif
break;
case 'C': /* [vlh] 4.2 Leave comments in... */
case 'c':
Cflag++;
/* sw "break" here???? */
case 'E': /* [vlh] 4.0 Preprocessor to stdout */
case 'e':
Eflag++;
continue;
case 'P': /* preprocessor pass only */
case 'p':
pflag++;
continue;
case '6': /* [vlh] 3.4 v6 compatibility */
incl[nincl++] = v6incl;
continue;
case '7': /* [vlh] 3.4 v7 compatibility */
incl[nincl++] = v7incl;
continue;
case '3': /* [vlh] 3.4 s3 compatibility */
incl[nincl++] = s3incl;
continue;
case '4': /* [vlh] 4.3 ucb compatibility */
incl[nincl++] = ucbincl;
continue;
case '5': /* [vlh] 3.4 s5 compatiblity */
incl[nincl++] = s5incl;
continue;
default:
printf(USAGE,calledby,FLAGS);
exit(-1);
} /* end of case statement */
if (i)
break;
} /* end of for statement */
} /* end of for statement */
if (argc > 2) { /* source [dest] */
printf(USAGE,calledby,FLAGS);
exit(-1);
}
source = *argv++;
if ( !Eflag )
if (argc==2) /* destination file specified */
strcpy(dest,*argv);
else
make_intermediate();
asflag = (source[strlen(source)-1] == 's');
domacro(ndefs);
cexit();
}
/* cexit - exit from C compiler driver*/
/* This deletes any existing temps and exits with the error status.*/
cexit() /* returns - none*/
{
exit(status);
}
/**
* 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[0];
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';
}
/* 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);
}
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 );
}
make_intermediate() /* returns pointer to string*/
{ /* if source t.c dest <= t.i */
register char *d, *s;
register int ndx;
s = source;
while ((ndx = index(s,'/')) != -1)
s += ndx+1; /* [vlh] */
for( d = dest; *d++ = *s++; ) ;
*(d-2) = 'i'; /* overwrite termination character */
}
/* cputc - put a character to a file descriptor (used by error) */
cputc(c, fn)
char c;
int fn;
{
#ifdef VERSADOS
versaputchar(c);
#else
if (fn == STDERR)
write(STDERR, &c, 1);
else
putchar(c);
#endif
}
#ifdef VERSADOS
extern struct iob *fout;
putchar(c)
{
versaputchar(c);
}
#endif
v6flush(v6buf)
struct iob *v6buf;
{
register i;
i = BSIZE - v6buf->cc;
v6buf->cc = BSIZE;
v6buf->cp = &(v6buf->cbuf[0]);
if(write(v6buf->fd,v6buf->cp,i) != i)
return(-1);
return(0);
}
#ifdef VERSADOS
#define BSIZE 512
struct iob versfout = { 1, BSIZE, &versfout.cbuf[0]};
versaputchar(c)
char c;
{
if (c == '\n') { /* end of line */
if (versaflush()) /* write one line */
return(-1);
return(c);
}
/* buffered output */
if (versfout.cc <= 0) {
versfout.cp = &(versfout.cbuf[0]);
if (write(versfout.fd,versfout.cp,BSIZE) != BSIZE)
return(-1);
versfout.cc = BSIZE;
}
*(versfout.cp)++ = c;
versfout.cc--;
return(c);
}
versaflush()
{
register short size, fildes;
if ((size = (BSIZE - versfout.cc)) == 0)
return(0);
versfout.cc = BSIZE;
versfout.cp = &(versfout.cbuf[0]);
fildes = (versfout.fd <= STDERR) ? 6 : versfout.fd;
if (write(fildes,versfout.cp,size) < 0)
return(-1);
return(0);
}
#endif

View File

@@ -0,0 +1,48 @@
pip machine.h=machine.68k
$2cp68 -i 0$1 cexpr.c $1x.i
$2c068 $1x.i $1x.1 $1x.2 $1x.3 -f
era $1x.i
$2c168 $1x.1 $1x.2 cexpr.s
era $1x.1
era $1x.2
$2as68 -l -u -f $1 -s 0$1 cexpr.s
era cexpr.s
$2cp68 -i 0$1 lex.c $1x.i
$2c068 $1x.i $1x.1 $1x.2 $1x.3 -f
era $1x.i
$2c168 $1x.1 $1x.2 lex.s
era $1x.1
era $1x.2
$2as68 -l -u -f $1 -s 0$1 lex.s
era lex.s
$2cp68 -i 0$1 macro.c $1x.i
$2c068 $1x.i $1x.1 $1x.2 $1x.3 -f
era $1x.i
$2c168 $1x.1 $1x.2 macro.s
era $1x.1
era $1x.2
$2as68 -l -u -f $1 -s 0$1 macro.s
era macro.s
$2cp68 -i 0$1 main.c $1x.i
$2c068 $1x.i $1x.1 $1x.2 $1x.3 -f
era $1x.i
$2c168 $1x.1 $1x.2 main.s
era $1x.1
era $1x.2
$2as68 -l -u -f $1 -s 0$1 main.s
era main.s
$2cp68 -i 0$1 util.c $1x.i
$2c068 $1x.i $1x.1 $1x.2 $1x.3 -f
era $1x.i
$2c168 $1x.1 $1x.2 util.s
era $1x.1
era $1x.2
$2as68 -l -u -f $1 -s 0$1 util.s
era util.s
link $1 $2

View File

@@ -0,0 +1,204 @@
/*
Copyright 1982
Alcyon Corporation
8716 Production Ave.
San Diego, Ca. 92121
*/
#include "machine.h"
#ifdef WHITESM
# include <stdio.h>
# include <klib.h>
# define ALTER_PR 1
#endif
#ifdef CPM
# include <stdio.h>
# include <klib.h>
# define ALTER_PR 1
#endif
#ifdef DECC
# define ALTER_PR 1
# define NONEST 1
#endif
#ifdef VERSADOS
# define NONEST 1
# define NOFORKS 1
# define ALTER_PR 1
#endif
#ifdef VAX11
# ifndef VMS
# define UNIX 1
# endif
#endif
#ifdef PDP11
# define UNIX 1
#endif
/*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
/* Types of preprocessor macros */
#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
/* Magic Numbers used in Macros */
#define ARG -1
#define NEWLABEL -2
#define LABEL -3
#define NOARGS -4
/* Skip state, using #ifdef... */
#define SKIP 0
#define NOSKIP 1
/* General Defines */
#define SOH '\01'
#define SSIZE 8
#define BSIZE 512
#define LINESIZE 512
#define MAXARGS 60
#define ARGBSIZE 1000
#define TOKSIZE 300 /*BUG 4/20/82 was 128*/
#define DEFSIZE 1024
#define PBSIZE 1000
#define STDERR 2 /* [vlh] 4.2, write errors to.... */
#define TRUE 1
#define FALSE 0
#define NDEFS 20
#define CSTKSIZE 20
#define FILESEP '/'
#define NINCL 10
#define LABSTART 1000
#define NUMLEN 6
#ifndef VERSADOS
# define HSIZE 1024
#else
# define HSIZE 2048
#endif
/* Symbol Table Entry structure */
struct symbol {
char s_name[SSIZE];
char *s_def;
} symtab[HSIZE];
/*buffered I/O structure*/
struct iob {
int fd;
int cc;
char *cp;
char cbuf[BSIZE];
} outbuf;
/* command line define structure */
struct defstruc {
char *ptr;
char *value;
} defs[NDEFS];
#define FSTACK 10
#define MAXPSIZE 128
struct stackstruc { /* [vlh] */
int ifd;
char ifile[MAXPSIZE];
int lineno;
#ifdef NONEST
char tbuf[BSIZE]; /* hold buffer in include... */
int tcc; /* hold count into buffer... */
char *tcp; /* pointer into buffer... */
#else /*sw Nesting really could be allowed on all */
struct iob inbuf; /*sw Moved this for include file nesting */
#endif
} filestack[FSTACK], *filep; /* stack of incl files, ptr to... */
/* Variables used by #line macros */
int literal; /*[vlh] 4.0 using #line */
int lit_num; /* for error messages */
char lit_file[]; /* for error messages */
/* Flag Variable Declarations */
int pflag;
int Cflag;
int Eflag;
int asflag;
char *source; /* preprocessor source file */
char dest[MAXPSIZE]; /* preprocessor destination file */
/* Miscellaneous Variable Declarations */
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*/
/*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*/
/* Function declarations */
char *lookup();
char *setend();
char *makecopy();
char *maketemp();
char *sbrk();
struct symbol *getsp();

View File

@@ -0,0 +1,14 @@
$1vsend preproc.h
$1vsend main.c
$1vsend macro.c
$1vsend make.sub
$1vsend link.sub
$1vsend cexpr.c
$1vsend cp68.rel
$1vsend util.c
$1vsend version.c
$1vsend machine.68k
$1vsend lex.c
$1vsend send.sub
$1vsend machine.h
$1vsend done

View File

@@ -0,0 +1,31 @@
/*
Copyright 1983
Alcyon Corporation
8716 Production Ave.
San Diego, CA 92121
*/
#include "preproc.h"
char *strcpy(s,t)
register char *s, *t;
{
register char *s1;
s1 = s;
while(*s++ = *t++)
;
return(s1);
}
strcmp(s,t)
register char *s, *t;
{
while( *s ) {
if( *s++ != *t++ ) {
s--;
t--;
break;
}
}
return( *s - *t );
}

View File

@@ -0,0 +1 @@
char *compiled = "@(#) c68 Preprocessor 4.3 - Thu Jan 5 09:49 1984";