_info 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #include <string.h>
  2. #include "config.h"
  3. /**
  4. * strset - an ordered set of strings
  5. *
  6. * This code implements an ordered set of string as a critbit tree. See:
  7. *
  8. * http://cr.yp.to/critbit.html
  9. * http://github.com/agl/critbit (which this code is based on)
  10. *
  11. * Note that ccan/htable is faster and uses less memory, but doesn't provide
  12. * ordered or prefix operations.
  13. *
  14. * Example:
  15. * // Print all words in order.
  16. * #include <ccan/strset/strset.h>
  17. * #include <ccan/grab_file/grab_file.h>
  18. * #include <err.h>
  19. * #include <string.h>
  20. *
  21. * static bool dump(const char *member, void *unused)
  22. * {
  23. * printf("%s ", member);
  24. * return true; // Keep going with iteration.
  25. * }
  26. *
  27. * int main(void)
  28. * {
  29. * struct strset words;
  30. * char *file, *word;
  31. *
  32. * strset_init(&words);
  33. * file = grab_fd(NULL, 0, NULL);
  34. * if (!file)
  35. * err(1, "Reading stdin");
  36. *
  37. * for (word = strtok(file, " \t\r\n");
  38. * word;
  39. * word = strtok(NULL, " \t\r\n")) {
  40. * strset_add(&words, word);
  41. * }
  42. * strset_iterate(&words, dump, NULL);
  43. * printf("\n");
  44. * return 0;
  45. * }
  46. * // Given "foo bar" outputs "bar foo "
  47. * // Given "foo foo bar" outputs "bar foo "
  48. *
  49. * License: CC0 (but some dependencies are LGPL!)
  50. * Author: Rusty Russell <rusty@rustcorp.com.au>
  51. * Ccanlint:
  52. * license_depends_compat FAIL
  53. */
  54. int main(int argc, char *argv[])
  55. {
  56. /* Expect exactly one argument */
  57. if (argc != 2)
  58. return 1;
  59. if (strcmp(argv[1], "depends") == 0) {
  60. printf("ccan/ilog\n"
  61. "ccan/likely\n"
  62. "ccan/short_types\n"
  63. "ccan/str\n"
  64. "ccan/typesafe_cb\n");
  65. return 0;
  66. }
  67. return 1;
  68. }