mirror of
https://github.com/SEPPDROID/Digital-Research-Source-Code.git
synced 2025-10-26 01:44:21 +00:00
Upload
Digital Research
This commit is contained in:
@@ -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);
|
||||
}
|
||||
@@ -0,0 +1,251 @@
|
||||
/*
|
||||
Copyright 1982
|
||||
Alcyon Corporation
|
||||
8716 Production Ave.
|
||||
San Diego, Ca. 92121
|
||||
*/
|
||||
#include "machine.h"
|
||||
/*
|
||||
* intermediate code operators
|
||||
* 0=>EOF, special operator
|
||||
*/
|
||||
#define EOF 0
|
||||
|
||||
/*1-59=>operators that generate code (entries in code gen optab)*/
|
||||
#define ADD 1
|
||||
#define SUB 2
|
||||
#define MULT 3
|
||||
#define DIV 4
|
||||
#define MOD 5
|
||||
#define RSH 6
|
||||
#define LSH 7
|
||||
#define AND 8
|
||||
#define OR 9
|
||||
#define XOR 10
|
||||
#define NOT 11
|
||||
#define UMINUS 12
|
||||
#define COMPL 13
|
||||
#define PREDEC 14
|
||||
#define PREINC 15
|
||||
#define POSTDEC 16
|
||||
#define POSTINC 17
|
||||
#define ASSIGN 18
|
||||
#define EQADD 19
|
||||
#define EQSUB 20
|
||||
#define EQMULT 21
|
||||
#define EQDIV 22
|
||||
#define EQMOD 23
|
||||
#define EQRSH 24
|
||||
#define EQLSH 25
|
||||
#define EQAND 26
|
||||
#define EQOR 27
|
||||
#define EQXOR 28
|
||||
#define FJSR 29
|
||||
#define EQUALS 30
|
||||
#define NEQUALS 31
|
||||
#define GREAT 32
|
||||
#define GREATEQ 33
|
||||
#define LESS 34
|
||||
#define LESSEQ 35
|
||||
#define INT2L 36
|
||||
#define LONG2I 37
|
||||
|
||||
/*machine dependent operators that generate code*/
|
||||
#define BTST 38
|
||||
#define LOAD 39
|
||||
#define LMULT 40
|
||||
#define LDIV 41
|
||||
#define LMOD 42
|
||||
#define LEQMULT 43
|
||||
#define LEQDIV 44
|
||||
#define LEQMOD 45
|
||||
#define EQADDR 46
|
||||
#define EQNOT 47
|
||||
#define EQNEG 48
|
||||
#define DOCAST 49
|
||||
|
||||
#define STASSIGN 50 /*[vlh]*/
|
||||
#define LONG2F 51 /*[vlh] 3.4*/
|
||||
#define FLOAT2L 52 /*[vlh] 3.4*/
|
||||
#define INT2F 53 /*[vlh] 3.4*/
|
||||
#define FLOAT2I 54 /*[vlh] 3.4*/
|
||||
#define LCGENOP 55 /*change if adding more operators...*/
|
||||
|
||||
/*intermediate code operators that do not generate code*/
|
||||
#define ADDR 60
|
||||
#define INDR 61
|
||||
#define LAND 62
|
||||
#define LOR 63
|
||||
#define QMARK 64
|
||||
#define COLON 65
|
||||
#define COMMA 66
|
||||
#define CINT 67
|
||||
#define CLONG 68
|
||||
#define SYMBOL 69
|
||||
#define AUTOINC 70
|
||||
#define AUTODEC 71
|
||||
#define CALL 72
|
||||
#define NACALL 73
|
||||
#define BFIELD 74
|
||||
#define IFGOTO 75
|
||||
#define INIT 76
|
||||
#define CFORREG 77
|
||||
#define DCLONG 78
|
||||
#define CFLOAT 79 /*[vlh] 3.4*/
|
||||
|
||||
/*operators local to parser*/
|
||||
#define CAST 80
|
||||
#define SEMI 81
|
||||
#define LCURBR 82
|
||||
#define RCURBR 83
|
||||
#define LBRACK 84
|
||||
#define RBRACK 85
|
||||
#define LPAREN 86
|
||||
#define RPAREN 87
|
||||
#define STRING 88
|
||||
#define RESWORD 89
|
||||
#define APTR 90
|
||||
#define PERIOD 91
|
||||
#define SIZEOF 92
|
||||
#define MPARENS 93
|
||||
#define FRETURN 94
|
||||
#define STACKEND 100
|
||||
|
||||
/*data types*/
|
||||
#define TYPELESS 0
|
||||
#define CHAR 1
|
||||
#define SHORT 2
|
||||
#define INT 3
|
||||
#define LONG 4
|
||||
#define UCHAR 5
|
||||
#define USHORT 6
|
||||
#define UNSIGNED 7
|
||||
#define ULONG 8
|
||||
#define FLOAT 9
|
||||
#define DOUBLE 10
|
||||
|
||||
/*data types local to parser*/
|
||||
#define STRUCT 11
|
||||
#define FRSTRUCT 12
|
||||
#define LLABEL 13
|
||||
|
||||
/*type flags and definitions*/
|
||||
#define TYPE 017
|
||||
#define SUPTYP 060
|
||||
#define ALLTYPE 077
|
||||
#define POINTER 020
|
||||
#define FUNCTION 040
|
||||
#define ARRAY 060
|
||||
#define SUTYPLEN 2
|
||||
|
||||
/*data registers*/
|
||||
#define DREG0 0
|
||||
#define DREG2 2
|
||||
#define DREG3 3
|
||||
#define DREG4 4
|
||||
#define DREG5 5
|
||||
#define DREG6 6
|
||||
#define DREG7 7
|
||||
#define AREG3 11
|
||||
#define AREG4 12
|
||||
#define AREG5 13
|
||||
|
||||
/*storage classes*/
|
||||
#define AUTO 1
|
||||
#define REGISTER 2
|
||||
#define EXTERNAL 3
|
||||
#define STATIC 4
|
||||
#define REGOFF 5
|
||||
#define EXTOFF 6
|
||||
#define STATOFF 7
|
||||
#define INDEXED 8
|
||||
|
||||
/*exclusively code generator storage classes*/
|
||||
#define CINDR 9
|
||||
#define CLINDR 10
|
||||
#define CFINDR 11 /* [vlh] 3.4 */
|
||||
|
||||
/*exclusively parser storage classes*/
|
||||
#define STRPROTO 9
|
||||
#define PDECLIST 10
|
||||
#define PARMLIST 11
|
||||
#define BFIELDCL 12
|
||||
#define UNELCL 13
|
||||
#define STELCL 14
|
||||
|
||||
|
||||
/*opinfo table bits*/
|
||||
#define OPPRI 077
|
||||
#define OPBIN 0100
|
||||
#define OPLVAL 0200
|
||||
#define OPREL 0400
|
||||
#define OPASSIGN 01000
|
||||
#define OPLWORD 02000
|
||||
#define OPRWORD 04000
|
||||
#define OPCOM 010000
|
||||
#define OPRAS 020000
|
||||
#define OPTERM 040000
|
||||
#define OPCONVS 0100000
|
||||
|
||||
/*68000 definitions*/
|
||||
#define PTRSIZE 4
|
||||
#define INTSIZE 2
|
||||
#define LONGSIZE 4
|
||||
#define SSIZE 8 /* chars per symbol */
|
||||
#define TRUE 1
|
||||
#define FALSE 0
|
||||
#define TABC '\t' /* tab character */
|
||||
#define EOLC '\n' /* end of line character */
|
||||
#define BITSPBYTE 8
|
||||
|
||||
/*operator class priorities*/
|
||||
#define TRMPRI 0 /* terminal nodes */
|
||||
#define RPNPRI 1 /* ) and ] */
|
||||
#define CALPRI 2 /* in-stack call, ( or [ */
|
||||
#define COLPRI 3 /* init or case priority for : or , */
|
||||
#define STKPRI 4 /* priority of end of stack */
|
||||
#define COMPRI 5 /* normal priority for , */
|
||||
#define ASGPRI 6 /* =, +=, -=, *=, /=, %=, ... */
|
||||
#define QMKPRI 7 /* ?: */
|
||||
#define LORPRI 8 /* || */
|
||||
#define LNDPRI 9 /* && */
|
||||
#define ORPRI 10 /* |, ! */
|
||||
#define ANDPRI 11 /* & */
|
||||
#define EQLPRI 12 /* ==, != */
|
||||
#define RELPRI 13 /* >, <, >=, <= */
|
||||
#define SHFPRI 14 /* <<, >> */
|
||||
#define ADDPRI 15 /* +, - */
|
||||
#define MULPRI 16 /* *, /, % */
|
||||
#define UNOPRI 17 /* ++, --, &, *, -, ~, sizeof */
|
||||
#define LPNPRI 18 /* ., ->, [, (, function call */
|
||||
#define PSTPRI 19 /* in-stack post--, post++ */
|
||||
|
||||
struct io_buf {
|
||||
int io_fd;
|
||||
int io_nc;
|
||||
char *io_p;
|
||||
char io_b[512];
|
||||
};
|
||||
|
||||
#ifdef PDP11
|
||||
struct { short hiword; short loword; };
|
||||
#endif
|
||||
#ifdef MC68000
|
||||
struct { short hiword; short loword; };
|
||||
#endif
|
||||
#ifdef VAX
|
||||
struct { short loword; short hiword; };
|
||||
#endif
|
||||
|
||||
#define EXPSIZE 1024
|
||||
int exprarea[EXPSIZE];
|
||||
|
||||
/* v6io buffer declaration */
|
||||
#define BLEN 512
|
||||
|
||||
struct iobuf{
|
||||
int fildes;
|
||||
int nunused;
|
||||
char *xfree;
|
||||
char buff[BLEN];
|
||||
};
|
||||
@@ -0,0 +1,163 @@
|
||||
/*
|
||||
Copyright 1982
|
||||
Alcyon Corporation
|
||||
8716 Production Ave.
|
||||
San Diego, Ca. 92121
|
||||
*/
|
||||
|
||||
#include "icode.h"
|
||||
#include "machine.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 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]=0;
|
||||
|
||||
/*buffered I/O structure*/
|
||||
struct ibuf {
|
||||
int fd;
|
||||
int nc;
|
||||
char *bp;
|
||||
char buffer[BUFSIZE];
|
||||
} outbuf=0;
|
||||
|
||||
/* command line define structure */
|
||||
struct defstruc {
|
||||
char *ptr;
|
||||
char *value;
|
||||
} defs[NDEFS]=0;
|
||||
|
||||
struct stackstruc { /* [vlh] */
|
||||
int ifd;
|
||||
char ifile[13];
|
||||
int lineno;
|
||||
struct ibuf inbuf;
|
||||
} filestack[FSTACK]=0, *filep=0; /* stack of incl files, ptr to... */
|
||||
#ifdef BULLSHIT /* Bullshit, bullshit, bullshit!!!*/
|
||||
#ifdef VERSADOS
|
||||
#define NONEST 1
|
||||
#define NOFORKS 1
|
||||
#endif
|
||||
|
||||
#ifdef VMS
|
||||
#define NONEST 1
|
||||
#endif
|
||||
|
||||
#ifdef NONEST
|
||||
struct ibuf holdbuf=0; /* alternate buffer, hold main file info */
|
||||
#endif
|
||||
#endif
|
||||
int mfail=0; /*macro error flag*/
|
||||
int skip=0; /*skipping current line*/
|
||||
char *defap=0; /*pointer to available define area*/
|
||||
char *defp=0; /*pointer to next avail define byte*/
|
||||
int defcount=0; /*bytes left in define area*/
|
||||
int defused=0; /*number of bytes used in define area*/
|
||||
int defmax=0; /*maximum define area used*/
|
||||
int pflag=0;
|
||||
int asflag=0;
|
||||
|
||||
/*line to output after macro substitution*/
|
||||
char line[LINESIZE+2]=0; /*line buffer*/
|
||||
char *linep=0; /*current line pointer*/
|
||||
int loverflow=0; /*line overflow flag*/
|
||||
int lineno=0;
|
||||
|
||||
/*push back buffer*/
|
||||
char pbbuf[PBSIZE]=0; /*push back buffer*/
|
||||
char *pbp=0; /*push back pointer*/
|
||||
int pbflag=0; /*checks for recursive definition*/
|
||||
|
||||
|
||||
char *lookup();
|
||||
char *setend();
|
||||
char *makecopy();
|
||||
char *makecopy();
|
||||
char *maketemp();
|
||||
char *sbrk();
|
||||
struct symbol *getsp();
|
||||
#define STKLEN 64
|
||||
int oprstk[STKLEN]=0;
|
||||
int opnstk[STKLEN]=0;
|
||||
int pristk[STKLEN]=0;
|
||||
int *oprptr=0;
|
||||
int *opnptr=0;
|
||||
int *priptr=0;
|
||||
|
||||
int nincl=0;
|
||||
char *incl[10]=0;
|
||||
char tmp[6]=0;
|
||||
#define CSTKSIZE 20
|
||||
char cstack[CSTKSIZE]=0;
|
||||
char *cstkptr=0;
|
||||
char inclname[TOKSIZE]=0;
|
||||
int cvalue=0;
|
||||
#define EXPSIZE 1024
|
||||
int exprarea[EXPSIZE]=0;
|
||||
@@ -0,0 +1,328 @@
|
||||
/*
|
||||
Copyright 1982
|
||||
Alcyon Corporation
|
||||
8716 Production Ave.
|
||||
San Diego, Ca. 92121
|
||||
*/
|
||||
|
||||
#include "preproc.h"
|
||||
char null[] "";
|
||||
|
||||
char ctype[] {
|
||||
EOF, ANYC, ANYC, ANYC, ANYC, ANYC, ANYC, ANYC, /*BUG 2*/
|
||||
ANYC, WHITE, NEWL, ANYC, ANYC, ANYC, ANYC, ANYC, /*BUG 2*/
|
||||
ANYC, ANYC, ANYC, ANYC, NEWL, ANYC, ANYC, ANYC, /*BUG 2*/
|
||||
ANYC, ANYC, ANYC, ANYC, ANYC, ANYC, ANYC, ANYC, /*BUG 2*/
|
||||
WHITE, NOT, DQUOTE, POUND, ANYC, MOD, AND, SQUOTE, /*BUG 2*/
|
||||
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, /*BUG 2*/
|
||||
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, /*BUG 2*/
|
||||
ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA,
|
||||
ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA,
|
||||
ALPHA, ALPHA, ALPHA, ANYC, OR, ANYC, COMPL, ANYC /*BUG 2*/
|
||||
};
|
||||
|
||||
/* 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)->ifile,(filep)->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(&(filep->inbuf))) < 0 ) {
|
||||
if( filep == &filestack[0] )
|
||||
return(EOF);
|
||||
close(filep->inbuf.fd);
|
||||
filep--;
|
||||
if( filep == &filestack[0] ) { /*need line for #include...*/
|
||||
putc('\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++;
|
||||
putc('\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);
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
$1lo68 -f $1 -r -o cp68.rel -unofloat 0$1s.o cexpr.o lex.o macro.o main.o util.o 0$1lib6.a 0$1clib
|
||||
era *.o
|
||||
|
||||
user 12!make $1
|
||||
@@ -0,0 +1,27 @@
|
||||
$ num
|
||||
CEXPR.C
|
||||
CEXPR.lis
|
||||
$ num
|
||||
INIT.C
|
||||
INIT.lis
|
||||
$ num
|
||||
LEX.C
|
||||
LEX.lis
|
||||
$ num
|
||||
MACRO.C
|
||||
MACRO.lis
|
||||
$ num
|
||||
MAIN.C
|
||||
MAIN.lis
|
||||
$ num
|
||||
UTIL.C
|
||||
UTIL.lis
|
||||
$ num
|
||||
ICODE.H
|
||||
ICODE.lst
|
||||
$ num
|
||||
MACHINE.H
|
||||
MACHINE.lst
|
||||
$ num
|
||||
PREPROC.H
|
||||
PREPROC.lst
|
||||
@@ -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*/
|
||||
@@ -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*/
|
||||
@@ -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*/
|
||||
@@ -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*/
|
||||
@@ -0,0 +1,673 @@
|
||||
/*
|
||||
Copyright 1982
|
||||
Alcyon Corporation
|
||||
8716 Production Ave.
|
||||
San Diego, Ca. 92121
|
||||
*/
|
||||
|
||||
#include "preproc.h"
|
||||
|
||||
#define CSTKSIZE 20
|
||||
#define FILESEP '/'
|
||||
#define NINCL 10
|
||||
|
||||
#ifdef UNIX
|
||||
char *stdincl "/usr/include/"; /*standard include directory*/
|
||||
#endif
|
||||
#ifdef VMS
|
||||
char *stdincl "lib:";
|
||||
#endif
|
||||
#ifdef CPM
|
||||
char *stdincl "";
|
||||
#endif
|
||||
|
||||
int clabel 1000;
|
||||
int nlabel 1001;
|
||||
int nincl;
|
||||
char *incl[10];
|
||||
char tmp[6];
|
||||
|
||||
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,
|
||||
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];
|
||||
|
||||
if( fopen(infile,&(filep->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;
|
||||
}
|
||||
lineno = 1;
|
||||
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 ) { /*[vlh] add fname & line#*/
|
||||
if (*l) {
|
||||
putc(SOH,&outbuf);
|
||||
for (p = (filep)->ifile; *p; p++)
|
||||
putc(*p,&outbuf);
|
||||
putc(SOH,&outbuf);
|
||||
itoa((filep)->lineno,tmp,5);
|
||||
for (p = tmp; *p==' '; ) p++;
|
||||
for ( ; *p; p++)
|
||||
putc(*p,&outbuf);
|
||||
putc(' ',&outbuf);
|
||||
if (!(*l)) putc(' ',&outbuf);
|
||||
}
|
||||
else nonewline++;
|
||||
(filep)->lineno++;
|
||||
}
|
||||
while( *l )
|
||||
putc(*l++,&outbuf);
|
||||
if (!nonewline) putc('\n',&outbuf);
|
||||
else nonewline = 0;
|
||||
}
|
||||
if( cstkptr != &cstack[0] )
|
||||
error("unmatched conditional");
|
||||
if( defused > defmax )
|
||||
defmax = defused;
|
||||
v6flush(&outbuf);
|
||||
close(outbuf.fd);
|
||||
close(filep->inbuf.fd);
|
||||
return(mfail==0);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
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++;
|
||||
putc('\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...*/
|
||||
filep++;
|
||||
if( filep >= &filestack[FSTACK] )
|
||||
error("includes nested too deeply");
|
||||
else {
|
||||
if( fopen(p,&(filep->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);
|
||||
}
|
||||
}
|
||||
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)->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);
|
||||
}
|
||||
|
||||
pbnum(num) /* returns - none*/
|
||||
int num;
|
||||
{
|
||||
register int digit;
|
||||
|
||||
do {
|
||||
digit = num % 10;
|
||||
num =/ 10;
|
||||
putback(digit+'0');
|
||||
} while( num > 0 );
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
#
|
||||
/*
|
||||
Copyright 1981
|
||||
Alcyon Corporation
|
||||
8474 Commerce Av.
|
||||
San Diego, Ca. 92121
|
||||
*/
|
||||
#include "preproc.h"
|
||||
int status = 0;
|
||||
char *stdincl; /* Include prefix for macro processor */
|
||||
/* cexit - exit from C compiler driver*/
|
||||
/* This deletes any existing temps and exits with the error status.*/
|
||||
cexit() /* returns - none*/
|
||||
{
|
||||
|
||||
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;
|
||||
{
|
||||
|
||||
if(argc < 3)
|
||||
usage();
|
||||
|
||||
if (*argv[1] == '-')
|
||||
{
|
||||
if(argc != 5 || argv[1][1] != 'i')
|
||||
usage();
|
||||
|
||||
stdincl = argv[2];
|
||||
domacro(argv[3],argv[4],0,0L);
|
||||
cexit();
|
||||
}
|
||||
if(argc != 3)
|
||||
usage();
|
||||
domacro(argv[1],argv[2],0,0L);
|
||||
cexit();
|
||||
}
|
||||
usage()
|
||||
{
|
||||
error("usage: c68 [-i x:] inputfile outputfile\n");
|
||||
exit();
|
||||
}
|
||||
|
||||
/* 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 );
|
||||
}
|
||||
|
||||
/* 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 int sign, i;
|
||||
char temp[6];
|
||||
|
||||
if( (sign=n) < 0 )
|
||||
n = -n;
|
||||
i = 0;
|
||||
do {
|
||||
temp[i++] = n % 10 + '0';
|
||||
} while( (n =/ 10) > 0 );
|
||||
if( sign < 0 )
|
||||
temp[i++] = '-';
|
||||
while( --w >= i ) /*pad on left with blanks*/
|
||||
*s++ = ' ';
|
||||
while( --i >= 0 ) /*move chars reversed*/
|
||||
*s++ = temp[i];
|
||||
*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) == 0 )
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
$1stat machine.h=rw
|
||||
$1pip machine.h=machine.68k
|
||||
|
||||
$1cp68 -i 0$1 CEXPR.c $1x.i
|
||||
$1c068 $1x.i $1x.ic $1x.st
|
||||
$1c168 $1x.ic CEXPR.s -LD
|
||||
era $1x.i
|
||||
era $1x.ic
|
||||
era $1x.st
|
||||
$1as68 -s 0$1 -f $1 -l -u CEXPR.s
|
||||
era CEXPR.s
|
||||
|
||||
$1cp68 -i 0$1 LEX.c $1x.i
|
||||
$1c068 $1x.i $1x.ic $1x.st
|
||||
$1c168 $1x.ic LEX.s -LD
|
||||
era $1x.i
|
||||
era $1x.ic
|
||||
era $1x.st
|
||||
$1as68 -s 0$1 -f $1 -l -u LEX.s
|
||||
era LEX.s
|
||||
|
||||
$1cp68 -i 0$1 MACRO.c $1x.i
|
||||
$1c068 $1x.i $1x.ic $1x.st
|
||||
$1c168 $1x.ic MACRO.s -LD
|
||||
era $1x.i
|
||||
era $1x.ic
|
||||
era $1x.st
|
||||
$1as68 -s 0$1 -f $1 -l -u MACRO.s
|
||||
era MACRO.s
|
||||
|
||||
$1cp68 -i 0$1 MAIN.c $1x.i
|
||||
$1c068 $1x.i $1x.ic $1x.st
|
||||
$1c168 $1x.ic MAIN.s -LD
|
||||
era $1x.i
|
||||
era $1x.ic
|
||||
era $1x.st
|
||||
$1as68 -s 0$1 -f $1 -l -u MAIN.s
|
||||
era MAIN.s
|
||||
|
||||
$1cp68 -i 0$1 UTIL.c $1x.i
|
||||
$1c068 $1x.i $1x.ic $1x.st
|
||||
$1c168 $1x.ic UTIL.s -LD
|
||||
era $1x.i
|
||||
era $1x.ic
|
||||
era $1x.st
|
||||
$1as68 -s 0$1 -f $1 -l -u UTIL.s
|
||||
era UTIL.s
|
||||
|
||||
link $1
|
||||
@@ -0,0 +1,150 @@
|
||||
/*
|
||||
Copyright 1982
|
||||
Alcyon Corporation
|
||||
8716 Production Ave.
|
||||
San Diego, Ca. 92121
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <klib.h>
|
||||
#include "icode.h"
|
||||
#include "machine.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 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];
|
||||
} outbuf;
|
||||
|
||||
/* command line define structure */
|
||||
struct defstruc {
|
||||
char *ptr;
|
||||
char *value;
|
||||
} defs[NDEFS];
|
||||
|
||||
struct stackstruc { /* [vlh] */
|
||||
int ifd;
|
||||
char ifile[13];
|
||||
int lineno;
|
||||
struct ibuf inbuf;
|
||||
} filestack[FSTACK], *filep; /* stack of incl files, ptr to... */
|
||||
|
||||
#ifdef BULLSHIT /* Bullshit, bullshit, bullshit!!!*/
|
||||
#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
|
||||
#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();
|
||||
#ifdef BULLSHIT
|
||||
char *maketemp();
|
||||
char *setend();
|
||||
char *makecopy();
|
||||
#endif
|
||||
char *sbrk();
|
||||
struct symbol *getsp();
|
||||
@@ -0,0 +1,12 @@
|
||||
e:send MACHINE.H
|
||||
e:send CEXPR.C
|
||||
e:send LEX.C
|
||||
e:send MACRO.C
|
||||
e:send MAIN.C
|
||||
e:send UTIL.C
|
||||
e:send ICODE.H
|
||||
e:send PREPROC.H
|
||||
e:send LINK.SUB
|
||||
e:send MAKE.SUB
|
||||
e:send MACHINE.68K
|
||||
e:send SEND11.SUB
|
||||
@@ -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 );
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
$ preproc
|
||||
$ set noon
|
||||
$ !
|
||||
$ ! Build file for VMS version of CP68
|
||||
$ !
|
||||
$ copy machine.vax machine.h
|
||||
$ pur machine.h
|
||||
$ cx CEXPR
|
||||
$ cx INIT
|
||||
$ cx LEX
|
||||
$ cx MACRO
|
||||
$ cx MAIN
|
||||
$ cx UTIL
|
||||
$ clink cexpr,init,lex,macro,main,util,lib:klib/lib cp68
|
||||
Reference in New Issue
Block a user