📄 edit.c
字号:
/*** Copyright (C) 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>#include <time.h>#include <tic.h>MODULE_ID("$Id: edit.c,v 1.8 2001/06/18 18:44:32 tom Exp $")/* * Terminfo edit features */static void show_info(struct test_list *, int *, int *);static void show_value(struct test_list *, int *, int *);static void show_untested(struct test_list *, int *, int *);static void show_changed(struct test_list *, int *, int *);#define SHOW_VALUE 1#define SHOW_EDIT 2#define SHOW_DELETE 3struct test_list edit_test_list[] = { {MENU_CLEAR, 0, 0, 0, "i) display current terminfo", show_info, 0}, {0, 0, 0, 0, "w) write the current terminfo to a file", save_info, 0}, {SHOW_VALUE, 3, 0, 0, "v) show value of a selected cap", show_value, 0}, {SHOW_EDIT, 4, 0, 0, "e) edit value of a selected cap", show_value, 0}, {SHOW_DELETE, 3, 0, 0, "d) delete string", show_value, 0}, {0, 3, 0, 0, "m) show caps that have been modified", show_changed, 0}, {MENU_CLEAR + FLAG_CAN_TEST, 0, 0, 0, "c) show caps that can be tested", show_report, 0}, {MENU_CLEAR + FLAG_TESTED, 0, 0, 0, "t) show caps that have been tested", show_report, 0}, {MENU_CLEAR + FLAG_FUNCTION_KEY, 0, 0, 0, "f) show a list of function keys", show_report, 0}, {MENU_CLEAR, 0, 0, 0, "u) show caps defined that can not be tested", show_untested, 0}, {MENU_LAST, 0, 0, 0, 0, 0, 0}};static char change_pad_text[MAX_CHANGES][80];struct test_list change_pad_list[MAX_CHANGES] = { {MENU_LAST, 0, 0, 0, 0, 0, 0}};static void build_change_menu(struct test_menu *);static void change_one_entry(struct test_list *, int *, int *);struct test_menu change_pad_menu = { 0, 'q', 0, "Select cap name", "change", 0, build_change_menu, change_pad_list, 0, 0, 0};extern struct test_results *pads[STRCOUNT]; /* save pad results here */static TERMTYPE original_term; /* terminal type description */static char flag_boolean[BOOLCOUNT]; /* flags for booleans */static char flag_numerics[NUMCOUNT]; /* flags for numerics */static char flag_strings[STRCOUNT]; /* flags for strings */static int xon_index; /* Subscript for (xon) */int xon_shadow;static int start_display; /* the display has just started */static int display_lines; /* number of lines displayed *//*** send_info_string(str)**** Return the terminfo string prefixed by the correct separator*/static voidsend_info_string( const char *str, int *ch){ int len; if (display_lines == -1) { return; } len = strlen(str); if (len + char_count + 3 >= columns) { if (start_display == 0) { put_str(","); } put_crlf(); if (++display_lines > lines) { ptext("-- more -- "); *ch = wait_here(); if (*ch == 'q') { display_lines = -1; return; } display_lines = 0; } if (len >= columns) { /* if the terminal does not (am) then this loses */ if (columns) { display_lines += ((strlen(str) + 3) / columns) + 1; } put_str(" "); put_str(str); start_display = 0; return; } ptext(" "); } else if (start_display == 0) { ptext(", "); } else { ptext(" "); } ptext(str); start_display = 0;}/*** show_info(test_list, status, ch)**** Display the current terminfo*/static voidshow_info( struct test_list *t GCC_UNUSED, int *state GCC_UNUSED, int *ch){ int i; char buf[1024]; display_lines = 1; start_display = 1; for (i = 0; i < BOOLCOUNT; i++) { if ((i == xon_index) ? xon_shadow : CUR Booleans[i]) { send_info_string(boolnames[i], ch); } } for (i = 0; i < NUMCOUNT; i++) { if (CUR Numbers[i] >= 0) { sprintf(buf, "%s#%d", numnames[i], CUR Numbers[i]); send_info_string(buf, ch); } } for (i = 0; i < STRCOUNT; i++) { if (CUR Strings[i]) { sprintf(buf, "%s=%s", strnames[i], print_expand(CUR Strings[i])); send_info_string(buf, ch); } } put_newlines(2); *ch = REQUEST_PROMPT;}/*** save_info_string(str, fp)**** Write the terminfo string prefixed by the correct separator*/static voidsave_info_string( const char *str, FILE *fp){ int len; len = strlen(str); if (len + display_lines >= 77) { if (display_lines > 0) { (void) fprintf(fp, "\n\t"); } display_lines = 8; } else if (display_lines > 0) { (void) fprintf(fp, " "); display_lines++; } else { (void) fprintf(fp, "\t"); display_lines = 8; } (void) fprintf(fp, "%s,", str); display_lines += len + 1;}/*** save_info(test_list, status, ch)**** Write the current terminfo to a file*/voidsave_info( struct test_list *t, int *state, int *ch){ int i; FILE *fp; time_t now; char buf[1024]; if ((fp = fopen(tty_basename, "w")) == (FILE *) NULL) { (void) sprintf(temp, "can't open: %s", tty_basename); ptextln(temp); generic_done_message(t, state, ch); return; } time(&now); /* Note: ctime() returns a newline at the end of the string */ (void) fprintf(fp, "# Terminfo created by TACK for TERM=%s on %s", tty_basename, ctime(&now)); (void) fprintf(fp, "%s|%s,\n", tty_basename, longname()); display_lines = 0; for (i = 0; i < BOOLCOUNT; i++) { if (i == xon_index ? xon_shadow : CUR Booleans[i]) { save_info_string(boolnames[i], fp); } } for (i = 0; i < NUMCOUNT; i++) { if (CUR Numbers[i] >= 0) { sprintf(buf, "%s#%d", numnames[i], CUR Numbers[i]); save_info_string(buf, fp); } } for (i = 0; i < STRCOUNT; i++) { if (CUR Strings[i]) { sprintf(buf, "%s=%s", strnames[i], _nc_tic_expand(CUR Strings[i], TRUE, TRUE)); save_info_string(buf, fp); } } (void) fprintf(fp, "\n"); (void) fclose(fp); sprintf(temp, "Terminfo saved as file: %s", tty_basename); ptextln(temp);}/*** show_value(test_list, status, ch)**** Display the value of a selected cap*/static voidshow_value( struct test_list *t, int *state GCC_UNUSED, int *ch){ struct name_table_entry const *nt; char *s; int n, op, b; char buf[1024]; char tmp[1024]; ptext("enter name: "); read_string(buf, 80); if (buf[0] == '\0' || buf[1] == '\0') { *ch = buf[0]; return; } if (line_count + 2 >= lines) { put_clear(); } op = t->flags & 255; if ((nt = _nc_find_entry(buf, _nc_info_hash_table))) { switch (nt->nte_type) { case BOOLEAN: if (op == SHOW_DELETE) { if (nt->nte_index == xon_index) { xon_shadow = 0; } else { CUR Booleans[nt->nte_index] = 0; } return; } b = nt->nte_index == xon_index ? xon_shadow : CUR Booleans[nt->nte_index]; sprintf(temp, "boolean %s %s", buf, b ? "True" : "False"); break; case STRING: if (op == SHOW_DELETE) { CUR Strings[nt->nte_index] = (char *) 0; return; } if (CUR Strings[nt->nte_index]) { sprintf(temp, "string %s %s", buf, expand(CUR Strings[nt->nte_index])); } else { sprintf(temp, "undefined string %s", buf); } break; case NUMBER: if (op == SHOW_DELETE) { CUR Numbers[nt->nte_index] = -1; return; } sprintf(temp, "numeric %s %d", buf, CUR Numbers[nt->nte_index]); break; default: sprintf(temp, "unknown"); break; } ptextln(temp); } else { sprintf(temp, "Cap not found: %s", buf); ptextln(temp); return; } if (op != SHOW_EDIT) { return; } if (nt->nte_type == BOOLEAN) { ptextln("Value flipped"); if (nt->nte_index == xon_index) { xon_shadow = !xon_shadow; } else { CUR Booleans[nt->nte_index] = !CUR Booleans[nt->nte_index]; } return; } ptextln("Enter new value"); read_string(buf, sizeof(buf)); switch (nt->nte_type) { case STRING: _nc_reset_input((FILE *) 0, buf); _nc_trans_string(tmp, tmp + sizeof(tmp)); s = (char *)malloc(strlen(tmp) + 1); strcpy(s, tmp); CUR Strings[nt->nte_index] = s; sprintf(temp, "new string value %s", nt->nte_name); ptextln(temp); ptextln(expand(CUR Strings[nt->nte_index])); break; case NUMBER: if (sscanf(buf, "%d", &n) == 1) { CUR Numbers[nt->nte_index] = n; sprintf(temp, "new numeric value %s %d", nt->nte_name, n); ptextln(temp); } else { sprintf(temp, "Illegal number: %s", buf); ptextln(temp); } break; default: break; }}/*** get_string_cap_byname(name, long_name)**** Given a cap name, find the value** Errors are quietly ignored.*/char *get_string_cap_byname( const char *name, const char **long_name){ struct name_table_entry const *nt; if ((nt = _nc_find_entry(name, _nc_info_hash_table))) { if (nt->nte_type == STRING) { *long_name = strfnames[nt->nte_index]; return (CUR Strings[nt->nte_index]); } } *long_name = "??"; return (char *) 0;}/*** get_string_cap_byvalue(value)**** Given a capability string, find its position in the data base.** Return the index or -1 if not found.*/intget_string_cap_byvalue( const char *value){ int i; if (value) { for (i = 0; i < STRCOUNT; i++) { if (CUR Strings[i] == value) { return i; } } /* search for translated strings */ for (i = 0; i < TM_last; i++) { if (TM_string[i].value == value) { return TM_string[i].index; } } } return -1;}/*** show_changed(test_list, status, ch)**** Display a list of caps that have been changed.*/static voidshow_changed( struct test_list *t GCC_UNUSED, int *state GCC_UNUSED, int *ch){ int i, header = 1, v; const char *a; const char *b; static char title[] = " old value cap new value"; char abuf[1024]; for (i = 0; i < BOOLCOUNT; i++) { v = (i == xon_index) ? xon_shadow : CUR Booleans[i]; if (original_term.Booleans[i] != v) { if (header) { ptextln(title); header = 0; } sprintf(temp, "%30d %6s %d", original_term.Booleans[i], boolnames[i], v); ptextln(temp); } } for (i = 0; i < NUMCOUNT; i++) { if (original_term.Numbers[i] != CUR Numbers[i]) { if (header) { ptextln(title); header = 0; } sprintf(temp, "%30d %6s %d", original_term.Numbers[i], numnames[i], CUR Numbers[i]); ptextln(temp); } } for (i = 0; i < STRCOUNT; i++) { a = original_term.Strings[i] ? original_term.Strings[i] : ""; b = CUR Strings[i] ? CUR Strings[i] : ""; if (strcmp(a, b)) { if (header) { ptextln(title); header = 0; } strcpy(abuf, _nc_tic_expand(a, TRUE, TRUE)); sprintf(temp, "%30s %6s %s", abuf, strnames[i], _nc_tic_expand(b, TRUE, TRUE)); putln(temp); } } if (header) { ptextln("No changes"); } put_crlf(); *ch = REQUEST_PROMPT;}/*** user_modified()**** Return TRUE if the user has modified the terminfo*/intuser_modified(void){ const char *a, *b;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -