_info 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #include <stdio.h>
  2. #include <string.h>
  3. /**
  4. * asort - typesafe array sort (qsort)
  5. *
  6. * qsort() is the standard routine for sorting an array of objects.
  7. * Unfortunately, it has two problems:
  8. * 1) It isn't typesafe,
  9. * 2) The comparison function doesn't take a context pointer.
  10. *
  11. * asort does both.
  12. *
  13. * License: LGPL
  14. * Author: Rusty Russell <rusty@rustcorp.com.au>
  15. *
  16. * Example:
  17. * #include <ccan/asort/asort.h>
  18. * #include <stdio.h>
  19. * #include <string.h>
  20. *
  21. * static int cmp(char *const *a, char *const *n, bool *casefold)
  22. * {
  23. * if (*casefold)
  24. * return strcasecmp(*a, *n);
  25. * else
  26. * return strcmp(*a, *n);
  27. * }
  28. *
  29. * int main(int argc, char *argv[])
  30. * {
  31. * bool casefold = false;
  32. * unsigned int i;
  33. *
  34. * if (argc < 2) {
  35. * fprintf(stderr, "Usage: %s [-i] <list>...\n"
  36. * "Sort arguments (-i = ignore case)\n",
  37. * argv[0]);
  38. * exit(1);
  39. * }
  40. *
  41. * if (strcmp(argv[1], "-i") == 0) {
  42. * casefold = true;
  43. * argc--;
  44. * argv++;
  45. * }
  46. * asort(&argv[1], argc-1, cmp, &casefold);
  47. * for (i = 1; i < argc; i++)
  48. * printf("%s ", argv[i]);
  49. * printf("\n");
  50. * return 0;
  51. * }
  52. */
  53. int main(int argc, char *argv[])
  54. {
  55. if (argc != 2)
  56. return 1;
  57. if (strcmp(argv[1], "depends") == 0) {
  58. printf("ccan/typesafe_cb\n");
  59. printf("ccan/array_size\n");
  60. return 0;
  61. }
  62. return 1;
  63. }