bug 491796 - arm-wince-gcc should support link and entry options r=dougt

This commit is contained in:
Brad Lassey 2009-06-18 07:28:57 -04:00
parent acf1a18bb3
commit 96329b9967
7 changed files with 346 additions and 321 deletions

View File

@ -109,25 +109,33 @@ clean: clobber
clobber:
rm $(MOZCE_TOOLS_BIN_DIR)/*.exe
$(MOZCE_TOOLS_BIN_DIR)/arm-wince-as.exe: $(MOZCE_TOOLS_DIR)/arm-wince-as.c $(MOZCE_TOOLS_DIR)/toolspath.h $(MOZCE_TOOLS_DIR)/Makefile
$(MOZCE_TOOLS_BIN_DIR)/linkargs.obj: $(MOZCE_TOOLS_DIR)/linkargs.c $(MOZCE_TOOLS_DIR)/toolspath.h $(MOZCE_TOOLS_DIR)/Makefile
mkdir -p $(MOZCE_TOOLS_BIN_DIR);
$(CC) $(CFLAGS) -Fo$(MOZCE_TOOLS_BIN_DIR) -Fe$@ $(MOZCE_TOOLS_DIR)/arm-wince-as.c
$(CC) $(CFLAGS) -c -Fo$(MOZCE_TOOLS_BIN_DIR)/linkargs.obj $(MOZCE_TOOLS_DIR)/linkargs.c
$(MOZCE_TOOLS_BIN_DIR)/arm-wince-gcc.exe: $(MOZCE_TOOLS_DIR)/arm-wince-gcc.c $(MOZCE_TOOLS_DIR)/toolspath.h $(MOZCE_TOOLS_DIR)/Makefile
$(MOZCE_TOOLS_BIN_DIR)/toolspath.obj: $(MOZCE_TOOLS_DIR)/toolspath.c $(MOZCE_TOOLS_DIR)/toolspath.h $(MOZCE_TOOLS_DIR)/Makefile
mkdir -p $(MOZCE_TOOLS_BIN_DIR);
$(CC) $(CFLAGS) -Fo$(MOZCE_TOOLS_BIN_DIR) -Fe$@ $(MOZCE_TOOLS_DIR)/arm-wince-gcc.c
$(CC) $(CFLAGS) -c -Fo$(MOZCE_TOOLS_BIN_DIR)/toolspath.obj $(MOZCE_TOOLS_DIR)/toolspath.c
$(MOZCE_TOOLS_BIN_DIR)/arm-wince-lib.exe: $(MOZCE_TOOLS_DIR)/arm-wince-lib.c $(MOZCE_TOOLS_DIR)/toolspath.h $(MOZCE_TOOLS_DIR)/Makefile
$(MOZCE_TOOLS_BIN_DIR)/arm-wince-as.exe: $(MOZCE_TOOLS_DIR)/arm-wince-as.c $(MOZCE_TOOLS_DIR)/toolspath.h $(MOZCE_TOOLS_DIR)/Makefile $(MOZCE_TOOLS_BIN_DIR)/toolspath.obj
mkdir -p $(MOZCE_TOOLS_BIN_DIR);
$(CC) $(CFLAGS) -Fo$(MOZCE_TOOLS_BIN_DIR) -Fe$@ $(MOZCE_TOOLS_DIR)/arm-wince-lib.c
$(CC) $(CFLAGS) -Fo$(MOZCE_TOOLS_BIN_DIR) -Fe$@ $(MOZCE_TOOLS_DIR)/arm-wince-as.c -link $(MOZCE_TOOLS_BIN_DIR)/toolspath.obj
$(MOZCE_TOOLS_BIN_DIR)/arm-wince-link.exe: $(MOZCE_TOOLS_DIR)/arm-wince-link.c $(MOZCE_TOOLS_DIR)/toolspath.h $(MOZCE_TOOLS_DIR)/Makefile
$(MOZCE_TOOLS_BIN_DIR)/arm-wince-gcc.exe: $(MOZCE_TOOLS_DIR)/arm-wince-gcc.c $(MOZCE_TOOLS_DIR)/toolspath.h $(MOZCE_TOOLS_DIR)/Makefile $(MOZCE_TOOLS_BIN_DIR)/linkargs.obj $(MOZCE_TOOLS_BIN_DIR)/toolspath.obj
mkdir -p $(MOZCE_TOOLS_BIN_DIR);
$(CC) $(CFLAGS) -Fo$(MOZCE_TOOLS_BIN_DIR) -Fe$@ $(MOZCE_TOOLS_DIR)/arm-wince-link.c
$(CC) $(CFLAGS) -Fo$(MOZCE_TOOLS_BIN_DIR) -Fe$@ $(MOZCE_TOOLS_DIR)/arm-wince-gcc.c -link $(MOZCE_TOOLS_BIN_DIR)/linkargs.obj $(MOZCE_TOOLS_BIN_DIR)/toolspath.obj
$(MOZCE_TOOLS_BIN_DIR)/arm-wince-res.exe: $(MOZCE_TOOLS_DIR)/arm-wince-res.c $(MOZCE_TOOLS_DIR)/toolspath.h $(MOZCE_TOOLS_DIR)/Makefile
$(MOZCE_TOOLS_BIN_DIR)/arm-wince-lib.exe: $(MOZCE_TOOLS_DIR)/arm-wince-lib.c $(MOZCE_TOOLS_DIR)/toolspath.h $(MOZCE_TOOLS_DIR)/Makefile $(MOZCE_TOOLS_BIN_DIR)/toolspath.obj
mkdir -p $(MOZCE_TOOLS_BIN_DIR);
$(CC) $(CFLAGS) -Fo$(MOZCE_TOOLS_BIN_DIR) -Fe$@ $(MOZCE_TOOLS_DIR)/arm-wince-res.c
$(CC) $(CFLAGS) -Fo$(MOZCE_TOOLS_BIN_DIR) -Fe$@ $(MOZCE_TOOLS_DIR)/arm-wince-lib.c -link $(MOZCE_TOOLS_BIN_DIR)/toolspath.obj
$(MOZCE_TOOLS_BIN_DIR)/arm-wince-link.exe: $(MOZCE_TOOLS_DIR)/arm-wince-link.c $(MOZCE_TOOLS_DIR)/toolspath.h $(MOZCE_TOOLS_DIR)/Makefile $(MOZCE_TOOLS_BIN_DIR)/linkargs.obj $(MOZCE_TOOLS_BIN_DIR)/toolspath.obj
mkdir -p $(MOZCE_TOOLS_BIN_DIR);
$(CC) $(CFLAGS) -Fo$(MOZCE_TOOLS_BIN_DIR) -Fe$@ $(MOZCE_TOOLS_DIR)/arm-wince-link.c -link $(MOZCE_TOOLS_BIN_DIR)/linkargs.obj $(MOZCE_TOOLS_BIN_DIR)/toolspath.obj
$(MOZCE_TOOLS_BIN_DIR)/arm-wince-res.exe: $(MOZCE_TOOLS_DIR)/arm-wince-res.c $(MOZCE_TOOLS_DIR)/toolspath.h $(MOZCE_TOOLS_DIR)/Makefile $(MOZCE_TOOLS_BIN_DIR)/toolspath.obj
mkdir -p $(MOZCE_TOOLS_BIN_DIR);
$(CC) $(CFLAGS) -Fo$(MOZCE_TOOLS_BIN_DIR) -Fe$@ $(MOZCE_TOOLS_DIR)/arm-wince-res.c -link $(MOZCE_TOOLS_BIN_DIR)/toolspath.obj
export:: $(SDK_TOOLS)

View File

@ -1,5 +1,5 @@
#include "toolspath.h"
#include "linkargs.h"
int
main(int argc, char **argv)
@ -8,6 +8,8 @@ main(int argc, char **argv)
int i = 0;
int j = 0;
int link = 0;
int s = 0;
int k = 0;
char* args[1000];
char outputFileArg[1000];
@ -66,29 +68,20 @@ main(int argc, char **argv)
strcat(outputFileArg, args[startOfArgvs+j]);
args[startOfArgvs+j] = outputFileArg;
}
if (strcmp(argv[j], "-link") ||
strcmp(argv[j], "-LINK") ||
strcmp(argv[j], "/link") ||
strcmp(argv[j], "/LINK"))
link = 1;
checkLinkArgs(&k, &s, &i, &j, args, argv);
j++;
}
if (link)
{
args[i++] = "/link";
args[i++] = "/ENTRY:main";
args[i++] = "/SUBSYSTEM:WINDOWSCE,5.02";
args[i++] = "/LIBPATH:\"" WCE_LIB "\"";
args[i++] = "/LIBPATH:\"" WCE_CRT "\"";
args[i++] = "/NODEFAULTLIB";
#ifdef HAVE_SHUNT // simple test to see if we're in configure or not
if(!getenv("NO_SHUNT")) {
args[i++] = "/LIBPATH:\"" SHUNT_LIB "\"";
args[i++] = "mozce_shunt.lib";
}
#endif
args[i++] = "winsock.lib";
args[i++] = "corelibc.lib";
args[i++] = "coredll.lib";
addLinkArgs(k, s, &i, &j, args, argv);
}
args[i] = NULL;

View File

@ -1,4 +1,5 @@
#include "toolspath.h"
#include "linkargs.h"
int
main(int argc, char **argv)
@ -9,56 +10,17 @@ main(int argc, char **argv)
int j = 0;
int k = 0;
int s = 0;
args[i++] = LINK_PATH;
args[i++] = "/LIBPATH:\"" WCE_LIB "\"";
args[i++] = "/LIBPATH:\"" WCE_CRT "\"";
args[i++] = "/NODEFAULTLIB";
#ifdef HAVE_SHUNT // simple test to see if we're in configure or not
if(getenv("NO_SHUNT") == NULL) {
args[i++] = "/LIBPATH:\"" SHUNT_LIB "\"";
args[i++] = "mozce_shunt.lib";
}
#endif
args[i++] = "corelibc.lib";
args[i++] = "coredll.lib";
args[i++] = "ceshell.lib";
args[i++] = "mmtimer.lib";
// if -DLL is not passed, then change the entry to 'main'
while(argv[j]) {
if (strncmp(argv[j], "-DLL", 4) == 0 ||
strncmp(argv[j], "/DLL", 4) == 0) {
k = 1;
}
if (strncmp(argv[j], "-entry", 6) == 0 ||
strncmp(argv[j], "/entry", 6) == 0 ||
strncmp(argv[j], "-ENTRY", 6) == 0 ||
strncmp(argv[j], "/ENTRY",6 ) == 0) {
k = 1;
}
if (strncmp(argv[j], "-subsystem:", 11) == 0 ||
strncmp(argv[j], "/subsystem:", 11) == 0 ||
strncmp(argv[j], "-SUBSYSTEM:", 11) == 0 ||
strncmp(argv[j], "/SUBSYSTEM:", 11) == 0) {
s = 1;
}
j++;
}
if (k==0)
args[i++] = "/ENTRY:main";
if (s==0){
args[i++] = "/subsystem:\"WINDOWSCE,5.02\"";
checkLinkArgs(&k, &s, &i, &j, args, argv);
j++;
}
args[i++] = LINK_PATH;
addLinkArgs(k, s, &i, &j, args, argv);
argpath_conv(&argv[1], &args[i]);
// dumpargs(args);
return run(args);
}

View File

@ -0,0 +1,46 @@
#include "toolspath.h"
#include "linkargs.h"
void checkLinkArgs(int* k, int* s, int* i, int* j, char** args, char** argv) {
if (strncmp(argv[*j], "-DLL", 4) == 0 ||
strncmp(argv[*j], "/DLL", 4) == 0) {
*k = 1;
}
if (strncmp(argv[*j], "-entry", 6) == 0 ||
strncmp(argv[*j], "/entry", 6) == 0 ||
strncmp(argv[*j], "-ENTRY", 6) == 0 ||
strncmp(argv[*j], "/ENTRY",6 ) == 0) {
*k = 1;
}
if (strncmp(argv[*j], "-subsystem:", 11) == 0 ||
strncmp(argv[*j], "/subsystem:", 11) == 0 ||
strncmp(argv[*j], "-SUBSYSTEM:", 11) == 0 ||
strncmp(argv[*j], "/SUBSYSTEM:", 11) == 0) {
*s = 1;
}
}
void addLinkArgs(int k, int s, int *i, int *j, char** args, char** argv) {
args[(*i)++] = "/LIBPATH:\"" WCE_LIB "\"";
args[(*i)++] = "/LIBPATH:\"" WCE_CRT "\"";
args[(*i)++] = "/NODEFAULTLIB";
#ifdef HAVE_SHUNT // simple test to see if we're in configure or not
if(getenv("NO_SHUNT") == NULL) {
args[(*i)++] = "/LIBPATH:\"" SHUNT_LIB "\"";
args[(*i)++] = "mozce_shunt.lib";
}
#endif
args[(*i)++] = "corelibc.lib";
args[(*i)++] = "coredll.lib";
args[(*i)++] = "ceshell.lib";
args[(*i)++] = "mmtimer.lib";
if (k==0)
args[(*i)++] = "/ENTRY:main";
if (s==0){
args[(*i)++] = "/subsystem:\"WINDOWSCE,5.02\"";
}
}

View File

@ -0,0 +1,7 @@
#ifndef LINKARGS_H
#define LINKARGS_H
void checkLinkArgs(int* k, int* s, int* i, int* j, char** args, char** argv);
void addLinkArgs(int k, int s, int *i, int *j, char** args, char** argv);
#endif

View File

@ -0,0 +1,251 @@
#include "toolspath.h"
int argpath_conv(char **args_in, char **args_out)
{
int i = 0;
while (args_in[i])
{
char *offset;
args_out[i] = args_in[i];
if (args_in[i])
{
// First, look for the case of "-Fo/c/xxxxxxx" and "/Fo/c/xxxxx"
if ( (args_out[i][0] == '-' || args_out[i][0] == '/') &&
(args_out[i][1] == 'F') && (args_out[i][2] == 'o') &&
(args_out[i][3] == '/') && (strlen(args_out[i]) > 5) ) {
//printf("ARGS_IN: -FoXXXX is %s\n",args_in[i]);
strcpy(noleak_buffers[next_buffer], args_in[i]);
noleak_buffers[next_buffer][0] = '/';
noleak_buffers[next_buffer][3] = noleak_buffers[next_buffer][4];
noleak_buffers[next_buffer][4] = ':';
args_out[i] = noleak_buffers[next_buffer];
//printf("ARGS_OUT: -FoXXXX is %s\n",args_out[i]);
next_buffer++;
}
else if ((args_out[i][0] == '/') && (args_out[i][2] == '/'))
{
// Assume this is a pathname, and adjust accordingly
//printf("ARGS_IN: PATHNAME ASSUMED: %s\n", args_in[i]);
strcpy(noleak_buffers[next_buffer], args_in[i]);
noleak_buffers[next_buffer][0] = noleak_buffers[next_buffer][1];
noleak_buffers[next_buffer][1] = ':';
args_out[i] = noleak_buffers[next_buffer];
//printf("ARGS_OUT: PATHNAME MODIFIED TO BE: %s\n", args_out[i]);
next_buffer++;
}
else if ((args_out[i][0] == '\\') && (args_out[i][2] == '\\'))
{
// Assume this is a pathname, and adjust accordingly
//printf("ARGS_IN: PATHNAME ASSUMED: %s\n", args_in[i]);
strcpy(noleak_buffers[next_buffer], args_in[i]);
noleak_buffers[next_buffer][0] = noleak_buffers[next_buffer][1];
noleak_buffers[next_buffer][1] = ':';
args_out[i] = noleak_buffers[next_buffer];
//printf("ARGS_OUT: PATHNAME MODIFIED TO BE: %s\n", args_out[i]);
next_buffer++;
}
else if ((args_out[i][0] == '\\') && (args_out[i][1] == '\\') &&
(args_out[i][3] == '\\') && (args_out[i][4] == '\\'))
{
// Assume this is a pathname, and adjust accordingly
//printf("ARGS_IN: PATHNAME ASSUMED: %s\n", args_in[i]);
noleak_buffers[next_buffer][0] = args_in[i][2];
noleak_buffers[next_buffer][1] = ':';
noleak_buffers[next_buffer][2] = '\0';
strcpy(noleak_buffers[next_buffer], &args_in[i][3]);
args_out[i] = noleak_buffers[next_buffer];
//printf("ARGS_OUT: PATHNAME MODIFIED TO BE: %s\n", args_out[i]);
next_buffer++;
}
else if ( strstr(args_out[i], "OUT:") || strstr(args_out[i], "DEF:") )
{
// Deal with -OUT:/c/....
//
// NOTE: THERE IS A BUG IN THIS IMPLEMENTATION IF
// THERE IS A SPACE IN THE TOPSRCDIR PATH.
//
// Should really check for spaces, then double-quote
// the path if any space is found.
// -- wolfe@lobo.us 25-Aug-08
if ((args_out[i][5] == '/') && (args_out[i][7] == '/'))
{
// Assume this is a pathname, and adjust accordingly
//printf("ARGS_IN: PATHNAME ASSUMED: %s\n", args_in[i]);
strcpy(noleak_buffers[next_buffer], args_in[i]);
noleak_buffers[next_buffer][5] = noleak_buffers[next_buffer][6];
noleak_buffers[next_buffer][6] = ':';
args_out[i] = noleak_buffers[next_buffer];
//printf("ARGS_OUT: PATHNAME MODIFIED TO BE: %s\n", args_out[i]);
}
// Deal with -OUT:"/c/...."
else if ((args_out[i][6] == '/') && (args_out[i][8] == '/'))
{
// Assume this is a pathname, and adjust accordingly
//printf("ARGS_IN: PATHNAME ASSUMED: %s\n", args_in[i]);
strcpy(noleak_buffers[next_buffer], args_in[i]);
noleak_buffers[next_buffer][6] = noleak_buffers[next_buffer][7];
noleak_buffers[next_buffer][7] = ':';
args_out[i] = noleak_buffers[next_buffer];
//printf("ARGS_OUT: PATHNAME MODIFIED TO BE: %s\n", args_out[i]);
}
next_buffer++;
}
else
{
char *offset = strstr(args_out[i], "/cygdrive/");
if (offset) {
strcpy(offset, offset+9);
offset[0] = offset[1];
offset[1] = ':';
offset[2] = '/';
}
if ( (args_out[i][0] == '-' || args_out[i][0] == '/') &&
(args_out[i][1] == 'D'))
{
offset = strstr(args_out[i]+2, "=");
if (offset)
{
char* equalsChar = offset;
if (equalsChar[1] == '"')
{
*equalsChar = '\0';
strcpy(noleak_buffers[next_buffer], args_out[i]);
*equalsChar = '=';
strcat(noleak_buffers[next_buffer], "=\\\"");
strcat(noleak_buffers[next_buffer], equalsChar+1);
strcat(noleak_buffers[next_buffer], "\\\"");
args_out[i] = noleak_buffers[next_buffer];
next_buffer++;
}
}
}
}
if (next_buffer > MAX_NOLEAK_BUFFERS) {
printf("OOPS - next_buffer > MAX_NOLEAK_BUFFERS\n");
exit(-1);
}
}
i++;
}
args_out[i] = NULL;
return i;
}
void dumpargs(char** args)
{
int i = 0;
if (args[0] == NULL)
printf(":: first element is null!\n");
while(args[i])
printf("%s ", args[i++]);
printf("\n");
fflush(stdout);
fflush(stderr);
}
DWORD run(char** args)
{
DWORD exitCode;
STARTUPINFO si;
PROCESS_INFORMATION pi;
char theArgs[1024*32] = {'\0'};
int totalLen = 0;
int i, j;
// Clear any link env variable that might get us tangled up
_putenv("LINK=");
_putenv("LIBPATH=");
_putenv("CC=");
_putenv("INCLUDE=" SHUNT_INC ";" WM_SDK_INC ";" WCE_INC);
_putenv("LIB=" WCE_LIB ";" WCE_CRT);
for (j=1; args[j]; j++)
{
int len = strlen(args[j]);
strcat(&theArgs[totalLen], args[j]);
totalLen += len;
strcat(&theArgs[totalLen], " ");
totalLen++;
}
i = strlen(args[0]);
for (j=0; j<i; j++)
{
if (args[0][j] == '/')
args[0][j] = '\\';
}
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi));
CreateProcess(args[0],
theArgs,
NULL,
NULL,
0,
0,
NULL,
NULL,
&si, // Pointer to STARTUPINFO structure.
&pi);
// Wait until child process exits.
WaitForSingleObject( pi.hProcess, INFINITE );
GetExitCodeProcess(pi.hProcess, &exitCode);
// Close process and thread handles.
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
return exitCode;
}

View File

@ -1,3 +1,6 @@
#ifndef TOOLPATH_H
#define TOOLPATH_H
#include <windows.h>
#include <stdio.h>
#include <process.h>
@ -27,253 +30,8 @@
#define MAX_NOLEAK_BUFFERS 1000
char noleak_buffers[MAX_NOLEAK_BUFFERS][1024];
static int next_buffer = 0;
int argpath_conv(char **args_in, char **args_out);
void dumpargs(char** args);
DWORD run(char** args);
int argpath_conv(char **args_in, char **args_out)
{
int i = 0;
while (args_in[i])
{
char *offset;
args_out[i] = args_in[i];
if (args_in[i])
{
// First, look for the case of "-Fo/c/xxxxxxx" and "/Fo/c/xxxxx"
if ( (args_out[i][0] == '-' || args_out[i][0] == '/') &&
(args_out[i][1] == 'F') && (args_out[i][2] == 'o') &&
(args_out[i][3] == '/') && (strlen(args_out[i]) > 5) ) {
//printf("ARGS_IN: -FoXXXX is %s\n",args_in[i]);
strcpy(noleak_buffers[next_buffer], args_in[i]);
noleak_buffers[next_buffer][0] = '/';
noleak_buffers[next_buffer][3] = noleak_buffers[next_buffer][4];
noleak_buffers[next_buffer][4] = ':';
args_out[i] = noleak_buffers[next_buffer];
//printf("ARGS_OUT: -FoXXXX is %s\n",args_out[i]);
next_buffer++;
}
else if ((args_out[i][0] == '/') && (args_out[i][2] == '/'))
{
// Assume this is a pathname, and adjust accordingly
//printf("ARGS_IN: PATHNAME ASSUMED: %s\n", args_in[i]);
strcpy(noleak_buffers[next_buffer], args_in[i]);
noleak_buffers[next_buffer][0] = noleak_buffers[next_buffer][1];
noleak_buffers[next_buffer][1] = ':';
args_out[i] = noleak_buffers[next_buffer];
//printf("ARGS_OUT: PATHNAME MODIFIED TO BE: %s\n", args_out[i]);
next_buffer++;
}
else if ((args_out[i][0] == '\\') && (args_out[i][2] == '\\'))
{
// Assume this is a pathname, and adjust accordingly
//printf("ARGS_IN: PATHNAME ASSUMED: %s\n", args_in[i]);
strcpy(noleak_buffers[next_buffer], args_in[i]);
noleak_buffers[next_buffer][0] = noleak_buffers[next_buffer][1];
noleak_buffers[next_buffer][1] = ':';
args_out[i] = noleak_buffers[next_buffer];
//printf("ARGS_OUT: PATHNAME MODIFIED TO BE: %s\n", args_out[i]);
next_buffer++;
}
else if ((args_out[i][0] == '\\') && (args_out[i][1] == '\\') &&
(args_out[i][3] == '\\') && (args_out[i][4] == '\\'))
{
// Assume this is a pathname, and adjust accordingly
//printf("ARGS_IN: PATHNAME ASSUMED: %s\n", args_in[i]);
noleak_buffers[next_buffer][0] = args_in[i][2];
noleak_buffers[next_buffer][1] = ':';
noleak_buffers[next_buffer][2] = '\0';
strcpy(noleak_buffers[next_buffer], &args_in[i][3]);
args_out[i] = noleak_buffers[next_buffer];
//printf("ARGS_OUT: PATHNAME MODIFIED TO BE: %s\n", args_out[i]);
next_buffer++;
}
else if ( strstr(args_out[i], "OUT:") || strstr(args_out[i], "DEF:") )
{
// Deal with -OUT:/c/....
//
// NOTE: THERE IS A BUG IN THIS IMPLEMENTATION IF
// THERE IS A SPACE IN THE TOPSRCDIR PATH.
//
// Should really check for spaces, then double-quote
// the path if any space is found.
// -- wolfe@lobo.us 25-Aug-08
if ((args_out[i][5] == '/') && (args_out[i][7] == '/'))
{
// Assume this is a pathname, and adjust accordingly
//printf("ARGS_IN: PATHNAME ASSUMED: %s\n", args_in[i]);
strcpy(noleak_buffers[next_buffer], args_in[i]);
noleak_buffers[next_buffer][5] = noleak_buffers[next_buffer][6];
noleak_buffers[next_buffer][6] = ':';
args_out[i] = noleak_buffers[next_buffer];
//printf("ARGS_OUT: PATHNAME MODIFIED TO BE: %s\n", args_out[i]);
}
// Deal with -OUT:"/c/...."
else if ((args_out[i][6] == '/') && (args_out[i][8] == '/'))
{
// Assume this is a pathname, and adjust accordingly
//printf("ARGS_IN: PATHNAME ASSUMED: %s\n", args_in[i]);
strcpy(noleak_buffers[next_buffer], args_in[i]);
noleak_buffers[next_buffer][6] = noleak_buffers[next_buffer][7];
noleak_buffers[next_buffer][7] = ':';
args_out[i] = noleak_buffers[next_buffer];
//printf("ARGS_OUT: PATHNAME MODIFIED TO BE: %s\n", args_out[i]);
}
next_buffer++;
}
else
{
char *offset = strstr(args_out[i], "/cygdrive/");
if (offset) {
strcpy(offset, offset+9);
offset[0] = offset[1];
offset[1] = ':';
offset[2] = '/';
}
if ( (args_out[i][0] == '-' || args_out[i][0] == '/') &&
(args_out[i][1] == 'D'))
{
offset = strstr(args_out[i]+2, "=");
if (offset)
{
char* equalsChar = offset;
if (equalsChar[1] == '"')
{
*equalsChar = '\0';
strcpy(noleak_buffers[next_buffer], args_out[i]);
*equalsChar = '=';
strcat(noleak_buffers[next_buffer], "=\\\"");
strcat(noleak_buffers[next_buffer], equalsChar+1);
strcat(noleak_buffers[next_buffer], "\\\"");
args_out[i] = noleak_buffers[next_buffer];
next_buffer++;
}
}
}
}
if (next_buffer > MAX_NOLEAK_BUFFERS) {
printf("OOPS - next_buffer > MAX_NOLEAK_BUFFERS\n");
exit(-1);
}
}
i++;
}
args_out[i] = NULL;
return i;
}
void dumpargs(char** args)
{
int i = 0;
if (args[0] == NULL)
printf(":: first element is null!\n");
while(args[i])
printf("%s ", args[i++]);
printf("\n");
fflush(stdout);
fflush(stderr);
}
DWORD run(char** args)
{
DWORD exitCode;
STARTUPINFO si;
PROCESS_INFORMATION pi;
char theArgs[1024*32];
int totalLen = 0;
int i, j;
// Clear any link env variable that might get us tangled up
_putenv("LINK=");
_putenv("LIBPATH=");
_putenv("CC=");
_putenv("INCLUDE=" SHUNT_INC ";" WM_SDK_INC ";" WCE_INC);
_putenv("LIB=" WCE_LIB ";" WCE_CRT);
for (j=1; args[j]; j++)
{
int len = strlen(args[j]);
strcat(&theArgs[totalLen], args[j]);
totalLen += len;
strcat(&theArgs[totalLen], " ");
totalLen++;
}
i = strlen(args[0]);
for (j=0; j<i; j++)
{
if (args[0][j] == '/')
args[0][j] = '\\';
}
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi));
CreateProcess(args[0],
theArgs,
NULL,
NULL,
0,
0,
NULL,
NULL,
&si, // Pointer to STARTUPINFO structure.
&pi);
// Wait until child process exits.
WaitForSingleObject( pi.hProcess, INFINITE );
GetExitCodeProcess(pi.hProcess, &exitCode);
// Close process and thread handles.
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
return exitCode;
}
#endif