dbd.c

来自「db.* (pronounced dee-be star) is an adva」· C语言 代码 · 共 159 行

C
159
字号
/*************************************************************************** *                                                                         * * 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"int EXTERNAL_FCN dbuild_dbd(const DB_SCHEMA * sc, DB_TASK *task){	DB_TCHAR dbname[FILENMLEN];    PSP_FH   dbf;    char    *ver;	int      i;	int      stat = S_OKAY;	union {		FILE_ENTRY      * fe;		V300_FILE_ENTRY * v300;		V301_FILE_ENTRY * v301;		V500_FILE_ENTRY * v500;		U500_FILE_ENTRY * u500;	} fptr;	switch(sc->sc_version) {	case  300:		ver = dbd_VERSION_300;		break;	case  301:		ver = dbd_VERSION_301;		break;	case  500:		ver = dbd_VERSION_500;		break;#if defined(UNICODE)	case -500:		ver = dbd_VERSION_u500;		/* TODO: we should implement U500_FILE_ENTRY -> FILE_ENTRY translation */		return dberr(S_INCOMPAT);		break;#endif	default: return dberr(S_INCOMPAT);	}	if (con_dbd(dbname, sc->sc_dbname, task->dbdpath, task) != S_OKAY)		return (task->db_status);	psp_fileRemove(dbname);	if ((dbf = psp_fileOpen(dbname, O_RDWR | O_CREAT, PSP_FLAG_DENYNO)) == NULL)        return dberr(S_NOFILE);	fptr.fe = sc->sc_files;#define WRITE(buf,size) ((psp_fileWrite(dbf, buf, (size)) == (size)) ?  S_OKAY : S_BADWRITE)    /* output dictionary version */    stat = WRITE(ver, DBD_COMPAT_LEN);    /* output page size */	if (stat == S_OKAY) stat = WRITE(&sc->sc_page_size, sizeof(short));    /* output file sizes */	if (stat == S_OKAY) stat = WRITE(&sc->sc_nfiles, sizeof(short));	if (stat == S_OKAY) stat = WRITE(&sc->sc_nrecords, sizeof(short));	if (stat == S_OKAY) stat = WRITE(&sc->sc_nfields, sizeof(short));	if (stat == S_OKAY) stat = WRITE(&sc->sc_nsets, sizeof(short));	if (stat == S_OKAY) stat = WRITE(&sc->sc_nmembers, sizeof(short));	if (stat == S_OKAY) stat = WRITE(&sc->sc_nsorts, sizeof(short));	if (stat == S_OKAY) stat = WRITE(&sc->sc_nkeys, sizeof(short));	if (stat == S_OKAY) {		for(i = 0; i < sc->sc_nfields; i++) {			switch(sc->sc_version) {			case dbd_V300:				stat = WRITE(fptr.v300++, sizeof(V300_FILE_ENTRY));				break;			case dbd_V301:				stat = WRITE(fptr.v301++, sizeof(V301_FILE_ENTRY));				break;			case dbd_V500:				stat = WRITE(fptr.v500++, sizeof(V500_FILE_ENTRY));				break;			case dbd_U500:				stat = WRITE(fptr.u500++, sizeof(U500_FILE_ENTRY));				break;			}		}	}    /* output record table */	for (i = 0; stat == S_OKAY && i < sc->sc_nrecords; i++)		stat = WRITE(sc->sc_records + i, sizeof(RECORD_ENTRY));    /* output field table */    for (i = 0; stat == S_OKAY && i < sc->sc_nfields; i++)        stat = WRITE(sc->sc_fields + i, sizeof(FIELD_ENTRY));    /* output set table */    for (i = 0; stat == S_OKAY && i < sc->sc_nsets; i++)        stat = WRITE(sc->sc_sets + i, sizeof(SET_ENTRY));    /* output member table */    for (i = 0; stat == S_OKAY && i < sc->sc_nmembers; i++)        stat = WRITE(sc->sc_members + i, sizeof(MEMBER_ENTRY));    /* output sort table */    for (i = 0; stat == S_OKAY && i < sc->sc_nsorts; i++)        stat = WRITE(sc->sc_sorts + i, sizeof(SORT_ENTRY));    /* output compound key table */    for (i = 0; stat == S_OKAY && i < sc->sc_nkeys; i++)        stat = WRITE(sc->sc_keys + i, sizeof(KEY_ENTRY));	if (stat == S_OKAY && sc->sc_names)		stat = WRITE(sc->sc_names, (int)strlen(sc->sc_names));	if (stat == S_OKAY && sc->sc_nsgdata)		stat = WRITE(sc->sc_sgdata, sc->sc_nsgdata);	psp_fileClose(dbf);	return (stat == S_OKAY) ? task->db_status : dberr(stat);}

⌨️ 快捷键说明

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