Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6555bf6893 | ||
|
|
bd796849ef | ||
|
|
9afbc0ad32 |
256
mach/pdp/cg/mach.c
Normal file
256
mach/pdp/cg/mach.c
Normal file
@@ -0,0 +1,256 @@
|
|||||||
|
#ifndef NORCSID
|
||||||
|
static char rcsid[] = "$Header$";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
|
*
|
||||||
|
* This product is part of the Amsterdam Compiler Kit.
|
||||||
|
*
|
||||||
|
* Permission to use, sell, duplicate or disclose this software must be
|
||||||
|
* obtained in writing. Requests for such permissions may be sent to
|
||||||
|
*
|
||||||
|
* Dr. Andrew S. Tanenbaum
|
||||||
|
* Wiskundig Seminarium
|
||||||
|
* Vrije Universiteit
|
||||||
|
* Postbox 7161
|
||||||
|
* 1007 MC Amsterdam
|
||||||
|
* The Netherlands
|
||||||
|
*
|
||||||
|
* Author: Hans van Staveren
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* machine dependent back end routines for the PDP-11
|
||||||
|
*/
|
||||||
|
|
||||||
|
static char procnam[40] ;
|
||||||
|
|
||||||
|
/* #define REGPATCH /* save all registers in markblock */
|
||||||
|
|
||||||
|
con_part(sz,w) register sz; word w; {
|
||||||
|
|
||||||
|
while (part_size % sz)
|
||||||
|
part_size++;
|
||||||
|
if (part_size == TEM_WSIZE)
|
||||||
|
part_flush();
|
||||||
|
if (sz == 1) {
|
||||||
|
w &= 0xFF;
|
||||||
|
if (part_size)
|
||||||
|
w <<= 8;
|
||||||
|
part_word |= w;
|
||||||
|
} else {
|
||||||
|
assert(sz == 2);
|
||||||
|
part_word = w;
|
||||||
|
}
|
||||||
|
part_size += sz;
|
||||||
|
}
|
||||||
|
|
||||||
|
con_mult(sz) word sz; {
|
||||||
|
long l;
|
||||||
|
|
||||||
|
if (sz != 4)
|
||||||
|
fatal("bad icon/ucon size");
|
||||||
|
#ifdef ACK_ASS
|
||||||
|
fprintf(codefile,".long %s\n",str);
|
||||||
|
#else
|
||||||
|
l = atol(str);
|
||||||
|
fprintf(codefile,"\t%o;%o\n",(int)(l>>16),(int)l);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The next function is difficult to do when not running on a PDP 11 or VAX
|
||||||
|
* The strategy followed is to assume the code generator is running on a PDP 11
|
||||||
|
* unless the ACK_ASS define is on.
|
||||||
|
* In the last case floating point constants are simply not handled
|
||||||
|
*/
|
||||||
|
|
||||||
|
con_float() {
|
||||||
|
#ifdef ACK_ASS
|
||||||
|
static int been_here;
|
||||||
|
|
||||||
|
if (argval != 4 && argval != 8)
|
||||||
|
fatal("bad fcon size");
|
||||||
|
fprintf(codefile,".long\t");
|
||||||
|
if (argval == 8)
|
||||||
|
fprintf(codefile,"F_DUM,");
|
||||||
|
fprintf(codefile,"F_DUM\n");
|
||||||
|
if ( !been_here++)
|
||||||
|
fprintf(stderr,"Warning : dummy float-constant(s)\n");
|
||||||
|
#else
|
||||||
|
double f;
|
||||||
|
register short *p,i;
|
||||||
|
|
||||||
|
if (argval != 4 && argval != 8)
|
||||||
|
fatal("bad fcon size");
|
||||||
|
f = atof(str);
|
||||||
|
p = (short *) &f;
|
||||||
|
i = *p++;
|
||||||
|
if (argval == 8) {
|
||||||
|
fprintf(codefile,"\t%o;%o;",i,*p++);
|
||||||
|
i = *p++;
|
||||||
|
}
|
||||||
|
fprintf(codefile,"\t%o;%o\n",i,*p++);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef REGVARS
|
||||||
|
|
||||||
|
char Rstring[10];
|
||||||
|
full lbytes;
|
||||||
|
struct regadm {
|
||||||
|
char *ra_str;
|
||||||
|
long ra_off;
|
||||||
|
} regadm[2];
|
||||||
|
int n_regvars;
|
||||||
|
|
||||||
|
regscore(off,size,typ,score,totyp) long off; {
|
||||||
|
|
||||||
|
if (size != 2)
|
||||||
|
return(-1);
|
||||||
|
score -= 1; /* allow for save/restore */
|
||||||
|
if (off>=0)
|
||||||
|
score -= 2;
|
||||||
|
if (typ==reg_pointer)
|
||||||
|
score *= 17;
|
||||||
|
else if (typ==reg_loop)
|
||||||
|
score = 10*score+50; /* Guestimate */
|
||||||
|
else
|
||||||
|
score *= 10;
|
||||||
|
return(score); /* estimated # of words of profit */
|
||||||
|
}
|
||||||
|
|
||||||
|
i_regsave() {
|
||||||
|
|
||||||
|
Rstring[0] = 0;
|
||||||
|
n_regvars=0;
|
||||||
|
}
|
||||||
|
|
||||||
|
f_regsave() {
|
||||||
|
register i;
|
||||||
|
|
||||||
|
if (n_regvars==0 || lbytes==0) {
|
||||||
|
#ifdef REGPATCH
|
||||||
|
fprintf(codefile,"mov r2,-(sp)\nmov r4,-(sp)\n");
|
||||||
|
#endif
|
||||||
|
fprintf(codefile,"mov r5,-(sp)\nmov sp,r5\n");
|
||||||
|
if (lbytes == 2)
|
||||||
|
fprintf(codefile,"tst -(sp)\n");
|
||||||
|
else if (lbytes!=0)
|
||||||
|
fprintf(codefile,"sub $0%o,sp\n",lbytes);
|
||||||
|
for (i=0;i<n_regvars;i++)
|
||||||
|
fprintf(codefile,"mov %s,-(sp)\n",regadm[i].ra_str);
|
||||||
|
} else {
|
||||||
|
if (lbytes>6) {
|
||||||
|
fprintf(codefile,"mov $0%o,r0\n",lbytes);
|
||||||
|
fprintf(codefile,"jsr r5,PR%s\n",Rstring);
|
||||||
|
} else {
|
||||||
|
fprintf(codefile,"jsr r5,PR%d%s\n",lbytes,Rstring);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (i=0;i<n_regvars;i++) {
|
||||||
|
if (regadm[i].ra_off>=0)
|
||||||
|
fprintf(codefile,"mov 0%lo(r5),%s\n",regadm[i].ra_off,
|
||||||
|
regadm[i].ra_str);
|
||||||
|
/* generate equates for access to registers */
|
||||||
|
fprintf(codefile,"~%s%s=%ld.\n",regadm[i].ra_str+1, procnam,
|
||||||
|
regadm[i].ra_off) ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
regsave(regstr,off,size) char *regstr; long off; {
|
||||||
|
|
||||||
|
fprintf(codefile,"%c Local %ld into %s\n",COMMENTCHAR,off,regstr);
|
||||||
|
/* commented away
|
||||||
|
#ifndef REGPATCH
|
||||||
|
fprintf(codefile,"mov %s,-(sp)\n",regstr);
|
||||||
|
#endif
|
||||||
|
strcat(Rstring,regstr);
|
||||||
|
if (off>=0)
|
||||||
|
fprintf(codefile,"mov 0%lo(r5),%s\n",off,regstr);
|
||||||
|
end of commented away */
|
||||||
|
|
||||||
|
strcat(Rstring,regstr);
|
||||||
|
regadm[n_regvars].ra_str = regstr;
|
||||||
|
regadm[n_regvars].ra_off = off;
|
||||||
|
n_regvars++;
|
||||||
|
}
|
||||||
|
|
||||||
|
regreturn() {
|
||||||
|
|
||||||
|
#ifdef REGPATCH
|
||||||
|
fprintf(codefile,"jmp eret\n");
|
||||||
|
#else
|
||||||
|
fprintf(codefile,"jmp RT%s\n",Rstring);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
doplb(name) char *name ; {
|
||||||
|
register char *p, *q ;
|
||||||
|
p=procnam, q=name ;
|
||||||
|
while ( *p++ = *q++ ) ;
|
||||||
|
fprintf(codefile,"%s:\n",name) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
prolog(nlocals) full nlocals; {
|
||||||
|
|
||||||
|
#ifndef REGVARS
|
||||||
|
#ifdef REGPATCH
|
||||||
|
fprintf(codefile,"mov r2,-(sp)\nmov r4,-(sp)\n");
|
||||||
|
#endif
|
||||||
|
fprintf(codefile,"mov r5,-(sp)\nmov sp,r5\n");
|
||||||
|
if (nlocals == 0)
|
||||||
|
return;
|
||||||
|
if (nlocals == 2)
|
||||||
|
fprintf(codefile,"tst -(sp)\n");
|
||||||
|
else
|
||||||
|
fprintf(codefile,"sub $0%o,sp\n",nlocals);
|
||||||
|
#else
|
||||||
|
lbytes = nlocals;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
dlbdlb(as,ls) string as,ls; {
|
||||||
|
|
||||||
|
if (strlen(as)+strlen(ls)+2<sizeof(labstr)) {
|
||||||
|
strcat(ls,":");
|
||||||
|
strcat(ls,as);
|
||||||
|
} else
|
||||||
|
fatal("too many consecutive labels");
|
||||||
|
}
|
||||||
|
|
||||||
|
mes(type) word type; {
|
||||||
|
int argt ;
|
||||||
|
|
||||||
|
switch ( (int)type ) {
|
||||||
|
case ms_ext :
|
||||||
|
for (;;) {
|
||||||
|
switch ( argt=getarg(
|
||||||
|
ptyp(sp_cend)|ptyp(sp_pnam)|sym_ptyp) ) {
|
||||||
|
case sp_cend :
|
||||||
|
return ;
|
||||||
|
default:
|
||||||
|
strarg(argt) ;
|
||||||
|
#ifdef ACK_ASS
|
||||||
|
fprintf(codefile,".define %s\n",argstr) ;
|
||||||
|
#else
|
||||||
|
fprintf(codefile,".globl %s\n",argstr) ;
|
||||||
|
#endif
|
||||||
|
break ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
default :
|
||||||
|
while ( getarg(any_ptyp) != sp_cend ) ;
|
||||||
|
break ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
char *segname[] = {
|
||||||
|
".text", /* SEGTXT */
|
||||||
|
".data", /* SEGCON */
|
||||||
|
".data", /* SEGROM */
|
||||||
|
".bss" /* SEGBSS */
|
||||||
|
};
|
||||||
46
mach/pdp/cg/mach.h
Normal file
46
mach/pdp/cg/mach.h
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
/* $Header$ */
|
||||||
|
|
||||||
|
/* The next define switches between codegeneration for an ACK assembler
|
||||||
|
* or for the standard UNIX V7 assembler.
|
||||||
|
* If on code is generated for the ACK assembler.
|
||||||
|
*/
|
||||||
|
/* #define ACK_ASS /* code for ACK assembler */
|
||||||
|
|
||||||
|
#ifdef ACK_ASS
|
||||||
|
#define COMMENTCHAR '!'
|
||||||
|
#define ex_ap(y) fprintf(codefile,".extern %s\n",y)
|
||||||
|
#else
|
||||||
|
#define COMMENTCHAR '/'
|
||||||
|
#define ex_ap(y) fprintf(codefile,".globl %s\n",y)
|
||||||
|
#endif
|
||||||
|
#define in_ap(y) /* nothing */
|
||||||
|
|
||||||
|
#define newplb(x) doplb(x)
|
||||||
|
#define newilb(x) fprintf(codefile,"%s:\n",x)
|
||||||
|
#define newdlb(x) fprintf(codefile,"%s:\n",x)
|
||||||
|
#ifdef ACK_ASS
|
||||||
|
#define newlbss(l,x) fprintf(codefile,"%s:.space 0%o\n",l,x);
|
||||||
|
#else
|
||||||
|
#define newlbss(l,x) fprintf(codefile,"%s:.=.+0%o\n",l,x);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define cst_fmt "$0%o"
|
||||||
|
#define off_fmt "0%o"
|
||||||
|
#define ilb_fmt "I%03x%x"
|
||||||
|
#define dlb_fmt "_%d"
|
||||||
|
#define hol_fmt "hol%d"
|
||||||
|
|
||||||
|
#define hol_off "0%o+hol%d"
|
||||||
|
|
||||||
|
#ifdef ACK_ASS
|
||||||
|
#define con_cst(x) fprintf(codefile,".short 0%o\n",x)
|
||||||
|
#define con_ilb(x) fprintf(codefile,".short %s\n",x)
|
||||||
|
#define con_dlb(x) fprintf(codefile,".short %s\n",x)
|
||||||
|
#else
|
||||||
|
#define con_cst(x) fprintf(codefile,"0%o\n",x)
|
||||||
|
#define con_ilb(x) fprintf(codefile,"%s\n",x)
|
||||||
|
#define con_dlb(x) fprintf(codefile,"%s\n",x)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define id_first '_'
|
||||||
|
#define BSS_INIT 0
|
||||||
2852
mach/pdp/cg/table
Normal file
2852
mach/pdp/cg/table
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,339 +0,0 @@
|
|||||||
/*
|
|
||||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
|
||||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
chtabgen - character table generator
|
|
||||||
|
|
||||||
Author: Erik Baalbergen (..tjalk!erikb)
|
|
||||||
Many mods by Ceriel Jacobs
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
#ifndef NORCSID
|
|
||||||
static char *RcsId = "$Id$";
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define MAXBUF 256
|
|
||||||
#define MAXTAB 10000
|
|
||||||
#define COMCOM '-'
|
|
||||||
#define FILECOM '%'
|
|
||||||
|
|
||||||
int InputForm = 'c'; /* default input format (and, currently, only one) */
|
|
||||||
char OutputForm[MAXBUF] = "%s,\n";
|
|
||||||
/* format for spitting out a string */
|
|
||||||
char *Table[MAXTAB];
|
|
||||||
char *ProgCall; /* callname of this program */
|
|
||||||
int TabSize = 128; /* default size of generated table */
|
|
||||||
char *InitialValue; /* initial value of all table entries */
|
|
||||||
|
|
||||||
extern char *malloc(), *strcpy();
|
|
||||||
|
|
||||||
main(argc, argv)
|
|
||||||
char *argv[];
|
|
||||||
{
|
|
||||||
|
|
||||||
ProgCall = *argv++;
|
|
||||||
argc--;
|
|
||||||
while (argc-- > 0) {
|
|
||||||
if (**argv == COMCOM) {
|
|
||||||
option(*argv++);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (! process(*argv++, InputForm)) {
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
exit(0);
|
|
||||||
/*NOTREACHED*/
|
|
||||||
}
|
|
||||||
|
|
||||||
char *
|
|
||||||
Salloc(s)
|
|
||||||
char *s;
|
|
||||||
{
|
|
||||||
char *ns = malloc((unsigned)strlen(s) + 1);
|
|
||||||
|
|
||||||
if (ns) {
|
|
||||||
strcpy(ns, s);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
fprintf(stderr, "%s: out of memory\n", ProgCall);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
return ns;
|
|
||||||
}
|
|
||||||
|
|
||||||
option(str)
|
|
||||||
char *str;
|
|
||||||
{
|
|
||||||
/* note that *str indicates the source of the option:
|
|
||||||
either COMCOM (from command line) or FILECOM (from a file).
|
|
||||||
*/
|
|
||||||
switch (*++str) {
|
|
||||||
|
|
||||||
case ' ': /* command */
|
|
||||||
case '\t':
|
|
||||||
case '\0':
|
|
||||||
break;
|
|
||||||
case 'I': /* for future extension */
|
|
||||||
InputForm = *++str;
|
|
||||||
break;
|
|
||||||
case 'f': /* input from file ... */
|
|
||||||
if (*++str == '\0') {
|
|
||||||
fprintf(stderr, "%s: -f: name expected\n", ProgCall);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
DoFile(str);
|
|
||||||
break;
|
|
||||||
case 'F': /* new output format string */
|
|
||||||
sprintf(OutputForm, "%s\n", ++str);
|
|
||||||
break;
|
|
||||||
case 'T': /* insert text literally */
|
|
||||||
printf("%s\n", ++str);
|
|
||||||
break;
|
|
||||||
case 'p': /* print table */
|
|
||||||
PrintTable();
|
|
||||||
break;
|
|
||||||
case 'C': /* clear table */
|
|
||||||
InitTable((char *)0);
|
|
||||||
break;
|
|
||||||
case 'i': /* initialize table with given value */
|
|
||||||
if (*++str == '\0') {
|
|
||||||
InitTable((char *)0);
|
|
||||||
}
|
|
||||||
else InitTable(str);
|
|
||||||
break;
|
|
||||||
case 'S':
|
|
||||||
{
|
|
||||||
int i = atoi(++str);
|
|
||||||
|
|
||||||
if (i <= 0 || i > MAXTAB) {
|
|
||||||
fprintf(stderr, "%s: size would exceed maximum\n",
|
|
||||||
ProgCall);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
TabSize = i;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
fprintf(stderr, "%s: bad option -%s\n", ProgCall, str);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
InitTable(ival)
|
|
||||||
char *ival;
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i = 0; i < TabSize; i++) {
|
|
||||||
Table[i] = 0;
|
|
||||||
}
|
|
||||||
InitialValue = 0;
|
|
||||||
if (ival) {
|
|
||||||
InitialValue = Salloc(ival);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
PrintTable()
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i = 0; i < TabSize; i++) {
|
|
||||||
if (Table[i]) {
|
|
||||||
printf(OutputForm, Table[i]);
|
|
||||||
}
|
|
||||||
else if (InitialValue) {
|
|
||||||
printf(OutputForm, InitialValue);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
printf(OutputForm, "0");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
process(str, format)
|
|
||||||
char *str;
|
|
||||||
{
|
|
||||||
char *cstr = str;
|
|
||||||
char *Name = cstr; /* overwrite original string! */
|
|
||||||
|
|
||||||
/* strip of the entry name
|
|
||||||
*/
|
|
||||||
while (*str && *str != ':') {
|
|
||||||
if (*str == '\\') {
|
|
||||||
++str;
|
|
||||||
}
|
|
||||||
*cstr++ = *str++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (*str != ':') {
|
|
||||||
fprintf(stderr, "%s: bad specification: \"%s\", ignored\n",
|
|
||||||
ProgCall, Name);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
*cstr = '\0';
|
|
||||||
str++;
|
|
||||||
|
|
||||||
switch (format) {
|
|
||||||
|
|
||||||
case 'c':
|
|
||||||
return c_proc(str, Name);
|
|
||||||
default:
|
|
||||||
fprintf(stderr, "%s: bad input format\n", ProgCall);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
c_proc(str, Name)
|
|
||||||
char *str;
|
|
||||||
char *Name;
|
|
||||||
{
|
|
||||||
int ch, ch2;
|
|
||||||
int quoted();
|
|
||||||
char *name = Salloc(Name);
|
|
||||||
|
|
||||||
while (*str) {
|
|
||||||
if (*str == '\\') {
|
|
||||||
ch = quoted(&str);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
ch = *str++ & 0377;
|
|
||||||
}
|
|
||||||
if (*str == '-') {
|
|
||||||
if (*++str == '\\') {
|
|
||||||
ch2 = quoted(&str);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (ch2 = (*str++ & 0377));
|
|
||||||
else str--;
|
|
||||||
}
|
|
||||||
if (ch > ch2) {
|
|
||||||
fprintf(stderr, "%s: bad range\n", ProgCall);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
while (ch <= ch2) {
|
|
||||||
if (! setval(ch, name)) return 0;
|
|
||||||
ch++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (! setval(ch, name)) return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
setval(ch, nm)
|
|
||||||
char *nm;
|
|
||||||
{
|
|
||||||
char **p = &Table[ch];
|
|
||||||
|
|
||||||
if (ch < 0 || ch >= TabSize) {
|
|
||||||
fprintf(stderr, "Illegal index: %d\n", ch);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
if (*(p = &Table[ch])) {
|
|
||||||
fprintf(stderr, "Warning: redefinition of index %d\n", ch);
|
|
||||||
}
|
|
||||||
*p = nm;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
quoted(pstr)
|
|
||||||
char **pstr;
|
|
||||||
{
|
|
||||||
int ch;
|
|
||||||
int i;
|
|
||||||
char *str = *pstr;
|
|
||||||
|
|
||||||
if ((*++str >= '0') && (*str <= '9')) {
|
|
||||||
ch = 0;
|
|
||||||
for (i = 0; i < 3; i++) {
|
|
||||||
ch = 8 * ch + (*str - '0');
|
|
||||||
if (*++str < '0' || *str > '9')
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
switch (*str++) {
|
|
||||||
case 'n':
|
|
||||||
ch = '\n';
|
|
||||||
break;
|
|
||||||
case 't':
|
|
||||||
ch = '\t';
|
|
||||||
break;
|
|
||||||
case 'b':
|
|
||||||
ch = '\b';
|
|
||||||
break;
|
|
||||||
case 'r':
|
|
||||||
ch = '\r';
|
|
||||||
break;
|
|
||||||
case 'f':
|
|
||||||
ch = '\f';
|
|
||||||
break;
|
|
||||||
case 'v':
|
|
||||||
ch = 013;
|
|
||||||
break;
|
|
||||||
default :
|
|
||||||
ch = *(str - 1);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*pstr = str;
|
|
||||||
return ch & 0377;
|
|
||||||
}
|
|
||||||
|
|
||||||
char *
|
|
||||||
getline(s, n, fp)
|
|
||||||
char *s;
|
|
||||||
FILE *fp;
|
|
||||||
{
|
|
||||||
int c = getc(fp);
|
|
||||||
char *str = s;
|
|
||||||
|
|
||||||
while (n--) {
|
|
||||||
if (c == EOF) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
if (c == '\n') {
|
|
||||||
*str++ = '\0';
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
*str++ = c;
|
|
||||||
c = getc(fp);
|
|
||||||
}
|
|
||||||
s[n - 1] = '\0';
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
#define BUFSIZE 1024
|
|
||||||
|
|
||||||
DoFile(name)
|
|
||||||
char *name;
|
|
||||||
{
|
|
||||||
char text[BUFSIZE];
|
|
||||||
FILE *fp;
|
|
||||||
|
|
||||||
if ((fp = fopen(name, "r")) == NULL) {
|
|
||||||
fprintf(stderr, "%s: cannot read file %s\n", ProgCall, name);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
while (getline(text, BUFSIZE, fp) != NULL) {
|
|
||||||
if (text[0] == FILECOM) {
|
|
||||||
option(text);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (! process(text, InputForm)) {
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user