"Fossies" - the Fresh Open Source Software Archive 
Member "portfwd-0.29/src/conf.lex" (28 Jan 2004, 4151 Bytes) of package /linux/privat/old/portfwd-0.29.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
1 /*
2 conf.lex
3
4 $Id: conf.lex,v 1.4 2004/01/28 19:14:10 evertonm Exp $
5 */
6
7 %{
8
9 #include <stdio.h>
10 #include <syslog.h>
11
12 /* Incluir antes de "yconf.h" */
13 #include "port_pair.h"
14 #include "net_portion.h"
15 #include "from_addr.hpp"
16 #include "host_map.hpp"
17 #include "proto_map.hpp"
18 #include "entry.hpp"
19 #include "vector.hpp"
20
21 #include "yconf.h"
22 #include "util.h"
23
24 int conf_line_number = 1;
25 int comment_nesting = 0;
26
27 const int IDENT_BUF_SIZE = 64;
28 char conf_ident[IDENT_BUF_SIZE];
29
30 const int CONF_LEX_STR_BUF_SIZE = 1024;
31 char conf_lex_str_buf[CONF_LEX_STR_BUF_SIZE];
32 char *conf_lex_str_end = conf_lex_str_buf + CONF_LEX_STR_BUF_SIZE;
33 char *conf_lex_str_curr;
34
35 static int add_str_char(char c)
36 {
37 if (conf_lex_str_curr < conf_lex_str_buf)
38 return 1; /* underflow */
39
40 if (conf_lex_str_curr >= conf_lex_str_end)
41 return 2; /* overflow */
42
43 *conf_lex_str_curr = c;
44
45 ++conf_lex_str_curr;
46
47 return 0;
48 }
49
50 #define STR_CHAR(c) \
51 { \
52 int result = add_str_char(c); \
53 if (result) { \
54 switch (result) { \
55 case 1: \
56 conf_error("string underflow"); \
57 break; \
58 case 2: \
59 conf_error("string overflow"); \
60 break; \
61 default: \
62 conf_error("unknown string error"); \
63 } \
64 return trap_tk(TK_ILLEGAL); \
65 } \
66 }
67
68 int trap_tk(int tk)
69 {
70 ONVERBOSE(syslog(LOG_DEBUG, "line %4d, token %4d '%s'\n", conf_line_number, tk, yytext));
71 return tk;
72 }
73
74 void show_last_token()
75 {
76 syslog(LOG_ERR, "Last token: '%s' at line: %d\n", yytext, conf_line_number);
77 }
78
79 void conf_error(const char *msg)
80 {
81 syslog(LOG_ERR, "Lexical error: %s\n", msg);
82 show_last_token();
83 }
84
85 %}
86
87 %array
88 %option noyywrap
89 %x Comment
90 %x String
91
92 NAME [a-zA-Z0-9][a-zA-Z0-9_.-]*
93
94 %%
95
96 %{
97 /* Reserved Symbols */
98 %}
99
100 tcp return trap_tk(TK_TCP);
101 udp return trap_tk(TK_UDP);
102 fragile return trap_tk(TK_FRAGILE);
103
104 ":" return trap_tk(TK_COLON);
105 ";" return trap_tk(TK_SCOLON);
106 "," return trap_tk(TK_COMMA);
107 "/" return trap_tk(TK_SLASH);
108 "+" return trap_tk(TK_RANGE);
109 "{" return trap_tk(TK_LBRACE);
110 "}" return trap_tk(TK_RBRACE);
111 "=>" return trap_tk(TK_ARROW);
112
113 ftp-active-mode-on return trap_tk(TK_ACTV);
114 ftp-passive-mode-on return trap_tk(TK_PASV);
115 user return trap_tk(TK_USER);
116 group return trap_tk(TK_GROUP);
117 bind-address {
118 syslog(LOG_ERR, "Found deprecated 'bind-address' token at line %d, please use 'listen-on' instead", conf_line_number);
119 return trap_tk(TK_BIND);
120 }
121 listen-on return trap_tk(TK_LISTEN);
122 source-address return trap_tk(TK_SOURCE);
123
124 %{
125 /* Names and Numbers */
126 %}
127
128 {NAME} {
129 safe_strcpy(conf_ident, yytext, IDENT_BUF_SIZE);
130 return trap_tk(TK_NAME);
131 }
132
133 %{
134 /* Blanks */
135 %}
136
137 [ \r\t] /* Ignore */
138 \n ++conf_line_number;
139
140 %{
141 /* Strings */
142 %}
143
144 "[" {
145 BEGIN(String);
146 conf_lex_str_curr = conf_lex_str_buf;
147 }
148 <String>\n {
149 ++conf_line_number;
150 STR_CHAR(*yytext);
151 }
152 <String>[^\]] STR_CHAR(*yytext);
153 <String>"]" {
154 BEGIN(INITIAL);
155 STR_CHAR('\0');
156 return trap_tk(TK_STRING);
157 }
158 <String><<EOF>> {
159 conf_error("EOF at unterminated string");
160 return trap_tk(TK_ILLEGAL);
161 }
162
163 %{
164 /* Comments */
165 %}
166
167 "/*" ++comment_nesting; BEGIN(Comment);
168 <Comment>"/*" ++comment_nesting;
169 <Comment>"*/" if (!--comment_nesting) BEGIN(INITIAL);
170 <Comment>\n ++conf_line_number;
171 <Comment>. /* Ignore */
172 <Comment><<EOF>> {
173 conf_error("EOF at unterminated comment");
174 return trap_tk(TK_ILLEGAL);
175 }
176
177 %{
178 /* Unknown */
179 %}
180
181 . {
182 conf_error("Unknown token");
183 return trap_tk(TK_ILLEGAL);
184 }
185
186 %%
187
188 /* C code */
189
190 /* eof: conf.lex */