Quellcode durchsuchen

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

Guillem Jover vor 18 Jahren
Ursprung
Commit
122fdc0fa5
10 geänderte Dateien mit 91 neuen und 69 gelöschten Zeilen
  1. 22 0
      ChangeLog
  2. 6 11
      dpkg-deb/main.c
  3. 6 11
      dpkg-split/main.c
  4. 6 11
      dselect/main.cc
  5. 1 1
      lib/Makefile.am
  6. 0 5
      lib/dpkg.h
  7. 26 8
      lib/showcright.c
  8. 12 0
      lib/myopt.h
  9. 6 11
      src/main.c
  10. 6 11
      src/query.c

+ 22 - 0
ChangeLog

@@ -1,3 +1,25 @@
+2008-03-11  Ian Jackson  <ian@davenant.greenend.org.uk>,
+            Guillem Jover  <guillem@debian.org>
+
+	* 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  <guillem@debian.org>
 
 	* lib/showcright.c (showcopyright): Move function prototype to ...

+ 6 - 11
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);
 

+ 6 - 11
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) {

+ 6 - 11
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);

+ 1 - 1
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 \

+ 0 - 5
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);

+ 26 - 8
lib/showcright.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 <ian@chiark.greenend.org.uk>
  *
@@ -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);
+}
+

+ 12 - 0
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 */

+ 6 - 11
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)"),

+ 6 - 11
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)"),