BRL-CAD
#include "common.h"
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <math.h>
#include <string.h>
#include <assert.h>
#include "bu/cv.h"
#include "bu/log.h"
#include "bu/malloc.h"
#include "bu/parallel.h"
#include "bu/parse.h"
#include "bu/str.h"
#include "bu/units.h"
Include dependency graph for parse.c:

Go to the source code of this file.

Macros

#define COMMA   ','
 
#define CKMEM(_len)
 
#define PARSE_MAGIC_1   0x15cb
 
#define PARSE_MAGIC_2   0xbc51
 
#define PARSE_INIT_GETPUT_1(_p)
 
#define PARSE_INIT_GETPUT_2(_p, _l)
 
#define PARSE_CK_GETPUT(_p)
 
#define STATE_UNKNOWN   0
 
#define STATE_IN_KEYWORD   1
 
#define STATE_IN_VALUE   2
 
#define STATE_IN_QUOTED_VALUE   3
 

Functions

int bu_struct_export (struct bu_external *ext, const void *base, const struct bu_structparse *imp)
 
int bu_struct_import (void *base, const struct bu_structparse *imp, const struct bu_external *ext, void *data)
 
size_t bu_struct_put (FILE *fp, const struct bu_external *ext)
 
size_t bu_struct_get (struct bu_external *ext, FILE *fp)
 
void bu_struct_wrap_buf (struct bu_external *ext, void *buf)
 
HIDDEN int parse_floating (const char *str, size_t count, fastf_t *floc, double *dloc)
 
HIDDEN int parse_struct_lookup (register const struct bu_structparse *sdp, register const char *name, const char *base, const char *const value, void *data)
 
int bu_struct_parse (const struct bu_vls *in_vls, const struct bu_structparse *desc, const char *base, void *data)
 
HIDDEN void parse_matprint (const char *name, register const fastf_t *mat)
 
HIDDEN void parse_dmatprint (const char *name, register const double *mat)
 
HIDDEN void parse_vls_matprint (struct bu_vls *vls, const char *name, register const fastf_t *mat)
 
HIDDEN void parse_vls_dmatprint (struct bu_vls *vls, const char *name, register const double *mat)
 
void bu_vls_struct_item (struct bu_vls *vp, const struct bu_structparse *sdp, const char *base, int sep_char)
 
int bu_vls_struct_item_named (struct bu_vls *vp, const struct bu_structparse *parsetab, const char *name, const char *base, int sep_char)
 
void bu_struct_print (const char *title, const struct bu_structparse *parsetab, const char *base)
 
HIDDEN void parse_vls_print_floating (struct bu_vls *vls, const char *name, size_t count, const fastf_t *fp, const double *dp)
 
void bu_vls_struct_print (struct bu_vls *vls, register const struct bu_structparse *sdp, const char *base)
 
void bu_vls_struct_print2 (struct bu_vls *vls_out, const char *title, const struct bu_structparse *parsetab, const char *base)
 
void bu_parse_mm (const struct bu_structparse *sdp, const char *name, char *base, const char *value)
 
int bu_key_eq_to_key_val (const char *in, const char **next, struct bu_vls *vls)
 
int bu_shader_to_list (const char *in, struct bu_vls *vls)
 
HIDDEN char * parse_list_elem (const char *in, int idx)
 
HIDDEN int parse_list_length (const char *in)
 
HIDDEN int parse_key_val_to_vls (struct bu_vls *vls, char *params)
 
int bu_shader_to_key_eq (const char *in, struct bu_vls *vls)
 
int bu_fwrite_external (FILE *fp, const struct bu_external *ep)
 
void bu_hexdump_external (FILE *fp, const struct bu_external *ep, const char *str)
 
void bu_free_external (register struct bu_external *ep)
 
void bu_copy_external (struct bu_external *op, const struct bu_external *ip)
 
char * bu_next_token (char *str)
 
void bu_structparse_get_terse_form (struct bu_vls *logstr, const struct bu_structparse *sp)
 
int bu_structparse_argv (struct bu_vls *logstr, int argc, const char **argv, const struct bu_structparse *desc, char *base, void *data)
 

Detailed Description

routines for parsing arbitrary structures

Routines to assign values to elements of arbitrary structures. The layout of a structure to be processed is described by a structure of type "bu_structparse", giving element names, element formats, an offset from the beginning of the structure, and a pointer to an optional "hooked" function that is called whenever that structure element is changed.

Definition in file parse.c.

Macro Definition Documentation

#define COMMA   ','
#define CKMEM (   _len)
Value:
{ \
register ssize_t offset; \
if ((offset = (ep - cp) - (_len)) < 0) { \
do { \
offset += ext->ext_nbytes; /* decr by new growth */ \
ext->ext_nbytes <<= 1; \
} while (offset < 0); \
offset = cp - (char *)ext->ext_buf; \
ext->ext_buf = (uint8_t *)bu_realloc((char *) ext->ext_buf, \
ext->ext_nbytes, "bu_struct_export"); \
ep = (char *)ext->ext_buf + ext->ext_nbytes; \
cp = (char *)ext->ext_buf + offset; \
} \
}
ptrdiff_t ssize_t
Definition: common.h:119
if(share_geom)
Definition: nmg_mod.c:3829
void * bu_realloc(void *ptr, size_t siz, const char *str)

Definition at line 45 of file parse.c.

Referenced by bu_struct_export().

#define PARSE_MAGIC_1   0x15cb

Definition at line 61 of file parse.c.

Referenced by bu_struct_get(), and bu_struct_wrap_buf().

#define PARSE_MAGIC_2   0xbc51

Definition at line 62 of file parse.c.

Referenced by bu_struct_get(), and bu_struct_wrap_buf().

#define PARSE_INIT_GETPUT_1 (   _p)
Value:
{ \
((unsigned char *) _p->ext_buf)[1] = (PARSE_MAGIC_1 & 0xFF); \
((unsigned char *) _p->ext_buf)[0] = (PARSE_MAGIC_1 >> 8) & 0xFF; \
}
#define PARSE_MAGIC_1
Definition: parse.c:61
#define BU_CK_EXTERNAL(_p)
Definition: parse.h:224

Definition at line 63 of file parse.c.

Referenced by bu_struct_export().

#define PARSE_INIT_GETPUT_2 (   _p,
  _l 
)
Value:
{ \
((unsigned char *) _p->ext_buf)[_l-1] = (PARSE_MAGIC_2 & 0xFF); \
((unsigned char *) _p->ext_buf)[_l-2] = (PARSE_MAGIC_2 >> 8) & 0xFF; \
}
#define PARSE_MAGIC_2
Definition: parse.c:62
#define BU_CK_EXTERNAL(_p)
Definition: parse.h:224

Definition at line 68 of file parse.c.

Referenced by bu_struct_export().

#define PARSE_CK_GETPUT (   _p)

Definition at line 75 of file parse.c.

Referenced by bu_struct_import(), and bu_struct_put().

#define STATE_UNKNOWN   0

Definition at line 1815 of file parse.c.

#define STATE_IN_KEYWORD   1

Definition at line 1816 of file parse.c.

Referenced by bu_key_eq_to_key_val().

#define STATE_IN_VALUE   2

Definition at line 1817 of file parse.c.

Referenced by bu_key_eq_to_key_val().

#define STATE_IN_QUOTED_VALUE   3

Definition at line 1818 of file parse.c.

Referenced by bu_key_eq_to_key_val().

Function Documentation

HIDDEN int parse_floating ( const char *  str,
size_t  count,
fastf_t floc,
double *  dloc 
)

Parse an array of one or more floating point values.

Returns: 0 when successful <0 upon failure

Definition at line 583 of file parse.c.

References bu_vls_addr(), bu_vls_free(), BU_VLS_INIT_ZERO, bu_vls_strncpy(), and UNLIKELY.

Referenced by parse_struct_lookup().

Here is the call graph for this function:

HIDDEN int parse_struct_lookup ( register const struct bu_structparse sdp,
register const char *  name,
const char *  base,
const char *const  value,
void *  data 
)
Returns
-2 parse error
-1 not found
0 entry found and processed

Definition at line 667 of file parse.c.

References BU_ASSERT, bu_bomb(), bu_log(), BU_STR_EQUAL, bu_vls_strcpy(), parse_floating(), bu_structparse::sp_count, bu_structparse::sp_fmt, bu_structparse::sp_hook, bu_structparse::sp_name, bu_structparse::sp_offset, and UNLIKELY.

Referenced by bu_struct_parse().

Here is the call graph for this function:

HIDDEN void parse_matprint ( const char *  name,
register const fastf_t mat 
)

Definition at line 971 of file parse.c.

References bu_log(), bu_log_indent_delta(), delta, and UNLIKELY.

Referenced by bu_struct_print().

Here is the call graph for this function:

HIDDEN void parse_dmatprint ( const char *  name,
register const double *  mat 
)

Definition at line 1000 of file parse.c.

References bu_log(), bu_log_indent_delta(), delta, and UNLIKELY.

Referenced by bu_struct_print().

Here is the call graph for this function:

HIDDEN void parse_vls_matprint ( struct bu_vls vls,
const char *  name,
register const fastf_t mat 
)

Definition at line 1029 of file parse.c.

References bu_log_indent_delta(), bu_log_indent_vls(), bu_vls_printf(), delta, and UNLIKELY.

Referenced by bu_vls_struct_print2().

Here is the call graph for this function:

HIDDEN void parse_vls_dmatprint ( struct bu_vls vls,
const char *  name,
register const double *  mat 
)

Definition at line 1063 of file parse.c.

References bu_log_indent_delta(), bu_log_indent_vls(), bu_vls_printf(), delta, and UNLIKELY.

Referenced by bu_vls_struct_print2().

Here is the call graph for this function:

HIDDEN void parse_vls_print_floating ( struct bu_vls vls,
const char *  name,
size_t  count,
const fastf_t fp,
const double *  dp 
)

Definition at line 1411 of file parse.c.

References bu_vls_extend(), COMMA, UNLIKELY, bu_vls::vls_len, bu_vls::vls_offset, and bu_vls::vls_str.

Referenced by bu_vls_struct_print().

Here is the call graph for this function:

void bu_vls_struct_print ( struct bu_vls vls,
register const struct bu_structparse sdp,
const char *  base 
)

Definition at line 1451 of file parse.c.

References BU_ASSERT, bu_bomb(), BU_CK_VLS, bu_log(), bu_vls_addr(), bu_vls_extend(), bu_vls_free(), BU_VLS_INIT_ZERO, bu_vls_printf(), bu_vls_putc(), bu_vls_vlscat(), COMMA, parse_vls_print_floating(), bu_structparse::sp_count, bu_structparse::sp_fmt, bu_structparse::sp_name, bu_structparse::sp_offset, UNLIKELY, bu_vls::vls_len, bu_vls::vls_offset, and bu_vls::vls_str.

Here is the call graph for this function:

HIDDEN char* parse_list_elem ( const char *  in,
int  idx 
)

Given a list in "{1}, {2}, {3}" form, return a copy of the 'index'th entry, which may itself be a list.

Note: caller is responsible for freeing the returned string.

Definition at line 2080 of file parse.c.

References bu_log(), bu_vls_free(), BU_VLS_INIT_ZERO, bu_vls_strdup(), and bu_vls_strncpy().

Referenced by bu_shader_to_key_eq(), and parse_key_val_to_vls().

Here is the call graph for this function:

HIDDEN int parse_list_length ( const char *  in)

Return number of items in a string, interpreted as a Tcl list.

Definition at line 2175 of file parse.c.

References UNLIKELY.

Referenced by bu_shader_to_key_eq(), and parse_key_val_to_vls().

HIDDEN int parse_key_val_to_vls ( struct bu_vls vls,
char *  params 
)

Definition at line 2225 of file parse.c.

References bu_free(), bu_log(), bu_vls_putc(), bu_vls_strcat(), parse_list_elem(), parse_list_length(), and UNLIKELY.

Referenced by bu_shader_to_key_eq().

Here is the call graph for this function:

void bu_free_external ( register struct bu_external ep)

Definition at line 2441 of file parse.c.

References BU_CK_EXTERNAL, bu_free(), bu_external::ext_buf, and UNLIKELY.

Here is the call graph for this function: