inittab.c

来自「db.* (pronounced dee-be star) is an adva」· C语言 代码 · 共 1,123 行 · 第 1/3 页

C
1,123
字号
/*************************************************************************** *                                                                         * * db.*                                                                    * * open source database kernel                                             * *                                                                         * * Copyright (c) 2000 Centura Software Corporation. All rights reserved.   * *                                                                         * * Use of this software, whether in source code format, or in executable,  * * binary object code form, is governed by the CENTURA OPEN SOURCE LICENSE * * which is fully described in the LICENSE.TXT file, included within this  * * distribution of source code files.                                      *  *                                                                         * * Except as provided herein, the contents of this file are subject to the * * Centura Open Source Public License Version 1.0 (the "License"); you may * * not use this file except in compliance with the License.  A copy of the * * License will be provided to you by Club ITTIA.                          * *                                                                         * * Software distributed under the License is distributed on an "AS IS"     * * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the * * License for the specific language governing rights and limitations      * * under the License.                                                      * *                                                                         * * The Original Code is db.linux version 1.0, released February 29, 2000.  * *                                                                         * * The Initial Developer of the Original Code is Centura Software          * * Corporation. Portions created by Centura Software Corporation are       * * Copyright (C) 1984-2000 Centura Software Corporation. All Rights        * * Reserved.                                                               * *                                                                         * * This file contains modifications to the Original Code made by ITTIA.    * * This file may only be used in accordance with the ITTIA DB.* V.2        * * License Agreement which is available at WWW.ITTIA.COM.                  * *                                                                         * **************************************************************************/#include "db.star.h"/* Internal function prototypes */static int INTERNAL_FCN initcurr(DB_TASK *);/* Compatible dictionary versions */static struct {	char * dbd;	short ver;} compat[] = {    { dbd_VERSION_300, dbd_V300 },    { dbd_VERSION_301, dbd_V301 },    { dbd_VERSION_500, dbd_V500 },#if defined(UNICODE)    { dbd_VERSION_u500, dbd_U500 }#endif};static int size_compat = sizeof(compat) / sizeof(*compat);static void getnames(DB_TCHAR **dest, DB_TCHAR **src, short start, short end){    register short     ii;    register DB_TCHAR *p = *src;    for (ii = start; ii < end; ii++)    {        dest[ii] = p;        while (*p && *p != DB_TEXT('\n'))            p++;        if (*p)            *p++ = 0;    }    *src = p;}static void skipnames(DB_TCHAR **src, short num){    short     ii;    DB_TCHAR *p = *src;    for (ii = 0; *p && ii < num; ii++)    {        while (*p && *p != DB_TEXT('\n'))            p++;        if (*p)            p++;    }    *src = p;}struct DICT_SIZE{    short Page_size;    short Size_ft;    short Size_rt;    short Size_fd;    short Size_st;    short Size_mt;    short Size_srt;    short Size_kt;};static int get_dbd_dict_sizes(int dbt_lc, struct DICT_SIZE * dict_size, DB_TASK * task){    char                dbd_ver[DBD_COMPAT_LEN + 1];    DB_TCHAR            dbfile[FILENMLEN];    DB_TCHAR            dbname[FILENMLEN]; /* Temporary working space */    int                 stat = S_OKAY;    PSP_FH              dbf;	DB_ENTRY          * curr_dbt = task->curr_db_table;	int                 i;	/* form database dictionary name */	if (curr_dbt->db_path[0])		vtstrcpy(dbname, curr_dbt->db_path);	else		dbname[0] = DB_TEXT('\0');		if (vtstrlen(dbname) + vtstrlen(curr_dbt->db_name) >= FILENMLEN + 4)		return (dberr(S_NAMELEN));		vtstrcat(dbname, curr_dbt->db_name);	if (con_dbd(dbfile, dbname, get_element(task->dbdpath, dbt_lc), task) != S_OKAY)		return (task->db_status);		if ((dbf = psp_fileOpen(dbfile, O_RDONLY, PSP_FLAG_DENYNO)) == NULL)		return (dberr(S_INVDB));		/* Read in and verify the dictionary version */	psp_fileSeek(dbf, 0);	if (psp_fileRead(dbf, dbd_ver, DBD_COMPAT_LEN) != DBD_COMPAT_LEN)	{		psp_fileClose(dbf);		return (dberr(S_BADREAD));	}		dbd_ver[DBD_COMPAT_LEN] = '\0';	for (i = 0; i < size_compat; i++)	{		if (strcmp(dbd_ver, compat[i].dbd) == 0)		{			curr_dbt->db_ver = (short) compat[i].ver;			break;		}	}		if (i == size_compat)	{		/* Incompatible dictionary file */		psp_fileClose(dbf);		return (dberr(S_INCOMPAT));	}		/* Read in database page and table sizes */	if (psp_fileRead(dbf, dict_size, sizeof(*dict_size)) <		(int) sizeof(*dict_size))		stat = S_BADREAD;		psp_fileClose(dbf);	if (stat != S_OKAY)		return (task->db_status = stat);		if (dict_size->Size_ft > 255)		return dberr(S_INVDB); /* probably different byte ordering */	return task->db_status;}static int load_dbd(int dbt_lc, const SG *sg, DB_TASK *task){    PSP_FH              dbf;    DB_TCHAR            dbname[FILENMLEN]; /* Temporary working space */    DB_TCHAR            dbfile[FILENMLEN];	DB_ENTRY          * curr_dbt = task->curr_db_table;    F_ADDR              flen = 0;    F_ADDR              fpos = 0;    F_ADDR              n;    int                 size;    int                 stat = S_OKAY;	int                 i;	DB_TCHAR           *p;    /* Old comment:	   Allocate extra array to convert file table from dbd format to       internal format. Don't know until we read the DBD version whether       this is a v3.00 DBD file (normal), v3.01, with file block       extensions (VxWorks), v5.00, with file block extensions and 256       char file names or u5.00 (same as v5.00, but wchar_t Unicode file       names. None of these versions of the file table is bigger than the       current FILE_ENTRY structure.	   New comment:       Suppose it is better not to allocate memory in advance at all,       so I used union and done entries reading iterative.    */	FILE_ENTRY         *fptr;	union {		V300_FILE_ENTRY    v300;		V301_FILE_ENTRY    v301;		V500_FILE_ENTRY    v500;		U500_FILE_ENTRY    u500;	} fe;	/* form database dictionary name */	if (curr_dbt->db_path[0])		vtstrcpy(dbname, curr_dbt->db_path);	else		dbname[0] = DB_TEXT('\0');		if (vtstrlen(dbname) + vtstrlen(curr_dbt->db_name) >= FILENMLEN + 4)		return (dberr(S_NAMELEN));		vtstrcat(dbname, curr_dbt->db_name);		if (con_dbd(dbfile, dbname, get_element(task->dbdpath, dbt_lc), task) != S_OKAY)		return (task->db_status);		dbf = psp_fileOpen(dbfile, O_RDONLY, PSP_FLAG_DENYNO);	flen = psp_fileLength(dbf);		/* determine dbd version, and read file table into appropriate	structure:	V3.00 has 48 character file names	V3.01 has 48 character file names with file table extensions	V5.00 has 256 character (ansi) file names with extensions	U5.00 has 256 character (unicode) file names with extensions	*/	size = (curr_dbt->db_ver == 500) ? sizeof(V500_FILE_ENTRY) :	(curr_dbt->db_ver == -500) ? sizeof(U500_FILE_ENTRY) :	(curr_dbt->db_ver == 301) ? sizeof(V301_FILE_ENTRY) : sizeof(V300_FILE_ENTRY);		fpos = DBD_COMPAT_LEN + 8L * sizeof(short);	psp_fileSeek(dbf, fpos);		if (stat == S_OKAY)	{		for (i = 0, fptr = &task->file_table[curr_dbt->ft_offset];		i < curr_dbt->Size_ft; ++i, ++fptr)		{			if (psp_fileRead(dbf, &fe.v300, size) < size) {				stat = S_BADREAD;				break;			}				fpos += size;			switch (curr_dbt->db_ver)			{			case 300:				atot(fe.v300.v3_ft_name, fptr->ft_name, FILENMLEN);				fptr->ft_status  = fe.v300.v3_ft_status;				fptr->ft_type    = fe.v300.v3_ft_type;				fptr->ft_slots   = fe.v300.v3_ft_slots;				fptr->ft_slsize  = fe.v300.v3_ft_slsize;				fptr->ft_pgsize  = fe.v300.v3_ft_pgsize;				fptr->ft_flags   = fe.v300.v3_ft_flags;				fptr->ft_pctincrease = 0;				fptr->ft_initial = 0;				fptr->ft_next    = 0;				fptr->ft_index   = -1;				fptr->ft_lmtimestamp = 0;				fptr->ft_cachetimestamp = 0;				break;							case 301:				atot(fe.v301.v3_ft_name, fptr->ft_name, FILENMLEN);				fptr->ft_status  = fe.v301.v3_ft_status;				fptr->ft_type    = fe.v301.v3_ft_type;				fptr->ft_slots   = fe.v301.v3_ft_slots;				fptr->ft_slsize  = fe.v301.v3_ft_slsize;				fptr->ft_pgsize  = fe.v301.v3_ft_pgsize;				fptr->ft_flags   = fe.v301.v3_ft_flags;				fptr->ft_pctincrease = fe.v301.v3_ft_pctincrease;				fptr->ft_initial = fe.v301.v3_ft_initial;				fptr->ft_next    = fe.v301.v3_ft_next;				fptr->ft_index = -1;				fptr->ft_lmtimestamp = 0;				fptr->ft_cachetimestamp = 0;				break;							case 500:				atot(fe.v500.v5_ft_name, fptr->ft_name, FILENMLEN);				fptr->ft_status  = fe.v500.v5_ft_status;				fptr->ft_type    = fe.v500.v5_ft_type;				fptr->ft_slots   = fe.v500.v5_ft_slots;				fptr->ft_slsize  = fe.v500.v5_ft_slsize;				fptr->ft_pgsize  = fe.v500.v5_ft_pgsize;				fptr->ft_flags   = fe.v500.v5_ft_flags;				fptr->ft_pctincrease = fe.v500.v5_ft_pctincrease;				fptr->ft_initial = fe.v500.v5_ft_initial;				fptr->ft_next    = fe.v500.v5_ft_next;				fptr->ft_index = -1;				fptr->ft_lmtimestamp = 0;				fptr->ft_cachetimestamp = 0;				break;#if defined(UNICODE)			case -500:				memcpy(fptr, &fe.u500, sizeof(FILE_ENTRY));				break;#endif			}		}	}	if (stat == S_OKAY)	{		n = curr_dbt->Size_rt * sizeof(RECORD_ENTRY);		if (psp_fileRead(dbf, &task->record_table[curr_dbt->rt_offset], n) < n)			stat = S_BADREAD;				fpos += n;	}		if (stat == S_OKAY && curr_dbt->Size_fd)	{		n = curr_dbt->Size_fd * sizeof(FIELD_ENTRY);		if (psp_fileRead(dbf, &task->field_table[curr_dbt->fd_offset], n) < n)			stat = S_BADREAD;				fpos += n;	}		if (stat == S_OKAY && curr_dbt->Size_st)	{		n = curr_dbt->Size_st * sizeof(SET_ENTRY);		if (psp_fileRead(dbf, &task->set_table[curr_dbt->st_offset], n) < n)			stat = S_BADREAD;				fpos += n;	}		if (stat == S_OKAY && curr_dbt->Size_mt)	{		n = curr_dbt->Size_mt * sizeof(MEMBER_ENTRY);		if (psp_fileRead(dbf, &task->member_table[curr_dbt->mt_offset], n) < n)			stat = S_BADREAD;				fpos += n;	}		if (stat == S_OKAY && curr_dbt->Size_srt)	{		n = curr_dbt->Size_srt * sizeof(SORT_ENTRY);		if (psp_fileRead(dbf, &task->sort_table[curr_dbt->srt_offset], n) < n)			stat = S_BADREAD;				fpos += n;	}		if (stat == S_OKAY && curr_dbt->Size_kt)	{		n = curr_dbt->Size_kt * sizeof(KEY_ENTRY);		if (psp_fileRead(dbf, &task->key_table[curr_dbt->kt_offset], n) < n)			stat = S_BADREAD;				fpos += n;	}		flen = (flen > fpos) ? (flen - fpos) : 0;	if (stat != S_OKAY)		;	else if ((p = (DB_TCHAR *) psp_cGetMemory(flen, 0)) == NULL)		stat = S_NOMEMORY;	else	{		if (psp_fileRead(dbf, p, flen) < flen)			stat = S_BADREAD;		else if (task->dboptions & READNAMES)		{#if defined(UNICODE)			if (v > 0) /* ANSI dbd, convert names to Unicode */			{				char *q = (char *)p;								p = (DB_TCHAR *) psp_cGetMemory(flen * sizeof(DB_TCHAR), 0);				if (!p)					stat = S_NOMEMORY;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?