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 libraries and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
24 * COMPONENT_NAME: austext
34 * (C) COPYRIGHT International Business Machines Corp. 1991,1995
36 * Licensed Materials - Property of IBM
37 * US Government Users Restricted Rights - Use, duplication or
38 * disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
40 /******************************* DTOEINIT.C ********************************
41 * $XConsortium: dtoeinit.c /main/6 1996/11/21 19:49:29 drk $
43 * Contains oe_initialize() function from universal "Opera Engine" code.
44 * Has been separated out because it is the largest function and
45 * needs to be tested separately.
48 * Revision 2.4 1996/03/13 22:52:04 miker
49 * Enabled several language loading debug requests from API.
51 * Revision 2.3 1995/10/25 21:59:27 miker
52 * Renamed from oeinit.c. Added prolog.
55 * Revision 2.2 1995/10/02 20:39:22 miker
56 * Added zbflags arg to load_semantic().
58 * Revision 2.1 1995/09/22 21:38:53 miker
59 * Freeze DtSearch 0.1, AusText 2.1.8
61 * Revision 1.14 1995/09/05 18:58:01 miker
62 * Changed all socblk refs to universal, global usrblk (no more merges).
63 * Deleted numerous globals. Added DTSEARCH define.
64 * Conflated all msglists to one ausapi_msglist. All for DtSearch...
71 #define XOS_USE_NO_LOCKING
72 #define X_INCLUDE_TIME_H
73 #include <X11/Xos_r.h>
75 #define PROGNAME "DTOEINIT"
79 extern int debugging_loadlang;
81 /************************************************/
85 /************************************************/
86 /* macro to test and free any malloc'ed pointer */
87 #define UNMALLOC(ptr) if(ptr){free(ptr);ptr=NULL;}
90 /********************************/
94 /********************************/
95 /* Dumps values from passed dblk.
96 * Used only for debugging initialization.
98 static void dump_dblk (char *msgprefix, DBLK *d)
101 fprintf (aa_stderr, "%s: DBLK v#%d name='%s' label='%s', path='%s'\n",
102 NULLORSTR (msgprefix), d->vistano, NULLORSTR (d->name),
103 NULLORSTR (d->label), NULLORSTR (d->path));
104 fprintf (aa_stderr, " mx=%d kt=", d->maxhits);
105 for (i = 0; i < d->ktcount; i++) {
106 fputc (' ', aa_stderr);
107 if (d->keytypes[i].is_selected)
108 fputc ('*', aa_stderr);
109 fputc (d->keytypes[i].ktchar, aa_stderr);
111 fputc ('\n', aa_stderr);
116 /************************************************/
120 /************************************************/
121 /* - verify version number compatibilities.
122 * - initialize socblk and OE_... globals.
123 * - load site defaults ocf file and create database list.
124 * - load dictionaries.
125 * - merge site defaults into usrblk.
126 * - open database(s).
128 void oe_initialize (void)
131 int good_dblk_count = 0;
132 DBLK *db, *bad_db, **lastlink;
133 char sprintbuf[1024];
137 if (usrblk.debug & USRDBG_RARE)
138 fprintf (aa_stderr, PROGNAME "555 Entered Engine Initialization.\n");
139 debugging_loadlang = (usrblk.debug & USRDBG_RARE);
141 /* Initialize most of the engine's globals.
142 * OE_bit_vector_size is set in ve_initialize().
143 * OE_bmhtab... are set by boyer-moore string searches only.
144 * OE_prodname is initialized by compiler and maybe changed by main().
145 * OE_expiration is initialized by compiler and never reset.
146 * OE_sitecnfg_fname is initialized by ausapi or loadocf and never reset.
147 * OE_sitecnfg_mtime is initialized by oe_initialize() and never reset.
149 global_memory_ptr = NULL;
150 austext_exit_mem = (void (*) (int)) release_shm_mem;
154 OE_search_type = 'P'; /* default is statistical searches */
155 OE_words_hitlimit = WORDS_HITLIMIT;
156 OE_enable_markdel = FALSE; /* former lvl2 default: TRUE */
157 OE_enable_usernotes = FALSE; /* former lvl2 default: TRUE */
158 OE_fastdecode = FALSE; /* former lvl2 default: TRUE */
159 OE_fileio = "-OFF"; /* former lvl2 default: "-ON" */
160 OE_uppercase_keys = FALSE; /* former lvl2 default: TRUE */
162 OEF_audit = FNAME_AUDIT;
163 OEF_discard = FNAME_DISCARD_DATA;
164 OEF_news = FNAME_SITENEWS;
165 OEF_notesnot = FNAME_NOTES_BAC;
166 OEF_notessem = FNAME_NOTES_SEM;
167 OEF_readme = FNAME_README;
169 for (oef = oef_table; oef->id != NULL; oef++)
170 oef->previously_specified = FALSE;
173 /* Verify version number compatibility between engine and UI.
174 * Only checked if request is OE_INITIALIZE, not on reinits.
176 if (usrblk.request == OE_INITIALIZE) {
177 if (!is_compatible_version (usrblk.query, SCHEMA_VERSION) ||
178 !is_compatible_version (usrblk.query, PROTOCOL_VERSION)) {
179 if (usrblk.query != NULL)
182 ptr = catgets (dtsearch_catd, MS_misc, 6, "<unknown>");
183 sprintf (sprintbuf, catgets (dtsearch_catd, MS_oeinit, 137,
184 "%s User Interface version %s and Engine "
185 "version %s are incompatible."),
186 PROGNAME"137", ptr, AUSAPI_VERSION);
187 DtSearchAddMessage (sprintbuf);
188 usrblk.retncode = OE_NOTAVAIL;
193 /* Load site configuration (ocf) file and create dblks list */
195 sprintf (sprintbuf, catgets (dtsearch_catd, MS_oeinit, 202,
196 "%s Initialization failed due to errors in configuration file."),
198 DtSearchAddMessage (sprintbuf);
199 usrblk.retncode = OE_NOTAVAIL;
203 /* Had to wait to write audit file till after site config set the flags */
204 if (OE_flags & OE_AUDIT || usrblk.debug & USRDBG_RARE) {
206 "ENGINEINIT='%s' UVER='%s' " AUDIT_WHOWHEN "\n",
207 AUSAPI_VERSION, usrblk.query, usrblk.userid,
209 if (usrblk.debug & USRDBG_RARE)
210 fprintf (aa_stderr, PROGNAME "362 %s", sprintbuf);
211 if (OE_flags & OE_AUDIT) {
212 if ((stream = fopen (OEF_audit, "a ")) != NULL)
213 /* the blank in "a " works around old aix bug */
215 fputs (sprintbuf, stream);
219 } /* endif to write to audit file */
222 /* ---- DATABASES PASSES #1 - #3 ------------------------------------
223 * Call vista to open databases and load system (dbrec) records.
224 * Where possible, this call will forgive errors by just
225 * unlinking the offending dblk from the dblist.
226 * However loss of all dblks equals a fatal error.
228 if (!ve_initialize()) {
230 sprintf (sprintbuf, catgets (dtsearch_catd, MS_oeinit, 266,
231 "%s Initialization failed due to errors in database,\n"
232 " language, or related files."),
234 DtSearchAddMessage (sprintbuf);
235 usrblk.retncode = OE_NOTAVAIL;
239 /* ---- DATABASES PASS #4 ------------------------------------
240 * Load each database's language and semantic files.
241 * If an error is discovered in any one dblk,
242 * it is unlinked from dblist.
243 * However loss of all dblks on dblist is fatal.
246 db = usrblk.dblist; /* could already = NULL after ve_initialize() */
247 lastlink = &usrblk.dblist;
249 if (!load_language (db, usrblk.dblist))
252 * This dblk successfully loaded its language and and semantic
253 * files. If no gui label was provided, set it to the
254 * database name. Then increment pointers and continue.
256 if (db->label == NULL)
257 db->label = strdup (db->name);
258 else if (db->label[0] == 0)
259 db->label = strdup (db->name);
262 lastlink = &db->link;
268 * One or more language or semantic files could not be loaded for
269 * this dblk. Unlink it and don't increment pointers.
271 bad_db = db; /* temp save */
272 *lastlink = db->link;
275 } /* end loop that loads all database files */
277 /* Abort if fatal dictionary load errors */
278 if (good_dblk_count <= 0) {
279 sprintf (sprintbuf, catgets (dtsearch_catd, MS_misc, 8,
280 "%s No valid databases remain."),
282 DtSearchAddMessage (sprintbuf);
286 memset (&saveusr, 0, sizeof (SAVEUSR));
288 OE_flags |= OE_INITOK;
289 if (usrblk.debug & USRDBG_RARE) {
291 _Xltimeparams localtime_buf;
293 if (*OE_expiration != 0)
295 time_ptr = _XLocaltime(OE_expiration, localtime_buf);
296 strftime (sprintbuf, 100, "%x", time_ptr);
299 strcpy (sprintbuf, "0");
300 if (OE_sitecnfg_mtime != 0)
302 time_ptr = _XLocaltime(&OE_sitecnfg_mtime, localtime_buf);
303 strftime (sprintbuf + 100, 100, "%x,%X", time_ptr);
306 strcpy (sprintbuf + 100, "0");
307 fprintf (aa_stderr, PROGNAME "666 Engine Initialization Completed.\n"
308 " usrblk.flags=%ld(x%04lx), usrblk.debug=%ld(x%04lx).\n"
309 " OE_flags=%ld(x%04lx), expiration=%s, sitecnfg=%s.\n"
310 ,usrblk.flags, usrblk.flags, usrblk.debug, usrblk.debug
311 ,OE_flags, OE_flags, sprintbuf, sprintbuf + 100
315 usrblk.retncode = OE_OK;
317 } /* oe_initialize() */
320 /************************************************/
322 /* oe_uninitialize */
324 /************************************************/
325 /* Called by Opera_Engine() whenever the site config file
326 * has been altered. Closes databases, frees all allocated storage,
327 * and resets everything so oe_initialize() can be re-called.
328 * Allows administrator to swap to newer, updated databases
329 * without forcing users to shutdown by changing PATH value
330 * in site config file.
332 void oe_uninitialize (void)
337 ve_shutdown (); /* close all databases */
338 UNMALLOC (usrblk.abstrbuf);
340 /* release shared memory, suffixes array, etc, if any */
343 /* Free allocated storage in oef table and reset the default filenames. */
344 for (oef = oef_table; oef->id != NULL; oef++) {
345 if (oef->previously_specified) {
346 oef->previously_specified = FALSE;
347 free (*(oef->OEFptr));
354 /* Save next dblk so we'll know where to go after freeing this one */
358 UNMALLOC (db->keytypes);
360 if (db->iifile != NULL) {
364 if (db->syofile != NULL) {
365 fclose (db->syofile);
368 if (db->syifile != NULL) {
369 fclose (db->syifile);
373 unload_language (db);
378 usrblk.dblist = NULL;
381 } /* oe_uninitialize() */
383 /******************************* DTOEINIT.C ********************************/