Linux Audio

Check our new training course

Loading...
Note: File does not exist in v6.2.
 1#include "cache.h"
 2#include "util.h"
 3#include "config.h"
 4
 5static const char *alias_key;
 6static char *alias_val;
 7
 8static int alias_lookup_cb(const char *k, const char *v,
 9			   void *cb __maybe_unused)
10{
11	if (!prefixcmp(k, "alias.") && !strcmp(k+6, alias_key)) {
12		if (!v)
13			return config_error_nonbool(k);
14		alias_val = strdup(v);
15		return 0;
16	}
17	return 0;
18}
19
20char *alias_lookup(const char *alias)
21{
22	alias_key = alias;
23	alias_val = NULL;
24	perf_config(alias_lookup_cb, NULL);
25	return alias_val;
26}
27
28int split_cmdline(char *cmdline, const char ***argv)
29{
30	int src, dst, count = 0, size = 16;
31	char quoted = 0;
32
33	*argv = malloc(sizeof(char*) * size);
34
35	/* split alias_string */
36	(*argv)[count++] = cmdline;
37	for (src = dst = 0; cmdline[src];) {
38		char c = cmdline[src];
39		if (!quoted && isspace(c)) {
40			cmdline[dst++] = 0;
41			while (cmdline[++src]
42					&& isspace(cmdline[src]))
43				; /* skip */
44			if (count >= size) {
45				size += 16;
46				*argv = realloc(*argv, sizeof(char*) * size);
47			}
48			(*argv)[count++] = cmdline + dst;
49		} else if (!quoted && (c == '\'' || c == '"')) {
50			quoted = c;
51			src++;
52		} else if (c == quoted) {
53			quoted = 0;
54			src++;
55		} else {
56			if (c == '\\' && quoted != '\'') {
57				src++;
58				c = cmdline[src];
59				if (!c) {
60					zfree(argv);
61					return error("cmdline ends with \\");
62				}
63			}
64			cmdline[dst++] = c;
65			src++;
66		}
67	}
68
69	cmdline[dst] = 0;
70
71	if (quoted) {
72		zfree(argv);
73		return error("unclosed quote");
74	}
75
76	return count;
77}
78