7d59c229b2d973bc42ed9da2158abe3e441d2074
[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
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}TESTPORT_PARAMETERS{WS}"]" {
162 if (YY_START!=SC_blockcomment) {
163 BEGIN(SC_TESTPORT_PARAMETERS);
164 RETURN(TestportParametersKeyword);
165 }
166 }
167
168 <*>"["{WS}EXECUTE{WS}"]" {
169 if (YY_START!=SC_blockcomment) {
170 BEGIN(SC_EXECUTE);
171 RETURN(ExecuteKeyword);
172 }
173 }
174
175 <*>"["{WS}EXTERNAL_COMMANDS{WS}"]" {
176 if (YY_START!=SC_blockcomment) {
177 BEGIN(SC_EXTERNAL_COMMANDS);
178 RETURN(ExternalCommandsKeyword);
179 }
180 }
181
182 <*>"["{WS}GROUPS{WS}"]" {
183 if (YY_START!=SC_blockcomment) {
184 BEGIN(SC_GROUPS);
185 RETURN(GroupsKeyword);
186 }
187 }
188
189 <*>"["{WS}COMPONENTS{WS}"]" {
190 if (YY_START!=SC_blockcomment) {
191 BEGIN(SC_COMPONENTS);
192 RETURN(ComponentsKeyword);
193 }
194 }
195
196 <*>"["{WS}MAIN_CONTROLLER{WS}"]" {
197 if (YY_START!=SC_blockcomment) {
198 BEGIN(SC_MAIN_CONTROLLER);
199 RETURN(MainControllerKeyword);
200 }
201 }
202
203 <*>"["{WS}INCLUDE{WS}"]" {
204 if (YY_START!=SC_blockcomment) {
205 BEGIN(SC_INCLUDE);
206 RETURN(IncludeKeyword);
207 }
208 }
209
210 <*>"["{WS}ORDERED_INCLUDE{WS}"]" {
211 if (YY_START!=SC_blockcomment) {
212 BEGIN(SC_ORDERED_INCLUDE);
213 }
214 }
215
216
217 <*>"["{WS}DEFINE{WS}"]" {
218 if (YY_START!=SC_blockcomment) {
219 BEGIN(SC_DEFINE);
220 RETURN(DefineKeyword);
221 }
222 }
223
224 /* Rules for SC_DEFINE must precede everything else */
225
226 <SC_DEFINE>{
227
228 "/*" {
229 comment_caller = SC_DEFINE;
230 BEGIN(SC_blockcomment);
231 }
232
233 {CHARSTRING} /* eats string */
234
235 {LINECOMMENT}
236
237 {NEWLINE} /* this is not in . */
238
239 \\\"
240
241 . /* eats unnecessary things */
242
243 }
244
245 <SC_ORDERED_INCLUDE>{
246
247 "/*" {
248 comment_caller = YY_START;
249 BEGIN(SC_blockcomment);
250 }
251
252 \" { BEGIN(SC_CSTRING); }
253
254 {LINECOMMENT}
255
256 {NEWLINE} /* this is not in . */
257
258 \\\"
259
260 . /* eat unnecessary chars */
261
262 }
263
264
265 <SC_CSTRING>{
266
267 \"\" cstring += '"';
268
269 \" {
270 std::string error_msg = switch_lexer(include_chain, cstring,
271 YY_CURRENT_BUFFER, yy_create_buffer, yy_switch_to_buffer, yylineno,
272 YY_BUF_SIZE);
273 if (error_msg.empty()) {
274 BEGIN(INITIAL);
275 } else {
276 config_read_error(error_msg.c_str());
277 }
278
279 cstring.clear();
280 } /* end of string */
281
282 \\[\\'"?] cstring += yytext[1]; /* backslash-quoted \ or " or ' or ? */
283 \\{NEWLINE} yylineno++;
284 \\a cstring += '\a';
285 \\b cstring += '\b';
286 \\f cstring += '\f';
287 \\n cstring += '\n';
288 \\r cstring += '\r';
289 \\t cstring += '\t';
290 \\v cstring += '\v';
291
292 \\[0-7]{1,3} {
293 unsigned int c;
294 sscanf(yytext + 1, "%o", &c);
295 if (c <= 255) cstring += c;
296 else config_read_error("Invalid octal character code in string literal");
297 }
298
299 \\x{HEX}{1,2} {
300 unsigned int c;
301 sscanf(yytext + 2, "%x", &c);
302 cstring += c;
303 }
304
305 \\(x[^\\\"]|.) config_read_error("Invalid excape sequence in string literal.");
306
307 {NEWLINE} {
308 cstring.append(yytext, yyleng);
309 yylineno++;
310 }
311
312 . {
313 cstring += yytext[0];
314 }
315 }
316 /* SC_cstring */
317
318
319 /* Values */
320
321 {NUMBER} {
322 yylval.int_val = NULL;
323 BN_dec2bn(&yylval.int_val, *yytext == '+' ? yytext + 1 : yytext);
324 RETURN(Number);
325 }
326
327 {FLOAT} {
328 yylval.float_val = atof(yytext);
329 RETURN(Float);
330 }
331
332 {BITSTRING} RETURN(Bstring);
333
334 {BITSTRINGMATCH} RETURN(BstringMatch);
335
336 {BITSTRING_BAD} {
337 config_read_error("Invalid bitstring value.");
338 RETURN(Bstring);
339 }
340
341 {HEXSTRING} RETURN(Hstring);
342
343 {HEXSTRINGMATCH} RETURN(HstringMatch);
344
345 {HEXSTRING_BAD} {
346 config_read_error("Invalid hexstring value.");
347 RETURN(Hstring);
348 }
349
350 {OCTETSTRING} RETURN(Ostring);
351
352 {OCTETSTRINGMATCH} RETURN(OstringMatch);
353
354 {OCTETSTRING_BAD} {
355 config_read_error("Invalid octetstring value.");
356 RETURN(Ostring);
357 }
358
359 {BINSTRING_BAD} config_read_error("Invalid string value.");
360
361 ' config_read_error("Unmatched ' character.");
362
363 {CHARSTRING} {
364 yylval.str_val = mcopystrn(yytext, yyleng);
365 RETURN(Cstring);
366 }
367
368 /* Section-wide keywords */
369
370 <SC_MODULE_PARAMETERS>
371 {
372 NULL RETURN(NULLKeyword);
373 null RETURN(nullKeyword);
374 char RETURN(CharKeyword);
375 objid RETURN(ObjIdKeyword);
376 omit RETURN(OmitKeyword);
377 none |
378 pass |
379 inconc |
380 fail |
381 error RETURN(VerdictValue);
382 complement RETURN(ComplementKeyword);
383 "\.\." RETURN(DotDot);
384 superset RETURN(SupersetKeyword);
385 subset RETURN(SubsetKeyword);
386 pattern RETURN(PatternKeyword);
387 permutation RETURN(PermutationKeyword);
388 length RETURN(LengthKeyword);
389 ifpresent RETURN(IfpresentKeyword);
390 infinity RETURN(InfinityKeyword);
391 }
392
393 <SC_MODULE_PARAMETERS,SC_LOGGING>
394 {
395 true |
396 false RETURN(BooleanValue);
397 }
398
399 <SC_MODULE_PARAMETERS,SC_LOGGING,SC_TESTPORT_PARAMETERS>
400 {
401 mtc RETURN(MTCKeyword);
402 system RETURN(SystemKeyword);
403 }
404
405 <SC_LOGGING>
406 {
407 [Ff]ile[Nn]ame |
408 [Ll]og[Ff]ile RETURN(LogFile);
409
410 [Ee]mergency[Ll]ogging RETURN(EmergencyLogging);
411
412 [Ee]mergency[Ll]ogging[Bb]ehaviour RETURN(EmergencyLoggingBehaviour);
413
414 [Bb]uffer[Aa]ll |
415 [Bb]uffer[Ma]asked RETURN(EmergencyLoggingBehaviourValue);
416
417 [Ee]mergency[Ll]ogging[Mm]ask RETURN(EmergencyLoggingMask);
418
419
420 [Ff]ile[Mm]ask RETURN(FileMask);
421
422 [Cc]onsole[Mm]ask RETURN(ConsoleMask);
423
424 [Tt]ime[Ss]tamp[Ff]ormat RETURN(TimestampFormat);
425 [Cc]onsole[Tt]ime[Ss]tamp[Ff]ormat RETURN(ConsoleTimestampFormat);
426
427 [Ll]og[Ss]ource[Ii]nfo |
428 [Ss]ource[Ii]nfo[Ff]ormat RETURN(SourceInfoFormat);
429
430 [Aa]ppend[Ff]ile RETURN(AppendFile);
431
432 [Ll]og[Ee]vent[Tt]ypes RETURN(LogEventTypes);
433
434 [Ll]og[Ee]ntity[Nn]ame RETURN(LogEntityName);
435
436 [Ll]og[Ff]ile[Ss]ize RETURN(LogFileSize);
437
438 [Ll]og[Ff]ile[Nn]umber RETURN(LogFileNumber);
439
440 [Dd]isk[Ff]ull[Aa]ction RETURN(DiskFullAction);
441
442 [Mm]atching[Hh]ints RETURN(MatchingHints);
443
444 [Ll]ogger[Pp]lugins RETURN(LoggerPlugins);
445
446 LOG_NOTHING RETURN(LoggingBit);
447
448 (TTCN_)?ACTION |
449 (TTCN_)?DEBUG |
450 (TTCN_)?DEFAULTOP |
451 (TTCN_)?ERROR |
452 (TTCN_)?EXECUTOR |
453 (TTCN_)?FUNCTION |
454 (TTCN_)?MATCHING |
455 (TTCN_)?PARALLEL |
456 (TTCN_)?PORTEVENT |
457 (TTCN_)?STATISTICS |
458 (TTCN_)?TESTCASE |
459 (TTCN_)?TIMEROP |
460 (TTCN_)?USER |
461 (TTCN_)?VERDICTOP |
462 (TTCN_)?WARNING |
463 LOG_ALL RETURN(LoggingBitCollection);
464
465 ACTION_UNQUALIFIED |
466 DEBUG_ENCDEC |
467 DEBUG_TESTPORT |
468 DEBUG_UNQUALIFIED |
469 DEFAULTOP_ACTIVATE |
470 DEFAULTOP_DEACTIVATE |
471 DEFAULTOP_EXIT |
472 DEFAULTOP_UNQUALIFIED |
473 ERROR_UNQUALIFIED |
474 EXECUTOR_COMPONENT |
475 EXECUTOR_CONFIGDATA |
476 EXECUTOR_EXTCOMMAND |
477 EXECUTOR_LOGOPTIONS |
478 EXECUTOR_RUNTIME |
479 EXECUTOR_UNQUALIFIED |
480 FUNCTION_RND |
481 FUNCTION_UNQUALIFIED |
482 MATCHING_DONE |
483 MATCHING_MCSUCCESS |
484 MATCHING_MCUNSUCC |
485 MATCHING_MMSUCCESS |
486 MATCHING_MMUNSUCC |
487 MATCHING_PCSUCCESS |
488 MATCHING_PCUNSUCC |
489 MATCHING_PMSUCCESS |
490 MATCHING_PMUNSUCC |
491 MATCHING_PROBLEM |
492 MATCHING_TIMEOUT |
493 MATCHING_UNQUALIFIED |
494 PARALLEL_PORTCONN |
495 PARALLEL_PORTMAP |
496 PARALLEL_PTC |
497 PARALLEL_UNQUALIFIED |
498 PORTEVENT_DUALRECV |
499 PORTEVENT_DUALSEND |
500 PORTEVENT_MCRECV |
501 PORTEVENT_MCSEND |
502 PORTEVENT_MMRECV |
503 PORTEVENT_MMSEND |
504 PORTEVENT_MQUEUE |
505 PORTEVENT_PCIN |
506 PORTEVENT_PCOUT |
507 PORTEVENT_PMIN |
508 PORTEVENT_PMOUT |
509 PORTEVENT_PQUEUE |
510 PORTEVENT_STATE |
511 PORTEVENT_UNQUALIFIED |
512 STATISTICS_UNQUALIFIED |
513 STATISTICS_VERDICT |
514 TESTCASE_FINISH |
515 TESTCASE_START |
516 TESTCASE_UNQUALIFIED |
517 TIMEROP_GUARD |
518 TIMEROP_READ |
519 TIMEROP_START |
520 TIMEROP_STOP |
521 TIMEROP_TIMEOUT |
522 TIMEROP_UNQUALIFIED |
523 USER_UNQUALIFIED |
524 VERDICTOP_FINAL |
525 VERDICTOP_GETVERDICT |
526 VERDICTOP_SETVERDICT |
527 VERDICTOP_UNQUALIFIED |
528 WARNING_UNQUALIFIED RETURN(LoggingBit);
529
530 [Tt][Ii][Mm][Ee] {yylval.ts_val=TSF_TIME; RETURN(TimestampValue);}
531 [Dd][Aa][Tt][Ee][Tt][Ii][Mm][Ee] {yylval.ts_val=TSF_DATE_TIME; RETURN(TimestampValue);}
532 [Ss][Ee][Cc][Oo][Nn][Dd][Ss] {yylval.ts_val=TSF_SEC; RETURN(TimestampValue);}
533
534 [Nn][Oo][Nn][Ee] |
535 [Ss][Ii][Nn][Gg][Ll][Ee] |
536 [Ss][Tt][Aa][Cc][Kk] RETURN(SourceInfoValue);
537
538 [Yy][Ee][Ss] |
539 [Nn][Oo] RETURN(YesNo);
540
541 [Dd]etailed RETURN(Detailed);
542 [Cc]ompact RETURN(Compact);
543 [Ss]ub[Cc]ategories RETURN(SubCategories);
544
545 [Ee]rror RETURN(Error);
546
547 [Ss]top RETURN(Stop);
548
549 [Rr]etry RETURN(Re_try);
550
551 [Dd]elete RETURN(Delete);
552 }
553
554 <SC_EXECUTE>control RETURN(ControlKeyword);
555
556 <SC_EXTERNAL_COMMANDS>
557 {
558 [Bb]egin[Cc]ontrol[Pp]art RETURN(BeginControlPart);
559 [Ee]nd[Cc]ontrol[Pp]art RETURN(EndControlPart);
560 [Bb]egin[Tt]est[Cc]ase RETURN(BeginTestCase);
561 [Ee]nd[Tt]est[Cc]ase RETURN(EndTestCase);
562 }
563
564 <SC_MAIN_CONTROLLER>
565 {
566 [Ll]ocal[Aa]ddress RETURN(LocalAddress);
567 [Tt][Cc][Pp][Pp]ort RETURN(TCPPort);
568 [Kk]ill[Tt]imer RETURN(KillTimer);
569 [Nn]um[Hh][Cc]s RETURN(NumHCs);
570 [Uu]nix[Ss]ockets[Ee]nabled RETURN(UnixSocketEnabled);
571 [Yy][Ee][Ss] RETURN(YesToken);
572 [Nn][Oo] RETURN(NoToken);
573 }
574
575 {TTCN3IDENTIFIER} {
576 switch (YY_START) {
577 case SC_GROUPS:
578 case SC_COMPONENTS:
579 case SC_EXECUTE:
580 case SC_MAIN_CONTROLLER:
581 yylval.str_val = (char*)Malloc(yyleng + 1);
582 memcpy(yylval.str_val, yytext, yyleng + 1);
583 break;
584 default:
585 yylval.str_val = NULL;
586 }
587 RETURN(Identifier);
588 }
589
590 <SC_MODULE_PARAMETERS>{ASN1LOWERIDENTIFIER} {
591 char *ttcn3_id = (char*)Malloc(yyleng + 1);
592 for (int i = 0; i < yyleng; i++) {
593 if (yytext[i] == '-') ttcn3_id[i] = '_';
594 else ttcn3_id[i] = yytext[i];
595 }
596 ttcn3_id[yyleng] = '\0';
597 config_read_warning("`%s' is not a valid TTCN-3 identifier. Did you mean "
598 "`%s'?", yytext, ttcn3_id);
599 cfg->config_read_buffer = mputprintf(cfg->config_read_buffer, "%s ", ttcn3_id);
600 Free(ttcn3_id);
601 return ASN1LowerIdentifier;
602 }
603
604 <SC_GROUPS,SC_COMPONENTS,SC_MAIN_CONTROLLER>{DNSNAME}|{IPV6} {
605 yylval.str_val = (char*)Malloc(yyleng + 1);
606 for (int i = 0; i < yyleng; i++) yylval.str_val[i] = tolower(yytext[i]);
607 yylval.str_val[yyleng] = '\0';
608 RETURN(DNSName);
609 }
610
611 {MACRO_BOOL} {
612 char *macroname = get_macro_id_from_ref(yytext);
613 size_t macrolen;
614 const char *macrovalue =
615 string_map_get_bykey(config_defines, macroname, &macrolen);
616 boolean bool_val;
617 if (macrovalue != NULL) {
618 if (!strcmp(macrovalue, "true")) bool_val = TRUE;
619 else if (!strcmp(macrovalue, "false")) bool_val = FALSE;
620 else {
621 config_read_error("Macro `%s' cannot be interpreted as boolean value: "
622 "`%s'", macroname, macrovalue);
623 bool_val = FALSE;
624 }
625 } else {
626 config_read_error("No macro or environmental variable defined with name "
627 "`%s'", macroname);
628 bool_val = FALSE;
629 }
630 Free(macroname);
631 if (whether_update_buffer()) cfg->config_read_buffer =
632 mputprintf(cfg->config_read_buffer, "%s ", bool_val ? "true" : "false");
633 return BooleanValue;
634 }
635
636 {MACRO_INT} {
637 char *macroname = get_macro_id_from_ref(yytext);
638 size_t macrolen = 0;
639 BIGNUM *BN_0 = BN_new();
640 BN_set_word(BN_0, 0);
641 const char *macrovalue =
642 string_map_get_bykey(config_defines, macroname, &macrolen);
643 if (macrovalue != NULL) {
644 if (string_is_int(macrovalue, macrolen)) {
645 yylval.int_val = NULL;
646 BN_dec2bn(&yylval.int_val,
647 *macrovalue == '+' ? macrovalue + 1 : macrovalue);
648 } else {
649 config_read_error("Macro `%s' cannot be interpreted as integer value: "
650 "`%s'", macroname, macrovalue);
651 yylval.int_val = BN_dup(BN_0);
652 }
653 } else {
654 config_read_error("No macro or environmental variable defined with name "
655 "`%s'", macroname);
656 yylval.int_val = BN_dup(BN_0);
657 }
658 BN_free(BN_0);
659 Free(macroname);
660 char *int_val_str = BN_bn2dec(yylval.int_val);
661 if (whether_update_buffer())
662 cfg->config_read_buffer = mputprintf(cfg->config_read_buffer, "%s ", int_val_str);
663 OPENSSL_free(int_val_str);
664 return Number;
665 }
666
667 {MACRO_FLOAT} {
668 char *macroname = get_macro_id_from_ref(yytext);
669 size_t macrolen;
670 const char *macrovalue =
671 string_map_get_bykey(config_defines, macroname, &macrolen);
672 if (macrovalue != NULL) {
673 if (string_is_float(macrovalue, macrolen))
674 yylval.float_val = atof(macrovalue);
675 else {
676 config_read_error("Macro `%s' cannot be interpreted as float value: "
677 "`%s'", macroname, macrovalue);
678 yylval.float_val = 0.0;
679 }
680 } else {
681 config_read_error("No macro or environmental variable defined"
682 " with name `%s'", macroname);
683 yylval.float_val = 0.0;
684 }
685 Free(macroname);
686 if (whether_update_buffer()) cfg->config_read_buffer =
687 mputprintf(cfg->config_read_buffer, "%f ", yylval.float_val);
688 return Float;
689 }
690
691 {MACRO_ID} {
692 char *macroname = get_macro_id_from_ref(yytext);
693 size_t macrolen;
694 const char *macrovalue =
695 string_map_get_bykey(config_defines, macroname, &macrolen);
696 boolean is_asn = FALSE;
697 if (macrovalue != NULL) {
698 if (string_is_id(macrovalue, macrolen)) {
699 yylval.str_val = mcopystr(macrovalue);
700 for (size_t i = 0; i < macrolen; i++) {
701 if (yylval.str_val[i] == '-') {
702 is_asn = TRUE;
703 yylval.str_val[i] = '_';
704 }
705 }
706 if (is_asn) config_read_warning("`%s' is not a valid TTCN-3 identifier. "
707 "Did you mean `%s'?", macrovalue, yylval.str_val);
708 if (whether_update_buffer()) cfg->config_read_buffer =
709 mputprintf(cfg->config_read_buffer, "%s ", yylval.str_val);
710 } else {
711 config_read_error("Macro `%s' cannot be interpreted as identifier: `%s'",
712 macroname, macrovalue);
713 yylval.str_val = NULL;
714 }
715 } else {
716 config_read_error("No macro or environmental variable defined with name "
717 "`%s'", macroname);
718 yylval.str_val = NULL;
719 }
720 Free(macroname);
721 return Identifier;
722 }
723
724 {MACRO_CSTR} {
725 char *macroname;
726 if (yytext[1] == '{') macroname = get_macro_id_from_ref(yytext);
727 else macroname = mcopystr(yytext + 1);
728 size_t macrolen;
729 const char *macrovalue = string_map_get_bykey
730 (config_defines, macroname, &macrolen);
731 if (macrovalue == NULL) {
732 config_read_error("No macro or environmental variable defined with "
733 "name `%s'", macroname);
734 yylval.str_val = memptystr();
735 Free(macroname);
736 return Cstring;
737 }
738
739 if (macrolen > 0 && macrovalue[0] == '{') { // structured
740 main_buffer = YY_CURRENT_BUFFER;
741 expansion_buffer = yy_scan_string(macrovalue);
742 yy_switch_to_buffer(expansion_buffer);
743 Free(macroname);
744 } else {
745 if (whether_update_buffer()) {
746 cfg->config_read_buffer=mputc(cfg->config_read_buffer, '"');
747 for (size_t i = 0; i < macrolen; i++) {
748 switch (macrovalue[i]) {
749 case '"':
750 cfg->config_read_buffer = mputstr(cfg->config_read_buffer, "\\\"");
751 break;
752 case '\\':
753 cfg->config_read_buffer = mputstr(cfg->config_read_buffer, "\\\\");
754 break;
755 case '\0':
756 cfg->config_read_buffer = mputstr(cfg->config_read_buffer, "\\000");
757 break;
758 default:
759 cfg->config_read_buffer = mputc(cfg->config_read_buffer, macrovalue[i]);
760 } /* switch */
761 } /* for */
762 cfg->config_read_buffer=mputstr(cfg->config_read_buffer, "\" ");
763 }
764 Free(macroname);
765 yylval.str_val = mcopystr(macrovalue);
766 return Cstring;
767 }
768 }
769
770 {MACRO_BSTR} {
771 char *macroname = get_macro_id_from_ref(yytext);
772 size_t macrolen;
773 const char *macrovalue =
774 string_map_get_bykey(config_defines, macroname, &macrolen);
775 if (macrovalue != NULL) {
776 if (string_is_bstr(macrovalue, macrolen)) {
777 if (whether_update_buffer()) cfg->config_read_buffer =
778 mputprintf(cfg->config_read_buffer, "'%s'B ", macrovalue);
779 } else config_read_error("Macro `%s' cannot be interpreted as bitstring "
780 "value: `%s'", macroname, macrovalue);
781 } else config_read_error("No macro or environmental variable defined with "
782 "name `%s'", macroname);
783 Free(macroname);
784 return Bstring;
785 }
786
787 {MACRO_HSTR} {
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_hstr(macrovalue, macrolen)) {
794 if (whether_update_buffer()) cfg->config_read_buffer =
795 mputprintf(cfg->config_read_buffer, "'%s'H ", macrovalue);
796 } else config_read_error("Macro `%s' cannot be interpreted as hexstring "
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 Hstring;
802 }
803
804 {MACRO_OSTR} {
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_ostr(macrovalue, macrolen)) {
811 if (whether_update_buffer()) cfg->config_read_buffer =
812 mputprintf(cfg->config_read_buffer, "'%s'O ", macrovalue);
813 } else config_read_error("Macro `%s' cannot be interpreted as octetstring "
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 Ostring;
819 }
820
821 {MACRO_BINARY} {
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 (whether_update_buffer()) {
828 cfg->config_read_buffer = mputc(cfg->config_read_buffer, '\'');
829 for (size_t i = 0; i < macrolen; i++) {
830 cfg->config_read_buffer = mputprintf(cfg->config_read_buffer, "%02X",
831 macrovalue[i]);
832 }
833 cfg->config_read_buffer = mputstr(cfg->config_read_buffer, "'O ");
834 }
835 } else config_read_error("No macro or environmental variable defined with "
836 "name `%s'", macroname);
837 Free(macroname);
838 return Ostring;
839 }
840
841 {MACRO_HOSTNAME} {
842 char *macroname = get_macro_id_from_ref(yytext);
843 size_t macrolen;
844 const char *macrovalue =
845 string_map_get_bykey(config_defines, macroname, &macrolen);
846 if (macrovalue != NULL) {
847 if (string_is_hostname(macrovalue, macrolen)) {
848 if (whether_update_buffer()) {
849 for (size_t i = 0; i < macrolen; i++) {
850 cfg->config_read_buffer =
851 mputc(cfg->config_read_buffer, tolower(macrovalue[i]));
852 }
853 yylval.str_val = NULL;
854 } else {
855 yylval.str_val = (char*)Malloc(macrolen + 1);
856 for (size_t i = 0; i < macrolen; i++)
857 yylval.str_val[i] = tolower(macrovalue[i]);
858 yylval.str_val[macrolen] = '\0';
859 }
860 } else {
861 config_read_error("Macro `%s' cannot be interpreted as host name: "
862 "`%s'", macroname, macrovalue);
863 yylval.str_val = NULL;
864 }
865 } else {
866 config_read_error("No macro or environmental variable defined with "
867 "name `%s'", macroname);
868 yylval.str_val = NULL;
869 }
870 Free(macroname);
871 return DNSName;
872 }
873
874 ":="|"=" RETURN(AssignmentChar);
875 "&=" RETURN(ConcatChar);
876
877 . RETURN(yytext[0]);
878
879 <*><<EOF>> {
880 if (expansion_buffer) {
881 yy_switch_to_buffer(main_buffer);
882 yy_delete_buffer(expansion_buffer);
883 expansion_buffer = NULL;
884 } else {
885 if (YY_START == SC_blockcomment) {
886 config_read_error("Unterminated block "
887 "comment (missing */ at the end of file).");
888 return EOF;
889 } else {
890 if (include_chain->size() > 1) {
891 yy_delete_buffer(YY_CURRENT_BUFFER);
892 fclose(include_chain->back().fp);
893 include_chain->pop_back();
894 yy_switch_to_buffer(include_chain->back().buffer_state);
895 yylineno = include_chain->back().line_number;
896 BEGIN(SC_ORDERED_INCLUDE);
897 } else {
898 return EOF;
899 }
900 }
901 }
902 }
903
904 %%
905
906 static void update_buffer()
907 {
908 if (whether_update_buffer()) {
909 cfg->config_read_buffer = mputstr(cfg->config_read_buffer, yytext);
910 cfg->config_read_buffer = mputc (cfg->config_read_buffer, ' ');
911 }
912 }
913
914 static boolean whether_update_buffer()
915 {
916 switch (YY_START) {
917 case SC_MODULE_PARAMETERS:
918 case SC_LOGGING:
919 case SC_TESTPORT_PARAMETERS:
920 case SC_EXTERNAL_COMMANDS:
921 return TRUE;
922 default:
923 return FALSE;
924 } /* switch */
925 }
926
927 void config_read_reset(const char* current_filename_) {
928 if (!include_chain) {
929 include_chain = new std::deque<IncludeElem<YY_BUFFER_STATE> >();
930 }
931
932 include_chain->clear();
933 include_chain->push_back(
934 IncludeElem<YY_BUFFER_STATE>(std::string(current_filename_), config_read_in));
935 }
936
937 void config_read_close() {
938 delete include_chain;
939 include_chain = NULL;
940 }
941
This page took 0.056056 seconds and 4 git commands to generate.