AST * bt_next_entry (AST * entry_list, AST * prev_entry)
Used to traverse the linked list of entries returned by bt_parse_file() (see bt_input). On the first call, you should supply NULL for prev_entry, and a pointer to the head of the list will be returned. On subsequent calls, pass the previous return value as prev_entry; the function returns the next entry in the list, or NULL if there are no more entries. Also returns NULL if either entry_list or prev_entry are improper.
For example (ignoring error handling and variable declarations):
AST * bt_next_field (AST * entry, AST * prev, char ** name)
Used to traverse the list of fields in a regular or macro definition entry. (You should call bt_entry_metatype() to determine if you have the right kind of entry before calling bt_next_field().) entry should be a pointer to the AST for a single entry, as returned by bt_parse_entry(), bt_parse_entry_s(), or bt_next_entry(). On the first call, supply NULL for prev; bt_next_field() will return a pointer to the first field in entry, or NULL if entry has no fields (for instance, if its a comment or preamble entry). On subsequent calls, pass the previous return value as prev; bt_next_field() will keep returning pointers to field sub-ASTs as long as it makes sense. These pointers can then be passed to bt_next_value() or bt_get_text() to get the fields value.
For example, the loop body in the previous example could be:
AST * bt_next_value (AST * head, AST * prev, bt_nodetype_t * nodetype, char ** text)
Traverses the list of simple values that make up the value of a single field. (Recall that a simple value is either a quoted string, a macro invocation, or a number. A compound value is a list of these separated by # in the original input. Depending on the string post-processing options used when the data was parsed, the list of simple values nature of the original data may be preserved in the AST that youre traversing, in which case youll need a bt_next_value() loop.
bt_next_value() works much like bt_next_entry() and bt_next_field(): on the first call, you supply NULL for prev, and on subsequent calls you supply the previous return value. Returns NULL when there are no more simple values to return. Also sets *nodetype and *text to the corresponding information from the simple value node. *nodetype will be one of BTAST_STRING, BTAST_MACRO, or BTAST_NUMBER; *text will point to the same string as the AST node does (it is not copied for you), so dont mess with it.
For example, the loop body in the bt_next_field() example could be replaced with:
See also bt_get_text.
bt_entry_metatype() bt_metatype_t bt_entry_metatype (AST * entry)
Returns the metatype of an entry. (Recall that the metatype is an enumerated type whose values are derived from the specific type of an entry; for instance, an @comment entry has type "comment" and metatype BTE_COMMENT. The type-metatype relationship is similarly obvious for BTE_PREAMBLE; BTE_MACRODEF corresponds to @string entries; and BTE_REGULAR corresponds to any other type.)
Returns BTE_UNKNOWN if entry is invalid (i.e., NULL or not a pointer to an entry AST).
bt_entry_type() char * bt_entry_type (AST * entry)
Returns the type of an entry. Recall that the type is the name that appears after the @ character in the original input. Returns NULL if entry is invalid (i.e., NULL or not a pointer to an entry AST).
bt_entry_key() char * bt_entry_key (AST * entry)
Returns the citation key of a regular entry. (The citation key is the name that appears after the entry-open delimiter in a regular entry.) Returns NULL if entry is invalid (i.e., NULL or not a pointer to the AST for a regular entry).
bt_get_text() char * bt_get_text (AST * node)
Performs all string post-processing (macro expansion, concatenation of simple values, and whitespace collapsing) of a compound value and returns the string that results. Can be called either on a field for a regular or macro definition entry (as returned by bt_next_field()), or on a comment or preamble entry. Returns NULL if called on an invalid AST node.
Greg Ward <firstname.lastname@example.org>
|btparse, version 0.71||BT_TRAVERSAL (1)||2015-05-28|