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