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 "gtxwindows.h" /*Generalized window interface*/
15 #include "gtxcurseswin.h" /*Curses window interface*/
16 #include "gtxdumbwin.h" /*Dumb terminal window interface*/
17 #include "gtxX11win.h" /*X11 window interface*/
18 #include <cmd.h> /*Command interpretation library*/
23 * Command line parameter indicies.
28 static char pn[] = "screen_test"; /*Program name*/
29 static int screen_debug = 0; /*Is debugging turned on?*/
31 /*--------------------------------------------------------------------------------
35 * Routine that does the actual testing of the chosen graphics
39 * pkg : Number of package to test.
43 * Error value otherwise.
46 * Nothing interesting.
50 *--------------------------------------------------------------------------------*/
52 static int test_this_package(pkg)
55 { /*test_this_package*/
57 static char rn[] = "test_this_package"; /*Routine name*/
58 register int code; /*Return code*/
59 struct gwin_initparams init_params; /*Window initialization params*/
60 struct gator_cursesgwin_params c_crparams; /*Curses window creation params*/
61 struct gator_dumbgwin_params d_crparams; /*Dumb terminal window creation params*/
62 struct gator_X11gwin_params x_crparams; /*X11 window creation params*/
63 struct gwin *newwin; /*New (sub)window*/
64 struct gwin_strparams strparams; /*String-drawing params*/
65 struct gwin_charparams charparams; /*Char-drawing params*/
66 char s[128]; /*Test string*/
67 int currx, curry; /*Sliding values of x & y*/
68 int currhighlight; /*Highlight this time around?*/
71 * Initialize the gator window package to drive the desired subsystem.
73 init_params.i_type = pkg;
76 init_params.i_width = 80;
77 init_params.i_height = 200;
78 init_params.i_debug = screen_debug;
80 code = gw_init(&init_params);
82 fprintf(stderr, "[%s:%s] Can't initialize gator windows for package %d; error is: %d\n", pn, rn, pkg, code);
86 sprintf(s, "Screen has %d lines", LINES);
88 strparams.y = LINES / 2;
90 strparams.highlight = 0;
91 WOP_DRAWSTRING(&gator_basegwin, &strparams);
93 sprintf(s, "and %d columns", COLS);
95 strparams.y = strparams.y + 1;
97 strparams.highlight = 1;
98 WOP_DRAWSTRING(&gator_basegwin, &strparams);
101 * Draw a set of chars down a diagonal, pausing inbetween.
104 for (currx = curry = 0; (currx < COLS) && (curry < LINES); currx++, curry++) {
105 charparams.x = currx;
106 charparams.y = curry;
108 charparams.highlight = currhighlight;
109 currhighlight = (currhighlight ? 0 : 1);
110 WOP_DRAWCHAR(&gator_basegwin, &charparams);
113 WOP_BOX(&gator_basegwin);
116 * Fill in the new window creation parameters and go for it.
118 c_crparams.gwin_params.cr_type = pkg;
119 c_crparams.gwin_params.cr_x = 40;
120 c_crparams.gwin_params.cr_y = 5;
121 c_crparams.gwin_params.cr_width = 20;
122 c_crparams.gwin_params.cr_height = 10;
123 c_crparams.gwin_params.cr_parentwin = (struct gwin *)(&gator_basegwin);
124 c_crparams.charwidth = 8;
125 c_crparams.charheight = 13;
126 c_crparams.box_vertchar = '|';
127 c_crparams.box_horizchar = '-';
128 newwin = WOP_CREATE(&c_crparams);
129 if (newwin == (struct gwin *)0) {
130 fprintf(stderr, "[%s:%s] Can't create a new window\n", pn, rn);
134 fprintf(stderr, "[%s:%s] New window created at 0x%x\n", pn, rn, newwin);
137 * Draw something to the new window; first, a highlighted banner.
139 sprintf(s, "%s", "Sub-window ");
143 strparams.highlight = 1;
144 WOP_DRAWSTRING(newwin, &strparams);
147 * Next, draw an `x' at each corner.
150 charparams.highlight = 1;
153 WOP_DRAWCHAR(newwin, &charparams);
156 WOP_DRAWCHAR(newwin, &charparams);
159 WOP_DRAWCHAR(newwin, &charparams);
162 WOP_DRAWCHAR(newwin, &charparams);
165 * Finally, box the sucker.
170 * Draw a few other things in the original window.
172 sprintf(s, "Screen has %d lines", LINES);
174 strparams.y = LINES / 2;
176 strparams.highlight = 0;
177 WOP_DRAWSTRING(&gator_basegwin, &strparams);
179 sprintf(s, "and %d columns", COLS);
181 strparams.y = strparams.y + 1;
183 strparams.highlight = 1;
184 WOP_DRAWSTRING(&gator_basegwin, &strparams);
187 * Let people admire the handiwork, then clean up.
189 WOP_DISPLAY(&gator_basegwin);
191 WOP_DISPLAY(&gator_basegwin);
192 WOP_CLEANUP(&gator_basegwin);
194 } /*test_this_package*/
196 /*--------------------------------------------------------------------------------
200 * Routine that is called when screen_test is invoked, responsible
201 * for basic initialization and command line parsing.
204 * as : Command syntax descriptor.
205 * arock : Associated rock (not used here).
208 * Zero (but may exit the entire program on error!)
211 * Nothing interesting.
214 * Initializes this program.
215 *--------------------------------------------------------------------------------*/
217 static int screen_testInit(as, arock)
218 struct cmd_syndesc *as;
221 { /*screen_testInit*/
223 static char rn[] = "screen_testInit"; /*Routine name*/
224 int pkg_to_test; /*Which package to test*/
226 if (as->parms[P_DEBUG].items != 0)
228 pkg_to_test = atoi(as->parms[P_PACKAGE].items->data);
229 fprintf(stderr, "[%s:%s] Testing graphics package %d: ", pn, rn, pkg_to_test);
230 switch (pkg_to_test) {
231 case GATOR_WIN_CURSES:
232 fprintf(stderr, "curses\n");
235 fprintf(stderr, "dumb terminal\n");
238 fprintf(stderr, "X11\n");
241 fprintf(stderr, "Illegal graphics package: %d\n", pkg_to_test);
242 } /*end switch (pkg_to_test)*/
245 * Now, drive the sucker.
247 test_this_package(pkg_to_test);
250 * We initialized (and ran) correctly, so return the good news.
254 } /*screen_testInit*/
256 #include "AFS_component_version_number.c"
264 static char rn[] = "main"; /*Routine name*/
265 register afs_int32 code; /*Return code*/
266 register struct cmd_syndesc *ts; /*Ptr to cmd line syntax descriptor*/
269 * There really aren't any opcodes here, but we do want to interpret switches
270 * from the command line. So, all we need do is set up the initcmd ``opcode''.
272 ts = cmd_CreateSyntax("initcmd", screen_testInit, 0, "Initialize, interpret command line");
273 cmd_AddParm(ts, "-package", CMD_SINGLE, CMD_REQUIRED, "Graphics package to use");
274 cmd_AddParm(ts, "-debug", CMD_FLAG, CMD_OPTIONAL, "Turn debugging on");
277 * Parse command-line switches & execute the test, then get the heck out of here.
279 code = cmd_Dispatch(argc, argv);
281 fprintf(stderr, "[%s:%s] Call to cmd_Dispatch() failed; code is %d\n", pn, rn, code);