Skip to content

Commit

Permalink
Merge pull request #4652 from WalterBright/runargs2
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinNowak authored and WalterBright committed May 15, 2015
1 parent 701e302 commit 49875d8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
10 changes: 5 additions & 5 deletions src/link.c
Original file line number Diff line number Diff line change
Expand Up @@ -811,18 +811,18 @@ int runProgram()
//printf("runProgram()\n");
if (global.params.verbose)
{
printf("%s", global.params.exefile);
for (size_t i = 0; i < global.params.runargs_length; i++)
printf(" %s", (char *)global.params.runargs[i]);
//printf("%s", global.params.exefile);
for (size_t i = 0; i < global.params.runargs->dim; ++i)
printf(" %s", (*global.params.runargs)[i]);
printf("\n");
}

// Build argv[]
Strings argv;

argv.push(global.params.exefile);
for (size_t i = 0; i < global.params.runargs_length; i++)
{ const char *a = global.params.runargs[i];
for (size_t i = 0; i < global.params.runargs->dim; ++i)
{ const char *a = (*global.params.runargs)[i];

#if _WIN32
// BUG: what about " appearing in the string?
Expand Down
19 changes: 13 additions & 6 deletions src/mars.c
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,8 @@ int main(int iargc, const char *argv[])
global.params.enabledV2hints = V2MODEnone;
global.params.quiet = 1;

global.params.runargs = new Strings();

global.params.linkswitches = new Strings();
global.params.libfiles = new Strings();
global.params.objfiles = new Strings();
Expand Down Expand Up @@ -933,9 +935,10 @@ int main(int iargc, const char *argv[])
exit(EXIT_SUCCESS);
}
else if (strcmp(p + 1, "run") == 0)
{ global.params.run = 1;
global.params.runargs_length = ((i >= argcstart) ? argc : argcstart) - i - 1;
if (global.params.runargs_length)
{
global.params.run = 1;
size_t length = ((i >= argcstart) ? argc : argcstart) - i - 1;
if (length)
{
const char *ext = FileName::ext(argv[i + 1]);
if (ext && FileName::equals(ext, "d") == 0
Expand All @@ -946,9 +949,12 @@ int main(int iargc, const char *argv[])
}

files.push((char *)argv[i + 1]);
global.params.runargs = &argv[i + 2];
i += global.params.runargs_length;
global.params.runargs_length--;
global.params.runargs->setDim(length - 1);
for (size_t j = 0; j < length - 1; ++j)
{
(*global.params.runargs)[j] = (char *)argv[i + 2 + j];
}
i += length;
}
else
{ global.params.run = 0;
Expand Down Expand Up @@ -1791,6 +1797,7 @@ V2MODE V2MODE_from_name(const char* name)

error(0, "-v2 mode '%s' unknown, aborting", name);
exit(2);
return (V2MODE)0;
}

const char* V2MODE_name(V2MODE mode)
Expand Down
3 changes: 1 addition & 2 deletions src/mars.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,7 @@ struct Param
char debugy;

char run; // run resulting executable
size_t runargs_length;
const char** runargs; // arguments for executable
Strings *runargs; // arguments for executable

// Linker stuff
Strings *objfiles;
Expand Down

0 comments on commit 49875d8

Please sign in to comment.