DtSearch/raima: remove register keyword
[oweals/cde.git] / cde / lib / DtSearch / raima / inittab.c
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
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)
10  * any later version.
11  *
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
16  * details.
17  *
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
22  */
23 /*
24  *   COMPONENT_NAME: austext
25  *
26  *   FUNCTIONS: alloc_dict
27  *              initcurr
28  *              inittab
29  *
30  *   ORIGINS: 27,157
31  *
32  *   This module contains IBM CONFIDENTIAL code. -- (IBM
33  *   Confidential Restricted when combined with the aggregated
34  *   modules for this product)
35  *
36  *   OBJECT CODE ONLY SOURCE MATERIALS
37  *   (C) COPYRIGHT International Business Machines Corp. 1995, 1996
38  *   All Rights Reserved
39  *   US Government Users Restricted Rights - Use, duplication or
40  *   disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
41  */
42 /*-----------------------------------------------------------------------
43  $XConsortium: inittab.c /main/5 1996/08/12 12:34:15 cde-ibm $
44    inittab.c -- db_VISTA table initialization module.
45
46    (C) Copyright 1987 by Raima Corporation.
47 -----------------------------------------------------------------------*/
48
49 /* ********************** EDIT HISTORY *******************************
50
51  SCR    DATE    INI                   DESCRIPTION
52 ----- --------- --- -----------------------------------------------------
53   101 21-Jun-88 RSC Initialized rn_type and rn_dba
54       23-Jun-88 RSC Make const_dbd, const_dbf unique to 7 chars
55   274 30-Jun-88 RSC Initialization of curr_rec was goofy (erroneous)
56   115 19-Jul-88 RSC Integrate VAX/VMS changes into code
57       04-Aug-88 RTK MULTI_TASK changes
58       18-Aug-88 RSC moved rn_type/dba to separate table.
59   417 31-Aug-88 RSC Initialized curr_rn_table.
60   420 19-Oct-88 RSC key_count was initialized wrong causing memory overwrites
61   438 06-Jan-89 RSC need to explicitly initialize size_xx
62   532 06-Jan-89 RSC Fixes to compile with ONE_DB
63  *
64  * $Log$
65  * Revision 1.3  1995/10/17  19:19:59  miker
66  * Changed .dbd file open mode from O_RDWR to O_RDONLY.
67  * When initializing tables only need to read .dbd file.
68  *
69  * Revision 1.2  1995/10/13  18:48:16  miker
70  * Change hardcoded dbfile[] size from 48 to DtSrFILENMLEN.
71  *
72  * Revision 1.1  1995/10/13  18:48:00  miker
73  * Original vista source.
74  */
75
76 #include <stdio.h>
77 #include <fcntl.h>
78 #include "vista.h"
79 #include "dbtype.h"
80 #include "inittab.h"
81 #include "dbswab.h"
82
83 #define DEBUG_INITTAB
84 int     debugging_inittab =     FALSE;
85 int     dump_init_tables =      FALSE;
86
87
88 /* Internal function prototypes */
89 static int alloc_dict(P0);
90 static int initcurr(P0);
91
92
93
94
95 /* Initialize database tables
96 */
97 int
98 inittab()
99 {
100    int dbt_lc;                  /* loop control */
101    INT i, j;
102    int key_offset = 0, key_count;
103    char dbfile[DtSrFILENMLEN], dbd_ver[DBD_COMPAT_LEN + 1];
104    char dbname[FILENMLEN];      /* Temporary working space */
105    int dbf;
106    FILE_ENTRY FAR *file_ptr;
107    FIELD_ENTRY FAR *fld_ptr;
108 #ifndef  ONE_DB
109 #define  DB_ENABLE   1
110 #else
111 #define  DB_ENABLE   0
112 #endif
113 #ifndef  NO_TIMESTAMP
114 #define  TS_ENABLE   1
115 #else
116 #define  TS_ENABLE   0
117 #endif
118 #if   DB_ENABLE | TS_ENABLE
119    RECORD_ENTRY FAR *rec_ptr;
120    SET_ENTRY FAR *set_ptr;
121 #endif
122 #ifndef  ONE_DB
123    MEMBER_ENTRY FAR *mem_ptr;
124    SORT_ENTRY FAR *srt_ptr;
125    KEY_ENTRY FAR *key_ptr;
126 #endif
127
128 #ifndef  NO_TIMESTAMP
129    db_tsrecs = db_tssets = FALSE;
130 #endif
131    size_ft = size_rt = size_st = size_mt = size_srt = size_fd = size_kt = 0;
132
133    /* compute individual dictionary sizes and offsets */
134 #ifndef  ONE_DB
135    for (dbt_lc = 0, curr_db_table = &db_table[old_no_of_dbs]; 
136         dbt_lc < no_of_dbs; ++dbt_lc, ++curr_db_table) {
137 #endif
138
139       /* form database dictionary name */
140       if ( DB_REF(db_path[0]) )
141          strcpy(dbname, DB_REF(db_path));
142       else
143          dbname[0] = '\0';
144
145 #ifdef DEBUG_INITTAB
146       if (debugging_inittab) {
147             printf (__FILE__"100 inittab: path='%s' dbname='%s'\n",
148                 dbname, DB_REF(db_name));
149             fflush (stdout);
150       }
151 #endif
152       if (strlen(dbname) + strlen(DB_REF(db_name)) >= FILENMLEN+4)
153          return( dberr(S_NAMELEN) );
154       strcat(dbname, DB_REF(db_name));
155       if (con_dbd(dbfile, dbname, get_element(dbdpath, dbt_lc)) != S_OKAY)
156          return( dberr(db_status) );
157
158       /*----------------- PASS 1 -------------------
159        * In this first pass, only opening to determine
160        * required table sizes, so opening read-only is ok.
161        */
162       if ( (dbf = open_b(dbfile, O_RDONLY)) < 0 )
163          return( dberr( S_INVDB ) );
164
165       /* Read in and verify the dictionary version */
166       DB_READ(dbf, dbd_ver, DBD_COMPAT_LEN);
167       dbd_ver[DBD_COMPAT_LEN] = '\0';
168       for ( i=0; i<size_compat; i++ ) {
169          if ( strcmp( dbd_ver, compat_dbd[i] ) == 0 ) goto goodver;
170       }
171
172       /* Incompatible dictionary file */
173       close( dbf );
174       return( dberr( S_INCOMPAT ) );
175 goodver:
176
177       /* Read in database page size */
178       DB_READ(dbf, (char FAR *)&DB_REF(Page_size), sizeof(INT));
179       NTOHS (DB_REF(Page_size));
180
181       /* Read in table sizes */
182       DB_READ(dbf, (char FAR *)&DB_REF(Size_ft), sizeof(INT));
183       NTOHS (DB_REF(Size_ft));
184       DB_READ(dbf, (char FAR *)&DB_REF(Size_rt), sizeof(INT));
185       NTOHS (DB_REF(Size_rt));
186       DB_READ(dbf, (char FAR *)&DB_REF(Size_fd), sizeof(INT));
187       NTOHS (DB_REF(Size_fd));
188       DB_READ(dbf, (char FAR *)&DB_REF(Size_st), sizeof(INT));
189       NTOHS (DB_REF(Size_st));
190       DB_READ(dbf, (char FAR *)&DB_REF(Size_mt), sizeof(INT));
191       NTOHS (DB_REF(Size_mt));
192       DB_READ(dbf, (char FAR *)&DB_REF(Size_srt), sizeof(INT));
193       NTOHS (DB_REF(Size_srt));
194       DB_READ(dbf, (char FAR *)&DB_REF(Size_kt), sizeof(INT));
195       NTOHS (DB_REF(Size_kt));
196       close(dbf);       /* end of PASS 1 */
197
198 #ifdef DEBUG_INITTAB
199       if (debugging_inittab) {
200          printf (__FILE__"152 sizes: pg=%d ft=%d rt=%d fd=%d\n"
201             "  st=%d mt=%d srt=%d kt=%d\n",
202             (int) DB_REF(Page_size),
203             (int) DB_REF(Size_ft),
204             (int) DB_REF(Size_rt),
205             (int) DB_REF(Size_fd),
206             (int) DB_REF(Size_st),
207             (int) DB_REF(Size_mt),
208             (int) DB_REF(Size_srt),
209             (int) DB_REF(Size_kt)
210             );
211           fflush (stdout);
212       }
213 #endif
214
215       DB_REF(sysdba) = NULL_DBA;
216
217 #ifndef  ONE_DB
218       /* update merged dictionary offsets and sizes */
219       if ( curr_db_table->Page_size > page_size ) {
220             page_size = curr_db_table->Page_size;
221 #ifdef DEBUG_INITTAB
222             if (debugging_inittab) {
223                 printf (__FILE__"191 db's page_size-->%d (largest = %d)\n",
224                     (int)page_size, (int)largest_page);
225                 fflush(stdout);
226             }
227 #endif
228       }
229
230       curr_db_table->ft_offset = size_ft;
231       size_ft += curr_db_table->Size_ft;
232       curr_db_table->rt_offset = size_rt;
233       size_rt += curr_db_table->Size_rt;
234       curr_db_table->fd_offset = size_fd;
235       size_fd += curr_db_table->Size_fd;
236       curr_db_table->st_offset = size_st;
237       size_st += curr_db_table->Size_st;
238       curr_db_table->mt_offset = size_mt;
239       size_mt += curr_db_table->Size_mt;
240       curr_db_table->srt_offset = size_srt;
241       size_srt += curr_db_table->Size_srt;
242       curr_db_table->kt_offset = size_kt;
243       size_kt += curr_db_table->Size_kt;
244    }
245 #endif
246    /* allocate dictionary space */
247    if ( alloc_dict() != S_OKAY ) return( db_status );
248
249    /* read in and adjust dictionary entries for each database */
250 #ifndef  ONE_DB
251    for (dbt_lc = 0, curr_db_table = &db_table[old_no_of_dbs]; 
252         dbt_lc < no_of_dbs; 
253         ++dbt_lc, ++curr_db_table) {
254 #endif
255
256       /* form database dictionary name */
257       if ( DB_REF(db_path[0]) )
258          strcpy(dbname, DB_REF(db_path));
259       else
260          dbname[0] = '\0';
261       if (strlen(dbname) + strlen(DB_REF(db_name)) >= FILENMLEN+4)
262          return( dberr(S_NAMELEN) );
263       strcat(dbname,DB_REF(db_name));
264       if (con_dbd(dbfile,dbname,get_element(dbdpath, dbt_lc)) != S_OKAY)
265          return( dberr(db_status) );
266 #ifdef DEBUG_INITTAB
267       if (dump_init_tables) {
268         printf (__FILE__"247 Tables for database '%s':\n", dbfile);
269         fflush (stdout);
270       }
271 #endif
272
273       /*----------------- PASS 2 -------------------
274        * Second pass just loads allocated tables,
275        * so opening .dbd file read-only is still ok.
276        */
277       dbf = open_b (dbfile, O_RDONLY);
278       DB_LSEEK(dbf, (off_t)(DBD_COMPAT_LEN + 8L*sizeof(INT)), 0);
279
280       /*----------------- FILE TABLE -------------------*/
281       DB_READ(dbf, (char FAR *)&file_table[ORIGIN(ft_offset)],
282             (DB_REF(Size_ft)*sizeof(FILE_ENTRY)));
283       /* Invalid if sizeof(xxxx_ENTRY) diff on each machine */
284       for (     i = 0, file_ptr = &file_table[ORIGIN(ft_offset)];
285                 i < DB_REF(Size_ft);
286                 i++, file_ptr++) {
287             /* Byte swap each INT on LITTLE_ENDIAN machines */
288             NTOHS (file_ptr->ft_slots);
289             NTOHS (file_ptr->ft_slsize);
290             NTOHS (file_ptr->ft_pgsize);
291             NTOHS (file_ptr->ft_flags);
292 #ifdef DEBUG_INITTAB
293             if (dump_init_tables) {
294                 printf (" FILE#%d: ty=%c slts=%2d slsz=%3d pgsz=%d '%s'\n",
295                     (int)i,
296                     file_ptr->ft_type,
297                     (int)file_ptr->ft_slots,
298                     (int)file_ptr->ft_slsize,
299                     (int)file_ptr->ft_pgsize,
300                     file_ptr->ft_name);
301                 fflush (stdout);
302             }
303 #endif
304       }
305
306       /*----------------- RECORD TABLE -------------------*/
307       DB_READ(dbf, (char FAR *)&record_table[ORIGIN(rt_offset)],
308            (DB_REF(Size_rt)*sizeof(RECORD_ENTRY)));
309       for (     i = 0, rec_ptr = &record_table[ORIGIN(rt_offset)];
310                 i < DB_REF(Size_rt);
311                 i++, rec_ptr++) {
312             /* Byte swap each INT on LITTLE_ENDIAN machines */
313             NTOHS (rec_ptr->rt_file);
314             NTOHS (rec_ptr->rt_len);
315             NTOHS (rec_ptr->rt_data);
316             NTOHS (rec_ptr->rt_fields);
317             NTOHS (rec_ptr->rt_fdtot);
318             NTOHS (rec_ptr->rt_flags);
319 #ifdef DEBUG_INITTAB
320             if (dump_init_tables) {
321                 printf (
322                     " REC #%d: fil=%d len=%3d data=%2d fld1=%2d flds=%2d\n",
323                     (int)i,
324                     (int)rec_ptr->rt_file,
325                     (int)rec_ptr->rt_len,
326                     (int)rec_ptr->rt_data,
327                     (int)rec_ptr->rt_fields,
328                     (int)rec_ptr->rt_fdtot);
329                 fflush (stdout);
330             }
331 #endif
332       }
333
334       /*----------------- FIELD TABLE -------------------*/
335       DB_READ(dbf, (char FAR *)&field_table[ORIGIN(fd_offset)],
336            (DB_REF(Size_fd)*sizeof(FIELD_ENTRY)));
337       for (     i = 0, fld_ptr = &field_table[ORIGIN(fd_offset)];
338                 i < DB_REF(Size_fd);
339                 i++, fld_ptr++) {
340             /* Byte swap each INT on LITTLE_ENDIAN machines */
341             NTOHS (fld_ptr->fd_len);
342             NTOHS (fld_ptr->fd_keyfile);
343             NTOHS (fld_ptr->fd_keyno);
344             NTOHS (fld_ptr->fd_ptr);
345             NTOHS (fld_ptr->fd_rec);
346             NTOHS (fld_ptr->fd_flags);
347             for (j=0;  j<MAXDIMS;  j++)
348                 NTOHS (fld_ptr->fd_dim[j]);
349 #ifdef DEBUG_INITTAB
350             if (dump_init_tables) {
351                 if (i == 0)
352                     puts ("         key typ len kfil key# ofs rec# flg dims");
353                 printf (
354                     " FLD#%2d  %c   %c  %3d  %d    %d   %3d  %d    %x",
355                     (int)i,
356                     fld_ptr->fd_key,
357                     fld_ptr->fd_type,
358                     (int)fld_ptr->fd_len,
359                     (int)fld_ptr->fd_keyfile,
360                     (int)fld_ptr->fd_keyno,
361                     (int)fld_ptr->fd_ptr,
362                     (int)fld_ptr->fd_rec,
363                     (int)fld_ptr->fd_flags);
364                 for (j=0; j<MAXDIMS; j++)
365                     if (fld_ptr->fd_dim[j])
366                         printf (" %d:%d", j, (int)fld_ptr->fd_dim[j]);
367                 putchar ('\n');
368                 fflush (stdout);
369             }
370 #endif
371       }
372
373       /*----------------- SET TABLE -------------------*/
374       DB_READ(dbf, (char FAR *)&set_table[ORIGIN(st_offset)],
375            (DB_REF(Size_st)*sizeof(SET_ENTRY)));
376       for (     i = 0, set_ptr = &set_table[ORIGIN(st_offset)];
377                 i < DB_REF(Size_st);
378                 i++, set_ptr++) {
379             /* Byte swap each INT on LITTLE_ENDIAN machines */
380             NTOHS (set_ptr->st_order);
381             NTOHS (set_ptr->st_own_rt);
382             NTOHS (set_ptr->st_own_ptr);
383             NTOHS (set_ptr->st_members);
384             NTOHS (set_ptr->st_memtot);
385             NTOHS (set_ptr->st_flags);
386 #ifdef DEBUG_INITTAB
387             if (dump_init_tables) {
388                 printf (
389                     " SET #%d: ord=%c owner=%d ownofs=%2d mem1=%d mems=%d\n",
390                     (int)i,
391                     (char)set_ptr->st_order,
392                     (int)set_ptr->st_own_rt,
393                     (int)set_ptr->st_own_ptr,
394                     (int)set_ptr->st_members,
395                     (int)set_ptr->st_memtot);
396                 fflush (stdout);
397             }
398 #endif
399       }
400
401       /*----------------- MEMBER TABLE -------------------*/
402       DB_READ(dbf, (char FAR *)&member_table[ORIGIN(mt_offset)],
403            (DB_REF(Size_mt)*sizeof(MEMBER_ENTRY)));
404       for (     i = 0, mem_ptr = &member_table[ORIGIN(mt_offset)];
405                 i < DB_REF(Size_mt);
406                 i++, mem_ptr++) {
407             /* Byte swap each INT on LITTLE_ENDIAN machines */
408             NTOHS (mem_ptr->mt_record);
409             NTOHS (mem_ptr->mt_mem_ptr);
410             NTOHS (mem_ptr->mt_sort_fld);
411             NTOHS (mem_ptr->mt_totsf);
412 #ifdef DEBUG_INITTAB
413             if (dump_init_tables) {
414                 printf (
415                     " MEM #%d: rec=%d ofs=%d sort1=%d sorts=%d\n",
416                     (int)i,
417                     (int)mem_ptr->mt_record,
418                     (int)mem_ptr->mt_mem_ptr,
419                     (int)mem_ptr->mt_sort_fld,
420                     (int)mem_ptr->mt_totsf);
421                 fflush (stdout);
422             }
423 #endif
424       }
425
426
427       DB_READ(dbf, (char FAR *)&sort_table[ORIGIN(srt_offset)],
428            (DB_REF(Size_srt)*sizeof(SORT_ENTRY)));
429       /* Member sort tables not used by DtSearch @@@ */
430       if (DB_REF(Size_srt)) {
431             /* Byte swap each INT on LITTLE_ENDIAN machines */
432             srt_ptr = &sort_table[ORIGIN(srt_offset)];
433             NTOHS (srt_ptr->se_fld);
434             NTOHS (srt_ptr->se_set);
435       }
436
437       DB_READ(dbf, (char FAR *)&key_table[ORIGIN(kt_offset)],
438            (DB_REF(Size_kt)*sizeof(KEY_ENTRY)));
439       /* Compound key tables not used by DtSearch @@@ */
440       if (DB_REF(Size_kt)) {
441             /* Byte swap each INT on LITTLE_ENDIAN machines */
442             key_ptr = &key_table[ORIGIN(kt_offset)];
443             NTOHS (key_ptr->kt_key);
444             NTOHS (key_ptr->kt_field);
445             NTOHS (key_ptr->kt_ptr);
446             NTOHS (key_ptr->kt_sort);
447       }
448
449       close(dbf);       /* end of PASS 2 */
450 #ifdef DEBUG_INITTAB
451       dump_init_tables = FALSE;
452 #endif
453 #ifndef  ONE_DB
454       curr_db_table->key_offset = key_offset;
455 #endif
456
457       /* update file table path entries */
458       if ( DB_REF(db_path[0]) || dbfpath[0] ) {
459          for (i = 0, file_ptr = &file_table[ORIGIN(ft_offset)];
460               i < DB_REF(Size_ft);
461               ++i, ++file_ptr) {
462
463             /* Construct the data/key file name */
464             if ( DB_REF(db_path[0]) )
465                strcpy(dbname, DB_REF(db_path));
466             else
467                dbname[0] = '\0';
468             if (strlen(dbname) + strlen(DB_REF(db_name)) >= FILENMLEN+4)
469                return( dberr(S_NAMELEN) );
470             strcat(dbname, DB_REF(db_name));
471             if (con_dbf(dbfile, file_ptr->ft_name, dbname,
472                get_element(dbfpath, dbt_lc)) != S_OKAY)
473                return( dberr(db_status) );
474
475             /* Save new name in dictionary */
476             strcpy(file_ptr->ft_name, dbfile);
477          } 
478       }
479 #if   DB_ENABLE | TS_ENABLE
480       /* adjust record table entries */
481       for (i = ORIGIN(rt_offset), rec_ptr = &record_table[ORIGIN(rt_offset)];
482            i < ORIGIN(rt_offset) + DB_REF(Size_rt);
483            ++i, ++rec_ptr) {
484 #ifndef  ONE_DB
485          rec_ptr->rt_file += curr_db_table->ft_offset;
486          rec_ptr->rt_fields += curr_db_table->fd_offset;
487 #endif
488 #ifndef  NO_TIMESTAMP
489          if ( rec_ptr->rt_flags & TIMESTAMPED ) {
490             db_tsrecs = TRUE;
491 #ifdef ONE_DB
492             break;
493 #endif
494          }
495 #endif
496       }
497 #endif
498       /* adjust field table entries */
499       for (key_count = 0, i = ORIGIN(fd_offset), 
500               fld_ptr = &field_table[ORIGIN(fd_offset)];
501            i < ORIGIN(fd_offset) + DB_REF(Size_fd);
502            ++i, ++fld_ptr) {
503 #ifndef  ONE_DB
504          fld_ptr->fd_rec += curr_db_table->rt_offset;
505 #endif
506          if ( fld_ptr->fd_key != NOKEY ) {
507             fld_ptr->fd_keyno += key_offset;
508             ++key_count;
509 #ifndef  ONE_DB
510             fld_ptr->fd_keyfile += curr_db_table->ft_offset;
511             if ( fld_ptr->fd_type == 'k' )
512                fld_ptr->fd_ptr += curr_db_table->kt_offset;
513 #endif
514          }
515       }
516       key_offset += key_count;
517
518 #if   DB_ENABLE | TS_ENABLE
519       /* adjust set table entries */
520       for (i = ORIGIN(st_offset), set_ptr = &set_table[ORIGIN(st_offset)];
521            i < ORIGIN(st_offset) + DB_REF(Size_st);
522            ++i, ++set_ptr) {
523 #ifndef  ONE_DB
524          set_ptr->st_own_rt += curr_db_table->rt_offset;
525          set_ptr->st_members += curr_db_table->mt_offset;
526 #endif
527 #ifndef  NO_TIMESTAMP
528          if ( set_ptr->st_flags & TIMESTAMPED ) {
529             db_tssets = TRUE;
530 #ifdef ONE_DB
531             break;
532 #endif
533          }
534 #endif
535       }
536 #endif
537
538 #ifndef  ONE_DB
539       /* adjust member table entries */
540       for (i = curr_db_table->mt_offset, 
541               mem_ptr = &member_table[curr_db_table->mt_offset];
542            i < curr_db_table->mt_offset + curr_db_table->Size_mt;
543            ++i, ++mem_ptr) {
544          mem_ptr->mt_record += curr_db_table->rt_offset;
545          mem_ptr->mt_sort_fld += curr_db_table->srt_offset;
546       }
547
548       /* adjust sort table entries */
549       for (i = curr_db_table->srt_offset, 
550               srt_ptr = &sort_table[curr_db_table->srt_offset];
551            i < curr_db_table->srt_offset + curr_db_table->Size_srt;
552            ++i, ++srt_ptr) {
553          srt_ptr->se_fld += curr_db_table->fd_offset;
554          srt_ptr->se_set += curr_db_table->st_offset;
555       }
556
557       /* adjust key table entries */
558       for (i = curr_db_table->kt_offset, 
559               key_ptr = &key_table[curr_db_table->kt_offset];
560            i < curr_db_table->kt_offset + curr_db_table->Size_kt;
561            ++i, ++key_ptr) {
562          key_ptr->kt_key += curr_db_table->fd_offset;
563          key_ptr->kt_field += curr_db_table->fd_offset;
564       }
565    }  /* end loop for each database */
566 #endif
567    initcurr();
568    return( db_status );
569 }
570
571
572
573 /* Allocate space for dictionary
574 */
575 static int alloc_dict()
576 {
577    int old_size;
578    int new_size;
579    int extra_file = 0;
580 #ifndef ONE_DB
581    DB_ENTRY FAR *db_ptr;
582 #endif
583
584    /* allocate and initialize file_table */
585 #ifndef NO_TRANS
586    if ( use_ovfl ) {
587       extra_file = 1;
588    }
589 #endif
590
591 #ifndef ONE_DB
592    if ( old_no_of_dbs == 0 ) {
593       old_size_ft = 0;
594       old_size_fd = 0;
595       old_size_st = 0;
596       old_size_mt = 0;
597       old_size_srt = 0;
598       old_size_kt = 0;
599       old_size_rt = 0;
600    }
601    else {
602       db_ptr = &db_table[old_no_of_dbs];
603       old_size_ft = db_ptr->Size_ft + db_ptr->ft_offset + extra_file;
604       old_size_fd = db_ptr->Size_fd + db_ptr->fd_offset;
605       old_size_st = db_ptr->Size_st + db_ptr->st_offset;
606       old_size_mt = db_ptr->Size_mt + db_ptr->mt_offset;
607       old_size_srt = db_ptr->Size_srt + db_ptr->srt_offset;
608       old_size_kt = db_ptr->Size_kt + db_ptr->kt_offset;
609       old_size_rt = db_ptr->Size_rt + db_ptr->rt_offset;
610    }
611 #endif
612
613    new_size = (size_ft + extra_file) * sizeof(FILE_ENTRY);
614    old_size = old_size_ft * sizeof(FILE_ENTRY);
615    if ( ALLOC_TABLE(&db_global.File_table, new_size, old_size, "file_table")
616                                                                 != S_OKAY ) {
617       return( db_status );
618    }
619
620    /* allocate record_table */
621    new_size = size_rt * sizeof(RECORD_ENTRY);
622    old_size = old_size_rt * sizeof(RECORD_ENTRY);
623    if ( ALLOC_TABLE(&db_global.Record_table, new_size, old_size, "record_table")
624                                                                 != S_OKAY ) {
625       return( db_status );
626    }
627
628    /* allocate field_table */
629    new_size = size_fd * sizeof(FIELD_ENTRY);
630    old_size = old_size_fd * sizeof(FIELD_ENTRY);
631    if ( ALLOC_TABLE(&db_global.Field_table, new_size, old_size, "field_table")
632                                                                 != S_OKAY ) {
633       return( db_status );
634    }
635
636    /* allocate set table */
637    if ( size_st ) {
638       new_size = size_st * sizeof(SET_ENTRY);
639       old_size = old_size_st * sizeof(SET_ENTRY);
640       if ( ALLOC_TABLE(&db_global.Set_table, new_size, old_size, "set_table")
641                                                                 != S_OKAY ) {
642          return( db_status );
643       }
644    } else set_table = NULL;
645
646    /* allocate member_table */
647    if ( size_mt ) {
648       new_size = size_mt * sizeof(MEMBER_ENTRY);
649       old_size = old_size_mt * sizeof(MEMBER_ENTRY);
650       if ( ALLOC_TABLE(&db_global.Member_table, new_size, old_size, "member_table")
651                                                                 != S_OKAY ) {
652          return( db_status );
653       }
654    } else member_table = NULL;
655
656    /* allocate sort_table */
657    if ( size_srt ) {
658       new_size = size_srt * sizeof(SORT_ENTRY);
659       old_size = old_size_srt * sizeof(SORT_ENTRY);
660       if ( ALLOC_TABLE(&db_global.Sort_table, new_size, old_size, "sort_table")
661                                                                 != S_OKAY ) {
662          return( db_status );
663       }
664    } else sort_table = NULL;
665
666    /* allocate key_table */
667    if ( size_kt ) {
668       new_size = size_kt * sizeof(KEY_ENTRY);
669       old_size = old_size_kt * sizeof(KEY_ENTRY);
670       if ( ALLOC_TABLE(&db_global.Key_table, new_size, old_size, "key_table")
671                                                                 != S_OKAY ) {
672          return( db_status );
673       }
674    } else key_table = NULL;
675
676    return( db_status = S_OKAY );
677 }
678
679 /* Initialize currency tables 
680 */
681 static int initcurr()
682 {
683    int dbt_lc;                  /* loop control */
684    int rec, i;
685    RECORD_ENTRY FAR *rec_ptr;
686    SET_ENTRY FAR *set_ptr;
687    DB_ADDR FAR *co_ptr;
688    int old_size;
689    int new_size;
690
691    /* Initialize current record and type */
692 #ifndef  ONE_DB
693    for (dbt_lc = no_of_dbs, curr_db_table = &db_table[old_no_of_dbs],
694                                 curr_rn_table = &rn_table[old_no_of_dbs];
695         --dbt_lc >= 0; ++curr_db_table, ++curr_rn_table) {
696       DB_REF(curr_dbt_rec) = NULL_DBA;
697 #endif
698       RN_REF(rn_dba)   = NULL_DBA;
699       RN_REF(rn_type)  = -1;
700 #ifndef ONE_DB
701    }
702 #endif
703
704    if ( size_st ) {
705       new_size = size_st * sizeof(DB_ADDR);
706       old_size = old_size_st * sizeof(DB_ADDR);
707       if ( ALLOC_TABLE(&db_global.Curr_own, new_size, old_size, "curr_own")
708                                                                 != S_OKAY ) {
709          return( db_status );
710       }
711       if ( ALLOC_TABLE(&db_global.Curr_mem, new_size, old_size, "curr_mem")
712                                                                 != S_OKAY ) {
713          return( db_status );
714       }
715 #ifndef  NO_TIMESTAMP
716       new_size = size_st * sizeof(ULONG);
717       old_size = old_size_st * sizeof(ULONG);
718       if ( db_tsrecs ) {
719          if ( ALLOC_TABLE(&db_global.Co_time, new_size, old_size, "co_time")
720                                                                 != S_OKAY ) {
721             return( db_status );
722          }
723          if ( ALLOC_TABLE(&db_global.Cm_time, new_size, old_size, "cm_time")
724                                                                 != S_OKAY ) {
725             return( db_status );
726          }
727       }
728       if ( db_tssets ) {
729          if ( ALLOC_TABLE(&db_global.Cs_time, new_size, old_size, "cs_time")
730                                                                 != S_OKAY ) {
731             return( db_status );
732          }
733       }
734 #endif
735       /* for each db make system record as curr_own of its sets */
736 #ifndef  ONE_DB
737       for (dbt_lc = no_of_dbs, curr_db_table = &db_table[old_no_of_dbs]; 
738            --dbt_lc >= 0; ++curr_db_table) {
739 #endif
740          for (rec = ORIGIN(rt_offset), 
741                  rec_ptr = &record_table[ORIGIN(rt_offset)];
742               rec < ORIGIN(rt_offset) + DB_REF(Size_rt);
743               ++rec, ++rec_ptr) {
744             if (rec_ptr->rt_fdtot == -1) { 
745                /* found system record */
746                curr_rec = ((FILEMASK & NUM2EXT(rec_ptr->rt_file, ft_offset))
747                                                             << FILESHIFT) | 1L;
748                /* make system record current of sets it owns */
749                for (i = ORIGIN(st_offset), 
750                        set_ptr = &set_table[ORIGIN(st_offset)],
751                        co_ptr = &curr_own[ORIGIN(st_offset)];
752                     i < ORIGIN(st_offset) + DB_REF(Size_st);
753                     ++i, ++set_ptr, ++co_ptr) {
754                   if (set_ptr->st_own_rt == rec) {
755                      *co_ptr = curr_rec;
756                   }
757                }
758                DB_REF(sysdba) = curr_rec;
759 #ifndef ONE_DB
760                DB_REF(curr_dbt_rec) = curr_rec;
761 #endif
762                break;
763             }
764          }
765 #ifndef  ONE_DB
766       }
767 #endif
768    }
769    else {
770       curr_own = NULL;
771       curr_mem = NULL;
772    }
773 #ifndef  ONE_DB
774    curr_db = 0;
775    MEM_LOCK(&db_global.Db_table);
776    curr_db_table = db_table;
777    MEM_LOCK(&db_global.Rn_table);
778    curr_rn_table = rn_table;
779    setdb_on = FALSE;
780    curr_rec = DB_REF(curr_dbt_rec);
781 #endif
782    return( db_status = S_OKAY );
783 }
784 /* vpp -nOS2 -dUNIX -nBSD -nVANILLA_BSD -nVMS -nMEMLOCK -nWINDOWS -nFAR_ALLOC -f/usr/users/master/config/nonwin inittab.c */