~ubuntu-branches/ubuntu/precise/9base/precise

« back to all changes in this revision

Viewing changes to mk/match.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Baumann
  • Date: 2009-08-20 17:34:06 UTC
  • mfrom: (6.2.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090820173406-xpwqa9ruyevvc0ut
Tags: 1:3-3
* Updating maintainer field.
* Updating vcs fields.
* Updating package to standards version 3.8.3.
* Updatin variables writing in rules to consistent style.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#include        "mk.h"
2
 
 
3
 
int
4
 
match(char *name, char *template, char *stem, Shell *sh)
5
 
{
6
 
        Rune r;
7
 
        int n;
8
 
 
9
 
        while(*name && *template){
10
 
                n = chartorune(&r, template);
11
 
                if (PERCENT(r))
12
 
                        break;
13
 
                while (n--)
14
 
                        if(*name++ != *template++)
15
 
                                return 0;
16
 
        }
17
 
        if(!PERCENT(*template))
18
 
                return 0;
19
 
        n = strlen(name)-strlen(template+1);
20
 
        if (n < 0)
21
 
                return 0;
22
 
        if (strcmp(template+1, name+n))
23
 
                return 0;
24
 
        strncpy(stem, name, n);
25
 
        stem[n] = 0;
26
 
        if(*template == '&')
27
 
                return !sh->charin(stem, "./");
28
 
        return 1;
29
 
}
30
 
 
31
 
void
32
 
subst(char *stem, char *template, char *dest)
33
 
{
34
 
        Rune r;
35
 
        char *s;
36
 
        int n;
37
 
 
38
 
        while(*template){
39
 
                n = chartorune(&r, template);
40
 
                if (PERCENT(r)) {
41
 
                        template += n;
42
 
                        for (s = stem; *s; s++)
43
 
                                *dest++ = *s;
44
 
                } else
45
 
                        while (n--)
46
 
                                *dest++ = *template++;
47
 
        }
48
 
        *dest = 0;
49
 
}