]> de.git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
Remove fs.c ansi.c and PORTING guide
authorDale Weiler <weilercdale@gmail.com>
Wed, 14 Jan 2015 02:25:17 +0000 (21:25 -0500)
committerDale Weiler <weilercdale@gmail.com>
Wed, 14 Jan 2015 02:25:17 +0000 (21:25 -0500)
Makefile
PORTING [deleted file]
ansi.c [deleted file]
fs.c [deleted file]
gmqcc.h
main.c
opts.c
platform.h [deleted file]
test.c
util.c

index 9b02469eb50a46172c7d80f72115f634e72f5e32..fdb173ea432ef03ae205989905b3654f442e030f 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -2,9 +2,9 @@ CC ?= clang
 CFLAGS = -MD -std=gnu99 -Wall -Wextra -pedantic-errors -g3
 LDFLAGS = -lm
 
 CFLAGS = -MD -std=gnu99 -Wall -Wextra -pedantic-errors -g3
 LDFLAGS = -lm
 
-CSRCS = ansi.c ast.c code.c conout.c fold.c fs.c ftepp.c hash.c intrin.c ir.c lexer.c main.c opts.c parser.c stat.c utf8.c util.c
-TSRCS = ansi.c conout.c fs.c hash.c opts.c stat.c test.c util.c
-VSRCS = ansi.c exec.c fs.c hash.c stat.c util.c
+CSRCS = ast.c code.c conout.c fold.c ftepp.c hash.c intrin.c ir.c lexer.c main.c opts.c parser.c stat.c utf8.c util.c
+TSRCS = conout.c hash.c opts.c stat.c test.c util.c
+VSRCS = exec.c hash.c stat.c util.c
 
 COBJS = $(CSRCS:.c=.o)
 TOBJS = $(TSRCS:.c=.o)
 
 COBJS = $(CSRCS:.c=.o)
 TOBJS = $(TSRCS:.c=.o)
diff --git a/PORTING b/PORTING
deleted file mode 100644 (file)
index bbdb274..0000000
--- a/PORTING
+++ /dev/null
@@ -1,4 +0,0 @@
-Porting gmqcc to a new platform is farily trivial, in most cases ansi.c
-will be sufficent enough to get it to run on your favorite platform. If
-however it isn't you can duplicate ansi.c and change it accordingly.
-Changes to platform.h may also be required.
diff --git a/ansi.c b/ansi.c
deleted file mode 100644 (file)
index 02db1b9..0000000
--- a/ansi.c
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright (C) 2012, 2013, 2014, 2015
- *     Dale Weiler
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy of
- * this software and associated documentation files (the "Software"), to deal in
- * the Software without restriction, including without limitation the rights to
- * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
- * of the Software, and to permit persons to whom the Software is furnished to do
- * so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-#include <string.h>
-#include <stdlib.h>
-
-#include "platform.h"
-#include "gmqcc.h"
-
-int platform_vasprintf(char **dat, const char *fmt, va_list args) {
-    int     ret;
-    int     len;
-    char   *tmp = NULL;
-    char    buf[128];
-    va_list cpy;
-
-    va_copy(cpy, args);
-    len = vsnprintf(buf, sizeof(buf), fmt, cpy);
-    va_end (cpy);
-
-    if (len < 0)
-        return len;
-
-    if (len < (int)sizeof(buf)) {
-        *dat = util_strdup(buf);
-        return len;
-    }
-
-    tmp = (char*)mem_a(len + 1);
-    if ((ret = vsnprintf(tmp, len + 1, fmt, args)) != len) {
-        mem_d(tmp);
-        *dat = NULL;
-        return -1;
-    }
-
-    *dat = tmp;
-    return len;
-}
diff --git a/fs.c b/fs.c
deleted file mode 100644 (file)
index 4c7a178..0000000
--- a/fs.c
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Copyright (C) 2012, 2013, 2014, 2015
- *     Dale Weiler
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy of
- * this software and associated documentation files (the "Software"), to deal in
- * the Software without restriction, including without limitation the rights to
- * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
- * of the Software, and to permit persons to whom the Software is furnished to do
- * so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-#include "gmqcc.h"
-
-int fs_file_getline(char **lineptr, size_t *n, FILE *stream) {
-    int   chr;
-    int   ret;
-    char *pos;
-
-    if (!lineptr || !n || !stream)
-        return -1;
-    if (!*lineptr) {
-        if (!(*lineptr = (char*)mem_a((*n=64))))
-            return -1;
-    }
-
-    chr = *n;
-    pos = *lineptr;
-
-    for (;;) {
-        int c = getc(stream);
-
-        if (chr < 2) {
-            *n += (*n > 16) ? *n : 64;
-            chr = *n + *lineptr - pos;
-            if (!(*lineptr = (char*)mem_r(*lineptr,*n)))
-                return -1;
-            pos = *n - chr + *lineptr;
-        }
-
-        if (ferror(stream))
-            return -1;
-        if (c == EOF) {
-            if (pos == *lineptr)
-                return -1;
-            else
-                break;
-        }
-
-        *pos++ = c;
-        chr--;
-        if (c == '\n')
-            break;
-    }
-    *pos = '\0';
-    return (ret = pos - *lineptr);
-}
diff --git a/gmqcc.h b/gmqcc.h
index 235059debecdebb9c00262a54eeeadc405bd80f1..1bdce34c186ba7fb5e9a78c009326095a5d3c25d 100644 (file)
--- a/gmqcc.h
+++ b/gmqcc.h
@@ -310,22 +310,17 @@ typedef struct hash_table_s {
  * util_htdel(foo);
  */
 hash_table_t *util_htnew (size_t size);
  * util_htdel(foo);
  */
 hash_table_t *util_htnew (size_t size);
-void          util_htrem (hash_table_t *ht, void (*callback)(void *data));
-void          util_htset (hash_table_t *ht, const char *key, void *value);
-void          util_htdel (hash_table_t *ht);
-size_t        util_hthash(hash_table_t *ht, const char *key);
-void          util_htseth(hash_table_t *ht, const char *key, size_t hash, void *value);
-void          util_htrmh (hash_table_t *ht, const char *key, size_t bin, void (*cb)(void*));
-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 */
-int fs_file_getline(char  **, size_t *, FILE *);
+void util_htrem(hash_table_t *ht, void (*callback)(void *data));
+void util_htset(hash_table_t *ht, const char *key, void *value);
+void util_htdel(hash_table_t *ht);
+size_t util_hthash(hash_table_t *ht, const char *key);
+void util_htseth(hash_table_t *ht, const char *key, size_t hash, void *value);
+void util_htrmh(hash_table_t *ht, const char *key, size_t bin, void (*cb)(void*));
+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, ...);
+int util_getline(char  **, size_t *, FILE *);
 
 /* code.c */
 
 
 /* code.c */
 
diff --git a/main.c b/main.c
index 9f64baf4b45aef79174a50b5aad6b41b3cf11629..3f6f6ef29318a6df614fa1eb25d24864c5a2118a 100644 (file)
--- a/main.c
+++ b/main.c
@@ -531,7 +531,7 @@ static bool progs_nextline(char **out, size_t *alen, FILE *src) {
     char  *end;
 
     line = *out;
     char  *end;
 
     line = *out;
-    len  = fs_file_getline(&line, alen, src);
+    len  = util_getline(&line, alen, src);
     if (len == -1)
         return false;
 
     if (len == -1)
         return false;
 
diff --git a/opts.c b/opts.c
index 116792f05a12e646520896ac45e873c31b45ac9b..272d3f738bb4a042883acc6ffe55c198902e4b01 100644 (file)
--- a/opts.c
+++ b/opts.c
@@ -234,7 +234,7 @@ static size_t opts_ini_parse (
     char *read_name;
     char *read_value;
 
     char *read_name;
     char *read_value;
 
-    while (fs_file_getline(&line, &linesize, filehandle) != EOF) {
+    while (util_getline(&line, &linesize, filehandle) != EOF) {
         parse_beg = line;
 
         /* handle BOM */
         parse_beg = line;
 
         /* handle BOM */
diff --git a/platform.h b/platform.h
deleted file mode 100644 (file)
index f4bd9ef..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright (C) 2012, 2013, 2014, 2015
- *     Dale Weiler
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy of
- * this software and associated documentation files (the "Software"), to deal in
- * the Software without restriction, including without limitation the rights to
- * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
- * of the Software, and to permit persons to whom the Software is furnished to do
- * so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-#ifndef GMQCC_PLATFORM_HDR
-#define GMQCC_PLATFORM_HDR
-
-#include <stdarg.h>
-#include <time.h>
-#include <stdio.h>
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <dirent.h>
-
-int platform_vasprintf(char **dat, const char *fmt, va_list args);
-
-#endif
diff --git a/test.c b/test.c
index f15d1fb6194c29ffb4f5014771a62665656d59e0..5e41be36b40c311f6c5c4d7ec4f3cd16da8be3f8 100644 (file)
--- a/test.c
+++ b/test.c
@@ -309,7 +309,7 @@ static bool task_template_parse(const char *file, task_template_t *tmpl, FILE *f
         return false;
 
     /* top down parsing */
         return false;
 
     /* top down parsing */
-    while (fs_file_getline(&back, &size, fp) != EOF) {
+    while (util_getline(&back, &size, fp) != EOF) {
         /* skip whitespace */
         data = back;
         if (*data && (*data == ' ' || *data == '\t'))
         /* skip whitespace */
         data = back;
         if (*data && (*data == ' ' || *data == '\t'))
@@ -932,7 +932,7 @@ static bool task_trymatch(size_t i, char ***line) {
         size_t size    = 0;
         size_t compare = 0;
 
         size_t size    = 0;
         size_t compare = 0;
 
-        while (fs_file_getline(&data, &size, execute) != EOF) {
+        while (util_getline(&data, &size, execute) != EOF) {
             if (!strcmp(data, "No main function found\n")) {
                 con_err("test failure: `%s` (No main function found) [%s]\n",
                     tmpl->description,
             if (!strcmp(data, "No main function found\n")) {
                 con_err("test failure: `%s` (No main function found) [%s]\n",
                     tmpl->description,
@@ -1066,7 +1066,7 @@ static size_t task_schedualize(size_t *pad) {
          * Read data from stdout first and pipe that stuff into a log file
          * then we do the same for stderr.
          */
          * Read data from stdout first and pipe that stuff into a log file
          * then we do the same for stderr.
          */
-        while (fs_file_getline(&data, &size, task_tasks[i].runhandles[1]) != EOF) {
+        while (util_getline(&data, &size, task_tasks[i].runhandles[1]) != EOF) {
             fputs(data, task_tasks[i].stdoutlog);
 
             if (strstr(data, "failed to open file")) {
             fputs(data, task_tasks[i].stdoutlog);
 
             if (strstr(data, "failed to open file")) {
@@ -1074,7 +1074,7 @@ static size_t task_schedualize(size_t *pad) {
                 execute                = false;
             }
         }
                 execute                = false;
             }
         }
-        while (fs_file_getline(&data, &size, task_tasks[i].runhandles[2]) != EOF) {
+        while (util_getline(&data, &size, task_tasks[i].runhandles[2]) != EOF) {
             /*
              * If a string contains an error we just dissalow execution
              * of it in the vm.
             /*
              * If a string contains an error we just dissalow execution
              * of it in the vm.
diff --git a/util.c b/util.c
index 0e468c0ea5a7efd2f9cffd5bc79ceab76934bac2..10fd9f47b4c6a4af713039884e3e69df6f2071a4 100644 (file)
--- a/util.c
+++ b/util.c
@@ -24,7 +24,6 @@
 #include <stdlib.h>
 #include <string.h>
 #include "gmqcc.h"
 #include <stdlib.h>
 #include <string.h>
 #include "gmqcc.h"
-#include "platform.h"
 
 /*
  * Initially this was handled with a table in the gmqcc.h header, but
 
 /*
  * Initially this was handled with a table in the gmqcc.h header, but
@@ -584,6 +583,36 @@ size_t util_optimizationtostr(const char *in, char *out, size_t outsz) {
     return util_strtransform(in, out, outsz, "_ ", 'a'-'A');
 }
 
     return util_strtransform(in, out, outsz, "_ ", 'a'-'A');
 }
 
+static int util_vasprintf(char **dat, const char *fmt, va_list args) {
+    int     ret;
+    int     len;
+    char   *tmp = NULL;
+    char    buf[128];
+    va_list cpy;
+
+    va_copy(cpy, args);
+    len = vsnprintf(buf, sizeof(buf), fmt, cpy);
+    va_end (cpy);
+
+    if (len < 0)
+        return len;
+
+    if (len < (int)sizeof(buf)) {
+        *dat = util_strdup(buf);
+        return len;
+    }
+
+    tmp = (char*)mem_a(len + 1);
+    if ((ret = vsnprintf(tmp, len + 1, fmt, args)) != len) {
+        mem_d(tmp);
+        *dat = NULL;
+        return -1;
+    }
+
+    *dat = tmp;
+    return len;
+}
+
 int util_snprintf(char *str, size_t size, const char *fmt, ...) {
     va_list  arg;
     int ret;
 int util_snprintf(char *str, size_t size, const char *fmt, ...) {
     va_list  arg;
     int ret;
@@ -597,7 +626,7 @@ int util_asprintf(char **ret, const char *fmt, ...) {
     va_list  args;
     int read;
     va_start(args, fmt);
     va_list  args;
     int read;
     va_start(args, fmt);
-    read = platform_vasprintf(ret, fmt, args);
+    read = util_vasprintf(ret, fmt, args);
     va_end(args);
     return read;
 }
     va_end(args);
     return read;
 }
@@ -635,6 +664,50 @@ const char *util_ctime(const time_t *timer) {
     return ctime(timer);
 }
 
     return ctime(timer);
 }
 
+int util_getline(char **lineptr, size_t *n, FILE *stream) {
+    int   chr;
+    int   ret;
+    char *pos;
+
+    if (!lineptr || !n || !stream)
+        return -1;
+    if (!*lineptr) {
+        if (!(*lineptr = (char*)mem_a((*n=64))))
+            return -1;
+    }
+
+    chr = *n;
+    pos = *lineptr;
+
+    for (;;) {
+        int c = getc(stream);
+
+        if (chr < 2) {
+            *n += (*n > 16) ? *n : 64;
+            chr = *n + *lineptr - pos;
+            if (!(*lineptr = (char*)mem_r(*lineptr,*n)))
+                return -1;
+            pos = *n - chr + *lineptr;
+        }
+
+        if (ferror(stream))
+            return -1;
+        if (c == EOF) {
+            if (pos == *lineptr)
+                return -1;
+            else
+                break;
+        }
+
+        *pos++ = c;
+        chr--;
+        if (c == '\n')
+            break;
+    }
+    *pos = '\0';
+    return (ret = pos - *lineptr);
+}
+
 #ifndef _WIN32
 #include <unistd.h>
 bool util_isatty(FILE *file) {
 #ifndef _WIN32
 #include <unistd.h>
 bool util_isatty(FILE *file) {