cmdline.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * libcsync -- a library to sync a directory with another
  3. *
  4. * Copyright (c) 2008-2013 by Andreas Schneider <asn@cryptomilk.org>
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include "config_csync.h"
  21. #include "torture.h"
  22. #ifdef HAVE_ARGP_H
  23. #include <argp.h>
  24. const char *argp_program_version = "csync test 0.2";
  25. const char *argp_program_bug_address = "<csync-devel@csync.org>";
  26. static char **cmdline;
  27. /* Program documentation. */
  28. static char doc[] = "csync test";
  29. /* The options we understand. */
  30. static struct argp_option options[] = {
  31. {
  32. .name = "verbose",
  33. .key = 'v',
  34. .arg = NULL,
  35. .flags = 0,
  36. .doc = "Make csync test more verbose",
  37. .group = 0
  38. },
  39. {NULL, 0, NULL, 0, NULL, 0}
  40. };
  41. /* Parse a single option. */
  42. static error_t parse_opt (int key, char *arg, struct argp_state *state) {
  43. /* Get the input argument from argp_parse, which we
  44. * know is a pointer to our arguments structure.
  45. */
  46. struct argument_s *arguments = state->input;
  47. /* arg is currently not used */
  48. (void) arg;
  49. switch (key) {
  50. case 'v':
  51. arguments->verbose++;
  52. break;
  53. case ARGP_KEY_ARG:
  54. /* End processing here. */
  55. cmdline = &state->argv [state->next - 1];
  56. state->next = state->argc;
  57. break;
  58. default:
  59. return ARGP_ERR_UNKNOWN;
  60. }
  61. return 0;
  62. }
  63. /* Our argp parser. */
  64. /* static struct argp argp = {options, parse_opt, args_doc, doc, NULL, NULL, NULL}; */
  65. static struct argp argp = {options, parse_opt, NULL, doc, NULL, NULL, NULL};
  66. #endif /* HAVE_ARGP_H */
  67. void torture_cmdline_parse(int argc, char **argv, struct argument_s *arguments) {
  68. /*
  69. * Parse our arguments; every option seen by parse_opt will
  70. * be reflected in arguments.
  71. */
  72. #ifdef HAVE_ARGP_H
  73. argp_parse(&argp, argc, argv, 0, 0, arguments);
  74. #else
  75. (void) argc;
  76. (void) argv;
  77. (void) arguments;
  78. #endif /* HAVE_ARGP_H */
  79. }