summaryrefslogtreecommitdiff
path: root/src
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
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')
-rw-r--r--src/preproc/preconv/preconv.cpp23
-rw-r--r--src/preproc/preconv/preconv.man10
-rw-r--r--src/roff/groff/groff.cpp12
-rw-r--r--src/roff/groff/groff.man14
4 files changed, 47 insertions, 12 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
diff --git a/src/roff/groff/groff.cpp b/src/roff/groff/groff.cpp
index 2930ebee..b3868156 100644
--- a/src/roff/groff/groff.cpp
+++ b/src/roff/groff/groff.cpp
@@ -1,5 +1,6 @@
// -*- C++ -*-
-/* Copyright (C) 1989-2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
+/* Copyright (C) 1989-2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
+ 2008
Free Software Foundation, Inc.
Written by James Clark (jjc@jclark.com)
@@ -135,7 +136,7 @@ int main(int argc, char **argv)
};
while ((opt = getopt_long(
argc, argv,
- "abcCd:eEf:F:gGhiI:lkK:L:m:M:n:No:pP:r:RsStT:UvVw:W:XzZ",
+ "abcCd:D:eEf:F:gGhiI:lkK:L:m:M:n:No:pP:r:RsStT:UvVw:W:XzZ",
long_options, NULL))
!= EOF) {
char buf[3];
@@ -156,6 +157,10 @@ int main(int argc, char **argv)
Pargs += optarg;
Pargs += '\0';
break;
+ case 'D':
+ commands[PRECONV_INDEX].set_name(command_prefix, "preconv");
+ commands[PRECONV_INDEX].append_arg("-D", optarg);
+ break;
case 'K':
commands[PRECONV_INDEX].append_arg("-e", optarg);
Kflag = 1;
@@ -743,7 +748,7 @@ void synopsis(FILE *stream)
fprintf(stream,
"usage: %s [-abceghiklpstvzCENRSUVXZ] [-Fdir] [-mname] [-Tdev] [-ffam]\n"
" [-wname] [-Wname] [-Mdir] [-dcs] [-rcn] [-nnum] [-olist] [-Parg]\n"
-" [-Karg] [-Larg] [-Idir] [files...]\n",
+" [-Darg] [-Karg] [-Larg] [-Idir] [files...]\n",
program_name);
}
@@ -790,6 +795,7 @@ void help()
"-U\tenable unsafe mode\n"
"-Idir\tsearch dir for soelim, troff, and grops. Implies -s\n"
"-Karg\tuse arg as input encoding. Implies -k\n"
+"-Darg\tuse arg as default input encoding. Implies -k\n"
"\n",
stdout);
exit(0);
diff --git a/src/roff/groff/groff.man b/src/roff/groff/groff.man
index 42290300..22b15acb 100644
--- a/src/roff/groff/groff.man
+++ b/src/roff/groff/groff.man
@@ -46,6 +46,7 @@ groff \- front-end for the groff document formatting system
.SY groff
.OP \-abcegiklpstzCEGNRSUVXZ
.OP \-d cs
+.OP \-D arg
.OP \-f fam
.OP \-F dir
.OP \-I dir
@@ -161,6 +162,17 @@ or are differently interpreted by
.
.
.TP
+.BI \-D\ arg
+Set default input encoding used by
+.B preconv
+to
+.IR arg .
+.
+Implies
+.BR \-k .
+.
+.
+.TP
.B \-e
Preprocess with
.BR @g@eqn .
@@ -216,6 +228,8 @@ Please refer to
.BR preconv 's
manual page for its behaviour if no
.B \-K
+(or
+.BR \-D )
option is specified.
.
.