I'm trying to write a simple program to act as a middle man for Borland's command line compiler. This way, I save the time of typing out many different options. But I keep encountering a problem at runtime and the program closes.
My problem, I think, is with a C style string, but since most of my code is C++, I decided to post it here. However, I did try using a C++ style string, but I got the same error at runtime. I managed to pinpoint the line on which the error occurs, each time, but as you know, this doesn't necessarily mean anything.
Code:#include <stdio.h>
#include "WindowProcedures.h"
int main(int argc, char* argv[])
{
string Borland = "bcc32";
string SetBorlandDirectory = "cd C:\\Borland\\Bcc55\\Bin";
string source;
char* csource = reinterpret_cast<char*>(malloc(MAX_PATH));
int csourcesize;
string directory;
string resetdirectory;
char cshortexecutable[MAX_PATH];
for(int index = 0; index < MAX_PATH; ++index)
cshortexecutable[index] = 0;
string shortexecutable;
string executable;
string arguments;
if(argc == 1)
{
system("C:\\Borland\\Bcc55\\Bin\\bcc32");
return EXIT_SUCCESS;
}
source = argv[1];
csource = strcpy(csource, argv[1]);
for(int index = 0; 1; ++index)
{
if(csource[index] != 0)
++csourcesize;
else
break;
}
for(int index = csourcesize; index >= 0; --index)
{
if(csource[index] == '\\') // ERROR OCCURS HERE...
{
for(; index < csourcesize; ++index)
csource[index] = 0;
break;
}
}
directory = csource;
resetdirectory = "cd \"" + directory + "\"";
csource = strcpy(csource, argv[1]);
for(int index = csourcesize + 1; index >= 0; --index)
{
if(csource[index] == '\\')
{
for(int index2 = 0; index < csourcesize; ++index2)
{
++index;
if(csource[index] != '.')
cshortexecutable[index2] = csource[index];
else
{
cshortexecutable[index2] = '.';
cshortexecutable[++index2] = 'e';
cshortexecutable[++index2] = 'x';
cshortexecutable[++index2] = 'e';
break;
}
}
break;
}
}
shortexecutable = cshortexecutable;
executable = directory + shortexecutable;
arguments = Borland + " -I\"" + directory + "\" -e\"" + executable + "\" \"" + source + "\"";
cout << SetBorlandDirectory << endl;
cout << arguments << endl;
cout << resetdirectory << endl;
/* system(SetBorlandDirectory.c_str());
system(arguments.c_str());
system(resetdirectory.c_str());*/
free(csource);
return EXIT_SUCCESS;
}
