📄 makeuctb.c
字号:
/* * makeuctb.c, derived from conmakehash.c - kw * * Original comments from conmakehash.c: * * Create arrays for initializing the kernel folded tables (using a hash * table turned out to be to limiting...) Unfortunately we can't simply * preinitialize the tables at compile time since kfree() cannot accept * memory not allocated by kmalloc(), and doing our own memory management * just for this seems like massive overkill. * * Copyright (C) 1995 H. Peter Anvin * * This program is a part of the Linux kernel, and may be freely * copied under the terms of the GNU General Public License (GPL), * version 2, or at your option any later version. */#ifdef NOTDEFINED#include <stdio.h>#include <stdlib.h>#include <sysexits.h>#include <string.h>#include <ctype.h>#else#include "HTUtils.h"#include "tcp.h"/* * Don't try to use LYexit(). */#ifdef exit#undef exit#endif /* exit */#endif /* NODEFINED */#ifndef TOLOWER#define TOLOWER(c) (isupper((unsigned char)c) ? tolower((unsigned char)c) : (c))#endif /* !TOLOWER */#include "UCkd.h"#include "UCDefs.h"#define MAX_FONTLEN 256/* * We don't deal with UCS4 here. - KW */typedef u16 unicode;PRIVATE void usage ARGS1( char *, argv0){ fprintf(stderr, "Usage: \n"); fprintf(stderr, " %s chartable [charsetmimename] [charsetdisplayname]\n", argv0); fprintf(stderr, "Utility to convert .tbl into .h files for Lynx compilation.\n"); exit(EX_USAGE);}/* copied from HTString.c, not everybody has strncasecmp */PUBLIC int strncasecomp ARGS3( CONST char*, a, CONST char *, b, int, n){ CONST char *p = a; CONST char *q = b; for (p = a, q = b; ; p++, q++) { int diff; if (p == (a+n)) return 0; /* Match up to n characters */ if (!(*p && *q)) return (*p - *q); diff = TOLOWER(*p) - TOLOWER(*q); if (diff) return diff; } /*NOTREACHED*/}PRIVATE int getunicode ARGS1( char **, p0){ char *p = *p0; while (*p == ' ' || *p == '\t') p++; if (*p == '-') { return -2; } else if (*p != 'U' || p[1] != '+' || !isxdigit(p[2]) || !isxdigit(p[3]) || !isxdigit(p[4]) || !isxdigit(p[5]) || isxdigit(p[6])) { return -1; } *p0 = p+6; return strtol((p + 2), 0, 16);}/* * Massive overkill, but who cares? */unicode unitable[MAX_FONTLEN][255];int unicount[MAX_FONTLEN];struct unimapdesc_str themap_str = {0, NULL};char *tblname;PRIVATE int RawOrEnc = 0;PRIVATE int Raw_found = 0; /* whether explicit R directive found */PRIVATE void addpair_str ARGS2( char *, str, int, un){ int i; if (un <= 0xfffe) { if (!themap_str.entry_ct) { /* * Initialize the map for replacement strings. */ themap_str.entries = (struct unipair_str *) malloc (2000 * sizeof (struct unipair_str)); if (!themap_str.entries) { fprintf(stderr, "%s: Out of memory\n", tblname); exit(EX_DATAERR); } } else { /* * Check that it isn't a duplicate. */ for (i = 0 ; i < themap_str.entry_ct; i++) { if (themap_str.entries[i].unicode == un ) { themap_str.entries[i].replace_str = str; return; } } } /* * Add to list. */ if (themap_str.entry_ct > 1999) { fprintf(stderr, "ERROR: Only 2000 unicode replacement strings permitted!\n"); exit(EX_DATAERR); } themap_str.entries[themap_str.entry_ct].unicode = un; themap_str.entries[themap_str.entry_ct].replace_str = str; themap_str.entry_ct++; } /* otherwise: ignore */}PRIVATE void addpair ARGS2( int, fp, int, un){ int i; if (!Raw_found) { /* enc not (yet) explicitly given with 'R' */ if (fp >= 128) { if (RawOrEnc != UCT_ENC_8BIT && RawOrEnc <= UCT_ENC_8859) { if (fp < 160) { /* cannot be 8859 */ RawOrEnc = UCT_ENC_8BIT; } else if (fp != 160 && fp != 173) { RawOrEnc = UCT_ENC_8859; /* hmmm.. more tests needed? */ } else if (unicount[fp] == 0 && fp != un) { /* first unicode for fp doesn't map to itself */ RawOrEnc = UCT_ENC_8BIT; } else { RawOrEnc = UCT_ENC_8859; /* hmmm.. more tests needed? */ } } } } if (un <= 0xfffe) { /* * Check that it isn't a duplicate. */ for (i = 0; i < unicount[fp]; i++) { if (unitable[fp][i] == un) { return; } } /* * Add to list. */ if (unicount[fp] > 254) { fprintf(stderr, "ERROR: Only 255 unicodes/glyph permitted!\n"); exit(EX_DATAERR); } unitable[fp][unicount[fp]] = un; unicount[fp]++; } /* otherwise: ignore */}char this_MIMEcharset[UC_MAXLEN_MIMECSNAME +1];char this_LYNXcharset[UC_MAXLEN_LYNXCSNAME +1];char id_append[UC_MAXLEN_ID_APPEND +1] = "_";int this_isDefaultMap = -1;int useDefaultMap = 1;int lowest_eight = 999;PUBLIC int main ARGS2( int, argc, char **, argv){ FILE *ctbl; char buffer[65536]; int fontlen; int i, nuni, nent; int fp0, fp1, un0, un1; char *p, *p1; char *tbuf, ch; if (argc < 2 || argc > 4) { usage(argv[0]); } if (!strcmp(argv[1], "-")) { ctbl = stdin; tblname = "stdin"; } else { ctbl = fopen(tblname = argv[1], "r"); if (!ctbl) { perror(tblname); exit(EX_NOINPUT); } } /* * For now we assume the default font is always 256 characters. */ fontlen = 256; /* * Initialize table. */ for (i = 0; i < fontlen; i++) { unicount[i] = 0; } /* * Now we comes to the tricky part. Parse the input table. */ while (fgets(buffer, sizeof(buffer), ctbl) != NULL) { if ((p = strchr(buffer, '\n')) != NULL) { *p = '\0'; } else { fprintf(stderr, "%s: Warning: line too long or incomplete.\n", tblname); } /* * Syntax accepted: * <fontpos> <unicode> <unicode> ... * <fontpos> <unicode range> <unicode range> ... * <fontpos> idem * <range> idem * <range> <unicode range> * <unicode> :<replace> * <unicode range> :<replace> * <unicode> "<C replace>" * <unicode range> "<C replace>" * * where <range> ::= <fontpos>-<fontpos> * and <unicode> ::= U+<h><h><h><h> * and <h> ::= <hexadecimal digit> * and <replace> any string not containing '\n' or '\0' * and <C replace> any string with C backslash escapes. */ p = buffer; while (*p == ' ' || *p == '\t') { p++; } if (!(*p) || *p == '#') { /* * Skip comment or blank line. */ continue; } switch (*p) { /* * Raw Unicode? I.e. needs some special * processing. One digit code. */ case 'R': if (p[1] == 'a' || p[1] == 'A') { buffer[sizeof(buffer) - 1] = '\0'; if (!strncasecomp(p, "RawOrEnc", 8)) { p += 8; } } p++; while (*p == ' ' || *p == '\t') { p++; } RawOrEnc = strtol(p,0,10); Raw_found = 1; continue; /* * Is this the default table? */ case 'D': if (p[1] == 'e' || p[1] == 'E') { buffer[sizeof(buffer) - 1] = '\0'; if (!strncasecomp(p, "Default", 7)) { p += 7; } } p++; while (*p == ' ' || *p == '\t') { p++; } this_isDefaultMap = (*p == '1' || TOLOWER(*p) == 'y'); continue; /* * Is this the default table? */ case 'F': if (p[1] == 'a' || p[1] == 'A') { buffer[sizeof(buffer) - 1] = '\0'; if (!strncasecomp(p, "FallBack", 8)) { p += 8; } } p++; while (*p == ' ' || *p == '\t') { p++; } useDefaultMap = (*p == '1' || tolower(*p) == 'y'); continue; case 'M': if (p[1] == 'i' || p[1] == 'I') { buffer[sizeof(buffer) - 1] = '\0'; if (!strncasecomp(p, "MIMEName", 8)) { p += 8; } } p++; while (*p == ' ' || *p == '\t') { p++; } sscanf(p,"%40s",this_MIMEcharset); continue; /* * Display charset name for options screen. */ case 'O': if (p[1] == 'p' || p[1] == 'P') { buffer[sizeof(buffer) - 1] = '\0'; if (!strncasecomp(p, "OptionName", 10)) { p += 10; } } p++; while (*p == ' ' || *p == '\t') { p++; } for (i = 0; *p && i < UC_MAXLEN_LYNXCSNAME; p++, i++) { this_LYNXcharset[i] = *p; } this_LYNXcharset[i] = '\0'; continue; } if (*p == 'U') { un0 = getunicode(&p);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -