gtx-prototypes-20090316
[openafs.git] / src / gtx / windows.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  * gator_windows.c
12  *
13  * Description:
14  *      Implementation of the gator windows interface.
15  *
16  *--------------------------------------------------------------------------------*/
17
18 #include <afsconfig.h>
19 #include <afs/param.h>
20
21 RCSID
22     ("$Header$");
23
24 /* On DUX "IN" is a variable in curses.h, so this can be a bit of a problem */
25 #ifdef IN
26 #undef IN
27 #endif
28
29 #include "gtxwindows.h"         /*Interface for this module */
30 #include "gtxcurseswin.h"       /*Interface for the curses module */
31 #include "gtxdumbwin.h"         /*Interface for the dumb terminal module */
32 #include "gtxX11win.h"          /*Interface for the X11 module */
33
34 static char mn[] = "gator_windows";     /*Module name */
35 struct gwinbaseops gwinbops;    /*Base window operation fn array */
36 struct gwin gator_basegwin;     /*Base gator window */
37
38 /*--------------------------------------------------------------------------------
39  * gw_init
40  *
41  * Description:
42  *      Initialize the gator window package.
43  *
44  * Arguments:
45  *      struct gwin_initparams *params : Ptr to initialization params.
46  *
47  * Returns:
48  *      0 on success,
49  *      Error value otherwise.
50  *
51  * Environment:
52  *      *** MUST BE THE FIRST ROUTINE CALLED FROM
53  *            THIS PACKAGE ***
54  *
55  * Side Effects:
56  *      Sets up the chosen lower-level graphics package, as well
57  *      as the base operation array (gwinbops).  Also sets up the
58  *      base window.
59  *--------------------------------------------------------------------------------*/
60
61 int
62 gw_init(struct gwin_initparams *params)
63 {                               /*gw_init */
64
65     static char rn[] = "gw_init";       /*Routine name */
66     register int code;          /*Return code */
67     int gwin_debug;             /*Is debugging turned on? */
68
69     /*
70      * Remember our debugging level.
71      */
72     gwin_debug = params->i_debug;
73     if (gwin_debug)
74         fprintf(stderr, "[%s:%s] Window debugging turned on\n", mn, rn);
75
76     /*
77      * What we do/call depends on the type of lower-level graphics
78      * package we'll be using.
79      */
80     switch (params->i_type) {
81     case GATOR_WIN_DUMB:        /*Dumb terminal */
82         if (gwin_debug)
83             fprintf(stderr,
84                     "[%s:%s] Initializing for the dumb terminal package\n",
85                     mn, rn);
86         gwinbops = gator_dumb_gwinbops;
87         code = gator_dumbgwin_init(gwin_debug);
88         if (code) {
89             fprintf(stderr,
90                     "[%s:%s] Error in dumb terminal initialization routine, gator_dumbgwin_init(): %d\n",
91                     mn, rn, code);
92             return (code);
93         }
94         break;
95
96     case GATOR_WIN_CURSES:      /*Curses */
97         if (gwin_debug)
98             fprintf(stderr, "[%s:%s] Initializing for the curses package\n",
99                     mn, rn);
100         gwinbops = gator_curses_gwinbops;
101         code = gator_cursesgwin_init(gwin_debug);
102         if (code) {
103             fprintf(stderr,
104                     "[%s:%s] Error in curses initialization routine, gator_cursesgwin_init(): %d\n",
105                     mn, rn, code);
106             return (code);
107         }
108         break;
109
110     case GATOR_WIN_X11: /*X11 */
111         if (gwin_debug)
112             fprintf(stderr, "[%s:%s] Initializing for the X11 package\n", mn,
113                     rn);
114         gwinbops = gator_X11_gwinbops;
115         code = gator_X11gwin_init(params);
116         if (code) {
117             fprintf(stderr,
118                     "[%s:%s] Error in X11 initialization routine, gator_X11gwin_init(): %d\n",
119                     mn, rn, code);
120             return (code);
121         }
122         break;
123
124     default:
125         fprintf(stderr, "[%s:%s] Illegal choice of graphics system: %d\n", mn,
126                 rn, params->i_type);
127         fprintf(stderr, "\tLegal choices are:\n");
128         fprintf(stderr, "\t\t%d: Dumb terminal\n", GATOR_WIN_DUMB);
129         fprintf(stderr, "\t\t%d: Curses\n", GATOR_WIN_CURSES);
130         fprintf(stderr, "\t\t%d: X11\n", GATOR_WIN_X11);
131         return (-1);
132     }                           /*end switch (params->i_type) */
133
134     /*
135      * Finally, return the good news.
136      */
137     return (0);
138
139 }                               /*gw_init */