qasm/qasm.cpp

176 lines
3.3 KiB
C++
Raw Normal View History

2019-11-11 23:56:03 +00:00
#include "app.h"
#include "asm.h"
#define CLASS PAL_APPCLASS
// return a pointer to the actual Application class
PAL_BASEAPP *PAL::appFactory(void)
{
return (new CLASS());
}
// you MUST supply this array 'appOptions'. NULL line and end.
programOption PAL::appOptions[] =
{
{ "debug", "d", "enable debug info (repeat for more verbosity)", "", false, true},
{ "config", "f", "load configuration data from a <file>", "<file>", false, false},
{ "exec", "x", "execute a command", "<command>", false, false},
2019-11-11 23:56:03 +00:00
{ "", "", "", "", false, false}
};
int CLASS::runServerApp(PAL_EVENTMANAGER *em)
{
int res = -1;
if (em != NULL)
{
PAL_BASEAPP::runServerApp(em);
2019-11-12 18:13:15 +00:00
#if 0
2019-11-11 23:56:03 +00:00
PAL_HTTPSERVERTASK *server = new PAL_HTTPSERVERTASK("httptask");
if (server != NULL)
{
em->startTask(server);
server->initServer(getConfig("http.listen", "0.0.0.0:9080"), false, 64);
res = 0;
}
2019-11-12 18:13:15 +00:00
#endif
2019-11-11 23:56:03 +00:00
}
return (res);
}
2019-11-14 17:43:27 +00:00
void CLASS::showerror(int ecode, std::string fname)
{
std::string s;
switch (ecode)
{
case -2:
s = "Permission Denied";
break;
case -3:
s = "File not found";
break;
default:
s = "Unknown Error";
break;
}
2019-11-14 18:47:50 +00:00
if (ecode < -1)
{
std::string a = Poco::Util::Application::instance().config().getString("application.name", "");
fprintf(stderr, "%s: %s: %s\n", a.c_str(), fname.c_str(), s.c_str());
}
2019-11-14 17:43:27 +00:00
}
2019-11-11 23:56:03 +00:00
int CLASS::runCommandLineApp(void)
{
TFileProcessor *t = NULL;
std::string line;
2019-11-14 05:56:50 +00:00
std::string startdirectory;
2019-11-14 18:47:50 +00:00
std::string fname;
2019-11-11 23:56:03 +00:00
// only called if SERVERAPP not defined
int res = -1;
2019-11-14 05:56:50 +00:00
startdirectory = Poco::Path::current();
2019-11-14 06:03:34 +00:00
//LOG_DEBUG << "currentdir: " << startdirectory << endl;
2019-11-14 05:56:50 +00:00
if (commandargs.size() == 0)
{
2019-11-14 05:56:50 +00:00
fprintf(stderr, "No files given (--help for help)\n\n");
return (res);
}
2019-11-11 23:56:03 +00:00
for (ArgVec::const_iterator it = commandargs.begin(); it != commandargs.end(); ++it)
{
Poco::File fn(*it);
2019-11-14 17:32:11 +00:00
int x;
2019-11-11 23:56:03 +00:00
std::string p = fn.path();
Poco::Path path(p);
2019-11-14 06:03:34 +00:00
//logger().information(path.toString());
2019-11-11 23:56:03 +00:00
std::string e = toUpper(path.getExtension());
std::string cmd = Poco::toUpper(getConfig("option.exec", "asm"));
2019-11-11 23:56:03 +00:00
if (cmd.length() > 0)
2019-11-11 23:56:03 +00:00
{
if (cmd == "REFORMAT")
{
res = 0;
t = new TMerlinConverter();
if (t != NULL)
{
2019-11-14 05:56:50 +00:00
try
{
t->init();
std::string f = path.toString();
2019-11-14 17:43:27 +00:00
t->filename = f;
2019-11-14 18:47:50 +00:00
x = t->processfile(f,fname);
2019-11-14 17:32:11 +00:00
if (x == 0)
2019-11-14 15:28:42 +00:00
{
t->process();
t->complete();
}
2019-11-14 17:32:11 +00:00
else
{
2019-11-14 18:47:50 +00:00
showerror(x, fname);
2019-11-14 17:43:27 +00:00
t->errorct = 1;
2019-11-14 17:32:11 +00:00
}
2019-11-14 05:56:50 +00:00
res = (t->errorct > 0) ? -1 : 0;
}
catch (...)
{
delete t;
t = NULL;
}
}
}
else if (cmd == "ASM")
{
2019-11-14 17:32:11 +00:00
int x;
2019-11-14 15:28:42 +00:00
t = new T65816Asm();
if (t != NULL)
{
2019-11-14 05:56:50 +00:00
try
{
t->init();
std::string f = path.toString();
2019-11-14 17:43:27 +00:00
t->filename = f;
2019-11-14 18:47:50 +00:00
x = t->processfile(f,fname);
2019-11-14 17:43:27 +00:00
f = t->filename;
2019-11-14 17:32:11 +00:00
if (x == 0)
2019-11-14 15:28:42 +00:00
{
t->process();
t->complete();
}
2019-11-14 17:32:11 +00:00
else
{
2019-11-14 18:47:50 +00:00
showerror(x, fname);
2019-11-14 17:43:27 +00:00
t->errorct = 1;
2019-11-14 17:32:11 +00:00
}
2019-11-14 05:56:50 +00:00
res = (t->errorct > 0) ? -1 : 0;
}
catch (...)
{
delete t;
t = NULL;
}
chdir(startdirectory.c_str()); // return us back to where we were
}
else
{
printf("not supported type\n");
}
}
else
{
2019-11-14 05:56:50 +00:00
fprintf(stderr, "Invalid command: <%s>\n\n", cmd.c_str());
}
2019-11-11 23:56:03 +00:00
}
}
return (res);
}