gtx: Tidy header includes
[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 #include <roken.h>
18
19 #include <afs/cmd.h>            /*Command interpretation library */
20
21 #include "gtxwindows.h"         /*Generalized window interface */
22 #include "gtxcurseswin.h"       /*Curses window interface */
23 #include "gtxdumbwin.h"         /*Dumb terminal window interface */
24 #include "gtxX11win.h"          /*X11 window interface */
25
26
27 /*
28  * Command line parameter indicies.
29  */
30 #define P_PACKAGE   0
31 #define P_DEBUG     1
32
33 static char pn[] = "screen_test";       /*Program name */
34 static int screen_debug = 0;    /*Is debugging turned on? */
35
36 /*--------------------------------------------------------------------------------
37  * test_this_package
38  *
39  * Description:
40  *      Routine that does the actual testing of the chosen graphics
41  *      package.
42  *
43  * Arguments:
44  *      pkg : Number of package to test.
45  *
46  * Returns:
47  *      0 on success,
48  *      Error value otherwise.
49  *
50  * Environment:
51  *      Nothing interesting.
52  *
53  * Side Effects:
54  *      As advertised.
55  *--------------------------------------------------------------------------------*/
56
57 static int
58 test_this_package(pkg)
59      int pkg;
60
61 {                               /*test_this_package */
62
63     static char rn[] = "test_this_package";     /*Routine name */
64     int code;           /*Return code */
65     struct gwin_initparams init_params; /*Window initialization params */
66     struct gator_cursesgwin_params c_crparams;  /*Curses window creation params */
67     struct gator_dumbgwin_params d_crparams;    /*Dumb terminal window creation params */
68     struct gator_X11gwin_params x_crparams;     /*X11 window creation params */
69     struct gwin *newwin;        /*New (sub)window */
70     struct gwin_strparams strparams;    /*String-drawing params */
71     struct gwin_charparams charparams;  /*Char-drawing params */
72     char s[128];                /*Test string */
73     int currx, curry;           /*Sliding values of x & y */
74     int currhighlight;          /*Highlight this time around? */
75
76     /*
77      * Initialize the gator window package to drive the desired subsystem.
78      */
79     init_params.i_type = pkg;
80     init_params.i_x = 0;
81     init_params.i_y = 0;
82     init_params.i_width = 80;
83     init_params.i_height = 200;
84     init_params.i_debug = screen_debug;
85
86     code = gw_init(&init_params);
87     if (code) {
88         fprintf(stderr,
89                 "[%s:%s] Can't initialize gator windows for package %d; error is: %d\n",
90                 pn, rn, pkg, code);
91         return (code);
92     }
93
94     sprintf(s, "Screen has %d lines", LINES);
95     strparams.x = 5;
96     strparams.y = LINES / 2;
97     strparams.s = s;
98     strparams.highlight = 0;
99     WOP_DRAWSTRING(&gator_basegwin, &strparams);
100
101     sprintf(s, "and %d columns", COLS);
102     strparams.x = 5;
103     strparams.y = strparams.y + 1;
104     strparams.s = s;
105     strparams.highlight = 1;
106     WOP_DRAWSTRING(&gator_basegwin, &strparams);
107
108     /*
109      * Draw a set of chars down a diagonal, pausing inbetween.
110      */
111     currhighlight = 1;
112     for (currx = curry = 0; (currx < COLS) && (curry < LINES);
113          currx++, curry++) {
114         charparams.x = currx;
115         charparams.y = curry;
116         charparams.c = 'x';
117         charparams.highlight = currhighlight;
118         currhighlight = (currhighlight ? 0 : 1);
119         WOP_DRAWCHAR(&gator_basegwin, &charparams);
120         sleep(1);
121     }
122     WOP_BOX(&gator_basegwin);
123
124     /*
125      * Fill in the new window creation parameters and go for it.
126      */
127     c_crparams.gwin_params.cr_type = pkg;
128     c_crparams.gwin_params.cr_x = 40;
129     c_crparams.gwin_params.cr_y = 5;
130     c_crparams.gwin_params.cr_width = 20;
131     c_crparams.gwin_params.cr_height = 10;
132     c_crparams.gwin_params.cr_parentwin = (struct gwin *)(&gator_basegwin);
133     c_crparams.charwidth = 8;
134     c_crparams.charheight = 13;
135     c_crparams.box_vertchar = '|';
136     c_crparams.box_horizchar = '-';
137     newwin = WOP_CREATE(&c_crparams);
138     if (newwin == NULL) {
139         fprintf(stderr, "[%s:%s] Can't create a new window\n", pn, rn);
140     } else if (screen_debug)
141         fprintf(stderr, "[%s:%s] New window created at 0x%x\n", pn, rn,
142                 newwin);
143
144     /*
145      * Draw something to the new window; first, a highlighted banner.
146      */
147     sprintf(s, "%s", "Sub-window        ");
148     strparams.x = 1;
149     strparams.y = 1;
150     strparams.s = s;
151     strparams.highlight = 1;
152     WOP_DRAWSTRING(newwin, &strparams);
153
154     /*
155      * Next, draw an `x' at each corner.
156      */
157     charparams.c = 'x';
158     charparams.highlight = 1;
159     charparams.x = 1;
160     charparams.y = 2;
161     WOP_DRAWCHAR(newwin, &charparams);
162     charparams.x = 18;
163     charparams.y = 2;
164     WOP_DRAWCHAR(newwin, &charparams);
165     charparams.x = 1;
166     charparams.y = 8;
167     WOP_DRAWCHAR(newwin, &charparams);
168     charparams.x = 18;
169     charparams.y = 8;
170     WOP_DRAWCHAR(newwin, &charparams);
171
172     /*
173      * Finally, box the sucker.
174      */
175     WOP_BOX(newwin);
176
177     /*
178      * Draw a few other things in the original window.
179      */
180     sprintf(s, "Screen has %d lines", LINES);
181     strparams.x = 5;
182     strparams.y = LINES / 2;
183     strparams.s = s;
184     strparams.highlight = 0;
185     WOP_DRAWSTRING(&gator_basegwin, &strparams);
186
187     sprintf(s, "and %d columns", COLS);
188     strparams.x = 5;
189     strparams.y = strparams.y + 1;
190     strparams.s = s;
191     strparams.highlight = 1;
192     WOP_DRAWSTRING(&gator_basegwin, &strparams);
193
194     /*
195      * Let people admire the handiwork, then clean up.
196      */
197     WOP_DISPLAY(&gator_basegwin);
198     sleep(10);
199     WOP_DISPLAY(&gator_basegwin);
200     WOP_CLEANUP(&gator_basegwin);
201
202 }                               /*test_this_package */
203
204 /*--------------------------------------------------------------------------------
205  * screen_testInit
206  *
207  * Description:
208  *      Routine that is called when screen_test is invoked, responsible
209  *      for basic initialization and command line parsing.
210  *
211  * Arguments:
212  *      as      : Command syntax descriptor.
213  *      arock   : Associated rock (not used here).
214  *
215  * Returns:
216  *      Zero (but may exit the entire program on error!)
217  *
218  * Environment:
219  *      Nothing interesting.
220  *
221  * Side Effects:
222  *      Initializes this program.
223  *--------------------------------------------------------------------------------*/
224
225 static int
226 screen_testInit(struct cmd_syndesc *as, void *arock)
227 {                               /*screen_testInit */
228
229     static char rn[] = "screen_testInit";       /*Routine name */
230     int pkg_to_test;            /*Which package to test */
231
232     if (as->parms[P_DEBUG].items != 0)
233         screen_debug = 1;
234     pkg_to_test = atoi(as->parms[P_PACKAGE].items->data);
235     fprintf(stderr, "[%s:%s] Testing graphics package %d: ", pn, rn,
236             pkg_to_test);
237     switch (pkg_to_test) {
238     case GATOR_WIN_CURSES:
239         fprintf(stderr, "curses\n");
240         break;
241     case GATOR_WIN_DUMB:
242         fprintf(stderr, "dumb terminal\n");
243         break;
244     case GATOR_WIN_X11:
245         fprintf(stderr, "X11\n");
246         break;
247     default:
248         fprintf(stderr, "Illegal graphics package: %d\n", pkg_to_test);
249     }                           /*end switch (pkg_to_test) */
250
251     /*
252      * Now, drive the sucker.
253      */
254     test_this_package(pkg_to_test);
255
256     /*
257      * We initialized (and ran) correctly, so return the good news.
258      */
259     return (0);
260
261 }                               /*screen_testInit */
262
263 #include "AFS_component_version_number.c"
264
265 main(argc, argv)
266      int argc;
267      char **argv;
268
269 {                               /*main */
270
271     static char rn[] = "main";  /*Routine name */
272     afs_int32 code;     /*Return code */
273     struct cmd_syndesc *ts;     /*Ptr to cmd line syntax descriptor */
274
275     /*
276      * There really aren't any opcodes here, but we do want to interpret switches
277      * from the command line.  So, all we need do is set up the initcmd ``opcode''.
278      */
279     ts = cmd_CreateSyntax("initcmd", screen_testInit, NULL,
280                           "Initialize, interpret command line");
281     cmd_AddParm(ts, "-package", CMD_SINGLE, CMD_REQUIRED,
282                 "Graphics package to use");
283     cmd_AddParm(ts, "-debug", CMD_FLAG, CMD_OPTIONAL, "Turn debugging on");
284
285     /*
286      * Parse command-line switches & execute the test, then get the heck out of here.
287      */
288     code = cmd_Dispatch(argc, argv);
289     if (code) {
290         fprintf(stderr, "[%s:%s] Call to cmd_Dispatch() failed; code is %d\n",
291                 pn, rn, code);
292         exit(1);
293     }
294
295 }                               /*main */