File indexing completed on 2025-01-26 04:43:59

0001 /* ------------------------------------------------------------------------
0002 @NAME       : btparse.h
0003 @DESCRIPTION: Declarations and types for users of the btparse library.
0004 
0005               (Actually, btparse.h is generated from btparse.h.in by
0006               the `configure' script, in order to automatically determine
0007               the appropriate values of HAVE_USHORT and HAVE_BOOLEAN.)
0008 @GLOBALS    :
0009 @CALLS      :
0010 @CREATED    : 1997/01/19, Greg Ward
0011 @MODIFIED   :
0012 @VERSION    : $Id: btparse.h.in,v 1.35 1999/12/28 18:23:17 greg Exp $
0013 @COPYRIGHT  : Copyright (c) 1996-97 by Gregory P. Ward.  All rights reserved.
0014 
0015               This file is part of the btparse library.  This library is
0016               free software; you can redistribute it and/or modify it under
0017               the terms of the GNU General Public License as
0018               published by the Free Software Foundation; either version 2
0019               of the License, or (at your option) any later version.
0020 -------------------------------------------------------------------------- */
0021 #ifndef BTPARSE_H
0022 #define BTPARSE_H
0023 
0024 #include <sys/types.h>                  /* probably supplies 'ushort' */
0025 #include <stdio.h>
0026 
0027 #include "config.h" /* not btparse's config.h but Tellico's */
0028 
0029 /*
0030  * Here we attempt to define HAVE_USHORT if a typdef for `ushort' appears
0031  * in <sys/types.h>.  The detective work is actually done by the
0032  * `configure' script, so if compilation fails because of duplicate
0033  * definitions of `ushort', that's a bug in `configure' -- please tell me
0034  * about it!
0035  */
0036 
0037 #ifndef HAVE_USHORT
0038 # define HAVE_USHORT 0
0039 #endif
0040 
0041 #if ! HAVE_USHORT                       /* needed for various bitmaps */
0042 typedef unsigned short ushort;
0043 #endif
0044 
0045 
0046 /* Likewise for boolean. */
0047 
0048 #ifndef HAVE_BOOLEAN
0049 # define HAVE_BOOLEAN 0
0050 #endif
0051 
0052 #if ! HAVE_BOOLEAN
0053 typedef int boolean;
0054 #endif
0055 
0056 #ifndef TRUE
0057 # define TRUE 1
0058 # define FALSE 0
0059 #endif
0060 
0061 #ifndef HAVE_STRLWR
0062 # define HAVE_STRLWR 0
0063 #endif
0064 
0065 #ifndef HAVE_STRUPR
0066 # define HAVE_STRUPR 0
0067 #endif
0068 
0069 
0070 /* Parsing (and post-processing) options */
0071 
0072 #define BTO_CONVERT   1                 /* convert numbers to strings? */
0073 #define BTO_EXPAND    2                 /* expand macros? */
0074 #define BTO_PASTE     4                 /* paste substrings together? */
0075 #define BTO_COLLAPSE  8                 /* collapse whitespace? */
0076 
0077 #define BTO_NOSTORE   16
0078 
0079 #define BTO_FULL (BTO_CONVERT | BTO_EXPAND | BTO_PASTE | BTO_COLLAPSE)
0080 #define BTO_MACRO (BTO_CONVERT | BTO_EXPAND | BTO_PASTE)
0081 #define BTO_MINIMAL 0
0082 
0083 #define BTO_STRINGMASK (BTO_CONVERT | BTO_EXPAND | BTO_PASTE | BTO_COLLAPSE)
0084 
0085 #define BT_VALID_NAMEPARTS "fvlj"
0086 #define BT_MAX_NAMEPARTS 4
0087 
0088 typedef enum
0089 {
0090    BTE_UNKNOWN,
0091    BTE_REGULAR,
0092    BTE_COMMENT,
0093    BTE_PREAMBLE,
0094    BTE_MACRODEF
0095 /*
0096    BTE_ALIAS,
0097    BTE_MODIFY
0098 */
0099 } bt_metatype;
0100 
0101 #define NUM_METATYPES ((int) BTE_MACRODEF + 1)
0102 
0103 typedef enum
0104 {
0105    BTAST_BOGUS,                           /* to detect uninitialized nodes */
0106    BTAST_ENTRY,
0107    BTAST_KEY,
0108    BTAST_FIELD,
0109    BTAST_STRING,
0110    BTAST_NUMBER,
0111    BTAST_MACRO
0112 } bt_nodetype;
0113 
0114 typedef enum
0115 {
0116    BTN_FIRST, BTN_VON, BTN_LAST, BTN_JR, BTN_NONE
0117 } bt_namepart;
0118 
0119 typedef enum
0120 {
0121    BTJ_MAYTIE,                          /* "discretionary" tie between words */
0122    BTJ_SPACE,                           /* force a space between words */
0123    BTJ_FORCETIE,                        /* force a tie (~ in TeX) */
0124    BTJ_NOTHING                          /* nothing between words */
0125 } bt_joinmethod;
0126 
0127 
0128 #define USER_DEFINED_AST 1
0129 
0130 #define zzcr_ast(ast,attr,tok,txt)              \
0131 {                                               \
0132    (ast)->filename = InputFilename;             \
0133    (ast)->line = (attr)->line;                  \
0134    (ast)->offset = (attr)->offset;              \
0135    (ast)->text = strdup ((attr)->text);         \
0136 }
0137 
0138 #define zzd_ast(ast)                            \
0139 /* printf ("zzd_ast: free'ing ast node with string %p (%s)\n", \
0140            (ast)->text, (ast)->text); */ \
0141    if ((ast)->text != NULL) free ((ast)->text);
0142 
0143 
0144 #ifdef USER_DEFINED_AST
0145 typedef struct _ast
0146 {
0147    struct _ast *right, *down;
0148    const char *     filename;
0149    int              line;
0150    int              offset;
0151    bt_nodetype    nodetype;
0152    bt_metatype    metatype;
0153    char *           text;
0154 } AST;
0155 #endif /* USER_DEFINED_AST */
0156 
0157 
0158 typedef struct
0159 {
0160    /*
0161     * `string' is the string that has been split; items[0] ...
0162     * items[num_items-1] are pointers into `string', or NULL for empty
0163     * substrings.  Note that `string' is actually a copy of the string
0164     * passed in to bt_split_list() with NULs inserted between substrings.
0165     */
0166 
0167    char *  string;
0168    int     num_items;
0169    char ** items;
0170 } bt_stringlist;
0171 
0172 
0173 typedef struct
0174 {
0175    bt_stringlist * tokens;              /* flat list of all tokens in name */
0176    char ** parts[BT_MAX_NAMEPARTS];     /* each elt. is list of pointers */
0177                                         /* into `tokens->string' */
0178    int     part_len[BT_MAX_NAMEPARTS];  /* length in tokens */
0179 } bt_name;
0180 
0181 
0182 typedef struct tex_tree_s
0183 {
0184    char * start;
0185    int    len;
0186    struct tex_tree_s
0187         * child,
0188         * next;
0189 } bt_tex_tree;
0190 
0191 
0192 typedef struct
0193 {
0194    /* These determine the order (and presence) of parts in the name. */
0195    int         num_parts;
0196    bt_namepart parts[BT_MAX_NAMEPARTS];
0197 
0198    /*
0199     * These lists are always in the order of the bt_namepart enum -- *not*
0200     * dependent on the particular order of parts the user specified!  (This
0201     * will make it a bit harder if I ever allow more than one occurrence of
0202     * a part in a format; since I don't allow that, I'm not [yet] worried
0203     * about it!)
0204     */
0205    const char *       pre_part[BT_MAX_NAMEPARTS];
0206    char *       post_part[BT_MAX_NAMEPARTS];
0207    char *       pre_token[BT_MAX_NAMEPARTS];
0208    const char *       post_token[BT_MAX_NAMEPARTS];
0209    boolean      abbrev[BT_MAX_NAMEPARTS];
0210    bt_joinmethod join_tokens[BT_MAX_NAMEPARTS];
0211    bt_joinmethod join_part[BT_MAX_NAMEPARTS];
0212 } bt_name_format;
0213 
0214 
0215 typedef enum
0216 {
0217    BTERR_NOTIFY,                /* notification about next action */
0218    BTERR_CONTENT,               /* warning about the content of a record */
0219    BTERR_LEXWARN,               /* warning in lexical analysis */
0220    BTERR_USAGEWARN,             /* warning about library usage */
0221    BTERR_LEXERR,                /* error in lexical analysis */
0222    BTERR_SYNTAX,                /* error in parser */
0223    BTERR_USAGEERR,              /* fatal error in library usage */
0224    BTERR_INTERNAL               /* my fault */
0225 } bt_errclass;
0226 
0227 typedef enum
0228 {
0229    BTACT_NONE,                  /* do nothing on error */
0230    BTACT_CRASH,                 /* call exit(1) */
0231    BTACT_ABORT                  /* call abort() */
0232 } bt_erraction;
0233 
0234 typedef struct
0235 {
0236    bt_errclass errclass;
0237    const char *      filename;
0238    int         line;
0239    const char *      item_desc;
0240    int         item;
0241    const char *message;
0242 } bt_error;
0243 
0244 typedef void (*bt_err_handler) (bt_error *);
0245 
0246 
0247 #if defined(__cplusplus__) || defined(__cplusplus) || defined(c_plusplus)
0248 extern "C" {
0249 #endif
0250 
0251 /* Function prototypes */
0252 
0253 /* init.c */
0254 void  bt_initialize (void);
0255 void  bt_free_ast (AST *ast);
0256 void  bt_cleanup (void);
0257 
0258 /* input.c */
0259 void    bt_set_stringopts (bt_metatype metatype, ushort options);
0260 AST * bt_parse_entry_s (char *    entry_text,
0261                         const char *    filename,
0262                         int       line,
0263                         ushort    options,
0264                         boolean * status);
0265 AST * bt_parse_entry   (FILE *    infile,
0266                         const char *    filename,
0267                         ushort    options,
0268                         boolean * status);
0269 AST * bt_parse_file    (char *    filename,
0270                         ushort    options,
0271                         boolean * overall_status);
0272 
0273 /* postprocess.c */
0274 void bt_postprocess_string (char * s, ushort options);
0275 char * bt_postprocess_value (AST * value, ushort options, boolean replace);
0276 char * bt_postprocess_field (AST * field, ushort options, boolean replace);
0277 void bt_postprocess_entry (AST * entry, ushort options);
0278 
0279 /* error.c */
0280 void   bt_reset_error_counts (void);
0281 int    bt_get_error_count (bt_errclass errclass);
0282 int *  bt_get_error_counts (int *counts);
0283 ushort bt_error_status (int *saved_counts);
0284 
0285 /* macros.c */
0286 void bt_add_macro_value (AST *assignment, ushort options);
0287 void bt_add_macro_text (const char * macro, const char * text, const char * filename, int line);
0288 void bt_delete_macro (const char * macro);
0289 void bt_delete_all_macros (void);
0290 int bt_macro_length (const char *macro);
0291 char * bt_macro_text (const char * macro, const char * filename, int line);
0292 
0293 /* traversal.c */
0294 AST *bt_next_entry (AST *entry_list, AST *prev_entry);
0295 bt_metatype bt_entry_metatype (AST *entry);
0296 char *bt_entry_type (AST *entry);
0297 char *bt_entry_key (AST *entry);
0298 AST *bt_next_field (AST *entry, AST *prev, char **name);
0299 AST *bt_next_macro (AST *entry, AST *prev, char **name);
0300 AST *bt_next_value (AST *head,
0301                     AST *prev,
0302                     bt_nodetype *nodetype,
0303                     char **text);
0304 char *bt_get_text (AST *node);
0305 
0306 /* modify.c */
0307 void bt_set_text (AST * node, char * new_text);
0308 void bt_entry_set_key (AST * entry, char * new_key);
0309 
0310 /* names.c */
0311 bt_stringlist * bt_split_list (char *   string,
0312                                char *   delim,
0313                                char *   filename,
0314                                int      line,
0315                                const char *   description);
0316 void bt_free_list (bt_stringlist *list);
0317 bt_name * bt_split_name (const char *  name,
0318                          const char *  filename,
0319                          int     line,
0320                          int     name_num);
0321 void bt_free_name (bt_name * name);
0322 
0323 /* tex_tree.c */
0324 bt_tex_tree * bt_build_tex_tree (char * string);
0325 void          bt_free_tex_tree (bt_tex_tree **top);
0326 void          bt_dump_tex_tree (bt_tex_tree *node, int depth, FILE *stream);
0327 char *        bt_flatten_tex_tree (bt_tex_tree *top);
0328 
0329 /* string_util.c */
0330 void bt_purify_string (char * string, ushort options);
0331 void bt_change_case (char transform, char * string, ushort options);
0332 
0333 /* format_name.c */
0334 bt_name_format * bt_create_name_format (char * parts, boolean abbrev_first);
0335 void bt_free_name_format (bt_name_format * format);
0336 void bt_set_format_text (bt_name_format * format,
0337                          bt_namepart part,
0338                          char * pre_part,
0339                          char * post_part,
0340                          char * pre_token,
0341                          char * post_token);
0342 void bt_set_format_options (bt_name_format * format,
0343                             bt_namepart part,
0344                             boolean abbrev,
0345                             bt_joinmethod join_tokens,
0346                             bt_joinmethod join_part);
0347 char * bt_format_name (bt_name * name, bt_name_format * format);
0348 
0349 #if defined(__cplusplus__) || defined(__cplusplus) || defined(c_plusplus)
0350 }
0351 #endif
0352 
0353 #endif /* BTPARSE_H */