2009-06-13 20:52:43 +00:00
|
|
|
#include "qcc.h"
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
==============
|
|
|
|
LoadFile
|
|
|
|
==============
|
|
|
|
*/
|
2018-05-28 10:12:10 +00:00
|
|
|
void *QCC_ReadFile(const char *fname, unsigned char *(*buf_get)(void *ctx, size_t len), void *buf_ctx, size_t *out_size, pbool issourcefile)
|
2018-01-23 01:49:49 +00:00
|
|
|
//unsigned char *PDECL QCC_ReadFile (const char *fname, void *buffer, int len, size_t *sz)
|
2009-06-13 20:52:43 +00:00
|
|
|
{
|
2018-01-23 01:49:49 +00:00
|
|
|
size_t len;
|
2009-06-13 20:52:43 +00:00
|
|
|
FILE *f;
|
2018-01-23 01:49:49 +00:00
|
|
|
char *buffer;
|
|
|
|
|
2009-06-13 20:52:43 +00:00
|
|
|
f = fopen(fname, "rb");
|
|
|
|
if (!f)
|
2018-01-23 01:49:49 +00:00
|
|
|
{
|
|
|
|
if (out_size)
|
|
|
|
*out_size = 0;
|
2009-06-13 20:52:43 +00:00
|
|
|
return NULL;
|
2018-01-23 01:49:49 +00:00
|
|
|
}
|
2009-06-13 20:52:43 +00:00
|
|
|
|
2018-01-23 01:49:49 +00:00
|
|
|
fseek(f, 0, SEEK_END);
|
|
|
|
len = ftell(f);
|
|
|
|
fseek(f, 0, SEEK_SET);
|
|
|
|
if (buf_get)
|
|
|
|
buffer = buf_get(buf_ctx, len+1);
|
|
|
|
else
|
|
|
|
buffer = malloc(len+1);
|
|
|
|
((char*)buffer)[len] = 0;
|
|
|
|
if (len != fread(buffer, 1, len, f))
|
|
|
|
{
|
|
|
|
if (!buf_get)
|
|
|
|
free(buffer);
|
|
|
|
buffer = NULL;
|
|
|
|
}
|
|
|
|
fclose(f);
|
2009-06-13 20:52:43 +00:00
|
|
|
|
2018-01-23 01:49:49 +00:00
|
|
|
if (out_size)
|
|
|
|
*out_size = len;
|
2009-06-13 20:52:43 +00:00
|
|
|
return buffer;
|
|
|
|
}
|
2013-03-12 22:32:25 +00:00
|
|
|
int PDECL QCC_FileSize (const char *fname)
|
2009-06-13 20:52:43 +00:00
|
|
|
{
|
|
|
|
long length;
|
|
|
|
FILE *f;
|
|
|
|
f = fopen(fname, "rb");
|
|
|
|
if (!f)
|
|
|
|
return -1;
|
|
|
|
fseek(f, 0, SEEK_END);
|
|
|
|
length = ftell(f);
|
|
|
|
fclose(f);
|
|
|
|
|
|
|
|
return length;
|
|
|
|
}
|
|
|
|
|
2013-03-12 22:32:25 +00:00
|
|
|
pbool PDECL QCC_WriteFile (const char *name, void *data, int len)
|
2009-06-13 20:52:43 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
|
|
2013-03-12 22:32:25 +00:00
|
|
|
void PDECL Sys_Error(const char *text, ...)
|
2009-06-13 20:52:43 +00:00
|
|
|
{
|
|
|
|
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);
|
2015-04-14 12:24:05 +00:00
|
|
|
// fputs(string, stderr);
|
2009-06-13 20:52:43 +00:00
|
|
|
if (logfile)
|
|
|
|
fputs(string, logfile);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main (int argc, char **argv)
|
|
|
|
{
|
2015-04-14 12:24:05 +00:00
|
|
|
unsigned int i;
|
2014-08-03 14:47:47 +00:00
|
|
|
pbool sucess;
|
2009-06-13 20:52:43 +00:00
|
|
|
progexterns_t ext;
|
|
|
|
progfuncs_t funcs;
|
|
|
|
progfuncs = &funcs;
|
|
|
|
memset(&funcs, 0, sizeof(funcs));
|
2013-03-12 22:32:25 +00:00
|
|
|
funcs.funcs.parms = &ext;
|
2009-06-13 20:52:43 +00:00
|
|
|
memset(&ext, 0, sizeof(progexterns_t));
|
2013-03-12 22:32:25 +00:00
|
|
|
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;
|
2018-05-28 10:12:10 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
logfile = fopen("fteqcc.log", "wt");
|
|
|
|
#endif
|
|
|
|
if (logfile)
|
2015-04-14 12:24:05 +00:00
|
|
|
{
|
2018-05-28 10:12:10 +00:00
|
|
|
fputs("Args:", logfile);
|
|
|
|
for (i = 0; i < argc; i++)
|
|
|
|
{
|
|
|
|
if (strchr(argv[i], ' '))
|
|
|
|
fprintf(logfile, " \"%s\"", argv[i]);
|
|
|
|
else
|
|
|
|
fprintf(logfile, " %s", argv[i]);
|
|
|
|
}
|
|
|
|
fprintf(logfile, "\n");
|
2015-04-14 12:24:05 +00:00
|
|
|
}
|
2015-07-07 02:03:31 +00:00
|
|
|
sucess = CompileParams(&funcs, NULL, argc, argv);
|
2009-06-13 20:52:43 +00:00
|
|
|
qccClearHunk();
|
|
|
|
if (logfile)
|
|
|
|
fclose(logfile);
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
// fgetc(stdin); //wait for keypress
|
|
|
|
#endif
|
2014-08-03 14:47:47 +00:00
|
|
|
return sucess?EXIT_SUCCESS:EXIT_FAILURE;
|
2009-06-13 20:52:43 +00:00
|
|
|
}
|