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