mirror of
https://github.com/DarkPlacesEngine/gmqcc.git
synced 2025-01-18 22:31:36 +00:00
Remove fs.c ansi.c and PORTING guide
This commit is contained in:
parent
2c421c3b71
commit
724bca0eec
10 changed files with 95 additions and 192 deletions
6
Makefile
6
Makefile
|
@ -2,9 +2,9 @@ CC ?= clang
|
|||
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)
|
||||
|
|
4
PORTING
4
PORTING
|
@ -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.
|
57
ansi.c
57
ansi.c
|
@ -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;
|
||||
}
|
67
fs.c
67
fs.c
|
@ -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);
|
||||
}
|
27
gmqcc.h
27
gmqcc.h
|
@ -310,22 +310,17 @@ typedef struct hash_table_s {
|
|||
* 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 */
|
||||
|
||||
|
|
2
main.c
2
main.c
|
@ -531,7 +531,7 @@ static bool progs_nextline(char **out, size_t *alen, FILE *src) {
|
|||
char *end;
|
||||
|
||||
line = *out;
|
||||
len = fs_file_getline(&line, alen, src);
|
||||
len = util_getline(&line, alen, src);
|
||||
if (len == -1)
|
||||
return false;
|
||||
|
||||
|
|
2
opts.c
2
opts.c
|
@ -234,7 +234,7 @@ static size_t opts_ini_parse (
|
|||
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 */
|
||||
|
|
37
platform.h
37
platform.h
|
@ -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
|
8
test.c
8
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 */
|
||||
while (fs_file_getline(&back, &size, fp) != EOF) {
|
||||
while (util_getline(&back, &size, fp) != EOF) {
|
||||
/* 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;
|
||||
|
||||
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,
|
||||
|
@ -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.
|
||||
*/
|
||||
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")) {
|
||||
|
@ -1074,7 +1074,7 @@ static size_t task_schedualize(size_t *pad) {
|
|||
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.
|
||||
|
|
77
util.c
77
util.c
|
@ -24,7 +24,6 @@
|
|||
#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
|
||||
|
@ -584,6 +583,36 @@ size_t util_optimizationtostr(const char *in, char *out, size_t outsz) {
|
|||
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;
|
||||
|
@ -597,7 +626,7 @@ int util_asprintf(char **ret, const char *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;
|
||||
}
|
||||
|
@ -635,6 +664,50 @@ const char *util_ctime(const time_t *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) {
|
||||
|
|
Loading…
Reference in a new issue