Pull in patch that properly includes stdint.h
[pkg-k5-afs_openafs.git] / src / gtx / objects.c
blob1dfcf95293708f940dca193b71cbe24eb796514b
1 /*
2 * Copyright 2000, International Business Machines Corporation and others.
3 * All Rights Reserved.
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 */
11 * Description:
12 * Implementation of the gator object interface.
14 *------------------------------------------------------------------------*/
16 #include <afsconfig.h>
17 #include <afs/param.h>
20 #include "gtxobjects.h" /*Interface for this module */
21 #include "gtxtextobj.h" /*Text object interface */
22 #include "gtxlightobj.h" /*Light object interface */
23 #include "gtxobjdict.h" /*Object dictionary module */
24 #include <stdio.h> /*Standard I/O stuff */
25 #include <errno.h>
27 #include <string.h>
28 #include <stdlib.h>
31 * Number of known gator object types.
33 #define GATOR_NUM_OBJTYPES 3
35 static char mn[] = "gator_objects"; /*Module name */
36 int objects_debug; /*Is debugging output on? */
38 int (*on_create[GATOR_NUM_OBJTYPES]) (struct onode *,
39 struct onode_createparams *);
40 /*Array of ptrs to creation functions */
42 struct onodeops objops[GATOR_NUM_OBJTYPES]; /*Per-type op arrays */
45 /*--------------------------------------------------------------------------------
46 * gator_objects_init
48 * Description:
49 * Initialize the gator object package.
51 * Arguments:
52 * struct onode_initparams *params: Initialization parameters.
54 * Returns:
55 * 0 on success,
56 * Error value otherwise.
58 * Environment:
59 * *** MUST BE THE FIRST ROUTINE CALLED FROM
60 * THIS PACKAGE ***
62 * Side Effects:
64 *--------------------------------------------------------------------------------*/
66 int
67 gator_objects_init(struct onode_initparams *params)
68 { /*gator_objects_init */
70 static char rn[] = "gator_objects_init"; /*Routine name */
71 static int initialized = 0; /*Have we been called? */
72 int code; /*Return code */
75 * If we've already been called, just return.
77 if (initialized) {
78 initialized++;
79 if (objects_debug)
80 fprintf(stderr, "[%s:%s] Called more than once!! (%d time[s])\n",
81 mn, rn, initialized);
82 return (0);
86 * Remember our debugging level.
88 objects_debug = params->i_debug;
91 * Set up the onode op array, one entry for each known gator object type.
93 if (objects_debug)
94 fprintf(stderr, "[%s:%s] Setting up objops array\n", mn, rn);
95 objops[GATOR_OBJ_TEXT] = gator_text_ops;
96 objops[GATOR_OBJ_LIGHT] = gator_light_ops;
99 * Initialize the object dictionary.
101 if (objects_debug)
102 fprintf(stderr, "[%s:%s] Initializing object dictionary\n", mn, rn);
103 code = gator_objdict_init(objects_debug);
104 if (code) {
105 fprintf(stderr,
106 "[%s:%s] Can't initialize object dictionary: error code is %d\n",
107 mn, rn, code);
108 return (code);
112 * Initialize the chosen window package. Remember the base window
113 * is accessible as gator_basegwin.
115 if (objects_debug) {
116 fprintf(stderr,
117 "[%s:%s] Initializing gator window module for package %d.\n",
118 mn, rn, params->i_gwparams->i_type);
119 fprintf(stderr,
120 "\tWindow init params are: type %d, (%d, %d), width=%d, height=%d, debug=%d\n",
121 params->i_gwparams->i_type, params->i_gwparams->i_x,
122 params->i_gwparams->i_y, params->i_gwparams->i_width,
123 params->i_gwparams->i_height, params->i_gwparams->i_debug);
125 code = gw_init(params->i_gwparams);
126 if (code) {
127 fprintf(stderr,
128 "[%s:%s] Can't initialize gator windows for package %d; error is: %d\n",
129 mn, rn, params->i_gwparams->i_type, code);
130 return (code);
134 * Set up the array of creation functions.
136 if (objects_debug)
137 fprintf(stderr,
138 "[%s:%s] Initializing gator object creation function array.\n",
139 mn, rn);
140 on_create[GATOR_OBJ_TEXT] = gator_text_create;
141 on_create[GATOR_OBJ_LIGHT] = gator_light_create;
144 * Finally, return the good news.
146 return (0);
148 } /*gator_objects_init */
150 /*--------------------------------------------------------------------------------
151 * gator_objects_create
153 * Description:
154 * Create an onode of the given type.
156 * Arguments:
157 * struct onode_createparams *params: Ptr to creation params.
159 * Returns:
160 * Ptr to newly-created onode if successful,
161 * Null pointer otherwise.
163 * Environment:
164 * Nothing interesting.
166 * Side Effects:
167 * As advertised.
168 *--------------------------------------------------------------------------------*/
170 struct onode *
171 gator_objects_create(struct onode_createparams *params)
172 { /*gator_objects_create */
174 static char rn[] = "gator_objects_create"; /*Routine name */
175 int code; /*Return code */
176 struct onode *new_onode; /*Ptr to new onode */
178 if (objects_debug) {
179 fprintf(stderr, "[%s:%s] Creating onode type %d, named '%s'\n", mn,
180 rn, params->cr_type, params->cr_name);
181 fprintf(stderr, "\tOrigin at (%d, %d)\n", params->cr_x, params->cr_y);
182 fprintf(stderr, "\tWidth=%d, height=%d\n", params->cr_width,
183 params->cr_height);
184 fprintf(stderr, "\tHelpstring='%s'\n", params->cr_helpstring);
185 fprintf(stderr, "\tWindow struct at %p\n", params->cr_window);
188 if (objects_debug)
189 fprintf(stderr,
190 "[%s:%s] Allocating %" AFS_SIZET_FMT " bytes for new onode structure\n", mn,
191 rn, sizeof(struct onode));
192 new_onode = (struct onode *)malloc(sizeof(struct onode));
193 if (new_onode == NULL) {
194 fprintf(stderr,
195 "[%s:%s] Can't allocate %" AFS_SIZET_FMT " bytes for new onode structure; errno is %d\n",
196 mn, rn, sizeof(struct onode), errno);
197 return (NULL);
201 * Fill in the onode fields we can do right away.
202 * **** Don't do anything with cr_helpstring yet - eventually,
203 * we'll create a scrollable text help object with it ****
205 if (objects_debug)
206 fprintf(stderr, "[%s:%s] Filling in onode fields\n", mn, rn);
207 new_onode->o_type = params->cr_type;
208 strcpy(new_onode->o_name, params->cr_name);
209 new_onode->o_x = params->cr_x;
210 new_onode->o_y = params->cr_y;
211 new_onode->o_width = params->cr_width;
212 new_onode->o_height = params->cr_height;
213 new_onode->o_changed = 1;
214 new_onode->o_refcount = 1;
215 new_onode->o_window = params->cr_window;
216 new_onode->o_op = &(objops[params->cr_type]);
217 new_onode->o_home = params->cr_home_obj;
218 new_onode->o_help = NULL;
219 new_onode->o_nextobj = NULL;
220 new_onode->o_upobj = params->cr_parent_obj;
221 new_onode->o_downobj = NULL;
224 * Call the proper routine to initialize the private parts of the
225 * given object.
227 if (objects_debug)
228 fprintf(stderr,
229 "[%s:%s] Calling the creation routine for gator object type %d\n",
230 mn, rn, params->cr_type);
231 code = (on_create[params->cr_type]) (new_onode, params);
232 if (code) {
233 if (objects_debug)
234 fprintf(stderr,
235 "[%s:%s] Error %d in creation routine for gator object type %d\n",
236 mn, rn, code, params->cr_type);
237 free(new_onode);
238 return (NULL);
242 * Set the links on the parent and previous objects, if so directed.
244 if (params->cr_prev_obj != NULL) {
245 if (objects_debug)
246 fprintf(stderr,
247 "[%s:%s] Setting o_nextobj pointer in the previous object located at %p (previous value was %p)\n",
248 mn, rn, params->cr_prev_obj,
249 params->cr_prev_obj->o_nextobj);
250 params->cr_prev_obj->o_nextobj = new_onode;
252 if (params->cr_parent_obj != NULL) {
253 if (objects_debug)
254 fprintf(stderr,
255 "[%s:%s] Setting o_downobj pointer in the parent object located at %p (previous value was %p)\n",
256 mn, rn, params->cr_parent_obj,
257 params->cr_parent_obj->o_downobj);
258 params->cr_parent_obj->o_downobj = new_onode;
262 * Return the location of the completely-initialized onode object.
264 return (new_onode);
266 } /*gator_objects_create */
268 /*--------------------------------------------------------------------------------
269 * gator_objects_lookup
271 * Description:
274 * Arguments:
275 * char *onode_name: Onode string name to find.
277 * Returns:
278 * Ptr to onode matching the given name if one exists,
279 * Null pointer otherwise.
281 * Environment:
282 * Nothing interesting.
284 * Side Effects:
285 * As advertised.
286 *--------------------------------------------------------------------------------*/
288 struct onode *
289 gator_objects_lookup(char *onode_name)
290 { /*gator_objects_lookup */
292 static char rn[] = "gator_objects_lookup"; /*Routine name */
295 * Life is very simple here - just call the dictionary routine.
297 if (objects_debug)
298 fprintf(stderr, "[%s:%s] Looking up gator object '%s'\n", mn, rn,
299 onode_name);
300 return (gator_objdict_lookup(onode_name));
302 } /*gator_objects_lookup */