diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2013-03-05 09:16:29 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2013-03-05 09:16:29 +0200 |
commit | f142ee94c2fa3d5f8ec3686b2ced2e1f0b807def (patch) | |
tree | 6a150aea4679db77420db91c26e6a93865abbe65 /slist.c | |
parent | a75760ff7d9bedcb1377fc3441f5e38178da1d6a (diff) | |
download | alck-f142ee94c2fa3d5f8ec3686b2ced2e1f0b807def.tar.gz alck-f142ee94c2fa3d5f8ec3686b2ced2e1f0b807def.tar.bz2 |
Revamp as a standalone project. Remove unneeded dependencies.
* Makefile.am: Remove
* Makefile: Restore from bc518485
* ckaliases.c: Rename to alck.c
* ckaliases.h: Rename to alck.h
* gram.y (emalloc, error)
(syserror, parserror): New functions.
(main): Use traditional getopt.
* lex.l: Use slist instead of obstack.
* slist.c: New file.
Diffstat (limited to 'slist.c')
-rw-r--r-- | slist.c | 97 |
1 files changed, 97 insertions, 0 deletions
@@ -0,0 +1,97 @@ +/* ckaliases - verify syntax of sendmail-style alias files + Copyright (C) 2005, 2007, 2013 Sergey Poznyakoff + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 3 of the License, or (at your + option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#include "alck.h" + +char * +slist_add_n(SLIST **plist, char *str, size_t n) +{ + struct string_list *p = emalloc(sizeof(*p)); + p->str = emalloc(n); + memcpy(p->str, str, n); + p->len = n; + p->next = NULL; + + if (!*plist) { + *plist = emalloc(sizeof(**plist)); + (*plist)->head = NULL; + } + + if ((*plist)->head == NULL) { + (*plist)->head = p; + (*plist)->count = 0; + } else { + (*plist)->tail->next = p; + (*plist)->count++; + } + (*plist)->tail = p; + return p->str; +} + +char * +slist_add(SLIST **plist, char *str) +{ + return slist_add_n(plist, str, strlen(str) + 1); +} + +void +slist_append(SLIST **pdst, SLIST *src) +{ + struct string_list *tail; + + if (!*pdst) { + *pdst = emalloc(sizeof(**pdst)); + (*pdst)->head = NULL; + (*pdst)->count = 0; + } + + if ((*pdst)->head = NULL) + (*pdst)->head = src->head; + + for (tail = src->tail; tail->next; tail = tail->next) + ; + + (*pdst)->tail = tail; + (*pdst)->count += src->count; +} + +char * +slist_member(SLIST *plist, char *name) +{ + struct string_list *p; + + if (plist) + for (p = plist->head; p; p = p->next) + if (p->str && strcmp(p->str, name) == 0) + return p->str; + return NULL; +} + +void +slist_destroy(SLIST **plist) +{ + struct string_list *p; + if (!plist || !*plist) + return; + p = (*plist)->head; + while (p) { + struct string_list *next = p->next; + free(p); + p = next; + } + free(*plist); + *plist = NULL; +} |