Fixed the remaining omision with commandlines. It should now function as a complete drop-in replacement for the original id q3asm.

git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@2913 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
Spoike 2008-02-11 22:38:05 +00:00
parent 9e3c465a79
commit eff3e85911
1 changed files with 97 additions and 12 deletions

View File

@ -828,15 +828,24 @@ void AssembleFile(struct assembler *w, int fnum, char *filename)
w->curseg = &w->segs[SEG_CODE];
f = fopen(filename, "rt");
f = fopen(filename, "rt");
if (!f)
{
_snprintf(linebuffer, sizeof(linebuffer)-1, "%s.asm", filename);
f = fopen(linebuffer, "rt");
}
if (f)
{
while(fgets(linebuffer, sizeof(linebuffer), f))
AssembleLine(w, linebuffer);
fclose(f);
}
else
w->errorcount++;
else
{
printf("couldn't open %s\n", filename);
w->errorcount++;
}
//reset the local symbol hash, so we don't find conflicting vars
memset(w->localsymboltablebuckets, 0, sizeof(w->localsymboltablebuckets));
@ -1044,7 +1053,13 @@ void Assemble(struct workload *w)
int ParseCommandList(struct workload *w, int numcmds, char **cmds)
{
char **t;
char **t;
FILE *f;
char *buffer, *pp, *pps;
unsigned int len, numextraargs;
char *suppargs[64];
while (numcmds)
{
if ((*cmds)[0] == '-')
@ -1052,19 +1067,89 @@ int ParseCommandList(struct workload *w, int numcmds, char **cmds)
if ((*cmds)[1] == 'f')
{
numcmds--;
cmds++;
//todo: include a file
printf("-f directive not supported yet\n");
return 1;
cmds++;
f = fopen(*cmds, "rt");
if (!f)
{
char blah[256];
_snprintf(blah, sizeof(blah)-1, "%s.q3asm", *cmds);
f = fopen(blah, "rt");
}
if (f)
{
fseek(f, 0, SEEK_END);
len = ftell(f);
fseek(f, 0, SEEK_SET);
buffer = malloc((len+9));
if (buffer)
{
if (fread(buffer, 1, len, f) == len)
{
buffer[len] = 0;
numextraargs = 0;
pp = buffer;
do
{
if (numextraargs == sizeof(suppargs)/sizeof(suppargs[0]))
break;
while (*pp == ' ' || *pp == '\r' || *pp == '\n')
{
pp++;
}
if (*pp == '\"')
{
pp++;
pps = pp;
while (*pp && *pp != '\"')
pp++;
}
else
{
pps = pp;
while (*pp && !(*pp == ' ' || *pp == '\r' || *pp == '\n'))
{
pp++;
}
}
if (*pp)
*pp++ = 0;
suppargs[numextraargs] = pps;
numextraargs++;
} while (*pp);
ParseCommandList(w, numextraargs, suppargs);
}
else
{
printf("failure reading source file\n");
}
free(buffer);
}
else
{
printf("out of memory\n");
}
fclose(f);
}
else
{
printf("couldn't open \"%s\"\n", *cmds);
}
}
else if ((*cmds)[1] == 'o')
{
numcmds--;
cmds++;
strncpy(w->output, *cmds, sizeof(w->output)-1);
w->output[sizeof(w->output)-1] = 0;
if (!strchr(*cmds, '.'))
{
_snprintf(w->output, sizeof(w->output)-1, "%s.qvm", *cmds);
}
else
{
strncpy(w->output, *cmds, sizeof(w->output)-1);
w->output[sizeof(w->output)-1] = 0;
}
}
else if ((*cmds)[1] == 'v')
w->verbose = 1;