-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpatchar.c
More file actions
68 lines (59 loc) · 1.82 KB
/
patchar.c
File metadata and controls
68 lines (59 loc) · 1.82 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
#include <external.h>
#include <caneka.h>
static i64 PatChar_continueFromStr(MemCh *m, Str *s, Str *ps, word flags){
byte *b = s->bytes;
byte *end = s->bytes+(s->length-1);
i64 total = 0;
while(b <= end){
PatCharDef *pat = (PatCharDef *)(ps->bytes+ps->length);
pat->flags = flags;
pat->from = pat->to = *b;
b++;
ps->length += sizeof(PatCharDef);
total += sizeof(PatCharDef);
}
return total;
}
PatCharDef *PatChar_FromStrVec(MemCh *m, StrVec *v){
size_t sz = (v->total+1) * sizeof(PatCharDef);
if(sz > STR_MAX){
Fatal(FUNCNAME, FILENAME, LINENUMBER,
"StrVec too long for PatChar Str", NULL);
return NULL;
}
Str *ps = Str_Make(m, sz);
Iter it;
Iter_Init(&it, v->p);
while((Iter_Next(&it) & END) == 0){
Str *s = (Str *)it.value;
PatChar_continueFromStr(m, s, ps, PAT_TERM);
}
PatCharDef *pat = (PatCharDef *)(ps->bytes+ps->length);
pat->flags = PAT_END;
pat->from = 0;
pat->to = 0;
ps->length += sizeof(PatCharDef);
return (PatCharDef *)ps->bytes;
}
PatCharDef *PatChar_fromStr(MemCh *m, Str *s, word flags){
size_t sz = (s->length+1) * sizeof(PatCharDef);
if(sz > STR_MAX){
Fatal(FUNCNAME, FILENAME, LINENUMBER,
"Str too long for PatChar Str", NULL);
return NULL;
}
Str *ps = Str_Make(m, sz);
PatChar_continueFromStr(m, s, ps, flags);
PatCharDef *pat = (PatCharDef *)(ps->bytes+ps->length);
pat->flags = PAT_END;
pat->from = 0;
pat->to = 0;
ps->length += sizeof(PatCharDef);
return (PatCharDef *)ps->bytes;
}
PatCharDef *PatChar_FromStr(MemCh *m, Str *s){
return PatChar_fromStr(m, s, PAT_TERM);
}
PatCharDef *PatChar_KoFromStr(MemCh *m, Str *s){
return PatChar_fromStr(m, s, PAT_KO|PAT_KO_TERM);
}