1 /*** database.h *************************************************************** 2 ** 3 ** This file is part of BibTool. 4 ** It is distributed under the GNU General Public License. 5 ** See the file COPYING for details. 6 ** 7 ** (c) 1996-2020 Gerd Neugebauer 8 ** 9 ** Net: gene@gerd-neugebauer.de 10 ** 11 ** This program is free software; you can redistribute it and/or modify 12 ** it under the terms of the GNU General Public License as published by 13 ** the Free Software Foundation; either version 2, or (at your option) 14 ** any later version. 15 ** 16 ** This program is distributed in the hope that it will be useful, 17 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 18 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 ** GNU General Public License for more details. 20 ** 21 ** You should have received a copy of the GNU General Public License 22 ** along with this program; if not, write to the Free Software 23 ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 24 ** 25 **----------------------------------------------------------------------------- 26 ** Description: 27 ** This header file contains functions which deal with databases. 28 ** 29 ** This header file provides also access to the functions and 30 ** variables defined in |database.c|. Consult the documentation 31 ** of this file for details. 32 ** 33 ** This header file automatically includes |<stdio.h>| and 34 ** |record.h| aswell. 35 ** 36 ******************************************************************************/ 37 38 #ifndef DATABASE_H 39 #define DATABASE_H 40 41 #include <stdio.h> 42 #include <bibtool/record.h> 43 44 /*----------------------------------------------------------------------------- 45 ** Typedef: DB 46 ** Purpose: This is a pointer type referencing a \BibTeX{} 47 ** database. It contains all information which 48 ** characterizes a database. 49 ** 50 ** The members of this record should not be used 51 ** explicitly. Instead the macros should be used which 52 ** are provided to accss this data type. 53 ** 54 **___________________________________________________ */ 55 typedef struct /* */ 56 { Record db_normal; /* List of normal records.*/ 57 Record db_string; /* List of local macros. */ 58 Record db_preamble; /* List of additional */ 59 /* \TeX{} code. */ 60 Record db_comment; /* List of trailing */ 61 /* comments which are */ 62 /* not attached to */ 63 /* records. */ 64 Record db_modify; /* List of modification */ 65 /* rules. */ 66 Record db_include; /* List of included files.*/ 67 Record db_alias; /* List of aliases. */ 68 } sDB, *DB; /* */ 69 70 /*----------------------------------------------------------------------------- 71 ** Constant: NoDB() 72 ** Type: DB 73 ** Purpose: This is an invalid database. In fact it is |NULL| of 74 ** the type |DB|. 75 **___________________________________________________ */ 76 #define NoDB ((DB)0) 77 78 /*----------------------------------------------------------------------------- 79 ** Macro: DBnormal() 80 ** Type: Record 81 ** Purpose: This is the functional representation of the normal 82 ** component of a database. It can be used to extract 83 ** this information. It can also be used as a lvalue. 84 ** Arguments: 85 ** DB The database to consider. 86 **___________________________________________________ */ 87 #define DBnormal(DB) ((DB)->db_normal) 88 89 /*----------------------------------------------------------------------------- 90 ** Macro: DBstring() 91 ** Type: Record 92 ** Purpose: This is the functional representation of the string 93 ** component of a database. It can be used to extract 94 ** this information. It can also be used as a lvalue. 95 ** Arguments: 96 ** DB The database to consider. 97 **___________________________________________________ */ 98 #define DBstring(DB) ((DB)->db_string) 99 100 /*----------------------------------------------------------------------------- 101 ** Macro: DBpreamble() 102 ** Type: Record 103 ** Purpose: This is the functional representation of the preamble 104 ** component of a database. It can be used to extract 105 ** this information. It can also be used as a lvalue. 106 ** Arguments: 107 ** DB The database to consider. 108 **___________________________________________________ */ 109 #define DBpreamble(DB) ((DB)->db_preamble) 110 111 /*----------------------------------------------------------------------------- 112 ** Macro: DBcomment() 113 ** Type: Record 114 ** Purpose: This is the functional representation of the comment 115 ** component of a database. It can be used to extract 116 ** this information. It can also be used as a lvalue. 117 ** Arguments: 118 ** DB The database to consider. 119 **___________________________________________________ */ 120 #define DBcomment(DB) ((DB)->db_comment) 121 122 /*----------------------------------------------------------------------------- 123 ** Macro: DBalias() 124 ** Type: Record 125 ** Purpose: This is the functional representation of the alias 126 ** component of a database. It can be used to extract 127 ** this information. It can also be used as a lvalue. 128 ** Arguments: 129 ** DB The database to consider. 130 **___________________________________________________ */ 131 #define DBalias(DB) ((DB)->db_alias) 132 133 /*----------------------------------------------------------------------------- 134 ** Macro: DBmodify() 135 ** Type: Record 136 ** Purpose: This is the functional representation of the modify 137 ** component of a database. It can be used to extract 138 ** this information. It can also be used as a lvalue. 139 ** Arguments: 140 ** DB The database to consider. 141 **___________________________________________________ */ 142 #define DBmodify(DB) ((DB)->db_modify) 143 144 /*----------------------------------------------------------------------------- 145 ** Macro: DBinclude() 146 ** Type: Record 147 ** Purpose: This is the functional representation of the include 148 ** component of a database. It can be used to extract 149 ** this information. It can also be used as a lvalue. 150 ** Arguments: 151 ** DB The database to consider. 152 **___________________________________________________ */ 153 #define DBinclude(DB) ((DB)->db_include) 154 155 /*---------------------------------------------------------------------------*/ 156 157 #ifdef __STDC__ 158 #define _ARG(A) A 159 #else 160 #define _ARG(A) () 161 #endif 162 DB new_db _ARG((void)); /* */ 163 Record db_find _ARG((DB db, Symbol key)); /* */ 164 Record db_search _ARG((DB db, Symbol key)); /* */ 165 Symbol db_new_key _ARG((DB db, Symbol key)); /* */ 166 Symbol db_string _ARG((DB db, Symbol sym, bool localp));/* */ 167 bool read_db _ARG((DB db,String file, bool verbose));/* */ 168 int *db_count _ARG((DB db, int *lp)); /* */ 169 void db_insert _ARG((DB db,Record rec, bool verbose));/* */ 170 void db_forall _ARG((DB db,bool (*fct)_ARG((DB, Record))));/* */ 171 void db_mac_sort _ARG((DB db)); /* */ 172 void db_rewind _ARG((DB db)); /* */ 173 void db_sort _ARG((DB db,int (*less)_ARG((Record, Record))));/* */ 174 void db_xref_undelete _ARG((DB db)); /* */ 175 void delete_record _ARG((DB db, Record rec)); /* */ 176 void free_db _ARG((DB db)); /* */ 177 void print_db _ARG((FILE *file, DB db, char *spec));/* */ 178 179 /*---------------------------------------------------------------------------*/ 180 181 #endif 182