Small, Fast S-Expression Library
sexp.h
Go to the documentation of this file.
1 
37 #ifndef __SEXP_H__
38 #define __SEXP_H__
39 
40 #include <stddef.h>
41 #include <stdio.h> /* for BUFSIZ only */
42 #include "faststack.h"
43 #include "cstring.h"
44 #include "sexp_memory.h"
45 #include "sexp_errors.h"
46 
47 /* doxygen documentation groups defined here */
48 
129 /*==============*/
130 /* ENUMERATIONS */
131 /*==============*/
132 
139 typedef enum {
145 
150  SEXP_LIST
151 } elt_t;
152 
170 typedef enum {
175 
181 
187 
194 
195 /*============*/
196 /* STRUCTURES */
197 /*============*/
198 
227 typedef struct elt {
240 
246  char *val;
247 
252 
256  size_t val_used;
257 
262  struct elt *list;
263 
269  struct elt *next;
270 
281 
291  char *bindata;
292 
296  size_t binlength;
298 
303 typedef enum {
308 
314 
326 
338 typedef struct parser_event_handlers {
343  void (* start_sexpr)();
344 
349  void (* end_sexpr)();
350 
357  void (* characters)(const char *data, size_t len, atom_t aty);
358 
365  void (* binary)(const char *data, size_t len);
367 
395 typedef struct pcont {
400 
409 
413  char *val;
414 
419 
423  size_t val_used;
424 
429  char *vcur;
430 
437  char *lastPos;
438 
444  char *sbuffer;
445 
450  unsigned int depth;
451 
456  unsigned int qdepth;
457 
463  unsigned int state;
464 
470  unsigned int esc;
471 
476  unsigned int squoted;
477 
484 
499 
500  /* -----------------------------------------------------------------
501  * These fields below are related to dealing with INLINE_BINARY mode
502  * ----------------------------------------------------------------- */
503 
509  size_t binexpected;
510 
514  size_t binread;
515 
519  char *bindata;
520 
530 
539 typedef struct sexp_iowrap {
544 
549  int fd;
550 
554  char buf[BUFSIZ];
555 
560  size_t cnt;
562 
563 /*========*/
564 /* GLOBAL */
565 /*========*/
566 
572 
573 /*===========*/
574 /* FUNCTIONS */
575 /*===========*/
576 
577 /* this is for C++ users */
578 #ifdef __cplusplus
579 extern "C" {
580 #endif
611 
621 
628 
637  void sexp_cleanup(void);
638 
649  int print_sexp(char *loc, size_t size, const sexp_t *e);
650 
660  int print_sexp_cstr(CSTRING **s, const sexp_t *e, size_t ss);
661 
666 
675  sexp_t *new_sexp_binary_atom(char *data, size_t binlength);
676 
687  sexp_t *new_sexp_atom(const char *buf, size_t bs, atom_t aty);
688 
693 
699 
707 
715 
728 
733  sexp_t *parse_sexp(char *s, size_t len);
734 
740  sexp_t *iparse_sexp(char *s, size_t len, pcont_t *cc);
741 
747  pcont_t *cparse_sexp(char *s, size_t len, pcont_t *pc);
748 
761 
766 
775  void print_pcont(pcont_t * pc, char * buf, size_t buflen);
776 
777 /* this is for C++ users */
778 #ifdef __cplusplus
779 }
780 #endif
781 
782 #include "sexp_ops.h"
783 
784 #endif /* __SEXP_H__ */
785 
Implementation of a fast stack with smart memory management.
sexp_t * read_one_sexp(sexp_iowrap_t *iow)
void destroy_iowrap(sexp_iowrap_t *iow)
sexp_iowrap_t * init_iowrap(int fd)
struct sexp_iowrap sexp_iowrap_t
sexp_t * parse_sexp(char *s, size_t len)
pcont_t * cparse_sexp(char *s, size_t len, pcont_t *pc)
sexp_t * iparse_sexp(char *s, size_t len, pcont_t *cc)
sexp_errcode_t set_parser_buffer_params(size_t ss, size_t gs)
sexp_t * new_sexp_list(sexp_t *l)
int print_sexp_cstr(CSTRING **s, const sexp_t *e, size_t ss)
struct pcont pcont_t
pcont_t * init_continuation(char *str)
void sexp_cleanup(void)
void sexp_t_deallocate(sexp_t *s)
atom_t
Definition: sexp.h:170
@ SEXP_BASIC
Definition: sexp.h:174
@ SEXP_DQUOTE
Definition: sexp.h:186
@ SEXP_SQUOTE
Definition: sexp.h:180
@ SEXP_BINARY
Definition: sexp.h:192
elt_t
Definition: sexp.h:139
@ SEXP_LIST
Definition: sexp.h:150
@ SEXP_VALUE
Definition: sexp.h:144
sexp_errcode_t sexp_errno
int print_sexp(char *loc, size_t size, const sexp_t *e)
void print_pcont(pcont_t *pc, char *buf, size_t buflen)
void reset_sexp_errno()
sexp_t * new_sexp_binary_atom(char *data, size_t binlength)
void destroy_sexp(sexp_t *s)
void destroy_continuation(pcont_t *pc)
parsermode_t
Definition: sexp.h:303
@ PARSER_EVENTS_ONLY
Definition: sexp.h:324
@ PARSER_INLINE_BINARY
Definition: sexp.h:313
@ PARSER_NORMAL
Definition: sexp.h:307
struct parser_event_handlers parser_event_handlers_t
sexp_t * new_sexp_atom(const char *buf, size_t bs, atom_t aty)
sexp_t * sexp_t_allocate(void)
struct elt sexp_t
Error conditions are enumerated here along with any routines for translating error codes to human rea...
sexp_errcode_t
Definition: sexp_errors.h:53
Wrappers around basic memory allocation/deallocation routines to allow memory usage limiting....
A collection of useful operations to perform on s-expressions.
Definition: cstring.h:54
Definition: sexp.h:227
struct elt * next
Definition: sexp.h:269
char * val
Definition: sexp.h:246
size_t val_used
Definition: sexp.h:256
atom_t aty
Definition: sexp.h:280
size_t val_allocated
Definition: sexp.h:251
struct elt * list
Definition: sexp.h:262
elt_t ty
Definition: sexp.h:239
size_t binlength
Definition: sexp.h:296
char * bindata
Definition: sexp.h:291
Definition: sexp.h:338
void(* start_sexpr)()
Definition: sexp.h:343
void(* end_sexpr)()
Definition: sexp.h:349
void(* binary)(const char *data, size_t len)
Definition: sexp.h:365
void(* characters)(const char *data, size_t len, atom_t aty)
Definition: sexp.h:357
Definition: sexp.h:395
parser_event_handlers_t * event_handlers
Definition: sexp.h:528
char * val
Definition: sexp.h:413
unsigned int esc
Definition: sexp.h:470
unsigned int state
Definition: sexp.h:463
size_t val_used
Definition: sexp.h:423
size_t binexpected
Definition: sexp.h:509
unsigned int depth
Definition: sexp.h:450
size_t binread
Definition: sexp.h:514
sexp_errcode_t error
Definition: sexp.h:483
unsigned int squoted
Definition: sexp.h:476
char * vcur
Definition: sexp.h:429
size_t val_allocated
Definition: sexp.h:418
faststack_t * stack
Definition: sexp.h:399
unsigned int qdepth
Definition: sexp.h:456
parsermode_t mode
Definition: sexp.h:498
sexp_t * last_sexp
Definition: sexp.h:408
char * lastPos
Definition: sexp.h:437
char * sbuffer
Definition: sexp.h:444
char * bindata
Definition: sexp.h:519
Definition: sexp.h:539
int fd
Definition: sexp.h:549
pcont_t * cc
Definition: sexp.h:543
size_t cnt
Definition: sexp.h:560
char buf[BUFSIZ]
Definition: sexp.h:554
Definition: faststack.h:78