BRL-CAD
|
BRL-CAD support library, error logging routines. More...
Files | |
file | log.h |
file | log.h |
Data Structures | |
struct | bu_hook |
struct | bu_hook_list |
struct | bu_lex_t_int |
struct | bu_lex_t_dbl |
struct | bu_lex_t_key |
struct | bu_lex_t_id |
union | bu_lex_token |
struct | bu_lex_key |
Macros | |
#define | BU_HOOK_LIST_INIT_ZERO { 0, 0, NULL} |
#define | BU_HOOK_LIST_IS_INITIALIZED(_p) ((_p)->capacity != 0) |
#define | BU_LEX_ANY 0 /* pseudo type */ |
#define | BU_LEX_INT 1 |
#define | BU_LEX_DOUBLE 2 |
#define | BU_LEX_SYMBOL 3 |
#define | BU_LEX_KEYWORD 4 |
#define | BU_LEX_IDENT 5 |
#define | BU_LEX_NUMBER 6 /* Pseudo type */ |
#define | BU_LEX_NEED_MORE 0 |
Typedefs | |
typedef int(* | bu_hook_t) (void *, void *) |
typedef struct bu_hook | bu_hook_list_t |
Functions | |
void | bu_hook_list_init (struct bu_hook_list *hlp) |
void | bu_hook_add (struct bu_hook_list *hlp, bu_hook_t func, void *clientdata) |
void | bu_hook_delete (struct bu_hook_list *hlp, bu_hook_t func, void *clientdata) |
void | bu_hook_call (struct bu_hook_list *hlp, void *buf) |
void | bu_hook_save_all (struct bu_hook_list *source, struct bu_hook_list *destination) |
void | bu_hook_delete_all (struct bu_hook_list *hlp) |
void | bu_hook_restore_all (struct bu_hook_list *destination, struct bu_hook_list *source) |
char * | bu_fgets (char *s, int size, FILE *stream) |
fgets replacement function that also handles CR as an EOL marker More... | |
void | bu_setlinebuf (FILE *fp) |
A portable way of doing setlinebuf(). More... | |
void | bu_log_indent_delta (int delta) |
parallel safe version of fprintf for logging More... | |
void | bu_log_indent_vls (struct bu_vls *v) |
void | bu_log_add_hook (bu_hook_t func, void *clientdata) |
void | bu_log_delete_hook (bu_hook_t func, void *clientdata) |
void | bu_log_hook_save_all (struct bu_hook_list *save_hlp) |
void | bu_log_hook_delete_all (void) |
void | bu_log_hook_restore_all (struct bu_hook_list *restore_hlp) |
void | bu_putchar (int c) |
int | bu_log (const char *,...) _BU_ATTR_PRINTF12 |
int | bu_flog (FILE *, const char *,...) _BU_ATTR_PRINTF23 |
int | bu_vsscanf (const char *src, const char *fmt, va_list ap) |
libbu implementations of vsscanf/sscanf() with extra format specifiers. More... | |
int | bu_sscanf (const char *src, const char *fmt,...) _BU_ATTR_SCANF23 |
int | bu_scan_fastf_t (int *c, const char *src, const char *delim, size_t n,...) |
int | bu_lex (union bu_lex_token *token, struct bu_vls *rtstr, struct bu_lex_key *keywords, struct bu_lex_key *symbols) |
long int | bu_mread (int fd, void *bufp, long int n) |
multiple-read to fill a buffer More... | |
BRL-CAD support library, error logging routines.
These are hook routines for keeping track of callback functions.
Note that the user may provide his own logging routine, by replacing these functions. That is why this is in file of its own. For example, LGT and RTSRV take advantage of this.
Here is an example of how to set up a custom logging callback. While bu_log presently writes to STDERR by default, this behavior should not be relied upon and may be changed to STDOUT in the future without notice.
#define BU_HOOK_LIST_INIT_ZERO { 0, 0, NULL} |
macro suitable for declaration statement initialization of a bu_hook_list struct. does not allocate memory. not suitable for initialization of a list head node.
#define BU_HOOK_LIST_IS_INITIALIZED | ( | _p | ) | ((_p)->capacity != 0) |
returns truthfully whether a non-head node bu_hook_list has been initialized via BU_HOOK_LIST_INIT() or BU_HOOK_LIST_INIT_ZERO.
typedef int(* bu_hook_t) (void *, void *) |
typedef struct bu_hook bu_hook_list_t |
void bu_hook_list_init | ( | struct bu_hook_list * | hlp | ) |
initialize a hook list to empty
the caller is responsible for ensuring memory is not leaked.
void bu_hook_add | ( | struct bu_hook_list * | hlp, |
bu_hook_t | func, | ||
void * | clientdata | ||
) |
add a hook to the list.
in addition to the callback, the call may optionally provide a data pointer that will get passed as the first argument to the 'func' hook function. the hook function may be NULL, which will result in a no-op (skipped) when bu_hook_call() is called.
void bu_hook_delete | ( | struct bu_hook_list * | hlp, |
bu_hook_t | func, | ||
void * | clientdata | ||
) |
delete a hook from the list.
this removes a specified callback function registered with a particular data pointer via bu_hook_add() from the hook list.
void bu_hook_call | ( | struct bu_hook_list * | hlp, |
void * | buf | ||
) |
call all registered hooks.
this invokes all callbacks added via bu_hook_add() passing any data pointer as the first argument and the provided 'buf' argument as the second argument, either of which may be NULL if desired.
void bu_hook_save_all | ( | struct bu_hook_list * | source, |
struct bu_hook_list * | destination | ||
) |
copy all hooks from one list to another
void bu_hook_delete_all | ( | struct bu_hook_list * | hlp | ) |
delete all hooks in a list
void bu_hook_restore_all | ( | struct bu_hook_list * | destination, |
struct bu_hook_list * | source | ||
) |
replace all hooks in a list with the hooks from another list
all hooks from ther 'destination' hook list will be deleted and all hooks in the 'source' list will be copied into the 'destination' list.
char * bu_fgets | ( | char * | s, |
int | size, | ||
FILE * | stream | ||
) |
fgets replacement function that also handles CR as an EOL marker
Reads in at most one less than size characters from stream and stores them into the buffer pointed to by s. Reading stops after an EOF, CR, LF, or a CR/LF combination. If a LF or CR is read, it is stored into the buffer. If a CR/LF is read, just a CR is stored into the buffer. A '\0' is stored after the last character in the buffer. Returns s on success, and NULL on error or when end of file occurs while no characters have been read.
void bu_setlinebuf | ( | FILE * | fp | ) |
A portable way of doing setlinebuf().
void bu_log_indent_delta | ( | int | delta | ) |
parallel safe version of fprintf for logging
Change global indentation level by indicated number of characters. Call with a large negative number to cancel all indentation.
void bu_log_indent_vls | ( | struct bu_vls * | v | ) |
For multi-line vls generators, honor logindent level like bu_log() does, and prefix the proper number of spaces. Should be called at the front of each new line.
void bu_log_add_hook | ( | bu_hook_t | func, |
void * | clientdata | ||
) |
Adds a hook to the list of bu_log hooks. The top (newest) one of these will be called with its associated client data and a string to be processed. Typically, these hook functions will display the output (possibly in an X window) or record it.
NOTE: The hook functions are all non-PARALLEL.
void bu_log_delete_hook | ( | bu_hook_t | func, |
void * | clientdata | ||
) |
Removes the hook matching the function and clientdata parameters from the hook list. Note that it is not necessarily the active (top) hook.
void bu_log_hook_save_all | ( | struct bu_hook_list * | save_hlp | ) |
void bu_log_hook_delete_all | ( | void | ) |
void bu_log_hook_restore_all | ( | struct bu_hook_list * | restore_hlp | ) |
void bu_putchar | ( | int | c | ) |
Log a single character with no flushing.
int bu_log | ( | const char * | , |
... | |||
) |
The routine is primarily called to log library events.
The function is essentially a semaphore-protected version of fprintf(stderr) with optional logging hooks and automatic indentation options.
int bu_flog | ( | FILE * | , |
const char * | , | ||
... | |||
) |
Just like bu_log() except that you can send output to a specified file pointer.
int bu_vsscanf | ( | const char * | src, |
const char * | fmt, | ||
va_list | ap | ||
) |
libbu implementations of vsscanf/sscanf() with extra format specifiers.
Custom vsscanf which wraps the system sscanf, and is wrapped by bu_sscanf.
bu_vsscanf differs notably from the underlying system sscanf in that:
V and %#V have been added as valid conversions. Both expect a pointer to a struct bu_vls as their argument.
V is comparable to %[^]. It instructs bu_vsscanf to read arbitrary characters from the source and store them in the vls buffer. The default maximum field width is infinity.
%#V is comparable to s. It instructs bu_vsscanf to skip leading whitespace, and then read characters from the source and store them in the vls buffer until the next whitespace character is encountered. The default maximum field width is infinity.
This routine has an associated test program named test_sscanf, which compares its behavior to the system sscanf.
int bu_sscanf | ( | const char * | src, |
const char * | fmt, | ||
... | |||
) |
Initializes the va_list, then calls bu_vsscanf.
This routine has an associated test program named test_sscanf, which compares its behavior to the system sscanf.
int bu_scan_fastf_t | ( | int * | c, |
const char * | src, | ||
const char * | delim, | ||
size_t | n, | ||
... | |||
) |
Routines for scanning certain kinds of data. Scans a sequence of fastf_t numbers from a string or stdin
Scanning fastf_t numbers with bu_sscanf() is difficult, because doing so requires scanning to some intermediate type like double and then assigning to the fastf_t variable to convert the value to whatever type fastf_t really is. This function makes it possible to scan a series of fastf_t numbers separated by some character(s) easily, by doing the required conversion internally to the functions. As series of delimiter characters will be skipped, empty scan fields are not supported (e.g., "0.0,,0.0,1.0" will scan as 3 fields, not 4 with the 2nd skipped).
[out] | c | Returns number of characters scanned by the function |
[in] | src | A source string to scan from, or NULL to read from stdin |
[in] | delim | Any delimiter character(s) to skip between scan values |
[in] | n | Number of fastf_t values to scan from the src input string |
[out] | ... | Pointers to fastf_t for storing scanned values (optional) |
int bu_lex | ( | union bu_lex_token * | token, |
struct bu_vls * | rtstr, | ||
struct bu_lex_key * | keywords, | ||
struct bu_lex_key * | symbols | ||
) |
long int bu_mread | ( | int | fd, |
void * | bufp, | ||
long int | n | ||
) |
multiple-read to fill a buffer
Provide a general means to a read some count of items from a file descriptor reading multiple times until the quantity desired is obtained. This is useful for pipes and network connections that don't necessarily deliver data with the same grouping as it is written with.
If a read error occurs, a negative value will be returns and errno should be set (by read()). "Multiple try" read. Read multiple times until quantity is obtained or an error occurs. This is useful for pipes.