1 /* src/btparse.h. Generated by configure. */ 2 /* ------------------------------------------------------------------------ 3 @NAME : btparse.h 4 @DESCRIPTION: Declarations and types for users of the btparse library. 5 6 (Actually, btparse.h is generated from btparse.h.in by 7 the `configure' script, in order to automatically determine 8 the appropriate values of HAVE_USHORT and HAVE_BOOLEAN.) 9 @GLOBALS : 10 @CALLS : 11 @CREATED : 1997/01/19, Greg Ward 12 @MODIFIED : 13 @VERSION : $Id: btparse.h.in 753 2005-07-23 20:13:48Z alberto $ 14 @COPYRIGHT : Copyright (c) 1996-97 by Gregory P. Ward. All rights reserved. 15 16 This file is part of the btparse library. This library is 17 free software; you can redistribute it and/or modify it under 18 the terms of the GNU Library General Public License as 19 published by the Free Software Foundation; either version 2 20 of the License, or (at your option) any later version. 21 -------------------------------------------------------------------------- */ 22 #ifndef BTPARSE_H 23 #define BTPARSE_H 24 25 #include <sys/types.h> /* probably supplies 'ushort' */ 26 #include <stdio.h> 27 28 /* 29 * Here we attempt to define HAVE_USHORT if a typdef for `ushort' appears 30 * in <sys/types.h>. The detective work is actually done by the 31 * `configure' script, so if compilation fails because of duplicate 32 * definitions of `ushort', that's a bug in `configure' -- please tell me 33 * about it! 34 */ 35 36 #define HAVE_USHORT_XSUB 0 37 38 #if defined(H_PERL) && HAVE_USHORT_XSUB 39 # ifndef HAVE_USHORT 40 # define HAVE_USHORT 1 41 # endif 42 #endif 43 44 #ifndef HAVE_USHORT 45 # define HAVE_USHORT 1 46 #endif 47 48 #if ! HAVE_USHORT /* needed for various bitmaps */ 49 typedef unsigned short ushort; 50 #endif 51 52 53 /* Likewise for boolean. */ 54 55 #ifndef HAVE_BOOLEAN 56 # define HAVE_BOOLEAN 0 57 #endif 58 59 #if ! HAVE_BOOLEAN 60 typedef int boolean; 61 #endif 62 63 #ifndef TRUE 64 # define TRUE 1 65 # define FALSE 0 66 #endif 67 68 /* Parsing (and post-processing) options */ 69 70 #define BTO_CONVERT 1 /* convert numbers to strings? */ 71 #define BTO_EXPAND 2 /* expand macros? */ 72 #define BTO_PASTE 4 /* paste substrings together? */ 73 #define BTO_COLLAPSE 8 /* collapse whitespace? */ 74 75 #define BTO_NOSTORE 16 76 77 #define BTO_FULL (BTO_CONVERT | BTO_EXPAND | BTO_PASTE | BTO_COLLAPSE) 78 #define BTO_MACRO (BTO_CONVERT | BTO_EXPAND | BTO_PASTE) 79 #define BTO_MINIMAL 0 80 81 #define BTO_STRINGMASK (BTO_CONVERT | BTO_EXPAND | BTO_PASTE | BTO_COLLAPSE) 82 83 #define BT_VALID_NAMEPARTS "fvlj" 84 #define BT_MAX_NAMEPARTS 4 85 86 typedef enum 87 { 88 BTE_UNKNOWN, 89 BTE_REGULAR, 90 BTE_COMMENT, 91 BTE_PREAMBLE, 92 BTE_MACRODEF 93 /* 94 BTE_ALIAS, 95 BTE_MODIFY 96 */ 97 } bt_metatype; 98 99 #define NUM_METATYPES ((int) BTE_MACRODEF + 1) 100 101 typedef enum 102 { 103 BTAST_BOGUS, /* to detect uninitialized nodes */ 104 BTAST_ENTRY, 105 BTAST_KEY, 106 BTAST_FIELD, 107 BTAST_STRING, 108 BTAST_NUMBER, 109 BTAST_MACRO 110 } bt_nodetype; 111 112 typedef enum 113 { 114 BTN_FIRST, BTN_VON, BTN_LAST, BTN_JR, BTN_NONE 115 } bt_namepart; 116 117 typedef enum 118 { 119 BTJ_MAYTIE, /* "discretionary" tie between words */ 120 BTJ_SPACE, /* force a space between words */ 121 BTJ_FORCETIE, /* force a tie (~ in TeX) */ 122 BTJ_NOTHING /* nothing between words */ 123 } bt_joinmethod; 124 125 126 #define USER_DEFINED_AST 1 127 128 #define zzcr_ast(ast,attr,tok,txt) \ 129 { \ 130 (ast)->filename = InputFilename; \ 131 (ast)->line = (attr)->line; \ 132 (ast)->offset = (attr)->offset; \ 133 (ast)->text = strdup ((attr)->text); \ 134 } 135 136 #define zzd_ast(ast) \ 137 /* printf ("zzd_ast: free'ing ast node with string %p (%s)\n", \ 138 (ast)->text, (ast)->text); */ \ 139 if ((ast)->text != NULL) free ((ast)->text); 140 141 142 #ifdef USER_DEFINED_AST 143 typedef struct _ast 144 { 145 struct _ast *right, *down; 146 char * filename; 147 int line; 148 int offset; 149 bt_nodetype nodetype; 150 bt_metatype metatype; 151 char * text; 152 } AST; 153 #endif /* USER_DEFINED_AST */ 154 155 156 typedef struct 157 { 158 /* 159 * `string' is the string that has been split; items[0] ... 160 * items[num_items-1] are pointers into `string', or NULL for empty 161 * substrings. Note that `string' is actually a copy of the string 162 * passed in to bt_split_list() with NULs inserted between substrings. 163 */ 164 165 char * string; 166 int num_items; 167 char ** items; 168 } bt_stringlist; 169 170 171 typedef struct 172 { 173 bt_stringlist * tokens; /* flat list of all tokens in name */ 174 char ** parts[BT_MAX_NAMEPARTS]; /* each elt. is list of pointers */ 175 /* into `tokens->string' */ 176 int part_len[BT_MAX_NAMEPARTS]; /* length in tokens */ 177 } bt_name; 178 179 180 typedef struct tex_tree_s 181 { 182 char * start; 183 int len; 184 struct tex_tree_s 185 * child, 186 * next; 187 } bt_tex_tree; 188 189 190 typedef struct 191 { 192 /* These determine the order (and presence) of parts in the name. */ 193 int num_parts; 194 bt_namepart parts[BT_MAX_NAMEPARTS]; 195 196 /* 197 * These lists are always in the order of the bt_namepart enum -- *not* 198 * dependent on the particular order of parts the user specified! (This 199 * will make it a bit harder if I ever allow more than one occurrence of 200 * a part in a format; since I don't allow that, I'm not [yet] worried 201 * about it!) 202 */ 203 char * pre_part[BT_MAX_NAMEPARTS]; 204 char * post_part[BT_MAX_NAMEPARTS]; 205 char * pre_token[BT_MAX_NAMEPARTS]; 206 char * post_token[BT_MAX_NAMEPARTS]; 207 boolean abbrev[BT_MAX_NAMEPARTS]; 208 bt_joinmethod join_tokens[BT_MAX_NAMEPARTS]; 209 bt_joinmethod join_part[BT_MAX_NAMEPARTS]; 210 } bt_name_format; 211 212 213 typedef enum 214 { 215 BTERR_NOTIFY, /* notification about next action */ 216 BTERR_CONTENT, /* warning about the content of a record */ 217 BTERR_LEXWARN, /* warning in lexical analysis */ 218 BTERR_USAGEWARN, /* warning about library usage */ 219 BTERR_LEXERR, /* error in lexical analysis */ 220 BTERR_SYNTAX, /* error in parser */ 221 BTERR_USAGEERR, /* fatal error in library usage */ 222 BTERR_INTERNAL /* my fault */ 223 } bt_errclass; 224 225 typedef enum 226 { 227 BTACT_NONE, /* do nothing on error */ 228 BTACT_CRASH, /* call exit(1) */ 229 BTACT_ABORT /* call abort() */ 230 } bt_erraction; 231 232 typedef struct 233 { 234 bt_errclass class; 235 char * filename; 236 int line; 237 char * item_desc; 238 int item; 239 char * message; 240 } bt_error; 241 242 typedef void (*bt_err_handler) (bt_error *); 243 244 245 #if defined(__cplusplus__) || defined(__cplusplus) || defined(c_plusplus) 246 extern "C" { 247 #endif 248 249 /* Function prototypes */ 250 251 /* 252 * First, we might need a prototype for strdup() (because the zzcr_ast 253 * macro uses it, and that macro is used in pccts/ast.c -- which I don't 254 * want to modify if I can help it, because it's someone else's code). 255 * This is to accomodate AIX, where including <string.h> apparently doesn't 256 * declare strdup() (reported by Reiner Schlotte 257 * <schlotte@geo.palmod.uni-bremen.de>), and compiling bibtex.c (which 258 * includes pccts/ast.c) crashes because of this (yes, yes, I know it 259 * should just be a warning -- I don't know what's going on there!). 260 * 261 * Unfortunately, this duplicates code in bt_config.h -- I can't include 262 * bt_config.h here, because this header must be freestanding; I don't want 263 * to include bt_config.h in pccts/ast.c, because I don't want to touch the 264 * PCCTS code if I can help it; but I don't want every source file that 265 * uses strdup() to have to include btparse.h. Hence the duplication. 266 * Yuck. 267 */ 268 #define HAVE_STRDUP_DECL 1 269 #if !HAVE_STRDUP_DECL 270 extern char *strdup (const char *s); 271 #endif 272 273 274 /* init.c */ 275 void bt_initialize (void); 276 void bt_free_ast (AST *ast); 277 void bt_cleanup (void); 278 279 /* input.c */ 280 void bt_set_stringopts (bt_metatype metatype, ushort options); 281 AST * bt_parse_entry_s (char * entry_text, 282 char * filename, 283 int line, 284 ushort options, 285 boolean * status); 286 AST * bt_parse_entry (FILE * infile, 287 char * filename, 288 ushort options, 289 boolean * status); 290 AST * bt_parse_file (char * filename, 291 ushort options, 292 boolean * overall_status); 293 294 /* post_parse.c */ 295 void bt_postprocess_string (char * s, ushort options); 296 char * bt_postprocess_value (AST * value, ushort options, boolean replace); 297 char * bt_postprocess_field (AST * field, ushort options, boolean replace); 298 void bt_postprocess_entry (AST * entry, ushort options); 299 300 /* error.c */ 301 void bt_reset_error_counts (void); 302 int bt_get_error_count (bt_errclass errclass); 303 int * bt_get_error_counts (int *counts); 304 ushort bt_error_status (int *saved_counts); 305 306 /* macros.c */ 307 void bt_add_macro_value (AST *assignment, ushort options); 308 void bt_add_macro_text (char * macro, char * text, char * filename, int line); 309 void bt_delete_macro (char * macro); 310 void bt_delete_all_macros (void); 311 int bt_macro_length (char *macro); 312 char * bt_macro_text (char * macro, char * filename, int line); 313 314 /* traversal.c */ 315 AST *bt_next_entry (AST *entry_list, AST *prev_entry); 316 bt_metatype bt_entry_metatype (AST *entry); 317 char *bt_entry_type (AST *entry); 318 char *bt_entry_key (AST *entry); 319 AST *bt_next_field (AST *entry, AST *prev, char **name); 320 AST *bt_next_macro (AST *entry, AST *prev, char **name); 321 AST *bt_next_value (AST *head, 322 AST *prev, 323 bt_nodetype *nodetype, 324 char **text); 325 char *bt_get_text (AST *node); 326 327 /* modify.c */ 328 void bt_set_text (AST * node, char * new_text); 329 void bt_entry_set_key (AST * entry, char * new_key); 330 331 /* names.c */ 332 bt_stringlist * bt_split_list (char * string, 333 char * delim, 334 char * filename, 335 int line, 336 char * description); 337 void bt_free_list (bt_stringlist *list); 338 bt_name * bt_split_name (char * name, 339 char * filename, 340 int line, 341 int name_num); 342 void bt_free_name (bt_name * name); 343 344 /* tex_tree.c */ 345 bt_tex_tree * bt_build_tex_tree (char * string); 346 void bt_free_tex_tree (bt_tex_tree **top); 347 void bt_dump_tex_tree (bt_tex_tree *node, int depth, FILE *stream); 348 char * bt_flatten_tex_tree (bt_tex_tree *top); 349 350 /* string_util.c */ 351 void bt_purify_string (char * string, ushort options); 352 void bt_change_case (char transform, char * string, ushort options); 353 354 /* format_name.c */ 355 bt_name_format * bt_create_name_format (char * parts, boolean abbrev_first); 356 void bt_free_name_format (bt_name_format * format); 357 void bt_set_format_text (bt_name_format * format, 358 bt_namepart part, 359 char * pre_part, 360 char * post_part, 361 char * pre_token, 362 char * post_token); 363 void bt_set_format_options (bt_name_format * format, 364 bt_namepart part, 365 boolean abbrev, 366 bt_joinmethod join_tokens, 367 bt_joinmethod join_part); 368 char * bt_format_name (bt_name * name, bt_name_format * format); 369 370 #if defined(__cplusplus__) || defined(__cplusplus) || defined(c_plusplus) 371 } 372 #endif 373 374 #endif /* BTPARSE_H */ 375