diff options
Diffstat (limited to 'Source/DOH')
-rw-r--r-- | Source/DOH/doh.h | 7 | ||||
-rw-r--r-- | Source/DOH/hash.c | 12 | ||||
-rw-r--r-- | Source/DOH/string.c | 42 |
3 files changed, 49 insertions, 12 deletions
diff --git a/Source/DOH/doh.h b/Source/DOH/doh.h index 6b4e457c8..69e1386a2 100644 --- a/Source/DOH/doh.h +++ b/Source/DOH/doh.h @@ -71,6 +71,7 @@ #define DohStringGetc DOH_NAMESPACE(StringGetc) #define DohStringUngetc DOH_NAMESPACE(StringUngetc) #define DohStringAppend DOH_NAMESPACE(StringAppend) +#define DohStringLen DOH_NAMESPACE(StringLen) #define DohStringEqual DOH_NAMESPACE(StringEqual) @@ -108,6 +109,7 @@ #define DohCopyto DOH_NAMESPACE(Copyto) #define DohNewList DOH_NAMESPACE(NewList) #define DohNewHash DOH_NAMESPACE(NewHash) +#define DohHashGetAttr DOH_NAMESPACE(HashGetAttr) #define DohHashCheckAttr DOH_NAMESPACE(HashCheckAttr) #define DohNewVoid DOH_NAMESPACE(NewVoid) #define DohSplit DOH_NAMESPACE(Split) @@ -252,12 +254,14 @@ extern int DohString_putc(DOH *so, int ch); extern int DohString_getc(DOH *so); extern int DohString_ungetc(DOH *so, int ch); extern void DohString_append(DOH *so, DOH *str); +extern int DohString_len(DOH *s1); extern int DohString_equal(DOH *s1, DOH *s2); #define DohStringPutc(ch,so) DohString_putc(so, ch) #define DohStringGetc(so) DohString_getc(so) #define DohStringUngetc(ch,so) DohString_ungetc(so, ch) #define DohStringAppend(so,str) DohString_append(so, str) +#define DohStringLen(so) DohString_len(so) #define DohStringEqual(s1,s2) DohString_equal(s1,s2) /* Meta-variables */ @@ -332,6 +336,7 @@ extern void DohSortList(DOH *lo, int (*cmp)(const DOH *, const DOH *)); * ----------------------------------------------------------------------------- */ extern DOHHash *DohNewHash(); +extern DOH *DohHashGetAttr(DOH *hash, DOH *key); extern int DohHashCheckAttr(DOH *hash, DOH *key, DOH *value); /* ----------------------------------------------------------------------------- @@ -388,6 +393,7 @@ extern void DohMemoryDebug(void); #define StringGetc DohStringGetc #define StringUngetc DohStringUngetc #define StringAppend DohStringAppend +#define StringLen DohStringLen #define StringEqual DohStringEqual #define Close DohClose @@ -416,6 +422,7 @@ extern void DohMemoryDebug(void); #define NewStringWithSize DohNewStringWithSize #define NewStringf DohNewStringf #define NewHash DohNewHash +#define HashGetAttr DohHashGetAttr #define HashCheckAttr DohHashCheckAttr #define NewList DohNewList #define NewFile DohNewFile diff --git a/Source/DOH/hash.c b/Source/DOH/hash.c index 56f0959a8..e91e1cc23 100644 --- a/Source/DOH/hash.c +++ b/Source/DOH/hash.c @@ -276,11 +276,19 @@ Hash_getattr(DOH *h, DOH *k) { return obj; } +DOH * +DohHashGetAttr(DOH *h, DOH *k) { + DOH *obj = 0; + Hash *ho = (Hash *) ObjData(h); + _Hash_getattr(ho, k, obj); + return obj; +} + /* ----------------------------------------------------------------------------- - * Hash_checkattr() + * HashCheckAttr() * - * Get an attribute from the hash table. Returns 0 if it doesn't exist. + * Check an attribute from the hash table. * ----------------------------------------------------------------------------- */ int diff --git a/Source/DOH/string.c b/Source/DOH/string.c index f37af39ee..adf66e530 100644 --- a/Source/DOH/string.c +++ b/Source/DOH/string.c @@ -65,7 +65,7 @@ CopyString(DOH *so) { String *str; String *s = (String *) ObjData(so); str = (String *) DohMalloc(sizeof(String)); - str->hashkey = -1; + str->hashkey = s->hashkey; str->sp = s->sp; str->line = s->line; str->file = s->file; @@ -87,18 +87,16 @@ CopyString(DOH *so) { static void DelString(DOH *so) { String *s = (String *) ObjData(so); - s->hashkey = -1; DohFree(s->str); - s->str = 0; DohFree(s); } /* ----------------------------------------------------------------------------- - * String_len() - Length of a string + * DohString_len() - Length of a string * ----------------------------------------------------------------------------- */ -static int -String_len(DOH *so) { +int +DohString_len(DOH *so) { String *s = (String *) ObjData(so); return s->len; } @@ -237,6 +235,7 @@ DohString_append(DOH *so, DOH *str) { s->len += l; } + /* ----------------------------------------------------------------------------- * void String_clear() - Clear a string * ----------------------------------------------------------------------------- */ @@ -269,17 +268,23 @@ String_insert(DOH *so, int pos, DOH *str) return 0; } + s = (String *) ObjData(so); s->hashkey = -1; - data = (char *) DohData(str); + if (DohCheck(str)) { + String *ss = (String *) ObjData(str); + data = String_data(str); + len = ss->len; + } else { + data = (char *) (str); + len = (int) strlen(data); + } nstr = s->str; - if (pos < 0) pos = 0; else if (pos > s->len) pos = s->len; /* See if there is room to insert the new data */ - len = Len(str); while (s->maxsize <= s->len+len) { s->str = (char *) DohRealloc(s->str,2*s->maxsize); assert(s->str); @@ -440,6 +445,7 @@ String_seek(DOH *so, long offset, int whence) inc = (nsp > s->sp) ? 1 : -1; { +#if 0 register int sp = s->sp; register char *tc = s->str; register int len = s->len; @@ -449,6 +455,22 @@ String_seek(DOH *so, long offset, int whence) s->line += inc; sp+=inc; } +#else + register int sp = s->sp; + register char *tc = s->str; + register int len = s->len; + if (inc > 0) { + while (sp != nsp) { + if (tc[++sp] == '\n') + ++s->line; + } + } else { + while (sp != nsp) { + if (tc[--sp] == '\n') + --s->line; + } + } +#endif s->sp = sp; } assert (s->sp >= 0); @@ -955,7 +977,7 @@ DohObjInfo DohStringType = { String_str, /* doh_str */ String_data, /* doh_data */ String_dump, /* doh_dump */ - String_len, /* doh_len */ + DohString_len, /* doh_len */ String_hash, /* doh_hash */ String_cmp, /* doh_cmp */ DohString_equal, /* doh_equal */ |