📄 ucdomap.c
字号:
PRIVATE u16 **uni_pagedir[32] ={ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};PRIVATE char* **uni_pagedir_str[32] ={ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};PRIVATE u16 * UC_current_unitable = NULL;PRIVATE struct unimapdesc_str *UC_current_unitable_str = NULL;/* * Keep a second set of structures for the translation designated * as "default" - kw */PRIVATE int unidefault_contents_valid = 0; /* Use ASCII-only mode for bootup*/PRIVATE int unidefault_str_contents_valid = 0;static u16 **unidefault_pagedir[32] ={ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};static char* **unidefault_pagedir_str[32] ={ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};PRIVATE u16 * UC_default_unitable = NULL;PRIVATE struct unimapdesc_str *UC_default_unitable_str = NULL;PRIVATE int con_insert_unipair ARGS3( u16, unicode, u16, fontpos, int, fordefault){ int i, n; u16 **p1, *p2; if(fordefault) p1 = unidefault_pagedir[n = unicode >> 11]; else p1 = uni_pagedir[n = unicode >> 11]; if (!p1) { p1 = (u16* *)malloc(32*sizeof(u16 *)); if (fordefault) unidefault_pagedir[n] = p1; else uni_pagedir[n] = p1; if ( !p1 ) return -ENOMEM; for (i = 0; i < 32; i++) { p1[i] = NULL; } } if (!(p2 = p1[n = (unicode >> 6) & 0x1f])) { p2 = p1[n] = (u16 *)malloc(64*sizeof(u16)); if (!p2) return -ENOMEM; for (i = 0; i < 64; i++) { p2[i] = 0xffff; /* No glyph for this character (yet) */ } } p2[unicode & 0x3f] = fontpos; return 0;}PRIVATE int con_insert_unipair_str ARGS3( u16, unicode, char *, replace_str, int, fordefault){ int i, n; char ***p1, **p2; if(fordefault) p1 = unidefault_pagedir_str[n = unicode >> 11]; else p1 = uni_pagedir_str[n = unicode >> 11]; if (!p1) { p1 = (char** *)malloc(32*sizeof(char **)); if (fordefault) unidefault_pagedir_str[n] = p1; else uni_pagedir_str[n] = p1; if ( !p1 ) return -ENOMEM; for (i = 0; i < 32; i++) { p1[i] = NULL; } } if (!(p2 = p1[n = (unicode >> 6) & 0x1f])) { p2 = p1[n] = (char* *)malloc(64*sizeof(char *)); if (!p2) return -ENOMEM; for (i = 0; i < 64; i++) { p2[i] = NULL; /* No replace string this character (yet) */ } } p2[unicode & 0x3f] = replace_str; return 0;}/* * ui arg was a leftover, deleted. - KW */PRIVATE void con_clear_unimap ARGS1( int, fordefault){ int i, j; u16 **p1; if (fordefault) { for (i = 0; i < 32; i++) { if ((p1 = unidefault_pagedir[i]) != NULL) { for (j = 0; j < 32; j++) { FREE(p1[j]); } FREE(p1); } unidefault_pagedir[i] = NULL; } unidefault_contents_valid = 1; } else { for (i = 0; i < 32; i++) { if ((p1 = uni_pagedir[i]) != NULL) { for (j = 0; j < 32; j++) { FREE(p1[j]); } FREE(p1); } uni_pagedir[i] = NULL; } hashtable_contents_valid = 1; }}PRIVATE void con_clear_unimap_str ARGS1(int, fordefault){ int i, j; char ***p1; if (fordefault) { for (i = 0; i < 32; i++) { if ((p1 = unidefault_pagedir_str[i]) != NULL) { for (j = 0; j < 32; j++) { FREE(p1[j]); } FREE(p1); } unidefault_pagedir_str[i] = NULL; } unidefault_str_contents_valid = 1; /* ??? probably no use... */ } else { for (i = 0; i < 32; i++) { if ((p1 = uni_pagedir_str[i]) != NULL) { for (j = 0; j < 32; j++) { FREE(p1[j]); } FREE(p1); } uni_pagedir_str[i] = NULL; } hashtable_str_contents_valid = 1; /* ??? probably no use... */ }}#ifdef NOTDEFINEDPRIVATE int con_set_unimap ARGS2( u16, ct, struct unipair *, list){ int err = 0, err1, i; while (ct--) { if ((err1 = con_insert_unipair(list->unicode, list->fontpos)) != 0) { err = err1; } list++; } for (i = 0; i <= 3; i++) { set_inverse_transl(i); /* Update all inverse translations */ } return err;}#endif /* NOTDEFINED *//* * Loads the unimap for the hardware font, as defined in uni_hash.tbl. * The representation used was the most compact I could come up * with. This routine is executed at sys_setup time, and when the * PIO_FONTRESET ioctl is called. */PRIVATE void con_set_default_unimap NOARGS{ int i, j; u16 *p; /* * The default font is always 256 characters. */ con_clear_unimap(1); p = dfont_unitable; for (i = 0; i < 256; i++) { for (j = dfont_unicount[i]; j; j--) { con_insert_unipair(*(p++), i, 1); } }#if 0 for (i = 0; i <= 3; i++) { set_inverse_transl(i); /* Update all inverse translations */ }#endif UC_default_unitable = dfont_unitable; con_clear_unimap_str(1); UC_con_set_unimap_str(dfont_replacedesc.entry_ct, repl_map, 1); UC_default_unitable_str = &dfont_replacedesc;}PUBLIC int UCNumCharsets = 0;PUBLIC int UCLYhndl_HTFile_for_unspec = -1;PUBLIC int UCLYhndl_HTFile_for_unrec = -1;PUBLIC int UCLYhndl_for_unspec = -1;PUBLIC int UCLYhndl_for_unrec = -1;PRIVATE int UC_con_set_unimap ARGS2( int, UC_charset_out_hndl, int, update_flag){ int i, j; u16 *p; if (!UC_valid_UC_charset(UC_charset_out_hndl)) { if (TRACE) fprintf(stderr, "UC_con_set_unimap: Invalid charset handle %d.\n", UC_charset_out_hndl); return -1; } p = UCInfo[UC_charset_out_hndl].unitable; if (p == UC_current_unitable) { /* test whether pointers are equal */ return update_flag; /* nothing to be done */ } UC_current_unitable = p; /* * The font is always 256 characters - so far. */ con_clear_unimap(0); for (i = 0; i < 256; i++) { for (j = UCInfo[UC_charset_out_hndl].unicount[i]; j; j--) { con_insert_unipair(*(p++), i, 0); } } if (update_flag) { for (i = 0; i <= 3; i++) { set_inverse_transl(i); /* Update all inverse translations */ } } return 0;}PRIVATE int UC_con_set_unimap_str ARGS3( u16, ct, struct unipair_str *, list, int, fordefault){ int err = 0, err1; while (ct--) { if ((err1 = con_insert_unipair_str(list->unicode, list->replace_str, fordefault)) != 0) { err = err1; } list++; } /* * No inverse translations for replacement strings! */ if (!err) { if (fordefault) unidefault_str_contents_valid = 1; else hashtable_str_contents_valid = 1; } return err;}#ifdef NOTDEFINEDPRIVATE int con_get_unimap ARGS3( u16, ct, u16 *, uct, struct unipair *, list){ int i, j, k, ect; u16 **p1, *p2; ect = 0; if (hashtable_contents_valid) { for (i = 0; i < 32; i++) { if ((p1 = uni_pagedir[i]) != NULL) { for (j = 0; j < 32; j++) { if ((p2 = *(p1++)) != NULL) { for (k = 0; k < 64; k++) { if (*p2 < MAX_GLYPH && ect++ < ct) { list->unicode = (u16) ((i<<11)+(j<<6)+k); list->fontpos = (u16) *p2; list++; } p2++; } } } } } } *uct = ect; return ((ect <= ct) ? 0 : -ENOMEM);}#endif /* NOTDEFINED */PRIVATE int conv_uni_to_pc ARGS2( long, ucs, int, usedefault){ int h; u16 **p1, *p2; /* * Only 16-bit codes supported at this time. */ if (ucs > 0xffff) { /* * U+FFFD: REPLACEMENT CHARACTER. */ ucs = 0xfffd; } else if (ucs < 0x20 || ucs >= 0xfffe) { /* * Not a printable character. */ return -1; } else if (ucs == 0xfeff || (ucs >= 0x200a && ucs <= 0x200f)) { /* * Zero-width space. */ return -2; } else if ((ucs & ~UNI_DIRECT_MASK) == UNI_DIRECT_BASE) { /* * UNI_DIRECT_BASE indicates the start of the region in the * User Zone which always has a 1:1 mapping to the currently * loaded font. The UNI_DIRECT_MASK indicates the bit span * of the region. */ return (ucs & UNI_DIRECT_MASK); } if (usedefault) { if (!unidefault_contents_valid) return -3; p1 = unidefault_pagedir[ucs >> 11]; } else { if (!hashtable_contents_valid) return -3; p1 = uni_pagedir[ucs >> 11]; } if (p1 && (p2 = p1[(ucs >> 6) & 0x1f]) && (h = p2[ucs & 0x3f]) < MAX_GLYPH) { return h; } /* * Not found. */ return -4;}/* * Note: contents of outbuf is not changes for negative return value! */PRIVATE int conv_uni_to_str ARGS4( char*, outbuf, int, buflen, long, ucs, int, usedefault){ char *h; char ***p1, **p2; /* * Only 16-bit codes supported at this time. */ if (ucs > 0xffff) { /* * U+FFFD: REPLACEMENT CHARACTER. */ ucs = 0xfffd; /* * Maybe the following two cases should be allowed here?? - KW */ } else if (ucs < 0x20 || ucs >= 0xfffe) { /* * Not a printable character. */ return -1; } else if (ucs == 0xfeff || (ucs >= 0x200a && ucs <= 0x200f)) { /* * Zero-width space. */ return -2;#ifdef NOTDEFINED /* We don't handle the following here: */ } else if ((ucs & ~UNI_DIRECT_MASK) == UNI_DIRECT_BASE) { /* * UNI_DIRECT_BASE indicates the start of the region in the * User Zone which always has a 1:1 mapping to the currently * loaded font. The UNI_DIRECT_MASK indicates the bit span * of the region. */ return ucs & UNI_DIRECT_MASK;#endif /* NOTDEFINED */ } if (usedefault) { if (!unidefault_str_contents_valid) return -3; p1 = unidefault_pagedir_str[ucs >> 11]; } else { if (!hashtable_str_contents_valid) return -3; p1 = uni_pagedir_str[ucs >> 11]; } if (p1 && (p2 = p1[(ucs >> 6) & 0x1f]) && (h = p2[ucs & 0x3f])) { strncpy (outbuf,h,(size_t) (buflen-1)); return 1; /* ok ! */ } /* * Not found. */ return -4;}PUBLIC int UCInitialized = 0;/* * [ original comment: - KW ] * This is called at sys_setup time, after memory and the console are * initialized. It must be possible to call kmalloc(..., GFP_KERNEL) * from this function, hence the call from sys_setup. */PRIVATE void UCconsole_map_init NOARGS{ con_set_default_unimap(); UCInitialized = 1;}/* * OK now, finally, some stuff that is more specifically for Lynx: - KW */#ifdef NOTDEFINEDPUBLIC int UCGetcharset_byMIMEname PARAMS((CONST char * UC_MIMEcharset));PUBLIC int UCGetcharset_byLYNXname PARAMS((CONST char * UC_LYNXcharset));#endif /* NOTDEFINED */PUBLIC int UCTransUniChar ARGS2( long, unicode, int, charset_out){ int rc = 0; int UChndl_out; int isdefault, trydefault = 0; u16 * ut; if ((UChndl_out = LYCharSet_UC[charset_out].UChndl) < 0) { if ((UChndl_out = default_UChndl) < 0) return -12;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -