-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathparser.c
53 lines (42 loc) · 957 Bytes
/
parser.c
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
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include "main.h"
#include "stack.h"
#include "parser.h"
extern stack_t STACK;
int ProcessLine(char *line, char *searchPattern) {
regex_t *preg;
int iRC;
char buffer[80];
preg = malloc(sizeof(regex_t));
if (NULL == preg) {
// malloc failed
return(-1);
}
iRC = regcomp(preg,searchPattern,REG_EXTENDED|REG_NOSUB);
if (0 != iRC ) {
// regex compile failed.
return(-2);
}
iRC = regexec(preg,line,0,NULL,0);
if (REG_NOMATCH == iRC ) {
// regexec failed to find a match
regerror (iRC, preg, buffer, 80);
//printf("%s\n",buffer);
goto processline_cleanup;
} else if (0 != iRC ) {
// regexec had some other error.
regerror (iRC, preg, buffer, 80);
printf("%s\n",buffer);
goto processline_cleanup;
}
// A match was found
//printf("%s",line);
processline_cleanup:
regfree(preg);
free(preg);
return (iRC);
}