1 /****************************************************************************
2 * Copyright (c) 2000-2008,2009 Free Software Foundation, Inc. *
4 * Permission is hereby granted, free of charge, to any person obtaining a *
5 * copy of this software and associated documentation files (the *
6 * "Software"), to deal in the Software without restriction, including *
7 * without limitation the rights to use, copy, modify, merge, publish, *
8 * distribute, distribute with modifications, sublicense, and/or sell *
9 * copies of the Software, and to permit persons to whom the Software is *
10 * furnished to do so, subject to the following conditions: *
12 * The above copyright notice and this permission notice shall be included *
13 * in all copies or substantial portions of the Software. *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
18 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
21 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
23 * Except as contained in this notice, the name(s) of the above copyright *
24 * holders shall not be used in advertising or otherwise to promote the *
25 * sale, use or other dealings in this Software without prior written *
27 ****************************************************************************/
30 * Author: Thomas E. Dickey - 2000
32 * $Id: railroad.c,v 1.19 2009/10/24 21:37:56 tom Exp $
34 * A simple demo of the termcap interface.
37 #include <test.priv.h>
56 static bool interrupted
= FALSE
;
65 if (write(STDOUT_FILENO
, &tmp
, 1) == -1)
68 if (putc(c
, stdout
) == EOF
)
79 napms(moveit
? 10 : 50); /* not really termcap... */
85 tputs(backup
!= 0 ? backup
: "\b", 1, outc
);
89 MyShowCursor(int flag
)
91 if (startC
!= 0 && finisC
!= 0) {
92 tputs(flag
? startC
: finisC
, 1, outc
);
99 if (startS
!= 0 && finisS
!= 0) {
100 tputs(flag
? startS
: finisS
, 1, outc
);
107 if (startU
!= 0 && finisU
!= 0) {
108 tputs(flag
? startU
: finisU
, 1, outc
);
113 ShowSign(char *string
)
119 tputs(tgoto(moveit
, 0, height
- 1), 1, outc
);
120 tputs(wipeit
, 1, outc
);
123 while (*string
!= 0) {
127 for (first
= length
- 2; first
>= (string
- base
); first
--) {
128 if (first
< length
- 1) {
129 tputs(tgoto(moveit
, first
+ 1, height
- 1), 1, outc
);
132 tputs(tgoto(moveit
, first
, height
- 1), 1, outc
);
138 first
= isupper(ch
) ? 'A' : 'a';
139 } else if (isdigit(ch
)) {
146 while (first
< last
) {
164 tputs(wipeit
, 1, outc
);
177 onsig(int n GCC_UNUSED
)
181 ExitProgram(EXIT_FAILURE
);
185 railroad(char **args
)
187 NCURSES_CONST
char *name
= getenv("TERM");
189 char area
[1024], *ap
= area
;
193 if (tgetent(buffer
, name
) >= 0) {
195 wipeit
= tgetstr("ce", &ap
);
196 height
= tgetnum("li");
197 length
= tgetnum("co");
198 moveit
= tgetstr("cm", &ap
);
210 startS
= tgetstr("so", &ap
);
211 finisS
= tgetstr("se", &ap
);
213 startU
= tgetstr("us", &ap
);
214 finisU
= tgetstr("ue", &ap
);
216 backup
= tgetstr("le", &ap
);
218 startC
= tgetstr("ve", &ap
);
219 finisC
= tgetstr("vi", &ap
);
233 main(int argc
, char *argv
[])
238 static char world
[] = "Hello World";
239 static char *hello
[] =
243 ExitProgram(EXIT_SUCCESS
);
248 main(int argc GCC_UNUSED
,
249 char *argv
[]GCC_UNUSED
)
251 printf("This program requires termcap\n");