1 /* $Header: dolist.c,v 3.0.1.6 90/03/12 16:33:02 lwall Locked $
3 * Copyright (c) 1989, Larry Wall
5 * You may distribute under the terms of the GNU General Public License
6 * as specified in the README file that comes with the perl 3.0 kit.
9 * Revision 3.0.1.6 90/03/12 16:33:02 lwall
10 * patch13: added list slice operator (LIST)[LIST]
11 * patch13: added splice operator: @oldelems = splice(@array,$offset,$len,LIST)
12 * patch13: made split('') act like split(//) rather than split(' ')
14 * Revision 3.0.1.5 90/02/28 17:09:44 lwall
15 * patch9: split now can split into more than 10000 elements
16 * patch9: @_ clobbered by ($foo,$bar) = split
17 * patch9: sped up pack and unpack
18 * patch9: unpack of single item now works in a scalar context
19 * patch9: slices ignored value of $[
20 * patch9: grep now returns number of items matched in scalar context
21 * patch9: grep iterations no longer in the regexp context of previous iteration
23 * Revision 3.0.1.4 89/12/21 19:58:46 lwall
24 * patch7: grep(1,@array) didn't work
25 * patch7: /$pat/; //; wrongly freed runtime pattern twice
27 * Revision 3.0.1.3 89/11/17 15:14:45 lwall
28 * patch5: grep() occasionally loses arguments or dumps core
30 * Revision 3.0.1.2 89/11/11 04:28:17 lwall
31 * patch2: non-existent slice values are now undefined rather than null
33 * Revision 3.0.1.1 89/10/26 23:11:51 lwall
34 * patch1: split in a subroutine wrongly freed referenced arguments
35 * patch1: reverse didn't work
37 * Revision 3.0 89/10/18 15:11:02 lwall
47 do_match(str,arg,gimme,arglast)
53 register STR **st = stack->ary_array;
54 register SPAT *spat = arg[2].arg_ptr.arg_spat;
56 register int sp = arglast[0] + 1;
57 STR *srchstr = st[sp];
58 register char *s = str_get(st[sp]);
59 char *strend = s + st[sp]->str_cur;
71 fatal("panic: do_match");
72 if (spat->spat_flags & SPAT_USED) {
85 if (spat->spat_runtime) {
87 sp = eval(spat->spat_runtime,G_SCALAR,sp);
88 st = stack->ary_array;
89 t = str_get(tmpstr = st[sp--]);
93 deb("2.SPAT /%s/\n",t);
95 if (spat->spat_regexp)
96 regfree(spat->spat_regexp);
97 spat->spat_regexp = regcomp(t,t+tmpstr->str_cur,
98 spat->spat_flags & SPAT_FOLD,1);
99 if (!*spat->spat_regexp->precomp && lastspat)
101 if (spat->spat_flags & SPAT_KEEP) {
102 if (spat->spat_runtime)
103 arg_free(spat->spat_runtime); /* it won't change, so */
104 spat->spat_runtime = Nullarg; /* no point compiling again */
106 if (!spat->spat_regexp->nparens)
107 gimme = G_SCALAR; /* accidental array context? */
108 if (regexec(spat->spat_regexp, s, strend, s, 0,
109 srchstr->str_pok & SP_STUDIED ? srchstr : Nullstr,
111 if (spat->spat_regexp->subbase)
117 if (gimme == G_ARRAY)
119 str_sset(str,&str_no);
130 if (spat->spat_flags & SPAT_ONCE)
134 deb("2.SPAT %c%s%c\n",ch,spat->spat_regexp->precomp,ch);
137 if (!*spat->spat_regexp->precomp && lastspat)
141 if (hint < s || hint > strend)
142 fatal("panic: hint in do_match");
145 if (spat->spat_regexp->regback >= 0) {
146 s -= spat->spat_regexp->regback;
153 else if (spat->spat_short) {
154 if (spat->spat_flags & SPAT_SCANFIRST) {
155 if (srchstr->str_pok & SP_STUDIED) {
156 if (screamfirst[spat->spat_short->str_rare] < 0)
158 else if (!(s = screaminstr(srchstr,spat->spat_short)))
160 else if (spat->spat_flags & SPAT_ALL)
164 else if (!(s = fbminstr((unsigned char*)s,
165 (unsigned char*)strend, spat->spat_short)))
168 else if (spat->spat_flags & SPAT_ALL)
170 if (s && spat->spat_regexp->regback >= 0) {
171 ++spat->spat_short->str_u.str_useful;
172 s -= spat->spat_regexp->regback;
179 else if (!multiline && (*spat->spat_short->str_ptr != *s ||
180 bcmp(spat->spat_short->str_ptr, s, spat->spat_slen) ))
182 if (--spat->spat_short->str_u.str_useful < 0) {
183 str_free(spat->spat_short);
184 spat->spat_short = Nullstr; /* opt is being useless */
187 if (!spat->spat_regexp->nparens)
188 gimme = G_SCALAR; /* accidental array context? */
189 if (regexec(spat->spat_regexp, s, strend, t, 0,
190 srchstr->str_pok & SP_STUDIED ? srchstr : Nullstr,
192 if (spat->spat_regexp->subbase)
195 if (spat->spat_flags & SPAT_ONCE)
196 spat->spat_flags |= SPAT_USED;
200 if (gimme == G_ARRAY)
202 str_sset(str,&str_no);
211 if (gimme == G_ARRAY) {
214 iters = spat->spat_regexp->nparens;
215 if (sp + iters >= stack->ary_max) {
216 astore(stack,sp + iters, Nullstr);
217 st = stack->ary_array; /* possibly realloced */
220 for (i = 1; i <= iters; i++) {
221 st[++sp] = str_static(&str_no);
222 if (s = spat->spat_regexp->startp[i]) {
223 len = spat->spat_regexp->endp[i] - s;
225 str_nset(st[sp],s,len);
231 str_sset(str,&str_yes);
238 ++spat->spat_short->str_u.str_useful;
240 if (spat->spat_flags & SPAT_ONCE)
241 spat->spat_flags |= SPAT_USED;
245 tmps = spat->spat_regexp->subbase = nsavestr(t,strend-t);
246 tmps = spat->spat_regexp->startp[0] = tmps + (s - t);
247 spat->spat_regexp->endp[0] = tmps + spat->spat_short->str_cur;
250 str_sset(str,&str_yes);
256 ++spat->spat_short->str_u.str_useful;
257 if (gimme == G_ARRAY)
259 str_sset(str,&str_no);
266 do_split(str,spat,limit,gimme,arglast)
273 register ARRAY *ary = stack;
274 STR **st = ary->ary_array;
275 register int sp = arglast[0] + 1;
276 register char *s = str_get(st[sp]);
277 char *strend = s + st[sp--]->str_cur;
281 int maxiters = (strend - s) + 10;
284 int origlimit = limit;
288 fatal("panic: do_split");
289 else if (spat->spat_runtime) {
291 sp = eval(spat->spat_runtime,G_SCALAR,sp);
292 st = stack->ary_array;
293 m = str_get(dstr = st[sp--]);
295 if (*m == ' ' && dstr->str_cur == 1) {
296 str_set(dstr,"\\s+");
298 spat->spat_flags |= SPAT_SKIPWHITE;
300 if (spat->spat_regexp)
301 regfree(spat->spat_regexp);
302 spat->spat_regexp = regcomp(m,m+dstr->str_cur,
303 spat->spat_flags & SPAT_FOLD,1);
304 if (spat->spat_flags & SPAT_KEEP ||
305 (spat->spat_runtime->arg_type == O_ITEM &&
306 (spat->spat_runtime[1].arg_type & A_MASK) == A_SINGLE) ) {
307 arg_free(spat->spat_runtime); /* it won't change, so */
308 spat->spat_runtime = Nullarg; /* no point compiling again */
313 deb("2.SPAT /%s/\n",spat->spat_regexp->precomp);
316 ary = stab_xarray(spat->spat_repl[1].arg_ptr.arg_stab);
317 if (ary && (gimme != G_ARRAY || (spat->spat_flags & SPAT_ONCE))) {
319 if (!(ary->ary_flags & ARF_REAL)) {
320 ary->ary_flags |= ARF_REAL;
321 for (i = ary->ary_fill; i >= 0; i--)
322 ary->ary_array[i] = Nullstr; /* don't free mere refs */
325 sp = -1; /* temporarily switch stacks */
330 if (spat->spat_flags & SPAT_SKIPWHITE) {
335 limit = maxiters + 2;
336 if (spat->spat_short) {
337 i = spat->spat_short->str_cur;
339 i = *spat->spat_short->str_ptr;
341 for (m = s; m < strend && *m != i; m++) ;
345 dstr = Str_new(30,m-s);
347 dstr = str_static(&str_undef);
348 str_nset(dstr,s,m-s);
349 (void)astore(ary, ++sp, dstr);
355 while (s < strend && --limit &&
356 (m=fbminstr((unsigned char*)s, (unsigned char*)strend,
361 dstr = Str_new(31,m-s);
363 dstr = str_static(&str_undef);
364 str_nset(dstr,s,m-s);
365 (void)astore(ary, ++sp, dstr);
371 maxiters += (strend - s) * spat->spat_regexp->nparens;
372 while (s < strend && --limit &&
373 regexec(spat->spat_regexp, s, strend, orig, 1, Nullstr, TRUE) ) {
374 if (spat->spat_regexp->subbase
375 && spat->spat_regexp->subbase != orig) {
378 orig = spat->spat_regexp->subbase;
380 strend = s + (strend - m);
382 m = spat->spat_regexp->startp[0];
384 dstr = Str_new(32,m-s);
386 dstr = str_static(&str_undef);
387 str_nset(dstr,s,m-s);
388 (void)astore(ary, ++sp, dstr);
389 if (spat->spat_regexp->nparens) {
390 for (i = 1; i <= spat->spat_regexp->nparens; i++) {
391 s = spat->spat_regexp->startp[i];
392 m = spat->spat_regexp->endp[i];
394 dstr = Str_new(33,m-s);
396 dstr = str_static(&str_undef);
397 str_nset(dstr,s,m-s);
398 (void)astore(ary, ++sp, dstr);
401 s = spat->spat_regexp->endp[0];
407 iters = sp - arglast[0];
408 if (iters > maxiters)
410 if (s < strend || origlimit) { /* keep field after final delim? */
412 dstr = Str_new(34,strend-s);
414 dstr = str_static(&str_undef);
415 str_nset(dstr,s,strend-s);
416 (void)astore(ary, ++sp, dstr);
421 while (iters > 0 && ary->ary_array[sp]->str_cur == 0)
428 zaps = str_get(afetch(ary,sp,FALSE));
432 while (iters > 0 && (!zapb)) {
435 zaps = str_get(afetch(ary,iters-1,FALSE));
443 if (gimme == G_ARRAY) {
445 astore(stack, arglast[0] + 1 + sp, Nullstr);
446 Copy(ary->ary_array, stack->ary_array + arglast[0] + 1, sp, STR*);
447 return arglast[0] + sp;
451 if (gimme == G_ARRAY)
455 str_numset(str,(double)iters);
462 do_unpack(str,gimme,arglast)
467 STR **st = stack->ary_array;
468 register int sp = arglast[0] + 1;
469 register char *pat = str_get(st[sp++]);
470 register char *s = str_get(st[sp]);
471 char *strend = s + st[sp--]->str_cur;
472 register char *patend = pat + st[sp]->str_cur;
476 /* These must not be in registers: */
481 unsigned char auchar;
482 unsigned short aushort;
484 unsigned long aulong;
487 if (gimme != G_ARRAY) { /* arrange to do first one only */
489 if (*pat == 'a' || *pat == 'A') {
490 while (isdigit(*patend))
495 while (pat < patend) {
499 while (isdigit(*pat))
500 len = (len * 10) + (*pat++ - '0');
512 if (s + len > strend)
514 str = Str_new(35,len);
517 if (datumtype == 'A') {
518 aptr = s; /* borrow register */
519 s = str->str_ptr + len - 1;
520 while (s >= str->str_ptr && (!*s || isspace(*s)))
523 str->str_cur = s - str->str_ptr;
524 s = aptr; /* unborrow register */
526 (void)astore(stack, ++sp, str_2static(str));
530 if (s + sizeof(char) > strend)
533 bcopy(s,(char*)&achar,sizeof(char));
538 if (aint >= 128) /* fake up signed chars */
540 str_numset(str,(double)aint);
541 (void)astore(stack, ++sp, str_2static(str));
546 if (s + sizeof(unsigned char) > strend)
549 bcopy(s,(char*)&auchar,sizeof(unsigned char));
550 s += sizeof(unsigned char);
553 auint = auchar; /* some can't cast uchar to double */
554 str_numset(str,(double)auint);
555 (void)astore(stack, ++sp, str_2static(str));
560 if (s + sizeof(short) > strend)
563 bcopy(s,(char*)&ashort,sizeof(short));
567 str_numset(str,(double)ashort);
568 (void)astore(stack, ++sp, str_2static(str));
574 if (s + sizeof(unsigned short) > strend)
577 bcopy(s,(char*)&aushort,sizeof(unsigned short));
578 s += sizeof(unsigned short);
582 if (datumtype == 'n')
583 aushort = ntohs(aushort);
585 str_numset(str,(double)aushort);
586 (void)astore(stack, ++sp, str_2static(str));
591 if (s + sizeof(int) > strend)
594 bcopy(s,(char*)&aint,sizeof(int));
598 str_numset(str,(double)aint);
599 (void)astore(stack, ++sp, str_2static(str));
604 if (s + sizeof(unsigned int) > strend)
607 bcopy(s,(char*)&auint,sizeof(unsigned int));
608 s += sizeof(unsigned int);
611 str_numset(str,(double)auint);
612 (void)astore(stack, ++sp, str_2static(str));
617 if (s + sizeof(long) > strend)
620 bcopy(s,(char*)&along,sizeof(long));
624 str_numset(str,(double)along);
625 (void)astore(stack, ++sp, str_2static(str));
631 if (s + sizeof(unsigned long) > strend)
634 bcopy(s,(char*)&aulong,sizeof(unsigned long));
635 s += sizeof(unsigned long);
639 if (datumtype == 'N')
640 aulong = ntohl(aulong);
642 str_numset(str,(double)aulong);
643 (void)astore(stack, ++sp, str_2static(str));
648 if (s + sizeof(char*) > strend)
651 bcopy(s,(char*)&aptr,sizeof(char*));
657 (void)astore(stack, ++sp, str_2static(str));
666 do_slice(stab,str,numarray,lval,gimme,arglast)
674 register STR **st = stack->ary_array;
675 register int sp = arglast[1];
676 register int max = arglast[2];
679 register int magic = 0;
682 int oldarybase = arybase;
685 if (numarray == 2) { /* a slice of a LIST */
687 ary->ary_fill = arglast[3];
689 st[sp] = str; /* make stack size available */
690 str_numset(str,(double)(sp - 1));
693 ary = stab_array(stab); /* a slice of an array */
699 else if (stab == sigstab)
702 else if (stab_hash(stab)->tbl_dbm)
704 #endif /* SOME_DBM */
706 hash = stab_hash(stab); /* a slice of an associative array */
709 if (gimme == G_ARRAY) {
713 st[sp-1] = afetch(ary,
714 ((int)str_gnum(st[sp])) - arybase, lval);
717 st[sp-1] = &str_undef;
723 tmps = str_get(st[sp]);
724 len = st[sp]->str_cur;
725 st[sp-1] = hfetch(hash,tmps,len, lval);
727 str_magic(st[sp-1],stab,magic,tmps,len);
730 st[sp-1] = &str_undef;
739 ((int)str_gnum(st[max])) - arybase, lval);
745 tmps = str_get(st[max]);
746 len = st[max]->str_cur;
747 st[sp] = hfetch(hash,tmps,len, lval);
749 str_magic(st[sp],stab,magic,tmps,len);
755 arybase = oldarybase;
760 do_splice(ary,str,gimme,arglast)
766 register STR **st = stack->ary_array;
767 register int sp = arglast[1];
768 int max = arglast[2] + 1;
780 offset = ((int)str_gnum(st[sp])) - arybase;
782 offset += ary->ary_fill + 1;
784 length = (int)str_gnum(st[sp++]);
789 length = ary->ary_max; /* close enough to infinity */
793 length = ary->ary_max;
801 if (offset > ary->ary_fill + 1)
802 offset = ary->ary_fill + 1;
803 after = ary->ary_fill + 1 - (offset + length);
804 if (after < 0) { /* not that much array */
805 length += after; /* offset+length now in array */
809 /* At this point, sp .. max-1 is our new LIST */
812 diff = newlen - length;
814 if (diff < 0) { /* shrinking the area */
816 New(451, tmparyval, newlen, STR*); /* so remember insertion */
817 Copy(st+sp, tmparyval, newlen, STR*);
821 if (gimme == G_ARRAY) { /* copy return vals to stack */
822 if (sp + length >= stack->ary_max) {
823 astore(stack,sp + length, Nullstr);
824 st = stack->ary_array;
826 Copy(ary->ary_array+offset, st+sp, length, STR*);
827 if (ary->ary_flags & ARF_REAL) {
828 for (i = length, dst = st+sp; i; i--)
829 str_2static(*dst++); /* free them eventualy */
834 st[sp] = ary->ary_array[offset+length-1];
835 if (ary->ary_flags & ARF_REAL)
838 ary->ary_fill += diff;
840 /* pull up or down? */
842 if (offset < after) { /* easier to pull up */
843 if (offset) { /* esp. if nothing to pull */
844 src = &ary->ary_array[offset-1];
845 dst = src - diff; /* diff is negative */
846 for (i = offset; i > 0; i--) /* can't trust Copy */
849 ary->ary_array -= diff; /* diff is negative */
850 ary->ary_max += diff;
853 if (after) { /* anything to pull down? */
854 src = ary->ary_array + offset + length;
855 dst = src + diff; /* diff is negative */
856 Copy(src, dst, after, STR*);
858 Zero(&ary->ary_array[ary->ary_fill+1], -diff, STR*);
859 /* avoid later double free */
862 for (src = tmparyval, dst = ary->ary_array + offset;
864 *dst = Str_new(46,0);
865 str_sset(*dst++,*src++);
870 else { /* no, expanding (or same) */
872 New(452, tmparyval, length, STR*); /* so remember deletion */
873 Copy(ary->ary_array+offset, tmparyval, length, STR*);
876 if (diff > 0) { /* expanding */
878 /* push up or down? */
880 if (offset < after && diff <= ary->ary_array - ary->ary_alloc) {
882 src = ary->ary_array;
884 Copy(src, dst, offset, STR*);
886 ary->ary_array -= diff; /* diff is positive */
887 ary->ary_max += diff;
888 ary->ary_fill += diff;
891 if (ary->ary_fill + diff >= ary->ary_max) /* oh, well */
892 astore(ary, ary->ary_fill + diff, Nullstr);
894 ary->ary_fill += diff;
896 dst = ary->ary_array + ary->ary_fill;
898 for (i = after; i; i--) {
899 if (*dst) /* str was hanging around */
900 str_free(*dst); /* after $#foo */
908 for (src = st+sp, dst = ary->ary_array + offset; newlen; newlen--) {
909 *dst = Str_new(46,0);
910 str_sset(*dst++,*src++);
913 if (gimme == G_ARRAY) { /* copy return vals to stack */
915 Copy(tmparyval, st+sp, length, STR*);
916 if (ary->ary_flags & ARF_REAL) {
917 for (i = length, dst = st+sp; i; i--)
918 str_2static(*dst++); /* free them eventualy */
925 st[sp] = tmparyval[length-1];
926 if (ary->ary_flags & ARF_REAL)
937 do_grep(arg,str,gimme,arglast)
943 STR **st = stack->ary_array;
944 register int dst = arglast[1];
945 register int src = dst + 1;
946 register int sp = arglast[2];
947 register int i = sp - arglast[1];
948 int oldsave = savestack->ary_fill;
949 SPAT *oldspat = curspat;
951 savesptr(&stab_val(defstab));
952 if ((arg[1].arg_type & A_MASK) != A_EXPR) {
953 arg[1].arg_type &= A_MASK;
955 arg[1].arg_type |= A_DONT;
957 arg = arg[1].arg_ptr.arg_arg;
959 stab_val(defstab) = st[src];
960 (void)eval(arg,G_SCALAR,sp);
961 st = stack->ary_array;
962 if (str_true(st[sp+1]))
967 restorelist(oldsave);
968 if (gimme != G_ARRAY) {
969 str_numset(str,(double)(dst - arglast[1]));
971 st[arglast[0]+1] = str;
974 return arglast[0] + (dst - arglast[1]);
978 do_reverse(str,gimme,arglast)
983 STR **st = stack->ary_array;
984 register STR **up = &st[arglast[1]];
985 register STR **down = &st[arglast[2]];
986 register int i = arglast[2] - arglast[1];
988 if (gimme != G_ARRAY) {
989 str_sset(str,&str_undef);
991 st[arglast[0]+1] = str;
999 i = arglast[2] - arglast[1];
1000 Copy(down+1,up,i/2,STR*);
1001 return arglast[2] - 1;
1004 static CMD *sortcmd;
1005 static STAB *firststab = Nullstab;
1006 static STAB *secondstab = Nullstab;
1009 do_sort(str,stab,gimme,arglast)
1015 STR **st = stack->ary_array;
1016 int sp = arglast[1];
1018 register int max = arglast[2] - sp;
1025 static ARRAY *sortstack = Null(ARRAY*);
1027 if (gimme != G_ARRAY) {
1028 str_sset(str,&str_undef);
1034 for (i = 0; i < max; i++) {
1035 if ((*up = up[1]) && !(*up)->str_pok)
1036 (void)str_2ptr(*up);
1041 if (stab_sub(stab) && (sortcmd = stab_sub(stab)->cmd)) {
1042 int oldtmps_base = tmps_base;
1045 sortstack = anew(Nullstab);
1046 sortstack->ary_flags = 0;
1050 tmps_base = tmps_max;
1052 firststab = stabent("a",TRUE);
1053 secondstab = stabent("b",TRUE);
1055 oldfirst = stab_val(firststab);
1056 oldsecond = stab_val(secondstab);
1058 qsort((char*)(st+sp+1),max,sizeof(STR*),sortsub);
1060 qsort(Nullch,max,sizeof(STR*),sortsub);
1062 stab_val(firststab) = oldfirst;
1063 stab_val(secondstab) = oldsecond;
1064 tmps_base = oldtmps_base;
1069 qsort((char*)(st+sp+1),max,sizeof(STR*),sortcmp);
1072 up = &st[arglast[1]];
1073 while (max > 0 && !*up)
1087 stab_val(firststab) = *str1;
1088 stab_val(secondstab) = *str2;
1089 cmd_exec(sortcmd,G_SCALAR,-1);
1090 return (int)str_gnum(*stack->ary_array);
1093 sortcmp(strp1,strp2)
1097 register STR *str1 = *strp1;
1098 register STR *str2 = *strp2;
1106 if (str1->str_cur < str2->str_cur) {
1107 if (retval = memcmp(str1->str_ptr, str2->str_ptr, str1->str_cur))
1112 else if (retval = memcmp(str1->str_ptr, str2->str_ptr, str2->str_cur))
1114 else if (str1->str_cur == str2->str_cur)
1121 do_range(gimme,arglast)
1125 STR **st = stack->ary_array;
1126 register int sp = arglast[0];
1127 register int i = (int)str_gnum(st[sp+1]);
1128 register ARRAY *ary = stack;
1130 int max = (int)str_gnum(st[sp+2]);
1132 if (gimme != G_ARRAY)
1133 fatal("panic: do_range");
1136 (void)astore(ary, ++sp, str = str_static(&str_no));
1137 str_numset(str,(double)i++);
1143 do_tms(str,gimme,arglast)
1148 STR **st = stack->ary_array;
1149 register int sp = arglast[0];
1151 if (gimme != G_ARRAY) {
1152 str_sset(str,&str_undef);
1157 (void)times(×buf);
1164 (void)astore(stack,++sp,
1165 str_2static(str_nmake(((double)timesbuf.tms_utime)/HZ)));
1166 (void)astore(stack,++sp,
1167 str_2static(str_nmake(((double)timesbuf.tms_stime)/HZ)));
1168 (void)astore(stack,++sp,
1169 str_2static(str_nmake(((double)timesbuf.tms_cutime)/HZ)));
1170 (void)astore(stack,++sp,
1171 str_2static(str_nmake(((double)timesbuf.tms_cstime)/HZ)));
1173 (void)astore(stack,++sp,
1174 str_2static(str_nmake(0.0)));
1180 do_time(str,tmbuf,gimme,arglast)
1186 register ARRAY *ary = stack;
1187 STR **st = ary->ary_array;
1188 register int sp = arglast[0];
1190 if (!tmbuf || gimme != G_ARRAY) {
1191 str_sset(str,&str_undef);
1196 (void)astore(ary,++sp,str_2static(str_nmake((double)tmbuf->tm_sec)));
1197 (void)astore(ary,++sp,str_2static(str_nmake((double)tmbuf->tm_min)));
1198 (void)astore(ary,++sp,str_2static(str_nmake((double)tmbuf->tm_hour)));
1199 (void)astore(ary,++sp,str_2static(str_nmake((double)tmbuf->tm_mday)));
1200 (void)astore(ary,++sp,str_2static(str_nmake((double)tmbuf->tm_mon)));
1201 (void)astore(ary,++sp,str_2static(str_nmake((double)tmbuf->tm_year)));
1202 (void)astore(ary,++sp,str_2static(str_nmake((double)tmbuf->tm_wday)));
1203 (void)astore(ary,++sp,str_2static(str_nmake((double)tmbuf->tm_yday)));
1204 (void)astore(ary,++sp,str_2static(str_nmake((double)tmbuf->tm_isdst)));
1209 do_kv(str,hash,kv,gimme,arglast)
1216 register ARRAY *ary = stack;
1217 STR **st = ary->ary_array;
1218 register int sp = arglast[0];
1220 register HENT *entry;
1223 int dokeys = (kv == O_KEYS || kv == O_HASH);
1224 int dovalues = (kv == O_VALUES || kv == O_HASH);
1226 if (gimme != G_ARRAY) {
1227 str_sset(str,&str_undef);
1232 (void)hiterinit(hash);
1233 while (entry = hiternext(hash)) {
1235 tmps = hiterkey(entry,&i);
1236 (void)astore(ary,++sp,str_2static(str_make(tmps,i)));
1239 tmpstr = Str_new(45,0);
1242 sprintf(buf,"%d%%%d=%d\n",entry->hent_hash,
1243 hash->tbl_max+1,entry->hent_hash & hash->tbl_max);
1244 str_set(tmpstr,buf);
1248 str_sset(tmpstr,hiterval(hash,entry));
1249 (void)astore(ary,++sp,str_2static(tmpstr));
1256 do_each(str,hash,gimme,arglast)
1262 STR **st = stack->ary_array;
1263 register int sp = arglast[0];
1264 static STR *mystrk = Nullstr;
1265 HENT *entry = hiternext(hash);
1275 if (gimme == G_ARRAY) {
1276 tmps = hiterkey(entry, &i);
1277 st[++sp] = mystrk = str_make(tmps,i);
1280 str_sset(str,hiterval(hash,entry));