Sync with 5.2.0
[deliverable/titan.core.git] / mctr2 / cli / config_read.l
1 /******************************************************************************
2 * Copyright (c) 2000-2014 Ericsson Telecom AB
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 ******************************************************************************/
8 %option yylineno
9 %option noyywrap
10 %option never-interactive
11 %option nounput
12
13 %{
14
15 #include <string.h>
16 #include <ctype.h>
17 #include <stdlib.h>
18
19 #include <deque>
20 #include <string>
21
22 #include <openssl/crypto.h>
23 #include <openssl/bn.h>
24
25 #include "../../common/cfg_process_utils.hh"
26 #include "../../common/Path2.hh"
27 #include "../../common/config_preproc.h"
28
29 #include "../../common/memory.h"
30 #include "../mctr/config_data.h"
31 #include "../../core/Types.h"
32 #include "config_read.tab.hh"
33
34 //#include "../../common/dbgnew.hh"
35
36 extern string_map_t *config_defines;
37
38 #define yylval config_read_lval
39
40 /* This buffer stores the state of the main buffer
41 while the macro expansion is happening. */
42 static YY_BUFFER_STATE main_buffer = NULL;
43 /* This buffer is active while the expansion of
44 a reference to a structured macro definition is happening.
45 Otherwise its value is NULL. */
46 static YY_BUFFER_STATE expansion_buffer = NULL;
47
48 static void update_buffer();
49 static boolean whether_update_buffer();
50
51 #define RETURN(x) do {update_buffer(); return (x);} while(0)
52
53 void config_read_warning(const char *warning_str, ...);
54 extern void config_read_error(const char *error_str, ...);
55 extern config_data *cfg;
56
57 static std::deque<IncludeElem<YY_BUFFER_STATE> >* include_chain = NULL;
58
59 std::string get_cfg_read_current_file() {
60 if (include_chain && !include_chain->empty()) {
61 return include_chain->back().get_full_path();
62 }
63 return std::string();
64 }
65
66 %}
67
68 WHITESPACE [ \t]
69 WS {WHITESPACE}*
70 NEWLINE \r|\n|\r\n
71 LINECOMMENT ("//"|"#")[^\r\n]*{NEWLINE}
72
73 NUMBER 0|([1-9][0-9]*)
74
75 FLOAT [+-]?({NUMBER}\.[0-9]+)|((({NUMBER}(\.[0-9]+)?)|(\.[0-9]+))[Ee][+-]?{NUMBER})
76
77 BIN 0|1
78 BITSTRING '{BIN}*'B
79 BINMATCH 0|1|\?|\*
80 BITSTRINGMATCH '{BINMATCH}*'B
81 BITSTRING_BAD '[^']*'B
82
83 HEX [0-9A-Fa-f]
84 HEXSTRING '{HEX}*'H
85 HEXMATCH [0-9A-Fa-f\?\*]
86 HEXSTRINGMATCH '{HEXMATCH}*'H
87 HEXSTRING_BAD '[^']*'H
88
89 OCT {HEX}{HEX}
90 OCTETSTRING '{OCT}*'O
91 OCTMATCH {HEX}{HEX}|\?|\*
92 OCTETSTRINGMATCH '{OCTMATCH}*'O
93 OCTETSTRING_BAD '[^']*'O
94
95 BINSTRING_BAD '[^']*'
96
97 TTCN3IDENTIFIER [A-Za-z][A-Za-z0-9_]*
98 ASN1LOWERIDENTIFIER [a-z](-?[A-Za-z0-9]+)*
99
100 MACRORVALUE ([0-9A-Za-z._-]+)|{IPV6}
101 MACRO_CSTR \${TTCN3IDENTIFIER}|\$"{"{WS}{TTCN3IDENTIFIER}{WS}(","{WS}charstring{WS})?"}"
102 MACRO_BOOL \$"{"{WS}{TTCN3IDENTIFIER}{WS}","{WS}boolean{WS}"}"
103 MACRO_FLOAT \$"{"{WS}{TTCN3IDENTIFIER}{WS}","{WS}float{WS}"}"
104 MACRO_ID \$"{"{WS}{TTCN3IDENTIFIER}{WS}","{WS}identifier{WS}"}"
105 MACRO_INT \$"{"{WS}{TTCN3IDENTIFIER}{WS}","{WS}integer{WS}"}"
106 MACRO_BSTR \$"{"{WS}{TTCN3IDENTIFIER}{WS}","{WS}bitstring{WS}"}"
107 MACRO_HSTR \$"{"{WS}{TTCN3IDENTIFIER}{WS}","{WS}hexstring{WS}"}"
108 MACRO_OSTR \$"{"{WS}{TTCN3IDENTIFIER}{WS}","{WS}octetstring{WS}"}"
109 MACRO_BINARY \$"{"{WS}{TTCN3IDENTIFIER}{WS}","{WS}binaryoctet{WS}"}"
110 MACRO_HOSTNAME \$"{"{WS}{TTCN3IDENTIFIER}{WS}","{WS}hostname{WS}"}"
111
112 CHAR [^\\\"]|\\([\\\'\"\?abfnrtv]|{NEWLINE}|[0-7]{1,3}|x{HEX}{1,2})|\"\"
113 CHARSTRING \"{CHAR}*\"
114
115 HOSTNAME [A-Za-z0-9]([A-Za-z0-9_\-]*[A-Za-z0-9])?
116 DNSNAME {HOSTNAME}(\.{HOSTNAME})*\.?
117
118 /* Example: fe80::c002:37ff:fe6c:0%fastethernet0/0 */
119 IPV6 [0-9A-Fa-f:.]+(%[0-9A-Za-z]+)?
120
121
122 %x SC_blockcomment SC_DEFINE SC_CSTRING SC_ORDERED_INCLUDE
123 %s SC_MODULE_PARAMETERS SC_LOGGING SC_TESTPORT_PARAMETERS SC_EXECUTE SC_GROUPS
124 %s SC_COMPONENTS SC_EXTERNAL_COMMANDS SC_MAIN_CONTROLLER SC_INCLUDE SC_PROFILER
125
126 %%
127 int comment_caller = INITIAL;
128
129 std::string cstring;
130
131 /* Eat up comments and whitespaces */
132
133 "/*" {
134 comment_caller = YY_START;
135 BEGIN(SC_blockcomment);
136 }
137 <SC_blockcomment>
138 {
139 "*/" BEGIN(comment_caller);
140 .|\n
141 }
142
143 {LINECOMMENT}|{WHITESPACE}|{NEWLINE}
144
145 /* Section delimiters */
146
147 <*>"["{WS}MODULE_PARAMETERS{WS}"]" {
148 if (YY_START!=SC_blockcomment) {
149 BEGIN(SC_MODULE_PARAMETERS);
150 RETURN(ModuleParametersKeyword);
151 }
152 }
153
154 <*>"["{WS}LOGGING{WS}"]" {
155 if (YY_START!=SC_blockcomment) {
156 BEGIN(SC_LOGGING);
157 RETURN(LoggingKeyword);
158 }
159 }
160
161 <*>"["{WS}PROFILER{WS}"]" {
162 if (YY_START!=SC_blockcomment) {
163 BEGIN(SC_PROFILER);
164 RETURN(ProfilerKeyword);
165 }
166 }
167
168 <*>"["{WS}TESTPORT_PARAMETERS{WS}"]" {
169 if (YY_START!=SC_blockcomment) {
170 BEGIN(SC_TESTPORT_PARAMETERS);
171 RETURN(TestportParametersKeyword);
172 }
173 }
174
175 <*>"["{WS}EXECUTE{WS}"]" {
176 if (YY_START!=SC_blockcomment) {
177 BEGIN(SC_EXECUTE);
178 RETURN(ExecuteKeyword);
179 }
180 }
181
182 <*>"["{WS}EXTERNAL_COMMANDS{WS}"]" {
183 if (YY_START!=SC_blockcomment) {
184 BEGIN(SC_EXTERNAL_COMMANDS);
185 RETURN(ExternalCommandsKeyword);
186 }
187 }
188
189 <*>"["{WS}GROUPS{WS}"]" {
190 if (YY_START!=SC_blockcomment) {
191 BEGIN(SC_GROUPS);
192 RETURN(GroupsKeyword);
193 }
194 }
195
196 <*>"["{WS}COMPONENTS{WS}"]" {
197 if (YY_START!=SC_blockcomment) {
198 BEGIN(SC_COMPONENTS);
199 RETURN(ComponentsKeyword);
200 }
201 }
202
203 <*>"["{WS}MAIN_CONTROLLER{WS}"]" {
204 if (YY_START!=SC_blockcomment) {
205 BEGIN(SC_MAIN_CONTROLLER);
206 RETURN(MainControllerKeyword);
207 }
208 }
209
210 <*>"["{WS}INCLUDE{WS}"]" {
211 if (YY_START!=SC_blockcomment) {
212 BEGIN(SC_INCLUDE);
213 RETURN(IncludeKeyword);
214 }
215 }
216
217 <*>"["{WS}ORDERED_INCLUDE{WS}"]" {
218 if (YY_START!=SC_blockcomment) {
219 BEGIN(SC_ORDERED_INCLUDE);
220 }
221 }
222
223
224 <*>"["{WS}DEFINE{WS}"]" {
225 if (YY_START!=SC_blockcomment) {
226 BEGIN(SC_DEFINE);
227 RETURN(DefineKeyword);
228 }
229 }
230
231 /* Rules for SC_DEFINE must precede everything else */
232
233 <SC_DEFINE>{
234
235 "/*" {
236 comment_caller = SC_DEFINE;
237 BEGIN(SC_blockcomment);
238 }
239
240 {CHARSTRING} /* eats string */
241
242 {LINECOMMENT}
243
244 {NEWLINE} /* this is not in . */
245
246 \\\"
247
248 . /* eats unnecessary things */
249
250 }
251
252 <SC_ORDERED_INCLUDE>{
253
254 "/*" {
255 comment_caller = YY_START;
256 BEGIN(SC_blockcomment);
257 }
258
259 \" { BEGIN(SC_CSTRING); }
260
261 {LINECOMMENT}
262
263 {NEWLINE} /* this is not in . */
264
265 \\\"
266
267 . /* eat unnecessary chars */
268
269 }
270
271
272 <SC_CSTRING>{
273
274 \"\" cstring += '"';
275
276 \" {
277 std::string error_msg = switch_lexer(include_chain, cstring,
278 YY_CURRENT_BUFFER, yy_create_buffer, yy_switch_to_buffer, yylineno,
279 YY_BUF_SIZE);
280 if (error_msg.empty()) {
281 BEGIN(INITIAL);
282 } else {
283 config_read_error(error_msg.c_str());
284 }
285
286 cstring.clear();
287 } /* end of string */
288
289 \\[\\'"?] cstring += yytext[1]; /* backslash-quoted \ or " or ' or ? */
290 \\{NEWLINE} yylineno++;
291 \\a cstring += '\a';
292 \\b cstring += '\b';
293 \\f cstring += '\f';
294 \\n cstring += '\n';
295 \\r cstring += '\r';
296 \\t cstring += '\t';
297 \\v cstring += '\v';
298
299 \\[0-7]{1,3} {
300 unsigned int c;
301 sscanf(yytext + 1, "%o", &c);
302 if (c <= 255) cstring += c;
303 else config_read_error("Invalid octal character code in string literal");
304 }
305
306 \\x{HEX}{1,2} {
307 unsigned int c;
308 sscanf(yytext + 2, "%x", &c);
309 cstring += c;
310 }
311
312 \\(x[^\\\"]|.) config_read_error("Invalid excape sequence in string literal.");
313
314 {NEWLINE} {
315 cstring.append(yytext, yyleng);
316 yylineno++;
317 }
318
319 . {
320 cstring += yytext[0];
321 }
322 }
323 /* SC_cstring */
324
325
326 /* Values */
327
328 {NUMBER} {
329 yylval.int_val = NULL;
330 BN_dec2bn(&yylval.int_val, *yytext == '+' ? yytext + 1 : yytext);
331 RETURN(Number);
332 }
333
334 {FLOAT} {
335 yylval.float_val = atof(yytext);
336 RETURN(Float);
337 }
338
339 {BITSTRING} RETURN(Bstring);
340
341 {BITSTRINGMATCH} RETURN(BstringMatch);
342
343 {BITSTRING_BAD} {
344 config_read_error("Invalid bitstring value.");
345 RETURN(Bstring);
346 }
347
348 {HEXSTRING} RETURN(Hstring);
349
350 {HEXSTRINGMATCH} RETURN(HstringMatch);
351
352 {HEXSTRING_BAD} {
353 config_read_error("Invalid hexstring value.");
354 RETURN(Hstring);
355 }
356
357 {OCTETSTRING} RETURN(Ostring);
358
359 {OCTETSTRINGMATCH} RETURN(OstringMatch);
360
361 {OCTETSTRING_BAD} {
362 config_read_error("Invalid octetstring value.");
363 RETURN(Ostring);
364 }
365
366 {BINSTRING_BAD} config_read_error("Invalid string value.");
367
368 ' config_read_error("Unmatched ' character.");
369
370 {CHARSTRING} {
371 yylval.str_val = mcopystrn(yytext, yyleng);
372 RETURN(Cstring);
373 }
374
375 /* Section-wide keywords */
376
377 <SC_MODULE_PARAMETERS>
378 {
379 NULL RETURN(NULLKeyword);
380 null RETURN(nullKeyword);
381 char RETURN(CharKeyword);
382 objid RETURN(ObjIdKeyword);
383 omit RETURN(OmitKeyword);
384 none |
385 pass |
386 inconc |
387 fail |
388 error RETURN(VerdictValue);
389 complement RETURN(ComplementKeyword);
390 "\.\." RETURN(DotDot);
391 superset RETURN(SupersetKeyword);
392 subset RETURN(SubsetKeyword);
393 pattern RETURN(PatternKeyword);
394 permutation RETURN(PermutationKeyword);
395 length RETURN(LengthKeyword);
396 ifpresent RETURN(IfpresentKeyword);
397 infinity RETURN(InfinityKeyword);
398 }
399
400 <SC_MODULE_PARAMETERS,SC_LOGGING,SC_PROFILER>
401 {
402 true |
403 false RETURN(BooleanValue);
404 }
405
406 <SC_MODULE_PARAMETERS,SC_LOGGING,SC_TESTPORT_PARAMETERS>
407 {
408 mtc RETURN(MTCKeyword);
409 system RETURN(SystemKeyword);
410 }
411
412 <SC_LOGGING>
413 {
414 [Ff]ile[Nn]ame |
415 [Ll]og[Ff]ile RETURN(LogFile);
416
417 [Ee]mergency[Ll]ogging RETURN(EmergencyLogging);
418
419 [Ee]mergency[Ll]ogging[Bb]ehaviour RETURN(EmergencyLoggingBehaviour);
420
421 [Bb]uffer[Aa]ll |
422 [Bb]uffer[Ma]asked RETURN(EmergencyLoggingBehaviourValue);
423
424 [Ee]mergency[Ll]ogging[Mm]ask RETURN(EmergencyLoggingMask);
425
426
427 [Ff]ile[Mm]ask RETURN(FileMask);
428
429 [Cc]onsole[Mm]ask RETURN(ConsoleMask);
430
431 [Tt]ime[Ss]tamp[Ff]ormat RETURN(TimestampFormat);
432 [Cc]onsole[Tt]ime[Ss]tamp[Ff]ormat RETURN(ConsoleTimestampFormat);
433
434 [Ll]og[Ss]ource[Ii]nfo |
435 [Ss]ource[Ii]nfo[Ff]ormat RETURN(SourceInfoFormat);
436
437 [Aa]ppend[Ff]ile RETURN(AppendFile);
438
439 [Ll]og[Ee]vent[Tt]ypes RETURN(LogEventTypes);
440
441 [Ll]og[Ee]ntity[Nn]ame RETURN(LogEntityName);
442
443 [Ll]og[Ff]ile[Ss]ize RETURN(LogFileSize);
444
445 [Ll]og[Ff]ile[Nn]umber RETURN(LogFileNumber);
446
447 [Dd]isk[Ff]ull[Aa]ction RETURN(DiskFullAction);
448
449 [Mm]atching[Hh]ints RETURN(MatchingHints);
450
451 [Ll]ogger[Pp]lugins RETURN(LoggerPlugins);
452
453 LOG_NOTHING RETURN(LoggingBit);
454
455 (TTCN_)?ACTION |
456 (TTCN_)?DEBUG |
457 (TTCN_)?DEFAULTOP |
458 (TTCN_)?ERROR |
459 (TTCN_)?EXECUTOR |
460 (TTCN_)?FUNCTION |
461 (TTCN_)?MATCHING |
462 (TTCN_)?PARALLEL |
463 (TTCN_)?PORTEVENT |
464 (TTCN_)?STATISTICS |
465 (TTCN_)?TESTCASE |
466 (TTCN_)?TIMEROP |
467 (TTCN_)?USER |
468 (TTCN_)?VERDICTOP |
469 (TTCN_)?WARNING |
470 LOG_ALL RETURN(LoggingBitCollection);
471
472 ACTION_UNQUALIFIED |
473 DEBUG_ENCDEC |
474 DEBUG_TESTPORT |
475 DEBUG_UNQUALIFIED |
476 DEFAULTOP_ACTIVATE |
477 DEFAULTOP_DEACTIVATE |
478 DEFAULTOP_EXIT |
479 DEFAULTOP_UNQUALIFIED |
480 ERROR_UNQUALIFIED |
481 EXECUTOR_COMPONENT |
482 EXECUTOR_CONFIGDATA |
483 EXECUTOR_EXTCOMMAND |
484 EXECUTOR_LOGOPTIONS |
485 EXECUTOR_RUNTIME |
486 EXECUTOR_UNQUALIFIED |
487 FUNCTION_RND |
488 FUNCTION_UNQUALIFIED |
489 MATCHING_DONE |
490 MATCHING_MCSUCCESS |
491 MATCHING_MCUNSUCC |
492 MATCHING_MMSUCCESS |
493 MATCHING_MMUNSUCC |
494 MATCHING_PCSUCCESS |
495 MATCHING_PCUNSUCC |
496 MATCHING_PMSUCCESS |
497 MATCHING_PMUNSUCC |
498 MATCHING_PROBLEM |
499 MATCHING_TIMEOUT |
500 MATCHING_UNQUALIFIED |
501 PARALLEL_PORTCONN |
502 PARALLEL_PORTMAP |
503 PARALLEL_PTC |
504 PARALLEL_UNQUALIFIED |
505 PORTEVENT_DUALRECV |
506 PORTEVENT_DUALSEND |
507 PORTEVENT_MCRECV |
508 PORTEVENT_MCSEND |
509 PORTEVENT_MMRECV |
510 PORTEVENT_MMSEND |
511 PORTEVENT_MQUEUE |
512 PORTEVENT_PCIN |
513 PORTEVENT_PCOUT |
514 PORTEVENT_PMIN |
515 PORTEVENT_PMOUT |
516 PORTEVENT_PQUEUE |
517 PORTEVENT_STATE |
518 PORTEVENT_UNQUALIFIED |
519 STATISTICS_UNQUALIFIED |
520 STATISTICS_VERDICT |
521 TESTCASE_FINISH |
522 TESTCASE_START |
523 TESTCASE_UNQUALIFIED |
524 TIMEROP_GUARD |
525 TIMEROP_READ |
526 TIMEROP_START |
527 TIMEROP_STOP |
528 TIMEROP_TIMEOUT |
529 TIMEROP_UNQUALIFIED |
530 USER_UNQUALIFIED |
531 VERDICTOP_FINAL |
532 VERDICTOP_GETVERDICT |
533 VERDICTOP_SETVERDICT |
534 VERDICTOP_UNQUALIFIED |
535 WARNING_UNQUALIFIED RETURN(LoggingBit);
536
537 [Tt][Ii][Mm][Ee] {yylval.ts_val=TSF_TIME; RETURN(TimestampValue);}
538 [Dd][Aa][Tt][Ee][Tt][Ii][Mm][Ee] {yylval.ts_val=TSF_DATE_TIME; RETURN(TimestampValue);}
539 [Ss][Ee][Cc][Oo][Nn][Dd][Ss] {yylval.ts_val=TSF_SEC; RETURN(TimestampValue);}
540
541 [Nn][Oo][Nn][Ee] |
542 [Ss][Ii][Nn][Gg][Ll][Ee] |
543 [Ss][Tt][Aa][Cc][Kk] RETURN(SourceInfoValue);
544
545 [Yy][Ee][Ss] |
546 [Nn][Oo] RETURN(YesNo);
547
548 [Dd]etailed RETURN(Detailed);
549 [Cc]ompact RETURN(Compact);
550 [Ss]ub[Cc]ategories RETURN(SubCategories);
551
552 [Ee]rror RETURN(Error);
553
554 [Ss]top RETURN(Stop);
555
556 [Rr]etry RETURN(Re_try);
557
558 [Dd]elete RETURN(Delete);
559 }
560
561 <SC_PROFILER>
562 {
563 [Dd]isable[Pp]rofiler return DisableProfilerKeyword;
564 [Dd]isable[Cc]overage return DisableCoverageKeyword;
565 [Dd]ata[Bb]ase[Ff]ile return DatabaseFileKeyword;
566 [Aa]ggregate[Dd]ata return AggregateDataKeyword;
567 [Ss]tatistics[Ff]ile return StatisticsFileKeyword;
568 [Dd]isable[Ss]tatistics return DisableStatisticsKeyword;
569 }
570
571 <SC_EXECUTE>control RETURN(ControlKeyword);
572
573 <SC_EXTERNAL_COMMANDS>
574 {
575 [Bb]egin[Cc]ontrol[Pp]art RETURN(BeginControlPart);
576 [Ee]nd[Cc]ontrol[Pp]art RETURN(EndControlPart);
577 [Bb]egin[Tt]est[Cc]ase RETURN(BeginTestCase);
578 [Ee]nd[Tt]est[Cc]ase RETURN(EndTestCase);
579 }
580
581 <SC_MAIN_CONTROLLER>
582 {
583 [Ll]ocal[Aa]ddress RETURN(LocalAddress);
584 [Tt][Cc][Pp][Pp]ort RETURN(TCPPort);
585 [Kk]ill[Tt]imer RETURN(KillTimer);
586 [Nn]um[Hh][Cc]s RETURN(NumHCs);
587 [Uu]nix[Ss]ockets[Ee]nabled RETURN(UnixSocketEnabled);
588 [Yy][Ee][Ss] RETURN(YesToken);
589 [Nn][Oo] RETURN(NoToken);
590 }
591
592 {TTCN3IDENTIFIER} {
593 switch (YY_START) {
594 case SC_GROUPS:
595 case SC_COMPONENTS:
596 case SC_EXECUTE:
597 case SC_MAIN_CONTROLLER:
598 yylval.str_val = (char*)Malloc(yyleng + 1);
599 memcpy(yylval.str_val, yytext, yyleng + 1);
600 break;
601 default:
602 yylval.str_val = NULL;
603 }
604 RETURN(Identifier);
605 }
606
607 <SC_MODULE_PARAMETERS>{ASN1LOWERIDENTIFIER} {
608 char *ttcn3_id = (char*)Malloc(yyleng + 1);
609 for (int i = 0; i < yyleng; i++) {
610 if (yytext[i] == '-') ttcn3_id[i] = '_';
611 else ttcn3_id[i] = yytext[i];
612 }
613 ttcn3_id[yyleng] = '\0';
614 config_read_warning("`%s' is not a valid TTCN-3 identifier. Did you mean "
615 "`%s'?", yytext, ttcn3_id);
616 cfg->config_read_buffer = mputprintf(cfg->config_read_buffer, "%s ", ttcn3_id);
617 Free(ttcn3_id);
618 return ASN1LowerIdentifier;
619 }
620
621 <SC_GROUPS,SC_COMPONENTS,SC_MAIN_CONTROLLER>{DNSNAME}|{IPV6} {
622 yylval.str_val = (char*)Malloc(yyleng + 1);
623 for (int i = 0; i < yyleng; i++) yylval.str_val[i] = tolower(yytext[i]);
624 yylval.str_val[yyleng] = '\0';
625 RETURN(DNSName);
626 }
627
628 {MACRO_BOOL} {
629 char *macroname = get_macro_id_from_ref(yytext);
630 size_t macrolen;
631 const char *macrovalue =
632 string_map_get_bykey(config_defines, macroname, &macrolen);
633 boolean bool_val;
634 if (macrovalue != NULL) {
635 if (!strcmp(macrovalue, "true")) bool_val = TRUE;
636 else if (!strcmp(macrovalue, "false")) bool_val = FALSE;
637 else {
638 config_read_error("Macro `%s' cannot be interpreted as boolean value: "
639 "`%s'", macroname, macrovalue);
640 bool_val = FALSE;
641 }
642 } else {
643 config_read_error("No macro or environmental variable defined with name "
644 "`%s'", macroname);
645 bool_val = FALSE;
646 }
647 Free(macroname);
648 if (whether_update_buffer()) cfg->config_read_buffer =
649 mputprintf(cfg->config_read_buffer, "%s ", bool_val ? "true" : "false");
650 return BooleanValue;
651 }
652
653 {MACRO_INT} {
654 char *macroname = get_macro_id_from_ref(yytext);
655 size_t macrolen = 0;
656 BIGNUM *BN_0 = BN_new();
657 BN_set_word(BN_0, 0);
658 const char *macrovalue =
659 string_map_get_bykey(config_defines, macroname, &macrolen);
660 if (macrovalue != NULL) {
661 if (string_is_int(macrovalue, macrolen)) {
662 yylval.int_val = NULL;
663 BN_dec2bn(&yylval.int_val,
664 *macrovalue == '+' ? macrovalue + 1 : macrovalue);
665 } else {
666 config_read_error("Macro `%s' cannot be interpreted as integer value: "
667 "`%s'", macroname, macrovalue);
668 yylval.int_val = BN_dup(BN_0);
669 }
670 } else {
671 config_read_error("No macro or environmental variable defined with name "
672 "`%s'", macroname);
673 yylval.int_val = BN_dup(BN_0);
674 }
675 BN_free(BN_0);
676 Free(macroname);
677 char *int_val_str = BN_bn2dec(yylval.int_val);
678 if (whether_update_buffer())
679 cfg->config_read_buffer = mputprintf(cfg->config_read_buffer, "%s ", int_val_str);
680 OPENSSL_free(int_val_str);
681 return Number;
682 }
683
684 {MACRO_FLOAT} {
685 char *macroname = get_macro_id_from_ref(yytext);
686 size_t macrolen;
687 const char *macrovalue =
688 string_map_get_bykey(config_defines, macroname, &macrolen);
689 if (macrovalue != NULL) {
690 if (string_is_float(macrovalue, macrolen))
691 yylval.float_val = atof(macrovalue);
692 else {
693 config_read_error("Macro `%s' cannot be interpreted as float value: "
694 "`%s'", macroname, macrovalue);
695 yylval.float_val = 0.0;
696 }
697 } else {
698 config_read_error("No macro or environmental variable defined"
699 " with name `%s'", macroname);
700 yylval.float_val = 0.0;
701 }
702 Free(macroname);
703 if (whether_update_buffer()) cfg->config_read_buffer =
704 mputprintf(cfg->config_read_buffer, "%f ", yylval.float_val);
705 return Float;
706 }
707
708 {MACRO_ID} {
709 char *macroname = get_macro_id_from_ref(yytext);
710 size_t macrolen;
711 const char *macrovalue =
712 string_map_get_bykey(config_defines, macroname, &macrolen);
713 boolean is_asn = FALSE;
714 if (macrovalue != NULL) {
715 if (string_is_id(macrovalue, macrolen)) {
716 yylval.str_val = mcopystr(macrovalue);
717 for (size_t i = 0; i < macrolen; i++) {
718 if (yylval.str_val[i] == '-') {
719 is_asn = TRUE;
720 yylval.str_val[i] = '_';
721 }
722 }
723 if (is_asn) config_read_warning("`%s' is not a valid TTCN-3 identifier. "
724 "Did you mean `%s'?", macrovalue, yylval.str_val);
725 if (whether_update_buffer()) cfg->config_read_buffer =
726 mputprintf(cfg->config_read_buffer, "%s ", yylval.str_val);
727 } else {
728 config_read_error("Macro `%s' cannot be interpreted as identifier: `%s'",
729 macroname, macrovalue);
730 yylval.str_val = NULL;
731 }
732 } else {
733 config_read_error("No macro or environmental variable defined with name "
734 "`%s'", macroname);
735 yylval.str_val = NULL;
736 }
737 Free(macroname);
738 return Identifier;
739 }
740
741 {MACRO_CSTR} {
742 char *macroname;
743 if (yytext[1] == '{') macroname = get_macro_id_from_ref(yytext);
744 else macroname = mcopystr(yytext + 1);
745 size_t macrolen;
746 const char *macrovalue = string_map_get_bykey
747 (config_defines, macroname, &macrolen);
748 if (macrovalue == NULL) {
749 config_read_error("No macro or environmental variable defined with "
750 "name `%s'", macroname);
751 yylval.str_val = memptystr();
752 Free(macroname);
753 return Cstring;
754 }
755
756 if (macrolen > 0 && macrovalue[0] == '{') { // structured
757 main_buffer = YY_CURRENT_BUFFER;
758 expansion_buffer = yy_scan_string(macrovalue);
759 yy_switch_to_buffer(expansion_buffer);
760 Free(macroname);
761 } else {
762 if (whether_update_buffer()) {
763 cfg->config_read_buffer=mputc(cfg->config_read_buffer, '"');
764 for (size_t i = 0; i < macrolen; i++) {
765 switch (macrovalue[i]) {
766 case '"':
767 cfg->config_read_buffer = mputstr(cfg->config_read_buffer, "\\\"");
768 break;
769 case '\\':
770 cfg->config_read_buffer = mputstr(cfg->config_read_buffer, "\\\\");
771 break;
772 case '\0':
773 cfg->config_read_buffer = mputstr(cfg->config_read_buffer, "\\000");
774 break;
775 default:
776 cfg->config_read_buffer = mputc(cfg->config_read_buffer, macrovalue[i]);
777 } /* switch */
778 } /* for */
779 cfg->config_read_buffer=mputstr(cfg->config_read_buffer, "\" ");
780 }
781 Free(macroname);
782 yylval.str_val = mcopystr(macrovalue);
783 return Cstring;
784 }
785 }
786
787 {MACRO_BSTR} {
788 char *macroname = get_macro_id_from_ref(yytext);
789 size_t macrolen;
790 const char *macrovalue =
791 string_map_get_bykey(config_defines, macroname, &macrolen);
792 if (macrovalue != NULL) {
793 if (string_is_bstr(macrovalue, macrolen)) {
794 if (whether_update_buffer()) cfg->config_read_buffer =
795 mputprintf(cfg->config_read_buffer, "'%s'B ", macrovalue);
796 } else config_read_error("Macro `%s' cannot be interpreted as bitstring "
797 "value: `%s'", macroname, macrovalue);
798 } else config_read_error("No macro or environmental variable defined with "
799 "name `%s'", macroname);
800 Free(macroname);
801 return Bstring;
802 }
803
804 {MACRO_HSTR} {
805 char *macroname = get_macro_id_from_ref(yytext);
806 size_t macrolen;
807 const char *macrovalue =
808 string_map_get_bykey(config_defines, macroname, &macrolen);
809 if (macrovalue != NULL) {
810 if (string_is_hstr(macrovalue, macrolen)) {
811 if (whether_update_buffer()) cfg->config_read_buffer =
812 mputprintf(cfg->config_read_buffer, "'%s'H ", macrovalue);
813 } else config_read_error("Macro `%s' cannot be interpreted as hexstring "
814 "value: `%s'", macroname, macrovalue);
815 } else config_read_error("No macro or environmental variable defined with "
816 "name `%s'", macroname);
817 Free(macroname);
818 return Hstring;
819 }
820
821 {MACRO_OSTR} {
822 char *macroname = get_macro_id_from_ref(yytext);
823 size_t macrolen;
824 const char *macrovalue =
825 string_map_get_bykey(config_defines, macroname, &macrolen);
826 if (macrovalue != NULL) {
827 if (string_is_ostr(macrovalue, macrolen)) {
828 if (whether_update_buffer()) cfg->config_read_buffer =
829 mputprintf(cfg->config_read_buffer, "'%s'O ", macrovalue);
830 } else config_read_error("Macro `%s' cannot be interpreted as octetstring "
831 "value: `%s'", macroname, macrovalue);
832 } else config_read_error("No macro or environmental variable defined with "
833 "name `%s'", macroname);
834 Free(macroname);
835 return Ostring;
836 }
837
838 {MACRO_BINARY} {
839 char *macroname = get_macro_id_from_ref(yytext);
840 size_t macrolen;
841 const char *macrovalue =
842 string_map_get_bykey(config_defines, macroname, &macrolen);
843 if (macrovalue != NULL) {
844 if (whether_update_buffer()) {
845 cfg->config_read_buffer = mputc(cfg->config_read_buffer, '\'');
846 for (size_t i = 0; i < macrolen; i++) {
847 cfg->config_read_buffer = mputprintf(cfg->config_read_buffer, "%02X",
848 macrovalue[i]);
849 }
850 cfg->config_read_buffer = mputstr(cfg->config_read_buffer, "'O ");
851 }
852 } else config_read_error("No macro or environmental variable defined with "
853 "name `%s'", macroname);
854 Free(macroname);
855 return Ostring;
856 }
857
858 {MACRO_HOSTNAME} {
859 char *macroname = get_macro_id_from_ref(yytext);
860 size_t macrolen;
861 const char *macrovalue =
862 string_map_get_bykey(config_defines, macroname, &macrolen);
863 if (macrovalue != NULL) {
864 if (string_is_hostname(macrovalue, macrolen)) {
865 if (whether_update_buffer()) {
866 for (size_t i = 0; i < macrolen; i++) {
867 cfg->config_read_buffer =
868 mputc(cfg->config_read_buffer, tolower(macrovalue[i]));
869 }
870 yylval.str_val = NULL;
871 } else {
872 yylval.str_val = (char*)Malloc(macrolen + 1);
873 for (size_t i = 0; i < macrolen; i++)
874 yylval.str_val[i] = tolower(macrovalue[i]);
875 yylval.str_val[macrolen] = '\0';
876 }
877 } else {
878 config_read_error("Macro `%s' cannot be interpreted as host name: "
879 "`%s'", macroname, macrovalue);
880 yylval.str_val = NULL;
881 }
882 } else {
883 config_read_error("No macro or environmental variable defined with "
884 "name `%s'", macroname);
885 yylval.str_val = NULL;
886 }
887 Free(macroname);
888 return DNSName;
889 }
890
891 ":="|"=" RETURN(AssignmentChar);
892 "&=" RETURN(ConcatChar);
893
894 . RETURN(yytext[0]);
895
896 <*><<EOF>> {
897 if (expansion_buffer) {
898 yy_switch_to_buffer(main_buffer);
899 yy_delete_buffer(expansion_buffer);
900 expansion_buffer = NULL;
901 } else {
902 if (YY_START == SC_blockcomment) {
903 config_read_error("Unterminated block "
904 "comment (missing */ at the end of file).");
905 return EOF;
906 } else {
907 if (include_chain->size() > 1) {
908 yy_delete_buffer(YY_CURRENT_BUFFER);
909 fclose(include_chain->back().fp);
910 include_chain->pop_back();
911 yy_switch_to_buffer(include_chain->back().buffer_state);
912 yylineno = include_chain->back().line_number;
913 BEGIN(SC_ORDERED_INCLUDE);
914 } else {
915 return EOF;
916 }
917 }
918 }
919 }
920
921 %%
922
923 static void update_buffer()
924 {
925 if (whether_update_buffer()) {
926 cfg->config_read_buffer = mputstr(cfg->config_read_buffer, yytext);
927 cfg->config_read_buffer = mputc (cfg->config_read_buffer, ' ');
928 }
929 }
930
931 static boolean whether_update_buffer()
932 {
933 switch (YY_START) {
934 case SC_MODULE_PARAMETERS:
935 case SC_LOGGING:
936 case SC_TESTPORT_PARAMETERS:
937 case SC_EXTERNAL_COMMANDS:
938 return TRUE;
939 default:
940 return FALSE;
941 } /* switch */
942 }
943
944 void config_read_reset(const char* current_filename_) {
945 if (!include_chain) {
946 include_chain = new std::deque<IncludeElem<YY_BUFFER_STATE> >();
947 }
948
949 include_chain->clear();
950 include_chain->push_back(
951 IncludeElem<YY_BUFFER_STATE>(std::string(current_filename_), config_read_in));
952 }
953
954 void config_read_close() {
955 delete include_chain;
956 include_chain = NULL;
957 }
958
This page took 0.070255 seconds and 5 git commands to generate.