-/* apps/errstr.c */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
#include <openssl/err.h>
#include <openssl/ssl.h>
-#undef PROG
-#define PROG errstr_main
+typedef enum OPTION_choice {
+ OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
+ OPT_STATS
+} OPTION_CHOICE;
-int MAIN(int, char **);
+OPTIONS errstr_options[] = {
+ {OPT_HELP_STR, 1, '-', "Usage: %s [options] errnum...\n"},
+ {OPT_HELP_STR, 1, '-', " errnum Error number\n"},
+ {"help", OPT_HELP, '-', "Display this summary"},
+ {"stats", OPT_STATS, '-',
+ "Print internal hashtable statistics (long!)"},
+ {NULL}
+};
-int MAIN(int argc, char **argv)
+int errstr_main(int argc, char **argv)
{
- int i, ret = 0;
- char buf[256];
+ OPTION_CHOICE o;
+ char buf[256], *prog;
+ int ret = 1;
unsigned long l;
- 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);
-
- SSL_load_error_strings();
-
- if ((argc > 1) && (strcmp(argv[1], "-stats") == 0)) {
- BIO *out = NULL;
-
- out = BIO_new(BIO_s_file());
- if ((out != NULL) && BIO_set_fp(out, stdout, BIO_NOCLOSE)) {
-#ifdef OPENSSL_SYS_VMS
- {
- BIO *tmpbio = BIO_new(BIO_f_linebuffer());
- out = BIO_push(tmpbio, out);
- }
-#endif
- lh_ERR_STRING_DATA_node_stats_bio(ERR_get_string_table(), out);
- lh_ERR_STRING_DATA_stats_bio(ERR_get_string_table(), out);
+ prog = opt_init(argc, argv, errstr_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(errstr_options);
+ ret = 0;
+ goto end;
+ case OPT_STATS:
+ lh_ERR_STRING_DATA_node_stats_bio(ERR_get_string_table(),
+ bio_out);
+ lh_ERR_STRING_DATA_stats_bio(ERR_get_string_table(), bio_out);
lh_ERR_STRING_DATA_node_usage_stats_bio(ERR_get_string_table(),
- out);
+ bio_out);
+ ret = 0;
+ goto end;
}
- BIO_free_all(out);
- argc--;
- argv++;
}
+ argc = opt_num_rest();
+ argv = opt_rest();
- for (i = 1; i < argc; i++) {
- if (sscanf(argv[i], "%lx", &l)) {
- ERR_error_string_n(l, buf, sizeof buf);
- printf("%s\n", buf);
- } else {
- printf("%s: bad error code\n", argv[i]);
- printf("usage: errstr [-stats] <errno> ...\n");
+ ret = 0;
+ for (argv = opt_rest(); *argv; argv++) {
+ if (!opt_ulong(*argv, &l))
ret++;
+ else {
+ ERR_error_string_n(l, buf, sizeof buf);
+ BIO_printf(bio_out, "%s\n", buf);
}
}
- apps_shutdown();
- OPENSSL_EXIT(ret);
+ end:
+ return (ret);
}