|
|
1.1 root 1: /* Copyright 1989 by AT&T Bell Laboratories */
2: #include "tags.h"
3: #include "descriptor.h"
4:
5: /* NOTE: all these functions use c_alloc, and modify saved_dataptr. */
6:
7: extern int saved_dataptr;
8:
9: int *c_alloc(siz) int siz;
10: {int *s=(int *)saved_dataptr;
11: saved_dataptr+= 4*siz;
12: return s;
13: }
14:
15: /* Make a C string into an ML string. Used by restartFn (through
16: mak_str_lst()).
17: */
18: mak_str(s)
19: char *s;
20: {int len = strlen(s);
21: if (len == 1) return(mak_int(*(char *)s));
22: else {int i = (len+3)>>2;
23: int *p = 1 + c_alloc(i+1);
24: p[i-1] = 0; /* allocate */
25: p[-1] = (len<<width_tags) + tag_string;
26: strncpy(p,s,len);
27: return((int)p);
28: }
29: }
30:
31: /* Make an ML string into a C string */
32: char *
33: get_str(x)
34: int x;
35: {
36: if (is_ptr(x)) return((char *)x);
37: else {char *s = (char *)c_alloc(1); *(int *)s = 0; *s = x; return s;}
38: }
39:
40: /* No good for strings/bytearrays (allocates by word, not byte).
41: Also a dangerous, as the last word should be allocated first for
42: garbage collector safety. Only used in bootup (run.c) and restartFn
43: (through mak_str_lst()). */
44: mak_obj(l,t)
45: int l,t;
46: {int *p = 1 + c_alloc(l+1);
47: p[-1] = mak_desc(l,t);
48: return((int)p);
49: }
50:
51: /* Take a vector of strings (like argv) and turn it into an ML string list.
52: Uses mak_obj, so it is unsafe and should be used with caution. Only
53: restartFn uses it for now. */
54: int *
55: mak_str_lst(sl)
56: char **sl;
57: {
58: int *list;
59: if (!(*sl)) return ((int *)ML_NIL);
60: list = (int *)mak_obj(2,tag_record);
61: list[1] = (int)mak_str_lst(sl+1);
62: list[0] = mak_str(*sl);
63: return list;
64: }
65:
66: ml_eqstr(a,b) int *a, *b;
67: {int alen=a[-1]>>4, blen = b[-1]>>4; int i;
68: if (alen != blen) return 0;
69: for(i=0; i*4<alen; i++) if (a[i]!=b[i]) return 0;
70: return 1;
71: }
72:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.