Skip to content

Commit d3cc544

Browse files
authored
Merge pull request #146 from arnaud-m/feat-141
Provide help option and refactor other options
2 parents a9964ca + 820846f commit d3cc544

18 files changed

+287
-193
lines changed

src/main/benchmarks/README.org

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
# Read the csf files with a list of country codes, and languages codes
4545
while IFS="," read ctry lang ; do
4646
INSTANCE="instances/$lang-$1-$2.dat"
47-
echo -ctry $ctry -lang $lang $1 $2 > $INSTANCE
47+
echo --ctry $ctry --lang $lang $1 $2 > $INSTANCE
4848
done < <(grep -v "^#\|^$" $LANGUAGES)
4949
}
5050
#+END_SRC
@@ -77,17 +77,13 @@ exit $?
7777

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

8383
*** All algorithms
8484

8585
#+BEGIN_SRC sh
86-
echo -v normal -d TRUE -lightM FALSE -lightP FALSE > algorithms/FF.dat
87-
echo -v normal -d TRUE -lightM FALSE -lightP TRUE > algorithms/FT.dat
88-
echo -v normal -d TRUE -lightM TRUE -lightP FALSE -newHeavyP FALSE > algorithms/TF.dat
89-
echo -v normal -d TRUE -lightM TRUE -lightP FALSE -newHeavyP TRUE > algorithms/TF_NEW.dat
90-
echo -v normal -d TRUE -lightM TRUE -lightP TRUE > algorithms/TT.dat
86+
echo -v normal --dry-run --light > algorithms/LIGHT.dat
9187
#+END_SRC
9288

9389

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

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

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

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

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

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

236232

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

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

247243
* Solve
@@ -301,14 +297,10 @@ Do not remove the content of the directory!
301297
** Configure the algorithm
302298

303299
#+BEGIN_SRC sh
304-
ARGS=" -v verbose -t 100"
305-
echo $ARGS -l TRUE > algorithms/BIGNUM.dat
306-
echo $ARGS -l FALSE -h FALSE > algorithms/SCALAR.dat
307-
echo $ARGS -l FALSE -h TRUE > algorithms/HORNER.dat
308-
309-
# echo $ARGS -l TRUE -search 1 > algorithms/BIGNUM-1.dat
310-
# echo $ARGS -l FALSE -h FALSE -search 1 > algorithms/SCALAR-1.dat
311-
# echo $ARGS -l FALSE -h TRUE -search 1 > algorithms/HORNER-1.dat
300+
ARGS=" -v verbose"
301+
echo $ARGS -s BIGNUM > algorithms/BIGNUM.dat
302+
echo $ARGS -s SCALAR > algorithms/SCALAR.dat
303+
echo $ARGS -s SCALAR --horner > algorithms/HORNER.dat
312304
#+END_SRC
313305

314306

src/main/java/cryptator/Cryptagen.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import java.io.FileNotFoundException;
1313
import java.util.ArrayList;
1414
import java.util.List;
15+
import java.util.OptionalInt;
1516
import java.util.Scanner;
1617
import java.util.logging.Level;
1718
import java.util.logging.Logger;
@@ -37,18 +38,23 @@ public static void main(final String[] args) {
3738
}
3839

3940
public static int doMain(final String[] args) {
40-
CryptagenOptionsParser optparser = new CryptagenOptionsParser();
41-
if (optparser.parseOptions(args)) {
41+
try {
42+
CryptagenOptionsParser optparser = new CryptagenOptionsParser();
43+
final OptionalInt parserExitCode = optparser.parseOptions(args);
44+
if (parserExitCode.isPresent()) {
45+
return parserExitCode.getAsInt();
46+
}
4247
final CryptagenConfig config = optparser.getConfig();
4348
final WordArray words = buildWords(config.getArguments(), config);
4449
if (words != null) {
4550
return generate(words, config);
4651
} else {
4752
LOGGER.log(Level.WARNING, "Empty word list.");
4853
}
54+
return -1;
55+
} finally {
56+
JULogUtil.flushLogs();
4957
}
50-
JULogUtil.flushLogs();
51-
return -1;
5258
}
5359

5460
private static List<String> readWords(final String filename) {

src/main/java/cryptator/Cryptamancer.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*/
99
package cryptator;
1010

11+
import java.util.OptionalInt;
1112
import java.util.Scanner;
1213
import java.util.logging.Level;
1314
import java.util.logging.Logger;
@@ -98,7 +99,8 @@ public static void main(final String[] args) throws Exception {
9899
JULogUtil.configureDefaultLoggers();
99100

100101
CryptamancerOptionsParser optparser = new CryptamancerOptionsParser();
101-
if (!optparser.parseOptions(args)) {
102+
final OptionalInt parserExitCode = optparser.parseOptions(args);
103+
if (parserExitCode.isPresent()) {
102104
return;
103105
}
104106
final CryptaLogConfig config = optparser.getConfig();

src/main/java/cryptator/Cryptator.java

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*/
99
package cryptator;
1010

11+
import java.util.OptionalInt;
1112
import java.util.logging.Level;
1213
import java.util.logging.Logger;
1314

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

3940
public static int doMain(final String[] args) {
40-
CryptatorOptionsParser optparser = new CryptatorOptionsParser();
41-
if (!optparser.parseOptions(args)) {
42-
return -1;
43-
}
44-
final CryptatorConfig config = optparser.getConfig();
41+
try {
42+
final CryptatorOptionsParser optparser = new CryptatorOptionsParser();
43+
final OptionalInt parserExitCode = optparser.parseOptions(args);
44+
if (parserExitCode.isPresent()) {
45+
return parserExitCode.getAsInt();
46+
}
47+
final CryptatorConfig config = optparser.getConfig();
4548

46-
final ICryptaSolver solver = buildSolver(config);
49+
final ICryptaSolver solver = buildSolver(config);
4750

48-
final CryptaParserWrapper parser = new CryptaParserWrapper();
51+
final CryptaParserWrapper parser = new CryptaParserWrapper();
4952

50-
int exitCode = 0;
51-
for (String cryptarithm : config.getArguments()) {
52-
exitCode += solve(cryptarithm, parser, solver, config);
53+
int exitCode = 0;
54+
for (String cryptarithm : config.getArguments()) {
55+
exitCode += solve(cryptarithm, parser, solver, config);
56+
}
57+
return exitCode;
58+
} finally {
59+
JULogUtil.flushLogs();
5360
}
54-
JULogUtil.flushLogs();
55-
return exitCode;
5661
}
5762

5863
private static class CryptatorOptionsParser extends OptionsParserWithLog<CryptatorConfig> {

0 commit comments

Comments
 (0)