void bt_set_stringopts (bt_metatype_t metatype, ushort options);
Set the string-processing options for a particular entry metatype. This affects the entry post-processing done by bt_parse_entry_s(), bt_parse_entry(), and bt_parse_file(). If bt_set_stringopts() is never called, the four metatypes default to the following sets of string options:
will cause the library to collapse whitespace in the value from all comment entries; the AST returned by one of the bt_parse_* functions will reflect this change.
AST * bt_parse_entry (FILE * infile, char * filename, ushort options, boolean * status);
Scans and parses the next BibTeX entry in infile. You should supply filename to help btparse generate accurate error messages; the library keeps track of infiles current line number internally, so you dont need to pass that in. options should be a bitmap of non-string-processing options (currently, BTO_NOSTORE to disable storing macro expansions is the only such option). *status will be set to TRUE if the entry parsed successfully or with only minor warnings, and FALSE if there were any serious lexical or syntactic errors. If status is NULL, then the parse status will be unavailable to you. Both minor warnings and serious errors are reported on stderr.
Returns a pointer to the abstract-syntax tree (AST) describing the entry just parsed, or NULL if no more entries were found in infile (this will leave infile at end-of-file). Do not attempt to second guess bt_parse_entry() by detecting end-of-file yourself; it must be allowed to determine this on its own so it can clean up some static data that is preserved between calls on the same file.
bt_parse_entry() has two important restrictions that you should know about. First, you should let btparse manage all the input on the file; this is for reasons both superficial (so the library knows the current line number in order to generate accurate error messages) and fundamental (the library must be allowed to detect end-of-file in order to cleanup certain static variables and allow you to parse another file). Second, you cannot interleave the parsing of two different files; attempting to do so will result in a fatal error that will crash your program. This is a direct result of the static state maintained between calls of bt_parse_entry().
Because of two distinct failures possible for bt_parse_entry() (end-of-file, which is expected but means to stop processing the current file; and error-in-input, which is not expected but allows you to continue processing the same file), you should usually call it like this:
At the end of this loop, feof (file) will be true.
AST * bt_parse_entry_s (char * entry_text, char * filename, int line, ushort options, boolean * status)
Scans and parses a single complete BibTeX entry contained in a string, entry_text. If you read this string from a file, you should help btparse generate accurate error messages by supplying the name of the file as filename and the line number of the beginning of the entry as line; otherwise, set filename to NULL and line to 1. options and status are the same as for bt_parse_entry().
Returns a pointer to the abstract-syntax tree (AST) describing the entry just parsed, and NULL if no entries were found in entry_text or if entry_text was NULL.
You should call bt_parse_entry_s() once more than the total number of entries you wish to parse; on the final call, set entry_text to NULL so the function knows theres no more text to parse. This final call allows it to clean up some structures allocated on the first call. Thus, bt_parse_entry_s() is usually used like this:
assuming that get_more_text() returns a pointer to the text of an entry to parse, or NULL if theres no more text available.
AST * bt_parse_file (char * filename, ushort options, boolean * status)
Scans and parses an entire BibTeX file. If filename is NULL or "-", then stdin will be read; otherwise, attempts to open the named file. If this attempt fails, prints an error message to stderr and returns NULL. options and status are the same as for bt_parse_entry()---note that *status will be FALSE if there were any errors in the entire file; for finer granularity of error-checking, you should use bt_parse_entry().
Returns a pointer to a linked list of ASTs representing the entries in the file, or NULL if no entries were found in the file. This list can be traversed with bt_next_entry(), and the individual entries then traversed as usual (see bt_traversal).
btparse, bt_postprocess, bt_traversal
Greg Ward <email@example.com>
|btparse, version 0.34||BT_INPUT (3)||2003-10-25|