-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlex.c
More file actions
67 lines (54 loc) · 1.24 KB
/
lex.c
File metadata and controls
67 lines (54 loc) · 1.24 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
%option noyywrap
%{
#undef _POSIX_SOURCE
#define _POSIX_SOURCE
#define YY_PROTO(proto) proto
#define YY_DECL char **yylex YY_PROTO(( void ))
int _numargs = 10;
char *_args[10];
int _argcount = 0;
int readInputForLexer(char *buffer, int *numBytesRead, int maxBytesToRead);
#include <stdio.h>
int fileno(FILE *);
#include <stdlib.h>
#include <string.h>
#undef YY_INPUT
#define YY_INPUT(b,r,s) readInputForLexer(b,&r,s)
%}
WORD [a-zA-Z0-9\/\.\-\=]+
SPECIAL [()><|&;*]
%%
_argcount = 0;
_args[0] = NULL;
{WORD}|{SPECIAL} {
if(_argcount < _numargs-1) {
_args[_argcount++] = (char *)strdup(yytext);
_args[_argcount] = NULL;
}
}
\n return _args;
[ \t]+
.
%%
char **get_line(void) {
return (char **)yylex();
}
int readInputForLexer(char *buffer, int *numBytesRead, int maxBytesToRead)
{
do {
int c = getc(stdin);
if (c == EOF) {
/* EOF indicates either EOF or error */
if (feof(stdin)) {
*numBytesRead = YY_NULL;
return 0;
}
/* Must have been a signal interrupting us */
clearerr(stdin);
} else {
buffer[0] = c;
*numBytesRead = 1;
return 0;
}
} while(1);
}