File: cmdlex.l

package info (click to toggle)
modemu 0.0.1-9
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 200 kB
  • ctags: 266
  • sloc: ansic: 1,860; lex: 146; makefile: 72
file content (146 lines) | stat: -rw-r--r-- 4,125 bytes parent folder | download | duplicates (4)
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
%{ /* -*- fundamental -*- */
/* lexer spec. for modemu command mode */
#include "cmdlex.h"	/*Cmdstat*/
#include "defs.h"	/*->atcmd.h (uchar)*/
#include "atcmd.h"	/*(atcmdDAddr)*/

#if 0
static struct {
	const char *ptr;
	const char *end;
} line;
#endif
static const char *ptr;

#if 0
#define yyInput() (*ptr++)
#define yyInput() (*ptr? *ptr++ : 0)
#endif

#if 0
static int
yyInput(void)
{
	if (line.ptr >= line.end) return 0;
	return *line.ptr++;
}
#endif

#ifdef FLEX_SCANNER
/*#undef yywrap*/
static int
flexYyInput(char *buf,int maxsize)
{
	int i;

	for (i = 0; i < maxsize; i++) {
		if (*ptr == 0) break;
		*buf++ = *ptr++;
	}
	return i;
}
# define YY_INPUT(buf,result,maxsize) (result = flexYyInput(buf,maxsize))
#else /*!ifdef FLEX_SCANNER*/
# undef input
# define input() (*ptr++)
# undef unput
# define unput(c) (ptr--) /* can't alter the const */
#endif /*ifdef FLEX_SCANNER*/

static Cmdstat cmdstat;

int
yywrap(void)
{
	return 1;
}

%}

	/*A_NUM	([0-9]{1,3}(\.[0-9]{1,3}){3}) <- meets ATT lex bug*/
	/*A_NUM	(([0-9]{1,3})(\.[0-9]{1,3}){3}) <- meets ATT lex bug*/
	/*A_NUM	(([0-9]{1,3}\.){3}[0-9]{1,3}) <- meets ATT lex bug*/
A_NUM	(([0-9]{1,3}\.){3}([0-9]{1,3}))
A_STR	([a-zA-Z][-a-zA-Z0-9.]*)
P_NUM	([0-9]{1,5})
P_STR	([a-zA-Z][-a-zA-Z0-9]*)
	/* TTYPE ([a-zA-Z][-/a-zA-Z0-9]*[a-zA-Z0-9]?) strict check */
TTYPE	([-/a-zA-Z0-9]*)

%s AT ATD
%k 1500

%%
%{
	BEGIN 0;
%}

<INITIAL>at |
<INITIAL>AT	{ BEGIN AT; cmdstat = CMDST_OK; }
<INITIAL>^#	{ return cmdstat = CMDST_NOAT; }
<INITIAL>.|\n	{ /*ignore preceding garbage*/ }

<AT>[dD]	{ BEGIN ATD; cmdstat = CMDST_ERROR; }
<AT>[eE][0-9]?	{ if (atcmdFake(yytext,"1")) return cmdstat = CMDST_ERROR; }
<AT>[fF][0-9]?	{ if (atcmdFake(yytext,"1")) return cmdstat = CMDST_ERROR; }
<AT>[hH][0-9]?	{ if (atcmdH(yytext)) return cmdstat = CMDST_ERROR; }
<AT>[iI][0-9]?	{ if (atcmdI(yytext)) return cmdstat = CMDST_ERROR; }
<AT>[oO][0-9]?	{ if (atcmdFake(yytext,"0")) return cmdstat = CMDST_ERROR;
		  cmdstat = CMDST_ATO; }
<AT>[pPtT]	{ /* just ignore */ }
<AT>[qQ][0-9]?	{ if (atcmdFake(yytext,"0")) return cmdstat = CMDST_ERROR; }
<AT>[vV][0-9]?	{ if (atcmdFake(yytext,"1")) return cmdstat = CMDST_ERROR; }
<AT>[xX][0-9]?	{ if (atcmdFake(yytext,"0")) return cmdstat = CMDST_ERROR; }
<AT>[sS][0-9]*=[0-9]*	{ /* ATT lex:[0-9]{0,n} n=2:OK n=3:NG */
			  if (atcmdSSet(yytext))
				return cmdstat = CMDST_ERROR; }
<AT>[sS][0-9]*\?	{ if (atcmdSQuery(yytext))
				return cmdstat = CMDST_ERROR; }
<AT>[zZ]		{ atcmdZ(); }
<AT>&[wW]		{ atcmdAW(); }
<AT>%[bB][0-9]?=[0-9]?	{ if (atcmdPB(yytext)) return cmdstat = CMDST_ERROR; }
<AT>%[dD][0-9]?		{ if (atcmdPD(yytext)) return cmdstat = CMDST_ERROR; }
<AT>%[lL][0-9]?		{ if (atcmdPL(yytext)) return cmdstat = CMDST_ERROR; }
<AT>%[qQ]		{ atcmdPQ(); }
<AT>%[rR][0-9]?		{ if (atcmdPR(yytext)) return cmdstat = CMDST_ERROR; }
<AT>%[tT][0-9]?		{ if (atcmdPT(yytext)) return cmdstat = CMDST_ERROR; }
<AT>%[tT]=\"{TTYPE}\"?	{ if (atcmdPTSet(yytext))
				return cmdstat = CMDST_ERROR; }
<AT>%[vV][0-9]*		{ if (atcmdPV(yytext)) return cmdstat = CMDST_ERROR; }
<AT>" "			{ /*ignore spaces*/ }
<AT>.|\n		{ return cmdstat = CMDST_ERROR; }

<ATD>[tTpP] |
<ATD>[0-9][wW,]		{ /* ignore them */ }
<ATD>[sS][0-9]*		{ /* use registered number (not work yet) */ }
<ATD>{A_NUM} |
<ATD>\"{A_NUM}\"?	{ atcmdD(yytext, ATDA_NUM, ATDP_NUL);
				cmdstat = CMDST_ATD; BEGIN AT; }
<ATD>{A_NUM}:{P_NUM} |
<ATD>\"{A_NUM}:{P_NUM}\"?	{ atcmdD(yytext, ATDA_NUM, ATDP_NUM);
					cmdstat = CMDST_ATD; BEGIN AT; }
<ATD>\"{A_NUM}:{P_STR}\"?	{ atcmdD(yytext, ATDA_NUM, ATDP_STR);
					cmdstat = CMDST_ATD; BEGIN AT; }
<ATD>\"{A_STR}\"?		{ atcmdD(yytext, ATDA_STR, ATDP_NUL);
					cmdstat = CMDST_ATD; BEGIN AT; }
<ATD>\"{A_STR}:{P_NUM}\"?	{ atcmdD(yytext, ATDA_STR, ATDP_NUM);
					cmdstat = CMDST_ATD; BEGIN AT; }
<ATD>\"{A_STR}:{P_STR}\"?	{ atcmdD(yytext, ATDA_STR, ATDP_STR);
					cmdstat = CMDST_ATD; BEGIN AT; }
<ATD>" "			{ /*ignore spaces*/ }
<ATD>.|\n			{ return cmdstat = CMDST_ERROR; }

%%

Cmdstat
cmdLex(const char *p)
{
	if (p == NULL) return CMDST_NOAT;
	ptr = p;
#ifdef FLEX_SCANNER
	yyrestart(yyin);
#endif
	cmdstat = CMDST_NOAT;
	yylex();
	return cmdstat;
}