2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
11 * screen_test: A test of the gator screen operations.
12 *--------------------------------------------------------------------------------*/
14 #include <afsconfig.h>
15 #include <afs/param.h>
19 #include <afs/cmd.h> /*Command interpretation library */
21 #include "gtxwindows.h" /*Generalized window interface */
22 #include "gtxcurseswin.h" /*Curses window interface */
23 #include "gtxdumbwin.h" /*Dumb terminal window interface */
24 #include "gtxX11win.h" /*X11 window interface */
28 * Command line parameter indicies.
33 static char pn
[] = "screen_test"; /*Program name */
34 static int screen_debug
= 0; /*Is debugging turned on? */
36 /*--------------------------------------------------------------------------------
40 * Routine that does the actual testing of the chosen graphics
44 * pkg : Number of package to test.
48 * Error value otherwise.
51 * Nothing interesting.
55 *--------------------------------------------------------------------------------*/
58 test_this_package(pkg
)
61 { /*test_this_package */
63 static char rn
[] = "test_this_package"; /*Routine name */
64 int code
; /*Return code */
65 struct gwin_initparams init_params
; /*Window initialization params */
66 struct gator_cursesgwin_params c_crparams
; /*Curses window creation params */
67 struct gator_dumbgwin_params d_crparams
; /*Dumb terminal window creation params */
68 struct gator_X11gwin_params x_crparams
; /*X11 window creation params */
69 struct gwin
*newwin
; /*New (sub)window */
70 struct gwin_strparams strparams
; /*String-drawing params */
71 struct gwin_charparams charparams
; /*Char-drawing params */
72 char s
[128]; /*Test string */
73 int currx
, curry
; /*Sliding values of x & y */
74 int currhighlight
; /*Highlight this time around? */
77 * Initialize the gator window package to drive the desired subsystem.
79 init_params
.i_type
= pkg
;
82 init_params
.i_width
= 80;
83 init_params
.i_height
= 200;
84 init_params
.i_debug
= screen_debug
;
86 code
= gw_init(&init_params
);
89 "[%s:%s] Can't initialize gator windows for package %d; error is: %d\n",
94 sprintf(s
, "Screen has %d lines", LINES
);
96 strparams
.y
= LINES
/ 2;
98 strparams
.highlight
= 0;
99 WOP_DRAWSTRING(&gator_basegwin
, &strparams
);
101 sprintf(s
, "and %d columns", COLS
);
103 strparams
.y
= strparams
.y
+ 1;
105 strparams
.highlight
= 1;
106 WOP_DRAWSTRING(&gator_basegwin
, &strparams
);
109 * Draw a set of chars down a diagonal, pausing inbetween.
112 for (currx
= curry
= 0; (currx
< COLS
) && (curry
< LINES
);
114 charparams
.x
= currx
;
115 charparams
.y
= curry
;
117 charparams
.highlight
= currhighlight
;
118 currhighlight
= (currhighlight
? 0 : 1);
119 WOP_DRAWCHAR(&gator_basegwin
, &charparams
);
122 WOP_BOX(&gator_basegwin
);
125 * Fill in the new window creation parameters and go for it.
127 c_crparams
.gwin_params
.cr_type
= pkg
;
128 c_crparams
.gwin_params
.cr_x
= 40;
129 c_crparams
.gwin_params
.cr_y
= 5;
130 c_crparams
.gwin_params
.cr_width
= 20;
131 c_crparams
.gwin_params
.cr_height
= 10;
132 c_crparams
.gwin_params
.cr_parentwin
= (struct gwin
*)(&gator_basegwin
);
133 c_crparams
.charwidth
= 8;
134 c_crparams
.charheight
= 13;
135 c_crparams
.box_vertchar
= '|';
136 c_crparams
.box_horizchar
= '-';
137 newwin
= WOP_CREATE(&c_crparams
);
138 if (newwin
== NULL
) {
139 fprintf(stderr
, "[%s:%s] Can't create a new window\n", pn
, rn
);
140 } else if (screen_debug
)
141 fprintf(stderr
, "[%s:%s] New window created at 0x%x\n", pn
, rn
,
145 * Draw something to the new window; first, a highlighted banner.
147 sprintf(s
, "%s", "Sub-window ");
151 strparams
.highlight
= 1;
152 WOP_DRAWSTRING(newwin
, &strparams
);
155 * Next, draw an `x' at each corner.
158 charparams
.highlight
= 1;
161 WOP_DRAWCHAR(newwin
, &charparams
);
164 WOP_DRAWCHAR(newwin
, &charparams
);
167 WOP_DRAWCHAR(newwin
, &charparams
);
170 WOP_DRAWCHAR(newwin
, &charparams
);
173 * Finally, box the sucker.
178 * Draw a few other things in the original window.
180 sprintf(s
, "Screen has %d lines", LINES
);
182 strparams
.y
= LINES
/ 2;
184 strparams
.highlight
= 0;
185 WOP_DRAWSTRING(&gator_basegwin
, &strparams
);
187 sprintf(s
, "and %d columns", COLS
);
189 strparams
.y
= strparams
.y
+ 1;
191 strparams
.highlight
= 1;
192 WOP_DRAWSTRING(&gator_basegwin
, &strparams
);
195 * Let people admire the handiwork, then clean up.
197 WOP_DISPLAY(&gator_basegwin
);
199 WOP_DISPLAY(&gator_basegwin
);
200 WOP_CLEANUP(&gator_basegwin
);
202 } /*test_this_package */
204 /*--------------------------------------------------------------------------------
208 * Routine that is called when screen_test is invoked, responsible
209 * for basic initialization and command line parsing.
212 * as : Command syntax descriptor.
213 * arock : Associated rock (not used here).
216 * Zero (but may exit the entire program on error!)
219 * Nothing interesting.
222 * Initializes this program.
223 *--------------------------------------------------------------------------------*/
226 screen_testInit(struct cmd_syndesc
*as
, void *arock
)
227 { /*screen_testInit */
229 static char rn
[] = "screen_testInit"; /*Routine name */
230 int pkg_to_test
; /*Which package to test */
232 if (as
->parms
[P_DEBUG
].items
!= 0)
234 pkg_to_test
= atoi(as
->parms
[P_PACKAGE
].items
->data
);
235 fprintf(stderr
, "[%s:%s] Testing graphics package %d: ", pn
, rn
,
237 switch (pkg_to_test
) {
238 case GATOR_WIN_CURSES
:
239 fprintf(stderr
, "curses\n");
242 fprintf(stderr
, "dumb terminal\n");
245 fprintf(stderr
, "X11\n");
248 fprintf(stderr
, "Illegal graphics package: %d\n", pkg_to_test
);
249 } /*end switch (pkg_to_test) */
252 * Now, drive the sucker.
254 test_this_package(pkg_to_test
);
257 * We initialized (and ran) correctly, so return the good news.
261 } /*screen_testInit */
263 #include "AFS_component_version_number.c"
271 static char rn
[] = "main"; /*Routine name */
272 afs_int32 code
; /*Return code */
273 struct cmd_syndesc
*ts
; /*Ptr to cmd line syntax descriptor */
276 * There really aren't any opcodes here, but we do want to interpret switches
277 * from the command line. So, all we need do is set up the initcmd ``opcode''.
279 ts
= cmd_CreateSyntax("initcmd", screen_testInit
, NULL
, 0,
280 "Initialize, interpret command line");
281 cmd_AddParm(ts
, "-package", CMD_SINGLE
, CMD_REQUIRED
,
282 "Graphics package to use");
283 cmd_AddParm(ts
, "-debug", CMD_FLAG
, CMD_OPTIONAL
, "Turn debugging on");
286 * Parse command-line switches & execute the test, then get the heck out of here.
288 code
= cmd_Dispatch(argc
, argv
);
290 fprintf(stderr
, "[%s:%s] Call to cmd_Dispatch() failed; code is %d\n",