2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
25 * $XConsortium: gil_loadfile.c /main/3 1995/11/06 18:29:14 rswiston $
29 * Routines to load in GUIDE intermediate language (GIL) files.
32 #include <sys/param.h>
33 #include <sys/types.h>
38 #include <ab_private/util.h>
39 #include <ab_private/abio.h>
40 #include <ab_private/trav.h>
41 #include <ab_private/gil.h>
44 #include "../libABobj/obj_utils.h"
48 * Read a GIL file into memory.
58 int rc = 0; /* r turn code */
61 ABObj interface = NULL;
62 AB_FILE_TYPE file_type = AB_FILE_UNDEF;
63 FILE *gilInFile = NULL;
65 /* printf("gil_load_file(%s)\n", gil_file); */
73 abil_loadmsg_set_line_number_callback(NULL); /*don't report line#*/
74 abil_loadmsg_set_file(gil_file);
77 * Create the root node for this beastie.
79 interface = obj_scoped_find_or_create_undef(project,
80 ab_ident_from_file_name(gil_file), AB_TYPE_MODULE);
81 if (interface == NULL)
83 abil_print_load_err(ERR_NO_MEMORY);
87 obj_set_file(interface, gil_file);
88 obj_set_is_defined(interface, TRUE);
91 * Open the input file.
99 if ((errmsg = abio_open_gil_input(gil_file, &gilInFile)) != NULL)
105 if (!util_be_silent())
106 fprintf(stderr, "%s: reading %s\n",
107 util_get_program_name(), gil_file);
111 * Find start of first object (should be interface)
113 if (abio_get_eof(gilInFile))
115 abil_print_load_err(ERR_EOF);
119 if (!abio_gil_get_object_begin(gilInFile))
121 abil_print_load_err(ERR_WANT_OBJECT);
127 * Loop reading the input file until there are no more objects.
129 while (!abio_get_file_end(gilInFile))
131 if (abio_get_eof(gilInFile))
133 abil_print_load_err(ERR_EOF);
137 if (!abio_gil_get_object_begin(gilInFile))
139 abil_print_load_err(ERR_WANT_OBJECT);
143 if ((rc = gilP_load_object(gilInFile, interface)) < 0)
150 if (inFile == NULL) /* don't close passed-in stream */
152 abio_close_input(gilInFile);
156 if (return_value < 0)
158 if (interface != NULL)
160 obj_destroy(interface);
164 if (interface != NULL)
166 obj_set_is_defined(interface, TRUE);
169 } /* gil_load_file */
173 * Loads in a GIL project file - DOES NOT LOAD IN THE INTERFACES IN
177 gil_load_project_file(
183 int return_value = 0;
184 int rc = 0; /* r turn code */
185 STRING errmsg = NULL;
186 ABObj project = obj_create(AB_TYPE_PROJECT, NULL);
187 FILE *gilInFile = NULL;
190 "gil_load_project_file(%s)\n", util_strsafe(project_file));
192 abil_loadmsg_clear();
193 abil_loadmsg_set_line_number_callback(NULL); /*don't report line#*/
194 abil_loadmsg_set_file(project_file);
198 abil_print_load_err(ERR_NO_MEMORY);
202 project->info.project.is_default = FALSE; /* spec'd by user */
203 obj_set_file(project, strdup(project_file));
204 obj_set_name(project, ab_ident_from_file_name(project_file));
207 * Some bonehead decided that a project file should consist of only one
208 * object and not have the surrounding parens like a GIL file. So, we
209 * can't use load_interface.
217 if ((errmsg = abio_open_gil_input(project_file, &gilInFile)) != NULL)
223 if (!util_be_silent())
225 fprintf(stderr, "%s: reading %s\n",
226 util_get_program_name(), project_file);
231 * Find start of project object
233 if (abio_get_eof(gilInFile))
235 abil_print_load_err(ERR_EOF);
239 if (!abio_gil_get_object_begin(gilInFile))
241 abil_print_load_err(ERR_WANT_OBJECT);
247 * The project is it's own parent...
249 if ((rc = gilP_load_object2(gilInFile, project, project)) < 0)
256 abio_close_input(gilInFile);
260 if (return_value < 0)
262 obj_destroy(project);
266 *projectOutPtr = project;
272 gil_load_project_file_and_resolve_all(
278 int return_value = 0;
280 ABObj project = NULL;
282 ABObj interface = NULL;
285 if ((rc = gil_load_project_file(project_file, inFile, &project)) < 0)
292 * Load in the interfaces referenced in the project file
294 for (trav_open(&trav, project, AB_TRAV_MODULES | AB_TRAV_MOD_SAFE);
295 (interface = trav_next(&trav)) != NULL; )
297 if (!obj_is_defined(interface))
299 if (gil_load_file(obj_get_file(interface), NULL, project) == NULL)
309 if (return_value < 0)
311 obj_destroy(project);
313 (*projectOutPtr) = project;