-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompl.c
More file actions
34 lines (29 loc) · 873 Bytes
/
Copy pathcompl.c
File metadata and controls
34 lines (29 loc) · 873 Bytes
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
#include "ltre.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void) {
size_t len = 0, cap = 256;
char *line = malloc(cap);
for (; !feof(stdin); len = 0) {
for (int c; c = fgetc(stdin), c != EOF && c != '\n'; line[len++] = c)
len + 1 == cap ? line = realloc(line, cap *= 2) : 0;
line[len] = '\0';
if (ferror(stdin))
perror("fgetc"), exit(EXIT_FAILURE);
if (feof(stdin))
break;
char *error = NULL, *loc = line;
struct regex *regex = ltre_parse(&loc, &error);
if (error) {
fprintf(stderr, "parse error: %s at pattern[%zu] near '%.16s'\n", error,
loc - line, loc);
continue;
}
struct dstate *dfa = ltre_compile(regex_compl(regex));
char *pattern = ltre_stringify(ltre_decompile(dfa));
puts(pattern);
dfa_free(dfa), free(pattern);
}
free(line);
}