5 #include "nel/misc/debug.h"
\r
6 #include "nel/misc/file.h"
\r
7 #include "nel/misc/mem_stream.h"
\r
13 using namespace std;
\r
14 using namespace NLMISC;
\r
18 // WARNING!!!! DEBUG_PRINTF are commented using // so IT MUST HAVE NO INSTRUCTION AFTER A DEBUG_PRINTF OR THEY LL BE COMMENTED
\r
20 //#define DEBUG_PRINTF InfoLog->displayRaw
\r
22 #define DEBUG_PRINTF(format, args...)
\r
24 #define DEBUG_PRINTF // InfoLog->displayRaw
\r
27 #define YY_NEVER_INTERACTIVE 1
\r
30 #define YY_NO_UNISTD_H 1
\r
33 #define isatty _isatty
\r
38 enum cf_type { T_UNKNOWN, T_INT, T_STRING, T_REAL };
\r
47 // use to parse the file, opened by CConfigFile::reparse()
\r
48 CMemStream cf_ifile;
\r
50 #define YY_INPUT(buf,result,max_size) { \
\r
51 if (cf_ifile.length() == 0) \
\r
53 DEBUG_PRINTF("YY_INPUT: eof");\
\r
56 uint32 nbc = std::min((uint32)max_size, (uint32)(cf_ifile.length() - cf_ifile.getPos())); \
\r
57 DEBUG_PRINTF("YY_INPUT: wanted %d bytes, will read %d\n", max_size, nbc);\
\r
58 cf_ifile.serialBuffer ((uint8 *)buf, nbc); \
\r
63 /* special include, need to know cf_value */
\r
65 #include "cf_gramatical.h"
\r
69 extern int cf_CurrentLine;
\r
79 %option nounput prefix="cf"
\r
85 variable ({alpha}|[_])({alpha}|{digit}|[_])*
\r
86 num1 {digit}+\.([eE][-+]?{digit}+)?
\r
87 num2 {digit}*\.{digit}+([eE][-+]?{digit}+)?
\r
95 "+" { if (!cf_Ignore) return PLUS; }
\r
96 "-" { if (!cf_Ignore) return MINUS; }
\r
97 "*" { if (!cf_Ignore) return MULT; }
\r
98 "/" { if (!cf_Ignore) return DIVIDE; }
\r
99 ")" { if (!cf_Ignore) return RPAREN; }
\r
100 "(" { if (!cf_Ignore) return LPAREN; }
\r
101 "=" { if (!cf_Ignore) return ASSIGN; }
\r
102 "+=" { if (!cf_Ignore) return ADD_ASSIGN; }
\r
103 ";" { if (!cf_Ignore) return SEMICOLON; }
\r
104 "}" { if (!cf_Ignore) return RBRACE; }
\r
105 "{" { if (!cf_Ignore) return LBRACE; }
\r
106 "," { if (!cf_Ignore) return COMMA; }
\r
107 "#fileline" { if (!cf_Ignore) return FILELINE; }
\r
110 (\ |\t) { /* ignore tabulation and spaces */; }
\r
113 /* ignore new line but count them */
\r
115 DEBUG_PRINTF("*****line++ %d\n", cf_CurrentLine);
\r
118 "//" { comment(); }
\r
120 \/\* { /* Start of a comment */ cf_Ignore = true; }
\r
122 \*\/ { /* End of a comment */ cf_Ignore = false; }
\r
124 {string} { /* A string */
\r
127 cflval.Val.Type = T_STRING;
\r
128 if (strlen(yytext+1) >= sizeof(cflval.Val.String))
\r
130 strcpy (cflval.Val.String, "");
\r
131 DEBUG_PRINTF("lex: string '%s' exceeds max length\n", yytext);
\r
134 strcpy (cflval.Val.String, yytext+1);
\r
135 cflval.Val.String[strlen(cflval.Val.String)-1] = '\0';
\r
136 DEBUG_PRINTF("lex: string '%s' '%s'\n", yytext, cflval.Val.String);
\r
141 {variable} { /* A variable */
\r
144 cflval.Val.Type = T_STRING;
\r
145 if (strlen(yytext+1) >= sizeof(cflval.Val.String))
\r
147 strcpy (cflval.Val.String, "");
\r
148 DEBUG_PRINTF("lex: string '%s' exceeds max length\n", yytext);
\r
151 strcpy (cflval.Val.String, yytext);
\r
152 DEBUG_PRINTF("lex: variable '%s' '%s'\n", yytext, cflval.Val.String);
\r
157 {real} { /* A real */
\r
160 cflval.Val.Type = T_REAL;
\r
161 cflval.Val.Real = atof (yytext);
\r
162 DEBUG_PRINTF("lex: real '%s' '%f\n", yytext, cflval.Val.Real);
\r
167 {int} { /* An int */
\r
170 cflval.Val.Type = T_INT;
\r
171 cflval.Val.Int = atoi (yytext);
\r
172 DEBUG_PRINTF("lex: int '%s' '%d'\n", yytext, cflval.Val.Int);
\r
177 {hex} { /* An hex int */
\r
180 cflval.Val.Type = T_INT;
\r
181 sscanf (yytext, "%x", &(cflval.Val.Int));
\r
182 DEBUG_PRINTF("lex: hexa '%s' '0x%x' '%d'\n", yytext, cflval.Val.Int, cflval.Val.Int);
\r
194 //"//".*\n { /* ignore one line comment but count the new line */ cf_CurrentLine++; DEBUG_PRINTF("*****line++ %d\n", cf_CurrentLine); }
\r
203 while (c != '\n' && c != -1);
\r