00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00033 #ifndef QOF_UTIL_H
00034 #define QOF_UTIL_H
00035
00036 #include <glib.h>
00037 #include <stddef.h>
00038 #include "config.h"
00039 #include "qof.h"
00040
00041
00042
00052 #define SAFE_STRCMP_REAL(fcn,da,db) { \
00053 if ((da) && (db)) { \
00054 if ((da) != (db)) { \
00055 int retval = fcn ((da), (db)); \
00056 \
00057 if (retval) return retval; \
00058 } \
00059 } else \
00060 if ((!(da)) && (db)) { \
00061 return -1; \
00062 } else \
00063 if ((da) && (!(db))) { \
00064 return +1; \
00065 } \
00066 }
00067
00069 #define SAFE_STRCMP(da,db) SAFE_STRCMP_REAL(strcmp,(da),(db))
00070
00071 #define SAFE_STRCASECMP(da,db) SAFE_STRCMP_REAL(strcasecmp,(da),(db))
00072
00076 #define ENUM_BODY(name, value) \
00077 name value,
00078
00079 #define AS_STRING_CASE(name, value) \
00080 case name: { return #name; }
00081
00082 #define FROM_STRING_CASE(name, value) \
00083 if (strcmp(str, #name) == 0) { \
00084 return name; }
00085
00086 #define DEFINE_ENUM(name, list) \
00087 typedef enum { \
00088 list(ENUM_BODY) \
00089 }name;
00090
00091 #define AS_STRING_DEC(name, list) \
00092 const char* name##asString(name n);
00093
00094 #define AS_STRING_FUNC(name, list) \
00095 const char* name##asString(name n) { \
00096 switch (n) { \
00097 list(AS_STRING_CASE) \
00098 default: return ""; } }
00099
00100 #define FROM_STRING_DEC(name, list) \
00101 name name##fromString \
00102 (const char* str);
00103
00104 #define FROM_STRING_FUNC(name, list) \
00105 name name##fromString \
00106 (const char* str) { \
00107 if(str == NULL) { return 0; } \
00108 list(FROM_STRING_CASE) \
00109 return 0; }
00110
00122 #define FROM_STRING_DEC_NON_TYPEDEF(name, list) \
00123 void name##fromString \
00124 (const char* str, enum name *type);
00125
00126 #define FROM_STRING_CASE_NON_TYPEDEF(name, value) \
00127 if (strcmp(str, #name) == 0) { *type = name; }
00128
00129 #define FROM_STRING_FUNC_NON_TYPEDEF(name, list) \
00130 void name##fromString \
00131 (const char* str, enum name *type) { \
00132 if(str == NULL) { return; } \
00133 list(FROM_STRING_CASE_NON_TYPEDEF) }
00134
00135 #define AS_STRING_DEC_NON_TYPEDEF(name, list) \
00136 const char* name##asString(enum name n);
00137
00138 #define AS_STRING_FUNC_NON_TYPEDEF(name, list) \
00139 const char* name##asString(enum name n) { \
00140 switch (n) { \
00141 list(AS_STRING_CASE_NON_TYPEDEF) \
00142 default: return ""; } }
00143
00144 #define AS_STRING_CASE_NON_TYPEDEF(name, value) \
00145 case name: { return #name; }
00146
00149
00150 #if HAVE_SCANF_LLD
00151 # define GNC_SCANF_LLD "%lld"
00152 #else
00153 # define GNC_SCANF_LLD "%qd"
00154 #endif
00155
00165 void qof_init (void);
00166
00173 void qof_close (void);
00174
00177
00178
00192 int safe_strcmp (const char * da, const char * db);
00193
00206 int safe_strcasecmp (const char * da, const char * db);
00207
00212 int null_strcmp (const char * da, const char * db);
00213
00217 extern char *strncasestr(const char *str1, const char *str2, size_t len);
00218 extern char *strcasestr(const char *str1, const char *str2);
00219
00223 char * ultostr (unsigned long val, int base);
00224
00227 gboolean gnc_strisnum(const char *s);
00228
00230 char * gnc_stpcpy (char *dest, const char *src);
00231
00232 #ifndef HAVE_STPCPY
00233 #define stpcpy gnc_stpcpy
00234 #endif
00235
00239 const char * qof_util_whitespace_filter (const char * val);
00240
00244 int qof_util_bool_to_int (const char * val);
00245
00246
00281 GCache* gnc_engine_get_string_cache(void);
00282
00284 void gnc_engine_string_cache_destroy (void);
00285
00289 void gnc_string_cache_remove(gconstpointer key);
00290
00294 gpointer gnc_string_cache_insert(gpointer key);
00295
00296 #define CACHE_INSERT(str) gnc_string_cache_insert((gpointer)(str));
00297 #define CACHE_REMOVE(str) gnc_string_cache_remove((str));
00298
00299 #endif
00300