X-Git-Url: https://git.xonotic.org/?p=xonotic%2Fgmqcc.git;a=blobdiff_plain;f=exec.c;h=8b0ee5e830722084c8e522840c05239cd918b431;hp=c81b5a2a28c7e4dc1e7c9e00327297145fa0895a;hb=0f7634876f8358d7d7da2ca50a28a6402753a3a3;hpb=48f8d0e0c3f60194f1676c02492361b7ea27af4d diff --git a/exec.c b/exec.c index c81b5a2..8b0ee5e 100644 --- a/exec.c +++ b/exec.c @@ -55,26 +55,26 @@ qc_program* prog_load(const char *filename, bool skipversion) { qc_program *prog; prog_header header; - FILE *file = file_open(filename, "rb"); + FILE *file = fs_file_open(filename, "rb"); if (!file) return NULL; - if (file_read(&header, sizeof(header), 1, file) != 1) { + if (fs_file_read(&header, sizeof(header), 1, file) != 1) { loaderror("failed to read header from '%s'", filename); - file_close(file); + fs_file_close(file); return NULL; } if (!skipversion && header.version != 6) { loaderror("header says this is a version %i progs, we need version 6\n", header.version); - file_close(file); + fs_file_close(file); return NULL; } prog = (qc_program*)mem_a(sizeof(qc_program)); if (!prog) { - file_close(file); + fs_file_close(file); fprintf(stderr, "failed to allocate program data\n"); return NULL; } @@ -90,11 +90,11 @@ qc_program* prog_load(const char *filename, bool skipversion) } #define read_data(hdrvar, progvar, reserved) \ - if (file_seek(file, header.hdrvar.offset, SEEK_SET) != 0) { \ + if (fs_file_seek(file, header.hdrvar.offset, SEEK_SET) != 0) { \ loaderror("seek failed"); \ goto error; \ } \ - if (file_read ( \ + if (fs_file_read ( \ vec_add(prog->progvar, header.hdrvar.length + reserved), \ sizeof(*prog->progvar), \ header.hdrvar.length, \ @@ -114,7 +114,7 @@ qc_program* prog_load(const char *filename, bool skipversion) read_data1(strings); read_data2(globals, 2); /* reserve more in case a RETURN using with the global at "the end" exists */ - file_close(file); + fs_file_close(file); /* profile counters */ memset(vec_add(prog->profile, vec_size(prog->code)), 0, sizeof(prog->profile[0]) * vec_size(prog->code)); @@ -354,7 +354,7 @@ static void trace_print_global(qc_program *prog, unsigned int glob, int vtype) done: if (len < (int)sizeof(spaces)-1) { spaces[sizeof(spaces)-1-len] = 0; - file_puts(stdout, spaces); + fs_file_puts(stdout, spaces); spaces[sizeof(spaces)-1-len] = ' '; } } @@ -455,7 +455,6 @@ static void prog_print_statement(qc_program *prog, prog_section_statement *st) else printf("(none)"); printf("\n"); } - fflush(stdout); } static qcint prog_enterfunction(qc_program *prog, prog_section_function *func) @@ -825,6 +824,16 @@ static int qc_strcmp(qc_program *prog) return 0; } +static int qc_floor(qc_program *prog) +{ + qcany *num, out; + CheckArgs(1); + num = GetArg(0); + out._float = floor(num->_float); + Return(out); + return 0; +} + static prog_builtin qc_builtins[] = { NULL, &qc_print, /* 1 */ @@ -839,7 +848,8 @@ static prog_builtin qc_builtins[] = { &qc_strcat, /* 10 */ &qc_strcmp, /* 11 */ &qc_normalize, /* 12 */ - &qc_sqrt /* 13 */ + &qc_sqrt, /* 13 */ + &qc_floor /* 14 */ }; static size_t qc_builtins_count = sizeof(qc_builtins) / sizeof(qc_builtins[0]); @@ -1128,11 +1138,33 @@ int main(int argc, char **argv) } if (opts_printdefs) { for (i = 0; i < vec_size(prog->defs); ++i) { - printf("Global: %8s %-16s at %u%s\n", + printf("Global: %8s %-16s at %u%s", type_name[prog->defs[i].type & DEF_TYPEMASK], prog_getstring(prog, prog->defs[i].name), (unsigned int)prog->defs[i].offset, ((prog->defs[i].type & DEF_SAVEGLOBAL) ? " [SAVE]" : "")); + if (opts_v) { + switch (prog->defs[i].type & DEF_TYPEMASK) { + case TYPE_FLOAT: + printf(" [init: %g]", ((qcany*)(prog->globals + prog->defs[i].offset))->_float); + break; + case TYPE_INTEGER: + printf(" [init: %i]", (int)( ((qcany*)(prog->globals + prog->defs[i].offset))->_int )); + break; + case TYPE_ENTITY: + case TYPE_FUNCTION: + case TYPE_FIELD: + case TYPE_POINTER: + printf(" [init: %u]", (unsigned)( ((qcany*)(prog->globals + prog->defs[i].offset))->_int )); + break; + case TYPE_STRING: + printf(" [init: `%s`]", prog_getstring(prog, ((qcany*)(prog->globals + prog->defs[i].offset))->string )); + break; + default: + break; + } + } + printf("\n"); } } if (opts_printfields) {