summaryrefslogtreecommitdiffstats
path: root/src/util
diff options
context:
space:
mode:
authorGreg Hudson <ghudson@mit.edu>2011-06-10 18:17:22 +0000
committerGreg Hudson <ghudson@mit.edu>2011-06-10 18:17:22 +0000
commitcb8b1138d6e349a77507f3c561fc7ee2dde5cd7c (patch)
treead5246d1ab834f44aa9a5de30b255d9f044c9663 /src/util
parentfd2f45cf93bfbf10863011fb1a61fc08041c2f51 (diff)
downloadkrb5-cb8b1138d6e349a77507f3c561fc7ee2dde5cd7c.tar.gz
krb5-cb8b1138d6e349a77507f3c561fc7ee2dde5cd7c.tar.xz
krb5-cb8b1138d6e349a77507f3c561fc7ee2dde5cd7c.zip
Add localization support to com_err
* Add compile_et arguments --textdomain and --localedir. * Store text domain and localedir at the end of error tables. * error_message() calls dgettext if the table has a text domain. * add_error_table() calls bindtextdomain if the table has a localedir. * Define N_() as no-op in generated source and mark up error messages. * When using system compile_et, test for --textdomain support. * Use --textdomain option when available. * Run xgettext over generated sources in compile_et rule. * Translate com_err results in krb5int_get_error() if com_err won't. ticket: 6918 git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@24960 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src/util')
-rw-r--r--src/util/Makefile.in1
-rw-r--r--src/util/et/compile_et.118
-rwxr-xr-xsrc/util/et/compile_et.sh30
-rw-r--r--src/util/et/error_message.c12
-rw-r--r--src/util/et/et_c.awk15
-rw-r--r--src/util/gss-kernel-lib/Makefile.in1
-rw-r--r--src/util/support/errors.c4
7 files changed, 68 insertions, 13 deletions
diff --git a/src/util/Makefile.in b/src/util/Makefile.in
index ba14a605f..b6e7af6e2 100644
--- a/src/util/Makefile.in
+++ b/src/util/Makefile.in
@@ -12,6 +12,7 @@ BUILDTOP=$(REL)..
MAYBE_ET_k5 = et
MAYBE_SS_k5 = ss
MAYBE_ET_sys =
+MAYBE_ET_intlsys =
MAYBE_SS_sys =
all-recurse:
diff --git a/src/util/et/compile_et.1 b/src/util/et/compile_et.1
index a082bca46..c9dff7815 100644
--- a/src/util/et/compile_et.1
+++ b/src/util/et/compile_et.1
@@ -8,6 +8,13 @@
compile_et \- error table compiler
.SH SYNOPSIS
.B compile_et
+[
+.B \-\-textdomain
+.I domain
+[
+.B \-\-localedir
+.I dir
+] ]
file
.SH DESCRIPTION
.B Compile_et
@@ -62,6 +69,17 @@ the ``.et'' suffix replaced by ``.c'' and ``.h''.
A ``#'' in the source file is treated as a comment character, and all
remaining text to the end of the source line will be ignored.
+If a text domain is provided with the
+.B \-\-textdomain
+option, error messages will be looked up in the specified domain with
+.BR gettext .
+If a locale directory is also provided with the
+.B \-\-localedir
+option, the text domain will be bound to the specified locale
+directory with
+.B bindtextdomain
+when the error table is initialized.
+
.SH BUGS
Since
diff --git a/src/util/et/compile_et.sh b/src/util/et/compile_et.sh
index adb0be666..f17ddba71 100755
--- a/src/util/et/compile_et.sh
+++ b/src/util/et/compile_et.sh
@@ -4,21 +4,33 @@
AWK=@AWK@
DIR=@DIR@
-usage="usage: $0 [ -d scriptDir ] inputfile.et"
+usage="usage: $0 [ -d scriptDir ] [ --textdomain domain [ --localedir dir ] ]"
+usage="$usage inputfile.et"
-if [ "$1" = "-d" ]; then
- if [ $# -lt 3 ]; then
+TEXTDOMAIN=
+LOCALEDIR=
+
+while [ $# -ge 2 ]; do
+ if [ "$1" = "-d" ]; then
+ DIR=$2; shift; shift
+ elif [ "$1" = "--textdomain" ]; then
+ TEXTDOMAIN=$2; shift; shift
+ elif [ "$1" = "--localedir" ]; then
+ LOCALEDIR=$2; shift; shift
+ else
echo $usage 1>&2 ; exit 1
fi
- DIR=$2 ; shift ; shift
-fi
-if [ $# -ne 1 ]; then
+done
+
+# --localedir requires --textdomain.
+if [ $# -ne 1 -o \( -n "$LOCALEDIR" -a -z "$TEXTDOMAIN" \) ]; then
echo $usage 1>&2 ; exit 1
fi
ROOT=`echo $1 | sed -e s/.et$//`
-BASE=`echo $ROOT | sed -e 's;.*/;;'`
+BASE=`echo "$ROOT" | sed -e 's;.*/;;'`
set -ex
-$AWK -f ${DIR}/et_h.awk outfile=${BASE}.h $ROOT.et
-$AWK -f ${DIR}/et_c.awk outfile=${BASE}.c $ROOT.et
+$AWK -f ${DIR}/et_h.awk "outfile=${BASE}.h" "$ROOT.et"
+$AWK -f ${DIR}/et_c.awk "outfile=${BASE}.c" "textdomain=$TEXTDOMAIN" \
+ "localedir=$LOCALEDIR" "$ROOT.et"
diff --git a/src/util/et/error_message.c b/src/util/et/error_message.c
index 35d58f306..01f2c03ca 100644
--- a/src/util/et/error_message.c
+++ b/src/util/et/error_message.c
@@ -185,7 +185,11 @@ found:
if (table->n_msgs <= (unsigned int) offset)
goto no_table_found;
- return table->msgs[offset];
+ /* If there's a string at the end of the table, it's a text domain. */
+ if (table->msgs[table->n_msgs] != NULL)
+ return dgettext(table->msgs[table->n_msgs], table->msgs[offset]);
+ else
+ return table->msgs[offset];
no_table_found:
k5_mutex_unlock(&et_list_lock);
@@ -290,6 +294,12 @@ add_error_table(const struct error_table *et)
}
e->next = et_list;
et_list = e;
+
+ /* If there are two strings at the end of the table, they are a text domain
+ * and locale dir, and we are supposed to call bindtextdomain. */
+ if (et->msgs[et->n_msgs] != NULL && et->msgs[et->n_msgs + 1] != NULL)
+ bindtextdomain(et->msgs[et->n_msgs], et->msgs[et->n_msgs + 1]);
+
return k5_mutex_unlock(&et_list_lock);
}
diff --git a/src/util/et/et_c.awk b/src/util/et/et_c.awk
index cc277f5dc..35d924aa3 100644
--- a/src/util/et/et_c.awk
+++ b/src/util/et/et_c.awk
@@ -117,6 +117,8 @@ c2n["_"]=63
print "extern void initialize_" table_name "_error_table (void);" > outfile
print "#endif" > outfile
print "" > outfile
+ print "#define N_(x) (x)" > outfile
+ print "" > outfile
print "/* Lclint doesn't handle null annotations on arrays" > outfile
print " properly, so we need this typedef in each" > outfile
print " generated .c file. */" > outfile
@@ -136,7 +138,7 @@ c2n["_"]=63
(continuation == 1) && ($0 ~ /"[ \t]*$/) {
# printf "\t\t\"%s,\n", $0 > outfile
- printf "\t%s,\n", cont_buf $0 > outfile
+ printf "\tN_(%s),\n", cont_buf $0 > outfile
continuation = 0;
}
@@ -152,7 +154,7 @@ c2n["_"]=63
text = text FS $i
}
text=substr(text,2,length(text)-1);
- printf "\t%s,\n", text > outfile
+ printf "\tN_(%s),\n", text > outfile
table_item_count++
}
@@ -179,7 +181,7 @@ c2n["_"]=63
{
if (skipone) {
- printf "\t%s,\n", $0 > outfile
+ printf "\tN_(%s),\n", $0 > outfile
}
skipone=0
}
@@ -188,6 +190,13 @@ END {
print "Error table too large!" | "cat 1>&2"
exit 1
}
+ # Put text domain and/or localedir at the end of the list.
+ if (textdomain) {
+ printf " \"%s\", /* Text domain */\n", textdomain > outfile
+ if (localedir) {
+ printf " \"%s\", /* Locale dir */\n", localedir > outfile
+ }
+ }
print " 0" > outfile
print "};" > outfile
print "" > outfile
diff --git a/src/util/gss-kernel-lib/Makefile.in b/src/util/gss-kernel-lib/Makefile.in
index c2291f04b..988774093 100644
--- a/src/util/gss-kernel-lib/Makefile.in
+++ b/src/util/gss-kernel-lib/Makefile.in
@@ -81,6 +81,7 @@ HEADERS= \
MAYBE_COMERR_k5 = com_err.h
MAYBE_COMERR_sys =
+MAYBE_COMERR_intlsys =
check-pytests:: t_kgss_user t_kgss_kernel
$(RUNPYTEST) $(srcdir)/t_kgss.py $(PYTESTFLAGS)
diff --git a/src/util/support/errors.c b/src/util/support/errors.c
index 00cc922eb..0cd39277d 100644
--- a/src/util/support/errors.c
+++ b/src/util/support/errors.c
@@ -172,6 +172,10 @@ krb5int_get_error (struct errinfo *ep, long code)
return ep->scratch_buf;
}
r = fptr(code);
+#ifndef HAVE_COM_ERR_INTL
+ /* Translate com_err results here if libcom_err won't do it. */
+ r = _(r);
+#endif
if (r == NULL) {
unlock();
goto format_number;