* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
+#define GMQCC_PLATFORM_HEADER
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
return vsnprintf(buffer, bytes, format, arg);
}
-int platform_sscanf(const char *str, const char *format, ...) {
- int rt;
- va_list va;
-
- va_start(va, format);
- rt = vsscanf(str, format, va);
- va_end (va);
-
- return rt;
+int platform_vsscanf(const char *str, const char *format, va_list arg) {
+ return vsscanf(str, format, arg);
}
const struct tm *platform_localtime(const time_t *timer) {
return getenv(var);
}
-int platform_snprintf(char *src, size_t bytes, const char *format, ...) {
- int rt;
- va_list va;
-
- va_start(va, format);
- rt = vsnprintf(src, bytes, format, va);
- va_end(va);
-
- return rt;
-}
-
int platform_vasprintf(char **dat, const char *fmt, va_list args) {
int ret;
int len;
#include "gmqcc.h"
#include "ast.h"
#include "parser.h"
-#include "platform.h"
#define ast_instantiate(T, ctx, destroyfn) \
T* self = (T*)mem_a(sizeof(T)); \
if (!e) {
if (pos + 6 >= bufsize)
goto full;
- platform_strncpy(buf + pos, "(null)", 6);
+ util_strncpy(buf + pos, "(null)", 6);
return pos + 6;
}
switch (e->vtype) {
case TYPE_VARIANT:
- platform_strncpy(buf + pos, "(variant)", 9);
+ util_strncpy(buf + pos, "(variant)", 9);
return pos + 9;
case TYPE_FIELD:
if (pos + 1 >= bufsize)
goto full;
buf[pos++] = '[';
- pos += platform_snprintf(buf + pos, bufsize - pos - 1, "%i", (int)e->count);
+ pos += util_snprintf(buf + pos, bufsize - pos - 1, "%i", (int)e->count);
if (pos + 1 >= bufsize)
goto full;
buf[pos++] = ']';
typelen = strlen(typestr);
if (pos + typelen >= bufsize)
goto full;
- platform_strncpy(buf + pos, typestr, typelen);
+ util_strncpy(buf + pos, typestr, typelen);
return pos + typelen;
}
namelen = strlen(self->name);
name = (char*)mem_a(namelen + 16);
- platform_strncpy(name, self->name, namelen);
+ util_strncpy(name, self->name, namelen);
array->ir_values = (ir_value**)mem_a(sizeof(array->ir_values[0]) * array->expression.count);
array->ir_values[0] = v;
for (ai = 1; ai < array->expression.count; ++ai) {
- platform_snprintf(name + namelen, 16, "[%u]", (unsigned int)ai);
+ util_snprintf(name + namelen, 16, "[%u]", (unsigned int)ai);
array->ir_values[ai] = ir_builder_create_field(ir, name, vtype);
if (!array->ir_values[ai]) {
mem_d(name);
namelen = strlen(self->name);
name = (char*)mem_a(namelen + 16);
- platform_strncpy(name, self->name, namelen);
+ util_strncpy(name, self->name, namelen);
self->ir_values = (ir_value**)mem_a(sizeof(self->ir_values[0]) * self->expression.count);
self->ir_values[0] = v;
for (ai = 1; ai < self->expression.count; ++ai) {
- platform_snprintf(name + namelen, 16, "[%u]", (unsigned int)ai);
+ util_snprintf(name + namelen, 16, "[%u]", (unsigned int)ai);
self->ir_values[ai] = ir_builder_create_global(ir, name, vtype);
if (!self->ir_values[ai]) {
mem_d(name);
namelen = strlen(self->name);
name = (char*)mem_a(namelen + 16);
- platform_strncpy(name, self->name, namelen);
+ util_strncpy(name, self->name, namelen);
self->ir_values[0] = v;
for (ai = 1; ai < self->expression.count; ++ai) {
- platform_snprintf(name + namelen, 16, "[%u]", (unsigned int)ai);
+ util_snprintf(name + namelen, 16, "[%u]", (unsigned int)ai);
self->ir_values[ai] = ir_function_create_local(func, name, vtype, param);
if (!self->ir_values[ai]) {
compile_error(ast_ctx(self), "internal_error: ir_builder_create_global failed on `%s`", name);
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
+#define GMQCC_PLATFORM_HEADER
#include "gmqcc.h"
#include "platform.h"
#include <errno.h>
#include <stdlib.h>
#include <string.h>
+#include <stdio.h>
#include "gmqcc.h"
-#include "platform.h"
static void loaderror(const char *fmt, ...)
{
va_start(ap, fmt);
vprintf(fmt, ap);
va_end(ap);
- printf(": %s\n", platform_strerror(err));
+ printf(": %s\n", util_strerror(err));
}
static void qcvmerror(qc_program_t *prog, const char *fmt, ...)
qcany_t str;
CheckArgs(1);
num = GetArg(0);
- platform_snprintf(buffer, sizeof(buffer), "%g", num->_float);
+ util_snprintf(buffer, sizeof(buffer), "%g", num->_float);
str.string = prog_tempstring(prog, buffer);
Return(str);
return 0;
qcany_t str;
CheckArgs(1);
num = GetArg(0);
- platform_snprintf(buffer, sizeof(buffer), "'%g %g %g'", num->vector[0], num->vector[1], num->vector[2]);
+ util_snprintf(buffer, sizeof(buffer), "'%g %g %g'", num->vector[0], num->vector[1], num->vector[2]);
str.string = prog_tempstring(prog, buffer);
Return(str);
return 0;
qcany_t str;
CheckArgs(1);
num = GetArg(0);
- platform_snprintf(buffer, sizeof(buffer), "%i", num->_int);
+ util_snprintf(buffer, sizeof(buffer), "%i", num->_int);
str.string = prog_tempstring(prog, buffer);
Return(str);
return 0;
arg->vector[2] = 0;
switch (main_params[i].vtype) {
case TYPE_VECTOR:
- (void)platform_sscanf(main_params[i].value, " %f %f %f ",
+ (void)util_sscanf(main_params[i].value, " %f %f %f ",
&arg->vector[0],
&arg->vector[1],
&arg->vector[2]);
#include "ast.h"
#include "parser.h"
-#include "platform.h"
#define FOLD_STRING_UNTRANSLATE_HTSIZE 1024
#define FOLD_STRING_DOTRANSLATE_HTSIZE 1024
if (translate) {
char name[32];
- platform_snprintf(name, sizeof(name), "dotranslate_%lu", (unsigned long)(fold->parser->translated++));
+ util_snprintf(name, sizeof(name), "dotranslate_%lu", (unsigned long)(fold->parser->translated++));
out = ast_value_new(parser_ctx(fold->parser), name, TYPE_STRING);
out->expression.flags |= AST_FLAG_INCLUDE_DEF; /* def needs to be included for translatables */
} else
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
+#define GMQCC_PLATFORM_HEADER
#include "gmqcc.h"
#include "platform.h"
}
int fs_file_getc(fs_file_t *fp) {
- return platform_fgetc((FILE*)fp);
+ int get = platform_fgetc((FILE*)fp);
+ return (get == EOF) ? FS_FILE_EOF : get;
}
int fs_file_puts(fs_file_t *fp, const char *str) {
}
int fs_file_seek(fs_file_t *fp, long int off, int whence) {
+ switch(whence) {
+ case FS_FILE_SEEK_CUR: whence = SEEK_CUR; break;
+ case FS_FILE_SEEK_SET: whence = SEEK_SET; break;
+ case FS_FILE_SEEK_END: whence = SEEK_END; break;
+ }
return platform_fseek((FILE*)fp, off, whence);
}
*/
#include <string.h>
#include <stdlib.h>
+#include <time.h>
#include <sys/stat.h>
#include "gmqcc.h"
#include "lexer.h"
-#include "platform.h"
#define HT_MACROS 1024
(void)context;
time (&rtime);
- itime = platform_localtime(&rtime);
+ itime = util_localtime(&rtime);
strftime(value, 82, "\"%b %d %Y\"", itime);
return value;
(void)context;
time (&rtime);
- itime = platform_localtime(&rtime);
+ itime = util_localtime(&rtime);
strftime(value, 82, "\"%X\"", itime);
return value;
static char *ftepp_predef_file(lex_file *context) {
size_t length = strlen(context->name) + 3; /* two quotes and a terminator */
char *value = (char*)mem_a(length);
- platform_snprintf(value, length, "\"%s\"", context->name);
+ util_snprintf(value, length, "\"%s\"", context->name);
return value;
}
if (stat(context->name, &finfo))
return util_strdup("\"<failed to determine timestamp>\"");
- find = platform_ctime(&finfo.st_mtime);
+ find = util_ctime(&finfo.st_mtime);
value = (char*)mem_a(strlen(find) + 1);
memcpy(&value[1], find, (size = strlen(find)) - 1);
if (resetline && !ftepp->in_macro) {
char lineno[128];
- platform_snprintf(lineno, 128, "\n#pragma line(%lu)\n", (unsigned long)(old_lexer->sline));
+ util_snprintf(lineno, 128, "\n#pragma line(%lu)\n", (unsigned long)(old_lexer->sline));
ftepp_out(ftepp, lineno, false);
}
ftepp_out(ftepp, "\n#pragma file(", false);
ftepp_out(ftepp, ctx.file, false);
- platform_snprintf(lineno, sizeof(lineno), ")\n#pragma line(%lu)\n", (unsigned long)(ctx.line+1));
+ util_snprintf(lineno, sizeof(lineno), ")\n#pragma line(%lu)\n", (unsigned long)(ctx.line+1));
ftepp_out(ftepp, lineno, false);
/* skip the line */
minor[2] = '"';
} else if (OPTS_OPTION_U32(OPTION_STANDARD) == COMPILER_GMQCC) {
ftepp_add_define(ftepp, NULL, "__STD_GMQCC__");
- platform_snprintf(major, 32, "\"%d\"", GMQCC_VERSION_MAJOR);
- platform_snprintf(minor, 32, "\"%d\"", GMQCC_VERSION_MINOR);
+ util_snprintf(major, 32, "\"%d\"", GMQCC_VERSION_MAJOR);
+ util_snprintf(minor, 32, "\"%d\"", GMQCC_VERSION_MINOR);
} else if (OPTS_OPTION_U32(OPTION_STANDARD) == COMPILER_QCCX) {
ftepp_add_define(ftepp, NULL, "__STD_QCCX__");
- platform_snprintf(major, 32, "\"%d\"", GMQCC_VERSION_MAJOR);
- platform_snprintf(minor, 32, "\"%d\"", GMQCC_VERSION_MINOR);
+ util_snprintf(major, 32, "\"%d\"", GMQCC_VERSION_MAJOR);
+ util_snprintf(minor, 32, "\"%d\"", GMQCC_VERSION_MINOR);
} else if (OPTS_OPTION_U32(OPTION_STANDARD) == COMPILER_QCC) {
ftepp_add_define(ftepp, NULL, "__STD_QCC__");
/* 1.0 */
#define GMQCC_HDR
#include <stdarg.h>
#include <stddef.h>
+#include <time.h> /* TODO remove?*/
/*
* Disable some over protective warnings in visual studio because fixing them is a waste
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);
/*
* A flexible vector implementation: all vector pointers contain some
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 dirent fs_dirent_t;
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;
* SOFTWARE.
*/
#include <string.h>
-
#include "parser.h"
-#include "platform.h"
/*
* Provides all the "intrinsics" / "builtins" for GMQCC. These can do
char buffer[1024];
char stype [1024];
- platform_snprintf(buffer, sizeof(buffer), "__builtin_%s", name);
- platform_snprintf(stype, sizeof(stype), "<%s>", type_name[vtype]);
+ util_snprintf(buffer, sizeof(buffer), "__builtin_%s", name);
+ util_snprintf(stype, sizeof(stype), "<%s>", type_name[vtype]);
*value = ast_value_new(intrin_ctx(intrin), buffer, TYPE_FUNCTION);
(*value)->intrinsic = true;
#include "gmqcc.h"
#include "ir.h"
-#include "platform.h"
/***********************************************************************
* Type sizes used at multiple points in the IR codegen
ir_value *global;
char name[128];
- platform_snprintf(name, sizeof(name), "EXTPARM#%i", (int)(vec_size(ir->extparam_protos)));
+ util_snprintf(name, sizeof(name), "EXTPARM#%i", (int)(vec_size(ir->extparam_protos)));
global = ir_value_var(name, store_global, TYPE_VECTOR);
vec_push(ir->extparam_protos, global);
return;
}
oprintf("%sfunction %s\n", ind, f->name);
- platform_strncat(ind, "\t", IND_BUFSZ-1);
+ util_strncat(ind, "\t", IND_BUFSZ-1);
if (vec_size(f->locals))
{
oprintf("%s%i locals:\n", ind, (int)vec_size(f->locals));
{
size_t i;
oprintf("%s:%s\n", ind, b->label);
- platform_strncat(ind, "\t", IND_BUFSZ-1);
+ util_strncat(ind, "\t", IND_BUFSZ-1);
if (b->instr && b->instr[0])
oprintf("%s (%i) [entry]\n", ind, (int)(b->instr[0]->eid-1));
return;
}
- platform_strncat(ind, "\t", IND_BUFSZ-1);
+ util_strncat(ind, "\t", IND_BUFSZ-1);
if (in->_ops[0] && (in->_ops[1] || in->_ops[2])) {
ir_value_dump(in->_ops[0], oprintf);
#include "gmqcc.h"
#include "lexer.h"
-#include "platform.h"
/*
* List of Keywords
}
if (lex->open_string) {
if (lex->open_string_pos >= lex->open_string_length)
- return EOF;
+ return FS_FILE_EOF;
lex->column++;
return lex->open_string[lex->open_string_pos++];
}
- return EOF;
+ return FS_FILE_EOF;
}
/* Get or put-back data
goto unroll;
lex->line = line;
- while (ch != '\n' && ch != EOF)
+ while (ch != '\n' && ch != FS_FILE_EOF)
ch = lex_getch(lex);
vec_free(command);
vec_free(param);
do
{
ch = lex_getch(lex);
- while (ch != EOF && util_isspace(ch)) {
+ while (ch != FS_FILE_EOF && util_isspace(ch)) {
if (ch == '\n') {
if (lex_try_pragma(lex))
continue;
lex_tokench(lex, ' ');
}
- while (ch != EOF && ch != '\n') {
+ while (ch != FS_FILE_EOF && ch != '\n') {
if (lex->flags.preprocessing)
lex_tokench(lex, ' '); /* ch); */
ch = lex_getch(lex);
lex_tokench(lex, ' ');
}
- while (ch != EOF)
+ while (ch != FS_FILE_EOF)
{
ch = lex_getch(lex);
if (ch == '*') {
ch = '/';
break;
}
- } while (ch != EOF && util_isspace(ch));
+ } while (ch != FS_FILE_EOF && util_isspace(ch));
if (haswhite) {
lex_endtoken(lex);
int ch;
ch = lex_getch(lex);
- while (ch != EOF && isident(ch))
+ while (ch != FS_FILE_EOF && isident(ch))
{
lex_tokench(lex, ch);
ch = lex_getch(lex);
lex_token_new(lex);
ch = lex_getch(lex);
- while (ch != EOF && ch != '\n' && util_isspace(ch))
+ while (ch != FS_FILE_EOF && ch != '\n' && util_isspace(ch))
ch = lex_getch(lex);
if (ch == '\n')
char u8buf[8]; /* way more than enough */
int u8len, uc;
- while (ch != EOF)
+ while (ch != FS_FILE_EOF)
{
ch = lex_getch(lex);
if (ch == quote)
if (lex->flags.preprocessing && ch == '\\') {
lex_tokench(lex, ch);
ch = lex_getch(lex);
- if (ch == EOF) {
+ if (ch == FS_FILE_EOF) {
lexerror(lex, "unexpected end of file");
- lex_ungetch(lex, EOF); /* next token to be TOKEN_EOF */
+ lex_ungetch(lex, FS_FILE_EOF); /* next token to be TOKEN_EOF */
return (lex->tok.ttype = TOKEN_ERROR);
}
lex_tokench(lex, ch);
}
else if (ch == '\\') {
ch = lex_getch(lex);
- if (ch == EOF) {
+ if (ch == FS_FILE_EOF) {
lexerror(lex, "unexpected end of file");
- lex_ungetch(lex, EOF); /* next token to be TOKEN_EOF */
+ lex_ungetch(lex, FS_FILE_EOF); /* next token to be TOKEN_EOF */
return (lex->tok.ttype = TOKEN_ERROR);
}
lex_tokench(lex, ch);
}
lexerror(lex, "unexpected end of file within string constant");
- lex_ungetch(lex, EOF); /* next token to be TOKEN_EOF */
+ lex_ungetch(lex, FS_FILE_EOF); /* next token to be TOKEN_EOF */
return (lex->tok.ttype = TOKEN_ERROR);
}
if (lex->eof)
return (lex->tok.ttype = TOKEN_FATAL);
- if (ch == EOF) {
+ if (ch == FS_FILE_EOF) {
lex->eof = true;
return (lex->tok.ttype = TOKEN_EOF);
}
if (!strcmp(v, "framevalue"))
{
ch = lex_getch(lex);
- while (ch != EOF && util_isspace(ch) && ch != '\n')
+ while (ch != FS_FILE_EOF && util_isspace(ch) && ch != '\n')
ch = lex_getch(lex);
if (!util_isdigit(ch)) {
vec_free(lex->frames);
/* skip line (fteqcc does it too) */
ch = lex_getch(lex);
- while (ch != EOF && ch != '\n')
+ while (ch != FS_FILE_EOF && ch != '\n')
ch = lex_getch(lex);
return lex_do(lex);
}
{
/* skip line */
ch = lex_getch(lex);
- while (ch != EOF && ch != '\n')
+ while (ch != FS_FILE_EOF && ch != '\n')
ch = lex_getch(lex);
return lex_do(lex);
}
lex->tok.ttype = TOKEN_CHARCONST;
/* It's a vector if we can successfully scan 3 floats */
- if (platform_sscanf(lex->tok.value, " %f %f %f ",
+ if (util_sscanf(lex->tok.value, " %f %f %f ",
&lex->tok.constval.v.x, &lex->tok.constval.v.y, &lex->tok.constval.v.z) == 3)
{
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
+#define GMQCC_PLATFORM_HEADER
#include <string.h>
#include <stdlib.h>
vsnprintf_s(buffer, bytes, bytes, format, arg);
}
-int platform_sscanf(const char *str, const char *format, ...) {
- va_list va;
- va_start(va, format);
- vsscanf_s(str, format, va);
- va_end(va);
+int platform_vsscanf(const char *str, const char *format, va_list va) {
+ return vsscanf_s(str, format, va);
}
const struct tm *platform_localtime(const time_t *timer) {
struct tm *t;
t = (struct tm*)platform_mem_allocate(sizeof(struct tm));
localtime_s(&t, timer);
- return &t;
+ return t;
}
const char *platform_ctime(const time_t *timer) {
return buffer;
}
-int platform_snprintf(char *src, size_t bytes, const char *format, ...) {
- int rt;
- va_list va;
- va_start(va, format);
-
- rt = vsprintf_s(src, bytes, format, va);
- va_end (va);
-
- return rt;
-}
-
/*
* TODO: this isn't exactly 'accurate' for MSVC but it seems to work,
* at least to some extent.
#include <stdlib.h>
#include "gmqcc.h"
-#include "platform.h"
const unsigned int opts_opt_oflag[COUNT_OPTIMIZATIONS+1] = {
# define GMQCC_TYPE_OPTIMIZATIONS
char *read_name;
char *read_value;
- while (fs_file_getline(&line, &linesize, filehandle) != EOF) {
+ while (fs_file_getline(&line, &linesize, filehandle) != FS_FILE_EOF) {
parse_beg = line;
/* handle BOM */
/* section found */
if (*(parse_end = opts_ini_next(parse_beg + 1, ']')) == ']') {
* parse_end = '\0'; /* terminate bro */
- platform_strncpy(section_data, parse_beg + 1, sizeof(section_data));
+ util_strncpy(section_data, parse_beg + 1, sizeof(section_data));
section_data[sizeof(section_data) - 1] = '\0';
*oldname_data = '\0';
} else if (!error) {
opts_ini_rstrip(read_value);
/* valid name value pair, lets call down to handler */
- platform_strncpy(oldname_data, read_name, sizeof(oldname_data));
+ util_strncpy(oldname_data, read_name, sizeof(oldname_data));
oldname_data[sizeof(oldname_data) - 1] ='\0';
if ((*errorhandle = loadhandle(section_data, read_name, read_value)) && !error)
#include <stdlib.h>
#include "gmqcc.h"
-#include "platform.h"
/*
* The PAK format uses a FOURCC concept for storing the magic ident within
memset(pathsplit, 0, 56);
- platform_strncpy(directory, entry, 56);
+ util_strncpy(directory, entry, 56);
for (itr = 0; (token = pak_tree_sep(&directory, "/")) != NULL; itr++) {
elements[itr] = token;
}
for (jtr = 0; jtr < itr - 1; jtr++) {
- platform_strcat(pathsplit, elements[jtr]);
- platform_strcat(pathsplit, "/");
+ util_strcat(pathsplit, elements[jtr]);
+ util_strcat(pathsplit, "/");
if (fs_dir_make(pathsplit)) {
mem_d(pathsplit);
* Time to read in the directory handles and prepare the directories
* vector. We're going to be reading some the file inwards soon.
*/
- fs_file_seek(pak->handle, pak->header.diroff, SEEK_SET);
+ fs_file_seek(pak->handle, pak->header.diroff, FS_FILE_SEEK_SET);
/*
* Read in all directories from the PAK file. These are considered
mem_d(local);
/* read */
- if (fs_file_seek (pak->handle, dir->pos, SEEK_SET) != 0)
+ if (fs_file_seek (pak->handle, dir->pos, FS_FILE_SEEK_SET) != 0)
goto err;
fs_file_read (dat, 1, dir->len, pak->handle);
* the directory entry, and the actual contents of the file
* to the PAK file itself.
*/
- if (fs_file_seek(fp, 0, SEEK_END) != 0 || ((len = fs_file_tell(fp)) < 0))
+ if (fs_file_seek(fp, 0, FS_FILE_SEEK_END) != 0 || ((len = fs_file_tell(fp)) < 0))
goto err;
- if (fs_file_seek(fp, 0, SEEK_SET) != 0)
+ if (fs_file_seek(fp, 0, FS_FILE_SEEK_SET) != 0)
goto err;
dir.len = len;
if (strlen(file) >= 56)
goto err;
- platform_strncpy(dir.name, file, strlen(file));
+ util_strncpy(dir.name, file, strlen(file));
/*
* Allocate some memory for loading in the data that will be
pak->header.diroff = tell;
/* patch header */
- if (fs_file_seek (pak->handle, 0, SEEK_SET) != 0)
+ if (fs_file_seek (pak->handle, 0, FS_FILE_SEEK_SET) != 0)
goto err;
fs_file_write(&(pak->header), sizeof(pak_header_t), 1, pak->handle);
/* write directories */
- if (fs_file_seek (pak->handle, pak->header.diroff, SEEK_SET) != 0)
+ if (fs_file_seek (pak->handle, pak->header.diroff, FS_FILE_SEEK_SET) != 0)
goto err;
- for (itr = 0; itr < vec_size(pak->directories); itr++) {
+ for (itr = 0; itr < vec_size(pak->directories); itr++)
fs_file_write(&(pak->directories[itr]), sizeof(pak_directory_t), 1, pak->handle);
- }
}
vec_free (pak->directories);
return true;
}
+#include <stdio.h>
int main(int argc, char **argv) {
bool extract = true;
char *redirout = (char*)stdout;
#include <math.h>
#include "parser.h"
-#include "platform.h"
#define PARSER_HT_LOCALS 2
#define PARSER_HT_SIZE 512
varargs->expression.flags |= AST_FLAG_IS_VARARG;
varargs->expression.next = (ast_expression*)ast_value_new(ast_ctx(var), NULL, TYPE_VECTOR);
varargs->expression.count = 0;
- platform_snprintf(name, sizeof(name), "%s##va##SET", var->name);
+ util_snprintf(name, sizeof(name), "%s##va##SET", var->name);
if (!parser_create_array_setter_proto(parser, varargs, name)) {
ast_delete(varargs);
ast_block_delete(block);
goto enderrfn;
}
- platform_snprintf(name, sizeof(name), "%s##va##GET", var->name);
+ util_snprintf(name, sizeof(name), "%s##va##GET", var->name);
if (!parser_create_array_getter_proto(parser, varargs, varargs->expression.next, name)) {
ast_delete(varargs);
ast_block_delete(block);
static bool create_array_accessors(parser_t *parser, ast_value *var)
{
char name[1024];
- platform_snprintf(name, sizeof(name), "%s##SET", var->name);
+ util_snprintf(name, sizeof(name), "%s##SET", var->name);
if (!parser_create_array_setter(parser, var, name))
return false;
- platform_snprintf(name, sizeof(name), "%s##GET", var->name);
+ util_snprintf(name, sizeof(name), "%s##GET", var->name);
if (!parser_create_array_getter(parser, var, var->expression.next, name))
return false;
return true;
goto cleanup;
}
- platform_snprintf(name, sizeof(name), "%s##SETF", var->name);
+ util_snprintf(name, sizeof(name), "%s##SETF", var->name);
if (!parser_create_array_field_setter(parser, array, name))
goto cleanup;
telem = ast_type_copy(ast_ctx(var), array->expression.next);
tfield = ast_value_new(ast_ctx(var), "<.type>", TYPE_FIELD);
tfield->expression.next = telem;
- platform_snprintf(name, sizeof(name), "%s##GETFP", var->name);
+ util_snprintf(name, sizeof(name), "%s##GETFP", var->name);
if (!parser_create_array_getter(parser, array, (ast_expression*)tfield, name)) {
ast_delete(tfield);
goto cleanup;
}
}
if (!parser->assign_op) {
- printf("internal error: initializing parser: failed to find assign operator\n");
+ con_err("internal error: initializing parser: failed to find assign operator\n");
mem_d(parser);
return NULL;
}
#ifndef GMQCC_PLATFORM_HDR
#define GMQCC_PLATFORM_HDR
+
+#ifndef GMQCC_PLATFORM_HEADER
+# error "This header shouldn't be included!"
+#endif
+
+#undef GMQCC_PLATFORM_HEADER
#include <stdarg.h>
#include <time.h>
#include <stdio.h>
#endif /*!_WIN32*/
int platform_vsnprintf(char *buffer, size_t bytes, const char *format, va_list arg);
-int platform_sscanf(const char *str, const char *format, ...);
+int platform_vsscanf(const char *str, const char *format, va_list arg);
const struct tm *platform_localtime(const time_t *timer);
const char *platform_ctime(const time_t *timer);
char *platform_strncat(char *dest, const char *src, size_t num);
const char *platform_tmpnam(char *str);
const char *platform_getenv(char *var);
-int platform_snprintf(char *src, size_t bytes, const char *format, ...);
int platform_vasprintf(char **dat, const char *fmt, va_list args);
char *platform_strcat(char *dest, const char *src);
char *platform_strncpy(char *dest, const char *src, size_t num);
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
+#define GMQCC_PLATFORM_HEADER
#include <stdlib.h>
#include <string.h>
char *cmd = NULL;
popen_t *open = (popen_t*)mem_a(sizeof(popen_t));
- platform_tmpnam(open->name_err);
- platform_tmpnam(open->name_out);
+ util_tmpnam(open->name_err);
+ util_tmpnam(open->name_out);
(void)mode; /* excluded */
return false;
/* top down parsing */
- while (fs_file_getline(&back, &size, fp) != EOF) {
+ while (fs_file_getline(&back, &size, fp) != FS_FILE_EOF) {
/* skip whitespace */
data = back;
if (*data && (*data == ' ' || *data == '\t'))
fs_file_t *tempfile = NULL;
task_template_t *tmpl = NULL;
- platform_snprintf(fullfile, sizeof(fullfile), "%s/%s", dir, file);
+ util_snprintf(fullfile, sizeof(fullfile), "%s/%s", dir, file);
tempfile = fs_file_open(fullfile, "r");
tmpl = (task_template_t*)mem_a(sizeof(task_template_t));
dir = fs_dir_open(directories[i]);
while ((files = fs_dir_read(dir))) {
- platform_snprintf(buffer, sizeof(buffer), "%s/%s", directories[i], files->d_name);
+ util_snprintf(buffer, sizeof(buffer), "%s/%s", directories[i], files->d_name);
if (stat(buffer, &directory) == -1) {
con_err("internal error: stat failed, aborting\n");
abort();
if (strcmp(tmpl->proceduretype, "-pp")) {
if (qcflags) {
if (tmpl->testflags && !strcmp(tmpl->testflags, "-no-defs")) {
- platform_snprintf(buf, sizeof(buf), "%s %s/%s %s %s -o %s",
+ util_snprintf(buf, sizeof(buf), "%s %s/%s %s %s -o %s",
task_bins[TASK_COMPILE],
directories[i],
tmpl->sourcefile,
tmpl->tempfilename
);
} else {
- platform_snprintf(buf, sizeof(buf), "%s %s/%s %s/%s %s %s -o %s",
+ util_snprintf(buf, sizeof(buf), "%s %s/%s %s/%s %s %s -o %s",
task_bins[TASK_COMPILE],
curdir,
defs,
}
} else {
if (tmpl->testflags && !strcmp(tmpl->testflags, "-no-defs")) {
- platform_snprintf(buf, sizeof(buf), "%s %s/%s %s -o %s",
+ util_snprintf(buf, sizeof(buf), "%s %s/%s %s -o %s",
task_bins[TASK_COMPILE],
directories[i],
tmpl->sourcefile,
tmpl->tempfilename
);
} else {
- platform_snprintf(buf, sizeof(buf), "%s %s/%s %s/%s %s -o %s",
+ util_snprintf(buf, sizeof(buf), "%s %s/%s %s/%s %s -o %s",
task_bins[TASK_COMPILE],
curdir,
defs,
} else {
/* Preprocessing (qcflags mean shit all here we don't allow them) */
if (tmpl->testflags && !strcmp(tmpl->testflags, "-no-defs")) {
- platform_snprintf(buf, sizeof(buf), "%s -E %s/%s -o %s",
+ util_snprintf(buf, sizeof(buf), "%s -E %s/%s -o %s",
task_bins[TASK_COMPILE],
directories[i],
tmpl->sourcefile,
tmpl->tempfilename
);
} else {
- platform_snprintf(buf, sizeof(buf), "%s -E %s/%s %s/%s -o %s",
+ util_snprintf(buf, sizeof(buf), "%s -E %s/%s %s/%s -o %s",
task_bins[TASK_COMPILE],
curdir,
defs,
* Open up some file desciptors for logging the stdout/stderr
* to our own.
*/
- platform_snprintf(buf, sizeof(buf), "%s.stdout", tmpl->tempfilename);
+ util_snprintf(buf, sizeof(buf), "%s.stdout", tmpl->tempfilename);
task.stdoutlogfile = util_strdup(buf);
if (!(task.stdoutlog = fs_file_open(buf, "w"))) {
con_err("error opening %s for stdout\n", buf);
continue;
}
- platform_snprintf(buf, sizeof(buf), "%s.stderr", tmpl->tempfilename);
+ util_snprintf(buf, sizeof(buf), "%s.stderr", tmpl->tempfilename);
task.stderrlogfile = util_strdup(buf);
if (!(task.stderrlog = fs_file_open(buf, "w"))) {
con_err("error opening %s for stderr\n", buf);
strstr(files->d_name, ".stdout") ||
strstr(files->d_name, ".stderr"))
{
- platform_snprintf(buffer, sizeof(buffer), "%s/%s", curdir, files->d_name);
+ util_snprintf(buffer, sizeof(buffer), "%s/%s", curdir, files->d_name);
if (remove(buffer))
con_err("error removing temporary file: %s\n", buffer);
}
* actually specified.
*/
if (!strcmp(tmpl->executeflags, "$null")) {
- platform_snprintf(buffer, sizeof(buffer), "%s %s",
+ util_snprintf(buffer, sizeof(buffer), "%s %s",
task_bins[TASK_EXECUTE],
tmpl->tempfilename
);
} else {
- platform_snprintf(buffer, sizeof(buffer), "%s %s %s",
+ util_snprintf(buffer, sizeof(buffer), "%s %s %s",
task_bins[TASK_EXECUTE],
tmpl->executeflags,
tmpl->tempfilename
size_t size = 0;
size_t compare = 0;
- while (fs_file_getline(&data, &size, execute) != EOF) {
+ while (fs_file_getline(&data, &size, execute) != FS_FILE_EOF) {
if (!strcmp(data, "No main function found\n")) {
con_err("test failure: `%s` (No main function found) [%s]\n",
tmpl->description,
size_t j = 0;
size_t failed = 0;
- platform_snprintf(space[0], sizeof(space[0]), "%d", (int)vec_size(task_tasks));
+ util_snprintf(space[0], sizeof(space[0]), "%d", (int)vec_size(task_tasks));
for (; i < vec_size(task_tasks); i++) {
memset(space[1], 0, sizeof(space[1]));
- platform_snprintf(space[1], sizeof(space[1]), "%d", (int)(i + 1));
+ util_snprintf(space[1], sizeof(space[1]), "%d", (int)(i + 1));
con_out("test #%u %*s", i + 1, strlen(space[0]) - strlen(space[1]), "");
* 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 (fs_file_getline(&data, &size, task_tasks[i].runhandles[1]) != FS_FILE_EOF) {
fs_file_puts(task_tasks[i].stdoutlog, data);
if (strstr(data, "failed to open file")) {
execute = false;
}
}
- while (fs_file_getline(&data, &size, task_tasks[i].runhandles[2]) != EOF) {
+ while (fs_file_getline(&data, &size, task_tasks[i].runhandles[2]) != FS_FILE_EOF) {
/*
* If a string contains an error we just dissalow execution
* of it in the vm.
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
+#define GMQCC_PLATFORM_HEADER
#include <string.h>
#include <stdlib.h>
+#include <stdarg.h>
#include "gmqcc.h"
#include "platform.h"
return util_strtransform(in, out, outsz, "_ ", 'a'-'A');
}
+int util_snprintf(char *str, size_t size, const char *fmt, ...) {
+ va_list arg;
+ int ret;
+
+ va_start(arg, fmt);
+ ret = platform_vsnprintf(str, size, fmt, arg);
+ va_end(arg);
+
+ return ret;
+}
+
int util_asprintf(char **ret, const char *fmt, ...) {
va_list args;
int read;
+
va_start(args, fmt);
read = platform_vasprintf(ret, fmt, args);
va_end (args);
return read;
}
+int util_sscanf(const char *str, const char *format, ...) {
+ va_list args;
+ int read;
+
+ va_start(args, format);
+ read = platform_vsscanf(str, format, args);
+ va_end(args);
+
+ return read;
+}
+
+char *util_strncpy(char *dest, const char *src, size_t n) {
+ return platform_strncpy(dest, src, n);
+}
+char *util_strncat(char *dest, const char *src, size_t n) {
+ return platform_strncat(dest, src, n);
+}
+char *util_strcat(char *dest, const char *src) {
+ return platform_strcat(dest, src);
+}
+const char *util_strerror(int err) {
+ return platform_strerror(err);
+}
+
+const struct tm *util_localtime(const time_t *timer) {
+ return platform_localtime(timer);
+}
+const char *util_ctime(const time_t *timer) {
+ return platform_ctime(timer);
+}
+
void util_seed(uint32_t value) {
srand((int)value);
}