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