Репозитории ALT
5.1: | 1.6f-alt11 |
4.1: | 1.6f-alt1 |
4.0: | 1.5m2-alt4 |
+backports: | 1.6f-alt5.M40.1 |
3.0: | 1.5m2-alt3 |
Группа :: Система/Основа
Пакет: man
Главная Изменения Спек Патчи Sources Загрузить Gear Bugs and FR Repocop
Патч: man-1.5m2-alt-recode.patch
Скачать
Скачать
--- man-1.5m2/src/man.c.vns 2004-05-27 17:10:09 +0400
+++ man-1.5m2/src/man.c 2004-05-27 17:13:35 +0400
@@ -30,6 +30,7 @@
#include <errno.h>
#include <unistd.h>
#include <locale.h>
+#include <langinfo.h>
#ifndef R_OK
#define R_OK 4
@@ -520,6 +521,102 @@
return s;
}
+static const char *
+get_locale_charset (void) {
+ static const char *charset;
+
+ if (charset)
+ return charset;
+
+ charset = getenv ("OUTPUT_CHARSET");
+ if (charset)
+ return charset;
+
+ charset = nl_langinfo (CODESET);
+ return charset;
+}
+
+static const char *
+get_man_charset (const char *path) {
+ char *file = my_xsprintf ("%s/.charset", path);
+ FILE *f = fopen (file,"r");
+ free (file);
+
+ if (!f)
+ return 0;
+ else {
+ static char charset [128] = "";
+
+ if (fgets (charset, sizeof charset, f)) {
+ char *p = strchr (charset, '\n');
+ if (p) *p = '\0';
+ }
+ fclose (f);
+ return charset;
+ }
+}
+
+static int
+is_iconv_cmd_valid (const char *cmd) {
+ const char sample[] = "TEST";
+ char *test_cmd = my_xsprintf("echo %s | LC_ALL=C %s 2>/dev/null", sample, cmd);
+ FILE *f = my_popen (test_cmd, "r");
+ free (test_cmd);
+
+ if (!f)
+ return 0;
+ else {
+ int rc = 0;
+ char buff[sizeof sample];
+
+ if (fgets (buff, sizeof buff, f) && !strncmp (buff, sample, sizeof sample - 1))
+ rc = 1;
+
+ pclose (f);
+ return rc;
+ }
+}
+
+static const char *
+make_iconv_cmd (const char *man_path) {
+ static const char *iconv_cmd;
+ static const char *man_charset;
+ const char *locale_charset;
+ const char *charset = get_man_charset (man_path);
+
+ if (!charset)
+ return 0;
+
+ if (man_charset && !strcmp (charset, man_charset))
+ return iconv_cmd;
+
+ locale_charset = get_locale_charset();
+ if (!locale_charset || !*locale_charset)
+ return 0;
+
+ man_charset = charset;
+ if (strcasecmp (man_charset, locale_charset))
+ {
+ const char *cmds[] = { getenv("MAN_ICONV"), getval("ICONV"), "/usr/bin/ionv" } ;
+ unsigned i, n_cmds = sizeof(cmds) / sizeof(cmds[0]);
+
+ for (i = 0; i < n_cmds; ++i) {
+ const char *cmd = cmds[i];
+ if (cmd && *cmd) {
+ char *try = my_xsprintf ("%S -c -f %S",
+ cmd, man_charset);
+ if (is_iconv_cmd_valid (try)) {
+ iconv_cmd = try;
+ break;
+ }
+ fprintf (stderr, "skipping iconv=%s\n", try);
+ free (try);
+ }
+ }
+ }
+ return iconv_cmd;
+}
+
/*
* Create command to format FILE, in the directory PATH/manX
*/
@@ -543,7 +640,7 @@
gripe (NO_CAT_FOR_NONSTD_LL);
expander = get_expander (file);
- converter = get_converter (path);
+ converter = make_iconv_cmd (path);
/* head */
bufh[0] = 0;
@@ -1218,6 +1315,8 @@
CHECK("MAN_HP_DIREXT", 128);
CHECK("PAGER", 128);
CHECK("SYSTEM", 64);
+ CHECK("MAN_ICONV", 128);
+ CHECK("OUTPUT_CHARSET", 128);
/* COLUMNS, LC_ALL, LC_CTYPE, MANPATH, MANWIDTH, MAN_IRIX_CATNAMES,
MAN_ICONV_PATH, MAN_ICONV_OPT, MAN_ICONV_INPUT_CHARSET,
MAN_ICONV_OUTPUT_CHARSET, NLSPATH, PATH */
--- man-1.5m2/src/paths.h.in.vns 2003-09-05 13:48:13 +0400
+++ man-1.5m2/src/paths.h.in 2004-05-27 17:10:09 +0400
@@ -32,6 +32,7 @@
{ "COMPRESS", "@compress@" },
{ "COMPRESS_EXT", "@compress_ext@" }, /* not a path, just a string variable */
{ "DECOMPRESS", "@decompress@" },
+ { "ICONV", "/usr/bin/iconv" }, /* standard glibc iconv command */
{ "MANSECT", "@sections@"}, /* idem */
{ "MANDEFOPTIONS", ""} /* idem */
};