[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
preconv: Allow set default encodding
From: |
Alexey Gladkov |
Subject: |
preconv: Allow set default encodding |
Date: |
Wed, 20 Aug 2008 02:34:46 +0400 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; ru; rv:1.8.1.14) Gecko/20080717 Thunderbird/2.0.0.14 Mnenhy/0.7.5.0 |
Greetings!
Following patch adds -D in the preconv to change the input encoding by
default.
--
Rgrds, legion
--- groff-1.19.3/src/preproc/preconv/preconv.cpp.fix 2008-08-20 01:57:33
+0400
+++ groff-1.19.3/src/preproc/preconv/preconv.cpp 2008-08-20 01:57:36
+0400
@@ -22,8 +22,9 @@ Foundation, 51 Franklin St - Fifth Floor
#include "lib.h"
#include <assert.h>
#include <stdlib.h>
+#include <string.h>
#include <errno.h>
#include "errarg.h"
#include "error.h"
#include "localcharset.h"
@@ -44,9 +45,9 @@ Foundation, 51 Franklin St - Fifth Floor
#define MAX_VAR_LEN 100
extern "C" const char *Version_string;
-const char *default_encoding;
+char *default_encoding = NULL;
char user_encoding[MAX_VAR_LEN];
char encoding_string[MAX_VAR_LEN];
int debug_flag = 0;
int raw_flag = 0;
@@ -1098,8 +1099,9 @@ 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"
"-v print version number\n"
@@ -1119,23 +1121,18 @@ main(int argc, char **argv)
// getopt() is called since the usage message shows the default
// encoding.
setlocale(LC_ALL, "");
char *locale = getlocale(LC_CTYPE);
- if (!locale || !strcmp(locale, "C") || !strcmp(locale, "POSIX"))
- default_encoding = "latin1";
- else
- default_encoding = locale_charset();
-
program_name = argv[0];
- int opt;
+ int opt, const_default_locale = 1;
static const struct option long_options[] = {
{ "help", no_argument, 0, 'h' },
{ "version", no_argument, 0, 'v' },
{ NULL, 0, 0, 0 }
};
// 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",
Version_string,
@@ -1157,8 +1154,19 @@ main(int argc, char **argv)
}
else
user_encoding[0] = 0;
break;
+ case 'D':
+ if (optarg) {
+ int len = strlen(optarg) + 1;
+ if ((default_encoding = (char *) malloc(len)) == NULL) {
+ fprintf(stderr, "malloc: %s\n", strerror(errno));
+ exit(1);
+ }
+ strncpy(default_encoding, optarg, len);
+ const_default_locale = 0;
+ }
+ break;
case 'r':
raw_flag = 1;
break;
case 'h':
@@ -1171,16 +1179,24 @@ main(int argc, char **argv)
break;
default:
assert(0);
}
+ if (!default_encoding) {
+ if (!locale || !strcmp(locale, "C") || !strcmp(locale, "POSIX"))
+ default_encoding = "latin1";
+ else
+ default_encoding = (char *) locale_charset();
+ }
int nbad = 0;
if (debug_flag)
fprintf(stderr, "default encoding: `%s'\n", default_encoding);
if (optind >= argc)
nbad += !do_file("-");
else
for (int i = optind; i < argc; i++)
nbad += !do_file(argv[i]);
+ if (!const_default_locale)
+ free(default_encoding);
if (ferror(stdout) || fflush(stdout) < 0)
fatal("output error");
return nbad != 0;
}
--- groff-1.19.3/src/preproc/preconv/preconv.man.fix 2008-08-20 01:57:36
+0400
+++ groff-1.19.3/src/preproc/preconv/preconv.man 2008-08-20 01:57:36
+0400
@@ -73,8 +73,12 @@ options of
.B \-d
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
.BR groff 's
--- groff-1.19.3/src/roff/groff/groff.cpp.fix 2008-08-20 01:57:33 +0400
+++ groff-1.19.3/src/roff/groff/groff.cpp 2008-08-20 02:08:27 +0400
@@ -134,9 +134,9 @@ int main(int argc, char **argv)
{ NULL, 0, 0, 0 }
};
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];
buf[0] = '-';
@@ -155,8 +155,12 @@ int main(int argc, char **argv)
Pargs += buf;
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;
// fall through
@@ -742,9 +746,9 @@ 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);
}
void help()
@@ -789,8 +793,9 @@ void help()
"-S\tenable safer mode (the default)\n"
"-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);
}
--- groff-1.19.3/src/roff/groff/groff.man.fix 2008-08-20 01:57:33 +0400
+++ groff-1.19.3/src/roff/groff/groff.man 2008-08-20 01:57:36 +0400
@@ -49,8 +49,9 @@ groff \- front-end for the groff documen
.OP \-f fam
.OP \-F dir
.OP \-I dir
.OP \-K arg
+.OP \-D arg
.OP \-L arg
.OP \-m name
.OP \-M dir
.OP \-n num
@@ -230,8 +231,19 @@ Implies
.BR \-k .
.
.
.TP
+.BI \-D\ arg
+Set default input encoding used by
+.B preconv
+to
+.IR arg .
+.
+Implies
+.BR \-k .
+.
+.
+.TP
.B \-l
Send the output to a spooler program for printing.
.
The command that should be used for this is specified by the
- preconv: Allow set default encodding,
Alexey Gladkov <=