options.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Copyright 2018-2020 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License 2.0 (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. #include "../testutil.h"
  10. #include "internal/nelem.h"
  11. #include "tu_local.h"
  12. #include "output.h"
  13. static int used[100] = { 0 };
  14. int test_skip_common_options(void)
  15. {
  16. OPTION_CHOICE_DEFAULT o;
  17. while ((o = (OPTION_CHOICE_DEFAULT)opt_next()) != OPT_EOF) {
  18. switch (o) {
  19. case OPT_TEST_CASES:
  20. break;
  21. default:
  22. case OPT_ERR:
  23. return 0;
  24. }
  25. }
  26. return 1;
  27. }
  28. size_t test_get_argument_count(void)
  29. {
  30. return opt_num_rest();
  31. }
  32. char *test_get_argument(size_t n)
  33. {
  34. char **argv = opt_rest();
  35. OPENSSL_assert(n < sizeof(used));
  36. if ((int)n >= opt_num_rest() || argv == NULL)
  37. return NULL;
  38. used[n] = 1;
  39. return argv[n];
  40. }
  41. void opt_check_usage(void)
  42. {
  43. int i;
  44. char **argv = opt_rest();
  45. int n, arg_count = opt_num_rest();
  46. if (arg_count > (int)OSSL_NELEM(used))
  47. n = (int)OSSL_NELEM(used);
  48. else
  49. n = arg_count;
  50. for (i = 0; i < n; i++) {
  51. if (used[i] == 0)
  52. test_printf_stderr("Warning ignored command-line argument %d: %s\n",
  53. i, argv[i]);
  54. }
  55. if (i < arg_count)
  56. test_printf_stderr("Warning arguments %d and later unchecked\n", i);
  57. }
  58. int opt_printf_stderr(const char *fmt, ...)
  59. {
  60. va_list ap;
  61. int ret;
  62. va_start(ap, fmt);
  63. ret = test_vprintf_stderr(fmt, ap);
  64. va_end(ap);
  65. return ret;
  66. }