summaryrefslogtreecommitdiff
path: root/src/preproc
diff options
context:
space:
mode:
authorwl <wl>2008-08-20 06:32:29 +0000
committerwl <wl>2008-08-20 06:32:29 +0000
commit695e91550e01d72d115c94b8b2605a92c6e962c3 (patch)
treeadece3b4e748654c361e52ef473b8751c25e420e /src/preproc
parent0cc3ce03e0a1b8f8553812e74eb4aa1cd0bc9122 (diff)
downloadgroff-695e91550e01d72d115c94b8b2605a92c6e962c3.tar.gz
Add default encoding option -D to preconv and groff.
* src/preproc/preconv/preconv.cpp (default_encoding): Make it an array. Update all users. (main): Handle new option -D. (usage): Updated. * src/preproc/preconv/preconv.man: Updated. * src/roff/groff/groff.cpp (main): Handle new option -D. (synopsis, help): Updated. * src/roff/groff/groff.man: Updated.
Diffstat (limited to 'src/preproc')
-rw-r--r--src/preproc/preconv/preconv.cpp23
-rw-r--r--src/preproc/preconv/preconv.man10
2 files changed, 24 insertions, 9 deletions
diff --git a/src/preproc/preconv/preconv.cpp b/src/preproc/preconv/preconv.cpp
index e93f42d0..d81a808c 100644
--- a/src/preproc/preconv/preconv.cpp
+++ b/src/preproc/preconv/preconv.cpp
@@ -1,5 +1,5 @@
// -*- C++ -*-
-/* Copyright (C) 2005, 2006
+/* Copyright (C) 2005, 2006, 2008
Free Software Foundation, Inc.
Written by Werner Lemberg (wl@gnu.org)
@@ -45,7 +45,7 @@ Foundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */
extern "C" const char *Version_string;
-const char *default_encoding;
+char default_encoding[MAX_VAR_LEN];
char user_encoding[MAX_VAR_LEN];
char encoding_string[MAX_VAR_LEN];
int debug_flag = 0;
@@ -1048,7 +1048,7 @@ do_file(const char *filename)
if (!file_encoding) {
if (debug_flag)
fprintf(stderr, " no file encoding\n");
- file_encoding = (char *)default_encoding;
+ file_encoding = default_encoding;
}
else
if (debug_flag)
@@ -1099,6 +1099,7 @@ usage(FILE *stream)
fprintf(stream, "usage: %s [ option ] [ files ]\n"
"\n"
"-d show debugging messages\n"
+ "-D encoding specify default encoding\n"
"-e encoding specify input encoding\n"
"-h print this message\n"
"-r don't add .lf requests\n"
@@ -1121,9 +1122,11 @@ main(int argc, char **argv)
setlocale(LC_ALL, "");
char *locale = getlocale(LC_CTYPE);
if (!locale || !strcmp(locale, "C") || !strcmp(locale, "POSIX"))
- default_encoding = "latin1";
- else
- default_encoding = locale_charset();
+ strcpy(default_encoding, "latin1");
+ else {
+ strncpy(default_encoding, locale_charset(), MAX_VAR_LEN - 1);
+ default_encoding[MAX_VAR_LEN - 1] = 0;
+ }
program_name = argv[0];
int opt;
@@ -1134,7 +1137,7 @@ main(int argc, char **argv)
};
// Parse the command line options.
while ((opt = getopt_long(argc, argv,
- "de:hrv", long_options, NULL)) != EOF)
+ "dD:e:hrv", long_options, NULL)) != EOF)
switch (opt) {
case 'v':
printf("GNU preconv (groff) version %s %s iconv support\n",
@@ -1158,6 +1161,12 @@ main(int argc, char **argv)
else
user_encoding[0] = 0;
break;
+ case 'D':
+ if (optarg) {
+ strncpy(default_encoding, optarg, MAX_VAR_LEN - 1);
+ default_encoding[MAX_VAR_LEN - 1] = 0;
+ }
+ break;
case 'r':
raw_flag = 1;
break;
diff --git a/src/preproc/preconv/preconv.man b/src/preproc/preconv/preconv.man
index 786351ad..cadb9aa6 100644
--- a/src/preproc/preconv/preconv.man
+++ b/src/preproc/preconv/preconv.man
@@ -74,6 +74,10 @@ options of
Emit debugging messages to standard error (mainly the used encoding).
.
.TP
+.BI \-D encoding
+Specify default encoding if everything fails (see below).
+.
+.TP
.BI \-e encoding
Specify input encoding explicitly, overriding all other methods.
This corresponds to
@@ -123,8 +127,10 @@ Finally, check whether there is a known
If found, use it.
.
.IP 4.
-If everything fails, use a default encoding as given by the current locale,
-or `latin1' if the locale is set to `C', `POSIX', or empty.
+If everything fails, use a default encoding as given with option
+.BR \-D ,
+by the current locale, or `latin1' if the locale is set to `C',
+`POSIX', or empty (in that order).
.
.PP
Note that the