Skip to content

Provide help option and refactor other options #146

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Mar 17, 2023
Merged
34 changes: 13 additions & 21 deletions src/main/benchmarks/README.org
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
# Read the csf files with a list of country codes, and languages codes
while IFS="," read ctry lang ; do
INSTANCE="instances/$lang-$1-$2.dat"
echo -ctry $ctry -lang $lang $1 $2 > $INSTANCE
echo --ctry $ctry --lang $lang $1 $2 > $INSTANCE
done < <(grep -v "^#\|^$" $LANGUAGES)
}
#+END_SRC
Expand Down Expand Up @@ -77,17 +77,13 @@ exit $?

*** Best algorithm
#+BEGIN_SRC sh
echo -v normal -d TRUE -lightM FALSE -lightP FALSE > algorithms/FF.dat
echo -v normal --dry-run > algorithms/HEAVY.dat
#+END_SRC

*** All algorithms

#+BEGIN_SRC sh
echo -v normal -d TRUE -lightM FALSE -lightP FALSE > algorithms/FF.dat
echo -v normal -d TRUE -lightM FALSE -lightP TRUE > algorithms/FT.dat
echo -v normal -d TRUE -lightM TRUE -lightP FALSE -newHeavyP FALSE > algorithms/TF.dat
echo -v normal -d TRUE -lightM TRUE -lightP FALSE -newHeavyP TRUE > algorithms/TF_NEW.dat
echo -v normal -d TRUE -lightM TRUE -lightP TRUE > algorithms/TT.dat
echo -v normal --dry-run --light > algorithms/LIGHT.dat
#+END_SRC


Expand Down Expand Up @@ -139,7 +135,7 @@ The word lists ~colors.txt~ and ~monsters.txt~ takes the most time by far (aroun

#+BEGIN_SRC sh
function generateLong() {
echo -minop $1 -maxop $1 words/$2 > instances/`basename -s .txt $2`-$1.dat
echo --min $1 --max $1 words/$2 > instances/`basename -s .txt $2`-$1.dat
}

# generateLong 9 9 monsters.txt
Expand Down Expand Up @@ -169,7 +165,7 @@ The word lists ~colors.txt~ and ~monsters.txt~ takes the most time by far (aroun
function generateMaxLong() {
find samples/ -type f -print | while read PATHNAME ; do
INSTANCE="instances/"`basename -s .txt $PATHNAME`-$1-$2.dat
echo -minop $1 -maxop $2 $PATHNAME > $INSTANCE
echo --min $1 --max $2 $PATHNAME > $INSTANCE
done
}

Expand Down Expand Up @@ -218,7 +214,7 @@ The word lists ~colors.txt~ and ~monsters.txt~ takes the most time by far (aroun
function generateCrossword() {
find samples/ -type f -print | while read PATHNAME ; do
INSTANCE="instances/"`basename -s .txt $PATHNAME`-$1.dat
echo -grid $1 $PATHNAME > $INSTANCE
echo --generate CROSS --cross $1 $PATHNAME > $INSTANCE
done
}

Expand All @@ -230,18 +226,18 @@ The word lists ~colors.txt~ and ~monsters.txt~ takes the most time by far (aroun

*** Addition
#+BEGIN_SRC sh
echo -v quiet -d FALSE -l TRUE -lightM FALSE -lightP FALSE > algorithms/ALL.dat
echo -v quiet --generate ADD -s BIGNUM > algorithms/ALL.dat
#+END_SRC


*** Multiplication
#+BEGIN_SRC sh
echo -v quiet -d FALSE -mult TRUE -multUnique TRUE -lightP FALSE > algorithms/ALL.dat
echo -v quiet --generate MUL --right UNIQUE > algorithms/ALL.dat
#+END_SRC

*** Long Multiplication
#+BEGIN_SRC sh
echo -v quiet -d FALSE -longMult TRUE -lightM FALSE -lightP FALSE > algorithms/ALL.dat
echo -v quiet --generate LMUL > algorithms/ALL.dat
#+END_SRC

* Solve
Expand Down Expand Up @@ -301,14 +297,10 @@ Do not remove the content of the directory!
** Configure the algorithm

#+BEGIN_SRC sh
ARGS=" -v verbose -t 100"
echo $ARGS -l TRUE > algorithms/BIGNUM.dat
echo $ARGS -l FALSE -h FALSE > algorithms/SCALAR.dat
echo $ARGS -l FALSE -h TRUE > algorithms/HORNER.dat

# echo $ARGS -l TRUE -search 1 > algorithms/BIGNUM-1.dat
# echo $ARGS -l FALSE -h FALSE -search 1 > algorithms/SCALAR-1.dat
# echo $ARGS -l FALSE -h TRUE -search 1 > algorithms/HORNER-1.dat
ARGS=" -v verbose"
echo $ARGS -s BIGNUM > algorithms/BIGNUM.dat
echo $ARGS -s SCALAR > algorithms/SCALAR.dat
echo $ARGS -s SCALAR --horner > algorithms/HORNER.dat
#+END_SRC


Expand Down
14 changes: 10 additions & 4 deletions src/main/java/cryptator/Cryptagen.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import java.util.OptionalInt;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand All @@ -37,18 +38,23 @@ public static void main(final String[] args) {
}

public static int doMain(final String[] args) {
CryptagenOptionsParser optparser = new CryptagenOptionsParser();
if (optparser.parseOptions(args)) {
try {
CryptagenOptionsParser optparser = new CryptagenOptionsParser();
final OptionalInt parserExitCode = optparser.parseOptions(args);
if (parserExitCode.isPresent()) {
return parserExitCode.getAsInt();
}
final CryptagenConfig config = optparser.getConfig();
final WordArray words = buildWords(config.getArguments(), config);
if (words != null) {
return generate(words, config);
} else {
LOGGER.log(Level.WARNING, "Empty word list.");
}
return -1;
} finally {
JULogUtil.flushLogs();
}
JULogUtil.flushLogs();
return -1;
}

private static List<String> readWords(final String filename) {
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/cryptator/Cryptamancer.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/
package cryptator;

import java.util.OptionalInt;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand Down Expand Up @@ -98,7 +99,8 @@ public static void main(final String[] args) throws Exception {
JULogUtil.configureDefaultLoggers();

CryptamancerOptionsParser optparser = new CryptamancerOptionsParser();
if (!optparser.parseOptions(args)) {
final OptionalInt parserExitCode = optparser.parseOptions(args);
if (parserExitCode.isPresent()) {
return;
}
final CryptaLogConfig config = optparser.getConfig();
Expand Down
29 changes: 17 additions & 12 deletions src/main/java/cryptator/Cryptator.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/
package cryptator;

import java.util.OptionalInt;
import java.util.logging.Level;
import java.util.logging.Logger;

Expand Down Expand Up @@ -37,22 +38,26 @@ public static void main(final String[] args) {
}

public static int doMain(final String[] args) {
CryptatorOptionsParser optparser = new CryptatorOptionsParser();
if (!optparser.parseOptions(args)) {
return -1;
}
final CryptatorConfig config = optparser.getConfig();
try {
final CryptatorOptionsParser optparser = new CryptatorOptionsParser();
final OptionalInt parserExitCode = optparser.parseOptions(args);
if (parserExitCode.isPresent()) {
return parserExitCode.getAsInt();
}
final CryptatorConfig config = optparser.getConfig();

final ICryptaSolver solver = buildSolver(config);
final ICryptaSolver solver = buildSolver(config);

final CryptaParserWrapper parser = new CryptaParserWrapper();
final CryptaParserWrapper parser = new CryptaParserWrapper();

int exitCode = 0;
for (String cryptarithm : config.getArguments()) {
exitCode += solve(cryptarithm, parser, solver, config);
int exitCode = 0;
for (String cryptarithm : config.getArguments()) {
exitCode += solve(cryptarithm, parser, solver, config);
}
return exitCode;
} finally {
JULogUtil.flushLogs();
}
JULogUtil.flushLogs();
return exitCode;
}

private static class CryptatorOptionsParser extends OptionsParserWithLog<CryptatorConfig> {
Expand Down
Loading