From cf22cf6118035ab8ee5cc25e5298a987073c8dc8 Mon Sep 17 00:00:00 2001 From: Guillem Jover Date: Sun, 3 Jul 2011 03:23:11 +0200 Subject: libdpkg: Rename myopt module to options --- dpkg-deb/build.c | 2 +- dpkg-deb/extract.c | 2 +- dpkg-deb/info.c | 2 +- dpkg-deb/main.c | 2 +- dpkg-split/info.c | 2 +- dpkg-split/join.c | 2 +- dpkg-split/main.c | 2 +- dpkg-split/queue.c | 2 +- dpkg-split/split.c | 2 +- dselect/main.cc | 2 +- lib/dpkg/Makefile.am | 4 +- lib/dpkg/myopt.c | 291 --------------------------------------------------- lib/dpkg/myopt.h | 75 ------------- lib/dpkg/options.c | 291 +++++++++++++++++++++++++++++++++++++++++++++++++++ lib/dpkg/options.h | 75 +++++++++++++ src/archives.c | 2 +- src/cleanup.c | 2 +- src/divertcmd.c | 2 +- src/enquiry.c | 2 +- src/errors.c | 2 +- src/main.c | 2 +- src/packages.c | 2 +- src/processarc.c | 2 +- src/querycmd.c | 2 +- src/remove.c | 2 +- src/select.c | 2 +- src/statcmd.c | 2 +- src/trigcmd.c | 2 +- src/update.c | 2 +- 29 files changed, 392 insertions(+), 392 deletions(-) delete mode 100644 lib/dpkg/myopt.c delete mode 100644 lib/dpkg/myopt.h create mode 100644 lib/dpkg/options.c create mode 100644 lib/dpkg/options.h diff --git a/dpkg-deb/build.c b/dpkg-deb/build.c index a88cb0ea0..75132ee34 100644 --- a/dpkg-deb/build.c +++ b/dpkg-deb/build.c @@ -48,7 +48,7 @@ #include #include #include -#include +#include #include "dpkg-deb.h" diff --git a/dpkg-deb/extract.c b/dpkg-deb/extract.c index 365be5d13..2dde994e3 100644 --- a/dpkg-deb/extract.c +++ b/dpkg-deb/extract.c @@ -47,7 +47,7 @@ #include #include #include -#include +#include #include "dpkg-deb.h" diff --git a/dpkg-deb/info.c b/dpkg-deb/info.c index 6f43f55fe..2bd0a5dc0 100644 --- a/dpkg-deb/info.c +++ b/dpkg-deb/info.c @@ -44,7 +44,7 @@ #include #include #include -#include +#include #include "dpkg-deb.h" diff --git a/dpkg-deb/main.c b/dpkg-deb/main.c index 5aa6c4d7a..49cf5e50c 100644 --- a/dpkg-deb/main.c +++ b/dpkg-deb/main.c @@ -42,7 +42,7 @@ #include #include #include -#include +#include #include "dpkg-deb.h" diff --git a/dpkg-split/info.c b/dpkg-split/info.c index 30e0c275c..6066f73a5 100644 --- a/dpkg-split/info.c +++ b/dpkg-split/info.c @@ -37,7 +37,7 @@ #include #include #include -#include +#include #include "dpkg-split.h" diff --git a/dpkg-split/join.c b/dpkg-split/join.c index 03017c886..95ed64aee 100644 --- a/dpkg-split/join.c +++ b/dpkg-split/join.c @@ -33,7 +33,7 @@ #include #include #include -#include +#include #include "dpkg-split.h" diff --git a/dpkg-split/main.c b/dpkg-split/main.c index c6d956d10..c4e7b33c9 100644 --- a/dpkg-split/main.c +++ b/dpkg-split/main.c @@ -37,7 +37,7 @@ #include #include #include -#include +#include #include "dpkg-split.h" diff --git a/dpkg-split/queue.c b/dpkg-split/queue.c index 53724347a..e758feb86 100644 --- a/dpkg-split/queue.c +++ b/dpkg-split/queue.c @@ -39,7 +39,7 @@ #include #include #include -#include +#include #include "dpkg-split.h" diff --git a/dpkg-split/split.c b/dpkg-split/split.c index d4fe4bc62..1b40f348f 100644 --- a/dpkg-split/split.c +++ b/dpkg-split/split.c @@ -43,7 +43,7 @@ #include #include #include -#include +#include #include "dpkg-split.h" diff --git a/dselect/main.cc b/dselect/main.cc index fa58defe5..6508b1f93 100644 --- a/dselect/main.cc +++ b/dselect/main.cc @@ -51,7 +51,7 @@ #include #include #include -#include +#include #include "dselect.h" #include "bindings.h" diff --git a/lib/dpkg/Makefile.am b/lib/dpkg/Makefile.am index a1c8f8e51..79508357c 100644 --- a/lib/dpkg/Makefile.am +++ b/lib/dpkg/Makefile.am @@ -43,9 +43,9 @@ libdpkg_a_SOURCES = \ log.c \ md5.c md5.h \ mlib.c \ - myopt.c \ namevalue.c \ nfmalloc.c \ + options.c \ parse.c \ parsehelp.c \ path.c \ @@ -83,8 +83,8 @@ pkginclude_HEADERS = \ file.h \ glob.h \ macros.h \ - myopt.h \ namevalue.h \ + options.h \ parsedump.h \ path.h \ pkg.h \ diff --git a/lib/dpkg/myopt.c b/lib/dpkg/myopt.c deleted file mode 100644 index 4181a9016..000000000 --- a/lib/dpkg/myopt.c +++ /dev/null @@ -1,291 +0,0 @@ -/* - * libdpkg - Debian packaging suite library routines - * myopt.c - my very own option parsing - * - * Copyright © 1994,1995 Ian Jackson - * Copyright © 2000,2002 Wichert Akkerman - * Copyright © 2008,2009 Guillem Jover - * - * This 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 2 of the License, or - * (at your option) any later version. - * - * This 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 . - */ - -#include -#include - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -static const char *printforhelp; - -void -badusage(const char *fmt, ...) -{ - char buf[1024]; - va_list args; - - va_start(args, fmt); - vsnprintf(buf, sizeof(buf), fmt, args); - va_end(args); - - ohshit("%s\n\n%s", buf, gettext(printforhelp)); -} - -static void DPKG_ATTR_NORET DPKG_ATTR_PRINTF(3) -config_error(const char *file_name, int line_num, const char *fmt, ...) -{ - char buf[1024]; - va_list args; - - va_start(args, fmt); - vsnprintf(buf, sizeof(buf), fmt, args); - va_end(args); - - ohshit(_("configuration error: %s:%d: %s"), file_name, line_num, buf); -} - -void myfileopt(const char* fn, const struct cmdinfo* cmdinfos) { - FILE* file; - int line_num = 0; - char linebuf[MAX_CONFIG_LINE]; - - file= fopen(fn, "r"); - if (!file) { - if (errno==ENOENT) - return; - warning(_("failed to open configuration file '%.255s' for reading: %s"), - fn, strerror(errno)); - return; - } - - while (fgets(linebuf, sizeof(linebuf), file)) { - char* opt; - const struct cmdinfo *cip; - int l; - - line_num++; - - if ((linebuf[0] == '#') || (linebuf[0] == '\n') || (linebuf[0] == '\0')) - continue; - l=strlen(linebuf); - if (linebuf[l - 1] == '\n') - linebuf[l - 1] = '\0'; - for (opt=linebuf;isalnum(*opt)||*opt=='-';opt++) ; - if (*opt == '\0') - opt=NULL; - else { - *opt++ = '\0'; - if (*opt=='=') opt++; - while (isspace(*opt)) opt++; - - opt = str_strip_quotes(opt); - if (opt == NULL) - config_error(fn, line_num, _("unbalanced quotes in '%s'"), linebuf); - } - - for (cip=cmdinfos; cip->olong || cip->oshort; cip++) { - if (!cip->olong) continue; - if (!strcmp(cip->olong,linebuf)) break; - l=strlen(cip->olong); - if ((cip->takesvalue==2) && (linebuf[l]=='-') && - !opt && !strncmp(linebuf,cip->olong,l)) { - opt=linebuf+l+1; - break; - } - } - - if (!cip->olong) - config_error(fn, line_num, _("unknown option '%s'"), linebuf); - - if (cip->takesvalue) { - if (!opt) - config_error(fn, line_num, _("'%s' needs a value"), linebuf); - if (cip->call) cip->call(cip,opt); - else - *cip->sassignto = m_strdup(opt); - } else { - if (opt) - config_error(fn, line_num, _("'%s' does not take a value"), linebuf); - if (cip->call) cip->call(cip,NULL); - else - *cip->iassignto = cip->arg_int; - } - } - if (ferror(file)) ohshite(_("read error in configuration file `%.255s'"), fn); - if (fclose(file)) ohshite(_("error closing configuration file `%.255s'"), fn); -} - -static int -valid_config_filename(const struct dirent *dent) -{ - const char *c; - - if (dent->d_name[0] == '.') - return 0; - - for (c = dent->d_name; *c; c++) - if (!isalnum(*c) && *c != '_' && *c != '-') - return 0; - - if (*c == '\0') - return 1; - else - return 0; -} - -static void -load_config_dir(const char *prog, const struct cmdinfo* cmdinfos) -{ - char *dirname; - struct dirent **dlist; - int dlist_n, i; - - m_asprintf(&dirname, "%s/%s.cfg.d", CONFIGDIR, prog); - - dlist_n = scandir(dirname, &dlist, valid_config_filename, alphasort); - if (dlist_n < 0) { - if (errno == ENOENT) { - free(dirname); - return; - } else - ohshite(_("error opening configuration directory '%s'"), dirname); - } - - for (i = 0; i < dlist_n; i++) { - char *filename; - - m_asprintf(&filename, "%s/%s", dirname, dlist[i]->d_name); - myfileopt(filename, cmdinfos); - - free(dlist[i]); - free(filename); - } - - free(dirname); - free(dlist); -} - -void loadcfgfile(const char *prog, const struct cmdinfo* cmdinfos) { - char *home, *file; - - load_config_dir(prog, cmdinfos); - - m_asprintf(&file, "%s/%s.cfg", CONFIGDIR, prog); - myfileopt(file, cmdinfos); - free(file); - - if ((home = getenv("HOME")) != NULL) { - m_asprintf(&file, "%s/.%s.cfg", home, prog); - myfileopt(file, cmdinfos); - free(file); - } -} - -void -myopt(const char *const **argvp, const struct cmdinfo *cmdinfos, - const char *help_str) -{ - const struct cmdinfo *cip; - const char *p, *value; - int l; - - printforhelp = help_str; - - ++(*argvp); - while ((p= **argvp) && *p == '-') { - ++(*argvp); - if (!strcmp(p,"--")) break; - if (*++p == '-') { - ++p; value=NULL; - for (cip= cmdinfos; - cip->olong || cip->oshort; - cip++) { - if (!cip->olong) continue; - if (!strcmp(p,cip->olong)) break; - l= strlen(cip->olong); - if (!strncmp(p,cip->olong,l) && - (p[l]== ((cip->takesvalue==2) ? '-' : '='))) { value=p+l+1; break; } - } - if (!cip->olong) badusage(_("unknown option --%s"),p); - if (cip->takesvalue) { - if (!value) { - value= *(*argvp)++; - if (!value) badusage(_("--%s option takes a value"),cip->olong); - } - if (cip->call) cip->call(cip,value); - else *cip->sassignto= value; - } else { - if (value) badusage(_("--%s option does not take a value"),cip->olong); - if (cip->call) cip->call(cip,NULL); - else - *cip->iassignto = cip->arg_int; - } - } else { - while (*p) { - for (cip= cmdinfos; (cip->olong || cip->oshort) && *p != cip->oshort; cip++); - if (!cip->oshort) badusage(_("unknown option -%c"),*p); - p++; - if (cip->takesvalue) { - if (!*p) { - value= *(*argvp)++; - if (!value) badusage(_("-%c option takes a value"),cip->oshort); - } else { - value= p; p=""; - if (*value == '=') value++; - } - if (cip->call) cip->call(cip,value); - else *cip->sassignto= value; - } else { - if (*p == '=') badusage(_("-%c option does not take a value"),cip->oshort); - if (cip->call) cip->call(cip,NULL); - else - *cip->iassignto = cip->arg_int; - } - } - } - } -} - -void -setobsolete(const struct cmdinfo *cip, const char *value) -{ - warning(_("obsolete option '--%s'\n"), cip->olong); -} - -const struct cmdinfo *cipaction = NULL; - -/* XXX: This function is a hack. */ -static inline int -option_short(int c) -{ - return c ? c : '\b'; -} - -void -setaction(const struct cmdinfo *cip, const char *value) -{ - if (cipaction) - badusage(_("conflicting actions -%c (--%s) and -%c (--%s)"), - option_short(cip->oshort), cip->olong, - option_short(cipaction->oshort), cipaction->olong); - cipaction = cip; -} diff --git a/lib/dpkg/myopt.h b/lib/dpkg/myopt.h deleted file mode 100644 index 230fd89c0..000000000 --- a/lib/dpkg/myopt.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - * libdpkg - Debian packaging suite library routines - * myopt.h - declarations for my very own option parsing - * - * Copyright © 1994,1995 Ian Jackson - * - * This 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 2 of the License, or - * (at your option) any later version. - * - * This 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 . - */ - -#ifndef MYOPT_H -#define MYOPT_H - -#include - -DPKG_BEGIN_DECLS - -typedef int action_func(const char *const *argv); - -struct cmdinfo { - const char *olong; - char oshort; - - /* - * 0 = Normal (-o, --option) - * 1 = Standard value (-o=value, --option=value or - * -o value, --option value) - * 2 = Option string continued (--option-value) - */ - int takesvalue; - int *iassignto; - const char **sassignto; - void (*call)(const struct cmdinfo*, const char *value); - - int arg_int; - void *arg_ptr; - - action_func *action; -}; - -void badusage(const char *fmt, ...) DPKG_ATTR_NORET DPKG_ATTR_PRINTF(1); - -#define MAX_CONFIG_LINE 1024 - -void myfileopt(const char* fn, const struct cmdinfo* cmdinfos); -void myopt(const char *const **argvp, const struct cmdinfo *cmdinfos, - const char *help_str); -void loadcfgfile(const char *prog, const struct cmdinfo *cmdinfos); - -/** - * Current cmdinfo action. - */ -extern const struct cmdinfo *cipaction; - -void setaction(const struct cmdinfo *cip, const char *value); -void setobsolete(const struct cmdinfo *cip, const char *value); - -#define ACTION(longopt, shortopt, code, func) \ - { longopt, shortopt, 0, NULL, NULL, setaction, code, NULL, func } -#define OBSOLETE(longopt, shortopt) \ - { longopt, shortopt, 0, NULL, NULL, setobsolete, 0, NULL, NULL } - -DPKG_END_DECLS - -#endif /* MYOPT_H */ diff --git a/lib/dpkg/options.c b/lib/dpkg/options.c new file mode 100644 index 000000000..3575e297d --- /dev/null +++ b/lib/dpkg/options.c @@ -0,0 +1,291 @@ +/* + * libdpkg - Debian packaging suite library routines + * options.c - option parsing functions + * + * Copyright © 1994,1995 Ian Jackson + * Copyright © 2000,2002 Wichert Akkerman + * Copyright © 2008,2009 Guillem Jover + * + * This 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 2 of the License, or + * (at your option) any later version. + * + * This 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 . + */ + +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +static const char *printforhelp; + +void +badusage(const char *fmt, ...) +{ + char buf[1024]; + va_list args; + + va_start(args, fmt); + vsnprintf(buf, sizeof(buf), fmt, args); + va_end(args); + + ohshit("%s\n\n%s", buf, gettext(printforhelp)); +} + +static void DPKG_ATTR_NORET DPKG_ATTR_PRINTF(3) +config_error(const char *file_name, int line_num, const char *fmt, ...) +{ + char buf[1024]; + va_list args; + + va_start(args, fmt); + vsnprintf(buf, sizeof(buf), fmt, args); + va_end(args); + + ohshit(_("configuration error: %s:%d: %s"), file_name, line_num, buf); +} + +void myfileopt(const char* fn, const struct cmdinfo* cmdinfos) { + FILE* file; + int line_num = 0; + char linebuf[MAX_CONFIG_LINE]; + + file= fopen(fn, "r"); + if (!file) { + if (errno==ENOENT) + return; + warning(_("failed to open configuration file '%.255s' for reading: %s"), + fn, strerror(errno)); + return; + } + + while (fgets(linebuf, sizeof(linebuf), file)) { + char* opt; + const struct cmdinfo *cip; + int l; + + line_num++; + + if ((linebuf[0] == '#') || (linebuf[0] == '\n') || (linebuf[0] == '\0')) + continue; + l=strlen(linebuf); + if (linebuf[l - 1] == '\n') + linebuf[l - 1] = '\0'; + for (opt=linebuf;isalnum(*opt)||*opt=='-';opt++) ; + if (*opt == '\0') + opt=NULL; + else { + *opt++ = '\0'; + if (*opt=='=') opt++; + while (isspace(*opt)) opt++; + + opt = str_strip_quotes(opt); + if (opt == NULL) + config_error(fn, line_num, _("unbalanced quotes in '%s'"), linebuf); + } + + for (cip=cmdinfos; cip->olong || cip->oshort; cip++) { + if (!cip->olong) continue; + if (!strcmp(cip->olong,linebuf)) break; + l=strlen(cip->olong); + if ((cip->takesvalue==2) && (linebuf[l]=='-') && + !opt && !strncmp(linebuf,cip->olong,l)) { + opt=linebuf+l+1; + break; + } + } + + if (!cip->olong) + config_error(fn, line_num, _("unknown option '%s'"), linebuf); + + if (cip->takesvalue) { + if (!opt) + config_error(fn, line_num, _("'%s' needs a value"), linebuf); + if (cip->call) cip->call(cip,opt); + else + *cip->sassignto = m_strdup(opt); + } else { + if (opt) + config_error(fn, line_num, _("'%s' does not take a value"), linebuf); + if (cip->call) cip->call(cip,NULL); + else + *cip->iassignto = cip->arg_int; + } + } + if (ferror(file)) ohshite(_("read error in configuration file `%.255s'"), fn); + if (fclose(file)) ohshite(_("error closing configuration file `%.255s'"), fn); +} + +static int +valid_config_filename(const struct dirent *dent) +{ + const char *c; + + if (dent->d_name[0] == '.') + return 0; + + for (c = dent->d_name; *c; c++) + if (!isalnum(*c) && *c != '_' && *c != '-') + return 0; + + if (*c == '\0') + return 1; + else + return 0; +} + +static void +load_config_dir(const char *prog, const struct cmdinfo* cmdinfos) +{ + char *dirname; + struct dirent **dlist; + int dlist_n, i; + + m_asprintf(&dirname, "%s/%s.cfg.d", CONFIGDIR, prog); + + dlist_n = scandir(dirname, &dlist, valid_config_filename, alphasort); + if (dlist_n < 0) { + if (errno == ENOENT) { + free(dirname); + return; + } else + ohshite(_("error opening configuration directory '%s'"), dirname); + } + + for (i = 0; i < dlist_n; i++) { + char *filename; + + m_asprintf(&filename, "%s/%s", dirname, dlist[i]->d_name); + myfileopt(filename, cmdinfos); + + free(dlist[i]); + free(filename); + } + + free(dirname); + free(dlist); +} + +void loadcfgfile(const char *prog, const struct cmdinfo* cmdinfos) { + char *home, *file; + + load_config_dir(prog, cmdinfos); + + m_asprintf(&file, "%s/%s.cfg", CONFIGDIR, prog); + myfileopt(file, cmdinfos); + free(file); + + if ((home = getenv("HOME")) != NULL) { + m_asprintf(&file, "%s/.%s.cfg", home, prog); + myfileopt(file, cmdinfos); + free(file); + } +} + +void +myopt(const char *const **argvp, const struct cmdinfo *cmdinfos, + const char *help_str) +{ + const struct cmdinfo *cip; + const char *p, *value; + int l; + + printforhelp = help_str; + + ++(*argvp); + while ((p= **argvp) && *p == '-') { + ++(*argvp); + if (!strcmp(p,"--")) break; + if (*++p == '-') { + ++p; value=NULL; + for (cip= cmdinfos; + cip->olong || cip->oshort; + cip++) { + if (!cip->olong) continue; + if (!strcmp(p,cip->olong)) break; + l= strlen(cip->olong); + if (!strncmp(p,cip->olong,l) && + (p[l]== ((cip->takesvalue==2) ? '-' : '='))) { value=p+l+1; break; } + } + if (!cip->olong) badusage(_("unknown option --%s"),p); + if (cip->takesvalue) { + if (!value) { + value= *(*argvp)++; + if (!value) badusage(_("--%s option takes a value"),cip->olong); + } + if (cip->call) cip->call(cip,value); + else *cip->sassignto= value; + } else { + if (value) badusage(_("--%s option does not take a value"),cip->olong); + if (cip->call) cip->call(cip,NULL); + else + *cip->iassignto = cip->arg_int; + } + } else { + while (*p) { + for (cip= cmdinfos; (cip->olong || cip->oshort) && *p != cip->oshort; cip++); + if (!cip->oshort) badusage(_("unknown option -%c"),*p); + p++; + if (cip->takesvalue) { + if (!*p) { + value= *(*argvp)++; + if (!value) badusage(_("-%c option takes a value"),cip->oshort); + } else { + value= p; p=""; + if (*value == '=') value++; + } + if (cip->call) cip->call(cip,value); + else *cip->sassignto= value; + } else { + if (*p == '=') badusage(_("-%c option does not take a value"),cip->oshort); + if (cip->call) cip->call(cip,NULL); + else + *cip->iassignto = cip->arg_int; + } + } + } + } +} + +void +setobsolete(const struct cmdinfo *cip, const char *value) +{ + warning(_("obsolete option '--%s'\n"), cip->olong); +} + +const struct cmdinfo *cipaction = NULL; + +/* XXX: This function is a hack. */ +static inline int +option_short(int c) +{ + return c ? c : '\b'; +} + +void +setaction(const struct cmdinfo *cip, const char *value) +{ + if (cipaction) + badusage(_("conflicting actions -%c (--%s) and -%c (--%s)"), + option_short(cip->oshort), cip->olong, + option_short(cipaction->oshort), cipaction->olong); + cipaction = cip; +} diff --git a/lib/dpkg/options.h b/lib/dpkg/options.h new file mode 100644 index 000000000..ba415bf13 --- /dev/null +++ b/lib/dpkg/options.h @@ -0,0 +1,75 @@ +/* + * libdpkg - Debian packaging suite library routines + * options.h - option parsing functions + * + * Copyright © 1994,1995 Ian Jackson + * + * This 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 2 of the License, or + * (at your option) any later version. + * + * This 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 . + */ + +#ifndef LIBDPKG_OPTIONS_H +#define LIBDPKG_OPTIONS_H + +#include + +DPKG_BEGIN_DECLS + +typedef int action_func(const char *const *argv); + +struct cmdinfo { + const char *olong; + char oshort; + + /* + * 0 = Normal (-o, --option) + * 1 = Standard value (-o=value, --option=value or + * -o value, --option value) + * 2 = Option string continued (--option-value) + */ + int takesvalue; + int *iassignto; + const char **sassignto; + void (*call)(const struct cmdinfo*, const char *value); + + int arg_int; + void *arg_ptr; + + action_func *action; +}; + +void badusage(const char *fmt, ...) DPKG_ATTR_NORET DPKG_ATTR_PRINTF(1); + +#define MAX_CONFIG_LINE 1024 + +void myfileopt(const char* fn, const struct cmdinfo* cmdinfos); +void myopt(const char *const **argvp, const struct cmdinfo *cmdinfos, + const char *help_str); +void loadcfgfile(const char *prog, const struct cmdinfo *cmdinfos); + +/** + * Current cmdinfo action. + */ +extern const struct cmdinfo *cipaction; + +void setaction(const struct cmdinfo *cip, const char *value); +void setobsolete(const struct cmdinfo *cip, const char *value); + +#define ACTION(longopt, shortopt, code, func) \ + { longopt, shortopt, 0, NULL, NULL, setaction, code, NULL, func } +#define OBSOLETE(longopt, shortopt) \ + { longopt, shortopt, 0, NULL, NULL, setobsolete, 0, NULL, NULL } + +DPKG_END_DECLS + +#endif /* LIBDPKG_OPTIONS_H */ diff --git a/src/archives.c b/src/archives.c index ff1d273da..f060e7067 100644 --- a/src/archives.c +++ b/src/archives.c @@ -51,7 +51,7 @@ #include #include #include -#include +#include #include #ifdef WITH_SELINUX diff --git a/src/cleanup.c b/src/cleanup.c index 91ffb2ca6..eff81aa41 100644 --- a/src/cleanup.c +++ b/src/cleanup.c @@ -37,7 +37,7 @@ #include #include #include -#include +#include #include "filesdb.h" #include "main.h" diff --git a/src/divertcmd.c b/src/divertcmd.c index efd08b560..a37624e9d 100644 --- a/src/divertcmd.c +++ b/src/divertcmd.c @@ -41,7 +41,7 @@ #include #include #include -#include +#include #include "filesdb.h" diff --git a/src/enquiry.c b/src/enquiry.c index 25ae142b8..40c3e736d 100644 --- a/src/enquiry.c +++ b/src/enquiry.c @@ -40,7 +40,7 @@ #include #include #include -#include +#include #include "filesdb.h" #include "main.h" diff --git a/src/errors.c b/src/errors.c index f01691031..ce0421296 100644 --- a/src/errors.c +++ b/src/errors.c @@ -37,7 +37,7 @@ #include #include #include -#include +#include #include "main.h" diff --git a/src/main.c b/src/main.c index d3e7d25f8..22bf8190d 100644 --- a/src/main.c +++ b/src/main.c @@ -48,7 +48,7 @@ #include #include #include -#include +#include #include "main.h" #include "filesdb.h" diff --git a/src/packages.c b/src/packages.c index c67a60032..b12947427 100644 --- a/src/packages.c +++ b/src/packages.c @@ -38,7 +38,7 @@ #include #include #include -#include +#include #include "filesdb.h" #include "main.h" diff --git a/src/processarc.c b/src/processarc.c index 39205d9cf..fa41833c5 100644 --- a/src/processarc.c +++ b/src/processarc.c @@ -47,7 +47,7 @@ #include #include #include -#include +#include #include #include "filesdb.h" diff --git a/src/querycmd.c b/src/querycmd.c index 71855e44b..cdda47d9d 100644 --- a/src/querycmd.c +++ b/src/querycmd.c @@ -46,7 +46,7 @@ #include #include #include -#include +#include #include "filesdb.h" #include "infodb.h" diff --git a/src/remove.c b/src/remove.c index aee25e723..d41465ea7 100644 --- a/src/remove.c +++ b/src/remove.c @@ -37,7 +37,7 @@ #include #include #include -#include +#include #include #include "infodb.h" diff --git a/src/select.c b/src/select.c index 712db97a8..f3c0e1ad4 100644 --- a/src/select.c +++ b/src/select.c @@ -31,7 +31,7 @@ #include #include #include -#include +#include #include "filesdb.h" #include "main.h" diff --git a/src/statcmd.c b/src/statcmd.c index b59d1b857..11ae1cfbc 100644 --- a/src/statcmd.c +++ b/src/statcmd.c @@ -43,7 +43,7 @@ #include #include #include -#include +#include #include "main.h" #include "filesdb.h" diff --git a/src/trigcmd.c b/src/trigcmd.c index 4c420444c..09fb34621 100644 --- a/src/trigcmd.c +++ b/src/trigcmd.c @@ -38,7 +38,7 @@ #include #include #include -#include +#include #include #include diff --git a/src/update.c b/src/update.c index 227c9d10b..44ef96566 100644 --- a/src/update.c +++ b/src/update.c @@ -30,7 +30,7 @@ #include #include #include -#include +#include #include "main.h" -- cgit v1.2.3