blob: f7d0cbf4e0b3afb407a089fa6c23e10c31ac592d (
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
|
#include "mk.h"
int
match(char *name, char *template, char *stem)
{
Rune r;
int n;
while(*name && *template){
n = chartorune(&r, template);
if (PERCENT(r))
break;
while (n--)
if(*name++ != *template++)
return 0;
}
if(!PERCENT(*template))
return 0;
n = strlen(name)-strlen(template+1);
if (n < 0)
return 0;
if (strcmp(template+1, name+n))
return 0;
strncpy(stem, name, n);
stem[n] = 0;
if(*template == '&')
return !charin(stem, "./");
return 1;
}
void
subst(char *stem, char *template, char *dest, int dlen)
{
Rune r;
char *s, *e;
int n;
e = dest+dlen-1;
while(*template){
n = chartorune(&r, template);
if (PERCENT(r)) {
template += n;
for (s = stem; *s; s++)
if(dest < e)
*dest++ = *s;
} else
while (n--){
if(dest < e)
*dest++ = *template;
template++;
}
}
*dest = 0;
}
|