forked from git/git
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalias.c
More file actions
Latest commit
90 lines (74 loc) · 1.76 KB
/
Copy pathalias.c
File metadata and controls
90 lines (74 loc) · 1.76 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include"cache.h"
#include"config.h"
structconfig_alias_data {
constchar*alias;
char*v;
};
staticintconfig_alias_cb(constchar*key, constchar*value, void*d)
{
structconfig_alias_data*data=d;
constchar*p;
if (skip_prefix(key, "alias.", &p) && !strcasecmp(p, data->alias))
returngit_config_string((constchar**)&data->v, key, value);
return0;
}
char*alias_lookup(constchar*alias)
{
structconfig_alias_datadata= { alias, NULL };
read_early_config(config_alias_cb, &data);
returndata.v;
}
#defineSPLIT_CMDLINE_BAD_ENDING 1
#defineSPLIT_CMDLINE_UNCLOSED_QUOTE 2
staticconstchar*split_cmdline_errors[] = {
"cmdline ends with \\",
"unclosed quote"
};
intsplit_cmdline(char*cmdline, constchar***argv)
{
intsrc, dst, count=0, size=16;
charquoted=0;
ALLOC_ARRAY(*argv, size);
/* split alias_string */
(*argv)[count++] =cmdline;
for (src=dst=0; cmdline[src];) {
charc=cmdline[src];
if (!quoted&&isspace(c)) {
cmdline[dst++] =0;
while (cmdline[++src]
&&isspace(cmdline[src]))
; /* skip */
ALLOC_GROW(*argv, count+1, size);
(*argv)[count++] =cmdline+dst;
} elseif (!quoted&& (c=='\''||c=='"')) {
quoted=c;
src++;
} elseif (c==quoted) {
quoted=0;
src++;
} else {
if (c=='\\'&"ed!='\'') {
src++;
c=cmdline[src];
if (!c) {
FREE_AND_NULL(*argv);
return-SPLIT_CMDLINE_BAD_ENDING;
}
}
cmdline[dst++] =c;
src++;
}
}
cmdline[dst] =0;
if (quoted) {
FREE_AND_NULL(*argv);
return-SPLIT_CMDLINE_UNCLOSED_QUOTE;
}
ALLOC_GROW(*argv, count+1, size);
(*argv)[count] =NULL;
returncount;
}
constchar*split_cmdline_strerror(intsplit_cmdline_errno)
{
returnsplit_cmdline_errors[-split_cmdline_errno-1];
}