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>
20 #include "gtxwindows.h" /*Generalized window interface */
21 #include "gtxcurseswin.h" /*Curses window interface */
22 #include "gtxdumbwin.h" /*Dumb terminal window interface */
23 #include "gtxX11win.h" /*X11 window interface */
24 #include <cmd.h> /*Command interpretation library */
29 * Command line parameter indicies.
34 static char pn[] = "screen_test"; /*Program name */
35 static int screen_debug = 0; /*Is debugging turned on? */
37 /*--------------------------------------------------------------------------------
41 * Routine that does the actual testing of the chosen graphics
45 * pkg : Number of package to test.
49 * Error value otherwise.
52 * Nothing interesting.
56 *--------------------------------------------------------------------------------*/
59 test_this_package(pkg)
62 { /*test_this_package */
64 static char rn[] = "test_this_package"; /*Routine name */
65 register int code; /*Return code */
66 struct gwin_initparams init_params; /*Window initialization params */
67 struct gator_cursesgwin_params c_crparams; /*Curses window creation params */
68 struct gator_dumbgwin_params d_crparams; /*Dumb terminal window creation params */
69 struct gator_X11gwin_params x_crparams; /*X11 window creation params */
70 struct gwin *newwin; /*New (sub)window */
71 struct gwin_strparams strparams; /*String-drawing params */
72 struct gwin_charparams charparams; /*Char-drawing params */
73 char s[128]; /*Test string */
74 int currx, curry; /*Sliding values of x & y */
75 int currhighlight; /*Highlight this time around? */
78 * Initialize the gator window package to drive the desired subsystem.
80 init_params.i_type = pkg;
83 init_params.i_width = 80;
84 init_params.i_height = 200;
85 init_params.i_debug = screen_debug;
87 code = gw_init(&init_params);
90 "[%s:%s] Can't initialize gator windows for package %d; error is: %d\n",
95 sprintf(s, "Screen has %d lines", LINES);
97 strparams.y = LINES / 2;
99 strparams.highlight = 0;
100 WOP_DRAWSTRING(&gator_basegwin, &strparams);
102 sprintf(s, "and %d columns", COLS);
104 strparams.y = strparams.y + 1;
106 strparams.highlight = 1;
107 WOP_DRAWSTRING(&gator_basegwin, &strparams);
110 * Draw a set of chars down a diagonal, pausing inbetween.
113 for (currx = curry = 0; (currx < COLS) && (curry < LINES);
115 charparams.x = currx;
116 charparams.y = curry;
118 charparams.highlight = currhighlight;
119 currhighlight = (currhighlight ? 0 : 1);
120 WOP_DRAWCHAR(&gator_basegwin, &charparams);
123 WOP_BOX(&gator_basegwin);
126 * Fill in the new window creation parameters and go for it.
128 c_crparams.gwin_params.cr_type = pkg;
129 c_crparams.gwin_params.cr_x = 40;
130 c_crparams.gwin_params.cr_y = 5;
131 c_crparams.gwin_params.cr_width = 20;
132 c_crparams.gwin_params.cr_height = 10;
133 c_crparams.gwin_params.cr_parentwin = (struct gwin *)(&gator_basegwin);
134 c_crparams.charwidth = 8;
135 c_crparams.charheight = 13;
136 c_crparams.box_vertchar = '|';
137 c_crparams.box_horizchar = '-';
138 newwin = WOP_CREATE(&c_crparams);
139 if (newwin == NULL) {
140 fprintf(stderr, "[%s:%s] Can't create a new window\n", pn, rn);
141 } else if (screen_debug)
142 fprintf(stderr, "[%s:%s] New window created at 0x%x\n", pn, rn,
146 * Draw something to the new window; first, a highlighted banner.
148 sprintf(s, "%s", "Sub-window ");
152 strparams.highlight = 1;
153 WOP_DRAWSTRING(newwin, &strparams);
156 * Next, draw an `x' at each corner.
159 charparams.highlight = 1;
162 WOP_DRAWCHAR(newwin, &charparams);
165 WOP_DRAWCHAR(newwin, &charparams);
168 WOP_DRAWCHAR(newwin, &charparams);
171 WOP_DRAWCHAR(newwin, &charparams);
174 * Finally, box the sucker.
179 * Draw a few other things in the original window.
181 sprintf(s, "Screen has %d lines", LINES);
183 strparams.y = LINES / 2;
185 strparams.highlight = 0;
186 WOP_DRAWSTRING(&gator_basegwin, &strparams);
188 sprintf(s, "and %d columns", COLS);
190 strparams.y = strparams.y + 1;
192 strparams.highlight = 1;
193 WOP_DRAWSTRING(&gator_basegwin, &strparams);
196 * Let people admire the handiwork, then clean up.
198 WOP_DISPLAY(&gator_basegwin);
200 WOP_DISPLAY(&gator_basegwin);
201 WOP_CLEANUP(&gator_basegwin);
203 } /*test_this_package */
205 /*--------------------------------------------------------------------------------
209 * Routine that is called when screen_test is invoked, responsible
210 * for basic initialization and command line parsing.
213 * as : Command syntax descriptor.
214 * arock : Associated rock (not used here).
217 * Zero (but may exit the entire program on error!)
220 * Nothing interesting.
223 * Initializes this program.
224 *--------------------------------------------------------------------------------*/
227 screen_testInit(struct cmd_syndesc *as, void *arock)
228 { /*screen_testInit */
230 static char rn[] = "screen_testInit"; /*Routine name */
231 int pkg_to_test; /*Which package to test */
233 if (as->parms[P_DEBUG].items != 0)
235 pkg_to_test = atoi(as->parms[P_PACKAGE].items->data);
236 fprintf(stderr, "[%s:%s] Testing graphics package %d: ", pn, rn,
238 switch (pkg_to_test) {
239 case GATOR_WIN_CURSES:
240 fprintf(stderr, "curses\n");
243 fprintf(stderr, "dumb terminal\n");
246 fprintf(stderr, "X11\n");
249 fprintf(stderr, "Illegal graphics package: %d\n", pkg_to_test);
250 } /*end switch (pkg_to_test) */
253 * Now, drive the sucker.
255 test_this_package(pkg_to_test);
258 * We initialized (and ran) correctly, so return the good news.
262 } /*screen_testInit */
264 #include "AFS_component_version_number.c"
272 static char rn[] = "main"; /*Routine name */
273 register afs_int32 code; /*Return code */
274 register struct cmd_syndesc *ts; /*Ptr to cmd line syntax descriptor */
277 * There really aren't any opcodes here, but we do want to interpret switches
278 * from the command line. So, all we need do is set up the initcmd ``opcode''.
280 ts = cmd_CreateSyntax("initcmd", screen_testInit, NULL,
281 "Initialize, interpret command line");
282 cmd_AddParm(ts, "-package", CMD_SINGLE, CMD_REQUIRED,
283 "Graphics package to use");
284 cmd_AddParm(ts, "-debug", CMD_FLAG, CMD_OPTIONAL, "Turn debugging on");
287 * Parse command-line switches & execute the test, then get the heck out of here.
289 code = cmd_Dispatch(argc, argv);
291 fprintf(stderr, "[%s:%s] Call to cmd_Dispatch() failed; code is %d\n",