#ifndef _LIBSE_H #define _LIBSE_H #include typedef struct { void* ptr; int size; int alloced; int sexpr; } car_t; typedef struct cons { union { void* ptr; struct cons* car_l; char* car_s; car_t car; }; struct cons* cdr; } list_t; enum _se_type { SE_NIL=0, SE_STRING, SE_LIST, }; #define SET_PARSE_NIL (1<<0) //Parse `NIL' as null pointer #define SET_PARSE_QUOTE (1<<1) //Parse "string quotes" #define SET_PARSE_ESCAPE (1<<2) //Parse "escape \" sequences \"" #define SET_PARSE_INSENSITIVE (1<<3) //PARSE ALL AS UPPERCASE #define SET_NO_WRAP (1<<4) //Interpret "(one two three)" as (one two three) instead of ((one two three)) #define SETP_DEFAULT (SET_PARSE_QUOTE | SET_PARSE_ESCAPE) #define SETP_LISP (SETP_DEFAULT | SET_PARSE_INSENSITIVE | SET_PARSE_NIL) #define se_parsed(s) se_parse((s), SET_DEFAULT) list_t* se_parse(const char* sexpr, unsigned int flags); //Parse string into list. void se_free(list_t* list); //Free whole list. void se_print(FILE* fp, const list_t* list); //Print list to fp, if fp is NULL, print to stdout. enum _se_type se_typeof(list_t* cons); //Get type of cons's car value. list_t* se_new(char* from, int dupe); //Create new cons. #define se_newd(f) se_new((f), 1) list_t* se_last(list_t* list); //Get last non-nil cons. car_t se_make(const char* fmt); //Parse "input" as string and "(input)" as sexpr and return as car_t. (NULL returns NIL). void se_rplaca(list_t* cons, car_t car); //Replace car of cons with `car' void se_rplacd(list_t* cons, list_t* cdr); //Replace cdr of cons with 'cdr' #endif /* _LIBSE_H */