]> git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - gmqcc.h
Resolve undefined functions to compiler builtins if they exist.
[xonotic/gmqcc.git] / gmqcc.h
diff --git a/gmqcc.h b/gmqcc.h
index b7f1f8f6c781e0150da831fa7e16bd0465c9dd54..bf506fff895812040a49a4fe7abe2e2df0300e36 100644 (file)
--- a/gmqcc.h
+++ b/gmqcc.h
@@ -24,7 +24,8 @@
 #ifndef GMQCC_HDR
 #define GMQCC_HDR
 #include <stdarg.h>
-#include <stdio.h> /* TODO: remove this */
+#include <stddef.h>
+#include <time.h>   /* TODO: remove?*/
 
 /*
  * Disable some over protective warnings in visual studio because fixing them is a waste
@@ -35,8 +36,8 @@
 #endif /*! _MSC_VER */
 
 #define GMQCC_VERSION_MAJOR 0
-#define GMQCC_VERSION_MINOR 4
-#define GMQCC_VERSION_PATCH 0
+#define GMQCC_VERSION_MINOR 3
+#define GMQCC_VERSION_PATCH 6
 #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)
@@ -149,7 +150,7 @@ GMQCC_IND_STRING(GMQCC_VERSION_PATCH) \
 #    define GMQCC_NORETURN
 #endif /*! (defined(__GNUC__) && __GNUC__ >= 2) || defined (__CLANG__) */
 
-#if (defined(__GNUC__)) || defined(__CLANG__)
+#if defined(__GNUC__) || defined(__CLANG__)
 #   define GMQCC_LIKELY(X)   __builtin_expect((X), 1)
 #   define GMQCC_UNLIKELY(X) __builtin_expect((X), 0)
 #else
@@ -157,6 +158,14 @@ GMQCC_IND_STRING(GMQCC_VERSION_PATCH) \
 #   define GMQCC_UNLIKELY(X) (X)
 #endif
 
+#if defined(__GNUC__) || defined(__CLANG__)
+#   define GMQCC_RESTRICT __restrict__
+#elif defined(__MSC_VER)
+#   define GMQCC_RESTRICT __restrict
+#else
+#   define GMQCC_RESTRICT
+#endif
+
 #define GMQCC_ARRAY_COUNT(X) (sizeof(X) / sizeof((X)[0]))
 
 #ifndef _MSC_VER
@@ -255,14 +264,14 @@ GMQCC_IND_STRING(GMQCC_VERSION_PATCH) \
 /* stat.c */
 void  stat_info          (void);
 char *stat_mem_strdup    (const char *, size_t,         const char *, bool);
-void *stat_mem_reallocate(void *,       size_t, size_t, const char *);
+void *stat_mem_reallocate(void *,       size_t, size_t, const char *, const char *);
 void  stat_mem_deallocate(void *);
-void *stat_mem_allocate  (size_t, size_t, const char *);
+void *stat_mem_allocate  (size_t, size_t, const char *, const char *);
 
-#define mem_a(SIZE)              stat_mem_allocate  ((SIZE), __LINE__, __FILE__)
+#define mem_a(SIZE)              stat_mem_allocate  ((SIZE), __LINE__, __FILE__, #SIZE)
 #define mem_d(PTRN)              stat_mem_deallocate((void*)(PTRN))
-#define mem_r(PTRN, SIZE)        stat_mem_reallocate((void*)(PTRN), (SIZE), __LINE__, __FILE__)
-#define mem_af(SIZE, FILE, LINE) stat_mem_allocate  ((SIZE), (LINE), (FILE))
+#define mem_r(PTRN, SIZE)        stat_mem_reallocate((void*)(PTRN), (SIZE), __LINE__, __FILE__, #SIZE)
+#define mem_af(SIZE, FILE, LINE) stat_mem_allocate  ((SIZE), (LINE), (FILE), #SIZE)
 
 /* TODO: rename to mem variations */
 #define util_strdup(SRC)         stat_mem_strdup((char*)(SRC), __LINE__, __FILE__, false)
@@ -301,8 +310,19 @@ uint16_t util_crc16(uint16_t crc, const char *data, size_t len);
 void     util_seed(uint32_t);
 uint32_t util_rand(void);
 
-int      util_vasprintf(char **ret, const char *fmt, va_list);
 int      util_asprintf (char **ret, const char *fmt, ...);
+int      util_sscanf   (const char *str, const char *format, ...);
+char    *util_strncpy  (char *dest, const char *src, size_t n);
+char    *util_strncat  (char *dest, const char *src, size_t n);
+char    *util_strcat   (char *dest, const char *src);
+const char *util_strerror(int err);
+
+const struct tm *util_localtime(const time_t *timer);
+const char      *util_ctime    (const time_t *timer);
+
+typedef struct fs_file_s fs_file_t;
+
+bool             util_isatty(fs_file_t *);
 
 /*
  * A flexible vector implementation: all vector pointers contain some
@@ -386,10 +406,17 @@ 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);
 
+int           util_snprintf(char *str, size_t, const char *fmt, ...);
+
 
 /* fs.c */
+#define FS_FILE_SEEK_SET  0
+#define FS_FILE_SEEK_CUR  1
+#define FS_FILE_SEEK_END  2
+#define FS_FILE_EOF      -1
+
 typedef struct fs_dir_s  fs_dir_t;
-typedef struct fs_file_s fs_file_t;
+/*typedef struct fs_file_s fs_file_t;*/
 typedef struct dirent    fs_dirent_t;
 
 void           fs_file_close  (fs_file_t *);
@@ -412,6 +439,7 @@ fs_dir_t      *fs_dir_open    (const char *);
 int            fs_dir_close   (fs_dir_t *);
 fs_dirent_t   *fs_dir_read    (fs_dir_t *);
 
+
 /* correct.c */
 typedef struct correct_trie_s {
     void                  *value;
@@ -991,11 +1019,19 @@ typedef enum {
     COMPILER_GMQCC    /* this   QuakeC */
 } opts_std_t;
 
-typedef union {
-    bool     B;
-    uint16_t U16;
-    uint32_t U32;
-    char    *STR;
+typedef struct {
+    union {
+        bool     b;
+        uint16_t u16;
+        uint32_t u32;
+
+        union {
+            char       *p;
+            const char *c;
+        } str;
+    } data;
+
+    bool allocated;
 } opt_value_t;
 
 
@@ -1017,9 +1053,11 @@ extern opts_cmd_t opts;
 #define OPTS_WARN(i)         OPTS_GENERIC(opts.warn,         (i))
 #define OPTS_WERROR(i)       OPTS_GENERIC(opts.werror,       (i))
 #define OPTS_OPTIMIZATION(i) OPTS_GENERIC(opts.optimization, (i))
-#define OPTS_OPTION_BOOL(X) (opts.options[X].B)
-#define OPTS_OPTION_U16(X)  (opts.options[X].U16)
-#define OPTS_OPTION_U32(X)  (opts.options[X].U32)
-#define OPTS_OPTION_STR(X)  (opts.options[X].STR)
+#define OPTS_OPTION_DUPED(X) (opts.options[X].allocated)
+#define OPTS_OPTION_BOOL(X) (opts.options[X].data.b)
+#define OPTS_OPTION_U16(X)  (opts.options[X].data.u16)
+#define OPTS_OPTION_U32(X)  (opts.options[X].data.u32)
+#define OPTS_OPTION_DUP(X) *(OPTS_OPTION_DUPED(X)=true, &(opts.options[X].data.str.p))
+#define OPTS_OPTION_STR(X)  (opts.options[X].data.str.c)
 
 #endif /*! GMQCC_HDR */