Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 53 additions & 31 deletions config/config.y
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ char *devstab[] = {
};

char saveattrid[MAXNAME]; /* Holds the IDENT from an attribute */
char devtypename[MAXNAME];

/********************************************************************************/
/* */
Expand All @@ -111,14 +112,14 @@ char saveattrid[MAXNAME]; /* Holds the IDENT from an attribute */
/********************************************************************************/

void addattr(int, int);
int addton(char *);
int config_atoi(char *, int);
void devisid(char *);
void devonid(char *);
void getattrid(char *);
void newdev(char *);
int newtype(char *);
void yyerror(char *);
void savename(char *);


%}
Expand Down Expand Up @@ -146,7 +147,7 @@ devtypes: /* nothing */ { doing = "device definitions"; }
devtype: tname COLON dev_tlist
;

tname: IDENT { $$ = newtype(yytext); }
tname: IDENT { savename(yytext); }
;

dev_tlist: theader attr_list
Expand All @@ -156,7 +157,7 @@ dev_tlist: theader attr_list
theader: ON tonid { $$ = $2; }
;

tonid: IDENT { $$ = addton(yytext); }
tonid: IDENT { newtype(yytext); }
;

attr_list: /* nothing */
Expand Down Expand Up @@ -462,28 +463,6 @@ void addattr(int tok, int val) {
}
}


/************************************************************************/
/* */
/* addton -- add an "on XXX" to the current type */
/* */
/************************************************************************/

int addton(char *tonid) {
int currtype; /* The current type */

if (strlen(tonid) >= MAXNAME) {
fprintf(stderr,"string %s is too long on line %d\n",
tonid, linectr);
exit(1);
}
currtype = ntypes - 1;
strcpy(dtypes[currtype].ison, tonid);

return currtype;
}


/************************************************************************/
/* */
/* config_atoi - convert an ascii string of text to an integer, */
Expand Down Expand Up @@ -593,7 +572,7 @@ void devonid(char *onname) {
for (i=0; i<ntypes; i++) {
tptr = &dtypes[i];
if ( (strcmp(dptr->tname,tptr->tname) == 0 ) &&
(strcmp(dptr->ison, tptr->ison) == 0 ) ){
(strcmp(dptr->ison, tptr->ison) == 0 ) ){

/* The specified type matches the ith entry, so */
/* set all attributes equal to the ones in the */
Expand Down Expand Up @@ -674,16 +653,35 @@ void newdev(char *name) {
}



/************************************************************************/
/* */
/* newtype -- allocate an entry in the type array and fill in the name */
/* savename -- save the name of a new device type for use when making dentrys */
/* */
/************************************************************************/

int newtype(char *name) {
void savename(char *name) {
if (strlen(name) >= MAXNAME) {
fprintf(stderr,"Type name %s is too long on line %d\n",
name, linectr);
exit(1);
}
strcpy(devtypename, name);
}


/************************************************************************/
/* */
/* newtype -- allocate an entry in the type array and fill in the name ison fields */
/* */
/************************************************************************/

int newtype(char *tonid) {

char *name = devtypename;
struct dev_ent *dptr; /* Ptr. to an entry in dtypes */
int i; /* Index into the type table */
int last = -1; /* The last entry in the type table with the same type name */

if (ntypes >= NTYPES) {
fprintf(stderr,"Too many types on line %d", linectr);
Expand All @@ -695,13 +693,22 @@ int newtype(char *name) {
exit(1);
}

/* Verify that the type name is unique */
if (strlen(tonid) >= MAXNAME) {
fprintf(stderr,"string %s is too long on line %d\n",
tonid, linectr);
exit(1);
}

/* Verify that the (type name, is on) pair is unique */

for (i=0; i<ntypes; i++) {
if (strcmp(name, dtypes[i].tname) == 0) {
fprintf(stderr, "Duplicate type name %s on line %d\n",
name, linectr);
last = i;
if (strcmp(tonid, dtypes[i].ison) == 0) {
fprintf(stderr, "Duplicate type name on line %d: %s on %s\n",
linectr, name, tonid);
exit(1);
}
}
}

Expand All @@ -711,6 +718,7 @@ int newtype(char *name) {

bzero((void *)dptr, sizeof(struct dev_ent));
strcpy(dptr->tname, name);
strcpy(dptr->ison, tonid);
strncpy(dptr->intr, "ioerr", 5);
strncpy(dptr->init, "ioerr", 5);
strncpy(dptr->open, "ioerr", 5);
Expand All @@ -722,6 +730,20 @@ int newtype(char *name) {
strncpy(dptr->getc, "ioerr", 5);
strncpy(dptr->putc, "ioerr", 5);

if (last != -1) {
struct dev_ent *lptr = &dtypes[last];

strcpy(dptr->intr, lptr->intr);
strcpy(dptr->init, lptr->init);
strcpy(dptr->open, lptr->open);
strcpy(dptr->close, lptr->close);
strcpy(dptr->read, lptr->read);
strcpy(dptr->write, lptr->write);
strcpy(dptr->control, lptr->control);
strcpy(dptr->seek, lptr->seek);
strcpy(dptr->getc, lptr->getc);
strcpy(dptr->putc, lptr->putc);
}
return ntypes++;
}

Expand Down