Skip to content

Commit 1bd5954

Browse files
committed
help option added
1 parent 6295270 commit 1bd5954

File tree

2 files changed

+32
-11
lines changed

2 files changed

+32
-11
lines changed

dse

33.8 KB
Binary file not shown.

dse.c

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ void gen_iv(u8 *buf, int size)
6666
while(--size >= 0) buf[size] += rand();
6767
}
6868

69-
char vers[] = "1.31";
69+
char vers[] = "1.32";
7070
char msg1[] = "The data is invalid: %s\n";
7171
char msg2[] = "The file already exists: %s\n";
7272

@@ -264,6 +264,23 @@ int gen_key(char *dst, int pass) // keyfile name, pass true to request password
264264
return 0;
265265
}
266266

267+
int usage(int level)
268+
{
269+
printf("usage:\n"
270+
"\tdse <keyfile> [password]\n"
271+
"\tdse <keyfile> <e | d> <source> <destination>\n"
272+
"\tdse <-V | --version>\n"
273+
"\tdse <-h | --help>\n");
274+
if (level>0)
275+
{
276+
printf("examples:\n"
277+
"\tdse mykey creates a random-content 32 bytes keyfile named mykey\n"
278+
"\tdse mykey mypsw creates a 32 bytes keyfile from the password mypsw\n"
279+
"\tdse mykey e data data.enc encryption\n"
280+
"\tdse mykey d data.enc data decryption\n");
281+
}
282+
return 0;
283+
}
267284

268285
/*=====================================================================*/
269286

@@ -277,9 +294,21 @@ int main(int argc, char *argv[])
277294
printf("dse %s\n", vers);
278295
return 0;
279296
}
297+
if (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0)
298+
{
299+
usage(1);
300+
return 0;
301+
}
302+
if (argv[1][0] == '-')
303+
{
304+
usage(0);
305+
return 1;
306+
}
280307
}
281-
308+
// key generator
282309
if(argc == 2 || argc == 3) return gen_key(argv[1], argc == 3);
310+
311+
// file encrypt or decrypt
283312
if(argc == 5)
284313
{
285314
*argv[2] = tolower(*argv[2]);
@@ -291,14 +320,6 @@ int main(int argc, char *argv[])
291320
}
292321
}
293322

294-
printf("usage:\n"
295-
"\tdse <keyfile> [password]\n"
296-
"\tdse <keyfile> <e | d> <source> <destination>\n"
297-
"\tdse <-V | --version>\n\n"
298-
"examples:\n"
299-
"\tdse mykey creates a random-content 32 bytes keyfile named mykey\n"
300-
"\tdse mykey mypsw creates a 32 bytes keyfile from the password mypsw\n"
301-
"\tdse mykey e data data.enc encryption\n"
302-
"\tdse mykey d data.enc data decryption\n");
323+
usage(0);
303324
return 1;
304325
}

0 commit comments

Comments
 (0)