forked from rileym65/Basic-02
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatch.c
More file actions
72 lines (69 loc) · 2.05 KB
/
Copy pathmatch.c
File metadata and controls
72 lines (69 loc) · 2.05 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
/*
*******************************************************************
*** This software is copyright 2021 by Michael H Riley ***
*** You have permission to use, modify, copy, and distribute ***
*** this software so long as this copyright notice is retained. ***
*** This software may not be used in commercial applications ***
*** without express written permission from the author. ***
*******************************************************************
*/
#include "header.h"
int match(char* line, char* pattern) {
int pos;
line = trim(line);
pattern = trim(pattern);
matchCount = 0;
while (*pattern != 0) {
pos = 0;
if (*line == 0 || *line == ':') {
return 0;
}
switch (*pattern) {
case 'A':
if ((*line < 'a' || *line > 'z') &&
(*line < 'A' || *line > 'Z')) return 0;
while ((*line >= 'a' && *line <= 'z') ||
(*line >= 'A' && *line <= 'Z') ||
(*line >= '0' && *line <= '9') ||
*line == '_') {
matches[matchCount][pos++] = *line;
matches[matchCount][pos] = 0;
line++;
}
matchCount++;
break;
case '#':
if (*line == '-') {
matches[matchCount][pos++] = '-';
matches[matchCount][pos] = 0;
line++;
}
if (*line < '0' || *line > '9') {
return 0;
}
while (*line >= '0' && *line <= '9') {
matches[matchCount][pos++] = *line;
matches[matchCount][pos] = 0;
line++;
}
matchCount++;
break;
default :
if (*line != *pattern) {
return 0;
}
matches[matchCount][pos++] = *line;
matches[matchCount][pos] = 0;
matchCount++;
line++;
break;
}
pattern++;
line = trim(line);
pattern=trim(pattern);
}
if (*line == 0 || *line == ':') {
return -1;
}
return 0;
}