|
|
1.1 ! root 1: #include <stdio.h> ! 2: #include <string.h> ! 3: #include <time.h> ! 4: #include "lib.h" ! 5: ! 6: void ! 7: addsub(struct sub **sublistp, char *ostr, char *nstr) ! 8: { ! 9: struct sub *nsub; ! 10: ! 11: nsub = xmalloc(sizeof (struct sub)); ! 12: nsub->ostr = xstrdup(ostr); ! 13: nsub->nstr = xstrdup(nstr); ! 14: nsub->next = *sublistp; ! 15: *sublistp = nsub; ! 16: } ! 17: ! 18: int ! 19: sub(struct sub **sublistp, int prefix, char str[], int maxlen) ! 20: { ! 21: struct sub *sub; ! 22: int olen, nlen; ! 23: ! 24: for (sub = *sublistp; sub; sub = sub->next) { ! 25: olen = strlen(sub->ostr); ! 26: if (prefix && strncmp(str, sub->ostr, olen) == 0) ! 27: break; ! 28: else if (!prefix && strcmp(str, sub->ostr)) ! 29: break; ! 30: } ! 31: if (!sub) ! 32: return 1; ! 33: nlen = strlen(sub->nstr); ! 34: if (strlen(str) + nlen - olen > maxlen) ! 35: return 0; ! 36: memmove(str + nlen, str + olen, strlen(str + olen) + 1); ! 37: strncpy(str, sub->nstr, nlen); ! 38: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.