_info 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include "config.h"
  4. /**
  5. * jmap - map from indices to values (based on libJudy)
  6. *
  7. * This provides a convenient wrapper for using JudyL arrays; using
  8. * integers or pointers as an index, Judy arrays provide an efficient
  9. * map to integers or pointers.
  10. *
  11. * jmap.h simply contains wrappers for a size_t-indexed size_t values, and
  12. * jmap_type.h contain a wrapper macro for size_t->pointer maps and pointer
  13. * ->pointer maps.
  14. *
  15. * Example:
  16. * // Silly example of associating data with arguments by pointer and int.
  17. * #include <string.h>
  18. * #include <stdio.h>
  19. * #include <ccan/jmap/jmap_type.h>
  20. *
  21. * struct opt_detail {
  22. * bool is_long;
  23. * unsigned int length; // == 1 if !is_long.
  24. * };
  25. *
  26. * // Define jmap_arg_<op> and jmap_arg, for int -> argv.
  27. * JMAP_DEFINE_UINTIDX_TYPE(char, arg);
  28. * // Define jmap_opt_<op> and jmap_opt, for argv -> struct opt_detail *.
  29. * JMAP_DEFINE_PTRIDX_TYPE(char, struct opt_detail, opt);
  30. *
  31. * int main(int argc, char *argv[])
  32. * {
  33. * int i;
  34. * // This map is equivalent to the argv[] array. Silly example.
  35. * struct jmap_arg *arg = jmap_arg_new();
  36. * struct jmap_opt *opt = jmap_opt_new();
  37. * struct opt_detail *d;
  38. *
  39. * // Note: this is not correct for real parsing!
  40. * for (i = 0; i < argc; i++) {
  41. * jmap_arg_add(arg, i, argv[i]);
  42. * if (i < 1 || argv[i][0] != '-')
  43. * continue;
  44. * d = malloc(sizeof(*d));
  45. * if (argv[i][1] == '-') {
  46. * // --<stuff>
  47. * d->is_long = true;
  48. * d->length = strlen(argv[i]+2);
  49. * } else {
  50. * // -<opt1>
  51. * d->is_long = false;
  52. * d->length = 1;
  53. * }
  54. * jmap_opt_add(opt, argv[i], d);
  55. * }
  56. *
  57. * printf("Found %lu options:\n", jmap_opt_count(opt));
  58. * for (i = jmap_arg_first(arg,-1); i!=-1; i = jmap_arg_next(arg,i,-1)) {
  59. * char *a = jmap_arg_get(arg, i);
  60. * d = jmap_opt_get(opt, a);
  61. * printf(" Arg %i ('%s') is a %s of %u chars\n",
  62. * i, a,
  63. * d == NULL ? "normal argument"
  64. * : d->is_long ? "long option"
  65. * : "short option",
  66. * d == NULL ? strlen(a) : d->length);
  67. * // We no longer need it, so free it here.
  68. * free(d);
  69. * }
  70. * jmap_opt_free(opt);
  71. * jmap_arg_free(arg);
  72. * return 0;
  73. * }
  74. *
  75. * License: LGPL (2 or any later version)
  76. * Author: Rusty Russell <rusty@rustcorp.com.au>
  77. */
  78. int main(int argc, char *argv[])
  79. {
  80. if (argc != 2)
  81. return 1;
  82. if (strcmp(argv[1], "depends") == 0) {
  83. printf("ccan/build_assert\n");
  84. printf("ccan/compiler\n");
  85. printf("Judy\n");
  86. return 0;
  87. }
  88. if (strcmp(argv[1], "libs") == 0) {
  89. printf("Judy\n");
  90. return 0;
  91. }
  92. return 1;
  93. }