/* read MAP_FILE and make appropriate d_mapchar-calls */ int ctb_init() { int map_fd; unsigned char inchar, outchar, subsort; char loc_buf[21], sortas[3]; short subs_i; char ctb_name[FILENMLEN*2]; strcpy( ctb_name, db_global.ctbpath ); strcat( ctb_name, CTBNAME ); if ( (map_fd = open_b(ctb_name,O_RDONLY)) != -1 ) { while(bgets(loc_buf,20,map_fd), *loc_buf) { if ( strcmp( loc_buf, "ignorecase" ) == 0 ) { if ( d_on_opt( IGNORECASE CURRTASK_PARM ) != S_OKAY ) break; } else { sscanf(loc_buf,"%c,%c,%hd,%2s",&inchar,&outchar,&subs_i,&sortas[0]); subsort = (unsigned char) subs_i; if (d_mapchar(inchar,outchar,sortas,subsort CURRTASK_PARM) != S_OKAY ) break; } } close(map_fd); return( db_status ); } return(db_status = S_OKAY); }
/* Initialize database tables */ int inittab() { register int dbt_lc; /* loop control */ register INT i, j; int key_offset = 0, key_count; char dbfile[DtSrFILENMLEN], dbd_ver[DBD_COMPAT_LEN + 1]; char dbname[FILENMLEN]; /* Temporary working space */ int dbf; FILE_ENTRY FAR *file_ptr; FIELD_ENTRY FAR *fld_ptr; #ifndef ONE_DB #define DB_ENABLE 1 #else #define DB_ENABLE 0 #endif #ifndef NO_TIMESTAMP #define TS_ENABLE 1 #else #define TS_ENABLE 0 #endif #if DB_ENABLE | TS_ENABLE RECORD_ENTRY FAR *rec_ptr; SET_ENTRY FAR *set_ptr; #endif #ifndef ONE_DB MEMBER_ENTRY FAR *mem_ptr; SORT_ENTRY FAR *srt_ptr; KEY_ENTRY FAR *key_ptr; #endif #ifndef NO_TIMESTAMP db_tsrecs = db_tssets = FALSE; #endif size_ft = size_rt = size_st = size_mt = size_srt = size_fd = size_kt = 0; /* compute individual dictionary sizes and offsets */ #ifndef ONE_DB for (dbt_lc = 0, curr_db_table = &db_table[old_no_of_dbs]; dbt_lc < no_of_dbs; ++dbt_lc, ++curr_db_table) { #endif /* form database dictionary name */ if ( DB_REF(db_path[0]) ) strcpy(dbname, DB_REF(db_path)); else dbname[0] = '\0'; #ifdef DEBUG_INITTAB if (debugging_inittab) { printf (__FILE__"100 inittab: path='%s' dbname='%s'\n", dbname, DB_REF(db_name)); fflush (stdout); } #endif if (strlen(dbname) + strlen(DB_REF(db_name)) >= FILENMLEN+4) return( dberr(S_NAMELEN) ); strcat(dbname, DB_REF(db_name)); if (con_dbd(dbfile, dbname, get_element(dbdpath, dbt_lc)) != S_OKAY) return( dberr(db_status) ); /*----------------- PASS 1 ------------------- * In this first pass, only opening to determine * required table sizes, so opening read-only is ok. */ if ( (dbf = open_b(dbfile, O_RDONLY)) < 0 ) return( dberr( S_INVDB ) ); /* Read in and verify the dictionary version */ DB_READ(dbf, dbd_ver, DBD_COMPAT_LEN); dbd_ver[DBD_COMPAT_LEN] = '\0'; for ( i=0; i<size_compat; i++ ) { if ( strcmp( dbd_ver, compat_dbd[i] ) == 0 ) goto goodver; } /* Incompatible dictionary file */ close( dbf ); return( dberr( S_INCOMPAT ) ); goodver: /* Read in database page size */ DB_READ(dbf, (char FAR *)&DB_REF(Page_size), sizeof(INT)); NTOHS (DB_REF(Page_size)); /* Read in table sizes */ DB_READ(dbf, (char FAR *)&DB_REF(Size_ft), sizeof(INT)); NTOHS (DB_REF(Size_ft)); DB_READ(dbf, (char FAR *)&DB_REF(Size_rt), sizeof(INT)); NTOHS (DB_REF(Size_rt)); DB_READ(dbf, (char FAR *)&DB_REF(Size_fd), sizeof(INT)); NTOHS (DB_REF(Size_fd)); DB_READ(dbf, (char FAR *)&DB_REF(Size_st), sizeof(INT)); NTOHS (DB_REF(Size_st)); DB_READ(dbf, (char FAR *)&DB_REF(Size_mt), sizeof(INT)); NTOHS (DB_REF(Size_mt)); DB_READ(dbf, (char FAR *)&DB_REF(Size_srt), sizeof(INT)); NTOHS (DB_REF(Size_srt)); DB_READ(dbf, (char FAR *)&DB_REF(Size_kt), sizeof(INT)); NTOHS (DB_REF(Size_kt)); close(dbf); /* end of PASS 1 */ #ifdef DEBUG_INITTAB if (debugging_inittab) { printf (__FILE__"152 sizes: pg=%d ft=%d rt=%d fd=%d\n" " st=%d mt=%d srt=%d kt=%d\n", (int) DB_REF(Page_size), (int) DB_REF(Size_ft), (int) DB_REF(Size_rt), (int) DB_REF(Size_fd), (int) DB_REF(Size_st), (int) DB_REF(Size_mt), (int) DB_REF(Size_srt), (int) DB_REF(Size_kt) ); fflush (stdout); } #endif DB_REF(sysdba) = NULL_DBA; #ifndef ONE_DB /* update merged dictionary offsets and sizes */ if ( curr_db_table->Page_size > page_size ) { page_size = curr_db_table->Page_size; #ifdef DEBUG_INITTAB if (debugging_inittab) { printf (__FILE__"191 db's page_size-->%d (largest = %d)\n", (int)page_size, (int)largest_page); fflush(stdout); } #endif } curr_db_table->ft_offset = size_ft; size_ft += curr_db_table->Size_ft; curr_db_table->rt_offset = size_rt; size_rt += curr_db_table->Size_rt; curr_db_table->fd_offset = size_fd; size_fd += curr_db_table->Size_fd; curr_db_table->st_offset = size_st; size_st += curr_db_table->Size_st; curr_db_table->mt_offset = size_mt; size_mt += curr_db_table->Size_mt; curr_db_table->srt_offset = size_srt; size_srt += curr_db_table->Size_srt; curr_db_table->kt_offset = size_kt; size_kt += curr_db_table->Size_kt; } #endif /* allocate dictionary space */ if ( alloc_dict() != S_OKAY ) return( db_status ); /* read in and adjust dictionary entries for each database */ #ifndef ONE_DB for (dbt_lc = 0, curr_db_table = &db_table[old_no_of_dbs]; dbt_lc < no_of_dbs; ++dbt_lc, ++curr_db_table) { #endif /* form database dictionary name */ if ( DB_REF(db_path[0]) ) strcpy(dbname, DB_REF(db_path)); else dbname[0] = '\0'; if (strlen(dbname) + strlen(DB_REF(db_name)) >= FILENMLEN+4) return( dberr(S_NAMELEN) ); strcat(dbname,DB_REF(db_name)); if (con_dbd(dbfile,dbname,get_element(dbdpath, dbt_lc)) != S_OKAY) return( dberr(db_status) ); #ifdef DEBUG_INITTAB if (dump_init_tables) { printf (__FILE__"247 Tables for database '%s':\n", dbfile); fflush (stdout); } #endif /*----------------- PASS 2 ------------------- * Second pass just loads allocated tables, * so opening .dbd file read-only is still ok. */ dbf = open_b (dbfile, O_RDONLY); DB_LSEEK(dbf, DBD_COMPAT_LEN + 8L*sizeof(INT), 0); /*----------------- FILE TABLE -------------------*/ DB_READ(dbf, (char FAR *)&file_table[ORIGIN(ft_offset)], (DB_REF(Size_ft)*sizeof(FILE_ENTRY))); /* Invalid if sizeof(xxxx_ENTRY) diff on each machine */ for ( i = 0, file_ptr = &file_table[ORIGIN(ft_offset)]; i < DB_REF(Size_ft); i++, file_ptr++) { /* Byte swap each INT on LITTLE_ENDIAN machines */ NTOHS (file_ptr->ft_slots); NTOHS (file_ptr->ft_slsize); NTOHS (file_ptr->ft_pgsize); NTOHS (file_ptr->ft_flags); #ifdef DEBUG_INITTAB if (dump_init_tables) { printf (" FILE#%d: ty=%c slts=%2d slsz=%3d pgsz=%d '%s'\n", (int)i, file_ptr->ft_type, (int)file_ptr->ft_slots, (int)file_ptr->ft_slsize, (int)file_ptr->ft_pgsize, file_ptr->ft_name); fflush (stdout); } #endif } /*----------------- RECORD TABLE -------------------*/ DB_READ(dbf, (char FAR *)&record_table[ORIGIN(rt_offset)], (DB_REF(Size_rt)*sizeof(RECORD_ENTRY))); for ( i = 0, rec_ptr = &record_table[ORIGIN(rt_offset)]; i < DB_REF(Size_rt); i++, rec_ptr++) { /* Byte swap each INT on LITTLE_ENDIAN machines */ NTOHS (rec_ptr->rt_file); NTOHS (rec_ptr->rt_len); NTOHS (rec_ptr->rt_data); NTOHS (rec_ptr->rt_fields); NTOHS (rec_ptr->rt_fdtot); NTOHS (rec_ptr->rt_flags); #ifdef DEBUG_INITTAB if (dump_init_tables) { printf ( " REC #%d: fil=%d len=%3d data=%2d fld1=%2d flds=%2d\n", (int)i, (int)rec_ptr->rt_file, (int)rec_ptr->rt_len, (int)rec_ptr->rt_data, (int)rec_ptr->rt_fields, (int)rec_ptr->rt_fdtot); fflush (stdout); } #endif } /*----------------- FIELD TABLE -------------------*/ DB_READ(dbf, (char FAR *)&field_table[ORIGIN(fd_offset)], (DB_REF(Size_fd)*sizeof(FIELD_ENTRY))); for ( i = 0, fld_ptr = &field_table[ORIGIN(fd_offset)]; i < DB_REF(Size_fd); i++, fld_ptr++) { /* Byte swap each INT on LITTLE_ENDIAN machines */ NTOHS (fld_ptr->fd_len); NTOHS (fld_ptr->fd_keyfile); NTOHS (fld_ptr->fd_keyno); NTOHS (fld_ptr->fd_ptr); NTOHS (fld_ptr->fd_rec); NTOHS (fld_ptr->fd_flags); for (j=0; j<MAXDIMS; j++) NTOHS (fld_ptr->fd_dim[j]); #ifdef DEBUG_INITTAB if (dump_init_tables) { if (i == 0) puts (" key typ len kfil key# ofs rec# flg dims"); printf ( " FLD#%2d %c %c %3d %d %d %3d %d %x", (int)i, fld_ptr->fd_key, fld_ptr->fd_type, (int)fld_ptr->fd_len, (int)fld_ptr->fd_keyfile, (int)fld_ptr->fd_keyno, (int)fld_ptr->fd_ptr, (int)fld_ptr->fd_rec, (int)fld_ptr->fd_flags); for (j=0; j<MAXDIMS; j++) if (fld_ptr->fd_dim[j]) printf (" %d:%d", j, (int)fld_ptr->fd_dim[j]); putchar ('\n'); fflush (stdout); } #endif } /*----------------- SET TABLE -------------------*/ DB_READ(dbf, (char FAR *)&set_table[ORIGIN(st_offset)], (DB_REF(Size_st)*sizeof(SET_ENTRY))); for ( i = 0, set_ptr = &set_table[ORIGIN(st_offset)]; i < DB_REF(Size_st); i++, set_ptr++) { /* Byte swap each INT on LITTLE_ENDIAN machines */ NTOHS (set_ptr->st_order); NTOHS (set_ptr->st_own_rt); NTOHS (set_ptr->st_own_ptr); NTOHS (set_ptr->st_members); NTOHS (set_ptr->st_memtot); NTOHS (set_ptr->st_flags); #ifdef DEBUG_INITTAB if (dump_init_tables) { printf ( " SET #%d: ord=%c owner=%d ownofs=%2d mem1=%d mems=%d\n", (int)i, (char)set_ptr->st_order, (int)set_ptr->st_own_rt, (int)set_ptr->st_own_ptr, (int)set_ptr->st_members, (int)set_ptr->st_memtot); fflush (stdout); } #endif } /*----------------- MEMBER TABLE -------------------*/ DB_READ(dbf, (char FAR *)&member_table[ORIGIN(mt_offset)], (DB_REF(Size_mt)*sizeof(MEMBER_ENTRY))); for ( i = 0, mem_ptr = &member_table[ORIGIN(mt_offset)]; i < DB_REF(Size_mt); i++, mem_ptr++) { /* Byte swap each INT on LITTLE_ENDIAN machines */ NTOHS (mem_ptr->mt_record); NTOHS (mem_ptr->mt_mem_ptr); NTOHS (mem_ptr->mt_sort_fld); NTOHS (mem_ptr->mt_totsf); #ifdef DEBUG_INITTAB if (dump_init_tables) { printf ( " MEM #%d: rec=%d ofs=%d sort1=%d sorts=%d\n", (int)i, (int)mem_ptr->mt_record, (int)mem_ptr->mt_mem_ptr, (int)mem_ptr->mt_sort_fld, (int)mem_ptr->mt_totsf); fflush (stdout); } #endif } DB_READ(dbf, (char FAR *)&sort_table[ORIGIN(srt_offset)], (DB_REF(Size_srt)*sizeof(SORT_ENTRY))); /* Member sort tables not used by DtSearch @@@ */ if (DB_REF(Size_srt)) { /* Byte swap each INT on LITTLE_ENDIAN machines */ srt_ptr = &sort_table[ORIGIN(srt_offset)]; NTOHS (srt_ptr->se_fld); NTOHS (srt_ptr->se_set); } DB_READ(dbf, (char FAR *)&key_table[ORIGIN(kt_offset)], (DB_REF(Size_kt)*sizeof(KEY_ENTRY))); /* Compound key tables not used by DtSearch @@@ */ if (DB_REF(Size_kt)) { /* Byte swap each INT on LITTLE_ENDIAN machines */ key_ptr = &key_table[ORIGIN(kt_offset)]; NTOHS (key_ptr->kt_key); NTOHS (key_ptr->kt_field); NTOHS (key_ptr->kt_ptr); NTOHS (key_ptr->kt_sort); } close(dbf); /* end of PASS 2 */ #ifdef DEBUG_INITTAB dump_init_tables = FALSE; #endif #ifndef ONE_DB curr_db_table->key_offset = key_offset; #endif /* update file table path entries */ if ( DB_REF(db_path[0]) || dbfpath[0] ) { for (i = 0, file_ptr = &file_table[ORIGIN(ft_offset)]; i < DB_REF(Size_ft); ++i, ++file_ptr) { /* Construct the data/key file name */ if ( DB_REF(db_path[0]) ) strcpy(dbname, DB_REF(db_path)); else dbname[0] = '\0'; if (strlen(dbname) + strlen(DB_REF(db_name)) >= FILENMLEN+4) return( dberr(S_NAMELEN) ); strcat(dbname, DB_REF(db_name)); if (con_dbf(dbfile, file_ptr->ft_name, dbname, get_element(dbfpath, dbt_lc)) != S_OKAY) return( dberr(db_status) ); /* Save new name in dictionary */ strcpy(file_ptr->ft_name, dbfile); } } #if DB_ENABLE | TS_ENABLE /* adjust record table entries */ for (i = ORIGIN(rt_offset), rec_ptr = &record_table[ORIGIN(rt_offset)]; i < ORIGIN(rt_offset) + DB_REF(Size_rt); ++i, ++rec_ptr) { #ifndef ONE_DB rec_ptr->rt_file += curr_db_table->ft_offset; rec_ptr->rt_fields += curr_db_table->fd_offset; #endif #ifndef NO_TIMESTAMP if ( rec_ptr->rt_flags & TIMESTAMPED ) { db_tsrecs = TRUE; #ifdef ONE_DB break; #endif } #endif } #endif /* adjust field table entries */ for (key_count = 0, i = ORIGIN(fd_offset), fld_ptr = &field_table[ORIGIN(fd_offset)]; i < ORIGIN(fd_offset) + DB_REF(Size_fd); ++i, ++fld_ptr) { #ifndef ONE_DB fld_ptr->fd_rec += curr_db_table->rt_offset; #endif if ( fld_ptr->fd_key != NOKEY ) { fld_ptr->fd_keyno += key_offset; ++key_count; #ifndef ONE_DB fld_ptr->fd_keyfile += curr_db_table->ft_offset; if ( fld_ptr->fd_type == 'k' ) fld_ptr->fd_ptr += curr_db_table->kt_offset; #endif } } key_offset += key_count; #if DB_ENABLE | TS_ENABLE /* adjust set table entries */ for (i = ORIGIN(st_offset), set_ptr = &set_table[ORIGIN(st_offset)]; i < ORIGIN(st_offset) + DB_REF(Size_st); ++i, ++set_ptr) { #ifndef ONE_DB set_ptr->st_own_rt += curr_db_table->rt_offset; set_ptr->st_members += curr_db_table->mt_offset; #endif #ifndef NO_TIMESTAMP if ( set_ptr->st_flags & TIMESTAMPED ) { db_tssets = TRUE; #ifdef ONE_DB break; #endif } #endif } #endif #ifndef ONE_DB /* adjust member table entries */ for (i = curr_db_table->mt_offset, mem_ptr = &member_table[curr_db_table->mt_offset]; i < curr_db_table->mt_offset + curr_db_table->Size_mt; ++i, ++mem_ptr) { mem_ptr->mt_record += curr_db_table->rt_offset; mem_ptr->mt_sort_fld += curr_db_table->srt_offset; } /* adjust sort table entries */ for (i = curr_db_table->srt_offset, srt_ptr = &sort_table[curr_db_table->srt_offset]; i < curr_db_table->srt_offset + curr_db_table->Size_srt; ++i, ++srt_ptr) { srt_ptr->se_fld += curr_db_table->fd_offset; srt_ptr->se_set += curr_db_table->st_offset; } /* adjust key table entries */ for (i = curr_db_table->kt_offset, key_ptr = &key_table[curr_db_table->kt_offset]; i < curr_db_table->kt_offset + curr_db_table->Size_kt; ++i, ++key_ptr) { key_ptr->kt_key += curr_db_table->fd_offset; key_ptr->kt_field += curr_db_table->fd_offset; } } /* end loop for each database */ #endif initcurr(); return( db_status ); }