Skip to content

Commit

Permalink
Merge branch 'stl' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
thunder422 committed Oct 18, 2014
2 parents 2fb73b6 + 3020cd6 commit a8bd956
Show file tree
Hide file tree
Showing 27 changed files with 820 additions and 714 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Expand Up @@ -72,7 +72,7 @@ if (NOT CMAKE_BUILD_TYPE)
endif (NOT CMAKE_BUILD_TYPE)
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")

set(ibcp_COPYRIGHT_YEAR 2013)
set(ibcp_COPYRIGHT_YEAR 2014)

set(ibcp_RELEASE_MAJOR 0)
set(ibcp_RELEASE_MINOR 6)
Expand Down Expand Up @@ -204,6 +204,7 @@ set(ibcp_SOURCES
token.cpp
translator.cpp
test_ibcp.cpp
utility.cpp
)

# list the header files containing QOBJECT
Expand Down
21 changes: 11 additions & 10 deletions basic/basic.cpp
Expand Up @@ -32,17 +32,18 @@

quint16 remEncode(ProgramModel *programUnit, const TokenPtr &token)
{
return programUnit->remDictionary()->add(token, Qt::CaseSensitive);
return programUnit->remDictionary()->add(token);
}

const QString remOperandText(const ProgramModel *programUnit, quint16 operand)
const std::string remOperandText(const ProgramModel *programUnit,
quint16 operand)
{
return programUnit->remDictionary()->string(operand);
}

void remRemove(ProgramModel *programUnit, quint16 operand)
{
programUnit->remDictionary()->remove(operand, Qt::CaseSensitive);
programUnit->remDictionary()->remove(operand);
}


Expand Down Expand Up @@ -71,7 +72,7 @@ quint16 constNumEncode(ProgramModel *programUnit, const TokenPtr &token)
return programUnit->constNumDictionary()->add(token);
}

const QString constNumOperandText(const ProgramModel *programUnit,
const std::string constNumOperandText(const ProgramModel *programUnit,
quint16 operand)
{
return programUnit->constNumDictionary()->string(operand);
Expand Down Expand Up @@ -114,18 +115,18 @@ ConstStrInfo::~ConstStrInfo(void)

quint16 constStrEncode(ProgramModel *programUnit, const TokenPtr &token)
{
return programUnit->constStrDictionary()->add(token, Qt::CaseSensitive);
return programUnit->constStrDictionary()->add(token);
}

const QString constStrOperandText(const ProgramModel *programUnit,
const std::string constStrOperandText(const ProgramModel *programUnit,
quint16 operand)
{
return programUnit->constStrDictionary()->string(operand);
}

void constStrRemove(ProgramModel *programUnit, quint16 operand)
{
programUnit->constStrDictionary()->remove(operand, Qt::CaseSensitive);
programUnit->constStrDictionary()->remove(operand);
}

void constStrRecreate(Recreator &recreator, RpnItemPtr &rpnItem)
Expand Down Expand Up @@ -155,19 +156,19 @@ quint16 varStrEncode(ProgramModel *programUnit, const TokenPtr &token)
}


const QString varDblOperandText(const ProgramModel *programUnit,
const std::string varDblOperandText(const ProgramModel *programUnit,
quint16 operand)
{
return programUnit->varDblDictionary()->string(operand);
}

const QString varIntOperandText(const ProgramModel *programUnit,
const std::string varIntOperandText(const ProgramModel *programUnit,
quint16 operand)
{
return programUnit->varIntDictionary()->string(operand);
}

const QString varStrOperandText(const ProgramModel *programUnit,
const std::string varStrOperandText(const ProgramModel *programUnit,
quint16 operand)
{
return programUnit->varStrDictionary()->string(operand);
Expand Down
16 changes: 9 additions & 7 deletions basic/basic.h
Expand Up @@ -28,6 +28,7 @@
#include <memory>

#include <QString>
#include <QVector>

#include "ibcp.h"
#include "token.h"
Expand Down Expand Up @@ -104,7 +105,7 @@ class ConstStrInfo : public AbstractInfo
class ConstStrDictionary : public InfoDictionary
{
public:
ConstStrDictionary(void)
ConstStrDictionary(void) : InfoDictionary(CaseSensitive::Yes)
{
m_info.reset(new ConstStrInfo);
}
Expand Down Expand Up @@ -135,16 +136,17 @@ quint16 varStrEncode(ProgramModel *programUnit, const TokenPtr &token);


// operand text functions
const QString remOperandText(const ProgramModel *programUnit, quint16 operand);
const QString constNumOperandText(const ProgramModel *programUnit,
const std::string remOperandText(const ProgramModel *programUnit,
quint16 operand);
const QString constStrOperandText(const ProgramModel *programUnit,
const std::string constNumOperandText(const ProgramModel *programUnit,
quint16 operand);
const QString varDblOperandText(const ProgramModel *programUnit,
const std::string constStrOperandText(const ProgramModel *programUnit,
quint16 operand);
const QString varIntOperandText(const ProgramModel *programUnit,
const std::string varDblOperandText(const ProgramModel *programUnit,
quint16 operand);
const QString varStrOperandText(const ProgramModel *programUnit,
const std::string varIntOperandText(const ProgramModel *programUnit,
quint16 operand);
const std::string varStrOperandText(const ProgramModel *programUnit,
quint16 operand);


Expand Down
119 changes: 46 additions & 73 deletions commandline.cpp
Expand Up @@ -22,40 +22,54 @@
//
// 2012-11-25 initial version

#include <QFileInfo>
#include <iostream>
#include <sstream>

#include "ibcp_config.h" // for cmake
#include "commandline.h"
#include "test_ibcp.h"
#include "utility.h"


// create copyright statement string
const char *CommandLine::s_copyrightStatement =
QT_TR_NOOP("%1 Copyright (C) 2010-%2 Thunder422");
// function to generate the copyright statement
const std::string CommandLine::copyrightStatement(const char *copyright)
{
std::ostringstream ss;

ss << " " << copyright << "(C) 2010-" << ibcp_COPYRIGHT_YEAR
<< " Thunder422";
return ss.str();
}


// create warranty statement string list
const char *CommandLine::s_warrantyStatement[] = {
QT_TR_NOOP("This program comes with ABSOLUTELY NO WARRANTY."),
QT_TR_NOOP("This is free software, and you are welcome to"),
QT_TR_NOOP("redistribute it under certain conditions."),
nullptr
};
// function to return the version number string
std::string CommandLine::version(void)
{
const char *p = ibcp_RELEASE_STRING;
while (!isdigit(*p) && *p)
{
++p;
}
return std::string(p);
}


CommandLine::CommandLine(const QStringList &args)
CommandLine::CommandLine(std::list<std::string> args) :
m_cout {nullptr}
{
// get base file name of program from first argument
m_programName = QFileInfo(args.at(0)).baseName();
m_programName = Utility::baseFileName(args.front());
args.pop_front(); // remove program name

m_returnCode = -1;
// NOTE: leave m_returnCode set to -1 to start GUI,

// create usage string
QStringList options {Tester::options()};
// append any other options here
options.prepend("<program file>|-h|-?|-v");
m_usage = tr("usage: %1 [%2]").arg(m_programName).arg(options.join("|"));
std::string usage = "usage: " + m_programName + "<program file>|-h|-?|-v|"
+ Tester::options();

if (args.count() == 1)
if (args.size() == 0)
{
// no options, start GUI
return;
Expand All @@ -68,105 +82,64 @@ CommandLine::CommandLine(const QStringList &args)
return;
}

Tester tester(args, cout());
Tester tester(m_programName, args, cout());
if (tester.hasError())
{
coutClose(); // close stdout
cout(stderr) << tester.errorMessage() << endl;
cout(&std::cerr) << tester.errorMessage() << '\n';
m_returnCode = 1;
return;
}
else if (tester.hasOption())
{
if (tester.run(this))
if (tester.run(std::move(copyrightStatement())))
{
m_returnCode = 0;
}
else
{
coutClose(); // close stdout
cout(stderr) << tester.errorMessage() << endl;
cout(&std::cerr) << tester.errorMessage() << '\n';
m_returnCode = 1;
}
return;
}

// check if a possible file name was specified
if (args.count() == 2 && !args.at(1).startsWith("-"))
if (args.size() == 1 && args.front().front() != '-')
{
// not an option so assume argument is a file name
m_fileName = args.at(1);
m_fileName = args.front();
return;
}

// unsupported option (NOTE: other options get checked before this)
m_returnCode = isHelpOption(args) ? 0 : 1; // error if not help option
cout(m_returnCode == 0 ? stdout : stderr) << m_usage << endl;
}


CommandLine::~CommandLine()
{
coutClose();
}


QTextStream &CommandLine::cout(FILE *stream)
{
if (!m_cout.device())
{
// setup standard output stream first time
QFile *output {new QFile};
output->open(stream, QIODevice::WriteOnly | QIODevice::Unbuffered);
m_cout.setDevice(output);
}
return m_cout;
cout(m_returnCode == 0 ? &std::cout : &std::cerr) << usage << '\n';
}



void CommandLine::coutClose(void)
std::ostream &CommandLine::cout(std::ostream *stream)
{
if (m_cout.device())
{
std::unique_ptr<QIODevice> output {m_cout.device()};
m_cout.setDevice(0);
}
m_cout = stream;
return *m_cout;
}


// function to check if version option was specified and to process it
bool CommandLine::isVersionOption(const QStringList &args)
bool CommandLine::isVersionOption(const std::list<std::string> &args)
{
if (args.count() != 2 || args.at(1) != "-v")
if (args.size() != 1 || args.front() != "-v")
{
return false; // not our option or extra/invalid options
}
cout() << tr("%1 version %2").arg(m_programName).arg(version()) << endl;
cout() << m_programName + " version " + version() << '\n';
return true;
}


// function to check for help options
bool CommandLine::isHelpOption(const QStringList &args) const
{
return args.count() == 2 && (args.at(1) == "-?" || args.at(1) == "-h");
}


// function to return the copyright year value
int CommandLine::copyrightYear(void) const
{
return ibcp_COPYRIGHT_YEAR;
}


// function to return the version number string
QString CommandLine::version(void) const
bool CommandLine::isHelpOption(const std::list<std::string> &args) const
{
QString versionString(ibcp_RELEASE_STRING);
int start {versionString.indexOf(QRegExp("\\d"))};
return versionString.mid(start);
return args.size() == 1 && (args.front() == "-?" || args.front() == "-h");
}


Expand Down

0 comments on commit a8bd956

Please sign in to comment.