]> git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - gmqcc.h
Fix alignment issues (can remove a clang warning, and also makes our code more portable!)
[xonotic/gmqcc.git] / gmqcc.h
diff --git a/gmqcc.h b/gmqcc.h
index 747aef4862ad7069d3a3500e6415661e457dac6a..ed371f5716d476c7d0f0063cd0b57b86edb9ef4a 100644 (file)
--- a/gmqcc.h
+++ b/gmqcc.h
  */
 #ifdef _MSC_VER
 #   pragma warning(disable : 4244 ) /* conversion from 'int' to 'float', possible loss of data */
-#   pragma warning(disable : 4018 ) /* signed/unsigned mismatch                                */
 #endif /*! _MSC_VER */
 
 #define GMQCC_VERSION_MAJOR 0
-#define GMQCC_VERSION_MINOR 3
-#define GMQCC_VERSION_PATCH 0
+#define GMQCC_VERSION_MINOR 2
+#define GMQCC_VERSION_PATCH 9
 #define GMQCC_VERSION_BUILD(J,N,P) (((J)<<16)|((N)<<8)|(P))
 #define GMQCC_VERSION \
     GMQCC_VERSION_BUILD(GMQCC_VERSION_MAJOR, GMQCC_VERSION_MINOR, GMQCC_VERSION_PATCH)
@@ -168,17 +167,6 @@ GMQCC_IND_STRING(GMQCC_VERSION_PATCH) \
     typedef __int64          int64_t;
 #endif /*! _MSC_VER */
 
-/* 
- *windows makes these prefixed because they're C99
- * TODO: utility versions that are type-safe and not
- * just plain textual subsitution.
- */
-#ifdef _MSC_VER
-#    define snprintf(X, Y, Z, ...) _snprintf(X, Y, Z, __VA_ARGS__)
-    /* strtof doesn't exist -> strtod does though :) */
-#    define strtof(X, Y)          (float)(strtod(X, Y))
-#endif /*! _MSC_VER */
-
 /*
  * Very roboust way at determining endianess at compile time: this handles
  * almost every possible situation.  Otherwise a runtime check has to be
@@ -263,7 +251,7 @@ GMQCC_IND_STRING(GMQCC_VERSION_PATCH) \
  * On windows systems where we're not compiling with MING32 we need a
  * little extra help on dependinces for implementing our own dirent.h
  * in fs.c.
- */   
+ */
 #if defined(_WIN32) && !defined(__MINGW32__)
 #   define _WIN32_LEAN_AND_MEAN
 #   include <windows.h>
@@ -275,7 +263,7 @@ GMQCC_IND_STRING(GMQCC_VERSION_PATCH) \
         unsigned short     d_reclen;
         unsigned short     d_namlen;
         char               d_name[FILENAME_MAX];
-    }
+    };
 
     typedef struct {
         struct _finddata_t dd_dta;
@@ -284,6 +272,14 @@ GMQCC_IND_STRING(GMQCC_VERSION_PATCH) \
         int                dd_stat;
         char               dd_name[1];
     } DIR;
+    /*
+     * Visual studio also lacks S_ISDIR for sys/stat.h, so we emulate this as well
+     * which is not hard at all.
+     */
+#    ifdef S_ISDIR
+#        undef  S_ISDIR
+#    endif /*! S_ISDIR */
+#   define S_ISDIR(X) ((X)&_S_IFDIR)
 #else
 #   include <dirent.h>
 #endif /*! _WIN32 && !defined(__MINGW32__) */
@@ -313,8 +309,18 @@ uint16_t util_crc16(uint16_t crc, const char *data, size_t len);
 void     util_seed(uint32_t);
 uint32_t util_rand();
 
-int util_vasprintf(char **ret, const char *fmt, va_list);
-int util_asprintf (char **ret, const char *fmt, ...);
+/*
+ * String functions (formatting, copying, concatenating, errors). These are wrapped
+ * to use the MSVC _safe_ versions when using MSVC, plus some implementations of
+ * these are non-conformant or don't exist such as asprintf and snprintf, which are
+ * not supported in C90, but do exist in C99.
+ */
+int         util_vasprintf(char **ret, const char *fmt, va_list);
+int         util_asprintf (char **ret, const char *fmt, ...);
+int         util_snprintf (char *src,  size_t bytes, const char *format, ...);
+char       *util_strcat   (char *dest, const char *src);
+char       *util_strncpy  (char *dest, const char *src, size_t num);
+const char *util_strerror (int num);
 
 
 #ifdef NOTRACK
@@ -355,7 +361,7 @@ void _util_vec_grow(void **a, size_t i, size_t s);
 )
 
 /* exposed interface */
-#define vec_meta(A)       (((vector_t*)(A)) - 1)
+#define vec_meta(A)       (((vector_t*)((void*)A)) - 1)
 #define vec_free(A)       ((void)((A) ? (mem_d((void*)vec_meta(A)), (A) = NULL) : 0))
 #define vec_push(A,V)     (GMQCC_VEC_WILLGROW((A),1), (A)[vec_meta(A)->used++] = (V))
 #define vec_size(A)       ((A) ? vec_meta(A)->used : 0)
@@ -380,14 +386,6 @@ typedef struct hash_table_t {
     struct hash_node_t **table;
 } hash_table_t, *ht;
 
-typedef struct hash_set_t {
-    size_t  bits;
-    size_t  mask;
-    size_t  capacity;
-    size_t *items;
-    size_t  total;
-} hash_set_t, *hs;
-
 /*
  * hashtable implementation:
  *
@@ -430,44 +428,6 @@ void          util_htrm  (hash_table_t *ht, const char *key, void (*cb)(void*));
 void         *util_htget (hash_table_t *ht, const char *key);
 void         *util_htgeth(hash_table_t *ht, const char *key, size_t hash);
 
-/*
- * hashset implementation:
- *      This was designed for pointers:  you manage the life of the object yourself
- *      if you do use this for non-pointers please be warned that the object may not
- *      be valid if the duration of it exceeds (i.e on stack).  So you need to allocate
- *      yourself, or put those in global scope to ensure duration is for the whole
- *      runtime.
- *
- * util_hsnew()                             -- to make a new hashset
- * util_hsadd(set, key)                     -- to add something in the set
- * util_hshas(set, key)                     -- to check if something is in the set
- * util_hsrem(set, key)                     -- to remove something in the set
- * util_hsdel(set)                          -- to delete the set
- *
- * example of use:
- * 
- * hs    foo = util_hsnew();
- * char *bar = "hello blub\n";
- * char *baz = "hello dale\n";
- *
- * util_hsadd(foo, bar);
- * util_hsadd(foo, baz);
- * util_hsrem(foo, baz);
- *
- * printf("bar %d | baz %d\n",
- *     util_hshas(foo, bar),
- *     util_hshad(foo, baz)
- * );
- *
- * util_hsdel(foo);  
- */
-
-hash_set_t *util_hsnew(void);
-int         util_hsadd(hash_set_t *, void *);
-int         util_hshas(hash_set_t *, void *);
-int         util_hsrem(hash_set_t *, void *);
-void        util_hsdel(hash_set_t *);
 /*===================================================================*/
 /*============================ file.c ===============================*/
 /*===================================================================*/
@@ -478,7 +438,7 @@ int            fs_file_getc   (FILE *);
 int            fs_file_printf (FILE *, const char *, ...);
 int            fs_file_puts   (FILE *, const char *);
 int            fs_file_seek   (FILE *, long int, int);
-long int       fs_file_tell   (FILE *); 
+long int       fs_file_tell   (FILE *);
 
 size_t         fs_file_read   (void *,        size_t, size_t, FILE *);
 size_t         fs_file_write  (const void *,  size_t, size_t, FILE *);
@@ -1052,9 +1012,11 @@ typedef struct {
 
 /*
  * line, file, counter, counter_last, random, random_last, date, time
+ * time_stamp.
+ * 
  * increment when items are added
  */
-#define FTEPP_PREDEF_COUNT 8
+#define FTEPP_PREDEF_COUNT 9
 
 struct ftepp_s *ftepp_create           ();
 bool            ftepp_preprocess_file  (struct ftepp_s *ftepp, const char *filename);