static char *sccsid
= "@(#)lookup.c 4.2 (Berkeley) 83/09/27";
* Define a variable from a command line argument.
register struct block
*bp
, *value
;
printf("define(%s)\n", name
);
if (cp
== NULL
|| cp
[1] == '\0')
value
= makeblock(NAME
, cp
);
while (*cp
== ' ' || *cp
== '\t');
while (*s
== ' ' || *s
== '\t')
value
= bp
= makeblock(NAME
, cp
);
bp
->b_next
= makeblock(NAME
, cp
);
bp
= makeblock(VAR
, name
);
(void) lookup(bp
->b_name
, bp
, 1);
static struct block
*hashtab
[HASHSIZE
];
* Lookup name in the table and return a pointer to it.
* Insert == 0 - just do lookup, return NULL if not found.
* insert == 1 - insert name with value, error if already defined.
* insert == 2 - replace name with value if not entered with insert == 1.
lookup(name
, value
, insert
)
register struct block
*b
, *f
;
printf("lookup(%s, %x, %d)\n", name
, value
, insert
);
for (b
= hashtab
[n
]; b
!= NULL
; b
= b
->b_next
) {
if (strcmp(name
, b
->b_name
))
warn("%s redefined\n", name
);
b
->b_args
= value
->b_args
;
} else if (value
->b_type
== VAR
)
fatal("%s redefined\n", name
);
while (f
= value
->b_next
) {
value
->b_next
= f
->b_next
;
fatal("%s not defined", name
);
value
->b_next
= hashtab
[n
];
* Make a block for lists of variables, commands, etc.
register struct block
*bp
;
fatal("ran out of memory\n");
bp
->b_next
= bp
->b_args
= NULL
;
if (type
== NAME
|| type
== VAR
) {
bp
->b_name
= cp
= (char *) malloc(strlen(name
) + 1);
fatal("ran out of memory\n");