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)
+++ /dev/null
-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.
+++ /dev/null
-/*
- * 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;
-}
+++ /dev/null
-/*
- * 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);
-}
* 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 */
char *end;
line = *out;
- len = fs_file_getline(&line, alen, src);
+ len = util_getline(&line, alen, src);
if (len == -1)
return false;
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 */
+++ /dev/null
-/*
- * 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
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'))
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,
* 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")) {
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.
#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
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;
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;
}
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) {