2 ** Copyright (C) 1991, 1997 Free Software Foundation, Inc.
4 ** This file is part of TACK.
6 ** TACK is free software; you can redistribute it and/or modify
7 ** it under the terms of the GNU General Public License as published by
8 ** the Free Software Foundation; either version 2, or (at your option)
11 ** TACK is distributed in the hope that it will be useful,
12 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ** GNU General Public License for more details.
16 ** You should have received a copy of the GNU General Public License
17 ** along with TACK; see the file COPYING. If not, write to
18 ** the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 ** Boston, MA 02111-1307, USA.
24 MODULE_ID("$Id: tack.c,v 1.2 2001/10/28 01:05:35 tom Exp $")
27 This program is designed to test terminfo, not curses. Therefore
28 I have used as little of curses as possible.
30 Pads associated with the following capabilities are used to set
31 delay times in the handler: (cr), (ind), (cub1), (ff), (tab).
33 I use the (nxon) capability to set the tty handler with/without
34 xon/xoff. If (smxon)/(rmxon) is defined I will change the terminal
37 (xon) inhibits the sending of delay characters in putp().
38 If the terminal is defined with no padding then the (xon) boolean
39 is a don't care. In this case I recommend that it be reset.
42 /*****************************************************************************
46 *****************************************************************************/
48 /* options and modes */
49 int debug_level
; /* debugging level */
50 int translate_mode
; /* translate tab, bs, cr, lf, ff */
51 int scan_mode
; /* use scan codes */
52 int char_mask
; /* either 0xFF else 0x7F, eight bit data mask */
53 int select_delay_type
; /* set handler delays for <cr><lf> */
54 int select_xon_xoff
; /* TTY driver XON/XOFF mode select */
55 int hex_out
; /* Display output in hex */
56 int send_reset_init
; /* Send the reset and initialization strings */
57 FILE *log_fp
; /* Terminal logfile */
59 /*****************************************************************************
63 *****************************************************************************/
65 extern struct test_menu sync_menu
;
67 static void tools_hex_echo(struct test_list
*, int *, int *);
68 static void tools_debug(struct test_list
*, int *, int *);
70 static char hex_echo_menu_entry
[80];
72 struct test_list tools_test_list
[] = {
73 {0, 0, 0, 0, "s) ANSI status reports", tools_status
, 0},
74 {0, 0, 0, 0, "g) ANSI SGR modes (bold, underline, reverse)", tools_sgr
, 0},
75 {0, 0, 0, 0, "c) ANSI character sets", tools_charset
, 0},
76 {0, 0, 0, 0, hex_echo_menu_entry
, tools_hex_echo
, 0},
77 {0, 0, 0, 0, "e) echo tool", tools_report
, 0},
78 {1, 0, 0, 0, "r) reply tool", tools_report
, 0},
79 {0, 0, 0, 0, "p) performance testing", 0, &sync_menu
},
80 {0, 0, 0, 0, "i) send reset and init", menu_reset_init
, 0},
81 {0, 0, "u8) (u9", 0, "u) test ENQ/ACK handshake", sync_handshake
, 0},
82 {0, 0, 0, 0, "d) change debug level", tools_debug
, 0},
83 {MENU_LAST
, 0, 0, 0, 0, 0, 0}
86 struct test_menu tools_menu
= {
87 0, 'q', 0, "Tools Menu", "tools",
88 0, 0, tools_test_list
, 0, 0, 0
91 static void tty_width(struct test_list
*, int *, int *);
92 static void tty_delay(struct test_list
*, int *, int *);
93 static void tty_xon(struct test_list
*, int *, int *);
94 static void tty_trans(struct test_list
*, int *, int *);
95 static void tty_show_state(struct test_menu
*);
97 static char tty_width_menu
[80];
98 static char tty_delay_menu
[80];
99 static char tty_xon_menu
[80];
100 static char tty_trans_menu
[80];
101 static char enable_xon_xoff
[] = {"x) enable xon/xoff"};
102 static char disable_xon_xoff
[] = {"x) disable xon/xoff"};
104 static struct test_list tty_test_list
[] = {
105 {0, 0, 0, 0, tty_width_menu
, tty_width
, 0},
106 {0, 0, 0, 0, tty_delay_menu
, tty_delay
, 0},
107 {0, 0, 0, 0, tty_xon_menu
, tty_xon
, 0},
108 {0, 0, 0, 0, tty_trans_menu
, tty_trans
, 0},
109 {MENU_LAST
, 0, 0, 0, 0, 0, 0}
112 static struct test_menu tty_menu
= {
113 0, 'q', 0, "Terminal and driver configuration",
115 tty_show_state
, tty_test_list
, 0, 0, 0
118 extern struct test_list edit_test_list
[];
120 struct test_menu edit_menu
= {
121 0, 'q', 0, "Edit terminfo menu",
123 0, edit_test_list
, 0, 0, 0
126 extern struct test_list mode_test_list
[];
128 struct test_menu mode_menu
= {
129 0, 'n', 0, "Test modes and glitches:",
130 "mode", "n) run standard tests",
131 0, mode_test_list
, 0, 0, 0
134 extern struct test_list acs_test_list
[];
136 static struct test_menu acs_menu
= {
138 "Test alternate character set and graphics rendition:",
139 "acs", "n) run standard tests",
140 0, acs_test_list
, 0, 0, 0
143 extern struct test_list color_test_list
[];
145 struct test_menu color_menu
= {
148 "color", "n) run standard tests",
149 0, color_test_list
, 0, 0, 0
152 extern struct test_list crum_test_list
[];
154 static struct test_menu crum_menu
= {
156 "Test cursor movement:",
157 "move", "n) run standard tests",
158 0, crum_test_list
, 0, 0, 0
161 extern struct test_list funkey_test_list
[];
163 static struct test_menu funkey_menu
= {
165 "Test function keys:",
166 "fkey", "n) run standard tests",
167 sync_test
, funkey_test_list
, 0, 0, 0
170 extern struct test_list printer_test_list
[];
172 static struct test_menu printer_menu
= {
175 "printer", "n) run standard tests",
176 0, printer_test_list
, 0, 0, 0
179 static void pad_gen(struct test_list
*, int *, int *);
180 extern struct test_list pad_test_list
[];
182 static struct test_menu pad_menu
= {
184 "Test padding and string capabilities:",
185 "pad", "n) run standard tests",
186 sync_test
, pad_test_list
, 0, 0, 0
189 static struct test_list normal_test_list
[] = {
190 {0, 0, 0, 0, "e) edit terminfo", 0, &edit_menu
},
191 {0, 0, 0, 0, "i) send reset and init", menu_reset_init
, 0},
192 {MENU_NEXT
, 0, 0, 0, "x) test modes and glitches", 0, &mode_menu
},
193 {MENU_NEXT
, 0, 0, 0, "a) test alternate character set and graphic rendition", 0, &acs_menu
},
194 {MENU_NEXT
, 0, 0, 0, "c) test color", 0, &color_menu
},
195 {MENU_NEXT
, 0, 0, 0, "m) test cursor movement", 0, &crum_menu
},
196 {MENU_NEXT
, 0, 0, 0, "f) test function keys", 0, &funkey_menu
},
197 {MENU_NEXT
, 0, 0, 0, "p) test padding and string capabilities", 0, &pad_menu
},
198 {0, 0, 0, 0, "P) test printer", 0, &printer_menu
},
199 {MENU_MENU
, 0, 0, 0, "/) test a specific capability", 0, 0},
200 {0, 0, 0, 0, "t) auto generate pad delays", pad_gen
, &pad_menu
},
201 {0, 0, "u8) (u9", 0, 0, sync_handshake
, 0},
202 {MENU_LAST
, 0, 0, 0, 0, 0, 0}
206 struct test_menu normal_menu
= {
207 0, 'n', 0, "Main test menu",
208 "test", "n) run standard tests",
209 0, normal_test_list
, 0, 0, 0
212 static void start_tools(struct test_list
*, int *, int *);
213 static void start_modes(struct test_list
*, int *, int *);
214 static void start_basic(struct test_list
*, int *, int *);
215 static void start_log(struct test_list
*, int *, int *);
217 static char logging_menu_entry
[80] = "l) start logging";
219 struct test_list start_test_list
[] = {
220 {0, 0, 0, 0, "b) display basic information", start_basic
, 0},
221 {0, 0, 0, 0, "m) change modes", start_modes
, 0},
222 {0, 0, 0, 0, "t) tools", start_tools
, 0},
223 {MENU_COMPLETE
, 0, 0, 0, "n) begin testing", 0, &normal_menu
},
224 {0, 0, 0, 0, logging_menu_entry
, start_log
, 0},
225 {MENU_LAST
, 0, 0, 0, 0, 0, 0}
229 struct test_menu start_menu
= {
230 0, 'n', 0, "Main Menu", "tack", 0,
231 0, start_test_list
, 0, 0, 0
234 static struct test_list write_terminfo_list
[] = {
235 {0, 0, 0, 0, "w) write the current terminfo to a file", save_info
, 0},
236 {MENU_LAST
, 0, 0, 0, 0, 0, 0}
239 /*****************************************************************************
241 * Menu command interpretation.
243 *****************************************************************************/
246 ** tools_hex_echo(testlist, state, ch)
248 ** Flip the hex echo flag.
252 struct test_list
*t GCC_UNUSED
,
253 int *state GCC_UNUSED
,
258 strcpy(hex_echo_menu_entry
,
259 "h) enable hex output on echo tool");
262 strcpy(hex_echo_menu_entry
,
263 "h) disable hex output on echo tool");
268 ** tools_debug(testlist, state, ch)
270 ** Change the debug level.
274 struct test_list
*t GCC_UNUSED
,
275 int *state GCC_UNUSED
,
280 ptext("Enter a new value: ");
281 read_string(buf
, sizeof(buf
));
283 sscanf(buf
, "%d", &debug_level
);
285 sprintf(temp
, "Debug level is now %d", debug_level
);
287 *ch
= REQUEST_PROMPT
;
291 ** start_tools(testlist, state, ch)
293 ** Run the generic test tools
297 struct test_list
*t GCC_UNUSED
,
298 int *state GCC_UNUSED
,
302 strcpy(hex_echo_menu_entry
,
303 "h) disable hex output on echo tool");
305 strcpy(hex_echo_menu_entry
,
306 "h) enable hex output on echo tool");
308 menu_display(&tools_menu
, 0);
314 ** Display the current state on the tty driver settings
318 struct test_menu
*menu GCC_UNUSED
)
322 "Accepting %d bits, UNIX delays %d, XON/XOFF %sabled, speed %ld, translate %s, scan-code mode %s.",
323 (char_mask
== ALLOW_PARITY
) ? 8 : 7,
325 select_xon_xoff
? "en" : "dis",
327 translate_mode
? "on" : "off",
328 scan_mode
? "on" : "off");
334 ** tty_width(testlist, state, ch)
336 ** Change the character width
340 struct test_list
*t GCC_UNUSED
,
341 int *state GCC_UNUSED
,
344 if (char_mask
== STRIP_PARITY
) {
345 char_mask
= ALLOW_PARITY
;
346 strcpy(tty_width_menu
, "7) treat terminal as 7-bit");
348 char_mask
= STRIP_PARITY
;
349 strcpy(tty_width_menu
, "8) treat terminal as 8-bit");
354 ** tty_delay(testlist, state, ch)
356 ** Change the delay for <cr><lf> in the TTY driver
360 struct test_list
*t GCC_UNUSED
,
361 int *state GCC_UNUSED
,
364 if (select_delay_type
) {
365 select_delay_type
= FALSE
;
366 strcpy(tty_delay_menu
,
367 "d) enable UNIX tty driver delays for <cr><lf>");
369 select_delay_type
= TRUE
;
370 strcpy(tty_delay_menu
,
371 "d) disable UNIX tty driver delays for <cr><lf>");
376 ** tty_xon(testlist, state, ch)
378 ** Change the XON/XOFF flags in the TTY driver
382 struct test_list
*t GCC_UNUSED
,
383 int *state GCC_UNUSED
,
386 if (select_xon_xoff
) {
387 if (needs_xon_xoff
) {
388 ptextln("This terminal is marked as needing XON/XOFF protocol with (nxon)");
391 tc_putp(exit_xon_mode
);
393 xon_xoff
= select_xon_xoff
= FALSE
;
394 strcpy(tty_xon_menu
, enable_xon_xoff
);
396 if (enter_xon_mode
) {
397 tc_putp(enter_xon_mode
);
399 xon_xoff
= select_xon_xoff
= TRUE
;
400 strcpy(tty_xon_menu
, disable_xon_xoff
);
406 ** tty_trans(testlist, state, ch)
408 ** Change the translation mode for special characters
412 struct test_list
*t GCC_UNUSED
,
413 int *state GCC_UNUSED
,
416 if (translate_mode
) {
417 translate_mode
= FALSE
;
418 strcpy(tty_trans_menu
,
419 "t) use terminfo values for \\b\\f\\n\\r\\t");
421 translate_mode
= TRUE
;
422 strcpy(tty_trans_menu
,
423 "t) override terminfo values for \\b\\f\\n\\r\\t");
428 ** pad_gen(testlist, state, ch)
430 ** Menu function for automatic pad generation
435 int *state GCC_UNUSED
,
439 if (tty_can_sync
== SYNC_NOT_TESTED
) {
442 auto_pad_mode
= TRUE
;
443 menu_display(t
->sub_menu
, ch
);
444 auto_pad_mode
= FALSE
;
448 ** start_modes(testlist, state, ch)
450 ** Change the TTY modes
454 struct test_list
*t GCC_UNUSED
,
455 int *state GCC_UNUSED
,
459 if (select_delay_type
) {
460 strcpy(tty_delay_menu
,
461 "d) disable UNIX tty driver delays for <cr><lf>");
463 strcpy(tty_delay_menu
,
464 "d) enable UNIX tty driver delays for <cr><lf>");
466 if (char_mask
== ALLOW_PARITY
) {
467 strcpy(tty_width_menu
,
468 "7) treat terminal as 7-bit");
470 strcpy(tty_width_menu
,
471 "8) treat terminal as 8-bit");
473 if (select_xon_xoff
) {
474 strcpy(tty_xon_menu
, disable_xon_xoff
);
476 strcpy(tty_xon_menu
, enable_xon_xoff
);
478 if (translate_mode
) {
479 strcpy(tty_trans_menu
,
480 "t) override terminfo values for \\b\\f\\n\\r\\t");
482 strcpy(tty_trans_menu
,
483 "t) use terminfo values for \\b\\f\\n\\r\\t");
485 menu_display(&tty_menu
, 0);
490 ** start_basic(testlist, state, ch)
492 ** Display basic terminal information
496 struct test_list
*t GCC_UNUSED
,
497 int *state GCC_UNUSED
,
501 *ch
= REQUEST_PROMPT
;
505 ** start_log(testlist, state, ch)
507 ** Start/stop in logging function
511 struct test_list
*t GCC_UNUSED
,
512 int *state GCC_UNUSED
,
515 if (logging_menu_entry
[5] == 'a') {
516 ptextln("The log file will capture all characters sent to the terminal.");
517 if ((log_fp
= fopen("tack.log", "w"))) {
518 ptextln("Start logging to file: tack.log");
519 strcpy(logging_menu_entry
, "l) stop logging");
521 ptextln("File open error: tack.log");
528 ptextln("Terminal output logging stopped.");
529 strcpy(logging_menu_entry
, "l) start logging");
536 ** Tell the user how its done.
542 (void) fprintf(stderr
, "usage: %s [-itV] [term]\n", name
);
548 ** Print version and other useful information.
553 printf("tack version %d.%02d\n", MAJOR_VERSION
, MINOR_VERSION
);
554 printf("Copyright (C) 1997 Free Software Foundation, Inc.\n");
555 printf("Tack comes with NO WARRANTY, to the extent permitted by law.\n");
556 printf("You may redistribute copies of Tack under the terms of the\n");
557 printf("GNU General Public License. For more information about\n");
558 printf("these matters, see the file named COPYING.\n");
562 /*****************************************************************************
566 *****************************************************************************/
569 main(int argc
, char *argv
[])
574 /* scan the option flags */
575 send_reset_init
= TRUE
;
576 translate_mode
= FALSE
;
577 term_variable
= getenv("TERM");
578 tty_can_sync
= SYNC_NOT_TESTED
;
579 for (i
= 1; i
< argc
; i
++) {
580 if (argv
[i
][0] == '-') {
581 for (j
= 1; argv
[i
][j
]; j
++) {
582 switch (argv
[i
][j
]) {
587 send_reset_init
= FALSE
;
590 translate_mode
= FALSE
;
598 term_variable
= argv
[i
];
601 (void) strcpy(tty_basename
, term_variable
);
603 curses_setup(argv
[0]);
605 menu_can_scan(&normal_menu
); /* extract which caps can be tested */
606 menu_display(&start_menu
, 0);
608 if (user_modified()) {
609 sprintf(temp
, "Hit y to save changes to file: %s ? ",
612 if (wait_here() == 'y') {
613 save_info(write_terminfo_list
, &i
, &j
);
617 put_str("\nTerminal test complete\n");