diff --git a/log/src/logdef.h b/log/src/logdef.h index 7e3f49cb832a7fd22cddd92d08c3cf11e502f64e..fd0c4e9a47be43b9d258ff7d03ec00485a4f40d0 100644 --- a/log/src/logdef.h +++ b/log/src/logdef.h @@ -3,6 +3,7 @@ #include <p2c/mylib.h> +#include <p2c/strlist.h> #include <p2c/newasm.h> #ifdef LOGDEF_G diff --git a/psys/include/p2c/newasm.h b/psys/include/p2c/newasm.h index 6cc1ffea4e1bd961843bdb27d19b2fe4322496cc..a8ff043292cdd65ea43e54b198c4ed3da3aab3ba 100644 --- a/psys/include/p2c/newasm.h +++ b/psys/include/p2c/newasm.h @@ -152,14 +152,6 @@ typedef union na_quadword { typedef na_quadword na_quadwordarray[]; -typedef struct na_strlist_t { - struct na_strlist_t *next; - na_long value; /* user-defined */ - char kind; /* user-defined */ - char len; /* for internal use */ - char s[256]; /* not entirely allocated */ -} na_strlist_t; - extern void* *P_nil2; @@ -284,27 +276,10 @@ extern void na_compint (na_long a, na_long b, long *res); extern void na_compstr (na_long a, na_long b, long *res); extern void na_qsort (na_long *a, long n, _PROCEDURE comp); -extern void strlist_init (na_strlist_t **base); -extern na_strlist_t *strlist_find (na_strlist_t *base, char *s); -extern na_strlist_t *strlist_cifind (na_strlist_t *base, char *s); -extern void strlist_change (na_strlist_t **base, na_strlist_t **ptr, - char *s); -extern void strlist_remove (na_strlist_t **base, char *s); -extern void strlist_delete (na_strlist_t **base, na_strlist_t *ptr); -extern void strlist_dispose (na_strlist_t **ptr); -extern void strlist_empty (na_strlist_t **base); -extern void strlist_copy (na_strlist_t **dest, na_strlist_t *src); - extern void na_bfand (long *s, long soff, long *d, long doff, long size); extern void na_bfbic (long *s, long soff, long *d, long doff, long size); extern void na_bfor (long *s, long soff, long *d, long doff, long size); extern void na_bfxor (long *s, long soff, long *d, long doff, long size); -extern char *strnew (char *s); -extern na_strlist_t *strlist_add (na_strlist_t **base, char *s); -extern na_strlist_t *strlist_append (na_strlist_t **base, char *s); -extern na_strlist_t *strlist_insert (na_strlist_t **base, char *s); - -extern void strlist_dump (FILE *f, na_strlist_t *base); #endif /*NEWASM_H*/ diff --git a/psys/include/p2c/numex.h b/psys/include/p2c/numex.h index b9cc0ceb8fe1f3d2ed31719f51989ce07e8d23fd..19562589bd100844e2e4e4d7406544b91fe554a4 100644 --- a/psys/include/p2c/numex.h +++ b/psys/include/p2c/numex.h @@ -2,6 +2,7 @@ #define NUMEX_H +#include <p2c/strlist.h> #include <p2c/newasm.h> #ifdef NUMEX_G diff --git a/psys/include/p2c/strlist.h b/psys/include/p2c/strlist.h new file mode 100644 index 0000000000000000000000000000000000000000..b1d18a69ef808f1223e298698cefcbc2cc890992 --- /dev/null +++ b/psys/include/p2c/strlist.h @@ -0,0 +1,31 @@ +#ifndef STRLIST_H +#define STRLIST_H + +typedef struct na_strlist_t +{ + struct na_strlist_t *next; + void * value; /* user-defined */ + char kind; /* user-defined */ + char len; /* for internal use */ + char s[256]; /* not entirely allocated */ +} na_strlist_t; + + +extern void strlist_init (na_strlist_t **base); +extern na_strlist_t *strlist_find (na_strlist_t *base, char *s); +extern na_strlist_t *strlist_cifind (na_strlist_t *base, char *s); +extern void strlist_change (na_strlist_t **base, na_strlist_t **ptr, char *s); +extern void strlist_remove (na_strlist_t **base, char *s); +extern void strlist_delete (na_strlist_t **base, na_strlist_t *ptr); +extern void strlist_dispose (na_strlist_t **ptr); +extern void strlist_empty (na_strlist_t **base); +extern void strlist_copy (na_strlist_t **dest, na_strlist_t *src); +extern na_strlist_t *strlist_add (na_strlist_t **base, char *s); +extern na_strlist_t *strlist_append (na_strlist_t **base, char *s); +extern na_strlist_t *strlist_insert (na_strlist_t **base, char *s); + +extern void strlist_dump (FILE *f, na_strlist_t *base); + + +#endif + diff --git a/psys/src/Makefile b/psys/src/Makefile index ccbc472ee9f7eb79499d7e92b2de123bfe86683a..9e1e126d6d746bf51368a174ce03c305a6e6a0e2 100644 --- a/psys/src/Makefile +++ b/psys/src/Makefile @@ -106,7 +106,8 @@ OBJS = sysdevs.o \ hpib_2.o \ mylib.o \ newkbd.o \ - strings.o \ + strings.o \ + strlist.o \ newasmlib.o \ newcrt.o \ math.o \ diff --git a/psys/src/newasmlib.c b/psys/src/newasmlib.c index 4c389a846ac5f505de493ab592366a555e5a55c7..05addee0540c74eca84fa9d5ee1efeaba6349a1a 100644 --- a/psys/src/newasmlib.c +++ b/psys/src/newasmlib.c @@ -1139,202 +1139,6 @@ void na_qsort(na_long *a, long n, _PROCEDURE comp) qsort(a, n, 4, (int (*)())qsortfunc); } - } - -/* Variable-length string allocation */ -static void outmem() -{ - fprintf(stderr, "Memory full!\n"); - exit(1); -} - - -#ifdef LACKS_STRDUP -char *strdup(char *s) -{ - char *sp; - int len = strlen(s); - - sp = (char *)malloc(len + 1); - if (!sp) outmem(); - strcpy(sp, s); - return sp; -} -#endif - - -/* String lists */ -void strlist_init(na_strlist_t **base) -{ - *base = NULL; -} - - -na_strlist_t *strlist_add(na_strlist_t **base, char *s) -{ - register na_strlist_t *lp; - register int len = strlen(s); - - while ((lp = *base) && strcmp(lp->s, s) < 0) - base = &lp->next; - if (!lp || strcmp(lp->s, s)) { - lp = (na_strlist_t *)malloc(sizeof(na_strlist_t) - 255 + len); - if (!lp) outmem(); - lp->next = *base; - *base = lp; - strcpy(lp->s, s); - lp->len = len; - } - lp->value = (na_long)0; - lp->kind = 0; - return lp; -} - - - -na_strlist_t *strlist_append(na_strlist_t **base, char *s) -{ - register na_strlist_t *lp; - register int len = strlen(s); - - while ((lp = *base)) - base = &lp->next; - lp = (na_strlist_t *)malloc(sizeof(na_strlist_t) - 255 + len); - if (!lp) outmem(); - lp->next = NULL; - *base = lp; - strcpy(lp->s, s); - lp->len = len; - lp->value = (na_long)0; - lp->kind = 0; - return lp; -} - - - -na_strlist_t *strlist_insert(na_strlist_t **base, char *s) -{ - register na_strlist_t *lp; - register int len = strlen(s); - - lp = (na_strlist_t *)malloc(sizeof(na_strlist_t) - 255 + len); - if (!lp) outmem(); - lp->next = *base; - *base = lp; - strcpy(lp->s, s); - lp->len = len; - lp->value = (na_long)0; - lp->kind = 0; - return lp; -} - -na_strlist_t *strlist_find(na_strlist_t *base, char *s) -{ - while (base && strcmp(base->s, s)) - base = base->next; - return base; -} - -na_strlist_t *strlist_cifind(na_strlist_t *base, char *s) -{ - while (base && strcicmp(base->s, s)) - base = base->next; - return base; -} - -void strlist_change(na_strlist_t **base, na_strlist_t **lp, char *s) -{ - register na_strlist_t *lp2 = *lp, *lp3; - register int len = strlen(s); - - while ((lp3 = *base) != lp2) { - if (lp3) - base = &lp3->next; - else - return; /* wasn't in the list */ - } - if (len > lp3->len) { /* must reallocate */ - lp3 = (na_strlist_t *)realloc(lp3, sizeof(na_strlist_t) - 255 + len); - if (!lp3) outmem(); - lp3->len = len; - *lp = lp3; - lp3->next = *base; - *base = lp3; - } - strcpy(lp3->s, s); -} - - -void strlist_remove(na_strlist_t **base, char *s) -{ - register na_strlist_t *lp; - - while ((lp = *base)) { - if (!strcmp(lp->s, s)) { - *base = lp->next; - free(lp); - return; - } - base = &lp->next; - } -} - - -void strlist_delete(na_strlist_t **base, na_strlist_t *lp) -{ - register na_strlist_t *lp2; - - while ((lp2 = *base)) { - if (lp2 == lp) { - *base = lp->next; - free(lp); - return; - } - base = &lp2->next; - } -} - - -void strlist_dispose(na_strlist_t **ptr) -{ - free(*ptr); - *ptr = NULL; -} - - -void strlist_empty(na_strlist_t **base) -{ - register na_strlist_t *lp; - - while ((lp = *base)) { - *base = lp->next; - free(lp); - } -} - -void strlist_copy(na_strlist_t **dest, na_strlist_t *src) -{ - register na_strlist_t *lp; - - while (src) { - lp = (na_strlist_t *)malloc(sizeof(na_strlist_t) - 255 + src->len); - lp->len = src->len; - lp->kind = src->kind; - lp->value = src->value; - strcpy(lp->s, src->s); - *dest = lp; - dest = &lp->next; - src = src->next; /* Change made by rhkoshi without much thought */ - } - *dest = NULL; -} - -void strlist_dump(FILE *f, na_strlist_t *base) -{ - while (base) { - fprintf(f, "\"%s\" %d, %ld\n", base->s, base->kind, (long)base->value); - base = base->next; - } } diff --git a/psys/src/strlist.c b/psys/src/strlist.c new file mode 100644 index 0000000000000000000000000000000000000000..91db1c9cbbae0d74708186b29923a7f732c179f1 --- /dev/null +++ b/psys/src/strlist.c @@ -0,0 +1,190 @@ +#include <p2c/p2c.h> +#include <p2c/strlist.h> + +void strlist_init(na_strlist_t **base) +{ + *base = NULL; +} + +na_strlist_t *strlist_add(na_strlist_t **base, char *s) +{ + na_strlist_t *lp; + int len = strlen(s); + + while ((lp = *base) && strcmp(lp->s, s) < 0) + base = &lp->next; + + if (!lp || strcmp(lp->s, s)) + { + lp = (na_strlist_t *)malloc(sizeof(na_strlist_t) - 255 + len); + if (!lp) + _OutMem(); + lp->next = *base; + *base = lp; + strcpy(lp->s, s); + lp->len = len; + } + + lp->value = (void *)0; + lp->kind = 0; + return lp; +} + +na_strlist_t *strlist_append(na_strlist_t **base, char *s) +{ + na_strlist_t *lp; + int len = strlen(s); + + while ((lp = *base)) + base = &lp->next; + + lp = (na_strlist_t *)malloc(sizeof(na_strlist_t) - 255 + len); + if (!lp) + _OutMem(); + + lp->next = NULL; + *base = lp; + strcpy(lp->s, s); + lp->len = len; + lp->value = (void *)0; + lp->kind = 0; + return lp; +} + +na_strlist_t *strlist_insert(na_strlist_t **base, char *s) +{ + na_strlist_t *lp; + int len = strlen(s); + + lp = (na_strlist_t *)malloc(sizeof(na_strlist_t) - 255 + len); + if (!lp) + _OutMem(); + + lp->next = *base; + *base = lp; + strcpy(lp->s, s); + lp->len = len; + lp->value = (void *)0; + lp->kind = 0; + return lp; +} + +na_strlist_t *strlist_find(na_strlist_t *base, char *s) +{ + while (base && strcmp(base->s, s)) + base = base->next; + return base; +} + +na_strlist_t *strlist_cifind(na_strlist_t *base, char *s) +{ + while (base && strcicmp(base->s, s)) + base = base->next; + return base; +} + +void strlist_change(na_strlist_t **base, na_strlist_t **lp, char *s) +{ + na_strlist_t *lp2 = *lp, *lp3; + int len = strlen(s); + + while ((lp3 = *base) != lp2) + { + if (lp3) + base = &lp3->next; + else + return; /* wasn't in the list */ + } + + /* must reallocate */ + if (len > lp3->len) + { + lp3 = (na_strlist_t *)realloc(lp3, sizeof(na_strlist_t) - 255 + len); + if (!lp3) + _OutMem(); + + lp3->len = len; + *lp = lp3; + lp3->next = *base; + *base = lp3; + } + + strcpy(lp3->s, s); +} + +void strlist_remove(na_strlist_t **base, char *s) +{ + na_strlist_t *lp; + + while ((lp = *base)) + { + if (!strcmp(lp->s, s)) + { + *base = lp->next; + free(lp); + return; + } + base = &lp->next; + } +} + +void strlist_delete(na_strlist_t **base, na_strlist_t *lp) +{ + na_strlist_t *lp2; + + while ((lp2 = *base)) + { + if (lp2 == lp) + { + *base = lp->next; + free(lp); + return; + } + base = &lp2->next; + } +} + +void strlist_dispose(na_strlist_t **ptr) +{ + free(*ptr); + *ptr = NULL; +} + +void strlist_empty(na_strlist_t **base) +{ + na_strlist_t *lp; + + while ((lp = *base)) + { + *base = lp->next; + free(lp); + } +} + +void strlist_copy(na_strlist_t **dest, na_strlist_t *src) +{ + na_strlist_t *lp; + + while (src != NULL) + { + lp = (na_strlist_t *)malloc(sizeof(na_strlist_t) - 255 + src->len); + lp->len = src->len; + lp->kind = src->kind; + lp->value = src->value; + strcpy(lp->s, src->s); + *dest = lp; + dest = &lp->next; + src = src->next; /* Change made by rhkoshi without much thought */ + } + *dest = NULL; +} + +void strlist_dump(FILE *f, na_strlist_t *base) +{ + while (base) + { + fprintf(f, "\"%s\" %d, %ld\n", base->s, base->kind, (long)base->value); + base = base->next; + } +} +