summaryrefslogtreecommitdiff
path: root/dpkg-deb/main.c
diff options
context:
space:
mode:
authorGuillem Jover <guillem@debian.org>2010-10-06 20:10:47 +0200
committerGuillem Jover <guillem@debian.org>2010-11-19 05:21:12 +0100
commita67107c05153db3fde51301450439761e1916a80 (patch)
tree897fa15fe0b890138c45e37f8319c2b8a8c574ce /dpkg-deb/main.c
parente8079c0ee34d4b3309ffbbd500b16525e9ec1b22 (diff)
downloaddpkg-a67107c05153db3fde51301450439761e1916a80.tar.gz
Use ACTION macros instead of ad-hoc action function handling
This makes the code uniform with the rest of the code base, removes the possibility of mismatched entries from cmdinfos and dofunctions arrays, and reduces the scope of the action pointer to main().
Diffstat (limited to 'dpkg-deb/main.c')
-rw-r--r--dpkg-deb/main.c40
1 files changed, 14 insertions, 26 deletions
diff --git a/dpkg-deb/main.c b/dpkg-deb/main.c
index 319e71547..cef1ed91b 100644
--- a/dpkg-deb/main.c
+++ b/dpkg-deb/main.c
@@ -135,7 +135,6 @@ int debugflag=0, nocheckflag=0, oldformatflag=BUILDOLDPKGFORMAT;
struct compressor *compressor = &compressor_gzip;
int compress_level = -1;
const struct cmdinfo *cipaction = NULL;
-dofunction *action = NULL;
static void setaction(const struct cmdinfo *cip, const char *value);
static void setcompresstype(const struct cmdinfo *cip, const char *value);
@@ -156,31 +155,20 @@ set_compress_level(const struct cmdinfo *cip, const char *value)
compress_level = level;
}
-static dofunction *const dofunctions[]= {
- do_build,
- do_contents,
- do_control,
- do_info,
- do_field,
- do_extract,
- do_vextract,
- do_fsystarfile,
- do_showinfo
-};
+#define ACTION(longopt, shortopt, code, function) \
+ { longopt, shortopt, 0, NULL, NULL, setaction, code, NULL, (voidfnp)function }
-/* NB: the entries using setaction must appear first and be in the
- * same order as dofunctions:
- */
static const struct cmdinfo cmdinfos[]= {
- { "build", 'b', 0, NULL, NULL, setaction },
- { "contents", 'c', 0, NULL, NULL, setaction },
- { "control", 'e', 0, NULL, NULL, setaction },
- { "info", 'I', 0, NULL, NULL, setaction },
- { "field", 'f', 0, NULL, NULL, setaction },
- { "extract", 'x', 0, NULL, NULL, setaction },
- { "vextract", 'X', 0, NULL, NULL, setaction },
- { "fsys-tarfile", 0, 0, NULL, NULL, setaction },
- { "show", 'W', 0, NULL, NULL, setaction },
+ ACTION("build", 'b', 0, do_build),
+ ACTION("contents", 'c', 0, do_contents),
+ ACTION("control", 'e', 0, do_control),
+ ACTION("info", 'I', 0, do_info),
+ ACTION("field", 'f', 0, do_field),
+ ACTION("extract", 'x', 0, do_extract),
+ ACTION("vextract", 'X', 0, do_vextract),
+ ACTION("fsys-tarfile", 0, 0, do_fsystarfile),
+ ACTION("show", 'W', 0, do_showinfo),
+
{ "new", 0, 0, &oldformatflag, NULL, NULL, 0 },
{ "old", 0, 0, &oldformatflag, NULL, NULL, 1 },
{ "debug", 'D', 0, &debugflag, NULL, NULL, 1 },
@@ -198,8 +186,6 @@ static void setaction(const struct cmdinfo *cip, const char *value) {
badusage(_("conflicting actions -%c (--%s) and -%c (--%s)"),
cip->oshort, cip->olong, cipaction->oshort, cipaction->olong);
cipaction= cip;
- assert((int)(cip - cmdinfos) < (int)(array_count(dofunctions)));
- action= dofunctions[cip-cmdinfos];
}
static void setcompresstype(const struct cmdinfo *cip, const char *value) {
@@ -210,6 +196,7 @@ static void setcompresstype(const struct cmdinfo *cip, const char *value) {
int main(int argc, const char *const *argv) {
jmp_buf ejbuf;
+ dofunction *action;
setlocale(LC_NUMERIC, "POSIX");
setlocale(LC_ALL, "");
@@ -222,6 +209,7 @@ int main(int argc, const char *const *argv) {
if (!cipaction) badusage(_("need an action option"));
unsetenv("GZIP");
+ action = (dofunction *)cipaction->farg;
action(argv);
standard_shutdown();
exit(0);