Standardize License information
[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 "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*/
19
20 extern int errno;
21
22 /*
23  * Command line parameter indicies.
24  */
25 #define P_PACKAGE   0
26 #define P_DEBUG     1
27
28 static char pn[] = "screen_test";   /*Program name*/
29 static int screen_debug = 0;        /*Is debugging turned on?*/
30
31 /*--------------------------------------------------------------------------------
32  * test_this_package
33  *
34  * Description:
35  *      Routine that does the actual testing of the chosen graphics
36  *      package.
37  *
38  * Arguments:
39  *      pkg : Number of package to test.
40  *
41  * Returns:
42  *      0 on success,
43  *      Error value otherwise.
44  *
45  * Environment:
46  *      Nothing interesting.
47  *
48  * Side Effects:
49  *      As advertised.
50  *--------------------------------------------------------------------------------*/
51
52 static int test_this_package(pkg)
53     int pkg;
54
55 { /*test_this_package*/
56
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?*/
69
70     /*
71      * Initialize the gator window package to drive the desired subsystem.
72      */
73     init_params.i_type   = pkg;
74     init_params.i_x      =   0;
75     init_params.i_y      =   0;
76     init_params.i_width  =  80;
77     init_params.i_height = 200;
78     init_params.i_debug  = screen_debug;
79
80     code = gw_init(&init_params);
81     if (code) {
82         fprintf(stderr, "[%s:%s] Can't initialize gator windows for package %d; error is: %d\n", pn, rn, pkg, code);
83         return(code);
84     }
85
86     sprintf(s, "Screen has %d lines", LINES);
87     strparams.x         = 5;
88     strparams.y         = LINES / 2;
89     strparams.s         = s;
90     strparams.highlight = 0;
91     WOP_DRAWSTRING(&gator_basegwin, &strparams);
92
93     sprintf(s, "and %d columns", COLS);
94     strparams.x         = 5;
95     strparams.y         = strparams.y + 1;
96     strparams.s         = s;
97     strparams.highlight = 1;
98     WOP_DRAWSTRING(&gator_basegwin, &strparams);
99
100     /*
101      * Draw a set of chars down a diagonal, pausing inbetween.
102      */
103     currhighlight = 1;
104     for (currx = curry = 0; (currx < COLS) && (curry < LINES); currx++, curry++) {
105         charparams.x        = currx;
106         charparams.y        = curry;
107         charparams.c        = 'x';
108         charparams.highlight = currhighlight;
109         currhighlight = (currhighlight ? 0 : 1);
110         WOP_DRAWCHAR(&gator_basegwin, &charparams);
111         sleep(1);
112     }
113     WOP_BOX(&gator_basegwin);
114
115     /*
116      * Fill in the new window creation parameters and go for it.
117      */
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);
131     }
132     else
133         if (screen_debug)
134             fprintf(stderr, "[%s:%s] New window created at 0x%x\n", pn, rn, newwin);
135
136     /*
137      * Draw something to the new window; first, a highlighted banner.
138      */
139     sprintf(s, "%s", "Sub-window        ");
140     strparams.x         = 1;
141     strparams.y         = 1;
142     strparams.s         = s;
143     strparams.highlight = 1;
144     WOP_DRAWSTRING(newwin, &strparams);
145
146     /*
147      * Next, draw an `x' at each corner.
148      */
149     charparams.c         = 'x';
150     charparams.highlight = 1;
151     charparams.x         = 1;
152     charparams.y         = 2;
153     WOP_DRAWCHAR(newwin, &charparams);
154     charparams.x         = 18;
155     charparams.y         = 2;
156     WOP_DRAWCHAR(newwin, &charparams);
157     charparams.x         = 1;
158     charparams.y         = 8;
159     WOP_DRAWCHAR(newwin, &charparams);
160     charparams.x         = 18;
161     charparams.y         = 8;
162     WOP_DRAWCHAR(newwin, &charparams);
163
164     /*
165      * Finally, box the sucker.
166      */
167     WOP_BOX(newwin);
168
169     /*
170       * Draw a few other things in the original window.
171       */
172     sprintf(s, "Screen has %d lines", LINES);
173     strparams.x         = 5;
174     strparams.y         = LINES / 2;
175     strparams.s         = s;
176     strparams.highlight = 0;
177     WOP_DRAWSTRING(&gator_basegwin, &strparams);
178
179     sprintf(s, "and %d columns", COLS);
180     strparams.x         = 5;
181     strparams.y         = strparams.y + 1;
182     strparams.s         = s;
183     strparams.highlight = 1;
184     WOP_DRAWSTRING(&gator_basegwin, &strparams);
185
186     /*
187      * Let people admire the handiwork, then clean up.
188      */
189     WOP_DISPLAY(&gator_basegwin);
190     sleep(10);
191     WOP_DISPLAY(&gator_basegwin);
192     WOP_CLEANUP(&gator_basegwin);
193
194 } /*test_this_package*/
195
196 /*--------------------------------------------------------------------------------
197  * screen_testInit
198  *
199  * Description:
200  *      Routine that is called when screen_test is invoked, responsible
201  *      for basic initialization and command line parsing.
202  *
203  * Arguments:
204  *      as      : Command syntax descriptor.
205  *      arock   : Associated rock (not used here).
206  *
207  * Returns:
208  *      Zero (but may exit the entire program on error!)
209  *
210  * Environment:
211  *      Nothing interesting.
212  *
213  * Side Effects:
214  *      Initializes this program.
215  *--------------------------------------------------------------------------------*/
216
217 static int screen_testInit(as, arock)
218     struct cmd_syndesc *as;
219     char *arock;
220
221 { /*screen_testInit*/
222
223     static char rn[] = "screen_testInit";   /*Routine name*/
224     int pkg_to_test;                        /*Which package to test*/
225
226     if (as->parms[P_DEBUG].items != 0)
227         screen_debug = 1;
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");
233             break;
234         case GATOR_WIN_DUMB:
235             fprintf(stderr, "dumb terminal\n");
236             break;
237         case GATOR_WIN_X11:
238             fprintf(stderr, "X11\n");
239             break;
240         default:
241             fprintf(stderr, "Illegal graphics package: %d\n", pkg_to_test);
242     } /*end switch (pkg_to_test)*/
243
244     /*
245      * Now, drive the sucker.
246      */
247     test_this_package(pkg_to_test);
248
249     /*
250      * We initialized (and ran) correctly, so return the good news.
251      */
252     return(0);
253
254 } /*screen_testInit*/
255
256 #include "AFS_component_version_number.c"
257
258 main(argc, argv)
259     int argc;
260     char **argv;
261
262 { /*main*/
263
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*/
267
268     /*
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''.
271      */
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");
275
276     /*
277      * Parse command-line switches & execute the test, then get the heck out of here.
278      */
279     code = cmd_Dispatch(argc, argv);
280     if (code) {
281         fprintf(stderr, "[%s:%s] Call to cmd_Dispatch() failed; code is %d\n", pn, rn, code);
282         exit(1);
283     }
284
285 } /*main*/