[RFC PATCH 2/5] error/warn framework: provide localized variants

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Provide localized variants of error(), warning(), die() etc.
to go along with localized messages.

Signed-off-by: Michael J Gruber <git@xxxxxxxxxxxxxxxxxxxx>
---
 git-compat-util.h |  8 ++++++
 usage.c           | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 82 insertions(+)

diff --git a/git-compat-util.h b/git-compat-util.h
index f1bf0a6749..48209a6c67 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -405,13 +405,21 @@ struct strbuf;
 /* General helper functions */
 extern void vreportf(const char *prefix, const char *err, va_list params);
 extern NORETURN void usage(const char *err);
+extern NORETURN void usage_(const char *err);
 extern NORETURN void usagef(const char *err, ...) __attribute__((format (printf, 1, 2)));
+extern NORETURN void usagef_(const char *err, ...) __attribute__((format (printf, 1, 2)));
 extern NORETURN void die(const char *err, ...) __attribute__((format (printf, 1, 2)));
+extern NORETURN void die_(const char *err, ...) __attribute__((format (printf, 1, 2)));
 extern NORETURN void die_errno(const char *err, ...) __attribute__((format (printf, 1, 2)));
+extern NORETURN void die_errno_(const char *err, ...) __attribute__((format (printf, 1, 2)));
 extern int error(const char *err, ...) __attribute__((format (printf, 1, 2)));
+extern int error_(const char *err, ...) __attribute__((format (printf, 1, 2)));
 extern int error_errno(const char *err, ...) __attribute__((format (printf, 1, 2)));
+extern int error_errno_(const char *err, ...) __attribute__((format (printf, 1, 2)));
 extern void warning(const char *err, ...) __attribute__((format (printf, 1, 2)));
+extern void warning_(const char *err, ...) __attribute__((format (printf, 1, 2)));
 extern void warning_errno(const char *err, ...) __attribute__((format (printf, 1, 2)));
+extern void warning_errno_(const char *err, ...) __attribute__((format (printf, 1, 2)));
 
 #ifndef NO_OPENSSL
 #ifdef APPLE_COMMON_CRYPTO
diff --git a/usage.c b/usage.c
index 4270b04bf9..d0cfb02a64 100644
--- a/usage.c
+++ b/usage.c
@@ -105,11 +105,25 @@ void NORETURN usagef(const char *err, ...)
 	va_end(params);
 }
 
+void NORETURN usagef_(const char *err, ...)
+{
+	va_list params;
+
+	va_start(params, err);
+	usage_routine(_("usage: "), err, params);
+	va_end(params);
+}
+
 void NORETURN usage(const char *err)
 {
 	usagef("%s", err);
 }
 
+void NORETURN usage_(const char *err)
+{
+	usagef_("%s", err);
+}
+
 void NORETURN die(const char *err, ...)
 {
 	va_list params;
@@ -124,6 +138,20 @@ void NORETURN die(const char *err, ...)
 	va_end(params);
 }
 
+void NORETURN die_(const char *err, ...)
+{
+	va_list params;
+
+	if (die_is_recursing()) {
+		fputs(_("fatal: recursion detected in die handler\n"), stderr);
+		exit(128);
+	}
+
+	va_start(params, err);
+	die_routine(_("fatal: "), err, params);
+	va_end(params);
+}
+
 static const char *fmt_with_err(char *buf, int n, const char *fmt)
 {
 	char str_error[256], *err;
@@ -163,6 +191,22 @@ void NORETURN die_errno(const char *fmt, ...)
 	va_end(params);
 }
 
+void NORETURN die_errno_(const char *fmt, ...)
+{
+	char buf[1024];
+	va_list params;
+
+	if (die_is_recursing()) {
+		fputs(_("fatal: recursion detected in die_errno handler\n"),
+			stderr);
+		exit(128);
+	}
+
+	va_start(params, fmt);
+	die_routine(_("fatal: "), fmt_with_err(buf, sizeof(buf), fmt), params);
+	va_end(params);
+}
+
 #undef error_errno
 int error_errno(const char *fmt, ...)
 {
@@ -175,6 +219,17 @@ int error_errno(const char *fmt, ...)
 	return -1;
 }
 
+int error_errno_(const char *fmt, ...)
+{
+	char buf[1024];
+	va_list params;
+
+	va_start(params, fmt);
+	error_routine(_("error: "), fmt_with_err(buf, sizeof(buf), fmt), params);
+	va_end(params);
+	return -1;
+}
+
 #undef error
 int error(const char *err, ...)
 {
@@ -186,6 +241,16 @@ int error(const char *err, ...)
 	return -1;
 }
 
+int error_(const char *err, ...)
+{
+	va_list params;
+
+	va_start(params, err);
+	error_routine(_("error: "), err, params);
+	va_end(params);
+	return -1;
+}
+
 void warning_errno(const char *warn, ...)
 {
 	char buf[1024];
@@ -204,3 +269,12 @@ void warning(const char *warn, ...)
 	warn_routine("warning: ", warn, params);
 	va_end(params);
 }
+
+void warning_(const char *warn, ...)
+{
+	va_list params;
+
+	va_start(params, warn);
+	warn_routine(_("warning: "), warn, params);
+	va_end(params);
+}
-- 
2.11.0.372.g2fcea0e476




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]