mirror of
https://github.com/nzp-team/fteqw.git
synced 2024-11-26 22:01:50 +00:00
9e2969390d
r4174 | acceptthis | 2013-01-25 15:56:53 +0000 (Fri, 25 Jan 2013) | 8 lines fix fteqcc 'tui'. Added new warning to detect non-utf-8 strings. Doesn't check for overlong. Added new warning to detect uninitialised locals. Fix ///* inside #if. Renamed -Olm to -Olo, and fixed the bugs that stopped it from working. Uses the uninit locals check to prevent breakages. Optimised -Os. 'local const foo' definitions no longer sit within the local variables block. Fixed confusion between OP_BOUNDCHECK and jumps. ------------------------------------------------------------------------ git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4172 fc73d0e0-1445-4013-8a0c-d673dee63da5
117 lines
2.1 KiB
C
117 lines
2.1 KiB
C
#include "qcc.h"
|
|
|
|
#include <stdarg.h>
|
|
#include <stdio.h>
|
|
|
|
/*
|
|
==============
|
|
LoadFile
|
|
==============
|
|
*/
|
|
unsigned char *PDECL QCC_ReadFile (const char *fname, void *buffer, int len)
|
|
{
|
|
long length;
|
|
FILE *f;
|
|
f = fopen(fname, "rb");
|
|
if (!f)
|
|
return NULL;
|
|
length = fread(buffer, 1, len, f);
|
|
fclose(f);
|
|
|
|
if (length != len)
|
|
return NULL;
|
|
|
|
return buffer;
|
|
}
|
|
int PDECL QCC_FileSize (const char *fname)
|
|
{
|
|
long length;
|
|
FILE *f;
|
|
f = fopen(fname, "rb");
|
|
if (!f)
|
|
return -1;
|
|
fseek(f, 0, SEEK_END);
|
|
length = ftell(f);
|
|
fclose(f);
|
|
|
|
return length;
|
|
}
|
|
|
|
pbool PDECL QCC_WriteFile (const char *name, void *data, int len)
|
|
{
|
|
long length;
|
|
FILE *f;
|
|
f = fopen(name, "wb");
|
|
if (!f)
|
|
return false;
|
|
length = fwrite(data, 1, len, f);
|
|
fclose(f);
|
|
|
|
if (length != len)
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
#undef printf
|
|
#undef Sys_Error
|
|
|
|
void PDECL Sys_Error(const char *text, ...)
|
|
{
|
|
va_list argptr;
|
|
static char msg[2048];
|
|
|
|
va_start (argptr,text);
|
|
QC_vsnprintf (msg,sizeof(msg)-1, text,argptr);
|
|
va_end (argptr);
|
|
|
|
QCC_Error(ERR_INTERNAL, "%s", msg);
|
|
}
|
|
|
|
|
|
FILE *logfile;
|
|
int logprintf(const char *format, ...)
|
|
{
|
|
va_list argptr;
|
|
static char string[1024];
|
|
|
|
va_start (argptr, format);
|
|
#ifdef _WIN32
|
|
_vsnprintf (string,sizeof(string)-1, format,argptr);
|
|
#else
|
|
vsnprintf (string,sizeof(string), format,argptr);
|
|
#endif
|
|
va_end (argptr);
|
|
|
|
printf("%s", string);
|
|
if (logfile)
|
|
fputs(string, logfile);
|
|
|
|
return 0;
|
|
}
|
|
|
|
int main (int argc, char **argv)
|
|
{
|
|
int sucess;
|
|
progexterns_t ext;
|
|
progfuncs_t funcs;
|
|
progfuncs = &funcs;
|
|
memset(&funcs, 0, sizeof(funcs));
|
|
funcs.funcs.parms = &ext;
|
|
memset(&ext, 0, sizeof(progexterns_t));
|
|
funcs.funcs.parms->ReadFile = QCC_ReadFile;
|
|
funcs.funcs.parms->FileSize = QCC_FileSize;
|
|
funcs.funcs.parms->WriteFile = QCC_WriteFile;
|
|
funcs.funcs.parms->Printf = logprintf;
|
|
funcs.funcs.parms->Sys_Error = Sys_Error;
|
|
logfile = fopen("fteqcc.log", "wt");
|
|
sucess = CompileParams(&funcs, true, argc, argv);
|
|
qccClearHunk();
|
|
if (logfile)
|
|
fclose(logfile);
|
|
|
|
#ifdef _WIN32
|
|
// fgetc(stdin); //wait for keypress
|
|
#endif
|
|
return !sucess;
|
|
}
|