📄 charset.c
字号:
/*** Copyright (C) 1991, 1997-2000 Free Software Foundation, Inc.**** This file is part of TACK.**** TACK is free software; you can redistribute it and/or modify** it under the terms of the GNU General Public License as published by** the Free Software Foundation; either version 2, or (at your option)** any later version.**** TACK is distributed in the hope that it will be useful,** but WITHOUT ANY WARRANTY; without even the implied warranty of** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the** GNU General Public License for more details.**** You should have received a copy of the GNU General Public License** along with TACK; see the file COPYING. If not, write to** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,** Boston, MA 02110-1301, USA*/#include <tack.h>MODULE_ID("$Id: charset.c,v 1.10 2005/09/17 19:49:16 tom Exp $")/* Menu definitions for alternate character set and SGR tests.*/static void charset_bel(struct test_list *t, int *state, int *ch);static void charset_flash(struct test_list *t, int *state, int *ch);static void charset_civis(struct test_list *t, int *state, int *ch);static void charset_cvvis(struct test_list *t, int *state, int *ch);static void charset_cnorm(struct test_list *t, int *state, int *ch);static void charset_hs(struct test_list *t, int *state, int *ch);static void charset_status(struct test_list *t, int *state, int *ch);static void charset_dsl(struct test_list *t, int *state, int *ch);static void charset_enacs(struct test_list *t, int *state, int *ch);static void charset_smacs(struct test_list *t, int *state, int *ch);static void charset_attributes(struct test_list *t, int *state, int *ch);static void charset_sgr(struct test_list *t, int *state, int *ch);struct test_list acs_test_list[] = { {0, 0, 0, 0, "e) edit terminfo", 0, &edit_menu}, {MENU_NEXT, 3, "bel", 0, 0, charset_bel, 0}, {MENU_NEXT, 3, "flash", 0, 0, charset_flash, 0}, {MENU_NEXT, 3, "civis", 0, 0, charset_civis, 0}, {MENU_NEXT, 3, "cvvis", 0, 0, charset_cvvis, 0}, {MENU_NEXT, 3, "cnorm", 0, 0, charset_cnorm, 0}, {MENU_NEXT, 3, "hs", 0, 0, charset_hs, 0}, {MENU_NEXT, 3, "tsl) (fsl) (wsl", "hs", 0, charset_status, 0}, {MENU_NEXT, 3, "dsl", "hs", 0, charset_dsl, 0}, {MENU_NEXT, 0, "acsc) (enacs) (smacs) (rmacs", 0, 0, charset_enacs, 0}, {MENU_NEXT, 0, "smacs) (rmacs", 0, 0, charset_smacs, 0}, {MENU_NEXT, 11, 0, 0, 0, charset_attributes, 0}, {MENU_NEXT, 11, "sgr) (sgr0", "ma", 0, charset_sgr, 0}, {MENU_LAST, 0, 0, 0, 0, 0, 0}};const struct mode_list alt_modes[] = { {"normal", "(sgr0)", "(sgr0)", 1}, {"standout", "(smso)", "(rmso)", 2}, {"underline", "(smul)", "(rmul)", 4}, {"reverse", "(rev)", "(sgr0)", 8}, {"blink", "(blink)", "(sgr0)", 16}, {"dim", "(dim)", "(sgr0)", 32}, {"bold", "(bold)", "(sgr0)", 64}, {"invis", "(invis)", "(sgr0)", 128}, {"protect", "(prot)", "(sgr0)", 256}, {"altcharset", "(smacs)", "(rmacs)", 512}};/* On many terminals the underline attribute is the last scan line. This is OK unless the following line is reverse video. Then the underline attribute does not show up. The following map will reorder the display so that the underline attribute will show up. */const int mode_map[10] = {0, 1, 3, 4, 5, 6, 7, 8, 9, 2};struct graphics_pair { unsigned char c; const char *name;};static struct graphics_pair glyph[] = { {'+', "arrow pointing right"}, {',', "arrow pointing left"}, {'.', "arrow pointing down"}, {'0', "solid square block"}, {'i', "lantern symbol"}, {'-', "arrow pointing up"}, {'`', "diamond"}, {'a', "checker board (stipple)"}, {'f', "degree symbol"}, {'g', "plus/minus"}, {'h', "board of squares"}, {'j', "lower right corner"}, {'k', "upper right corner"}, {'l', "upper left corner"}, {'m', "lower left corner"}, {'n', "plus"}, {'o', "scan line 1"}, {'p', "scan line 3"}, {'q', "horizontal line"}, {'r', "scan line 7"}, {'s', "scan line 9"}, {'t', "left tee (|-)"}, {'u', "right tee (-|)"}, {'v', "bottom tee(_|_)"}, {'w', "top tee (T)"}, {'x', "vertical line"}, {'y', "less/equal"}, {'z', "greater/equal"}, {'{', "Pi"}, {'|', "not equal"}, {'}', "UK pound sign"}, {'~', "bullet"}, {'\0', "\0"}};/*** charset_hs(test_list, status, ch)**** (hs) test Has status line*/static voidcharset_hs( struct test_list *t, int *state, int *ch){ if (has_status_line != 1) { ptext("(hs) Has-status line is not defined. "); generic_done_message(t, state, ch); }}/*** charset_status(test_list, status, ch)**** (tsl) (fsl) (wsl) test Status line*/static voidcharset_status( struct test_list *t, int *state, int *ch){ int i, max; char *s; static char m[] = "*** status line *** 123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789."; if (has_status_line != 1) { return; } put_clear(); max = width_status_line == -1 ? columns : width_status_line; sprintf(temp, "Terminal has status line of %d characters", max); ptextln(temp); put_str("This line s"); s = tparm(to_status_line, 0); tc_putp(s); for (i = 0; i < max; i++) putchp(m[i]); tc_putp(from_status_line); putln("hould not be broken."); ptextln("If the previous line is not a complete sentence then (tsl) to-status-line, (fsl) from-status-line, or (wsl) width-of-status-line is incorrect." ); generic_done_message(t, state, ch);}/*** charset_dsl(test_list, status, ch)**** (dsl) test Disable status line*/static voidcharset_dsl( struct test_list *t, int *state, int *ch){ if (has_status_line != 1) { return; } if (dis_status_line) { ptextln("Disable status line (dsl)"); tc_putp(dis_status_line); ptext("If you can still see the status line then (dsl) disable-status-line has failed. "); } else { ptext("(dsl) Disable-status-line is not defined. "); } generic_done_message(t, state, ch);}voideat_cookie(void){ /* put a blank if this is not a magic cookie terminal */ if (magic_cookie_glitch < 1) putchp(' ');}voidput_mode(char *s){ /* send the attribute string (with or without % execution) */ tc_putp(tparm(s)); /* allow % execution */}voidset_attr(int a){ /* set the attribute from the bits in a */ int i, b[32]; if (magic_cookie_glitch > 0) { char_count += magic_cookie_glitch; } if (a == 0 && exit_attribute_mode) { put_mode(exit_attribute_mode); return; } for (i = 0; i < 31; i++) { b[i] = (a >> i) & 1; } tc_putp(tparm(set_attributes, b[1], b[2], b[3], b[4], b[5], b[6], b[7], b[8], b[9]));}/*** charset_sgr(test_list, status, ch)**** (sgr) test Set Graphics Rendition*/static voidcharset_sgr( struct test_list *t, int *state, int *ch){ int i, j; if (!set_attributes) { ptext("(sgr) Set-graphics-rendition is not defined. "); generic_done_message(t, state, ch); return; } if (!exit_attribute_mode) { ptextln("(sgr0) Set-graphics-rendition-zero is not defined."); /* go ahead and test anyway */ } ptext("Test video attributes (sgr)"); for (i = 0; i < (int) (sizeof(alt_modes) / sizeof(struct mode_list)); i++) { put_crlf(); sprintf(temp, "%d %-20s", i, alt_modes[i].name); put_str(temp); set_attr(alt_modes[i].number); sprintf(temp, "%s", alt_modes[i].name); put_str(temp); set_attr(0); } putln("\n\nDouble mode test"); for (i = 0; i <= 9; i++) { sprintf(temp, " %2d ", mode_map[i]); put_str(temp); } for (i = 0; i <= 9; i++) { put_crlf(); sprintf(temp, "%d", mode_map[i]); put_str(temp); for (j = 0; j <= 9; j++) { eat_cookie(); set_attr((1 << mode_map[i]) | (1 << mode_map[j])); put_str("Aa"); set_attr(0); if (j < 9) eat_cookie(); } } put_crlf();#ifdef max_attributes if (max_attributes >= 0) { sprintf(temp, "(ma) Maximum attributes %d ", max_attributes); ptext(temp); }#endif generic_done_message(t, state, ch);}/*** test_one_attr(mode-number, begin-string, end-string)**** Display one attribute line.*/static voidtest_one_attr( int n, char *begin_mode, char *end_mode){ int i; sprintf(temp, "%-10s %s ", alt_modes[n].name, alt_modes[n].begin_mode); ptext(temp); for (; char_count < 19;) { putchp(' '); } if (begin_mode) { putchp('.'); put_mode(begin_mode); put_str(alt_modes[n].name); for (i = strlen(alt_modes[n].name); i < 13; i++) { putchp(' '); } if (end_mode) { put_mode(end_mode); sprintf(temp, ". %s", alt_modes[n].end_mode); } else { set_attr(0); strcpy(temp, ". (sgr)"); } ptextln(temp); } else { for (i = 0; i < magic_cookie_glitch; i++) putchp('*'); put_str("*** missing ***"); for (i = 0; i < magic_cookie_glitch; i++) putchp('*'); put_crlf(); }}/*** charset_attributes(test_list, status, ch)**** Test SGR*/static voidcharset_attributes( struct test_list *t, int *state, int *ch){ putln("Test video attributes"); test_one_attr(1, enter_standout_mode, exit_standout_mode); test_one_attr(2, enter_underline_mode, exit_underline_mode); test_one_attr(9, enter_alt_charset_mode, exit_alt_charset_mode); if (!exit_attribute_mode && !set_attributes) { ptextln("(sgr0) exit attribute mode is not defined.");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -