📄 y.tab.c
字号:
fprintf(confh,
"/* conf.h (GENERATED FILE; DO NOT EDIT) */\n");
fprintf(confc,
"/* conf.c (GENERATED FILE; DO NOT EDIT) */\n");
fprintf(confc, "\n#include %s\n", CONFHREF);
fprintf(confh, "\n#define\tNULLPTR\t(char *)0\n");
if (verbose)
printf("Writing output...\n");
fprintf(confh,"\n/* Device table declarations */\n");
for (i=0 ; (p=ftout[i])!=NULL ; i++)
fprintf(confh, "%s", p);
/* write device declarations and definitions; count type refs. */
fprintf(confh, "\n/* Device name definitions */\n\n");
for (i=0,s=devs; s!=NIL ; s=s->dvnext,i++) {
fprintf(confh, "#define\t%-12s%d\t\t\t/* type %-8s */\n",
s->dvname, i, s->dvtname);
s->dvminor = symtab[s->dvtnum].symoccurs++;
}
/* write count of device types */
fprintf(confh,"\n/* Control block sizes */\n\n");
for (i=0 ; i<nsym ; i++)
if (symtab[i].symoccurs > 0) {
fprintf(confh, "#define\tN%s\t%d\n",
symtab[i].symname, symtab[i].symoccurs);
}
if (ndevs > 0)
fprintf(confh, "\n#define\tNDEVS\t%d\n\n", ndevs);
/* empty symbol table, collect, and write names of all I/O routines */
nsym = 0;
for (s=devs; s!=NIL ; s=s->dvnext) {
i=lookup(s->dvinit,strlen(s->dvinit));
symtab[i].symtype = INIT;
i=lookup(s->dvopen,strlen(s->dvopen));
symtab[i].symtype = OPEN;
i=lookup(s->dvclose,strlen(s->dvclose));
symtab[i].symtype = CLOSE;
i=lookup(s->dvread,strlen(s->dvread));
symtab[i].symtype = READ;
i=lookup(s->dvwrite,strlen(s->dvwrite));
symtab[i].symtype = WRITE;
i=lookup(s->dvseek,strlen(s->dvseek));
symtab[i].symtype = SEEK;
i=lookup(s->dvcntl,strlen(s->dvcntl));
symtab[i].symtype = CNTL;
i=lookup(s->dvgetc,strlen(s->dvgetc));
symtab[i].symtype = GETC;
i=lookup(s->dvputc,strlen(s->dvputc));
symtab[i].symtype = PUTC;
i=lookup(s->dviint,strlen(s->dviint));
symtab[i].symtype = IINT;
i=lookup(s->dvoint,strlen(s->dvoint));
symtab[i].symtype = OINT;
}
fprintf(confh,
"/* Declarations of I/O routines referenced */\n\n");
for (i=0 ; i<nsym ; i++)
prdef(confh, symtab[i].symname, symtab[i].symtype);
/* produce devtab (giant I/O switch table) */
fprintf(confc, "\n/* device independent I/O switch */\n\n");
if (ndevs > 0) {
fprintf(confc, "struct\tdevsw\tdevtab[NDEVS] = {\n");
fprintf(confc, "\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n",
"/* Format of entries is:",
"device-number, device-name,",
"init, open, close,",
"read, write, seek,",
"getc, putc, cntl,",
"device-csr-address, input-vector, output-vector,",
"iint-handler, oint-handler, control-block, minor-device,",
"*/");
}
for (fcount=0,s=devs ; s!=NIL ; s=s->dvnext,fcount++) {
fprintf(confc, "\n/* %s is %s */\n\n",s->dvname,s->dvtname);
fprintf(confc, "%d, \"%s\",\n", fcount, s->dvname);
fprintf(confc, "%s, %s, %s,\n",
s->dvinit, s->dvopen, s->dvclose);
fprintf(confc, "%s, %s, %s,\n",
s->dvread, s->dvwrite, s->dvseek);
fprintf(confc, "%s, %s, %s,\n",
s->dvgetc, s->dvputc, s->dvcntl);
fprintf(confc, "0%06o, 0%03o, 0%03o,\n",
s->dvcsr, s->dvivec, s->dvovec);
fprintf(confc, "%s, %s, NULLPTR, %d",
s->dviint, s->dvoint, s->dvminor);
if ( s->dvnext != NIL )
fprintf(confc, ",\n");
else
fprintf(confc, "\n\t};");
}
/* Copy definitions to output */
if (brkcount == 2 && verbose)
printf("Copying definitions to %s...\n", CONFIGH);
if (brkcount == 2 )
while ( (c=input()) > 0) /* lex input routine */
putc(c, confh);
/* guarantee conf.c written later than conf.c for make */
fclose(confh);
fprintf(confc, "\n");
fclose(confc);
/* finish up and write report for user if requested */
if (verbose) {
printf("\nConfiguration complete. Number of devs=%d:\n\n",ndevs);
for (s=devs; s!=NIL ; s=s->dvnext)
printf(
"Device %s (on %s) csr=0%-7o, ivec=0%-3o, ovec=0%-3o, minor=%d\n",
s->dvname, s->dvdevice, s->dvcsr, s->dvivec, s->dvovec,
s->dvminor);
}
}
yyerror(s)
char *s;
{
fprintf(stderr,"Syntax error in %s on line %d\n",
doing,linectr);
}
/* lookup -- lookup a name in the symbol table; return position */
lookup(str,len)
char *str;
int len;
{
int i;
char *s;
if (len >= 20) {
len = 19;
fprintf(stderr,"warning: name %s truncated\n",str);
}
s = (char *)malloc(len+1);
strncpy(s,str,len);
s[len] = '\000';
for (i=0 ; i<nsym ; i++)
if (strcmp(s,symtab[i].symname) == 0){
return(i);
}
symtab[nsym].symname = s;
symtab[nsym].symoccurs = 0;
return(nsym++);
}
int
l_atoi(p, len)
char *p;
int len;
{
int base, rv;
if (*p == '0') {
++p; --len;
if (*p == 'x' || *p == 'X') {
++p; --len; /* skip 'x' */
base = 16;
} else
base = 8;
} else
base = 10;
rv = 0;
for (; len > 0; ++p, --len) {
rv *= base;
if (isdigit(*p))
rv += *p - '0';
else if (isupper(*p))
rv += *p - 'A' + 10;
else
rv += *p - 'a' + 10;
}
return rv;
}
/* newattr -- add a new attribute spec to current type/device description */
newattr(tok,val)
int tok; /* token type (attribute type) */
int val; /* symbol number of value */
{
char *c;
dvptr s;
if (devs == NIL) /* doing types */
s = currtype;
else
s = lastdv;
if (val>=0 && val<nsym) {
c = symtab[val].symname;
if (strlen(c) > 20 ) {
fprintf(stderr,"Internal overflow\n");
exit(1);
}
} else
c = NULL;
switch (tok) {
case CSR: s->dvcsr = (void *)val;
break;
case IVEC: s->dvivec = val;
break;
case OVEC: s->dvovec = val;
break;
case IRQ: s->dvovec = s->dvivec = val;
break;
case IINT: strcpy(s->dviint,c);
break;
case OINT: strcpy(s->dvoint,c);
break;
case READ: strcpy(s->dvread,c);
break;
case WRITE: strcpy(s->dvwrite,c);
break;
case GETC: strcpy(s->dvgetc,c);
break;
case PUTC: strcpy(s->dvputc,c);
break;
case OPEN: strcpy(s->dvopen,c);
break;
case CLOSE: strcpy(s->dvclose,c);
break;
case INIT: strcpy(s->dvinit,c);
break;
case SEEK: strcpy(s->dvseek,c);
break;
case CNTL: strcpy(s->dvcntl,c);
break;
default: fprintf(stderr, "Internal error 1\n");
}
}
/* cktname -- check type name for duplicates */
cktname(symid)
int symid;
{
dvptr s;
extern dvptr ftypes;
char *name;
name = symtab[symid].symname;
for (s=ftypes; s!=NIL ; s=s->dvnext) {
if (s->dvtname == name) {
fprintf(stderr,"Duplicate type name %s on line %d\n",
name,linectr);
exit(1);
}
}
return(symid);
}
/* mktype -- make a node in the type list and initialize to defaults */
mktype(int deviceid)
{
dvptr s,p;
char *tn,*dn;
p = NIL;
tn = symtab[currtname].symname;
dn = symtab[deviceid].symname;
for (s = ftypes; s!=NIL ; s=s->dvnext) {
if (s->dvtname == tn && s->dvdevice==dn) {
fprintf(stderr,
"Duplicate device %s for type %s on line %d\n",
dn, tn, linectr);
exit(1);
}
p = s;
}
currtype = s = (dvptr) malloc( sizeof(struct dvtype));
if (ftypes != NIL) {
p->dvnext = s;
}
else {
ftypes = s;
}
initattr(s, currtname, deviceid);
}
/* initialize attributes in a type declaration node to typename... */
initattr(fstr, tnum, deviceid)
dvptr fstr;
int tnum;
int deviceid;
{
char *typnam;
typnam = symtab[tnum].symname;
fstr->dvname = NULL;
fstr->dvtname = typnam;
fstr->dvtnum = tnum;
fstr->dvdevice = symtab[deviceid].symname;
fstr->dvcsr = 0;
fstr->dvivec = 0;
fstr->dvovec = 0;
strcpy(fstr->dviint,typnam);
strcat(fstr->dviint,"iin");
strcpy(fstr->dvoint,typnam);
strcat(fstr->dvoint,"oin");
strcpy(fstr->dvinit,typnam);
strcat(fstr->dvinit,"init");
strcpy(fstr->dvopen,typnam);
strcat(fstr->dvopen,"open");
strcpy(fstr->dvclose,typnam);
strcat(fstr->dvclose,"close");
strcpy(fstr->dvread,typnam);
strcat(fstr->dvread,"read");
strcpy(fstr->dvwrite,typnam);
strcat(fstr->dvwrite,"write");
strcpy(fstr->dvcntl,typnam);
strcat(fstr->dvcntl,"control");
strcpy(fstr->dvseek,typnam);
strcat(fstr->dvseek,"seek");
strcpy(fstr->dvgetc,typnam);
strcat(fstr->dvgetc,"getc");
strcpy(fstr->dvputc,typnam);
strcat(fstr->dvputc,"putc");
fstr->dvminor = 0;
}
/* mkdev -- make a node on the device list */
mkdev(nameid, typid, deviceid)
int nameid, typid, deviceid;
{
dvptr s;
char *devn,*tn,*dn;
int found;
s = (dvptr) malloc(sizeof(struct dvtype));
s->dvnext = NIL;
if (devs == NIL) {
devs = s;
lastdv = s;
} else {
lastdv->dvnext = s;
lastdv = s;
}
ndevs++;
tn = symtab[typid].symname;
devn = symtab[nameid].symname;
if (deviceid >= 0)
dn = symtab[deviceid].symname;
else
dn = NULL;
found = 0;
for (s=ftypes ; s != NULL ; s=s->dvnext)
if (s->dvtname == tn && (dn==NULL || s->dvdevice==dn)) {
strdup(lastdv,s,sizeof(struct dvtype));
found=1;
break;
}
if (found==0) {
fprintf(stderr,
"Bad type or device name in declaration of %s on line %d\n",
devn, linectr);
exit(1);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -