Small, Fast S-Expression Library
|
00001 00037 #ifndef __SEXP_H__ 00038 #define __SEXP_H__ 00039 00040 #include <stddef.h> 00041 #include <stdio.h> /* for BUFSIZ only */ 00042 #include "faststack.h" 00043 #include "cstring.h" 00044 #include "sexp_memory.h" 00045 #include "sexp_errors.h" 00046 00047 /* doxygen documentation groups defined here */ 00048 00129 /*==============*/ 00130 /* ENUMERATIONS */ 00131 /*==============*/ 00132 00139 typedef enum { 00144 SEXP_VALUE, 00145 00150 SEXP_LIST 00151 } elt_t; 00152 00170 typedef enum { 00174 SEXP_BASIC, 00175 00180 SEXP_SQUOTE, 00181 00186 SEXP_DQUOTE, 00187 00192 SEXP_BINARY 00193 } atom_t; 00194 00195 /*============*/ 00196 /* STRUCTURES */ 00197 /*============*/ 00198 00227 typedef struct elt { 00239 elt_t ty; 00240 00246 char *val; 00247 00251 size_t val_allocated; 00252 00256 size_t val_used; 00257 00262 struct elt *list; 00263 00269 struct elt *next; 00270 00280 atom_t aty; 00281 00291 char *bindata; 00292 00296 size_t binlength; 00297 } sexp_t; 00298 00303 typedef enum { 00307 PARSER_NORMAL, 00308 00313 PARSER_INLINE_BINARY, 00314 00324 PARSER_EVENTS_ONLY 00325 } parsermode_t; 00326 00338 typedef struct parser_event_handlers { 00343 void (* start_sexpr)(); 00344 00349 void (* end_sexpr)(); 00350 00357 void (* characters)(const char *data, size_t len, atom_t aty); 00358 00365 void (* binary)(const char *data, size_t len); 00366 } parser_event_handlers_t; 00367 00395 typedef struct pcont { 00399 faststack_t *stack; 00400 00408 sexp_t *last_sexp; 00409 00413 char *val; 00414 00418 size_t val_allocated; 00419 00423 size_t val_used; 00424 00429 char *vcur; 00430 00437 char *lastPos; 00438 00444 char *sbuffer; 00445 00450 unsigned int depth; 00451 00456 unsigned int qdepth; 00457 00463 unsigned int state; 00464 00470 unsigned int esc; 00471 00476 unsigned int squoted; 00477 00483 sexp_errcode_t error; 00484 00498 parsermode_t mode; 00499 00500 /* ----------------------------------------------------------------- 00501 * These fields below are related to dealing with INLINE_BINARY mode 00502 * ----------------------------------------------------------------- */ 00503 00509 size_t binexpected; 00510 00514 size_t binread; 00515 00519 char *bindata; 00520 00528 parser_event_handlers_t *event_handlers; 00529 } pcont_t; 00530 00539 typedef struct sexp_iowrap { 00543 pcont_t *cc; 00544 00549 int fd; 00550 00554 char buf[BUFSIZ]; 00555 00560 int cnt; 00561 } sexp_iowrap_t; 00562 00563 /*========*/ 00564 /* GLOBAL */ 00565 /*========*/ 00566 00571 extern sexp_errcode_t sexp_errno; 00572 00573 /*===========*/ 00574 /* FUNCTIONS */ 00575 /*===========*/ 00576 00577 /* this is for C++ users */ 00578 #ifdef __cplusplus 00579 extern "C" { 00580 #endif 00581 00610 sexp_errcode_t set_parser_buffer_params(size_t ss, size_t gs); 00611 00620 sexp_t *sexp_t_allocate(void); 00621 00627 void sexp_t_deallocate(sexp_t *s); 00628 00637 void sexp_cleanup(void); 00638 00649 int print_sexp(char *loc, size_t size, const sexp_t *e); 00650 00660 int print_sexp_cstr(CSTRING **s, const sexp_t *e, size_t ss); 00661 00665 sexp_t *new_sexp_list(sexp_t *l); 00666 00677 sexp_t *new_sexp_atom(const char *buf, size_t bs, atom_t aty); 00678 00682 pcont_t *init_continuation(char *str); 00683 00688 void destroy_continuation (pcont_t * pc); 00689 00696 sexp_iowrap_t *init_iowrap(int fd); 00697 00704 void destroy_iowrap(sexp_iowrap_t *iow); 00705 00717 sexp_t *read_one_sexp(sexp_iowrap_t *iow); 00718 00723 sexp_t *parse_sexp(char *s, size_t len); 00724 00730 sexp_t *iparse_sexp(char *s, size_t len, pcont_t *cc); 00731 00737 pcont_t *cparse_sexp(char *s, size_t len, pcont_t *pc); 00738 00750 void destroy_sexp(sexp_t *s); 00751 00755 void reset_sexp_errno(); 00756 00757 /* this is for C++ users */ 00758 #ifdef __cplusplus 00759 } 00760 #endif 00761 00762 #include "sexp_ops.h" 00763 00764 #endif /* __SEXP_H__ */ 00765