00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00026 #ifndef UTIL_H
00027 #define UTIL_H
00028
00029 #ifdef HAVE_CONFIG_H
00030 # include <config.h>
00031 #endif
00032
00033 #ifdef WITH_DMALLOC
00034 # include <dmalloc.h>
00035 #endif
00036
00037 #include <stdio.h>
00038
00039 #include <glib.h>
00040
00041 #include "gcontainer.h"
00042
00043 #ifdef WITH_GTHREAD
00044 # ifdef G_THREADS_ENABLED
00045 # ifndef G_THREADS_IMPL_NONE
00046 # define USE_GTHREADS
00047 # endif
00048 # endif
00049 #endif
00050
00051 #ifndef USE_GTHREADS
00052 # ifdef G_LOCK
00053 # undef G_LOCK
00054 # endif
00055 # ifdef G_UNLOCK
00056 # undef G_UNLOCK
00057 # endif
00058 # ifdef G_THREADS_ENABLED
00059 # undef G_THREADS_ENABLED
00060 # endif
00061 # define G_LOCK(arg)
00062 # define G_UNLOCK(arg)
00063 #endif
00064
00065 #ifdef WITH_LEAKBUG
00066 # include <leakbug.h>
00067 # define LB_REGISTER(ptr, dataSize) lbRegister((ptr), (dataSize), __FILE__, __LINE__, LEAKBUG_DEBUG_LEVEL)
00068 # define g_free(ptr) if (ptr != NULL) { free(ptr); }
00069 # define g_strdup strdup
00070 # define g_calloc calloc
00071 # define g_malloc malloc
00072 # define g_realloc realloc
00073 #else
00074 # define LB_REGISTER(ptr, dataSize)
00075 #endif
00076
00078 #ifdef DEBUG
00079 # define DBUGOUT(args...) do { printf("luau: %s: %s: ", __FILE__, __func__); printf(args); printf("\n"); } while (0)
00080 #else
00081 # define DBUGOUT(args...)
00082 #endif
00083
00085 #define nnull_g_string_free(ptr, boole) do { \
00086 if (ptr != NULL) { g_string_free(ptr, boole); } \
00087 } while (0)
00088
00090 #define nnull_g_free(ptr) do { \
00091 if (ptr != NULL) { g_free(ptr); } \
00092 } while (0)
00093
00094
00095
00097 #define TEMP_DIR "/tmp"
00098
00099
00101 inline int lutil_streq(const char *str1, const char *str2);
00103 inline int lutil_strcaseeq(const char *str1, const char *str2);
00105 char* lutil_createString(int length);
00107 char* lutil_vstrcreate(const char *src1, ...);
00109 char* lutil_mprintf(const char *template, ...);
00111 char* lutil_strjoin(const char *delim, const GContainer *strings);
00113 GContainer* lutil_gsplit(const char *delim, const char *str);
00114 char* lutil_valistToString(const char *template, va_list args);
00116 gboolean lutil_findString(const GContainer *array, const char *string);
00118 void lutil_printIndented(int indent, int length, const char *string);
00120 gboolean lutil_isCompletelyBlank(const char *input);
00122 void lutil_strToLower(char *str);
00123 void lutil_strToUpper(char *str);
00124 gboolean lutil_containsAlpha(const char *str);
00125 gboolean lutil_containsDigit(const char *str);
00126
00127 GString* lutil_uncompress(GString *data);
00128
00129
00130
00132 char* lutil_getTempFilename(void);
00134 gboolean lutil_fileExists(const char *path);
00136 gboolean lutil_isDirectory(const char *path);
00137
00138
00140 gint lutil_gintCompare(gpointer p1, gpointer p2);
00142 int lutil_intcmp(int i1, int i2);
00143 char* lutil_sizeToString(int size, int sigfig);
00144
00145
00146 #endif