From 5cfe48265ebad0ffa0a980dbc2d131fceeecdf3b Mon Sep 17 00:00:00 2001 From: Renaud G Date: Wed, 8 Apr 2015 21:34:02 +0200 Subject: -remove memory leaks -delete created objects --- diceParser.pro | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'diceParser.pro') diff --git a/diceParser.pro b/diceParser.pro index 2d72fcb..c339933 100644 --- a/diceParser.pro +++ b/diceParser.pro @@ -43,7 +43,8 @@ SOURCES += main.cpp \ result/result.cpp \ result/scalarresult.cpp \ parsingtoolbox.cpp \ - result/stringresult.cpp + result/stringresult.cpp \ + dicealias.cpp HEADERS += \ @@ -56,7 +57,8 @@ HEADERS += \ result/result.h \ result/scalarresult.h \ result/parsingtoolbox.h \ - result/stringresult.h + result/stringresult.h \ + dicealias.h OTHER_FILES += README.md \ HelpMe.md -- cgit v1.2.3-70-g09d2 From cd21a9b1252f4d000b18ccecacc9c4e92d59f67b Mon Sep 17 00:00:00 2001 From: Renaud G Date: Thu, 23 Apr 2015 10:51:01 +0200 Subject: amend files for cli main application --- cli/main.cpp | 122 ++++++++++++++++++++++++++++++++++++++++----------------- diceParser.pro | 7 +++- 2 files changed, 91 insertions(+), 38 deletions(-) (limited to 'diceParser.pro') diff --git a/cli/main.cpp b/cli/main.cpp index 7b70e23..8f1ec67 100644 --- a/cli/main.cpp +++ b/cli/main.cpp @@ -19,27 +19,100 @@ * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#ifdef HAVE_IRC -#include -#include "irc/mainwindow.h" -#endif #include #include "diceparser.h" +#include +#include -int main(int argc, char *argv[]) +void startDiceParsing(QString& cmd,QString& treeFile,bool highlight) { - #ifdef HAVE_IRC - QApplication a(argc, argv); + DiceParser* parser = new DiceParser(); + if(parser->parseLine(cmd)) + { + parser->Start(); + // + if(treeFile.isEmpty()) + { + parser->displayResult(); + } + else + { + parser->writeDownDotTree(); + } + } +} + + - MainWindow main; -#endif - DiceParser* myParser = new DiceParser(); +int main(int argc, char *argv[]) +{ QStringList commands; + QString cmd; + QString dotFile; + + bool color=true; + + QCommandLineParser optionParser; + QCommandLineOption color(QStringList() << "co"<< "color-off", tr("Disable color to highlight result")); + QCommandLineOption version(QStringList() << "v"<< "version", tr("Show the version and quit.")); + QCommandLineOption reset(QStringList() << "reset-settings", tr("Erase the settings and use the default parameters")); + QCommandLineOption dotFile(QStringList() << "d"<<"dot-file", tr("Instead of rolling dice, generate the execution tree and write it in "),"dotfile"); + QCommandLineOption translation(QStringList() << "t"<<"translation", QObject::tr("path to the translation file: "),"translationfile"); + QCommandLineOption help(QStringList() << "h"<<"help", QObject::tr("Display this help")); + + optionParser.addOption(color); + optionParser.addOption(version); + optionParser.addOption(reset); + optionParser.addOption(dotFile); + optionParser.addOption(translation); + optionParser.addOption(help); + + for(int i=1;i6]+@c[=10]" + cmd = commands.first(); + + + startDiceParsing(cmd,dotFile,color); + + /*commands<< "10d10c[>6]+@c[=10]" << "1L[cheminée,chocolat,épée,arc,chute de pierre]" << "10d10c[>=6]-@c[=1]" << "10d10c[>=6]-@c[=1]-@c[=1]" @@ -76,32 +149,9 @@ int main(int argc, char *argv[]) << "la" << "400000D20/400000" << "100*3*8";// +*/ + - if(argc>1) - { - for(int i=1;iparseLine(cmd)) - { - myParser->Start(); - // myParser->displayDotTree(); - myParser->displayResult(); - } - else - { - qDebug() << "echec"; - } - } - #ifdef HAVE_IRC - main.show(); - return a.exec(); -#endif - delete myParser; return 0; } diff --git a/diceParser.pro b/diceParser.pro index c339933..8af57a4 100644 --- a/diceParser.pro +++ b/diceParser.pro @@ -18,8 +18,11 @@ TEMPLATE = app #CONFIG+= IRC #CONFIG+= GUI - - +CONFIG+= CLI +CLI { +DEFINES += CLI +include(cli/cli.pri)cd +} IRC { include(irc/irc.pri) QT += gui widgets -- cgit v1.2.3-70-g09d2 From c356c8bf53f46efb2ba0aaa6d91ef4c4ade320b6 Mon Sep 17 00:00:00 2001 From: Renaud G Date: Fri, 24 Apr 2015 11:08:32 +0200 Subject: add commandLine parser(not working yet) --- cli/main.cpp | 129 ++++++++++++++++++++++++++++++++++++++++++++++++--------- diceParser.pro | 3 +- 2 files changed, 110 insertions(+), 22 deletions(-) (limited to 'diceParser.pro') diff --git a/cli/main.cpp b/cli/main.cpp index 8f1ec67..7476eb4 100644 --- a/cli/main.cpp +++ b/cli/main.cpp @@ -24,21 +24,101 @@ #include "diceparser.h" #include #include +#include + +QString diceToText(ExportedDiceResult& dice) +{ + QStringList resultGlobal; + foreach(int face, dice.keys()) + { + QStringList result; + ListDiceResult diceResult = dice.value(face); + bool previousHighlight=false; + QString patternColor("\e[0;31m"); + //patternColor = patternColorarg(); + foreach (DiceAndHighlight tmp, diceResult) + { + QStringList diceListStr; + QStringList diceListChildren; + if((previousHighlight)&&(!tmp.second)) + { + result << patternColor << result.join(',') <<"\e[0m"; + } + previousHighlight = tmp.second; + for(int i =0; i < tmp.first.size(); ++i) + { + quint64 dievalue = tmp.first[i]; + if(i==0) + { + diceListStr << QString::number(dievalue); + } + else + { + diceListChildren << QString::number(dievalue); + } + } + if(!diceListChildren.isEmpty()) + { + diceListStr << QString("[%1]").arg(diceListChildren.join(',')); + } + + result << diceListStr.join(' '); + } + if(previousHighlight) + { + QStringList list; + list << patternColor << result.join(',') << "\e[0m"; + result = list; + } + if(dice.keys().size()>1) + { + resultGlobal << QString(" d%2:(%1)").arg(result.join(' ')).arg(face); + } + else + { + resultGlobal << result; + } + } + return resultGlobal.join(' '); +} void startDiceParsing(QString& cmd,QString& treeFile,bool highlight) { DiceParser* parser = new DiceParser(); + if(parser->parseLine(cmd)) { parser->Start(); // if(treeFile.isEmpty()) { - parser->displayResult(); + ExportedDiceResult list; + parser->getLastDiceResult(list); + QString diceText = diceToText(list); + QString scalarText; + QString str; + + if(parser->hasIntegerResultNotInFirst()) + { + scalarText = QString("%1").arg(parser->getLastIntegerResult()); + } + else if(!list.isEmpty()) + { + scalarText = QString("%1").arg(parser->getSumOfDiceResult()); + } + + str = QString("Result: \e[0;31m%1\e[0m, details:[%3 (%2)]").arg(scalarText).arg(diceText).arg(parser->getDiceCommand()); + + if(parser->hasStringResult()) + { + str = parser->getStringResult().replace("\n","
"); + } + qDebug() << str; + } else { - parser->writeDownDotTree(); + parser->writeDownDotTree(treeFile); } } } @@ -51,19 +131,23 @@ int main(int argc, char *argv[]) QStringList commands; QString cmd; - QString dotFile; + QString dotFileStr; - bool color=true; + bool colorb=false; QCommandLineParser optionParser; - QCommandLineOption color(QStringList() << "co"<< "color-off", tr("Disable color to highlight result")); - QCommandLineOption version(QStringList() << "v"<< "version", tr("Show the version and quit.")); - QCommandLineOption reset(QStringList() << "reset-settings", tr("Erase the settings and use the default parameters")); - QCommandLineOption dotFile(QStringList() << "d"<<"dot-file", tr("Instead of rolling dice, generate the execution tree and write it in "),"dotfile"); - QCommandLineOption translation(QStringList() << "t"<<"translation", QObject::tr("path to the translation file: "),"translationfile"); - QCommandLineOption help(QStringList() << "h"<<"help", QObject::tr("Display this help")); - - optionParser.addOption(color); + QCommandLineOption color(QStringList() << "co"<< "color-off", "Disable color to highlight result"); + QCommandLineOption version(QStringList() << "v"<< "version", "Show the version and quit."); + QCommandLineOption reset(QStringList() << "reset-settings", "Erase the settings and use the default parameters"); + QCommandLineOption dotFile(QStringList() << "d"<<"dot-file", "Instead of rolling dice, generate the execution tree and write it in ","dotfile"); + QCommandLineOption translation(QStringList() << "t"<<"translation", "path to the translation file: ","translationfile"); + QCommandLineOption help(QStringList() << "h"<<"help", "Display this help"); + + if(!optionParser.addOption(color)) + { + qDebug()<< optionParser.errorText(); + } + optionParser.addOption(version); optionParser.addOption(reset); optionParser.addOption(dotFile); @@ -76,12 +160,20 @@ int main(int argc, char *argv[]) commands << QString::fromLatin1(argv[i]); } - optionParser.parse(commands); + if(!optionParser.parse(commands)) + { + qDebug()<< optionParser.errorText(); + } + else + { + qDebug() << "no error"; + } if(optionParser.isSet(color)) { - return 0; + qDebug() << "color"; + colorb = false; } else if(optionParser.isSet(version)) { @@ -93,7 +185,7 @@ int main(int argc, char *argv[]) } else if(optionParser.isSet(dotFile)) { - dotFile = optionParser.value(dotFile); + dotFileStr = optionParser.value(dotFile); } else if(optionParser.isSet(translation)) { @@ -101,16 +193,13 @@ int main(int argc, char *argv[]) } else if(optionParser.isSet(help)) { - cmd = "help"; } - - cmd = commands.first(); - - startDiceParsing(cmd,dotFile,color); + qDebug() << "super 5" << cmd << dotFileStr << colorb; + startDiceParsing(cmd,dotFileStr,colorb); /*commands<< "10d10c[>6]+@c[=10]" << "1L[cheminée,chocolat,épée,arc,chute de pierre]" diff --git a/diceParser.pro b/diceParser.pro index 8af57a4..3a95496 100644 --- a/diceParser.pro +++ b/diceParser.pro @@ -36,8 +36,7 @@ DEFINES+= HAVE_GUI } -SOURCES += main.cpp \ - diceparser.cpp \ +SOURCES += diceparser.cpp \ result/diceresult.cpp \ range.cpp \ booleancondition.cpp \ -- cgit v1.2.3-70-g09d2