dtd.c
来自「db.* (pronounced dee-be star) is an adva」· C语言 代码 · 共 356 行
C
356 行
/*************************************************************************** * * * 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. * * * **************************************************************************//*----------------------------------------------------------------------- dtd.c - XML validation Produces an XML DTD for a database.-----------------------------------------------------------------------*/#include "db.star.h"#define ELEMENT 0#define ATTLIST 1#define CLASSIC_FIELD 0x0#define STRUCTURE 0x1#define ARRAY 0x2static int print_decl_beg (int type, FILE *df);static DB_BOOLEAN field_is_array (char fieldType, short dimensions[]);int xml_print_dtd (FILE *df, DB_TASK *task){ int i, status, set_ndx, mem_ndx, rec_ndx, fld_ndx, aux_fld_ndx, last_mem_ndx, last_field_ndx; DB_TCHAR *name; DB_BOOLEAN firstToSave; /* print db description */ if (status = print_decl_beg(ELEMENT, df)) return status; name = (DB_TCHAR *) psp_cGetMemory( (vtstrlen(task->curr_db_table->db_name) + 1) * sizeof(DB_TCHAR), 0); vtstrupr(vtstrcpy(name, task->curr_db_table->db_name)); status = vftprintf(df, DB_TEXT("%s ("), name); psp_freeMemory(name, 0); if (0 == status) return S_NOSPACE; for (set_ndx = 0; set_ndx < task->size_st; set_ndx++) /* print all sets owned by system */ { if (task->record_table[task->set_table[set_ndx].st_own_rt].rt_fdtot == -1) { if (0 == vftprintf(df, DB_TEXT("%s?,"), task->set_names[set_ndx])) return S_NOSPACE; } } if (vfputtc(DB_TEXT('('), df) != DB_TEXT('(')) return S_NOSPACE; firstToSave = TRUE; for (rec_ndx = 0; rec_ndx < task->size_rt; rec_ndx++) /* print all record names, except system record */ { if (task->record_table[rec_ndx].rt_fdtot == -1) { continue; } else { if (TRUE == firstToSave) { firstToSave = FALSE; } else { if (vfputtc(DB_TEXT('|'), df) != DB_TEXT('|')) return S_NOSPACE; } if (0 == vftprintf(df, DB_TEXT("%s"), task->record_names[rec_ndx])) return S_NOSPACE; } } if (0 == vftprintf(df, DB_TEXT(")*)>\n"))) return S_NOSPACE; /* print record description */ for (rec_ndx = 0; rec_ndx < task->size_rt; rec_ndx++) /* iterate over all records, except system record */ { if (task->record_table[rec_ndx].rt_fdtot == -1) { continue; } else { if (status = print_decl_beg(ELEMENT, df)) // print: "<!ELEMENT " return status; /* print the name of this record */ if (0 == vftprintf(df, DB_TEXT("%s ("), task->record_names[rec_ndx])) return S_NOSPACE; firstToSave = TRUE; for (set_ndx = 0; set_ndx < task->size_st; set_ndx++) /* print all sets owned by this record */ { if (task->set_table[set_ndx].st_own_rt == rec_ndx) { if (TRUE == firstToSave) { firstToSave = FALSE; } else { if (vfputtc(DB_TEXT(','), df) != DB_TEXT(',')) return S_NOSPACE; } if (0 == vftprintf(df, DB_TEXT("%s?"), task->set_names[set_ndx])) return S_NOSPACE; } } /* iterate over record's fields */ for ( fld_ndx = task->record_table[rec_ndx].rt_fields; fld_ndx < task->record_table[rec_ndx].rt_fields + task->record_table[rec_ndx].rt_fdtot; fld_ndx++) { if (STRUCTFLD == task->field_table[fld_ndx].fd_flags) continue; if (TRUE == firstToSave) { firstToSave = FALSE; } else { if (vfputtc(DB_TEXT(','), df) != DB_TEXT(',')) return S_NOSPACE; } if (0 == vftprintf(df, DB_TEXT("%s"), task->field_names[fld_ndx])) return S_NOSPACE; if (TRUE == field_is_array (task->field_table[fld_ndx].fd_type, task->field_table[fld_ndx].fd_dim)) { if (vfputtc(DB_TEXT('+'), df) != DB_TEXT('+')) return S_NOSPACE; } } if (0 == vftprintf(df, DB_TEXT(")?>\n"))) return S_NOSPACE; } } /* print id and idref attributes for each record */ for (rec_ndx = 0; rec_ndx < task->size_rt; rec_ndx++) /* iterate over all records, except system record */ { if (task->record_table[rec_ndx].rt_fdtot == -1) { continue; } else { /* print id attribute */ if (status = print_decl_beg(ATTLIST, df)) // print: "<!ATTLIST " return status; if (0 == vftprintf(df, DB_TEXT("%s id ID #IMPLIED>\n"), task->record_names[rec_ndx])) return S_NOSPACE; /* print idref attribute */ if (status = print_decl_beg(ATTLIST, df)) // print: "<!ATTLIST " return status; if (0 == vftprintf(df, DB_TEXT("%s idref IDREF #IMPLIED>\n"), task->record_names[rec_ndx])) return S_NOSPACE; } } for (set_ndx = 0; set_ndx < task->size_st; set_ndx++) /* print element for each set */ { if (status = print_decl_beg(ELEMENT, df)) // print: "<!ELEMENT " return status; if (0 == vftprintf(df, DB_TEXT("%s ("), task->set_names[set_ndx])) return S_NOSPACE; /* list members */ last_mem_ndx = task->set_table[set_ndx].st_members + task->set_table[set_ndx].st_memtot; /* iterate over set's members */ firstToSave = TRUE; for ( mem_ndx = task->set_table[set_ndx].st_members; mem_ndx < last_mem_ndx; mem_ndx++) { if (TRUE == firstToSave) { firstToSave = FALSE; } else { if (vfputtc(DB_TEXT(','), df) != DB_TEXT(',')) return S_NOSPACE; } if (0 == vftprintf(df, DB_TEXT("%s"), task->record_names[task->member_table[mem_ndx].mt_record])) return S_NOSPACE; } if (0 == vftprintf(df, DB_TEXT(")*>\n"))) return S_NOSPACE; } for (rec_ndx = 0; rec_ndx < task->size_rt; rec_ndx++) /* iterate over all records, except system record */ { if (task->record_table[rec_ndx].rt_fdtot == -1) { continue; } else { last_field_ndx = task->record_table[rec_ndx].rt_fields + task->record_table[rec_ndx].rt_fdtot; /* iterate over record's fields */ for ( fld_ndx = task->record_table[rec_ndx].rt_fields; fld_ndx < last_field_ndx; fld_ndx++) { /* print element for field */ if (status = print_decl_beg(ELEMENT, df)) // print: "<!ELEMENT " return status; if (GROUPED == task->field_table[fld_ndx].fd_type) { if (0 == vftprintf(df, DB_TEXT("%s ("), task->field_names[fld_ndx])) return S_NOSPACE; firstToSave = TRUE; aux_fld_ndx = fld_ndx+1; while ( (aux_fld_ndx<last_field_ndx) && (task->field_table[aux_fld_ndx].fd_flags & STRUCTFLD)) { if (TRUE == firstToSave) { firstToSave = FALSE; } else { if (vfputtc(DB_TEXT(','), df) != DB_TEXT(',')) return S_NOSPACE; } if (0 == vftprintf(df, DB_TEXT("%s"), task->field_names[aux_fld_ndx])) return S_NOSPACE; aux_fld_ndx++; } if (0 == vftprintf(df, DB_TEXT(")>\n"))) return S_NOSPACE; } else { if (0 == vftprintf(df, DB_TEXT("%s (#PCDATA)>\n"), task->field_names[fld_ndx])) return S_NOSPACE; } /* print an idref attribute for DBADDR fields */ if (task->field_table[fld_ndx].fd_type == DBADDR) { if (status = print_decl_beg(ATTLIST, df)) // print: "<!ELEMENT " return status; if (0 == vftprintf(df, DB_TEXT("%s idref IDREF #IMPLIED>\n"), task->field_names[fld_ndx])) return S_NOSPACE; } } } } return S_OKAY;}/***************************************************************************/DB_BOOLEAN field_is_array (char fieldType, short dimensions[]){ short dims; /* determine if there is an array */ for (dims = 0; dims < MAXDIMS && dimensions[dims]; dims++) ; if (0 < dims) { if (((CHARACTER==fieldType) || (WIDECHAR==fieldType)) && (1==dims)) dims=0; /* string */ if (dims>0) return TRUE; } return FALSE;}/***************************************************************************/static int print_decl_beg (int type, FILE *df){ if (ELEMENT == type) { if (vftprintf(df, DB_TEXT("<!ELEMENT ")) == 0) return S_NOSPACE; } else { if (vftprintf(df, DB_TEXT("<!ATTLIST ")) == 0) return S_NOSPACE; } return S_OKAY;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?