Lines 80-87
Link Here
|
80 |
int fsstnd; |
80 |
int fsstnd; |
81 |
int noautopath; |
81 |
int noautopath; |
82 |
int nocache; |
82 |
int nocache; |
83 |
static int is_japanese; |
83 |
|
84 |
static char *language; |
|
|
85 |
static char **section_list; |
84 |
static char **section_list; |
86 |
|
85 |
|
87 |
#ifdef DO_COMPRESS |
86 |
#ifdef DO_COMPRESS |
Lines 442-448
Link Here
|
442 |
} |
441 |
} |
443 |
|
442 |
|
444 |
static int |
443 |
static int |
445 |
is_lang_page (char *lang, const char *file) { |
444 |
is_lang_page (const char *lang, const char *file) { |
446 |
char lang_path[16] = ""; |
445 |
char lang_path[16] = ""; |
447 |
|
446 |
|
448 |
snprintf(lang_path, sizeof(lang_path), "/%s/", lang); |
447 |
snprintf(lang_path, sizeof(lang_path), "/%s/", lang); |
Lines 457-478
Link Here
|
457 |
return 0; |
456 |
return 0; |
458 |
} |
457 |
} |
459 |
|
458 |
|
|
|
459 |
/* we need to pass, as a parameter, what the character set of a man page |
460 |
* is likely to be if it is not utf-8, so that nroff can iconv it to utf-8. |
461 |
* |
462 |
* the character set/encoding is "guessed" based on the most common non-Unicode |
463 |
* encoding used for man pages. |
464 |
*/ |
465 |
|
466 |
typedef struct { |
467 |
const char *lang; |
468 |
const char *encoding; |
469 |
} lc2enc_t; |
470 |
|
471 |
static const lc2enc_t lc2enc[] = { |
472 |
{ "C", "ASCII" }, |
473 |
{ "de", "ISO-8859-1" }, |
474 |
{ "en", "ISO-8859-1" }, |
475 |
{ "es", "ISO-8859-1" }, |
476 |
{ "fr", "ISO-8859-1" }, |
477 |
{ "it", "ISO-8859-1" }, |
478 |
{ "pt", "ISO-8859-1" }, |
479 |
{ "hr", "ISO-8859-2" }, |
480 |
{ "cs", "ISO-8859-2" }, |
481 |
{ "et", "ISO-8859-2" }, |
482 |
{ "hu", "ISO-8859-2" }, |
483 |
{ "lv", "ISO-8859-2" }, |
484 |
{ "lt", "ISO-8859-2" }, |
485 |
{ "pl", "ISO-8859-2" }, |
486 |
{ "ro", "ISO-8859-2" }, |
487 |
{ "sk", "ISO-8859-2" }, |
488 |
{ "sl", "ISO-8859-2" }, |
489 |
{ "bg", "KOI8-R" }, |
490 |
{ "be", "KOI8-R" }, |
491 |
{ "mk", "KOI8-R" }, |
492 |
{ "ru", "KOI8-R" }, |
493 |
{ "sh", "KOI8-R" }, |
494 |
{ "uk", "KOI8-R" }, |
495 |
{ "el", "ISO-8859-7" }, |
496 |
{ "tr", "ISO-8859-9" }, |
497 |
{ "ja", "EUC-JP" }, |
498 |
{ "ko", "EUC-KR" }, |
499 |
{ "zh_CN", "GB2312" }, |
500 |
{ "zh_HK", "BIG5" }, |
501 |
{ "zh_TW", "BIG5" }, |
502 |
{ NULL } |
503 |
}; |
504 |
|
505 |
static const char * |
506 |
get_legacy_encoding(const char *file) { |
507 |
const lc2enc_t *ptr; |
508 |
|
509 |
for (ptr = lc2enc; ptr->lang != NULL; ptr++) { |
510 |
if (is_lang_page(ptr->lang, file)) { |
511 |
return ptr->encoding; |
512 |
} |
513 |
} |
514 |
return "ISO-8859-1"; |
515 |
} |
516 |
|
460 |
static int |
517 |
static int |
461 |
parse_roff_directive (char *cp, const char *file, char *buf, int buflen) { |
518 |
parse_roff_directive (char *cp, const char *file, char *buf, int buflen) { |
462 |
char c; |
519 |
char c; |
463 |
int tbl_found = 0; |
520 |
int tbl_found = 0; |
464 |
int use_jroff; |
|
|
465 |
|
466 |
use_jroff = (is_japanese && |
467 |
(strstr(file, "/jman/") || is_lang_page(language, file))); |
468 |
|
521 |
|
469 |
while ((c = *cp++) != '\0') { |
522 |
while ((c = *cp++) != '\0') { |
470 |
switch (c) { |
523 |
switch (c) { |
471 |
case 'e': |
524 |
case 'e': |
472 |
if (debug) |
525 |
if (debug) |
473 |
gripe (FOUND_EQN); |
526 |
gripe (FOUND_EQN); |
474 |
add_directive((do_troff ? "EQN" : use_jroff ? "JNEQN": "NEQN"), |
527 |
add_directive((do_troff ? "EQN" : "NEQN"), file, buf, buflen); |
475 |
file, buf, buflen); |
|
|
476 |
break; |
528 |
break; |
477 |
|
529 |
|
478 |
case 'g': |
530 |
case 'g': |
Lines 520-528
Link Here
|
520 |
if (*buf == 0) |
572 |
if (*buf == 0) |
521 |
return 1; |
573 |
return 1; |
522 |
|
574 |
|
523 |
add_directive (do_troff ? "TROFF" : use_jroff ? "JNROFF" : "NROFF", |
575 |
add_directive (do_troff ? "TROFF" : "NROFF", "", buf, buflen); |
524 |
"", buf, buflen); |
|
|
525 |
|
576 |
|
|
|
577 |
if (!do_troff && strstr(buf, "NROFF_OLD_CHARSET") != NULL) { |
578 |
const char *encoding = NULL; |
579 |
size_t len = strlen("NROFF_OLD_CHARSET"); |
580 |
char *p = strstr(buf, "NROFF_OLD_CHARSET"); |
581 |
|
582 |
if (debug) { |
583 |
fprintf(stderr, "\nfound '%s' in path\n", "NROFF_OLD_CHARSET"); |
584 |
} |
585 |
encoding = get_legacy_encoding(file); |
586 |
if (debug) { |
587 |
fprintf(stderr, "\nold charset of '%s' is '%s'\n", file, encoding); |
588 |
} |
589 |
if (strlen(encoding) < len) { |
590 |
memmove(p, p + len, strlen(p + len) + 1); |
591 |
memmove(p + strlen(encoding), p, strlen(p) + 1); |
592 |
memcpy(p, encoding, strlen(encoding)); |
593 |
} |
594 |
} |
595 |
|
526 |
if (tbl_found && !do_troff && *getval("COL")) |
596 |
if (tbl_found && !do_troff && *getval("COL")) |
527 |
add_directive ("COL", "", buf, buflen); |
597 |
add_directive ("COL", "", buf, buflen); |
528 |
|
598 |
|
Lines 1181-1202
Link Here
|
1181 |
return status; |
1251 |
return status; |
1182 |
} |
1252 |
} |
1183 |
|
1253 |
|
1184 |
/* Special code for Japanese (to pick jnroff instead of nroff, etc.) */ |
|
|
1185 |
static void |
1186 |
setlang(void) { |
1187 |
char *lang; |
1188 |
|
1189 |
/* We use getenv() instead of setlocale(), because of |
1190 |
glibc 2.1.x security policy for SetUID/SetGID binary. */ |
1191 |
if ((lang = getenv("LANG")) == NULL && |
1192 |
(lang = getenv("LC_ALL")) == NULL && |
1193 |
(lang = getenv("LC_CTYPE")) == NULL) |
1194 |
/* nothing */; |
1195 |
|
1196 |
language = lang; |
1197 |
is_japanese = (lang && strncmp(lang, "ja", 2) == 0); |
1198 |
} |
1199 |
|
1200 |
/* |
1254 |
/* |
1201 |
* Handle the apropos option. Cheat by using another program. |
1255 |
* Handle the apropos option. Cheat by using another program. |
1202 |
*/ |
1256 |
*/ |
Lines 1263-1272
Link Here
|
1263 |
setlocale(LC_MESSAGES, ""); |
1317 |
setlocale(LC_MESSAGES, ""); |
1264 |
#endif |
1318 |
#endif |
1265 |
|
1319 |
|
1266 |
/* No doubt we'll need some generic language code here later. |
|
|
1267 |
For the moment only Japanese support. */ |
1268 |
setlang(); |
1269 |
|
1270 |
/* Handle /usr/man/man1.Z/name.1 nonsense from HP */ |
1320 |
/* Handle /usr/man/man1.Z/name.1 nonsense from HP */ |
1271 |
dohp = getenv("MAN_HP_DIREXT"); /* .Z */ |
1321 |
dohp = getenv("MAN_HP_DIREXT"); /* .Z */ |
1272 |
|
1322 |
|