The following commit has been merged in the master branch:
commit 122fdc0fa5fe90a7d5f6919f2d3177fd0830c360
Author: Guillem Jover <[EMAIL PROTECTED]>
Date:   Tue Mar 11 07:01:57 2008 +0200

    Move command line common option utilities to lib/myopt-util.c

diff --git a/ChangeLog b/ChangeLog
index 77445b3..fd73dcb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,25 @@
+2008-03-11  Ian Jackson  <[EMAIL PROTECTED]>,
+            Guillem Jover  <[EMAIL PROTECTED]>
+
+       * lib/showcright.c: Rename to ...
+       * lib/myopt-util.c: ... this.
+       * lib/Makefile.am (libdpkg_a_SOURCES): Rename 'showcright.c' to
+       'myopt-util.c'.
+
+       * lib/dpkg.h (struct cmdinfo): Remove declaration.
+       (showcopyright): Move prototype to ...
+       * lib/myopt-util.c: ... here.
+       (helponly, versiononly): New functions.
+       * lib/myopt.h: Include <dpkg-def.h>.
+       (showcopyright, helponly, versiononly, usage, printversion): New
+       function prototypes.
+       * dpkg-deb/main.c (printversion, usage): Remove static keyword.
+       (helponly, versiononly): Remove function declarations and definitions.
+       * dpkg-split/main.c: Likewise.
+       * dselect/main.cc: Likewise.
+       * src/main.c: Likewise.
+       * src/query.c: Likewise.
+
 2008-03-11  Guillem Jover  <[EMAIL PROTECTED]>
 
        * lib/showcright.c (showcopyright): Move function prototype to ...
diff --git a/dpkg-deb/main.c b/dpkg-deb/main.c
index fe7dc68..527bebc 100644
--- a/dpkg-deb/main.c
+++ b/dpkg-deb/main.c
@@ -42,7 +42,9 @@
 
 const char* showformat = "${Package}\t${Version}\n";
 
-static void printversion(void) {
+void
+printversion(void)
+{
   if (printf(_("Debian `%s' package archive backend version %s.\n"),
             BACKEND, DPKG_VERSION_ARCH) < 0) werr("stdout");
   if (printf(_("This is free software; see the GNU General Public License 
version 2 or\n"
@@ -51,7 +53,9 @@ static void printversion(void) {
             BACKEND) < 0) werr("stdout");
 }
 
-static void usage(void) {
+void
+usage(void)
+{
   if (printf(_(
 "Usage: %s [<option> ...] <command>\n"
 "\n"), BACKEND) < 0) werr("stdout");
@@ -121,15 +125,6 @@ enum compress_type compress_type = compress_type_gzip;
 const struct cmdinfo *cipaction = NULL;
 dofunction *action = NULL;
 
-static void helponly(const struct cmdinfo *cip, const char *value) 
NONRETURNING;
-static void helponly(const struct cmdinfo *cip, const char *value) {
-  usage(); exit(0);
-}
-static void versiononly(const struct cmdinfo *cip, const char *value) 
NONRETURNING;
-static void versiononly(const struct cmdinfo *cip, const char *value) {
-  printversion(); exit(0);
-}
-
 static void setaction(const struct cmdinfo *cip, const char *value);
 static void setcompresstype(const struct cmdinfo *cip, const char *value);
 
diff --git a/dpkg-split/main.c b/dpkg-split/main.c
index 4fb801f..7eff4b4 100644
--- a/dpkg-split/main.c
+++ b/dpkg-split/main.c
@@ -34,7 +34,9 @@
 
 #include "dpkg-split.h"
 
-static void printversion(void) {
+void
+printversion(void)
+{
   if (printf(_("Debian `%s' package split/join tool; version %s.\n"),
             SPLITTER, DPKG_VERSION_ARCH) < 0) werr ("stdout");
   if (printf(_("Copyright (C) 1994-1996 Ian Jackson.\n")) < 0) werr ("stdout");
@@ -44,7 +46,9 @@ static void printversion(void) {
             SPLITTER) < 0) werr("stdout");
 }
 
-static void usage(void) {
+void
+usage(void)
+{
   if (printf(_(
 "Usage: %s [<option> ...] <command>\n"
 "\n"), SPLITTER) < 0) werr("stdout");
@@ -96,15 +100,6 @@ void rerreof(FILE *f, const char *fn) {
   ohshit(_("unexpected end of file in %.250s"),fn);
 }
 
-static void helponly(const struct cmdinfo *cip, const char *value) 
NONRETURNING;
-static void helponly(const struct cmdinfo *cip, const char *value) {
-  usage(); exit(0);
-}
-static void versiononly(const struct cmdinfo *cip, const char *value) 
NONRETURNING;
-static void versiononly(const struct cmdinfo *cip, const char *value) {
-  printversion(); exit(0);
-}
-
 static void setaction(const struct cmdinfo *cip, const char *value);
 
 static void setpartsize(const struct cmdinfo *cip, const char *value) {
diff --git a/dselect/main.cc b/dselect/main.cc
index 947d267..99702cf 100644
--- a/dselect/main.cc
+++ b/dselect/main.cc
@@ -155,14 +155,18 @@ static const char licensestring[]= N_(
       "later for copying conditions. There is NO warranty.\n"
       "See %s --license for copyright and license details.\n");
 
-static void printversion(void) {
+void
+printversion(void)
+{
   if (printf(gettext(programdesc), DSELECT, DPKG_VERSION_ARCH) < 0)
     werr("stdout");
   if (printf(gettext(copyrightstring)) < 0) werr("stdout");
   if (printf(gettext(licensestring), DSELECT) < 0) werr("stdout");
 }
 
-static void usage(void) {
+void
+usage(void)
+{
   int i;
   if (printf(_(
 "Usage: %s [<option> ...] [<action> ...]\n"
@@ -207,15 +211,6 @@ static void usage(void) {
 /* These are called by C code, so need to have C calling convention */
 extern "C" {
 
-  static void helponly(const struct cmdinfo*, const char*) NONRETURNING;
-  static void helponly(const struct cmdinfo*, const char*) {
-    usage(); exit(0);
-  }
-  static void versiononly(const struct cmdinfo*, const char*) NONRETURNING;
-  static void versiononly(const struct cmdinfo*, const char*) {
-    printversion(); exit(0);
-  }
-
   static void setdebug(const struct cmdinfo*, const char *v) {
     debug= fopen(v,"a");
     if (!debug) ohshite(_("couldn't open debug file `%.255s'\n"),v);
diff --git a/lib/Makefile.am b/lib/Makefile.am
index a5a3ac9..2c34bb2 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -27,11 +27,11 @@ libdpkg_a_SOURCES = \
        md5.c md5.h \
        mlib.c \
        myopt.c myopt.h \
+       myopt-util.c \
        nfmalloc.c \
        parse.c \
        parsehelp.c \
        parsedump.h \
-       showcright.c \
        showpkg.c \
        tarfn.c tarfn.h \
        utils.c \
diff --git a/lib/dpkg.h b/lib/dpkg.h
index ccc4bf9..7e2e428 100644
--- a/lib/dpkg.h
+++ b/lib/dpkg.h
@@ -351,11 +351,6 @@ off_t buffer_copy(buffer_data_t read_data, buffer_data_t 
write_data, off_t limit
 
 extern volatile int onerr_abort;
 
-/*** from showcright.c ***/
-
-struct cmdinfo;
-void showcopyright(const struct cmdinfo *c, const char *v) NONRETURNING;
-
 /*** from utils.c ***/
 
 int cisdigit(int c);
diff --git a/lib/showcright.c b/lib/myopt-util.c
similarity index 67%
rename from lib/showcright.c
rename to lib/myopt-util.c
index da61547..6620aeb 100644
--- a/lib/showcright.c
+++ b/lib/myopt-util.c
@@ -1,6 +1,6 @@
 /*
  * libdpkg - Debian packaging suite library routines
- * showcright.c - show copyright file routine
+ * myopt-util.c - command line option utilities
  *
  * Copyright (C) 1994,1995 Ian Jackson <[EMAIL PROTECTED]>
  *
@@ -26,11 +26,29 @@
 
 #include <dpkg.h>
 
-void showcopyright(const struct cmdinfo *c, const char *v) {
-  int fd;
-  fd= open(COPYINGFILE,O_RDONLY);
-  if (fd < 0)
-    ohshite(_("cannot open GPL file"));
-  fd_fd_copy(fd, 1, -1, "showcopyright");
-  exit(0);
+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
+showcopyright(const struct cmdinfo *cip, const char *value)
+{
+       int fd;
+
+       fd = open(COPYINGFILE, O_RDONLY);
+       if (fd < 0)
+               ohshite(_("cannot open GPL file"));
+       fd_fd_copy(fd, 1, -1, "showcopyright");
+       exit(0);
+}
+
diff --git a/lib/myopt.h b/lib/myopt.h
index cb59f82..dcc9214 100644
--- a/lib/myopt.h
+++ b/lib/myopt.h
@@ -22,6 +22,8 @@
 #ifndef MYOPT_H
 #define MYOPT_H
 
+#include <dpkg-def.h>
+
 typedef void (*voidfnp)(void);
 
 struct cmdinfo {
@@ -39,4 +41,14 @@ struct cmdinfo {
 void myfileopt(const char* fn, const struct cmdinfo* cmdinfos);
 void myopt(const char *const **argvp, const struct cmdinfo *cmdinfos);
 void loadcfgfile(const char *prog, const struct cmdinfo *cmdinfos);
+
+/* Utility functions. */
+void showcopyright(const struct cmdinfo *cip, const char *value) NONRETURNING;
+void helponly(const struct cmdinfo *cip, const char *value) NONRETURNING;
+void versiononly(const struct cmdinfo *cip, const char *value) NONRETURNING;
+
+/* To be defined by callers. */
+void usage(void);
+void printversion(void);
+
 #endif /* MYOPT_H */
diff --git a/src/main.c b/src/main.c
index b4bd50f..5fac146 100644
--- a/src/main.c
+++ b/src/main.c
@@ -40,7 +40,9 @@
 
 #include "main.h"
 
-static void printversion(void) {
+void
+printversion(void)
+{
   if (printf(_("Debian `%s' package management program version %s.\n"),
             DPKG, DPKG_VERSION_ARCH) < 0) werr("stdout");
   if (printf(_("This is free software; see the GNU General Public License 
version 2 or\n"
@@ -52,7 +54,9 @@ static void printversion(void) {
    options that need fixing:
   dpkg --yet-to-unpack                 \n\
   */
-static void usage(void) {
+void
+usage(void)
+{
   if (fprintf (stdout, _(
 "Usage: %s [<option> ...] <command>\n"
 "\n"), DPKG) < 0) werr ("stdout");
@@ -193,15 +197,6 @@ static const struct forceinfo {
   {  NULL                                               }
 };
 
-static void helponly(const struct cmdinfo *cip, const char *value) 
NONRETURNING;
-static void helponly(const struct cmdinfo *cip, const char *value) {
-  usage(); exit(0);
-}
-static void versiononly(const struct cmdinfo *cip, const char *value) 
NONRETURNING;
-static void versiononly(const struct cmdinfo *cip, const char *value) {
-  printversion(); exit(0);
-}
-
 static void setaction(const struct cmdinfo *cip, const char *value) {
   if (cipaction)
     badusage(_("conflicting actions -%c (--%s) and -%c (--%s)"),
diff --git a/src/query.c b/src/query.c
index 4a7f9cb..2e524cf 100644
--- a/src/query.c
+++ b/src/query.c
@@ -484,7 +484,9 @@ void showpackages(const char *const *argv) {
   modstatdb_shutdown();
 }
 
-static void printversion(void) {
+void
+printversion(void)
+{
   if (printf(_("Debian `%s' package management program query tool\n"),
             DPKGQUERY) < 0) werr("stdout");
   if (printf(_("This is free software; see the GNU General Public License 
version 2 or\n"
@@ -496,7 +498,9 @@ static void printversion(void) {
    options that need fixing:
   dpkg --yet-to-unpack                 \n\
   */
-static void usage(void) {
+void
+usage(void)
+{
   if (printf(_(
 "Usage: %s [<option> ...] <command>\n"
 "\n"), DPKGQUERY) < 0) werr ("stdout");
@@ -553,15 +557,6 @@ const char *admindir= ADMINDIR;
 const char *instdir= "";
 struct packageinlist *ignoredependss=0;
 
-static void helponly(const struct cmdinfo *cip, const char *value) 
NONRETURNING;
-static void helponly(const struct cmdinfo *cip, const char *value) {
-  usage(); exit(0);
-}
-static void versiononly(const struct cmdinfo *cip, const char *value) 
NONRETURNING;
-static void versiononly(const struct cmdinfo *cip, const char *value) {
-  printversion(); exit(0);
-}
-
 static void setaction(const struct cmdinfo *cip, const char *value) {
   if (cipaction)
     badusage(_("conflicting actions -%c (--%s) and -%c (--%s)"),

-- 
dpkg's main repository


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to