version 1.1, 1995/10/18 08:45:59 |
version 1.2, 1996/02/03 12:12:29 |
|
|
/* |
/* |
* Copyright (c) 1983, 1993 |
* Copyright (c) 1983 Regents of the University of California. |
* The Regents of the University of California. All rights reserved. |
* All rights reserved. |
* |
* |
* Redistribution and use in source and binary forms, with or without |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* modification, are permitted provided that the following conditions |
|
|
*/ |
*/ |
|
|
#ifndef lint |
#ifndef lint |
/* from: static char sccsid[] = "@(#)lookup.c 8.1 (Berkeley) 6/9/93"; */ |
static char RCSid[] = |
static char *rcsid = "$Id$"; |
"$Id$"; |
|
|
|
static char sccsid[] = "@(#)lookup.c 5.1 (Berkeley) 6/6/85"; |
|
|
|
static char copyright[] = |
|
"@(#) Copyright (c) 1983 Regents of the University of California.\n\ |
|
All rights reserved.\n"; |
#endif /* not lint */ |
#endif /* not lint */ |
|
|
#include "defs.h" |
#include "defs.h" |
|
|
/* |
/* |
* Define a variable from a command line argument. |
* Define a variable from a command line argument. |
*/ |
*/ |
void |
|
define(name) |
define(name) |
char *name; |
char *name; |
{ |
{ |
|
|
register struct namelist *nl; |
register struct namelist *nl; |
struct namelist *value; |
struct namelist *value; |
|
|
if (debug) |
debugmsg(DM_CALL, "define(%s)", name); |
printf("define(%s)\n", name); |
|
|
|
cp = index(name, '='); |
cp = strchr(name, '='); |
if (cp == NULL) |
if (cp == NULL) |
value = NULL; |
value = NULL; |
else if (cp[1] == '\0') { |
else if (cp[1] == '\0') { |
|
|
*cp++ = '\0'; |
*cp++ = '\0'; |
value = makenl(cp); |
value = makenl(cp); |
} else { |
} else { |
|
value = NULL; |
nl = NULL; |
nl = NULL; |
*cp++ = '\0'; |
*cp++ = '\0'; |
do |
do |
|
|
*/ |
*/ |
|
|
struct namelist * |
struct namelist * |
lookup(name, action, value) |
lookup(name, action, value) /* %% in name. Ignore quotas in name */ |
char *name; |
char *name; |
int action; |
int action; |
struct namelist *value; |
struct namelist *value; |
|
|
register unsigned n; |
register unsigned n; |
register char *cp; |
register char *cp; |
register struct syment *s; |
register struct syment *s; |
char buf[256]; |
char ebuf[BUFSIZ]; |
|
|
if (debug) |
debugmsg(DM_CALL, "lookup(%s, %d, %x)", name, action, value); |
printf("lookup(%s, %d, %x)\n", name, action, value); |
|
|
|
n = 0; |
n = 0; |
for (cp = name; *cp; ) |
for (cp = name; *cp; ) |
|
|
continue; |
continue; |
if (action != LOOKUP) { |
if (action != LOOKUP) { |
if (action != INSERT || s->s_type != CONST) { |
if (action != INSERT || s->s_type != CONST) { |
(void)sprintf(buf, "%s redefined", name); |
(void) sprintf(ebuf, "%s redefined", name); |
yyerror(buf); |
yyerror(ebuf); |
} |
} |
} |
} |
return(s->s_value); |
return(s->s_value); |
} |
} |
|
|
if (action == LOOKUP) { |
if (action == LOOKUP) { |
(void)sprintf(buf, "%s undefined", name); |
(void) sprintf(ebuf, "%s undefined", name); |
yyerror(buf); |
yyerror(ebuf); |
return(NULL); |
return(NULL); |
} |
} |
|
|
s = ALLOC(syment); |
s = ALLOC(syment); |
if (s == NULL) |
|
fatal("ran out of memory\n"); |
|
s->s_next = hashtab[n]; |
s->s_next = hashtab[n]; |
hashtab[n] = s; |
hashtab[n] = s; |
s->s_type = action == INSERT ? VAR : CONST; |
s->s_type = action == INSERT ? VAR : CONST; |
s->s_name = name; |
s->s_name = name; |
s->s_value = value; |
s->s_value = value; |
|
|
return(value); |
return(value); |
} |
} |