.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "btparse::doc::bt_macros 3" .TH btparse::doc::bt_macros 3 2024-01-10 "btparse, version 0.89" btparse .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME bt_macros \- accessing and manipulating the btparse macro table .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 6 \& void bt_add_macro_value (AST * assignment, \& btshort options); \& void bt_add_macro_text (char * macro, \& char * text, \& char * filename, \& int line); \& \& void bt_delete_macro (char * macro); \& void bt_delete_all_macros (void); \& \& int bt_macro_length (char *macro); \& char * bt_macro_text (char * macro, \& char * filename, \& int line); .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" \&\fBbtparse\fR maintains a single table of all macros (abbreviations) encountered while parsing BibTeX entries. It updates this table whenever it encounters a "macro definition" (\f(CW@string\fR) entry, and refers to it whenever a macro is used in an entry and needs to be expanded. (Macros are not necessarily expanded on input, although this is the default. See bt_postprocess.) Macro definitions are only cleared when \fBbtparse\fR's global cleanup function, \f(CWbt_cleanup()\fR, is called. Thus, unless you explicitly call \f(CWbt_delete_macro()\fR or \&\f(CWbt_delete_all_macros()\fR, macro definitions persist for as long as you use the library\-\-\-usually, the lifetime of your process. .SH FUNCTIONS .IX Header "FUNCTIONS" You can use the following functions to add macros, delete them, and query their values\-\-\-thus interfering with \fBbtparse\fR's normal operation on the fly. .IP "bt_add_macro_text ()" 4 .IX Item "bt_add_macro_text ()" .Vb 4 \& void bt_add_macro_text (char * macro, \& char * text, \& char * filename, \& int line); .Ve .Sp Defines a new macro, or redefines an old one. \f(CW\*(C`macro\*(C'\fR is the name of the macro, and \f(CW\*(C`text\*(C'\fR is the text it should expand to. \f(CW\*(C`filename\*(C'\fR and \&\f(CW\*(C`line\*(C'\fR are just used to generate any warnings about the macro definition; if they don't apply, specify \f(CW\*(C`NULL\*(C'\fR for \f(CW\*(C`filename\*(C'\fR and \&\f(CW0\fR for \f(CW\*(C`line\*(C'\fR. The only such warning occurs when you redefine an old macro: its value is overridden, and \f(CWbt_add_macro_text()\fR issues a warning saying so. .Sp For instance, when parsing this macro definition entry: .Sp .Vb 1 \& @string{fubar = "Fouled Up Beyond All Recognition"} .Ve .Sp the library (in particular, the post-processing code called after an entry is successfully parsed) will ultimately do this: .Sp .Vb 2 \& bt_add_macro_text ("fubar", "Fouled Up Beyond All Recognition", \& filename, line); .Ve .Sp This in turn will cause the macro \f(CW\*(C`fubar\*(C'\fR to be expanded appropriately whenever the post-processing code sees it in any future entries. .IP "bt_add_macro_value ()" 4 .IX Item "bt_add_macro_value ()" .Vb 2 \& void bt_add_macro_value (AST * assignment, \& btshort options); .Ve .Sp This function is mainly for internal use by the library, but it's available to you if you ever find yourself with a little bit of AST representing a macro definition, and you want to set the macro yourself (rather than letting the library's post-processing code take care of it for you). \f(CW\*(C`assignment\*(C'\fR must be an AST node as returned by \&\f(CWbt_next_field()\fR. Unlike most other \fBbtparse\fR functions that take an \&\f(CW\*(C`options\*(C'\fR argument, \f(CW\*(C`options\*(C'\fR here tells how the value in \&\f(CW\*(C`assignment\*(C'\fR was post-processed. This is needed because macro values have to be processed in a special way to be valid in future expansions; if this one wasn't processed like that, \f(CWbt_add_macro_value()\fR will do it for you. If you don't know how the value was post-processed, just supply \f(CW0\fR for \f(CW\*(C`options\*(C'\fR\-\-\-that's guaranteed to describe something different from "the right way" for macros, so the post-processing will be done correctly. .Sp The processing done to macro values is mainly to ensure that we can get away with storing just a string in the macro table: macros invoked by the macro are themselves expanded, and all sub-strings are concatenated. For instance, if \fBbtparse\fR parses these entries: .Sp .Vb 2 \& @string{and = " and "} \& @string{jim_n_bob = "James Smith" # and # "Bob Jones"} .Ve .Sp then the value stored for \f(CW\*(C`jim_n_bob\*(C'\fR should obviously be the string \&\f(CW"James Smith and Bob Jones"\fR. To ensure this, \fBbtparse\fR has to process the value of \f(CW\*(C`and\*(C'\fR differently from most BibTeX strings: in particular, whitespace is \fInot\fR collapsed before the string is stored. That way, the correct value, \f(CW" and "\fR, is interpolated into the value of \f(CW\*(C`jim_n_bob\*(C'\fR. Thus, all macro values have sub-macros expanded and strings concatenated before they are stored, but whitespace is not collapsed until the macro is used in a regular entry. .Sp This function calls \f(CWbt_add_macro_text()\fR, so the same proviso about redefining old macros applies\-\-\-a warning will be issued, and the old value lost. .IP "bt_delete_macro ()" 4 .IX Item "bt_delete_macro ()" .Vb 1 \& void bt_delete_macro (char * macro); .Ve .Sp Deletes a macro from the macro table. If \f(CW\*(C`macro\*(C'\fR isn't defined, takes no action. .IP "bt_delete_all_macros ()" 4 .IX Item "bt_delete_all_macros ()" .Vb 1 \& void bt_delete_all_macros (void); .Ve .Sp Deletes all macros from the macro table. .IP "bt_macro_length ()" 4 .IX Item "bt_macro_length ()" .Vb 1 \& int bt_macro_length (char *macro); .Ve .Sp Returns the length of a macro's expansion text. If the macro is undefined, returns 0; no warning is issued. .IP "bt_macro_text ()" 4 .IX Item "bt_macro_text ()" .Vb 3 \& char * bt_macro_text (char * macro, \& char * filename, \& int line); .Ve .Sp Returns the expansion text of a macro. If the macro is not defined, issues a warning and returns \f(CW\*(C`NULL\*(C'\fR. \f(CW\*(C`filename\*(C'\fR and \f(CW\*(C`line\*(C'\fR are used for generating this warning; if they don't apply (i.e. you're not expanding the macro as a result of finding it in some file), supply \&\f(CW\*(C`NULL\*(C'\fR for \f(CW\*(C`filename\*(C'\fR and \f(CW0\fR for \f(CW\*(C`line\*(C'\fR. .SH "SEE ALSO" .IX Header "SEE ALSO" btparse .SH AUTHOR .IX Header "AUTHOR" Greg Ward