pata_legacy: fix CONFIG_PATA_WINBOND_VLB_MODULE test
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / tools / perf / util / alias.c
blobb8144e80bb1e5b436d95f1c96757fe34b9451946
1 #include "cache.h"
3 static const char *alias_key;
4 static char *alias_val;
6 static int alias_lookup_cb(const char *k, const char *v, void *cb __used)
8 if (!prefixcmp(k, "alias.") && !strcmp(k+6, alias_key)) {
9 if (!v)
10 return config_error_nonbool(k);
11 alias_val = strdup(v);
12 return 0;
14 return 0;
17 char *alias_lookup(const char *alias)
19 alias_key = alias;
20 alias_val = NULL;
21 perf_config(alias_lookup_cb, NULL);
22 return alias_val;
25 int split_cmdline(char *cmdline, const char ***argv)
27 int src, dst, count = 0, size = 16;
28 char quoted = 0;
30 *argv = malloc(sizeof(char*) * size);
32 /* split alias_string */
33 (*argv)[count++] = cmdline;
34 for (src = dst = 0; cmdline[src];) {
35 char c = cmdline[src];
36 if (!quoted && isspace(c)) {
37 cmdline[dst++] = 0;
38 while (cmdline[++src]
39 && isspace(cmdline[src]))
40 ; /* skip */
41 if (count >= size) {
42 size += 16;
43 *argv = realloc(*argv, sizeof(char*) * size);
45 (*argv)[count++] = cmdline + dst;
46 } else if (!quoted && (c == '\'' || c == '"')) {
47 quoted = c;
48 src++;
49 } else if (c == quoted) {
50 quoted = 0;
51 src++;
52 } else {
53 if (c == '\\' && quoted != '\'') {
54 src++;
55 c = cmdline[src];
56 if (!c) {
57 free(*argv);
58 *argv = NULL;
59 return error("cmdline ends with \\");
62 cmdline[dst++] = c;
63 src++;
67 cmdline[dst] = 0;
69 if (quoted) {
70 free(*argv);
71 *argv = NULL;
72 return error("unclosed quote");
75 return count;