?? fun.c
字號:
/*** Copyright (C) 1991, 1997 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., 59 Temple Place - Suite 330,** Boston, MA 02111-1307, USA.*/#include <tack.h>MODULE_ID("$Id: fun.c,v 1.3 2000/03/04 20:29:21 tom Exp $")/* * Test the function keys on the terminal. The code for echo tests * lives here too. */static void funkey_keys(struct test_list *, int *, int *);static void funkey_meta(struct test_list *, int *, int *);static void funkey_label(struct test_list *, int *, int *);static void funkey_prog(struct test_list *, int *, int *);static void funkey_local(struct test_list *, int *, int *);struct test_list funkey_test_list[] = { {0, 0, 0, 0, "e) edit terminfo", 0, &edit_menu}, {MENU_CLEAR + FLAG_FUNCTION_KEY, 0, 0, 0, "f) show a list of function keys", show_report, 0}, {MENU_NEXT | MENU_CLEAR, 0, "smkx) (rmkx", 0, "k) test function keys", funkey_keys, 0}, {MENU_NEXT, 10, "km", "smm rmm", 0, funkey_meta, 0}, {MENU_NEXT, 8, "nlab) (smln) (pln) (rmln", "lw lh", 0, funkey_label, 0}, {MENU_NEXT, 2, "pfx", 0, 0, funkey_prog, 0}, {MENU_NEXT, 2, "pfloc", 0, 0, funkey_local, 0}, {MENU_LAST, 0, 0, 0, 0, 0, 0}};static void printer_on(struct test_list *, int *, int *);static void printer_mc0(struct test_list *, int *, int *);struct test_list printer_test_list[] = { {0, 0, 0, 0, "e) edit terminfo", 0, &edit_menu}, {MENU_NEXT | MENU_CLEAR, 0, "mc4) (mc5) (mc5i", 0, 0, printer_on, 0}, {MENU_NEXT | MENU_CLEAR, 0, "mc0", 0, 0, printer_mc0, 0}, {MENU_LAST, 0, 0, 0, 0, 0, 0}};#define MAX_STRINGS STRCOUNT/* scan code externals */extern int scan_max; /* length of longest scan code */extern char **scan_up, **scan_down, **scan_name;extern int *scan_tested, *scan_length;/* local definitions */static const char *fk_name[MAX_STRINGS];static char *fkval[MAX_STRINGS];static char *fk_label[MAX_STRINGS]; /* function key labels (if any) */static int fk_tested[MAX_STRINGS];static int fkmax = 1; /* length of longest key */static int got_labels = 0; /* true if we have some labels */static int key_count = 0;static int end_state;/* unknown function keys */#define MAX_FK_UNK 50static char *fk_unknown[MAX_FK_UNK];static int fk_length[MAX_FK_UNK];static int funk;/*** keys_tested(first-time, show-help, hex-output)**** Display a list of the keys not tested.*/static voidkeys_tested( int first_time, int show_help, int hex_output){ int i, l; char outbuf[256]; put_clear(); tty_set(); flush_input(); if (got_labels) { putln("Function key labels:"); for (i = 0; i < key_count; ++i) { if (fk_label[i]) { sprintf(outbuf, "%s %s", fk_name[i] ? fk_name[i] : "??", fk_label[i]); put_columns(outbuf, strlen(outbuf), 16); } } put_newlines(2); } if (funk) { putln("The following keys are not defined:"); for (i = 0; i < funk; ++i) { put_columns(fk_unknown[i], fk_length[i], 16); } put_mode(exit_attribute_mode); put_newlines(2); } if (first_time) { putln("The following keys are defined:"); } else { putln("The following keys have not been tested:"); } if (scan_mode) { for (i = 0; scan_down[i]; i++) { if (!scan_tested[i]) { if (hex_output) { strcpy(outbuf, hex_expand_to(scan_down[i], 3)); } else { strcpy(outbuf, expand(scan_down[i])); } l = expand_chars; if (hex_output) { strcat(outbuf, hex_expand_to(scan_up[i], 3)); } else { strcat(outbuf, expand(scan_up[i])); } expand_chars += l; l = strlen(scan_name[i]); if (((char_count + 16) & ~15) + ((expand_chars + 7) & ~7) + l >= columns) { put_crlf(); } else if (char_count + 24 > columns) { put_crlf(); } else if (char_count) { putchp(' '); } put_columns(outbuf, expand_chars, 16); put_columns(scan_name[i], l, 8); } } } else { for (i = 0; i < key_count; i++) { if (!fk_tested[i]) { if (hex_output) { strcpy(outbuf, hex_expand_to(fkval[i], 3)); } else { strcpy(outbuf, expand(fkval[i])); } l = strlen(fk_name[i]); if (((char_count + 16) & ~15) + ((expand_chars + 7) & ~7) + l >= columns) { put_crlf(); } else if (char_count + 24 > columns) { put_crlf(); } else if (char_count) { putchp(' '); } put_columns(outbuf, expand_chars, 16); put_columns(fk_name[i], l, 8); } } } put_newlines(2); if (show_help) { ptextln("Hit any function key. Type 'end' to quit. Type ? to update the display."); put_crlf(); }}/*** enter_key(name, value, label)**** Enter a function key into the data base*/voidenter_key( const char *name, char *value, char *lab){ int j; if (value) { j = strlen(value); fkmax = fkmax > j ? fkmax : j; /* do not permit duplicates */ for (j = 0; j < key_count; j++) { if (!strcmp(fk_name[j], name)) { return; } } fkval[key_count] = value; fk_tested[key_count] = 0; fk_label[key_count] = lab; fk_name[key_count++] = name; if (lab) { got_labels = TRUE; } }}static voidfresh_line(void){ /* clear the line for a new function key line */ if (over_strike) { put_crlf(); } else { put_cr(); if (clr_eol) { tc_putp(clr_eol); } else { put_str(" \r"); } }}static intend_funky(int ch){ /* return true if this is the end */ switch (ch) { case 'e': case 'E': end_state = 'e'; break; case 'n': case 'N': if (end_state == 'e') { end_state = 'n'; } else { end_state = 0; } break; case 'd': case 'D': if (end_state == 'n') { end_state = 'd'; } else { end_state = 0; } break; case 'l': case 'L': if (end_state == 'l') { end_state = '?'; } else { end_state = 'l'; } break; default: end_state = 0; break; } return end_state == 'd';}static intfound_match(char *s, int hx, int cc){ /* return true if this string is a match */ int j, f; char outbuf[256]; if (!*s) { return 0; } if (scan_mode) { for (j = f = 0; scan_down[j]; j++) { if (scan_length[j] == 0) { continue; } if (!strncmp(s, scan_down[j], scan_length[j])) { if (!f) { /* first match */ put_cr(); if (hx) { put_str(hex_expand_to(s, 10)); } else { put_str(expand_to(s, 10)); } f = 1; } (void) end_funky(scan_name[j][0]); put_str(" "); put_str(scan_name[j]); scan_tested[j] = 1; s += scan_length[j]; if (strncmp(s, scan_up[j], scan_length[j])) { put_str(" scan down"); } else { s += scan_length[j]; } if (!*s) { break; } j = -1; } if (!strncmp(s, scan_up[j], scan_length[j])) { if (!f) { /* first match */ put_cr(); if (hx) { put_str(hex_expand_to(s, 10)); } else { put_str(expand_to(s, 10)); } f = 1; } put_str(" "); put_str(scan_name[j]); put_str(" scan up"); s += scan_length[j]; if (!*s) { break; } j = -1; } } } else { for (j = f = 0; j < key_count; j++) { if (!strcmp(s, fkval[j])) { if (!f) { /* first match */ put_cr(); if (hx) { put_str(hex_expand_to(s, 10)); } else { put_str(expand_to(s, 10)); } f = 1; } sprintf(outbuf, " (%s)", fk_name[j]); put_str(outbuf); if (fk_label[j]) { sprintf(outbuf, " <%s>", fk_label[j]); put_str(outbuf); } fk_tested[j] = 1; } } } if (end_state == '?') { keys_tested(0, 1, hx); tty_raw(cc, char_mask); end_state = 0; } return f;}static intfound_exit(char *keybuf, int hx, int cc){ /* return true if the user wants to exit */ int j, k; char *s; if (scan_mode) { if (*keybuf == '\0') { return TRUE; } } else { /* break is a special case */ if (*keybuf == '\0') { fresh_line(); tty_set(); ptext("Hit X to exit: "); if (wait_here() == 'X') { return TRUE; } keys_tested(0, 1, hx); tty_raw(cc, char_mask); return FALSE; } /* is this the end? */ for (k = 0; (j = (keybuf[k] & STRIP_PARITY)); k++) { if (end_funky(j)) { return TRUE; } } j = TRUE; /* does he need an updated list? */ for (k = 0; keybuf[k]; k++) { j &= (keybuf[k] & STRIP_PARITY) == '?'; } if (j || end_state == '?') { keys_tested(0, 1, hx); tty_raw(cc, char_mask); end_state = 0; return FALSE; } } put_cr(); if (hx) { s = hex_expand_to(keybuf, 10); } else { s = expand_to(keybuf, 10); } sprintf(temp, "%s Unknown", s); put_str(temp); for (j = 0; j < MAX_FK_UNK; j++) { if (j == funk) { fk_length[funk] = expand_chars; if ((fk_unknown[funk] = (char *)malloc(strlen(s) + 1))) { strcpy(fk_unknown[funk++], s); } break; } if (fk_length[j] == expand_chars) { if (!strcmp(fk_unknown[j], s)) { break; } } } return FALSE;}/*** funkey_keys(test_list, status, ch)**** Test function keys*/static voidfunkey_keys( struct test_list *t, int *state, int *ch){ char keybuf[256]; if (keypad_xmit) { tc_putp(keypad_xmit); } keys_tested(1, 1, hex_out); /* also clears screen */ keybuf[0] = '\0'; end_state = 0; if (scan_mode) { fkmax = scan_max; } tty_raw(0, char_mask); while (end_state != 'd') { read_key(keybuf, sizeof(keybuf)); fresh_line(); if (found_match(keybuf, hex_out, 0)) { continue;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -