4059cd4594f2b665bccc7de9f47f571d7619cac2
[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 *file_ptr;
107    FIELD_ENTRY *fld_ptr;
108 #define  DB_ENABLE   1
109 #define  TS_ENABLE   0
110 #if   DB_ENABLE | TS_ENABLE
111    RECORD_ENTRY *rec_ptr;
112    SET_ENTRY *set_ptr;
113 #endif
114    MEMBER_ENTRY *mem_ptr;
115    SORT_ENTRY *srt_ptr;
116    KEY_ENTRY *key_ptr;
117
118    size_ft = size_rt = size_st = size_mt = size_srt = size_fd = size_kt = 0;
119
120    /* compute individual dictionary sizes and offsets */
121    for (dbt_lc = 0, curr_db_table = &db_table[old_no_of_dbs]; 
122         dbt_lc < no_of_dbs; ++dbt_lc, ++curr_db_table) {
123
124       /* form database dictionary name */
125       if ( DB_REF(db_path[0]) )
126          strcpy(dbname, DB_REF(db_path));
127       else
128          dbname[0] = '\0';
129
130 #ifdef DEBUG_INITTAB
131       if (debugging_inittab) {
132             printf (__FILE__"100 inittab: path='%s' dbname='%s'\n",
133                 dbname, DB_REF(db_name));
134             fflush (stdout);
135       }
136 #endif
137       if (strlen(dbname) + strlen(DB_REF(db_name)) >= FILENMLEN+4)
138          return( dberr(S_NAMELEN) );
139       strcat(dbname, DB_REF(db_name));
140       if (con_dbd(dbfile, dbname, get_element(dbdpath, dbt_lc)) != S_OKAY)
141          return( dberr(db_status) );
142
143       /*----------------- PASS 1 -------------------
144        * In this first pass, only opening to determine
145        * required table sizes, so opening read-only is ok.
146        */
147       if ( (dbf = open_b(dbfile, O_RDONLY)) < 0 )
148          return( dberr( S_INVDB ) );
149
150       /* Read in and verify the dictionary version */
151       DB_READ(dbf, dbd_ver, DBD_COMPAT_LEN);
152       dbd_ver[DBD_COMPAT_LEN] = '\0';
153       for ( i=0; i<size_compat; i++ ) {
154          if ( strcmp( dbd_ver, compat_dbd[i] ) == 0 ) goto goodver;
155       }
156
157       /* Incompatible dictionary file */
158       close( dbf );
159       return( dberr( S_INCOMPAT ) );
160 goodver:
161
162       /* Read in database page size */
163       DB_READ(dbf, (char *)&DB_REF(Page_size), sizeof(INT));
164       NTOHS (DB_REF(Page_size));
165
166       /* Read in table sizes */
167       DB_READ(dbf, (char *)&DB_REF(Size_ft), sizeof(INT));
168       NTOHS (DB_REF(Size_ft));
169       DB_READ(dbf, (char *)&DB_REF(Size_rt), sizeof(INT));
170       NTOHS (DB_REF(Size_rt));
171       DB_READ(dbf, (char *)&DB_REF(Size_fd), sizeof(INT));
172       NTOHS (DB_REF(Size_fd));
173       DB_READ(dbf, (char *)&DB_REF(Size_st), sizeof(INT));
174       NTOHS (DB_REF(Size_st));
175       DB_READ(dbf, (char *)&DB_REF(Size_mt), sizeof(INT));
176       NTOHS (DB_REF(Size_mt));
177       DB_READ(dbf, (char *)&DB_REF(Size_srt), sizeof(INT));
178       NTOHS (DB_REF(Size_srt));
179       DB_READ(dbf, (char *)&DB_REF(Size_kt), sizeof(INT));
180       NTOHS (DB_REF(Size_kt));
181       close(dbf);       /* end of PASS 1 */
182
183 #ifdef DEBUG_INITTAB
184       if (debugging_inittab) {
185          printf (__FILE__"152 sizes: pg=%d ft=%d rt=%d fd=%d\n"
186             "  st=%d mt=%d srt=%d kt=%d\n",
187             (int) DB_REF(Page_size),
188             (int) DB_REF(Size_ft),
189             (int) DB_REF(Size_rt),
190             (int) DB_REF(Size_fd),
191             (int) DB_REF(Size_st),
192             (int) DB_REF(Size_mt),
193             (int) DB_REF(Size_srt),
194             (int) DB_REF(Size_kt)
195             );
196           fflush (stdout);
197       }
198 #endif
199
200       DB_REF(sysdba) = NULL_DBA;
201
202       /* update merged dictionary offsets and sizes */
203       if ( curr_db_table->Page_size > page_size ) {
204             page_size = curr_db_table->Page_size;
205 #ifdef DEBUG_INITTAB
206             if (debugging_inittab) {
207                 printf (__FILE__"191 db's page_size-->%d (largest = %d)\n",
208                     (int)page_size, (int)largest_page);
209                 fflush(stdout);
210             }
211 #endif
212       }
213
214       curr_db_table->ft_offset = size_ft;
215       size_ft += curr_db_table->Size_ft;
216       curr_db_table->rt_offset = size_rt;
217       size_rt += curr_db_table->Size_rt;
218       curr_db_table->fd_offset = size_fd;
219       size_fd += curr_db_table->Size_fd;
220       curr_db_table->st_offset = size_st;
221       size_st += curr_db_table->Size_st;
222       curr_db_table->mt_offset = size_mt;
223       size_mt += curr_db_table->Size_mt;
224       curr_db_table->srt_offset = size_srt;
225       size_srt += curr_db_table->Size_srt;
226       curr_db_table->kt_offset = size_kt;
227       size_kt += curr_db_table->Size_kt;
228    }
229    /* allocate dictionary space */
230    if ( alloc_dict() != S_OKAY ) return( db_status );
231
232    /* read in and adjust dictionary entries for each database */
233    for (dbt_lc = 0, curr_db_table = &db_table[old_no_of_dbs]; 
234         dbt_lc < no_of_dbs; 
235         ++dbt_lc, ++curr_db_table) {
236
237       /* form database dictionary name */
238       if ( DB_REF(db_path[0]) )
239          strcpy(dbname, DB_REF(db_path));
240       else
241          dbname[0] = '\0';
242       if (strlen(dbname) + strlen(DB_REF(db_name)) >= FILENMLEN+4)
243          return( dberr(S_NAMELEN) );
244       strcat(dbname,DB_REF(db_name));
245       if (con_dbd(dbfile,dbname,get_element(dbdpath, dbt_lc)) != S_OKAY)
246          return( dberr(db_status) );
247 #ifdef DEBUG_INITTAB
248       if (dump_init_tables) {
249         printf (__FILE__"247 Tables for database '%s':\n", dbfile);
250         fflush (stdout);
251       }
252 #endif
253
254       /*----------------- PASS 2 -------------------
255        * Second pass just loads allocated tables,
256        * so opening .dbd file read-only is still ok.
257        */
258       dbf = open_b (dbfile, O_RDONLY);
259       DB_LSEEK(dbf, (off_t)(DBD_COMPAT_LEN + 8L*sizeof(INT)), 0);
260
261       /*----------------- FILE TABLE -------------------*/
262       DB_READ(dbf, (char *)&file_table[ORIGIN(ft_offset)],
263             (DB_REF(Size_ft)*sizeof(FILE_ENTRY)));
264       /* Invalid if sizeof(xxxx_ENTRY) diff on each machine */
265       for (     i = 0, file_ptr = &file_table[ORIGIN(ft_offset)];
266                 i < DB_REF(Size_ft);
267                 i++, file_ptr++) {
268             /* Byte swap each INT on LITTLE_ENDIAN machines */
269             NTOHS (file_ptr->ft_slots);
270             NTOHS (file_ptr->ft_slsize);
271             NTOHS (file_ptr->ft_pgsize);
272             NTOHS (file_ptr->ft_flags);
273 #ifdef DEBUG_INITTAB
274             if (dump_init_tables) {
275                 printf (" FILE#%d: ty=%c slts=%2d slsz=%3d pgsz=%d '%s'\n",
276                     (int)i,
277                     file_ptr->ft_type,
278                     (int)file_ptr->ft_slots,
279                     (int)file_ptr->ft_slsize,
280                     (int)file_ptr->ft_pgsize,
281                     file_ptr->ft_name);
282                 fflush (stdout);
283             }
284 #endif
285       }
286
287       /*----------------- RECORD TABLE -------------------*/
288       DB_READ(dbf, (char *)&record_table[ORIGIN(rt_offset)],
289            (DB_REF(Size_rt)*sizeof(RECORD_ENTRY)));
290       for (     i = 0, rec_ptr = &record_table[ORIGIN(rt_offset)];
291                 i < DB_REF(Size_rt);
292                 i++, rec_ptr++) {
293             /* Byte swap each INT on LITTLE_ENDIAN machines */
294             NTOHS (rec_ptr->rt_file);
295             NTOHS (rec_ptr->rt_len);
296             NTOHS (rec_ptr->rt_data);
297             NTOHS (rec_ptr->rt_fields);
298             NTOHS (rec_ptr->rt_fdtot);
299             NTOHS (rec_ptr->rt_flags);
300 #ifdef DEBUG_INITTAB
301             if (dump_init_tables) {
302                 printf (
303                     " REC #%d: fil=%d len=%3d data=%2d fld1=%2d flds=%2d\n",
304                     (int)i,
305                     (int)rec_ptr->rt_file,
306                     (int)rec_ptr->rt_len,
307                     (int)rec_ptr->rt_data,
308                     (int)rec_ptr->rt_fields,
309                     (int)rec_ptr->rt_fdtot);
310                 fflush (stdout);
311             }
312 #endif
313       }
314
315       /*----------------- FIELD TABLE -------------------*/
316       DB_READ(dbf, (char *)&field_table[ORIGIN(fd_offset)],
317            (DB_REF(Size_fd)*sizeof(FIELD_ENTRY)));
318       for (     i = 0, fld_ptr = &field_table[ORIGIN(fd_offset)];
319                 i < DB_REF(Size_fd);
320                 i++, fld_ptr++) {
321             /* Byte swap each INT on LITTLE_ENDIAN machines */
322             NTOHS (fld_ptr->fd_len);
323             NTOHS (fld_ptr->fd_keyfile);
324             NTOHS (fld_ptr->fd_keyno);
325             NTOHS (fld_ptr->fd_ptr);
326             NTOHS (fld_ptr->fd_rec);
327             NTOHS (fld_ptr->fd_flags);
328             for (j=0;  j<MAXDIMS;  j++)
329                 NTOHS (fld_ptr->fd_dim[j]);
330 #ifdef DEBUG_INITTAB
331             if (dump_init_tables) {
332                 if (i == 0)
333                     puts ("         key typ len kfil key# ofs rec# flg dims");
334                 printf (
335                     " FLD#%2d  %c   %c  %3d  %d    %d   %3d  %d    %x",
336                     (int)i,
337                     fld_ptr->fd_key,
338                     fld_ptr->fd_type,
339                     (int)fld_ptr->fd_len,
340                     (int)fld_ptr->fd_keyfile,
341                     (int)fld_ptr->fd_keyno,
342                     (int)fld_ptr->fd_ptr,
343                     (int)fld_ptr->fd_rec,
344                     (int)fld_ptr->fd_flags);
345                 for (j=0; j<MAXDIMS; j++)
346                     if (fld_ptr->fd_dim[j])
347                         printf (" %d:%d", j, (int)fld_ptr->fd_dim[j]);
348                 putchar ('\n');
349                 fflush (stdout);
350             }
351 #endif
352       }
353
354       /*----------------- SET TABLE -------------------*/
355       DB_READ(dbf, (char *)&set_table[ORIGIN(st_offset)],
356            (DB_REF(Size_st)*sizeof(SET_ENTRY)));
357       for (     i = 0, set_ptr = &set_table[ORIGIN(st_offset)];
358                 i < DB_REF(Size_st);
359                 i++, set_ptr++) {
360             /* Byte swap each INT on LITTLE_ENDIAN machines */
361             NTOHS (set_ptr->st_order);
362             NTOHS (set_ptr->st_own_rt);
363             NTOHS (set_ptr->st_own_ptr);
364             NTOHS (set_ptr->st_members);
365             NTOHS (set_ptr->st_memtot);
366             NTOHS (set_ptr->st_flags);
367 #ifdef DEBUG_INITTAB
368             if (dump_init_tables) {
369                 printf (
370                     " SET #%d: ord=%c owner=%d ownofs=%2d mem1=%d mems=%d\n",
371                     (int)i,
372                     (char)set_ptr->st_order,
373                     (int)set_ptr->st_own_rt,
374                     (int)set_ptr->st_own_ptr,
375                     (int)set_ptr->st_members,
376                     (int)set_ptr->st_memtot);
377                 fflush (stdout);
378             }
379 #endif
380       }
381
382       /*----------------- MEMBER TABLE -------------------*/
383       DB_READ(dbf, (char *)&member_table[ORIGIN(mt_offset)],
384            (DB_REF(Size_mt)*sizeof(MEMBER_ENTRY)));
385       for (     i = 0, mem_ptr = &member_table[ORIGIN(mt_offset)];
386                 i < DB_REF(Size_mt);
387                 i++, mem_ptr++) {
388             /* Byte swap each INT on LITTLE_ENDIAN machines */
389             NTOHS (mem_ptr->mt_record);
390             NTOHS (mem_ptr->mt_mem_ptr);
391             NTOHS (mem_ptr->mt_sort_fld);
392             NTOHS (mem_ptr->mt_totsf);
393 #ifdef DEBUG_INITTAB
394             if (dump_init_tables) {
395                 printf (
396                     " MEM #%d: rec=%d ofs=%d sort1=%d sorts=%d\n",
397                     (int)i,
398                     (int)mem_ptr->mt_record,
399                     (int)mem_ptr->mt_mem_ptr,
400                     (int)mem_ptr->mt_sort_fld,
401                     (int)mem_ptr->mt_totsf);
402                 fflush (stdout);
403             }
404 #endif
405       }
406
407
408       DB_READ(dbf, (char *)&sort_table[ORIGIN(srt_offset)],
409            (DB_REF(Size_srt)*sizeof(SORT_ENTRY)));
410       /* Member sort tables not used by DtSearch @@@ */
411       if (DB_REF(Size_srt)) {
412             /* Byte swap each INT on LITTLE_ENDIAN machines */
413             srt_ptr = &sort_table[ORIGIN(srt_offset)];
414             NTOHS (srt_ptr->se_fld);
415             NTOHS (srt_ptr->se_set);
416       }
417
418       DB_READ(dbf, (char *)&key_table[ORIGIN(kt_offset)],
419            (DB_REF(Size_kt)*sizeof(KEY_ENTRY)));
420       /* Compound key tables not used by DtSearch @@@ */
421       if (DB_REF(Size_kt)) {
422             /* Byte swap each INT on LITTLE_ENDIAN machines */
423             key_ptr = &key_table[ORIGIN(kt_offset)];
424             NTOHS (key_ptr->kt_key);
425             NTOHS (key_ptr->kt_field);
426             NTOHS (key_ptr->kt_ptr);
427             NTOHS (key_ptr->kt_sort);
428       }
429
430       close(dbf);       /* end of PASS 2 */
431 #ifdef DEBUG_INITTAB
432       dump_init_tables = FALSE;
433 #endif
434       curr_db_table->key_offset = key_offset;
435
436       /* update file table path entries */
437       if ( DB_REF(db_path[0]) || dbfpath[0] ) {
438          for (i = 0, file_ptr = &file_table[ORIGIN(ft_offset)];
439               i < DB_REF(Size_ft);
440               ++i, ++file_ptr) {
441
442             /* Construct the data/key file name */
443             if ( DB_REF(db_path[0]) )
444                strcpy(dbname, DB_REF(db_path));
445             else
446                dbname[0] = '\0';
447             if (strlen(dbname) + strlen(DB_REF(db_name)) >= FILENMLEN+4)
448                return( dberr(S_NAMELEN) );
449             strcat(dbname, DB_REF(db_name));
450             if (con_dbf(dbfile, file_ptr->ft_name, dbname,
451                get_element(dbfpath, dbt_lc)) != S_OKAY)
452                return( dberr(db_status) );
453
454             /* Save new name in dictionary */
455             strcpy(file_ptr->ft_name, dbfile);
456          } 
457       }
458 #if   DB_ENABLE | TS_ENABLE
459       /* adjust record table entries */
460       for (i = ORIGIN(rt_offset), rec_ptr = &record_table[ORIGIN(rt_offset)];
461            i < ORIGIN(rt_offset) + DB_REF(Size_rt);
462            ++i, ++rec_ptr) {
463          rec_ptr->rt_file += curr_db_table->ft_offset;
464          rec_ptr->rt_fields += curr_db_table->fd_offset;
465       }
466 #endif
467       /* adjust field table entries */
468       for (key_count = 0, i = ORIGIN(fd_offset), 
469               fld_ptr = &field_table[ORIGIN(fd_offset)];
470            i < ORIGIN(fd_offset) + DB_REF(Size_fd);
471            ++i, ++fld_ptr) {
472          fld_ptr->fd_rec += curr_db_table->rt_offset;
473          if ( fld_ptr->fd_key != NOKEY ) {
474             fld_ptr->fd_keyno += key_offset;
475             ++key_count;
476             fld_ptr->fd_keyfile += curr_db_table->ft_offset;
477             if ( fld_ptr->fd_type == 'k' )
478                fld_ptr->fd_ptr += curr_db_table->kt_offset;
479          }
480       }
481       key_offset += key_count;
482
483 #if   DB_ENABLE | TS_ENABLE
484       /* adjust set table entries */
485       for (i = ORIGIN(st_offset), set_ptr = &set_table[ORIGIN(st_offset)];
486            i < ORIGIN(st_offset) + DB_REF(Size_st);
487            ++i, ++set_ptr) {
488          set_ptr->st_own_rt += curr_db_table->rt_offset;
489          set_ptr->st_members += curr_db_table->mt_offset;
490       }
491 #endif
492
493       /* adjust member table entries */
494       for (i = curr_db_table->mt_offset, 
495               mem_ptr = &member_table[curr_db_table->mt_offset];
496            i < curr_db_table->mt_offset + curr_db_table->Size_mt;
497            ++i, ++mem_ptr) {
498          mem_ptr->mt_record += curr_db_table->rt_offset;
499          mem_ptr->mt_sort_fld += curr_db_table->srt_offset;
500       }
501
502       /* adjust sort table entries */
503       for (i = curr_db_table->srt_offset, 
504               srt_ptr = &sort_table[curr_db_table->srt_offset];
505            i < curr_db_table->srt_offset + curr_db_table->Size_srt;
506            ++i, ++srt_ptr) {
507          srt_ptr->se_fld += curr_db_table->fd_offset;
508          srt_ptr->se_set += curr_db_table->st_offset;
509       }
510
511       /* adjust key table entries */
512       for (i = curr_db_table->kt_offset, 
513               key_ptr = &key_table[curr_db_table->kt_offset];
514            i < curr_db_table->kt_offset + curr_db_table->Size_kt;
515            ++i, ++key_ptr) {
516          key_ptr->kt_key += curr_db_table->fd_offset;
517          key_ptr->kt_field += curr_db_table->fd_offset;
518       }
519    }  /* end loop for each database */
520    initcurr();
521    return( db_status );
522 }
523
524
525
526 /* Allocate space for dictionary
527 */
528 static int alloc_dict()
529 {
530    int old_size;
531    int new_size;
532    int extra_file = 0;
533    DB_ENTRY *db_ptr;
534
535    /* allocate and initialize file_table */
536
537    if ( old_no_of_dbs == 0 ) {
538       old_size_ft = 0;
539       old_size_fd = 0;
540       old_size_st = 0;
541       old_size_mt = 0;
542       old_size_srt = 0;
543       old_size_kt = 0;
544       old_size_rt = 0;
545    }
546    else {
547       db_ptr = &db_table[old_no_of_dbs];
548       old_size_ft = db_ptr->Size_ft + db_ptr->ft_offset + extra_file;
549       old_size_fd = db_ptr->Size_fd + db_ptr->fd_offset;
550       old_size_st = db_ptr->Size_st + db_ptr->st_offset;
551       old_size_mt = db_ptr->Size_mt + db_ptr->mt_offset;
552       old_size_srt = db_ptr->Size_srt + db_ptr->srt_offset;
553       old_size_kt = db_ptr->Size_kt + db_ptr->kt_offset;
554       old_size_rt = db_ptr->Size_rt + db_ptr->rt_offset;
555    }
556
557    new_size = (size_ft + extra_file) * sizeof(FILE_ENTRY);
558    old_size = old_size_ft * sizeof(FILE_ENTRY);
559    if ( ALLOC_TABLE(&db_global.File_table, new_size, old_size, "file_table")
560                                                                 != S_OKAY ) {
561       return( db_status );
562    }
563
564    /* allocate record_table */
565    new_size = size_rt * sizeof(RECORD_ENTRY);
566    old_size = old_size_rt * sizeof(RECORD_ENTRY);
567    if ( ALLOC_TABLE(&db_global.Record_table, new_size, old_size, "record_table")
568                                                                 != S_OKAY ) {
569       return( db_status );
570    }
571
572    /* allocate field_table */
573    new_size = size_fd * sizeof(FIELD_ENTRY);
574    old_size = old_size_fd * sizeof(FIELD_ENTRY);
575    if ( ALLOC_TABLE(&db_global.Field_table, new_size, old_size, "field_table")
576                                                                 != S_OKAY ) {
577       return( db_status );
578    }
579
580    /* allocate set table */
581    if ( size_st ) {
582       new_size = size_st * sizeof(SET_ENTRY);
583       old_size = old_size_st * sizeof(SET_ENTRY);
584       if ( ALLOC_TABLE(&db_global.Set_table, new_size, old_size, "set_table")
585                                                                 != S_OKAY ) {
586          return( db_status );
587       }
588    } else set_table = NULL;
589
590    /* allocate member_table */
591    if ( size_mt ) {
592       new_size = size_mt * sizeof(MEMBER_ENTRY);
593       old_size = old_size_mt * sizeof(MEMBER_ENTRY);
594       if ( ALLOC_TABLE(&db_global.Member_table, new_size, old_size, "member_table")
595                                                                 != S_OKAY ) {
596          return( db_status );
597       }
598    } else member_table = NULL;
599
600    /* allocate sort_table */
601    if ( size_srt ) {
602       new_size = size_srt * sizeof(SORT_ENTRY);
603       old_size = old_size_srt * sizeof(SORT_ENTRY);
604       if ( ALLOC_TABLE(&db_global.Sort_table, new_size, old_size, "sort_table")
605                                                                 != S_OKAY ) {
606          return( db_status );
607       }
608    } else sort_table = NULL;
609
610    /* allocate key_table */
611    if ( size_kt ) {
612       new_size = size_kt * sizeof(KEY_ENTRY);
613       old_size = old_size_kt * sizeof(KEY_ENTRY);
614       if ( ALLOC_TABLE(&db_global.Key_table, new_size, old_size, "key_table")
615                                                                 != S_OKAY ) {
616          return( db_status );
617       }
618    } else key_table = NULL;
619
620    return( db_status = S_OKAY );
621 }
622
623 /* Initialize currency tables 
624 */
625 static int initcurr()
626 {
627    int dbt_lc;                  /* loop control */
628    int rec, i;
629    RECORD_ENTRY *rec_ptr;
630    SET_ENTRY *set_ptr;
631    DB_ADDR *co_ptr;
632    int old_size;
633    int new_size;
634
635    /* Initialize current record and type */
636    for (dbt_lc = no_of_dbs, curr_db_table = &db_table[old_no_of_dbs],
637                                 curr_rn_table = &rn_table[old_no_of_dbs];
638         --dbt_lc >= 0; ++curr_db_table, ++curr_rn_table) {
639       DB_REF(curr_dbt_rec) = NULL_DBA;
640       RN_REF(rn_dba)   = NULL_DBA;
641       RN_REF(rn_type)  = -1;
642    }
643
644    if ( size_st ) {
645       new_size = size_st * sizeof(DB_ADDR);
646       old_size = old_size_st * sizeof(DB_ADDR);
647       if ( ALLOC_TABLE(&db_global.Curr_own, new_size, old_size, "curr_own")
648                                                                 != S_OKAY ) {
649          return( db_status );
650       }
651       if ( ALLOC_TABLE(&db_global.Curr_mem, new_size, old_size, "curr_mem")
652                                                                 != S_OKAY ) {
653          return( db_status );
654       }
655       /* for each db make system record as curr_own of its sets */
656       for (dbt_lc = no_of_dbs, curr_db_table = &db_table[old_no_of_dbs]; 
657            --dbt_lc >= 0; ++curr_db_table) {
658          for (rec = ORIGIN(rt_offset), 
659                  rec_ptr = &record_table[ORIGIN(rt_offset)];
660               rec < ORIGIN(rt_offset) + DB_REF(Size_rt);
661               ++rec, ++rec_ptr) {
662             if (rec_ptr->rt_fdtot == -1) { 
663                /* found system record */
664                curr_rec = ((FILEMASK & NUM2EXT(rec_ptr->rt_file, ft_offset))
665                                                             << FILESHIFT) | 1L;
666                /* make system record current of sets it owns */
667                for (i = ORIGIN(st_offset), 
668                        set_ptr = &set_table[ORIGIN(st_offset)],
669                        co_ptr = &curr_own[ORIGIN(st_offset)];
670                     i < ORIGIN(st_offset) + DB_REF(Size_st);
671                     ++i, ++set_ptr, ++co_ptr) {
672                   if (set_ptr->st_own_rt == rec) {
673                      *co_ptr = curr_rec;
674                   }
675                }
676                DB_REF(sysdba) = curr_rec;
677                DB_REF(curr_dbt_rec) = curr_rec;
678                break;
679             }
680          }
681       }
682    }
683    else {
684       curr_own = NULL;
685       curr_mem = NULL;
686    }
687    curr_db = 0;
688    MEM_LOCK(&db_global.Db_table);
689    curr_db_table = db_table;
690    MEM_LOCK(&db_global.Rn_table);
691    curr_rn_table = rn_table;
692    setdb_on = FALSE;
693    curr_rec = DB_REF(curr_dbt_rec);
694    return( db_status = S_OKAY );
695 }
696 /* vpp -nOS2 -dUNIX -nBSD -nVANILLA_BSD -nVMS -nMEMLOCK -nWINDOWS -nFAR_ALLOC -f/usr/users/master/config/nonwin inittab.c */