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>
18 #include "gtxwindows.h" /*Generalized window interface */
19 #include "gtxcurseswin.h" /*Curses window interface */
20 #include "gtxdumbwin.h" /*Dumb terminal window interface */
21 #include "gtxX11win.h" /*X11 window interface */
22 #include <cmd.h> /*Command interpretation library */
27 * Command line parameter indicies.
32 static char pn[] = "screen_test"; /*Program name */
33 static int screen_debug = 0; /*Is debugging turned on? */
35 /*--------------------------------------------------------------------------------
39 * Routine that does the actual testing of the chosen graphics
43 * pkg : Number of package to test.
47 * Error value otherwise.
50 * Nothing interesting.
54 *--------------------------------------------------------------------------------*/
57 test_this_package(pkg)
60 { /*test_this_package */
62 static char rn[] = "test_this_package"; /*Routine name */
63 register int code; /*Return code */
64 struct gwin_initparams init_params; /*Window initialization params */
65 struct gator_cursesgwin_params c_crparams; /*Curses window creation params */
66 struct gator_dumbgwin_params d_crparams; /*Dumb terminal window creation params */
67 struct gator_X11gwin_params x_crparams; /*X11 window creation params */
68 struct gwin *newwin; /*New (sub)window */
69 struct gwin_strparams strparams; /*String-drawing params */
70 struct gwin_charparams charparams; /*Char-drawing params */
71 char s[128]; /*Test string */
72 int currx, curry; /*Sliding values of x & y */
73 int currhighlight; /*Highlight this time around? */
76 * Initialize the gator window package to drive the desired subsystem.
78 init_params.i_type = pkg;
81 init_params.i_width = 80;
82 init_params.i_height = 200;
83 init_params.i_debug = screen_debug;
85 code = gw_init(&init_params);
88 "[%s:%s] Can't initialize gator windows for package %d; error is: %d\n",
93 sprintf(s, "Screen has %d lines", LINES);
95 strparams.y = LINES / 2;
97 strparams.highlight = 0;
98 WOP_DRAWSTRING(&gator_basegwin, &strparams);
100 sprintf(s, "and %d columns", COLS);
102 strparams.y = strparams.y + 1;
104 strparams.highlight = 1;
105 WOP_DRAWSTRING(&gator_basegwin, &strparams);
108 * Draw a set of chars down a diagonal, pausing inbetween.
111 for (currx = curry = 0; (currx < COLS) && (curry < LINES);
113 charparams.x = currx;
114 charparams.y = curry;
116 charparams.highlight = currhighlight;
117 currhighlight = (currhighlight ? 0 : 1);
118 WOP_DRAWCHAR(&gator_basegwin, &charparams);
121 WOP_BOX(&gator_basegwin);
124 * Fill in the new window creation parameters and go for it.
126 c_crparams.gwin_params.cr_type = pkg;
127 c_crparams.gwin_params.cr_x = 40;
128 c_crparams.gwin_params.cr_y = 5;
129 c_crparams.gwin_params.cr_width = 20;
130 c_crparams.gwin_params.cr_height = 10;
131 c_crparams.gwin_params.cr_parentwin = (struct gwin *)(&gator_basegwin);
132 c_crparams.charwidth = 8;
133 c_crparams.charheight = 13;
134 c_crparams.box_vertchar = '|';
135 c_crparams.box_horizchar = '-';
136 newwin = WOP_CREATE(&c_crparams);
137 if (newwin == NULL) {
138 fprintf(stderr, "[%s:%s] Can't create a new window\n", pn, rn);
139 } else if (screen_debug)
140 fprintf(stderr, "[%s:%s] New window created at 0x%x\n", pn, rn,
144 * Draw something to the new window; first, a highlighted banner.
146 sprintf(s, "%s", "Sub-window ");
150 strparams.highlight = 1;
151 WOP_DRAWSTRING(newwin, &strparams);
154 * Next, draw an `x' at each corner.
157 charparams.highlight = 1;
160 WOP_DRAWCHAR(newwin, &charparams);
163 WOP_DRAWCHAR(newwin, &charparams);
166 WOP_DRAWCHAR(newwin, &charparams);
169 WOP_DRAWCHAR(newwin, &charparams);
172 * Finally, box the sucker.
177 * Draw a few other things in the original window.
179 sprintf(s, "Screen has %d lines", LINES);
181 strparams.y = LINES / 2;
183 strparams.highlight = 0;
184 WOP_DRAWSTRING(&gator_basegwin, &strparams);
186 sprintf(s, "and %d columns", COLS);
188 strparams.y = strparams.y + 1;
190 strparams.highlight = 1;
191 WOP_DRAWSTRING(&gator_basegwin, &strparams);
194 * Let people admire the handiwork, then clean up.
196 WOP_DISPLAY(&gator_basegwin);
198 WOP_DISPLAY(&gator_basegwin);
199 WOP_CLEANUP(&gator_basegwin);
201 } /*test_this_package */
203 /*--------------------------------------------------------------------------------
207 * Routine that is called when screen_test is invoked, responsible
208 * for basic initialization and command line parsing.
211 * as : Command syntax descriptor.
212 * arock : Associated rock (not used here).
215 * Zero (but may exit the entire program on error!)
218 * Nothing interesting.
221 * Initializes this program.
222 *--------------------------------------------------------------------------------*/
225 screen_testInit(struct cmd_syndesc *as, void *arock)
226 { /*screen_testInit */
228 static char rn[] = "screen_testInit"; /*Routine name */
229 int pkg_to_test; /*Which package to test */
231 if (as->parms[P_DEBUG].items != 0)
233 pkg_to_test = atoi(as->parms[P_PACKAGE].items->data);
234 fprintf(stderr, "[%s:%s] Testing graphics package %d: ", pn, rn,
236 switch (pkg_to_test) {
237 case GATOR_WIN_CURSES:
238 fprintf(stderr, "curses\n");
241 fprintf(stderr, "dumb terminal\n");
244 fprintf(stderr, "X11\n");
247 fprintf(stderr, "Illegal graphics package: %d\n", pkg_to_test);
248 } /*end switch (pkg_to_test) */
251 * Now, drive the sucker.
253 test_this_package(pkg_to_test);
256 * We initialized (and ran) correctly, so return the good news.
260 } /*screen_testInit */
262 #include "AFS_component_version_number.c"
270 static char rn[] = "main"; /*Routine name */
271 register afs_int32 code; /*Return code */
272 register struct cmd_syndesc *ts; /*Ptr to cmd line syntax descriptor */
275 * There really aren't any opcodes here, but we do want to interpret switches
276 * from the command line. So, all we need do is set up the initcmd ``opcode''.
278 ts = cmd_CreateSyntax("initcmd", screen_testInit, NULL,
279 "Initialize, interpret command line");
280 cmd_AddParm(ts, "-package", CMD_SINGLE, CMD_REQUIRED,
281 "Graphics package to use");
282 cmd_AddParm(ts, "-debug", CMD_FLAG, CMD_OPTIONAL, "Turn debugging on");
285 * Parse command-line switches & execute the test, then get the heck out of here.
287 code = cmd_Dispatch(argc, argv);
289 fprintf(stderr, "[%s:%s] Call to cmd_Dispatch() failed; code is %d\n",