STATIC int unalias(char *name) { struct alias *ap, **app; app = hashalias(name); for (ap = *app; ap; app = &(ap->next), ap = ap->next) { if (equal(name, ap->name)) { /* * if the alias is currently in use (i.e. its * buffer is being used by the input routine) we * just null out the name instead of freeing it. * We could clear it out later, but this situation * is so rare that it hardly seems worth it. */ if (ap->flag & ALIASINUSE) *ap->name = '\0'; else { INTOFF; *app = ap->next; ckfree(ap->name); ckfree(ap->val); ckfree(ap); INTON; } return (0); } } return (1); }
static void setalias(const char *name, const char *val) { struct alias *ap, **app; app = hashalias(name); for (ap = *app; ap; ap = ap->next) { if (equal(name, ap->name)) { INTOFF; ckfree(ap->val); ap->val = savestr(val); INTON; return; } } /* not found */ INTOFF; ap = ckmalloc(sizeof (struct alias)); ap->name = savestr(name); ap->val = savestr(val); ap->flag = 0; ap->next = *app; *app = ap; aliases++; INTON; }
static void setalias(const char *name, const char *val) { struct alias *ap, **app; app = hashalias(name); for (ap = *app; ap; ap = ap->next) { if (equal(name, ap->name)) { INTOFF; ckfree(ap->val); ap->val = savestr(val); INTON; return; } } /* not found */ INTOFF; ap = ckmalloc(sizeof (struct alias)); ap->name = savestr(name); /* * XXX - HACK: in order that the parser will not finish reading the * alias value off the input before processing the next alias, we * dummy up an extra space at the end of the alias. This is a crock * and should be re-thought. The idea (if you feel inclined to help) * is to avoid alias recursions. The mechanism used is: when * expanding an alias, the value of the alias is pushed back on the * input as a string and a pointer to the alias is stored with the * string. The alias is marked as being in use. When the input * routine finishes reading the string, it marks the alias not * in use. The problem is synchronization with the parser. Since * it reads ahead, the alias is marked not in use before the * resulting token(s) is next checked for further alias sub. The * H A C K is that we add a little fluff after the alias value * so that the string will not be exhausted. This is a good * idea ------- ***NOT*** */ #ifdef notyet ap->val = savestr(val); #else /* hack */ { size_t len = strlen(val); ap->val = ckmalloc(len + 2); memcpy(ap->val, val, len); ap->val[len] = ' '; /* fluff */ ap->val[len+1] = '\0'; } #endif ap->flag = 0; ap->next = *app; *app = ap; aliases++; INTON; }
struct alias * lookupalias(char *name, int check) { struct alias *ap = *hashalias(name); for (; ap; ap = ap->next) { if (equal(name, ap->name)) { if (check && (ap->flag & ALIASINUSE)) return (NULL); return (ap); } } return (NULL); }
struct alias * lookupalias(const char *name, int check) { struct alias *ap = *hashalias(name); while (ap != NULL) { if (equal(name, ap->name)) { if (check && (ap->flag & ALIASINUSE)) return NULL; return ap; } ap = ap->next; } return NULL; }
STATIC int unalias(char *name) { struct alias *ap, **app; app = hashalias(name); while ((ap = *app) != NULL) { if (equal(name, ap->name)) { (void) freealias(app, 0); return 0; } app = &ap->next; } return 1; }
STATIC void setalias(char *name, char *val) { struct alias *ap, **app; (void) unalias(name); /* old one (if any) is now gone */ app = hashalias(name); INTOFF; ap = ckmalloc(sizeof (struct alias)); ap->name = savestr(name); ap->flag = 0; ap->val = savestr(val); ap->next = *app; *app = ap; INTON; }