source: trunk/essentials/sys-libs/ncurses/tack/modes.c@ 3043

Last change on this file since 3043 was 2621, checked in by bird, 20 years ago

GNU ncurses 5.5

File size: 20.5 KB
Line 
1/*
2** Copyright (C) 1991, 1997 Free Software Foundation, Inc.
3**
4** This file is part of TACK.
5**
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)
9** any later version.
10**
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.
15**
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., 51 Franklin Street, Fifth Floor,
19** Boston, MA 02110-1301, USA
20*/
21
22#include <tack.h>
23
24MODULE_ID("$Id: modes.c,v 1.2 2005/09/17 19:49:16 tom Exp $")
25
26/*
27 * Tests boolean flags and terminal modes.
28 */
29static void subtest_os(struct test_list *, int *, int *);
30static void subtest_rmam(struct test_list *, int *, int *);
31static void subtest_smam(struct test_list *, int *, int *);
32static void subtest_am(struct test_list *, int *, int *);
33static void subtest_ul(struct test_list *, int *, int *);
34static void subtest_uc(struct test_list *, int *, int *);
35static void subtest_bw(struct test_list *, int *, int *);
36static void subtest_xenl(struct test_list *, int *, int *);
37static void subtest_eo(struct test_list *, int *, int *);
38static void subtest_xmc(struct test_list *, int *, int *);
39static void subtest_xhp(struct test_list *, int *, int *);
40static void subtest_mir(struct test_list *, int *, int *);
41static void subtest_msgr(struct test_list *, int *, int *);
42static void subtest_tbc(struct test_list *, int *, int *);
43static void subtest_xt(struct test_list *, int *, int *);
44static void subtest_hts(struct test_list *, int *, int *);
45static void subtest_cbt(struct test_list *, int *, int *);
46static void subtest_in(struct test_list *, int *, int *);
47static void subtest_dadb(struct test_list *, int *, int *);
48
49struct test_list mode_test_list[] = {
50 {0, 0, 0, 0, "e) edit terminfo", 0, &edit_menu},
51 {MENU_NEXT, 3, "os", 0, 0, subtest_os, 0},
52 {MENU_NEXT, 1, "rmam", 0, 0, subtest_rmam, 0},
53 {MENU_NEXT, 1, "smam", 0, 0, subtest_smam, 0},
54 {MENU_NEXT, 1, "am", 0, 0, subtest_am, 0},
55 {MENU_NEXT, 3, "ul", 0, 0, subtest_ul, 0},
56 {MENU_NEXT, 3, "uc", 0, 0, subtest_uc, 0},
57 {MENU_NEXT, 3, "bw", 0, 0, subtest_bw, 0},
58 {MENU_NEXT, 4, "xenl", 0, 0, subtest_xenl, 0},
59 {MENU_NEXT, 3, "eo", 0, 0, subtest_eo, 0},
60 {MENU_NEXT, 3, "xmc", 0, 0, subtest_xmc, 0},
61 {MENU_NEXT, 3, "xhp", 0, 0, subtest_xhp, 0},
62 {MENU_NEXT, 6, "mir", 0, 0, subtest_mir, 0},
63 {MENU_NEXT, 6, "msgr", 0, 0, subtest_msgr, 0},
64 {MENU_NEXT | MENU_CLEAR, 0, "tbc", "it", 0, subtest_tbc, 0},
65 {MENU_NEXT | MENU_CLEAR, 0, "hts", "it", 0, subtest_hts, 0},
66 {MENU_NEXT, 4, "xt", "it", 0, subtest_xt, 0},
67 {MENU_NEXT, 1, "cbt", "it", 0, subtest_cbt, 0},
68 {MENU_NEXT, 6, "in", 0, 0, subtest_in, 0},
69 {MENU_NEXT, 1, "da) (db", 0, 0, subtest_dadb, 0},
70 {MENU_LAST, 0, 0, 0, 0, 0, 0}
71};
72
73/*
74** subtest_os(test_list, status, ch)
75**
76** test over strike mode (os)
77*/
78static void
79subtest_os(
80 struct test_list *t,
81 int *state,
82 int *ch)
83{
84 ptext("(os) should be true, not false.");
85 put_cr();
86 ptextln("(os) should be false.");
87 sprintf(temp, "(os) over-strike is %s in the data base. ",
88 over_strike ? "true" : "false");
89 ptext(temp);
90 generic_done_message(t, state, ch);
91}
92
93/*
94** subtest_rmam(test_list, status, ch)
95**
96** test exit automatic margins mode (rmam)
97*/
98static void
99subtest_rmam(
100 struct test_list *t,
101 int *state,
102 int *ch)
103{
104 int j;
105
106 if (!exit_am_mode) {
107 ptext("(rmam) not present. ");
108 } else
109 if (!can_go_home) {
110 ptext("(rmam) not tested, no way to home cursor. ");
111 } else
112 if (over_strike) {
113 put_clear();
114 go_home();
115 tc_putp(exit_am_mode);
116 ptext("\n(rmam) will reset (am)");
117 go_home();
118 for (j = 0; j < columns; j++)
119 put_this(' ');
120 ptext("(rmam) will not reset (am)");
121 go_home();
122 put_newlines(2);
123 } else {
124 put_clear();
125 go_home();
126 tc_putp(exit_am_mode);
127 ptext("\n(rmam) will reset (am)");
128 go_home();
129 for (j = 0; j < columns; j++)
130 put_this(' ');
131 ptext("(rmam) will not reset (am) ");
132 go_home();
133 put_str(" ");
134 go_home();
135 put_newlines(2);
136 }
137 ptext("Exit-automatic-margins ");
138 generic_done_message(t, state, ch);
139}
140
141/*
142** subtest_smam(test_list, status, ch)
143**
144** test enter automatic margins mode (smam)
145*/
146static void
147subtest_smam(
148 struct test_list *t,
149 int *state,
150 int *ch)
151{
152 int i, j;
153
154 if (!enter_am_mode) {
155 ptext("(smam) not present. ");
156 } else
157 if (!can_go_home) {
158 ptext("(smam) not tested, no way to home cursor. ");
159 } else
160 if (over_strike) {
161 put_clear();
162 go_home();
163 tc_putp(enter_am_mode);
164 ptext("\n(smam) will ");
165 i = char_count;
166 ptext("not set (am)");
167 go_home();
168 for (j = -i; j < columns; j++)
169 put_this(' ');
170 put_str("@@@");
171 put_newlines(2);
172 } else {
173 put_clear();
174 go_home();
175 tc_putp(enter_am_mode);
176 ptext("\n(smam) will not set (am)");
177 go_home();
178 for (j = 0; j < columns; j++)
179 put_this(' ');
180 ptext("(smam) will set (am) ");
181 go_home();
182 put_str(" ");
183 put_newlines(2);
184 }
185 ptext("Enter-automatic-margins ");
186 generic_done_message(t, state, ch);
187}
188
189/*
190** subtest_am(test_list, status, ch)
191**
192** test automatic margins (am)
193*/
194static void
195subtest_am(
196 struct test_list *t,
197 int *state,
198 int *ch)
199{
200 int i, j;
201
202 if (!can_go_home) {
203 ptextln("(am) not tested, no way to home cursor. ");
204 } else
205 if (over_strike) {
206 put_clear();
207 go_home();
208 ptext("\n(am) should ");
209 i = char_count;
210 ptext("not be set");
211 go_home();
212 for (j = -i; j < columns; j++)
213 put_this(' ');
214 put_str("@@@");
215 go_home();
216 put_newlines(2);
217 sprintf(temp, "(am) is %s in the data base",
218 auto_right_margin ? "true" : "false");
219 ptextln(temp);
220 } else {
221 put_clear();
222 go_home();
223 ptext("\n(am) should not be set");
224 go_home();
225 for (j = 0; j < columns; j++)
226 put_this(' ');
227 ptext("(am) should be set ");
228 go_home();
229 put_str(" \n\n");
230 sprintf(temp, "(am) is %s in the data base",
231 auto_right_margin ? "true" : "false");
232 ptextln(temp);
233 }
234 ptext("Automatic-right-margin ");
235 generic_done_message(t, state, ch);
236}
237
238/* Note: uprint() sends underscore back-space character, and
239 ucprint() sends character back-space underscore. */
240
241/*
242** uprint(string)
243**
244** underline string for (ul) test
245*/
246static void
247uprint(const char *s)
248{
249 if (s) {
250 while (*s) {
251 put_str("_\b");
252 putchp(*s++);
253 }
254 }
255}
256
257/*
258** ucprint(string)
259**
260** underline string for (uc) test
261*/
262static void
263ucprint(const char *s)
264{
265 if (s) {
266 while (*s) {
267 putchp(*s++);
268 putchp('\b');
269 tc_putp(underline_char);
270 }
271 }
272}
273
274/*
275** subtest_ul(test_list, status, ch)
276**
277** test transparent underline (ul)
278*/
279static void
280subtest_ul(
281 struct test_list *t,
282 int *state,
283 int *ch)
284{
285 if (!over_strike) {
286 /* (ul) is used only if (os) is reset */
287 put_crlf();
288 sprintf(temp, "This text should %sbe underlined.",
289 transparent_underline ? "" : "not ");
290 uprint(temp);
291 put_crlf();
292 ptextln("If the above line is not underlined the (ul) should be false.");
293 sprintf(temp, "(ul) Transparent-underline is %s in the data base",
294 transparent_underline ? "true" : "false");
295 ptextln(temp);
296 generic_done_message(t, state, ch);
297 }
298}
299
300/*
301** subtest_uc(test_list, status, ch)
302**
303** test underline character (uc)
304*/
305static void
306subtest_uc(
307 struct test_list *t,
308 int *state,
309 int *ch)
310{
311 if (!over_strike) {
312 if (underline_char) {
313 ucprint("This text should be underlined.");
314 put_crlf();
315 ptextln("If the above text is not underlined the (uc) has failed.");
316 ptext("Underline-character ");
317 } else {
318 ptext("(uc) underline-character is not defined. ");
319 }
320 generic_done_message(t, state, ch);
321 }
322}
323
324/*
325** subtest_bw(test_list, status, ch)
326**
327** test auto left margin (bw)
328*/
329static void
330subtest_bw(
331 struct test_list *t,
332 int *state,
333 int *ch)
334{
335 int i, j;
336
337 if (over_strike) {
338 /* test (bw) */
339 ptext("\n(bw) should ");
340 i = char_count;
341 ptextln("not be set.");
342 for (j = i; j < columns; j++)
343 put_str("\b");
344 put_str("@@@");
345 put_crlf();
346 sprintf(temp, "(bw) Auto-left-margin is %s in the data base",
347 auto_left_margin ? "true" : "false");
348 ptextln(temp);
349 } else {
350 /* test (bw) */
351 ptextln("(bw) should not be set.");
352 for (i = 12; i < columns; i++)
353 put_str("\b");
354 if (delete_character) {
355 for (i = 0; i < 4; i++)
356 tc_putp(delete_character);
357 } else {
358 put_str(" ");
359 }
360 put_crlf();
361 sprintf(temp, "(bw) Auto-left-margin is %s in the data base",
362 auto_left_margin ? "true" : "false");
363 ptextln(temp);
364 }
365 generic_done_message(t, state, ch);
366}
367
368/*
369** subtest_tbc(test_list, status, ch)
370**
371** test clear tabs (tbc)
372*/
373static void
374subtest_tbc(
375 struct test_list *t,
376 int *state,
377 int *ch)
378{
379 int tabat; /* the tab spacing we end up with */
380 int i;
381
382 if (clear_all_tabs && !set_tab) {
383 ptext("(tbc) Clear-all-tabs is defined but (hts) set-tab is not. ");
384 ptext("Once the tabs are cleared there is no way to set them. ");
385 } else
386 if (clear_all_tabs) {
387 tabat = set_tab ? 8 : init_tabs;
388 tc_putp(clear_all_tabs);
389 ptext("Clear tabs (tbc)");
390 go_home();
391 put_crlf();
392 putchp('\t');
393 putchp('T');
394 go_home();
395 put_newlines(2);
396 for (i = 0; i < columns; i++) {
397 if (i == tabat) {
398 putchp('T');
399 } else {
400 putchp('.');
401 }
402 }
403 go_home();
404 ptext("\n\n\nIf the above two lines have T's in the same column then (tbc) has failed. ");
405 } else {
406 ptext("(tbc) Clear-all-tabs is not defined. ");
407 }
408 generic_done_message(t, state, ch);
409}
410
411/*
412** subtest_hts(test_list, status, ch)
413**
414** (ht) and set tabs with (hts)
415*/
416static void
417subtest_hts(
418 struct test_list *t,
419 int *state,
420 int *ch)
421{
422 int tabat; /* the tab spacing we end up with */
423 int i;
424
425 tabat = init_tabs;
426 if (set_tab) {
427 ptext("Tabs set with (hts)");
428 put_crlf();
429 for (i = 1; i < columns; i++) {
430 if (i % 8 == 1) {
431 tc_putp(set_tab);
432 }
433 putchp(' ');
434 }
435 tabat = 8;
436 } else {
437 sprintf(temp, "(hts) Set-tabs not defined. (it) Initial-tabs at %d", init_tabs);
438 ptext(temp);
439 }
440 go_home();
441 put_newlines(2);
442 if (tabat <= 0) {
443 tabat = 8;
444 }
445 for (i = tabat; i < columns; i += tabat) {
446 putchp('\t');
447 putchp('T');
448 }
449 go_home();
450 put_newlines(3);
451 for (i = 1; i < columns; i++) {
452 putchp('.');
453 }
454 go_home();
455 put_newlines(3);
456 for (i = tabat; i < columns; i += tabat) {
457 putchp('\t');
458 putchp('T');
459 }
460 go_home();
461 put_newlines(4);
462 putchp('.');
463 for (i = 2; i < columns; i++) {
464 if (i % tabat == 1) {
465 putchp('T');
466 } else {
467 putchp('.');
468 }
469 }
470 go_home();
471 put_newlines(5);
472 if (set_tab) {
473 ptextln("If the last two lines are not the same then (hts) has failed.");
474 } else
475 if (init_tabs > 0) {
476 ptextln("If the last two lines are not the same then (it) is wrong.");
477 } else {
478 ptextln("If the last two lines are the same then maybe you do have tabs and (it) should be changed.");
479 }
480 generic_done_message(t, state, ch);
481}
482
483/*
484** subtest_xt(test_list, status, ch)
485**
486** (xt) glitch
487*/
488static void
489subtest_xt(
490 struct test_list *t,
491 int *state,
492 int *ch)
493{
494 int tabat; /* the tab spacing we end up with */
495 int cc;
496
497 tabat = set_tab ? 8 : init_tabs;
498 if (!over_strike && (tabat > 0)) {
499 ptext("(xt) should not ");
500 put_cr();
501 ptext("(xt) should");
502 cc = char_count;
503 while (cc < 16) {
504 putchp('\t');