Parcourir la source

libdpkg: New dpkg_locales_init()

Switch all program to use the new function instead of open-coding it.
Guillem Jover il y a 12 ans
Parent
commit
fa1cd230b9
13 fichiers modifiés avec 46 ajouts et 33 suppressions
  1. 1 4
      dpkg-deb/main.c
  2. 1 4
      dpkg-split/main.c
  3. 1 4
      dselect/main.cc
  4. 1 1
      lib/dpkg/Makefile.am
  5. 32 0
      lib/dpkg/i18n.c
  6. 2 0
      lib/dpkg/i18n.h
  7. 2 0
      lib/dpkg/libdpkg.map
  8. 1 0
      po/POTFILES.in
  9. 1 4
      src/divertcmd.c
  10. 1 4
      src/main.c
  11. 1 4
      src/querycmd.c
  12. 1 4
      src/statcmd.c
  13. 1 4
      src/trigcmd.c

+ 1 - 4
dpkg-deb/main.c

@@ -247,10 +247,7 @@ int main(int argc, const char *const *argv) {
   int ret;
 
   setlocale(LC_NUMERIC, "POSIX");
-  setlocale(LC_ALL, "");
-  bindtextdomain(PACKAGE, LOCALEDIR);
-  textdomain(PACKAGE);
-
+  dpkg_locales_init(PACKAGE);
   dpkg_program_init(BACKEND);
   dpkg_options_parse(&argv, cmdinfos, printforhelp);
 

+ 1 - 4
dpkg-split/main.c

@@ -155,10 +155,7 @@ static const struct cmdinfo cmdinfos[]= {
 int main(int argc, const char *const *argv) {
   int ret;
 
-  setlocale(LC_ALL, "");
-  bindtextdomain(PACKAGE, LOCALEDIR);
-  textdomain(PACKAGE);
-
+  dpkg_locales_init(PACKAGE);
   dpkg_program_init(SPLITTER);
   dpkg_options_parse(&argv, cmdinfos, printforhelp);
 

+ 1 - 4
dselect/main.cc

@@ -508,10 +508,7 @@ dselect_catch_fatal_error()
 int
 main(int, const char *const *argv)
 {
-  setlocale(LC_ALL, "");
-  bindtextdomain(DSELECT, LOCALEDIR);
-  textdomain(DSELECT);
-
+  dpkg_locales_init(DSELECT);
   dpkg_set_progname(DSELECT);
 
   push_error_context_func(dselect_catch_fatal_error, print_fatal_error, 0);

+ 1 - 1
lib/dpkg/Makefile.am

@@ -44,7 +44,7 @@ libdpkg_a_SOURCES = \
 	file.c \
 	fields.c \
 	glob.c \
-	i18n.h \
+	i18n.c i18n.h \
 	log.c \
 	mlib.c \
 	namevalue.c \

+ 32 - 0
lib/dpkg/i18n.c

@@ -0,0 +1,32 @@
+/*
+ * libdpkg - Debian packaging suite library routines
+ * i18n.c - i18n support
+ *
+ * Copyright © 2013 Guillem Jover <guillem@debian.org>
+ *
+ * This is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <config.h>
+#include <compat.h>
+
+#include <dpkg/i18n.h>
+
+void
+dpkg_locales_init(const char *package)
+{
+	setlocale(LC_ALL, "");
+	bindtextdomain(package, LOCALEDIR);
+	textdomain(package);
+}

+ 2 - 0
lib/dpkg/i18n.h

@@ -42,6 +42,8 @@ DPKG_BEGIN_DECLS
 #define N_(str) gettext_noop(str)
 #define C_(ctxt, str) pgettext(ctxt, str)
 
+void dpkg_locales_init(const char *package);
+
 /** @} */
 
 DPKG_END_DECLS

+ 2 - 0
lib/dpkg/libdpkg.map

@@ -62,6 +62,8 @@ LIBDPKG_PRIVATE {
 	fgets_checked;
 
 	# Charset and string functions
+	dpkg_locales_init;
+
 	cisdigit;
 
 	str_escape_fmt;

+ 1 - 0
po/POTFILES.in

@@ -15,6 +15,7 @@ lib/dpkg/ehandle.c
 lib/dpkg/fields.c
 lib/dpkg/file.c
 lib/dpkg/glob.c
+lib/dpkg/i18n.c
 lib/dpkg/log.c
 lib/dpkg/mlib.c
 lib/dpkg/nfmalloc.c

+ 1 - 4
src/divertcmd.c

@@ -767,10 +767,7 @@ main(int argc, const char * const *argv)
 	const char *env_pkgname;
 	int ret;
 
-	setlocale(LC_ALL, "");
-	bindtextdomain(PACKAGE, LOCALEDIR);
-	textdomain(PACKAGE);
-
+	dpkg_locales_init(PACKAGE);
 	dpkg_program_init("dpkg-divert");
 	dpkg_options_parse(&argv, cmdinfos, printforhelp);
 

+ 1 - 4
src/main.c

@@ -843,10 +843,7 @@ commandfd(const char *const *argv)
 int main(int argc, const char *const *argv) {
   int ret;
 
-  setlocale(LC_ALL, "");
-  bindtextdomain(PACKAGE, LOCALEDIR);
-  textdomain(PACKAGE);
-
+  dpkg_locales_init(PACKAGE);
   dpkg_program_init("dpkg");
   dpkg_options_load(DPKG, cmdinfos);
   dpkg_options_parse(&argv, cmdinfos, printforhelp);

+ 1 - 4
src/querycmd.c

@@ -861,10 +861,7 @@ static const struct cmdinfo cmdinfos[]= {
 int main(int argc, const char *const *argv) {
   int ret;
 
-  setlocale(LC_ALL, "");
-  bindtextdomain(PACKAGE, LOCALEDIR);
-  textdomain(PACKAGE);
-
+  dpkg_locales_init(PACKAGE);
   dpkg_program_init("dpkg-query");
   dpkg_options_parse(&argv, cmdinfos, printforhelp);
 

+ 1 - 4
src/statcmd.c

@@ -346,10 +346,7 @@ main(int argc, const char *const *argv)
 {
 	int ret;
 
-	setlocale(LC_ALL, "");
-	bindtextdomain(PACKAGE, LOCALEDIR);
-	textdomain(PACKAGE);
-
+	dpkg_locales_init(PACKAGE);
 	dpkg_program_init("dpkg-statoverride");
 	dpkg_options_parse(&argv, cmdinfos, printforhelp);
 

+ 1 - 4
src/trigcmd.c

@@ -208,10 +208,7 @@ main(int argc, const char *const *argv)
 	const char *badname;
 	enum trigdef_updateflags tduf;
 
-	setlocale(LC_ALL, "");
-	bindtextdomain(PACKAGE, LOCALEDIR);
-	textdomain(PACKAGE);
-
+	dpkg_locales_init(PACKAGE);
 	dpkg_program_init("dpkg-trigger");
 	dpkg_options_parse(&argv, cmdinfos, printforhelp);