Improved CLI interface

This commit is contained in:
David Anderson 2004-08-11 09:32:24 +00:00
parent b5ef654987
commit 7fad1802cf
4 changed files with 37 additions and 6 deletions

View File

@ -111,7 +111,7 @@ int Compiler::CipCount()
return cipc; return cipc;
} }
bool Compiler::Compile() bool Compiler::Compile(std::string &out)
{ {
if (CodeList.size() < 1 || !CError || CError->GetStatus() >= Err_Error) if (CodeList.size() < 1 || !CError || CError->GetStatus() >= Err_Error)
{ {
@ -204,7 +204,7 @@ bool Compiler::Compile()
fileSize = hea; fileSize = hea;
std::string amxname; std::string amxname;
amxname.assign(filename); amxname.assign(out);
int pos = (int)amxname.find(".asm"); int pos = (int)amxname.find(".asm");
if (pos != std::string::npos) if (pos != std::string::npos)
{ {

View File

@ -23,6 +23,7 @@
#include "amxasm.h" #include "amxasm.h"
std::string filename; std::string filename;
std::string output_name;
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
@ -33,13 +34,15 @@ int main(int argc, char **argv)
if (filename.size() < 1) if (filename.size() < 1)
{ {
print_version(); print_version();
print_options();
exit(0); exit(0);
} }
Program.Load(filename); Program.Load(filename);
if (Program.Parse()) if (Program.Parse())
{ {
if (Program.Compile())
if (Program.Compile(output_name.size() ? output_name : filename))
printf("Done.\n"); printf("Done.\n");
else else
printf("Compile build failed.\n"); printf("Compile build failed.\n");
@ -53,8 +56,9 @@ int main(int argc, char **argv)
void get_options(int argc, char **argv, Compiler &Prog) void get_options(int argc, char **argv, Compiler &Prog)
{ {
int i = 0; /* index */ int i = 0; /* index */
int opt_flag = 0; /* flag for option detection */ char opt_flag = 0; /* flag for option detection */
char *option = 0; /* option pointer */ char *option = 0; /* option pointer */
char c = 0; /* option marker */
for (i=1; i<argc; i++) for (i=1; i<argc; i++)
{ {
if (argv[i][0] == '-') if (argv[i][0] == '-')
@ -63,10 +67,21 @@ void get_options(int argc, char **argv, Compiler &Prog)
option = argv[i]; option = argv[i];
switch (argv[i][1]) switch (argv[i][1])
{ {
case 'o':
{
if (strlen(argv[i]) > 2)
{
output_name.assign(&(argv[i][2]));
} else {
opt_flag = 'o';
}
break;
}
case 'v': case 'v':
{ {
opt_flag = 0; /* no options expected */ opt_flag = 0; /* no options expected */
print_version(); print_version();
exit(0);
break; break;
} /* case */ } /* case */
case 'd': case 'd':
@ -81,7 +96,14 @@ void get_options(int argc, char **argv, Compiler &Prog)
{ {
filename.assign(argv[i]); filename.assign(argv[i]);
} else { } else {
/* TODO */ switch (opt_flag)
{
case 'o':
{
output_name.assign(argv[i]);
break;
}
}
} }
} /* if */ } /* if */
} }
@ -91,5 +113,13 @@ void print_version()
{ {
printf("Small/AMX Assembler 1.00\n"); printf("Small/AMX Assembler 1.00\n");
printf("(C)2004 David 'BAILOPAN' Anderson\n"); printf("(C)2004 David 'BAILOPAN' Anderson\n");
exit(0); }
void print_options()
{
printf("\nOptions:\n");
printf("\t-d\t\t- Add debug opcodes (will double file size)\n");
printf("\t-v\t\t- Output version and exit\n");
printf("\t-o\t\t- Specify file to write\n");
printf("\n");
} }

View File

@ -220,5 +220,6 @@ void get_options(int argc, char **argv, Compiler &Prog);
void InitOpcodes(); void InitOpcodes();
void DestroyArgList(std::vector<std::string *> &List); void DestroyArgList(std::vector<std::string *> &List);
void print_version(); void print_version();
void print_options();
#endif //_INCLUDE_AMXASM_H #endif //_INCLUDE_AMXASM_H

Binary file not shown.