ddltable.c
来自「db.* (pronounced dee-be star) is an adva」· C语言 代码 · 共 2,236 行 · 第 1/5 页
C
2,236 行
/*************************************************************************** * * * 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. * * * **************************************************************************//*----------------------------------------------------------------------- ddltable.c - db.* DDL processor table handling routines This module contains functions that are called during the parsing of a db.* ddlp schema. They store and validate the data as it is recognized by the parser.-----------------------------------------------------------------------*/#include "db.star.h"#include "version.h"#include "parser.h"#include "ddldefs.h"#define FATAL 1#define NOT_FATAL 0/* ********************** GLOBAL VARIABLE DECLARATIONS *************** *//* timestamped record list */static ID_INFO *trlist = NULL;static ID_INFO *trlast = NULL;static int ts_all_recs = FALSE;/* timestamped set list */static ID_INFO *tslist = NULL;static ID_INFO *tslast = NULL;static int ts_all_sets = FALSE;/* constant list */static CONST_INFO *const_list = NULL;static CONST_INFO *const_last = NULL;/* type list */static TYPE_INFO *type_list = NULL;static TYPE_INFO *type_last = NULL;static short key_prefix = 0;/* ********************** LOCAL FUNCTION DECLARATIONS ************* */static int add_base_type (DB_TCHAR *, short, char, int);static void free_elems (ELEM_INFO *);static void free_idlist (ID_INFO *);static void pr_hdr (void);/* ********************** LOCAL VARIABLE DECLARATIONS **************** */static int lines, page;static unsigned short str_flg; /* Set if struct contains non-chars */static int SystemSetDynamic = FALSE;static int InSystemSet = FALSE;static short max_page_size = 0;/* Initialize variables, etc. */void tableInit (void){ trlist = NULL; trlast = NULL; ts_all_recs = FALSE; tslist = NULL; tslast = NULL; ts_all_sets = FALSE; const_list = NULL; const_last = NULL; type_list = NULL; type_last = NULL; key_prefix = 0; InSystemSet = FALSE; SystemSetDynamic = FALSE;}int vstricmp(const char *s1, const char *s2){ int result, c1, c2; if (s1 == NULL) { if (s2 == NULL) return 0; else return -1; } else if (s2 == NULL) { return 1; } do { c1 = (int) ((unsigned char) (islower(*s1) ? toupper(*s1) : *s1)); c2 = (int) ((unsigned char) (islower(*s2) ? toupper(*s2) : *s2)); result = c1 - c2; /* arithmetic over-/under-flow not possible */ s1++; s2++; } while (c1 && c2 && !result); return (result);}/* Store timestamped record list*/void ts_recs(ID_INFO *id_list){ ID_INFO *p; if (id_list) { if (trlist == NULL) trlist = id_list; else trlast->next_id = id_list; for (p = id_list; p; p = p->next_id) { if (ddlp_g.x_flag) add_xref(NULL, p->id_name, 'r', p->id_line); trlast = p; } } else { ts_all_recs = TRUE; }}/* Store timestamped set list*/void ts_sets(ID_INFO *id_list){ ID_INFO *p; if (id_list) { if (tslist == NULL) tslist = id_list; else tslast->next_id = id_list; for (p = id_list; p; p = p->next_id) { if (ddlp_g.x_flag) add_xref(NULL, p->id_name, 's', p->id_line); tslast = p; } } else { ts_all_sets = TRUE; }}/* Initialize type list*/void init_lists(){ trlist = trlast = NULL; tslist = tslast = NULL; ts_all_recs = FALSE; ts_all_sets = FALSE; const_list = const_last = NULL; type_list = type_last = NULL; ddlp_g.elem_list = ddlp_g.elem_last = NULL; ddlp_g.file_list = ddlp_g.file_last = NULL; ddlp_g.rec_list = ddlp_g.last_rec = NULL; ddlp_g.field_list = ddlp_g.last_fld = ddlp_g.cur_struct = NULL; ddlp_g.key_list = ddlp_g.last_key = NULL; ddlp_g.set_list = ddlp_g.last_set = NULL; ddlp_g.mem_list = ddlp_g.last_mem = NULL; ddlp_g.sort_list = ddlp_g.last_sort = NULL; key_prefix = 0; add_base_type(DB_TEXT("DB_ADDR"), sizeof(DB_ADDR), 'd', 0); add_base_type(DB_TEXT("char"), sizeof(char), 'c', 0); add_base_type(DB_TEXT("wchar_t"), sizeof(wchar_t), 'C', 0); add_base_type(DB_TEXT("short"), sizeof(short), 's', 0); add_base_type(DB_TEXT("long"), sizeof(long), 'l', 0); add_base_type(DB_TEXT("float"), sizeof(float), 'f', 0); add_base_type(DB_TEXT("double"), sizeof(double), 'F', 0); add_base_type(DB_TEXT("unsigned char"), sizeof(char), 'c', 1); add_base_type(DB_TEXT("unsigned short"), sizeof(short), 's', 1); add_base_type(DB_TEXT("unsigned long"), sizeof(long), 'l', 1); add_base_type(DB_TEXT("int"), sizeof(int), 'i', 0); add_base_type(DB_TEXT("unsigned int"), sizeof(int), 'i', 1);}/* Add a structure to the type list*/int add_struct_type(DB_TCHAR *name){ TYPE_INFO *p = type_list; while (p) { if (vtstrcmp(p->type_name, name) == 0) return (0); p = p->next_type; } if ((p = (TYPE_INFO *) psp_cGetMemory(sizeof(TYPE_INFO), 0)) == NULL) { ddlp_abort(DB_TEXT("out of memory")); return (0); } if (type_last == NULL) type_list = p; else type_last->next_type = p; type_last = p; p->next_type = NULL; vtstrcpy(p->type_name, name); p->elem = ddlp_g.elem_list; ddlp_g.elem_list = NULL; ddlp_g.elem_last = NULL; return(1);}/* Add a type to the type list **********************************************/static int add_base_type(DB_TCHAR *name, short size, char ch, int sign){ TYPE_INFO *p = type_list; int dim; while (p) { if (vtstrcmp(p->type_name, name) == 0) return (0); p = p->next_type; } if ((p = (TYPE_INFO *) psp_cGetMemory(sizeof(TYPE_INFO), 0)) == NULL) { ddlp_abort(DB_TEXT("out of memory")); return (0); } if (type_last == NULL) type_list = p; else type_last->next_type = p; type_last = p; p->next_type = NULL; vtstrcpy(p->type_name, name); for (dim = 0; dim < MAXDIMS; dim++) p->dims[dim] = 0; p->type_size = size; p->type_char = ch; p->type_sign = sign; p->elem = NULL; return (1);}/* Add a type to the type list **********************************************/int add_type(DB_TCHAR *name, TYPE_INFO *ti){ TYPE_INFO *p = type_list; int dim, tot_dims; while (p) { if (vtstrcmp(p->type_name, name) == 0) return (0); p = p->next_type; } if ((p = (TYPE_INFO *) psp_cGetMemory(sizeof(TYPE_INFO), 0)) == NULL) { ddlp_abort(DB_TEXT("out of memory")); return (0); } if (type_last == NULL) type_list = p; else type_last->next_type = p; type_last = p; p->next_type = NULL; vtstrcpy(p->type_name, name); memset(p->dims, 0, MAXDIMS * sizeof(short)); for (tot_dims = 0; (tot_dims < MAXDIMS) && ti->dims[tot_dims]; tot_dims++) p->dims[tot_dims] = ti->dims[tot_dims]; for (dim = 0; (dim < MAXDIMS) && ddlp_g.fd_entry.fd_dim[dim]; dim++, tot_dims++) { if (tot_dims >= MAXDIMS) { vstprintf(ddlp_g.msg, DB_TEXT("too many array dimensions, maximum is %d"), MAXDIMS); dderror(ddlp_g.msg, ddlp_g.line); break; } p->dims[tot_dims] = ddlp_g.fd_entry.fd_dim[dim]; } if (ti->elem) { p->elem = ti->elem; p->elem->use_count++; } else { p->type_size = ti->type_size; p->type_char = ti->type_char; p->type_sign = ti->type_sign; } return (1);}/* Find a constant in the constant list */TYPE_INFO *find_type(DB_TCHAR *name, int sign){ TYPE_INFO *p = type_list; DB_TCHAR tempbuff[NAMELEN + 10]; tempbuff[0] = 0; if (sign) vtstrcpy(tempbuff, DB_TEXT("unsigned ")); vtstrcat(tempbuff, name); if (vtstrcmp(DB_TEXT("db_addr"), tempbuff) == 0) { return(type_list); } else { while (p) { if (vtstrcmp(p->type_name, tempbuff) == 0) return (p); p = p->next_type; } return (NULL); }}void del_type(DB_TCHAR *name){ TYPE_INFO *p = type_list, *q = NULL; while (p && (vtstrcmp(p->type_name, name) != 0)) { q = p; p = p->next_type; } if (p) { if (q) { q->next_type = p->next_type; if (q->next_type == NULL) type_last = q; } else { type_list = p->next_type; if (type_list == NULL) type_last = NULL; } if (p->elem->use_count-- == 0) free_elems(p->elem); psp_freeMemory(p, 0); }}/* Add a constant to the constant list */int add_const(DB_TCHAR *name, short value){ CONST_INFO *p = const_list; while (p) { if (vtstrcmp(p->const_name, name) == 0) { p->value = value; return (0); } p = p->next_const; } if ((p = (CONST_INFO *) psp_cGetMemory(sizeof(CONST_INFO), 0)) == NULL) { ddlp_abort(DB_TEXT("out of memory")); return (0); } if (const_last == NULL) const_list = p; else const_last->next_const = p; const_last = p; p->next_const = NULL; vtstrcpy(p->const_name, name); p->value = value; return (1);}/* Find a constant in the constant list */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?