From: Michael J Gruber <git@drmicha.warpmail.net>
To: git@vger.kernel.org
Subject: [RFC PATCH 2/5] error/warn framework: provide localized variants
Date: Mon, 2 Jan 2017 12:14:51 +0100 [thread overview]
Message-ID: <732991717d24d92df8e87838cff51a551e263a17.1483354746.git.git@drmicha.warpmail.net> (raw)
In-Reply-To: <cover.1483354746.git.git@drmicha.warpmail.net>
Provide localized variants of error(), warning(), die() etc.
to go along with localized messages.
Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>
---
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
next prev parent reply other threads:[~2017-01-02 11:15 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-02 11:14 [RFC PATCH 0/5] Localise error headers Michael J Gruber
2017-01-02 11:14 ` [RFC PATCH 1/5] error/warning framework: prepare for l10n Michael J Gruber
2017-01-02 11:14 ` Michael J Gruber [this message]
2017-01-02 11:14 ` [RFC PATCH 3/5] error/warning framework framework: coccinelli rules Michael J Gruber
2017-01-03 12:26 ` [RFC PATCH 0/5] Localise error headers Duy Nguyen
2017-01-03 19:45 ` Stefan Beller
2017-01-04 13:25 ` Duy Nguyen
2017-01-07 9:34 ` Duy Nguyen
2017-01-04 7:05 ` Jeff King
2017-01-09 12:43 ` Michael J Gruber
2017-01-10 9:04 ` Jeff King
2017-01-10 18:28 ` Stefan Beller
2017-01-11 11:37 ` Jeff King
2017-01-11 17:15 ` Stefan Beller
2017-01-21 14:24 ` Jeff King
2017-01-11 18:08 ` Junio C Hamano
2017-01-20 13:08 ` Duy Nguyen
2017-01-21 14:19 ` Jeff King
2017-01-21 14:20 ` Jeff King
2017-03-30 15:18 ` Michael J Gruber
2017-04-01 8:12 ` Jeff King
2017-04-01 17:38 ` Junio C Hamano
2017-01-20 13:23 ` Duy Nguyen
2017-01-20 13:31 ` Duy Nguyen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=732991717d24d92df8e87838cff51a551e263a17.1483354746.git.git@drmicha.warpmail.net \
--to=git@drmicha.warpmail.net \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).