summaryrefslogtreecommitdiff
path: root/apps/version.c
diff options
context:
space:
mode:
authorRich Salz <rsalz@openssl.org>2015-04-24 15:26:15 -0400
committerRich Salz <rsalz@openssl.org>2015-04-24 15:26:15 -0400
commit7e1b7485706c2b11091b5fa897fe496a2faa56cc (patch)
treed008e38fda900d081a2496023625184c5c89a5ff /apps/version.c
parent53dd4ddf71ad79a64be934ca19445b1cf560adab (diff)
downloadopenssl-new-7e1b7485706c2b11091b5fa897fe496a2faa56cc.tar.gz
Big apps cleanup (option-parsing, etc)
This is merges the old "rsalz-monolith" branch over to master. The biggest change is that option parsing switch from cascasding 'else if strcmp("-foo")' to a utility routine and somethin akin to getopt. Also, an error in the command line no longer prints the full summary; use -help (or --help :) for that. There have been many other changes and code-cleanup, see bullet list below. Special thanks to Matt for the long and detailed code review. TEMPORARY: For now, comment out CRYPTO_mem_leaks() at end of main Tickets closed: RT3515: Use 3DES in pkcs12 if built with no-rc2 RT1766: s_client -reconnect and -starttls broke RT2932: Catch write errors RT2604: port should be 'unsigned short' RT2983: total_bytes undeclared #ifdef RENEG RT1523: Add -nocert to fix output in x509 app RT3508: Remove unused variable introduced by b09eb24 RT3511: doc fix; req default serial is random RT1325,2973: Add more extensions to c_rehash RT2119,3407: Updated to dgst.pod RT2379: Additional typo fix RT2693: Extra include of string.h RT2880: HFS is case-insensitive filenames RT3246: req command prints version number wrong Other changes; incompatibilities marked with *: Add SCSV support Add -misalign to speed command Make dhparam, dsaparam, ecparam, x509 output C in proper style Make some internal ocsp.c functions void Only display cert usages with -help in verify Use global bio_err, remove "BIO*err" parameter from functions For filenames, - always means stdin (or stdout as appropriate) Add aliases for -des/aes "wrap" ciphers. *Remove support for IISSGC (server gated crypto) *The undocumented OCSP -header flag is now "-header name=value" *Documented the OCSP -header flag Reviewed-by: Matt Caswell <matt@openssl.org>
Diffstat (limited to 'apps/version.c')
-rw-r--r--apps/version.c88
1 files changed, 54 insertions, 34 deletions
diff --git a/apps/version.c b/apps/version.c
index 8807d4c7b0..1fa7cfe536 100644
--- a/apps/version.c
+++ b/apps/version.c
@@ -1,4 +1,3 @@
-/* apps/version.c */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -132,45 +131,66 @@
# include <openssl/blowfish.h>
#endif
-#undef PROG
-#define PROG version_main
+typedef enum OPTION_choice {
+ OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
+ OPT_B, OPT_D, OPT_F, OPT_O, OPT_P, OPT_V, OPT_A
+} OPTION_CHOICE;
-int MAIN(int, char **);
+OPTIONS version_options[] = {
+ {"help", OPT_HELP, '-', "Display this summary"},
+ {"a", OPT_A, '-', "Show all data"},
+ {"b", OPT_B, '-', "Show build date"},
+ {"d", OPT_D, '-', "Show configuration directory"},
+ {"f", OPT_F, '-', "Show compiler flags used"},
+ {"o", OPT_O, '-', "Show some internal datatype options"},
+ {"p", OPT_P, '-', "Show target build platform"},
+ {"v", OPT_V, '-', "Show library version"},
+ {NULL}
+};
-int MAIN(int argc, char **argv)
+int version_main(int argc, char **argv)
{
- int i, ret = 0;
+ int ret = 1, dirty = 0;
int cflags = 0, version = 0, date = 0, options = 0, platform = 0, dir = 0;
+ char *prog;
+ OPTION_CHOICE o;
- apps_startup();
-
- if (bio_err == NULL)
- if ((bio_err = BIO_new(BIO_s_file())) != NULL)
- BIO_set_fp(bio_err, stderr, BIO_NOCLOSE | BIO_FP_TEXT);
-
- if (argc == 1)
- version = 1;
- for (i = 1; i < argc; i++) {
- if (strcmp(argv[i], "-v") == 0)
- version = 1;
- else if (strcmp(argv[i], "-b") == 0)
- date = 1;
- else if (strcmp(argv[i], "-f") == 0)
- cflags = 1;
- else if (strcmp(argv[i], "-o") == 0)
- options = 1;
- else if (strcmp(argv[i], "-p") == 0)
- platform = 1;
- else if (strcmp(argv[i], "-d") == 0)
- dir = 1;
- else if (strcmp(argv[i], "-a") == 0)
- date = version = cflags = options = platform = dir = 1;
- else {
- BIO_printf(bio_err, "usage:version -[avbofpd]\n");
- ret = 1;
+ prog = opt_init(argc, argv, version_options);
+ while ((o = opt_next()) != OPT_EOF) {
+ switch (o) {
+ case OPT_EOF:
+ case OPT_ERR:
+ BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
goto end;
+ case OPT_HELP:
+ opt_help(version_options);
+ ret = 0;
+ goto end;
+ case OPT_B:
+ dirty = date = 1;
+ break;
+ case OPT_D:
+ dirty = dir = 1;
+ break;
+ case OPT_F:
+ dirty = cflags = 1;
+ break;
+ case OPT_O:
+ dirty = options = 1;
+ break;
+ case OPT_P:
+ dirty = platform = 1;
+ break;
+ case OPT_V:
+ dirty = version = 1;
+ break;
+ case OPT_A:
+ cflags = version = date = platform = dir = 1;
+ break;
}
}
+ if (!dirty)
+ version = 1;
if (version) {
if (SSLeay() == SSLEAY_VERSION_NUMBER) {
@@ -208,7 +228,7 @@ int MAIN(int argc, char **argv)
printf("%s\n", SSLeay_version(SSLEAY_CFLAGS));
if (dir)
printf("%s\n", SSLeay_version(SSLEAY_DIR));
+ ret = 0;
end:
- apps_shutdown();
- OPENSSL_EXIT(ret);
+ return (ret);
}