aboutsummaryrefslogtreecommitdiff
path: root/challenge-099/abigail/awk/ch-1.awk
blob: c35d249793bb57f98c416cd548ea009dbcbf771c (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
#!/usr/bin/awk

#
# See ../README.md
#

#
# Run as: awk -f ch-1.awk < input-file
#

{
    string  = $1
    pattern = $2
    split (pattern, characters, "")
    regexp  = ""
    for (i = 1; i <= length (characters); i ++) {
        if (characters [i] == "?") {
            regexp = regexp "."
            continue;
        }
        if (characters [i] == "*") {
            regexp = regexp ".*"
            continue;
        }
        if (match (characters [i], "[^a-zA-Z0-9]")) {
            regexp = regexp "\\"
        }
        regexp = regexp characters [i]
    }
    print match (string, "^" regexp "$") ? 1 : 0
}