-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathxssym.c
92 lines (79 loc) · 2.01 KB
/
xssym.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/* xssym.c - symbol handling routines */
/* Copyright (c) 1988, by David Michael Betz
All Rights Reserved
Permission is granted for unrestricted non-commercial use */
#include <string.h>
#include "xscheme.h"
/* external variables */
extern LVAL obarray;
/* forward declarations */
#ifdef __STDC__
static LVAL findprop(LVAL sym,LVAL prp);
#else
LVAL findprop();
#endif
/* xlsubr - define a builtin function */
void xlsubr(sname,type,fcn,offset)
char *sname; int type; LVAL (*fcn)(); int offset;
{
LVAL sym;
sym = xlenter(sname);
setvalue(sym,cvsubr(type,fcn,offset));
}
/* xlenter - enter a symbol into the obarray */
LVAL xlenter(name)
char *name;
{
LVAL array,sym;
int i;
/* get the current obarray and the hash index for this symbol */
array = getvalue(obarray);
i = hash(name,HSIZE);
/* check if symbol is already in table */
for (sym = getelement(array,i); sym; sym = cdr(sym))
if (strcmp(name,getstring(getpname(car(sym)))) == 0)
return (car(sym));
/* make a new symbol node and link it into the list */
sym = cons(cvsymbol(name),getelement(array,i));
setelement(array,i,sym);
sym = car(sym);
/* return the new symbol */
return (sym);
}
/* xlgetprop - get the value of a property */
LVAL xlgetprop(sym,prp)
LVAL sym,prp;
{
LVAL p;
return ((p = findprop(sym,prp)) == NIL ? NIL : car(p));
}
/* xlputprop - put a property value onto the property list */
void xlputprop(sym,val,prp)
LVAL sym,val,prp;
{
LVAL pair;
if ((pair = findprop(sym,prp)) != NIL)
rplaca(pair,val);
else
setplist(sym,cons(prp,cons(val,getplist(sym))));
}
/* findprop - find a property pair */
static LVAL findprop(sym,prp)
LVAL sym,prp;
{
LVAL p;
for (p = getplist(sym); consp(p) && consp(cdr(p)); p = cdr(cdr(p)))
if (car(p) == prp)
return (cdr(p));
return (NIL);
}
/* hash - hash a symbol name string */
int hash(str,len)
char *str; int len;
{
int i;
for (i = 0; *str; )
i = (i << 2) ^ *str++;
i %= len;
return (i < 0 ? -i : i);
}