X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=util.h;h=3855a8227a9dfc801a8c49f0cb091e1e30f57f42;hb=de010509fa0e57ba955da6512c714fbff8606af3;hp=759cd16fae2baa7ffc73d20a04e56f37a923f290;hpb=ad2265d4fc54fc9ba99fc606e6174df34bfb4a0f;p=polyglot.git diff --git a/util.h b/util.h index 759cd16..3855a82 100644 --- a/util.h +++ b/util.h @@ -6,9 +6,25 @@ // includes -#include +#include +#include +#include +#include + +// defines + +#ifndef EXIT_SUCCES +#define EXIT_SUCCES 0 +#endif + +#ifndef STDIN_FILENO +#define STDIN_FILENO 0 +#endif + +#ifndef STDOUT_FILENO +#define STDOUT_FILENO 1 +#endif -// constants #undef FALSE #define FALSE 0 @@ -52,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; @@ -63,6 +109,8 @@ typedef unsigned short uint16; typedef signed int sint32; typedef unsigned int uint32; +typedef int bool; + #ifdef _MSC_VER typedef signed __int64 sint64; typedef unsigned __int64 uint64; @@ -71,28 +119,15 @@ typedef unsigned int uint32; typedef unsigned long long int uint64; #endif -struct my_timer_t { +typedef struct { double start_real; double elapsed_real; bool running; -}; +} my_timer_t; + // functions -#ifdef _WIN32 - #include - inline void Idle(void) { - Sleep(1); - } - inline void Idle500msecs(void){ - Sleep(500); - } -#else - #include - inline void Idle(void) { - usleep(1000); - } -#endif extern void util_init (); extern void my_random_init (); @@ -114,22 +149,43 @@ 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); extern void my_string_set (const char * * variable, const char string[]); +extern double now_real (); + extern void my_timer_reset (my_timer_t * timer); extern void my_timer_start (my_timer_t * timer); extern void my_timer_stop (my_timer_t * timer); extern double my_timer_elapsed_real (const my_timer_t * timer); +extern char * my_error(); + +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