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
|
int
do_kv(TARG,hash,kv,gimme,arglast)
STR *TARG;
HASH *hash;
int kv;
int gimme;
int *arglast;
{
register ARRAY *ary = stack;
STR **st = ary->ary_array;
register int sp = arglast[0];
int i;
register HENT *entry;
char *tmps;
STR *tmpstr;
int dokeys = (kv == O_KEYS || kv == O_HASH);
int dovalues = (kv == O_VALUES || kv == O_HASH);
if (gimme != G_ARRAY) {
i = 0;
(void)hiterinit(hash);
/*SUPPRESS 560*/
while (entry = hiternext(hash)) {
i++;
}
str_numset(TARG,(double)i);
STABSET(TARG);
st[++sp] = TARG;
return sp;
}
(void)hiterinit(hash);
/*SUPPRESS 560*/
while (entry = hiternext(hash)) {
if (dokeys) {
tmps = hiterkey(entry,&i);
if (!i)
tmps = "";
(void)astore(ary,++sp,str_2mortal(str_make(tmps,i)));
}
if (dovalues) {
tmpstr = Str_new(45,0);
#ifdef DEBUGGING
if (debug & 8192) {
sprintf(buf,"%d%%%d=%d\n",entry->hent_hash,
hash->tbl_max+1,entry->hent_hash & hash->tbl_max);
str_set(tmpstr,buf);
}
else
#endif
str_sset(tmpstr,hiterval(hash,entry));
(void)astore(ary,++sp,str_2mortal(tmpstr));
}
}
return sp;
}
|