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