Skip to content

Commit bacd49b

Browse files
authored
added --version option
1 parent e663a6e commit bacd49b

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/main.c

+15-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include "sha1.h"
99

1010

11-
#define MSGMAXLEN 1024
11+
#define MSGMAXLEN 4096
1212

1313
#define USAGE "USAGE: '%s' <message> [options]"
1414
#define USAGE_HELP "See \"'%s' --help\" for more infos."
@@ -37,6 +37,7 @@ typedef enum hash_type {
3737

3838
// displays help page
3939
void display_help(const char* command_argv0);
40+
void display_version(void);
4041
int argparse(int argc, char *argv[], hash_type* htype, verbose* vblevel);
4142
char* get_algorithm(hash_type hash);
4243
void display_hash(word32* H, hash_type htype, verbose vblevel);
@@ -54,6 +55,9 @@ int main(int argc, char *argv[]) {
5455
} else if (strcmp(argv[1], "-h")==0 || strcmp(argv[1], "--help")==0) {
5556
display_help(argv[0]);
5657
return EXIT_SUCCESS;
58+
} else if (strcmp(argv[1], "--version")==0) {
59+
display_version();
60+
return EXIT_SUCCESS;
5761
} else /* if (argc > 2)*/ { // If the command has arguments
5862
int retval = argparse(argc,argv,&htype,&vblevel);
5963
if (retval != EXIT_SUCCESS) {return EXIT_FAILURE;}
@@ -242,9 +246,19 @@ char* get_algorithm(hash_type hash) {
242246
return hashname;
243247
}
244248

249+
void display_version(void) {
250+
// printf("================================================================================\n");
251+
printf("shak version %s\n",SHAKVERSION);
252+
printf("Copyright (c) 2024 elfurioux\nMIT License, built with\n%s\n\n",GCCVERSION);
253+
printf("THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n");
254+
printf("IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n");
255+
printf("FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\n");
256+
}
257+
245258
void display_help(const char* command_argv0) {
246259
// printf("================================================================================\n");
247260
printf(USAGE "\n\n", command_argv0);
261+
printf(" --version Shows the version and copyright and exit.\n");
248262
printf(" --help Shows this help page then exit.\n");
249263
printf(" -h Equivalent of --help\n");
250264
printf(" --hash <hash> Specifies the type of hash to use. (default sha256)\n");
@@ -267,8 +281,6 @@ void display_help(const char* command_argv0) {
267281
printf(" gram does, display every computation step, might be a\n");
268282
printf(" bunch of informations.\n");
269283
printf(" --verbose=[0-2] equivalent of -v");
270-
271-
return;
272284
}
273285

274286
int argparse(int argc, char *argv[], hash_type* htype, verbose* vblevel) {

0 commit comments

Comments
 (0)