#include #include #include #include #include #include #include "tmvttext.h" static void* text_new(TMPool pool,TMValueType vtype); static void* text_new_from_string(TMPool pool,TMValueType vtype, const char *s); static int text_equal(TMValueType, const void *, const void*); static void text_free(TMPool pool,TMValueType vtype, void *s); static int text_to_string(TMValueType, const void *text, char* buf, size_t size); static int text_to_xml(TMValueType, const void *text, char* buf, size_t size); static void *text_parse_argstring(TMPool pool,TMValueType vtype, int opcode, const char *argstring); static struct op_table ops[] = { { "=" , TM_OP_Text_EQUAL }, { "LIKE" , TM_OP_Text_LIKE }, { NULL, 0 } }; struct TMValueType Text = { "Text", 0, /* values do not contain topics */ text_new, text_new_from_string, text_to_string, text_to_xml, text_equal, text_free, NULL, ops, text_parse_argstring }; void* text_new(TMPool pool,TMValueType vtype) { assert(0); /* FIXME does not make sense, but if NULLs allowd...?! */ return NULL; } void* text_new_from_string(TMPool pool,TMValueType vtype, const char *s) { char *self; if(*s == '\'') s++; self = tm_strdup(pool,s); if(self[strlen(self)-1] == '\'') self[strlen(self)-1] = '\0'; return self; } void text_free(TMPool pool,TMValueType vtype, void *s) { assert(s); /* FIXME: allow NULLs?? */ TM_FREE(pool,s); } int text_to_string(TMValueType vtype, const void *text, char* buf, size_t size) { return ( snprintf(buf,size,"%s", text ? (char*)text : "") ); } int text_to_xml(TMValueType vtype,const void *text, char* buf, size_t size) { int n; n = snprintf(buf,size," %s",(char*)text); assert(n < size); return n; } int text_equal(TMValueType vtype, const void *lhs, const void *rhs) { assert(lhs); assert(rhs); return ( strcmp((const char*)lhs,(const char *)rhs) == 0); } void *text_parse_argstring(TMPool pool,TMValueType vtype, int opcode, const char *argstring) { switch(opcode) { case TM_OP_Text_EQUAL: return tm_strdup(pool,argstring); case TM_OP_Text_LIKE: return tm_strdup(pool,argstring); default: assert(0); } return NULL; }