pull-prototypes-to-head-20020821
[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("$Header$");
18
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*/
24
25 extern int errno;
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 test_this_package(pkg)
58     int pkg;
59
60 { /*test_this_package*/
61
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?*/
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, "[%s:%s] Can't initialize gator windows for package %d; error is: %d\n", pn, rn, pkg, code);
88         return(code);
89     }
90
91     sprintf(s, "Screen has %d lines", LINES);
92     strparams.x         = 5;
93     strparams.y         = LINES / 2;
94     strparams.s         = s;
95     strparams.highlight = 0;
96     WOP_DRAWSTRING(&gator_basegwin, &strparams);
97
98     sprintf(s, "and %d columns", COLS);
99     strparams.x         = 5;
100     strparams.y         = strparams.y + 1;
101     strparams.s         = s;
102     strparams.highlight = 1;
103     WOP_DRAWSTRING(&gator_basegwin, &strparams);
104
105     /*
106      * Draw a set of chars down a diagonal, pausing inbetween.
107      */
108     currhighlight = 1;
109     for (currx = curry = 0; (currx < COLS) && (curry < LINES); currx++, curry++) {
110         charparams.x        = currx;
111         charparams.y        = curry;
112         charparams.c        = 'x';
113         charparams.highlight = currhighlight;
114         currhighlight = (currhighlight ? 0 : 1);
115         WOP_DRAWCHAR(&gator_basegwin, &charparams);
116         sleep(1);
117     }
118     WOP_BOX(&gator_basegwin);
119
120     /*
121      * Fill in the new window creation parameters and go for it.
122      */
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);
136     }
137     else
138         if (screen_debug)
139             fprintf(stderr, "[%s:%s] New window created at 0x%x\n", pn, rn, newwin);
140
141     /*
142      * Draw something to the new window; first, a highlighted banner.
143      */
144     sprintf(s, "%s", "Sub-window        ");
145     strparams.x         = 1;
146     strparams.y         = 1;
147     strparams.s         = s;
148     strparams.highlight = 1;
149     WOP_DRAWSTRING(newwin, &strparams);
150
151     /*
152      * Next, draw an `x' at each corner.
153      */
154     charparams.c         = 'x';
155     charparams.highlight = 1;
156     charparams.x         = 1;
157     charparams.y         = 2;
158     WOP_DRAWCHAR(newwin, &charparams);
159     charparams.x         = 18;
160     charparams.y         = 2;
161     WOP_DRAWCHAR(newwin, &charparams);
162     charparams.x         = 1;
163     charparams.y         = 8;
164     WOP_DRAWCHAR(newwin, &charparams);
165     charparams.x         = 18;
166     charparams.y         = 8;
167     WOP_DRAWCHAR(newwin, &charparams);
168
169     /*
170      * Finally, box the sucker.
171      */
172     WOP_BOX(newwin);
173
174     /*
175       * Draw a few other things in the original window.
176       */
177     sprintf(s, "Screen has %d lines", LINES);
178     strparams.x         = 5;
179     strparams.y         = LINES / 2;
180     strparams.s         = s;
181     strparams.highlight = 0;
182     WOP_DRAWSTRING(&gator_basegwin, &strparams);
183
184     sprintf(s, "and %d columns", COLS);
185     strparams.x         = 5;
186     strparams.y         = strparams.y + 1;
187     strparams.s         = s;
188     strparams.highlight = 1;
189     WOP_DRAWSTRING(&gator_basegwin, &strparams);
190
191     /*
192      * Let people admire the handiwork, then clean up.
193      */
194     WOP_DISPLAY(&gator_basegwin);
195     sleep(10);
196     WOP_DISPLAY(&gator_basegwin);
197     WOP_CLEANUP(&gator_basegwin);
198
199 } /*test_this_package*/
200
201 /*--------------------------------------------------------------------------------
202  * screen_testInit
203  *
204  * Description:
205  *      Routine that is called when screen_test is invoked, responsible
206  *      for basic initialization and command line parsing.
207  *
208  * Arguments:
209  *      as      : Command syntax descriptor.
210  *      arock   : Associated rock (not used here).
211  *
212  * Returns:
213  *      Zero (but may exit the entire program on error!)
214  *
215  * Environment:
216  *      Nothing interesting.
217  *
218  * Side Effects:
219  *      Initializes this program.
220  *--------------------------------------------------------------------------------*/
221
222 static int screen_testInit(as, arock)
223     struct cmd_syndesc *as;
224     char *arock;
225
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, pkg_to_test);
235     switch (pkg_to_test) {
236         case GATOR_WIN_CURSES:
237             fprintf(stderr, "curses\n");
238             break;
239         case GATOR_WIN_DUMB:
240             fprintf(stderr, "dumb terminal\n");
241             break;
242         case GATOR_WIN_X11:
243             fprintf(stderr, "X11\n");
244             break;
245         default:
246             fprintf(stderr, "Illegal graphics package: %d\n", pkg_to_test);
247     } /*end switch (pkg_to_test)*/
248
249     /*
250      * Now, drive the sucker.
251      */
252     test_this_package(pkg_to_test);
253
254     /*
255      * We initialized (and ran) correctly, so return the good news.
256      */
257     return(0);
258
259 } /*screen_testInit*/
260
261 #include "AFS_component_version_number.c"
262
263 main(argc, argv)
264     int argc;
265     char **argv;
266
267 { /*main*/
268
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*/
272
273     /*
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''.
276      */
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");
280
281     /*
282      * Parse command-line switches & execute the test, then get the heck out of here.
283      */
284     code = cmd_Dispatch(argc, argv);
285     if (code) {
286         fprintf(stderr, "[%s:%s] Call to cmd_Dispatch() failed; code is %d\n", pn, rn, code);
287         exit(1);
288     }
289
290 } /*main*/