This commit is contained in:
marketideas 2019-11-13 21:56:50 -08:00
parent 04366729a8
commit 3dd2c835ba
2 changed files with 113 additions and 89 deletions

140
asm.cpp
View File

@ -394,93 +394,103 @@ int CLASS::processfile(std::string &p)
Poco::Path tp(p);
Poco::Path path = tp.makeAbsolute();
Poco::Path parent = path.parent();
std::string currentdir=Poco::Path::current();
std::string dir = parent.toString();;
valid = true;
p1 = tp.toString();
Poco::File fn(p1);
if (!fn.exists())
try
{
fn = Poco::File(p1 + ".s");
printf("filename : %s\n", path.toString().c_str());
printf("directory: %s\n", dir.c_str());
valid = true;
p1 = tp.toString();
Poco::File fn(p1);
if (!fn.exists())
{
fn = Poco::File(p1 + ".S");
fn = Poco::File(p1 + ".s");
if (!fn.exists())
{
fn = Poco::File(p1 + ".mac");
fn = Poco::File(p1 + ".S");
if (!fn.exists())
{
valid = false;
fn = Poco::File(p1 + ".mac");
if (!fn.exists())
{
valid = false;
}
}
}
}
}
p1 = fn.path();
p1 = fn.path();
if (valid)
{
std::ifstream f(p1);
if (f.is_open())
if (valid)
{
//printf("file is open\n");
line = "";
chdir(dir.c_str()); // change directory to where the file is
while ((!done) && (f.good()) && (!f.eof()))
std::ifstream f(p1);
if (f.is_open())
{
c = f.get();
if (c == 0x8D) // merlin line ending
//printf("file is open\n");
line = "";
while ((!done) && (f.good()) && (!f.eof()))
{
c = 0x0A; // convert to linux
c = f.get();
if (c == 0x8D) // merlin line ending
{
c = 0x0A; // convert to linux
}
if (c == 0x8A) // possible merlin line ending
{
c = 0x00; // ignore
}
c &= 0x7F;
int x;
switch (c)
{
case 0x0D:
break;
case 0x09:
line += " ";
break;
case 0x0A:
linect++;
x = doline(linect, line);
if (x < 0)
{
done = true;
}
line = "";
break;
default:
if ((c >= ' ') && (c < 0x7F))
{
line += c;
}
else
{
//printf("garbage %08X\n",c);
}
break;
}
}
if (c == 0x8A) // possible merlin line ending
if ( (f.eof()))
{
c = 0x00; // ignore
res = 0;
}
c &= 0x7F;
int x;
switch (c)
{
case 0x0D:
break;
case 0x09:
line += " ";
break;
case 0x0A:
linect++;
x = doline(linect, line);
if (x < 0)
{
done = true;
}
line = "";
break;
default:
if ((c >= ' ') && (c < 0x7F))
{
line += c;
}
else
{
//printf("garbage %08X\n",c);
}
break;
}
}
if ( (f.eof()))
{
res = 0;
}
}
else
{
fprintf(stderr, "File <%s> does not exist.\n\n", p.c_str());
}
}
else
catch(...)
{
fprintf(stderr, "File <%s> does not exist.\n\n", p.c_str());
}
chdir(currentdir.c_str());
//printf("\n\nfile read result: %d\n", res);
return (res);
}
@ -1231,7 +1241,7 @@ int CLASS::substituteVariables(MerlinLine & line)
std::string oper = line.operand;
std::string s;
TSymbol *sym;
uint32_t len, off,ct;
uint32_t len, off, ct;
slen = oper.length();
if (slen > 0)
@ -1267,7 +1277,7 @@ int CLASS::substituteVariables(MerlinLine & line)
if (sym != NULL)
{
ct++;
if (pass>0)
if (pass > 0)
{
//printf("%d |%s|\n", ct, s.c_str());
}

View File

@ -43,15 +43,18 @@ int CLASS::runCommandLineApp(void)
{
TFileProcessor *t = NULL;
std::string line;
std::string startdirectory;
// only called if SERVERAPP not defined
int res = -1;
//LOG_DEBUG << "command line mode" << endl;
if (commandargs.size()==0)
startdirectory = Poco::Path::current();
LOG_DEBUG << "currentdir: " << startdirectory << endl;
if (commandargs.size() == 0)
{
fprintf(stderr,"No files given (--help for help)\n\n");
return(res);
fprintf(stderr, "No files given (--help for help)\n\n");
return (res);
}
for (ArgVec::const_iterator it = commandargs.begin(); it != commandargs.end(); ++it)
@ -60,7 +63,7 @@ int CLASS::runCommandLineApp(void)
std::string p = fn.path();
Poco::Path path(p);
//logger().information(path.toString());
logger().information(path.toString());
std::string e = toUpper(path.getExtension());
@ -74,16 +77,20 @@ int CLASS::runCommandLineApp(void)
t = new TMerlinConverter();
if (t != NULL)
{
t->init();
std::string f = path.toString();
t->processfile(f);
t->process();
t->complete();
res = (t->errorct > 0) ? -1 : 0;
delete t;
t = NULL;
try
{
t->init();
std::string f = path.toString();
t->processfile(f);
t->process();
t->complete();
res = (t->errorct > 0) ? -1 : 0;
}
catch (...)
{
delete t;
t = NULL;
}
}
}
else if (cmd == "ASM")
@ -101,14 +108,21 @@ int CLASS::runCommandLineApp(void)
}
if (t != NULL)
{
t->init();
std::string f = path.toString();
t->processfile(f);
t->process();
t->complete();
res = (t->errorct > 0) ? -1 : 0;
delete t;
t = NULL;
try
{
t->init();
std::string f = path.toString();
t->processfile(f);
t->process();
t->complete();
res = (t->errorct > 0) ? -1 : 0;
}
catch (...)
{
delete t;
t = NULL;
}
chdir(startdirectory.c_str()); // return us back to where we were
}
else
{
@ -117,7 +131,7 @@ int CLASS::runCommandLineApp(void)
}
else
{
fprintf(stderr,"Invalid command: <%s>\n\n", cmd.c_str());
fprintf(stderr, "Invalid command: <%s>\n\n", cmd.c_str());
}
}
}