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 "gtxwindows.h" /*Generalized window interface*/
20 #include "gtxcurseswin.h" /*Curses window interface*/
21 #include "gtxdumbwin.h" /*Dumb terminal window interface*/
22 #include "gtxX11win.h" /*X11 window interface*/
23 #include <cmd.h> /*Command interpretation library*/
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 *--------------------------------------------------------------------------------*/
57 static int 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);
87 fprintf(stderr, "[%s:%s] Can't initialize gator windows for package %d; error is: %d\n", pn, rn, pkg, code);
91 sprintf(s, "Screen has %d lines", LINES);
93 strparams.y = LINES / 2;
95 strparams.highlight = 0;
96 WOP_DRAWSTRING(&gator_basegwin, &strparams);
98 sprintf(s, "and %d columns", COLS);
100 strparams.y = strparams.y + 1;
102 strparams.highlight = 1;
103 WOP_DRAWSTRING(&gator_basegwin, &strparams);
106 * Draw a set of chars down a diagonal, pausing inbetween.
109 for (currx = curry = 0; (currx < COLS) && (curry < LINES); currx++, curry++) {
110 charparams.x = currx;
111 charparams.y = curry;
113 charparams.highlight = currhighlight;
114 currhighlight = (currhighlight ? 0 : 1);
115 WOP_DRAWCHAR(&gator_basegwin, &charparams);
118 WOP_BOX(&gator_basegwin);
121 * Fill in the new window creation parameters and go for it.
123 c_crparams.gwin_params.cr_type = pkg;
124 c_crparams.gwin_params.cr_x = 40;
125 c_crparams.gwin_params.cr_y = 5;
126 c_crparams.gwin_params.cr_width = 20;
127 c_crparams.gwin_params.cr_height = 10;
128 c_crparams.gwin_params.cr_parentwin = (struct gwin *)(&gator_basegwin);
129 c_crparams.charwidth = 8;
130 c_crparams.charheight = 13;
131 c_crparams.box_vertchar = '|';
132 c_crparams.box_horizchar = '-';
133 newwin = WOP_CREATE(&c_crparams);
134 if (newwin == NULL) {
135 fprintf(stderr, "[%s:%s] Can't create a new window\n", pn, rn);
139 fprintf(stderr, "[%s:%s] New window created at 0x%x\n", pn, rn, newwin);
142 * Draw something to the new window; first, a highlighted banner.
144 sprintf(s, "%s", "Sub-window ");
148 strparams.highlight = 1;
149 WOP_DRAWSTRING(newwin, &strparams);
152 * Next, draw an `x' at each corner.
155 charparams.highlight = 1;
158 WOP_DRAWCHAR(newwin, &charparams);
161 WOP_DRAWCHAR(newwin, &charparams);
164 WOP_DRAWCHAR(newwin, &charparams);
167 WOP_DRAWCHAR(newwin, &charparams);
170 * Finally, box the sucker.
175 * Draw a few other things in the original window.
177 sprintf(s, "Screen has %d lines", LINES);
179 strparams.y = LINES / 2;
181 strparams.highlight = 0;
182 WOP_DRAWSTRING(&gator_basegwin, &strparams);
184 sprintf(s, "and %d columns", COLS);
186 strparams.y = strparams.y + 1;
188 strparams.highlight = 1;
189 WOP_DRAWSTRING(&gator_basegwin, &strparams);
192 * Let people admire the handiwork, then clean up.
194 WOP_DISPLAY(&gator_basegwin);
196 WOP_DISPLAY(&gator_basegwin);
197 WOP_CLEANUP(&gator_basegwin);
199 } /*test_this_package*/
201 /*--------------------------------------------------------------------------------
205 * Routine that is called when screen_test is invoked, responsible
206 * for basic initialization and command line parsing.
209 * as : Command syntax descriptor.
210 * arock : Associated rock (not used here).
213 * Zero (but may exit the entire program on error!)
216 * Nothing interesting.
219 * Initializes this program.
220 *--------------------------------------------------------------------------------*/
222 static int screen_testInit(as, arock)
223 struct cmd_syndesc *as;
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, pkg_to_test);
235 switch (pkg_to_test) {
236 case GATOR_WIN_CURSES:
237 fprintf(stderr, "curses\n");
240 fprintf(stderr, "dumb terminal\n");
243 fprintf(stderr, "X11\n");
246 fprintf(stderr, "Illegal graphics package: %d\n", pkg_to_test);
247 } /*end switch (pkg_to_test)*/
250 * Now, drive the sucker.
252 test_this_package(pkg_to_test);
255 * We initialized (and ran) correctly, so return the good news.
259 } /*screen_testInit*/
261 #include "AFS_component_version_number.c"
269 static char rn[] = "main"; /*Routine name*/
270 register afs_int32 code; /*Return code*/
271 register struct cmd_syndesc *ts; /*Ptr to cmd line syntax descriptor*/
274 * There really aren't any opcodes here, but we do want to interpret switches
275 * from the command line. So, all we need do is set up the initcmd ``opcode''.
277 ts = cmd_CreateSyntax("initcmd", screen_testInit, 0, "Initialize, interpret command line");
278 cmd_AddParm(ts, "-package", CMD_SINGLE, CMD_REQUIRED, "Graphics package to use");
279 cmd_AddParm(ts, "-debug", CMD_FLAG, CMD_OPTIONAL, "Turn debugging on");
282 * Parse command-line switches & execute the test, then get the heck out of here.
284 code = cmd_Dispatch(argc, argv);
286 fprintf(stderr, "[%s:%s] Call to cmd_Dispatch() failed; code is %d\n", pn, rn, code);