Add basic CL switches and help, version and license text.
This commit is contained in:
parent
f0fbc0b3a3
commit
79dae3de0b
3 changed files with 80 additions and 9 deletions
|
@ -6,9 +6,19 @@ set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3 -Wall -Wdeprecated")
|
||||||
set(CMAKE_D_FLAGS_DEBUG "${CMAKE_D_FLAGS_DEBUG} -funittest -g -O0 -Wall -Wdeprecated")
|
set(CMAKE_D_FLAGS_DEBUG "${CMAKE_D_FLAGS_DEBUG} -funittest -g -O0 -Wall -Wdeprecated")
|
||||||
set(CMAKE_D_FLAGS_RELEASE "${CMAKE_D_FLAGS_RELEASE} -O3 -Wall -Wdeprecated")
|
set(CMAKE_D_FLAGS_RELEASE "${CMAKE_D_FLAGS_RELEASE} -O3 -Wall -Wdeprecated")
|
||||||
|
|
||||||
|
set(DEFAULT_TIGER_VERSION "1")
|
||||||
|
set(TIGERSUM_MAJOR "0")
|
||||||
|
set(TIGERSUM_MINOR "1")
|
||||||
|
|
||||||
|
configure_file(
|
||||||
|
"${PROJECT_SOURCE_DIR}/${PROJECT_NAME}Config.d.in"
|
||||||
|
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.d"
|
||||||
|
)
|
||||||
|
|
||||||
include_directories(
|
include_directories(
|
||||||
.
|
.
|
||||||
)
|
)
|
||||||
|
add_definitions("-J${PROJECT_BINARY_DIR}")
|
||||||
|
|
||||||
add_executable(${PROJECT_NAME}
|
add_executable(${PROJECT_NAME}
|
||||||
sboxes.c
|
sboxes.c
|
||||||
|
|
70
main.d
70
main.d
|
@ -18,19 +18,75 @@
|
||||||
import std.stdio;
|
import std.stdio;
|
||||||
import std.file;
|
import std.file;
|
||||||
import tiger;
|
import tiger;
|
||||||
|
import std.array;
|
||||||
|
import std.getopt;
|
||||||
|
|
||||||
|
mixin(import("tigersumConfig.d"));
|
||||||
|
|
||||||
void main (string[] parArgs) {
|
void main (string[] parArgs) {
|
||||||
const auto cwd = getcwd();
|
const auto cwd = getcwd();
|
||||||
const auto working_dir = cwd ~ (cwd[$-1] == '/' ? "" : "/");
|
const auto working_dir = cwd ~ (cwd[$-1] == '/' ? "" : "/");
|
||||||
|
|
||||||
foreach (arg; parArgs[1 .. $]) {
|
bool show_version, show_help, show_license;
|
||||||
const auto curr_path = working_dir ~ arg;
|
bool check_mode;
|
||||||
File curr_file = File(curr_path, "rb");
|
ushort tiger_version = TIGER_VERSION_DEF;
|
||||||
if (!isDir(curr_path)) {
|
|
||||||
writefln("%s %s", tigerToString(getTiger(curr_file, true)), arg);
|
getopt(parArgs,
|
||||||
|
"version|v", &show_version,
|
||||||
|
"help|h", &show_help,
|
||||||
|
"check|c", &check_mode,
|
||||||
|
"tiger|t", &tiger_version,
|
||||||
|
"licence|license", &show_license
|
||||||
|
);
|
||||||
|
|
||||||
|
if (check_mode) {
|
||||||
|
}
|
||||||
|
else if (show_help) {
|
||||||
|
writefln("Usage: %s [OPTION]... [FILE]...", PROGRAM_NAME);
|
||||||
|
writeln(" -c, --check Read tiger sums from FILE and check them.");
|
||||||
|
writeln(" -h, --help Show this help.");
|
||||||
|
writeln(" -v, --version Show version info and quit.");
|
||||||
|
writefln(" -t n, --tiger=n Set the tiger version that should be used. Valid values are 1 or 2, %d is default.", TIGER_VERSION_DEF);
|
||||||
|
writefln(" --license Show details about the license under which %s is distributed.", PROGRAM_NAME);
|
||||||
|
}
|
||||||
|
else if (show_version) {
|
||||||
|
writefln("%s %d.%d Copyright © %d Michele \"King_DuckZ\" Santullo", PROGRAM_NAME, TIGERSUM_VERSION_MAJOR, TIGERSUM_VERSION_MINOR, COPYRIGHT_YEAR);
|
||||||
|
writeln("Using the reference tiger implementation by Ross Anderson and Eli Biham");
|
||||||
|
writeln("http://www.cs.technion.ac.il/~biham/Reports/Tiger/");
|
||||||
|
writeln();
|
||||||
|
writeln("This program comes with ABSOLUTELY NO WARRANTY.");
|
||||||
|
writeln("This is free software, and you are welcome to redistribute it");
|
||||||
|
writefln("under certain conditions; run %s --license for details.", PROGRAM_NAME);
|
||||||
|
}
|
||||||
|
else if (show_license) {
|
||||||
|
writefln("%s - a command line utility to calculate the tiger hash from input.", PROGRAM_NAME);
|
||||||
|
writefln("Copyright © %d Michele \"King_DuckZ\" Santullo", COPYRIGHT_YEAR);
|
||||||
|
writeln();
|
||||||
|
writefln("%s is free software: you can redistribute it and/or modify", PROGRAM_NAME);
|
||||||
|
writeln("it under the terms of the GNU General Public License as published by");
|
||||||
|
writeln("the Free Software Foundation, either version 3 of the License, or");
|
||||||
|
writeln("(at your option) any later version.");
|
||||||
|
writeln();
|
||||||
|
writefln("%s is distributed in the hope that it will be useful,", PROGRAM_NAME);
|
||||||
|
writeln("but WITHOUT ANY WARRANTY; without even the implied warranty of");
|
||||||
|
writeln("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the");
|
||||||
|
writeln("GNU General Public License for more details.");
|
||||||
|
writeln();
|
||||||
|
writeln("You should have received a copy of the GNU General Public License");
|
||||||
|
writeln("along with this program. If not, see <http://www.gnu.org/licenses/>.");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
writefln("tigersum: %s: is a directory", arg);
|
//regular mode
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//foreach (arg; parArgs[1 .. $]) {
|
||||||
|
// const auto curr_path = working_dir ~ arg;
|
||||||
|
// File curr_file = File(curr_path, "rb");
|
||||||
|
// if (!isDir(curr_path)) {
|
||||||
|
// writefln("%s %s", tigerToString(getTiger(curr_file, true)), arg);
|
||||||
|
// }
|
||||||
|
// else {
|
||||||
|
// writefln("tigersum: %s: is a directory", arg);
|
||||||
|
// }
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
|
|
5
tigersumConfig.d.in
Normal file
5
tigersumConfig.d.in
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
const ushort TIGER_VERSION_DEF = @DEFAULT_TIGER_VERSION@;
|
||||||
|
const ushort TIGERSUM_VERSION_MAJOR = @TIGERSUM_MAJOR@;
|
||||||
|
const ushort TIGERSUM_VERSION_MINOR = @TIGERSUM_MINOR@;
|
||||||
|
const ushort COPYRIGHT_YEAR = 2014;
|
||||||
|
const string PROGRAM_NAME = "@PROJECT_NAME@";
|
Loading…
Reference in a new issue