Skip to content

Commit

Permalink
Merge pull request #3 from SpamixOfficial/master
Browse files Browse the repository at this point in the history
Replaced "usage" filename with actual filename, so that it fits all OS's
  • Loading branch information
miselin authored Jul 18, 2024
2 parents b5479eb + b3d4d67 commit 24df227
Showing 1 changed file with 41 additions and 33 deletions.
74 changes: 41 additions & 33 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,39 +44,47 @@ void stripExtension(const char *in, char *out, size_t len) {
*strrchr(out, '.') = 0;
}

int main(int argc, const char *argv[]) {
// check for valid number of arguments
if ((argc < 2) || (argv[1] == NULL)) {
// Inform the user
log(Error,
"Usage: tibasic.exe [options] "
"filename\nOptions:\n\t-d\t\tDecompile\n\t-o filename\tOutput file");
return 1;
}

Compiler compiler;
Compiler *pCompiler = &compiler;

string inFile, outFile;

bool bDecompile = false;

// Parse arguments
inFile = argv[argc - 1]; // Last argument is always filename
for (int i = 1; i < argc - 1; i++) {
if (!strcmp(argv[i], "-o") && !outFile.length()) {
i++; // Next argument is filename
// Output filename
if (i >= argc - 1) {
log(Error, "-o requires a parameter (output filename).");
return 1;
}
outFile = argv[i];
} else if (!strcmp(argv[i], "-d"))
bDecompile = true;
else {
log(Error, "Unknown option specified");
return 1;
int main( int argc, char* argv[] )
{
// check for valid number of arguments
if((argc < 2) || (argv[1] == NULL))
{

// Error string, with some minor formatting
string errorstring = "Usage: " + string(argv[0]) + " [options] filename\nOptions:\n\t-d\t\tDecompile\n\t-o filename\tOutput file";
// Inform the user
log(Error, errorstring.c_str());
return 1;
}

Compiler compiler; Compiler *pCompiler = &compiler;

string inFile, outFile;

bool bDecompile = false;

// Parse arguments
inFile = argv[argc - 1]; // Last argument is always filename
for(int i = 1; i < argc - 1; i++)
{
if(!strcmp(argv[i], "-o") && !outFile.length())
{
i++; // Next argument is filename
// Output filename
if(i >= argc - 1)
{
log(Error, "-o requires a parameter (output filename).");
return 1;
}
outFile = argv[i];
}
else if(!strcmp(argv[i], "-d"))
bDecompile = true;
else
{
log(Error, "Unknown option specified");
return 1;
}
}
}

Expand Down

0 comments on commit 24df227

Please sign in to comment.