diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2013-01-01 13:25:55 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2013-01-01 13:33:04 +0200 |
commit | 24e6dfa7cffceea0cac0f3cc349192788f040939 (patch) | |
tree | c2bd53e9bc58873c8187e6bd622ae152b35d1d51 /src/builtin.c | |
parent | 2bdd70d698c63d32f25b4f1142e09f5eaef4812a (diff) | |
download | wydawca-24e6dfa7cffceea0cac0f3cc349192788f040939.tar.gz wydawca-24e6dfa7cffceea0cac0f3cc349192788f040939.tar.bz2 |
Update copyright years. Switch to a familiar style.
Diffstat (limited to 'src/builtin.c')
-rw-r--r-- | src/builtin.c | 337 |
1 files changed, 162 insertions, 175 deletions
diff --git a/src/builtin.c b/src/builtin.c index f031897..72b73cd 100644 --- a/src/builtin.c +++ b/src/builtin.c @@ -1,5 +1,5 @@ /* wydawca - automatic release submission daemon - Copyright (C) 2009-2011 Sergey Poznyakoff + Copyright (C) 2009-2013 Sergey Poznyakoff Wydawca is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the @@ -22,21 +22,21 @@ #endif int -builtin_init (struct dictionary *dict) +builtin_init(struct dictionary *dict) { - return 0; + return 0; } int -builtin_done (struct dictionary *dict) +builtin_done(struct dictionary *dict) { - return 0; + return 0; } void * -builtin_open (struct dictionary *dict) +builtin_open(struct dictionary *dict) { - return dict; + return dict; } #define CMP_EXACT 0 @@ -52,216 +52,203 @@ builtin_open (struct dictionary *dict) typedef int (*strcmp_fn) (const char *, const char *, int flags); static int -cmp_exact (const char *pat, const char *str, int flags) +cmp_exact(const char *pat, const char *str, int flags) { - return strcmp (pat, str) == 0; + return strcmp(pat, str) == 0; } static int -cmp_exact_ci (const char *pat, const char *str, int flags) +cmp_exact_ci(const char *pat, const char *str, int flags) { - return strcmp (pat, str) == 0; + return strcmp(pat, str) == 0; } static int -cmp_fnmatch (const char *pat, const char *str, int flags) +cmp_fnmatch(const char *pat, const char *str, int flags) { - return fnmatch (pat, str, flags) == 0; + return fnmatch(pat, str, flags) == 0; } static int -cmp_regex (const char *pat, const char *str, int flags) +cmp_regex(const char *pat, const char *str, int flags) { - int rc; - regex_t regex; - - rc = regcomp (®ex, pat, flags); - if (rc) - { - char errbuf[512]; - - regerror (rc, ®ex, errbuf, sizeof (errbuf)); - logmsg (LOG_ERR, _("%s: cannot compile regexp: %s"), pat, errbuf); - return 0; - } - - rc = regexec (®ex, str, 0, NULL, 0); - regfree (®ex); - return rc == 0; + int rc; + regex_t regex; + + rc = regcomp(®ex, pat, flags); + if (rc) { + char errbuf[512]; + + regerror(rc, ®ex, errbuf, sizeof(errbuf)); + logmsg(LOG_ERR, _("%s: cannot compile regexp: %s"), pat, + errbuf); + return 0; + } + + rc = regexec(®ex, str, 0, NULL, 0); + regfree(®ex); + return rc == 0; } int -parse_cmp_type (const char *pat, strcmp_fn *cmpfn, int *rf) +parse_cmp_type(const char *pat, strcmp_fn * cmpfn, int *rf) { - size_t len = strcspn (pat, ","); - int flags = 0; - int cmp; - - if (STRMATCH ("exact", pat, len)) - cmp = CMP_EXACT; - else if (STRMATCH ("fnmatch", pat, len)) - cmp = CMP_FNMATCH; - else if (STRMATCH ("regex", pat, len)) - cmp = CMP_REGEX; - else - return 1; - - pat += len; - if (*pat) - { - while (*++pat) - { - switch (*pat) - { - case 'i': - flags |= RF_ICASE; - break; - - case 'b': - flags |= RF_BASIC; - break; - - default: - logmsg (LOG_NOTICE, _("unrecognized comparison flag: %c"), *pat); - } + size_t len = strcspn(pat, ","); + int flags = 0; + int cmp; + + if (STRMATCH("exact", pat, len)) + cmp = CMP_EXACT; + else if (STRMATCH("fnmatch", pat, len)) + cmp = CMP_FNMATCH; + else if (STRMATCH("regex", pat, len)) + cmp = CMP_REGEX; + else + return 1; + + pat += len; + if (*pat) { + while (*++pat) { + switch (*pat) { + case 'i': + flags |= RF_ICASE; + break; + + case 'b': + flags |= RF_BASIC; + break; + + default: + logmsg(LOG_NOTICE, + _("unrecognized comparison flag: %c"), + *pat); + } + } + } + + switch (cmp) { + case CMP_EXACT: + *cmpfn = (flags & RF_ICASE) ? cmp_exact_ci : cmp_exact; + break; + + case CMP_FNMATCH: + *cmpfn = cmp_fnmatch; + *rf = FNM_NOESCAPE | FNM_PERIOD | + ((flags & RF_ICASE) ? FNM_CASEFOLD : 0); + break; + + case CMP_REGEX: + *cmpfn = cmp_regex; + *rf = ((flags & RF_BASIC) ? 0 : REG_EXTENDED) | REG_NOSUB; + if (flags & RF_ICASE) + *rf |= REG_ICASE; + break; } - } - - switch (cmp) - { - case CMP_EXACT: - *cmpfn = (flags & RF_ICASE) ? cmp_exact_ci : cmp_exact; - break; - - case CMP_FNMATCH: - *cmpfn = cmp_fnmatch; - *rf = FNM_NOESCAPE | FNM_PERIOD | - ((flags & RF_ICASE) ? FNM_CASEFOLD : 0); - break; - - case CMP_REGEX: - *cmpfn = cmp_regex; - *rf = ((flags & RF_BASIC) ? 0 : REG_EXTENDED) | REG_NOSUB; - if (flags & RF_ICASE) - *rf |= REG_ICASE; - break; - } - return 0; + return 0; } -struct builtin_data_storage -{ - struct txtacc *acc; - char **wp; +struct builtin_data_storage { + struct txtacc *acc; + char **wp; }; static int default_ncol[] = { - 4, /* project-uploader: name, realname, email, pubkey */ - 2, /* project-owner: email, realname */ + 4, /* project-uploader: name, realname, email, pubkey */ + 2, /* project-owner: email, realname */ }; int -builtin_lookup (struct dictionary *dict, void *handle, const char *req) +builtin_lookup(struct dictionary *dict, void *handle, const char *req) { - int i; - int rc; - size_t count = 0; - struct txtacc *acc; - int flags = 0; - strcmp_fn cmpfn = cmp_exact; - struct builtin_data_storage *bds; - int ncol = default_ncol[dict->id]; - - if (dict->parmc == 0) - { - dict->nrow = dict->ncol = 0; - return 0; - } + int i; + int rc; + size_t count = 0; + struct txtacc *acc; + int flags = 0; + strcmp_fn cmpfn = cmp_exact; + struct builtin_data_storage *bds; + int ncol = default_ncol[dict->id]; + + if (dict->parmc == 0) { + dict->nrow = dict->ncol = 0; + return 0; + } - acc = txtacc_create (); + acc = txtacc_create(); - for (i = 0; i < dict->parmc; i++) - { - char *pat = dict->parmv[i]; + for (i = 0; i < dict->parmc; i++) { + char *pat = dict->parmv[i]; - if (pat[0] == '/') - { - pat++; - if (*pat != '/' && parse_cmp_type (pat, &cmpfn, &flags) == 0) - continue; - } + if (pat[0] == '/') { + pat++; + if (*pat != '/' + && parse_cmp_type(pat, &cmpfn, &flags) == 0) + continue; + } + + if (i + ncol >= dict->parmc) + break; + + if (cmpfn(pat, req, flags)) { + size_t j; + for (j = 1; j <= ncol; j++) { + char *val = dict->parmv[i + j]; + txtacc_grow(acc, val, strlen(val) + 1); + } + count++; + } - if (i + ncol >= dict->parmc) - break; - - if (cmpfn (pat, req, flags)) - { - size_t j; - for (j = 1; j <= ncol; j++) - { - char *val = dict->parmv[i + j]; - txtacc_grow (acc, val, strlen (val) + 1); - } - count++; + i += ncol; } - i += ncol; - } - - dict->nrow = count; - dict->ncol = ncol; - - if (count == 0) - { - txtacc_free (acc); - bds = NULL; - rc = 1; - } - else - { - size_t i; - char *p; - - bds = grecs_malloc (sizeof (*bds)); - count *= ncol; - bds->wp = grecs_calloc (count, sizeof (bds->wp[0])); - bds->acc = acc; - p = txtacc_finish (acc, 0); - - for (i = 0; i < count; i++) - { - bds->wp[i] = p; - p += strlen (p) + 1; + dict->nrow = count; + dict->ncol = ncol; + + if (count == 0) { + txtacc_free(acc); + bds = NULL; + rc = 1; + } else { + size_t i; + char *p; + + bds = grecs_malloc(sizeof(*bds)); + count *= ncol; + bds->wp = grecs_calloc(count, sizeof(bds->wp[0])); + bds->acc = acc; + p = txtacc_finish(acc, 0); + + for (i = 0; i < count; i++) { + bds->wp[i] = p; + p += strlen(p) + 1; + } + rc = 0; } - rc = 0; - } - dict->storage = bds; + dict->storage = bds; - return rc; + return rc; } int -builtin_free_result (struct dictionary *dict, void *handle) +builtin_free_result(struct dictionary *dict, void *handle) { - if (dict->storage) - { - struct builtin_data_storage *bds = dict->storage; - txtacc_free (bds->acc); - free (bds->wp); - free (bds); - dict->storage = NULL; - } - return 0; + if (dict->storage) { + struct builtin_data_storage *bds = dict->storage; + txtacc_free(bds->acc); + free(bds->wp); + free(bds); + dict->storage = NULL; + } + return 0; } int -builtin_get (struct dictionary *dict, void *handle, - unsigned nrow, unsigned ncol) +builtin_get(struct dictionary *dict, void *handle, unsigned nrow, + unsigned ncol) { - struct builtin_data_storage *bds = dict->storage; - char *str = bds->wp[nrow * dict->ncol + ncol]; - dictionary_copy_result (dict, str, strlen (str)); - return 0; + struct builtin_data_storage *bds = dict->storage; + char *str = bds->wp[nrow * dict->ncol + ncol]; + dictionary_copy_result(dict, str, strlen(str)); + return 0; } - |