death to trailing whitespace
[openafs.git] / src / gtx / screen_test.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  *
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
8  */
9
10 /*
11  * screen_test: A test of the gator screen operations.
12  *--------------------------------------------------------------------------------*/
13
14 #include <afsconfig.h>
15 #include <afs/param.h>
16
17
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 */
23 #include <errno.h>
24
25
26 /*
27  * Command line parameter indicies.
28  */
29 #define P_PACKAGE   0
30 #define P_DEBUG     1
31
32 static char pn[] = "screen_test";       /*Program name */
33 static int screen_debug = 0;    /*Is debugging turned on? */
34
35 /*--------------------------------------------------------------------------------
36  * test_this_package
37  *
38  * Description:
39  *      Routine that does the actual testing of the chosen graphics
40  *      package.
41  *
42  * Arguments:
43  *      pkg : Number of package to test.
44  *
45  * Returns:
46  *      0 on success,
47  *      Error value otherwise.
48  *
49  * Environment:
50  *      Nothing interesting.
51  *
52  * Side Effects:
53  *      As advertised.
54  *--------------------------------------------------------------------------------*/
55
56 static int
57 test_this_package(pkg)
58      int pkg;
59
60 {                               /*test_this_package */
61
62     static char rn[] = "test_this_package";     /*Routine name */
63     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? */
74
75     /*
76      * Initialize the gator window package to drive the desired subsystem.
77      */
78     init_params.i_type = pkg;
79     init_params.i_x = 0;
80     init_params.i_y = 0;
81     init_params.i_width = 80;
82     init_params.i_height = 200;
83     init_params.i_debug = screen_debug;
84
85     code = gw_init(&init_params);
86     if (code) {
87         fprintf(stderr,
88                 "[%s:%s] Can't initialize gator windows for package %d; error is: %d\n",
89                 pn, rn, pkg, code);
90         return (code);
91     }
92
93     sprintf(s, "Screen has %d lines", LINES);
94     strparams.x = 5;
95     strparams.y = LINES / 2;
96     strparams.s = s;
97     strparams.highlight = 0;
98     WOP_DRAWSTRING(&gator_basegwin, &strparams);
99
100     sprintf(s, "and %d columns", COLS);
101     strparams.x = 5;
102     strparams.y = strparams.y + 1;
103     strparams.s = s;
104     strparams.highlight = 1;
105     WOP_DRAWSTRING(&gator_basegwin, &strparams);
106
107     /*
108      * Draw a set of chars down a diagonal, pausing inbetween.
109      */
110     currhighlight = 1;
111     for (currx = curry = 0; (currx < COLS) && (curry < LINES);
112          currx++, curry++) {
113         charparams.x = currx;
114         charparams.y = curry;
115         charparams.c = 'x';
116         charparams.highlight = currhighlight;
117         currhighlight = (currhighlight ? 0 : 1);
118         WOP_DRAWCHAR(&gator_basegwin, &charparams);
119         sleep(1);
120     }
121     WOP_BOX(&gator_basegwin);
122
123     /*
124      * Fill in the new window creation parameters and go for it.
125      */
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,
141                 newwin);
142
143     /*
144      * Draw something to the new window; first, a highlighted banner.
145      */
146     sprintf(s, "%s", "Sub-window        ");
147     strparams.x = 1;
148     strparams.y = 1;
149     strparams.s = s;
150     strparams.highlight = 1;
151     WOP_DRAWSTRING(newwin, &strparams);
152
153     /*
154      * Next, draw an `x' at each corner.
155      */
156     charparams.c = 'x';
157     charparams.highlight = 1;
158     charparams.x = 1;
159     charparams.y = 2;
160     WOP_DRAWCHAR(newwin, &charparams);
161     charparams.x = 18;
162     charparams.y = 2;
163     WOP_DRAWCHAR(newwin, &charparams);
164     charparams.x = 1;
165     charparams.y = 8;
166     WOP_DRAWCHAR(newwin, &charparams);
167     charparams.x = 18;
168     charparams.y = 8;
169     WOP_DRAWCHAR(newwin, &charparams);
170
171     /*
172      * Finally, box the sucker.
173      */
174     WOP_BOX(newwin);
175
176     /*
177      * Draw a few other things in the original window.
178      */
179     sprintf(s, "Screen has %d lines", LINES);
180     strparams.x = 5;
181     strparams.y = LINES / 2;
182     strparams.s = s;
183     strparams.highlight = 0;
184     WOP_DRAWSTRING(&gator_basegwin, &strparams);
185
186     sprintf(s, "and %d columns", COLS);
187     strparams.x = 5;
188     strparams.y = strparams.y + 1;
189     strparams.s = s;
190     strparams.highlight = 1;
191     WOP_DRAWSTRING(&gator_basegwin, &strparams);
192
193     /*
194      * Let people admire the handiwork, then clean up.
195      */
196     WOP_DISPLAY(&gator_basegwin);
197     sleep(10);
198     WOP_DISPLAY(&gator_basegwin);
199     WOP_CLEANUP(&gator_basegwin);
200
201 }                               /*test_this_package */
202
203 /*--------------------------------------------------------------------------------
204  * screen_testInit
205  *
206  * Description:
207  *      Routine that is called when screen_test is invoked, responsible
208  *      for basic initialization and command line parsing.
209  *
210  * Arguments:
211  *      as      : Command syntax descriptor.
212  *      arock   : Associated rock (not used here).
213  *
214  * Returns:
215  *      Zero (but may exit the entire program on error!)
216  *
217  * Environment:
218  *      Nothing interesting.
219  *
220  * Side Effects:
221  *      Initializes this program.
222  *--------------------------------------------------------------------------------*/
223
224 static int
225 screen_testInit(struct cmd_syndesc *as, void *arock)
226 {                               /*screen_testInit */
227
228     static char rn[] = "screen_testInit";       /*Routine name */
229     int pkg_to_test;            /*Which package to test */
230
231     if (as->parms[P_DEBUG].items != 0)
232         screen_debug = 1;
233     pkg_to_test = atoi(as->parms[P_PACKAGE].items->data);
234     fprintf(stderr, "[%s:%s] Testing graphics package %d: ", pn, rn,
235             pkg_to_test);
236     switch (pkg_to_test) {
237     case GATOR_WIN_CURSES:
238         fprintf(stderr, "curses\n");
239         break;
240     case GATOR_WIN_DUMB:
241         fprintf(stderr, "dumb terminal\n");
242         break;
243     case GATOR_WIN_X11:
244         fprintf(stderr, "X11\n");
245         break;
246     default:
247         fprintf(stderr, "Illegal graphics package: %d\n", pkg_to_test);
248     }                           /*end switch (pkg_to_test) */
249
250     /*
251      * Now, drive the sucker.
252      */
253     test_this_package(pkg_to_test);
254
255     /*
256      * We initialized (and ran) correctly, so return the good news.
257      */
258     return (0);
259
260 }                               /*screen_testInit */
261
262 #include "AFS_component_version_number.c"
263
264 main(argc, argv)
265      int argc;
266      char **argv;
267
268 {                               /*main */
269
270     static char rn[] = "main";  /*Routine name */
271     afs_int32 code;     /*Return code */
272     struct cmd_syndesc *ts;     /*Ptr to cmd line syntax descriptor */
273
274     /*
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''.
277      */
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");
283
284     /*
285      * Parse command-line switches & execute the test, then get the heck out of here.
286      */
287     code = cmd_Dispatch(argc, argv);
288     if (code) {
289         fprintf(stderr, "[%s:%s] Call to cmd_Dispatch() failed; code is %d\n",
290                 pn, rn, code);
291         exit(1);
292     }
293
294 }                               /*main */