浏览代码

libdpkg: Do not require programs to define printforhelp

Instead define it in myopt.c and initialize it through a new argument to
myopt().
Guillem Jover 15 年之前
父节点
当前提交
0fc0d6d598
共有 11 个文件被更改,包括 30 次插入22 次删除
  1. 2 2
      dpkg-deb/main.c
  2. 2 2
      dpkg-split/main.c
  3. 2 2
      dselect/main.cc
  4. 0 1
      lib/dpkg/libdpkg.Versions
  5. 8 1
      lib/dpkg/myopt.c
  6. 2 3
      lib/dpkg/myopt.h
  7. 3 2
      src/divertcmd.c
  8. 3 3
      src/main.c
  9. 3 2
      src/querycmd.c
  10. 3 2
      src/statcmd.c
  11. 2 2
      src/trigcmd.c

+ 2 - 2
dpkg-deb/main.c

@@ -126,7 +126,7 @@ usage(const struct cmdinfo *cip, const char *value)
 }
 
 const char thisname[]= BACKEND;
-const char printforhelp[]=
+static const char printforhelp[] =
   N_("Type dpkg-deb --help for help about manipulating *.deb files;\n"
      "Type dpkg --help for help about installing and deinstalling packages.");
 
@@ -190,7 +190,7 @@ int main(int argc, const char *const *argv) {
   textdomain(PACKAGE);
 
   standard_startup();
-  myopt(&argv, cmdinfos);
+  myopt(&argv, cmdinfos, printforhelp);
 
   if (!cipaction) badusage(_("need an action option"));
 

+ 2 - 2
dpkg-split/main.c

@@ -101,7 +101,7 @@ usage(const struct cmdinfo *cip, const char *value)
 }
 
 const char thisname[]= SPLITTER;
-const char printforhelp[]= N_("Type dpkg-split --help for help.");
+static const char printforhelp[] = N_("Type dpkg-split --help for help.");
 
 struct partqueue *queue= NULL;
 
@@ -160,7 +160,7 @@ int main(int argc, const char *const *argv) {
   textdomain(PACKAGE);
 
   standard_startup();
-  myopt(&argv, cmdinfos);
+  myopt(&argv, cmdinfos, printforhelp);
 
   if (!cipaction) badusage(_("need an action option"));
 

+ 2 - 2
dselect/main.cc

@@ -58,7 +58,7 @@
 #include "pkglist.h"
 
 const char thisname[]= DSELECT;
-const char printforhelp[]= N_("Type dselect --help for help.");
+static const char printforhelp[] = N_("Type dselect --help for help.");
 
 modstatdb_rw readwrite;
 int expertmode= 0;
@@ -517,7 +517,7 @@ main(int, const char *const *argv)
   push_error_context_func(dselect_catch_fatal_error, print_fatal_error, 0);
 
   loadcfgfile(DSELECT, cmdinfos);
-  myopt(&argv,cmdinfos);
+  myopt(&argv, cmdinfos, printforhelp);
 
   admindir = dpkg_db_set_dir(admindir);
 

+ 0 - 1
lib/dpkg/libdpkg.Versions

@@ -134,7 +134,6 @@ LIBDPKG_PRIVATE {
 	loadcfgfile;
 	myopt;
 	badusage;
-	# printforhelp;		# XXX variable, do not require external
 	# thisname;		# XXX variable, do not require external
 	cipaction;		# XXX variable, do not export
 	setaction;

+ 8 - 1
lib/dpkg/myopt.c

@@ -35,6 +35,8 @@
 #include <dpkg/string.h>
 #include <dpkg/myopt.h>
 
+static const char *printforhelp;
+
 void
 badusage(const char *fmt, ...)
 {
@@ -198,11 +200,16 @@ void loadcfgfile(const char *prog, const struct cmdinfo* cmdinfos) {
   }
 }
 
-void myopt(const char *const **argvp, const struct cmdinfo *cmdinfos) {
+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);

+ 2 - 3
lib/dpkg/myopt.h

@@ -48,14 +48,13 @@ struct cmdinfo {
   action_func *action;
 };
 
-extern const char printforhelp[];
-
 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);
+void myopt(const char *const **argvp, const struct cmdinfo *cmdinfos,
+           const char *help_str);
 void loadcfgfile(const char *prog, const struct cmdinfo *cmdinfos);
 
 /**

+ 3 - 2
src/divertcmd.c

@@ -47,7 +47,8 @@
 
 
 const char thisname[] = "dpkg-divert";
-const char printforhelp[] = N_("Use --help for help about querying packages.");
+static const char printforhelp[] = N_(
+"Use --help for help about querying packages.");
 
 static const char *admindir;
 
@@ -698,7 +699,7 @@ main(int argc, const char * const *argv)
 	textdomain(PACKAGE);
 
 	standard_startup();
-	myopt(&argv, cmdinfos);
+	myopt(&argv, cmdinfos, printforhelp);
 
 	admindir = dpkg_db_set_dir(admindir);
 

+ 3 - 3
src/main.c

@@ -167,7 +167,7 @@ usage(const struct cmdinfo *ci, const char *value)
 
 const char thisname[]= "dpkg";
 const char native_arch[] = ARCHITECTURE;
-const char printforhelp[]= N_(
+static const char printforhelp[] = N_(
 "Type dpkg --help for help about installing and deinstalling packages [*];\n"
 "Use `dselect' or `aptitude' for user-friendly package management;\n"
 "Type dpkg -Dhelp for a list of dpkg debug flag values;\n"
@@ -716,7 +716,7 @@ commandfd(const char *const *argv)
         newargs[i] = m_strdup(newargs[i]);
 
     setaction(NULL, NULL);
-    myopt((const char *const**)&newargs,cmdinfos);
+    myopt((const char *const **)&newargs, cmdinfos, printforhelp);
     if (!cipaction) badusage(_("need an action option"));
 
     ret |= cipaction->action(newargs);
@@ -736,7 +736,7 @@ int main(int argc, const char *const *argv) {
 
   standard_startup();
   loadcfgfile(DPKG, cmdinfos);
-  myopt(&argv, cmdinfos);
+  myopt(&argv, cmdinfos, printforhelp);
 
   if (!cipaction) badusage(_("need an action option"));
 

+ 3 - 2
src/querycmd.c

@@ -653,7 +653,8 @@ usage(const struct cmdinfo *ci, const char *value)
 }
 
 const char thisname[]= "dpkg-query";
-const char printforhelp[]= N_("Use --help for help about querying packages.");
+static const char printforhelp[] = N_(
+"Use --help for help about querying packages.");
 
 static const char *admindir;
 
@@ -684,7 +685,7 @@ int main(int argc, const char *const *argv) {
   textdomain(PACKAGE);
 
   standard_startup();
-  myopt(&argv, cmdinfos);
+  myopt(&argv, cmdinfos, printforhelp);
 
   admindir = dpkg_db_set_dir(admindir);
 

+ 3 - 2
src/statcmd.c

@@ -49,7 +49,8 @@
 #include "filesdb.h"
 
 const char thisname[] = "dpkg-statoverride";
-const char printforhelp[] = N_("Use --help for help about querying packages.");
+static const char printforhelp[] = N_(
+"Use --help for help about querying packages.");
 
 static void DPKG_ATTR_NORET
 printversion(const struct cmdinfo *cip, const char *value)
@@ -369,7 +370,7 @@ main(int argc, const char *const *argv)
 	textdomain(PACKAGE);
 
 	standard_startup();
-	myopt(&argv, cmdinfos);
+	myopt(&argv, cmdinfos, printforhelp);
 
 	admindir = dpkg_db_set_dir(admindir);
 

+ 2 - 2
src/trigcmd.c

@@ -44,7 +44,7 @@
 
 const char thisname[] = "dpkg-trigger";
 
-const char printforhelp[] = N_(
+static const char printforhelp[] = N_(
 "Type dpkg-trigger --help for help about this utility.");
 
 static void DPKG_ATTR_NORET
@@ -189,7 +189,7 @@ main(int argc, const char *const *argv)
 	textdomain(PACKAGE);
 
 	standard_startup();
-	myopt(&argv, cmdinfos);
+	myopt(&argv, cmdinfos, printforhelp);
 
 	admindir = dpkg_db_set_dir(admindir);