summaryrefslogtreecommitdiff
path: root/ccan/asort/_info
blob: 28e2faebecb3edfcc8e3eff487b99c59cc219401 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "config.h"
#include <stdio.h>
#include <string.h>

/**
 * asort - typesafe array sort (qsort)
 *
 * qsort() is the standard routine for sorting an array of objects.
 * Unfortunately, it has two problems:
 *     1) It isn't typesafe,
 *     2) The comparison function doesn't take a context pointer.
 *
 * asort does both.
 *
 * License: LGPL (v2.1 or any later version)
 * Author: Rusty Russell <rusty@rustcorp.com.au>
 *
 * Example:
 *	#include <ccan/asort/asort.h>
 *	#include <stdio.h>
 *	#include <string.h>
 *	
 *	static int cmp(char *const *a, char *const *n, bool *casefold)
 *	{
 *		if (*casefold)
 *			return strcasecmp(*a, *n);
 *		else
 *			return strcmp(*a, *n);
 *	}
 *	
 *	int main(int argc, char *argv[])
 *	{
 *		bool casefold = false;
 *		unsigned int i;
 *	
 *		if (argc < 2) {
 *			fprintf(stderr, "Usage: %s [-i] <list>...\n"
 *				"Sort arguments (-i = ignore case)\n",
 *				argv[0]);
 *			exit(1);
 *		}
 *	
 *		if (strcmp(argv[1], "-i") == 0) {
 *			casefold = true;
 *			argc--;
 *			argv++;
 *		}
 *		asort(&argv[1], argc-1, cmp, &casefold);
 *		for (i = 1; i < argc; i++)
 *			printf("%s ", argv[i]);
 *		printf("\n");
 *		return 0;
 *	}
 */
int main(int argc, char *argv[])
{
	if (argc != 2)
		return 1;

	if (strcmp(argv[1], "depends") == 0) {
		printf("ccan/order\n");
		return 0;
	}
	if (strcmp(argv[1], "testdepends") == 0) {
		printf("ccan/array_size\n");
		return 0;
	}

	return 1;
}