_info 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include "config.h"
  4. /**
  5. * opt - simple command line parsing
  6. *
  7. * Simple but powerful command line parsing.
  8. *
  9. * See Also:
  10. * ccan/autodata
  11. *
  12. * Example:
  13. * #include <ccan/opt/opt.h>
  14. * #include <stdio.h>
  15. * #include <stdlib.h>
  16. *
  17. * static bool someflag;
  18. * static int verbose;
  19. * static char *somestring;
  20. *
  21. * static struct opt_table opts[] = {
  22. * OPT_WITHOUT_ARG("--verbose|-v", opt_inc_intval, &verbose,
  23. * "Verbose mode (can be specified more than once)"),
  24. * OPT_WITHOUT_ARG("--someflag", opt_set_bool, &someflag,
  25. * "Set someflag"),
  26. * OPT_WITH_ARG("--somefile=<filename>", opt_set_charp, opt_show_charp,
  27. * &somestring, "Set somefile to <filename>"),
  28. * OPT_WITHOUT_ARG("--usage|--help|-h", opt_usage_and_exit,
  29. * "args...\nA silly test program.",
  30. * "Print this message."),
  31. * OPT_ENDTABLE
  32. * };
  33. *
  34. * int main(int argc, char *argv[])
  35. * {
  36. * int i;
  37. *
  38. * opt_register_table(opts, NULL);
  39. * // For fun, register an extra one.
  40. * opt_register_noarg("--no-someflag", opt_set_invbool, &someflag,
  41. * "Unset someflag");
  42. * if (!opt_parse(&argc, argv, opt_log_stderr))
  43. * exit(1);
  44. *
  45. * printf("someflag = %i, verbose = %i, somestring = %s\n",
  46. * someflag, verbose, somestring);
  47. * printf("%u args left over:", argc - 1);
  48. * for (i = 1; i < argc; i++)
  49. * printf(" %s", argv[i]);
  50. * printf("\n");
  51. * return 0;
  52. * }
  53. *
  54. * License: GPL (v2 or any later version)
  55. * Author: Rusty Russell <rusty@rustcorp.com.au>
  56. */
  57. int main(int argc, char *argv[])
  58. {
  59. if (argc != 2)
  60. return 1;
  61. if (strcmp(argv[1], "depends") == 0) {
  62. printf("ccan/cast\n");
  63. printf("ccan/compiler\n");
  64. printf("ccan/typesafe_cb\n");
  65. return 0;
  66. }
  67. return 1;
  68. }