2 * Copyright (c) 1983 Regents of the University of California.
5 * Redistribution and use in source and binary forms are permitted
6 * provided that the above copyright notice and this paragraph are
7 * duplicated in all such forms and that any documentation,
8 * advertising materials, and other materials related to such
9 * distribution and use acknowledge that the software was developed
10 * by the University of California, Berkeley. The name of the
11 * University may not be used to endorse or promote products derived
12 * from this software without specific prior written permission.
14 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
15 * Use is subject to license terms.
17 #pragma ident "%Z%%M% %I% %E% SMI"
28 struct namelist
*s_value
;
29 struct syment
*s_next
;
32 static struct syment
*hashtab
[HASHSIZE
];
35 * Define a variable from a command line argument.
41 register char *cp
, *s
;
42 register struct namelist
*nl
;
43 struct namelist
*value
;
46 printf("define(%s)\n", name
);
48 cp
= index(name
, '=');
51 else if (cp
[1] == '\0') {
54 } else if (cp
[1] != '(') {
62 while (*cp
== ' ' || *cp
== '\t');
72 while (*s
== ' ' || *s
== '\t')
81 value
= nl
= makenl(cp
);
83 nl
->n_next
= makenl(cp
);
91 (void) lookup(name
, REPLACE
, value
);
95 * Lookup name in the table and return a pointer to it.
96 * LOOKUP - just do lookup, return NULL if not found.
97 * INSERT - insert name with value, error if already defined.
98 * REPLACE - insert or replace name with value.
102 lookup(name
, action
, value
)
105 struct namelist
*value
;
109 register struct syment
*s
;
113 printf("lookup(%s, %d, %x)\n", name
, action
, value
);
116 for (cp
= name
; *cp
; )
120 for (s
= hashtab
[n
]; s
!= NULL
; s
= s
->s_next
) {
121 if (strcmp(name
, s
->s_name
))
123 if (action
!= LOOKUP
) {
124 if (action
!= INSERT
|| s
->s_type
!= CONST
) {
125 (void)sprintf(buf
, "%.*s redefined",
126 sizeof(buf
) - sizeof(" redefined"), name
);
133 if (action
== LOOKUP
) {
134 (void)sprintf(buf
, "%.*s undefined",
135 sizeof(buf
) - sizeof(" undefined"), name
);
142 fatal("ran out of memory\n");
143 s
->s_next
= hashtab
[n
];
145 s
->s_type
= action
== INSERT
? VAR
: CONST
;