瀏覽代碼

Remove helponly and versiononly functions

Directly use printversion and usage functions, make them exit and change
their prototypes to fit cmdinfos.

This solves the ugly situation of expecting helponly and versiononly
callers to respectively define printversion and usage themselves.
Guillem Jover 17 年之前
父節點
當前提交
e18a89b3b1
共有 8 個文件被更改,包括 60 次插入56 次删除
  1. 10 6
      dpkg-deb/main.c
  2. 10 6
      dpkg-split/main.c
  3. 10 6
      dselect/main.cc
  4. 0 14
      lib/dpkg/myopt-util.c
  5. 0 6
      lib/dpkg/myopt.h
  6. 10 6
      src/main.c
  7. 10 6
      src/query.c
  8. 10 6
      src/trigcmd.c

+ 10 - 6
dpkg-deb/main.c

@@ -50,8 +50,8 @@
 
 
 const char* showformat	= "${Package}\t${Version}\n";
 const char* showformat	= "${Package}\t${Version}\n";
 
 
-void
-printversion(void)
+static void
+printversion(const struct cmdinfo *cip, const char *value)
 {
 {
   printf(_("Debian `%s' package archive backend version %s.\n"),
   printf(_("Debian `%s' package archive backend version %s.\n"),
          BACKEND, DPKG_VERSION_ARCH);
          BACKEND, DPKG_VERSION_ARCH);
@@ -61,10 +61,12 @@ printversion(void)
 "See %s --license for copyright and license details.\n"), BACKEND);
 "See %s --license for copyright and license details.\n"), BACKEND);
 
 
   m_output(stdout, _("<standard output>"));
   m_output(stdout, _("<standard output>"));
+
+  exit(0);
 }
 }
 
 
-void
-usage(void)
+static void
+usage(const struct cmdinfo *cip, const char *value)
 {
 {
   printf(_(
   printf(_(
 "Usage: %s [<option> ...] <command>\n"
 "Usage: %s [<option> ...] <command>\n"
@@ -123,6 +125,8 @@ usage(void)
 "unpacked using `dpkg-deb --extract' will be incorrectly installed !\n"));
 "unpacked using `dpkg-deb --extract' will be incorrectly installed !\n"));
 
 
   m_output(stdout, _("<standard output>"));
   m_output(stdout, _("<standard output>"));
+
+  exit(0);
 }
 }
 
 
 const char thisname[]= BACKEND;
 const char thisname[]= BACKEND;
@@ -171,8 +175,8 @@ static const struct cmdinfo cmdinfos[]= {
   { "compression",   'z', 1, NULL,           &compression, NULL,          1 },
   { "compression",   'z', 1, NULL,           &compression, NULL,          1 },
   { "compress_type", 'Z', 1, NULL,           NULL,         setcompresstype  },
   { "compress_type", 'Z', 1, NULL,           NULL,         setcompresstype  },
   { "showformat",    0,   1, NULL,           &showformat,  NULL             },
   { "showformat",    0,   1, NULL,           &showformat,  NULL             },
-  { "help",          'h', 0, NULL,           NULL,         helponly         },
-  { "version",       0,   0, NULL,           NULL,         versiononly      },
+  { "help",          'h', 0, NULL,           NULL,         usage            },
+  { "version",       0,   0, NULL,           NULL,         printversion     },
   /* UK spelling. */
   /* UK spelling. */
   { "licence",       0,   0, NULL,           NULL,         showcopyright    },
   { "licence",       0,   0, NULL,           NULL,         showcopyright    },
   /* US spelling. */
   /* US spelling. */

+ 10 - 6
dpkg-split/main.c

@@ -42,8 +42,8 @@
 
 
 #include "dpkg-split.h"
 #include "dpkg-split.h"
 
 
-void
-printversion(void)
+static void
+printversion(const struct cmdinfo *cip, const char *value)
 {
 {
   printf(_("Debian `%s' package split/join tool; version %s.\n"),
   printf(_("Debian `%s' package split/join tool; version %s.\n"),
          SPLITTER, DPKG_VERSION_ARCH);
          SPLITTER, DPKG_VERSION_ARCH);
@@ -54,10 +54,12 @@ printversion(void)
 "See %s --license for copyright and license details.\n"), SPLITTER);
 "See %s --license for copyright and license details.\n"), SPLITTER);
 
 
   m_output(stdout, _("<standard output>"));
   m_output(stdout, _("<standard output>"));
+
+  exit(0);
 }
 }
 
 
-void
-usage(void)
+static void
+usage(const struct cmdinfo *cip, const char *value)
 {
 {
   printf(_(
   printf(_(
 "Usage: %s [<option> ...] <command>\n"
 "Usage: %s [<option> ...] <command>\n"
@@ -91,6 +93,8 @@ usage(void)
          ADMINDIR, PARTSDIR);
          ADMINDIR, PARTSDIR);
 
 
   m_output(stdout, _("<standard output>"));
   m_output(stdout, _("<standard output>"));
+
+  exit(0);
 }
 }
 
 
 const char thisname[]= SPLITTER;
 const char thisname[]= SPLITTER;
@@ -149,8 +153,8 @@ static const struct cmdinfo cmdinfos[]= {
   { "auto",         'a',  0,  NULL, NULL,             setaction           },
   { "auto",         'a',  0,  NULL, NULL,             setaction           },
   { "listq",        'l',  0,  NULL, NULL,             setaction           },
   { "listq",        'l',  0,  NULL, NULL,             setaction           },
   { "discard",      'd',  0,  NULL, NULL,             setaction           },
   { "discard",      'd',  0,  NULL, NULL,             setaction           },
-  { "help",         'h',  0,  NULL, NULL,             helponly            },
-  { "version",       0,   0,  NULL, NULL,             versiononly         },
+  { "help",         'h',  0,  NULL, NULL,             usage               },
+  { "version",       0,   0,  NULL, NULL,             printversion        },
   { "licence",       0,   0,  NULL, NULL,             showcopyright       }, /* UK spelling */
   { "licence",       0,   0,  NULL, NULL,             showcopyright       }, /* UK spelling */
   { "license",       0,   0,  NULL, NULL,             showcopyright       }, /* US spelling */
   { "license",       0,   0,  NULL, NULL,             showcopyright       }, /* US spelling */
   { "depotdir",      0,   1,  NULL, &depotdir,     NULL                   },
   { "depotdir",      0,   1,  NULL, &depotdir,     NULL                   },

+ 10 - 6
dselect/main.cc

@@ -166,18 +166,20 @@ static const char licensestring[]= N_(
       "later for copying conditions. There is NO warranty.\n"
       "later for copying conditions. There is NO warranty.\n"
       "See %s --license for copyright and license details.\n");
       "See %s --license for copyright and license details.\n");
 
 
-void
-printversion(void)
+static void
+printversion(const struct cmdinfo *ci, const char *value)
 {
 {
   printf(gettext(programdesc), DSELECT, DPKG_VERSION_ARCH);
   printf(gettext(programdesc), DSELECT, DPKG_VERSION_ARCH);
   printf(gettext(copyrightstring));
   printf(gettext(copyrightstring));
   printf(gettext(licensestring), DSELECT);
   printf(gettext(licensestring), DSELECT);
 
 
   m_output(stdout, _("<standard output>"));
   m_output(stdout, _("<standard output>"));
+
+  exit(0);
 }
 }
 
 
-void
-usage(void)
+static void
+usage(const struct cmdinfo *ci, const char *value)
 {
 {
   int i;
   int i;
 
 
@@ -221,6 +223,8 @@ usage(void)
   fputs("\n\n", stdout);
   fputs("\n\n", stdout);
 
 
   m_output(stdout, _("<standard output>"));
   m_output(stdout, _("<standard output>"));
+
+  exit(0);
 }
 }
 
 
 /* These are called by C code, so need to have C calling convention */
 /* These are called by C code, so need to have C calling convention */
@@ -304,8 +308,8 @@ static const struct cmdinfo cmdinfos[]= {
   { "admindir",     0,   1,  0,  &admindir,  0               },
   { "admindir",     0,   1,  0,  &admindir,  0               },
   { "debug",       'D',  1,  0,  0,          setdebug        },
   { "debug",       'D',  1,  0,  0,          setdebug        },
   { "expert",      'E',  0,  0,  0,          setexpert       },
   { "expert",      'E',  0,  0,  0,          setexpert       },
-  { "help",        'h',  0,  0,  0,          helponly        },
-  { "version",      0,   0,  0,  0,          versiononly     },
+  { "help",        'h',  0,  0,  0,          usage           },
+  { "version",      0,   0,  0,  0,          printversion    },
   { "licence",      0,   0,  0,  0,          showcopyright   }, /* UK spelling */
   { "licence",      0,   0,  0,  0,          showcopyright   }, /* UK spelling */
   { "license",      0,   0,  0,  0,          showcopyright   }, /* US spelling */
   { "license",      0,   0,  0,  0,          showcopyright   }, /* US spelling */
   { "color",        0,   1,  0,  0,          setcolor        }, /* US spelling */
   { "color",        0,   1,  0,  0,          setcolor        }, /* US spelling */

+ 0 - 14
lib/dpkg/myopt-util.c

@@ -31,20 +31,6 @@
 #include <dpkg/buffer.h>
 #include <dpkg/buffer.h>
 #include <dpkg/myopt.h>
 #include <dpkg/myopt.h>
 
 
-void
-helponly(const struct cmdinfo *cip, const char *value)
-{
-	usage();
-	exit(0);
-}
-
-void
-versiononly(const struct cmdinfo *cip, const char *value)
-{
-	printversion();
-	exit(0);
-}
-
 void
 void
 showcopyright(const struct cmdinfo *cip, const char *value)
 showcopyright(const struct cmdinfo *cip, const char *value)
 {
 {

+ 0 - 6
lib/dpkg/myopt.h

@@ -52,12 +52,6 @@ void loadcfgfile(const char *prog, const struct cmdinfo *cmdinfos);
 
 
 /* Utility functions. */
 /* Utility functions. */
 void showcopyright(const struct cmdinfo *cip, const char *value) DPKG_ATTR_NORET;
 void showcopyright(const struct cmdinfo *cip, const char *value) DPKG_ATTR_NORET;
-void helponly(const struct cmdinfo *cip, const char *value) DPKG_ATTR_NORET;
-void versiononly(const struct cmdinfo *cip, const char *value) DPKG_ATTR_NORET;
-
-/* To be defined by callers. */
-void usage(void);
-void printversion(void);
 
 
 DPKG_END_DECLS
 DPKG_END_DECLS
 
 

+ 10 - 6
src/main.c

@@ -50,8 +50,8 @@
 #include "main.h"
 #include "main.h"
 #include "filesdb.h"
 #include "filesdb.h"
 
 
-void
-printversion(void)
+static void
+printversion(const struct cmdinfo *ci, const char *value)
 {
 {
   printf(_("Debian `%s' package management program version %s.\n"),
   printf(_("Debian `%s' package management program version %s.\n"),
          DPKG, DPKG_VERSION_ARCH);
          DPKG, DPKG_VERSION_ARCH);
@@ -61,13 +61,15 @@ printversion(void)
 "See %s --license for copyright and license details.\n"), DPKG);
 "See %s --license for copyright and license details.\n"), DPKG);
 
 
   m_output(stdout, _("<standard output>"));
   m_output(stdout, _("<standard output>"));
+
+  exit(0);
 }
 }
 /*
 /*
    options that need fixing:
    options that need fixing:
   dpkg --yet-to-unpack                 \n\
   dpkg --yet-to-unpack                 \n\
   */
   */
-void
-usage(void)
+static void
+usage(const struct cmdinfo *ci, const char *value)
 {
 {
   printf(_(
   printf(_(
 "Usage: %s [<option> ...] <command>\n"
 "Usage: %s [<option> ...] <command>\n"
@@ -152,6 +154,8 @@ usage(void)
 "Use `dselect' or `aptitude' for user-friendly package management.\n"));
 "Use `dselect' or `aptitude' for user-friendly package management.\n"));
 
 
   m_output(stdout, _("<standard output>"));
   m_output(stdout, _("<standard output>"));
+
+  exit(0);
 }
 }
 
 
 const char thisname[]= "dpkg";
 const char thisname[]= "dpkg";
@@ -516,8 +520,8 @@ static const struct cmdinfo cmdinfos[]= {
   { "refuse",            0,   2, NULL,          NULL,      setforce,      0 },
   { "refuse",            0,   2, NULL,          NULL,      setforce,      0 },
   { "no-force",          0,   2, NULL,          NULL,      setforce,      0 },
   { "no-force",          0,   2, NULL,          NULL,      setforce,      0 },
   { "debug",             'D', 1, NULL,          NULL,      setdebug,      0 },
   { "debug",             'D', 1, NULL,          NULL,      setdebug,      0 },
-  { "help",              'h', 0, NULL,          NULL,      helponly,      0 },
-  { "version",           0,   0, NULL,          NULL,      versiononly,   0 },
+  { "help",              'h', 0, NULL,          NULL,      usage,         0 },
+  { "version",           0,   0, NULL,          NULL,      printversion,  0 },
   /* UK spelling. */
   /* UK spelling. */
   { "licence",           0,   0, NULL,          NULL,      showcopyright, 0 },
   { "licence",           0,   0, NULL,          NULL,      showcopyright, 0 },
   /* US spelling. */
   /* US spelling. */

+ 10 - 6
src/query.c

@@ -553,8 +553,8 @@ control_path(const char *const *argv)
   modstatdb_shutdown();
   modstatdb_shutdown();
 }
 }
 
 
-void
-printversion(void)
+static void
+printversion(const struct cmdinfo *ci, const char *value)
 {
 {
   printf(_("Debian `%s' package management program query tool\n"), DPKGQUERY);
   printf(_("Debian `%s' package management program query tool\n"), DPKGQUERY);
   printf(_(
   printf(_(
@@ -563,10 +563,12 @@ printversion(void)
 "See %s --license for copyright and license details.\n"), DPKGQUERY);
 "See %s --license for copyright and license details.\n"), DPKGQUERY);
 
 
   m_output(stdout, _("<standard output>"));
   m_output(stdout, _("<standard output>"));
+
+  exit(0);
 }
 }
 
 
-void
-usage(void)
+static void
+usage(const struct cmdinfo *ci, const char *value)
 {
 {
   printf(_(
   printf(_(
 "Usage: %s [<option> ...] <command>\n"
 "Usage: %s [<option> ...] <command>\n"
@@ -606,6 +608,8 @@ usage(void)
 "  case left alignment will be used.\n"));
 "  case left alignment will be used.\n"));
 
 
   m_output(stdout, _("<standard output>"));
   m_output(stdout, _("<standard output>"));
+
+  exit(0);
 }
 }
 
 
 const char thisname[]= "dpkg-query";
 const char thisname[]= "dpkg-query";
@@ -644,8 +648,8 @@ static const struct cmdinfo cmdinfos[]= {
 
 
   { "admindir",   0,   1, NULL, &admindir,   NULL          },
   { "admindir",   0,   1, NULL, &admindir,   NULL          },
   { "showformat", 'f', 1, NULL, &showformat, NULL          },
   { "showformat", 'f', 1, NULL, &showformat, NULL          },
-  { "help",       'h', 0, NULL, NULL,        helponly      },
-  { "version",    0,   0, NULL, NULL,        versiononly   },
+  { "help",       'h', 0, NULL, NULL,        usage         },
+  { "version",    0,   0, NULL, NULL,        printversion  },
   /* UK spelling. */
   /* UK spelling. */
   { "licence",    0,   0, NULL, NULL,        showcopyright },
   { "licence",    0,   0, NULL, NULL,        showcopyright },
   /* US spelling */
   /* US spelling */

+ 10 - 6
src/trigcmd.c

@@ -48,8 +48,8 @@ const char thisname[] = "dpkg-trigger";
 const char printforhelp[] = N_(
 const char printforhelp[] = N_(
 "Type dpkg-trigger --help for help about this utility.");
 "Type dpkg-trigger --help for help about this utility.");
 
 
-void
-printversion(void)
+static void
+printversion(const struct cmdinfo *ci, const char *value)
 {
 {
 	printf(_("Debian %s package trigger utility.\n"), thisname);
 	printf(_("Debian %s package trigger utility.\n"), thisname);
 
 
@@ -59,10 +59,12 @@ printversion(void)
 "See %s --license for copyright and license details.\n"), thisname);
 "See %s --license for copyright and license details.\n"), thisname);
 
 
 	m_output(stdout, _("<standard output>"));
 	m_output(stdout, _("<standard output>"));
+
+	exit(0);
 }
 }
 
 
-void
-usage(void)
+static void
+usage(const struct cmdinfo *ci, const char *value)
 {
 {
 	printf(_(
 	printf(_(
 "Usage: %s [<options> ...] <trigger-name>\n"
 "Usage: %s [<options> ...] <trigger-name>\n"
@@ -90,6 +92,8 @@ usage(void)
 "\n"), ADMINDIR);
 "\n"), ADMINDIR);
 
 
 	m_output(stdout, _("<standard output>"));
 	m_output(stdout, _("<standard output>"));
+
+	exit(0);
 }
 }
 
 
 static const char *admindir = ADMINDIR;
 static const char *admindir = ADMINDIR;
@@ -170,8 +174,8 @@ static const struct cmdinfo cmdinfos[] = {
 	{ "no-await",        0,   0, NULL,     &bypackage, noawait },
 	{ "no-await",        0,   0, NULL,     &bypackage, noawait },
 	{ "no-act",          0,   0, &f_noact, NULL,       NULL, 1 },
 	{ "no-act",          0,   0, &f_noact, NULL,       NULL, 1 },
 	{ "check-supported", 0,   0, &f_check, NULL,       NULL, 1 },
 	{ "check-supported", 0,   0, &f_check, NULL,       NULL, 1 },
-	{ "help",            'h', 0, NULL,     NULL,       helponly },
-	{ "version",         0,   0, NULL,     NULL,       versiononly },
+	{ "help",            'h', 0, NULL,     NULL,       usage   },
+	{ "version",         0,   0, NULL,     NULL,       printversion  },
 	/* UK spelling */
 	/* UK spelling */
 	{ "licence",         0,   0, NULL,     NULL,       showcopyright },
 	{ "licence",         0,   0, NULL,     NULL,       showcopyright },
 	/* US spelling */
 	/* US spelling */