X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=util.h;h=3855a8227a9dfc801a8c49f0cb091e1e30f57f42;hb=60900035e6d0309705f2326ee50edc52386305e9;hp=cf197fe9d63d4fca0a83dcfe8ce592d800879d52;hpb=e15efca6667b2673b4c1a5879a6917eab6800e58;p=polyglot.git diff --git a/util.h b/util.h index cf197fe..3855a82 100644 --- a/util.h +++ b/util.h @@ -7,6 +7,9 @@ // includes #include +#include +#include +#include // defines @@ -65,6 +68,36 @@ #define snprintf _snprintf #endif +#define FormatBufferSize 4096 + +#ifdef _MSC_VER +#define vsnprintf _vsnprintf +#endif + +#define CONSTRUCT_ARG_STRING(format,buf) \ + { \ + va_list arg_list; \ + int written; \ + va_start(arg_list,format); \ + written=vsnprintf(buf, \ + sizeof(buf), \ + format, \ + arg_list); \ + va_end(arg_list); \ + buf[sizeof(buf)-1]='\0'; \ + if(written>=sizeof(buf) || written<0){ \ + my_fatal("write_buffer overflow: file \"%s\", line %d\n", \ + __FILE__,__LINE__); \ + } \ + } \ + +#define TO_BOOL(string) ((my_string_case_equal(string,"false") || \ + my_string_equal(string,"0"))?FALSE:TRUE) + +#define IS_BOOL(string) (my_string_case_equal(string,"false")|| \ + my_string_case_equal(string,"true") || \ + my_string_case_equal(string,"1") || \ + my_string_case_equal(string,"0")) // types typedef signed char sint8; @@ -92,6 +125,7 @@ typedef struct { bool running; } my_timer_t; + // functions extern void util_init (); @@ -115,11 +149,20 @@ extern void my_log (const char format[], ...); extern void my_fatal (const char format[], ...); extern bool my_file_read_line (FILE * file, char string[], int size); +extern void my_path_join (char *join_path, const char *path, const char *file); + +extern int my_mkdir (const char *path); extern bool my_string_empty (const char string[]); extern bool my_string_whitespace (const char string[]); extern bool my_string_equal (const char string_1[], const char string_2[]); extern bool my_string_case_equal (const char string_1[], const char string_2[]); +extern const char* my_string_case_contains(const char haystack[], + const char needle[]); + + +extern bool my_string_to_lower (char dst[], const char src[]); + extern char * my_strdup (const char string[]); extern void my_string_clear (const char * * variable); @@ -135,8 +178,14 @@ extern double my_timer_elapsed_real (const my_timer_t * timer); extern char * my_error(); -extern char * my_getcwd (char *buf, size_t size); -extern int my_chdir (const char *path); +extern void my_dequote (char *out, + const char *in, + const char *special); +extern void my_quote (char *out, + const char *in, + const char *special); + +extern void my_sleep (int msec); #endif // !defined UTIL_H