1 /******************************************************************************
2 * Copyright (c) 2000-2015 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 ******************************************************************************/
10 %option never-interactive
22 #include <openssl/crypto.h>
23 #include <openssl/bn.h>
25 #include "../../common/cfg_process_utils.hh"
26 #include "../../common/Path2.hh"
27 #include "../../common/config_preproc.h"
29 #include "../../common/memory.h"
30 #include "../mctr/config_data.h"
31 #include "../../core/Types.h"
32 #include "config_read.tab.hh"
34 //#include "../../common/dbgnew.hh"
36 extern string_map_t *config_defines;
38 #define yylval config_read_lval
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;
48 static void update_buffer();
49 static boolean whether_update_buffer();
51 #define RETURN(x) do {update_buffer(); return (x);} while(0)
53 void config_read_warning(const char *warning_str, ...);
54 extern void config_read_error(const char *error_str, ...);
55 extern config_data *cfg;
57 static std::deque<IncludeElem<YY_BUFFER_STATE> >* include_chain = NULL;
59 std::string get_cfg_read_current_file() {
60 if (include_chain && !include_chain->empty()) {
61 return include_chain->back().get_full_path();
71 LINECOMMENT ("//"|"#")[^\r\n]*{NEWLINE}
73 NUMBER 0|([1-9][0-9]*)
75 FLOAT [+-]?({NUMBER}\.[0-9]+)|((({NUMBER}(\.[0-9]+)?)|(\.[0-9]+))[Ee][+-]?{NUMBER})
80 BITSTRINGMATCH '{BINMATCH}*'B
81 BITSTRING_BAD '[^']*'B
85 HEXMATCH [0-9A-Fa-f\?\*]
86 HEXSTRINGMATCH '{HEXMATCH}*'H
87 HEXSTRING_BAD '[^']*'H
91 OCTMATCH {HEX}{HEX}|\?|\*
92 OCTETSTRINGMATCH '{OCTMATCH}*'O
93 OCTETSTRING_BAD '[^']*'O
97 TTCN3IDENTIFIER [A-Za-z][A-Za-z0-9_]*
98 ASN1LOWERIDENTIFIER [a-z](-?[A-Za-z0-9]+)*
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}"}"
112 CHAR [^\\\"]|\\([\\\'\"\?abfnrtv]|{NEWLINE}|[0-7]{1,3}|x{HEX}{1,2})|\"\"
113 CHARSTRING \"{CHAR}*\"
115 HOSTNAME [A-Za-z0-9]([A-Za-z0-9_\-]*[A-Za-z0-9])?
116 DNSNAME {HOSTNAME}(\.{HOSTNAME})*\.?
118 /* Example: fe80::c002:37ff:fe6c:0%fastethernet0/0 */
119 IPV6 [0-9A-Fa-f:.]+(%[0-9A-Za-z]+)?
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
127 int comment_caller = INITIAL;
131 /* Eat up comments and whitespaces */
134 comment_caller = YY_START;
135 BEGIN(SC_blockcomment);
139 "*/" BEGIN(comment_caller);
143 {LINECOMMENT}|{WHITESPACE}|{NEWLINE}
145 /* Section delimiters */
147 <*>"["{WS}MODULE_PARAMETERS{WS}"]" {
148 if (YY_START!=SC_blockcomment) {
149 BEGIN(SC_MODULE_PARAMETERS);
150 RETURN(ModuleParametersKeyword);
154 <*>"["{WS}LOGGING{WS}"]" {
155 if (YY_START!=SC_blockcomment) {
157 RETURN(LoggingKeyword);
161 <*>"["{WS}PROFILER{WS}"]" {
162 if (YY_START!=SC_blockcomment) {
164 RETURN(ProfilerKeyword);
168 <*>"["{WS}TESTPORT_PARAMETERS{WS}"]" {
169 if (YY_START!=SC_blockcomment) {
170 BEGIN(SC_TESTPORT_PARAMETERS);
171 RETURN(TestportParametersKeyword);
175 <*>"["{WS}EXECUTE{WS}"]" {
176 if (YY_START!=SC_blockcomment) {
178 RETURN(ExecuteKeyword);
182 <*>"["{WS}EXTERNAL_COMMANDS{WS}"]" {
183 if (YY_START!=SC_blockcomment) {
184 BEGIN(SC_EXTERNAL_COMMANDS);
185 RETURN(ExternalCommandsKeyword);
189 <*>"["{WS}GROUPS{WS}"]" {
190 if (YY_START!=SC_blockcomment) {
192 RETURN(GroupsKeyword);
196 <*>"["{WS}COMPONENTS{WS}"]" {
197 if (YY_START!=SC_blockcomment) {
198 BEGIN(SC_COMPONENTS);
199 RETURN(ComponentsKeyword);
203 <*>"["{WS}MAIN_CONTROLLER{WS}"]" {
204 if (YY_START!=SC_blockcomment) {
205 BEGIN(SC_MAIN_CONTROLLER);
206 RETURN(MainControllerKeyword);
210 <*>"["{WS}INCLUDE{WS}"]" {
211 if (YY_START!=SC_blockcomment) {
213 RETURN(IncludeKeyword);
217 <*>"["{WS}ORDERED_INCLUDE{WS}"]" {
218 if (YY_START!=SC_blockcomment) {
219 BEGIN(SC_ORDERED_INCLUDE);
224 <*>"["{WS}DEFINE{WS}"]" {
225 if (YY_START!=SC_blockcomment) {
227 RETURN(DefineKeyword);
231 /* Rules for SC_DEFINE must precede everything else */
236 comment_caller = SC_DEFINE;
237 BEGIN(SC_blockcomment);
240 {CHARSTRING} /* eats string */
244 {NEWLINE} /* this is not in . */
248 . /* eats unnecessary things */
252 <SC_ORDERED_INCLUDE>{
255 comment_caller = YY_START;
256 BEGIN(SC_blockcomment);
259 \" { BEGIN(SC_CSTRING); }
263 {NEWLINE} /* this is not in . */
267 . /* eat unnecessary chars */
277 std::string error_msg = switch_lexer(include_chain, cstring,
278 YY_CURRENT_BUFFER, yy_create_buffer, yy_switch_to_buffer, yylineno,
280 if (error_msg.empty()) {
283 config_read_error(error_msg.c_str());
287 } /* end of string */
289 \\[\\'"?] cstring += yytext[1]; /* backslash-quoted \ or " or ' or ? */
290 \\{NEWLINE} yylineno++;
301 sscanf(yytext + 1, "%o", &c);
302 if (c <= 255) cstring += c;
303 else config_read_error("Invalid octal character code in string literal");
308 sscanf(yytext + 2, "%x", &c);
312 \\(x[^\\\"]|.) config_read_error("Invalid excape sequence in string literal.");
315 cstring.append(yytext, yyleng);
320 cstring += yytext[0];
326 <SC_PROFILER>{HEX}+ {
327 /* numeric statistics filter (check this before checking NUMBERs) */
328 RETURN(ProfilerStatsFlag);
335 yylval.int_val = NULL;
336 BN_dec2bn(&yylval.int_val, *yytext == '+' ? yytext + 1 : yytext);
337 if (YY_START == SC_MODULE_PARAMETERS) {
344 yylval.float_val = atof(yytext);
345 if (YY_START == SC_MODULE_PARAMETERS) {
351 {BITSTRING} RETURN(Bstring);
353 {BITSTRINGMATCH} RETURN(BstringMatch);
356 config_read_error("Invalid bitstring value.");
360 {HEXSTRING} RETURN(Hstring);
362 {HEXSTRINGMATCH} RETURN(HstringMatch);
365 config_read_error("Invalid hexstring value.");
369 {OCTETSTRING} RETURN(Ostring);
371 {OCTETSTRINGMATCH} RETURN(OstringMatch);
374 config_read_error("Invalid octetstring value.");
378 {BINSTRING_BAD} config_read_error("Invalid string value.");
380 ' config_read_error("Unmatched ' character.");
383 yylval.str_val = mcopystrn(yytext, yyleng);
384 if (YY_START == SC_MODULE_PARAMETERS) {
390 /* Section-wide keywords */
392 <SC_MODULE_PARAMETERS>
394 NULL RETURN(NULLKeyword);
395 null RETURN(nullKeyword);
396 char RETURN(CharKeyword);
397 objid RETURN(ObjIdKeyword);
398 omit RETURN(OmitKeyword);
403 error RETURN(VerdictValue);
404 complement RETURN(ComplementKeyword);
405 "\.\." RETURN(DotDot);
406 superset RETURN(SupersetKeyword);
407 subset RETURN(SubsetKeyword);
408 pattern RETURN(PatternKeyword);
409 permutation RETURN(PermutationKeyword);
410 length RETURN(LengthKeyword);
411 ifpresent RETURN(IfpresentKeyword);
412 infinity RETURN(InfinityKeyword);
415 <SC_MODULE_PARAMETERS,SC_LOGGING,SC_PROFILER>
418 false RETURN(BooleanValue);
421 <SC_MODULE_PARAMETERS,SC_LOGGING,SC_TESTPORT_PARAMETERS>
423 mtc RETURN(MTCKeyword);
424 system RETURN(SystemKeyword);
430 [Ll]og[Ff]ile RETURN(LogFile);
432 [Ee]mergency[Ll]ogging RETURN(EmergencyLogging);
434 [Ee]mergency[Ll]ogging[Bb]ehaviour RETURN(EmergencyLoggingBehaviour);
437 [Bb]uffer[Ma]asked RETURN(EmergencyLoggingBehaviourValue);
439 [Ee]mergency[Ll]ogging[Mm]ask RETURN(EmergencyLoggingMask);
442 [Ff]ile[Mm]ask RETURN(FileMask);
444 [Cc]onsole[Mm]ask RETURN(ConsoleMask);
446 [Tt]ime[Ss]tamp[Ff]ormat RETURN(TimestampFormat);
447 [Cc]onsole[Tt]ime[Ss]tamp[Ff]ormat RETURN(ConsoleTimestampFormat);
449 [Ll]og[Ss]ource[Ii]nfo |
450 [Ss]ource[Ii]nfo[Ff]ormat RETURN(SourceInfoFormat);
452 [Aa]ppend[Ff]ile RETURN(AppendFile);
454 [Ll]og[Ee]vent[Tt]ypes RETURN(LogEventTypes);
456 [Ll]og[Ee]ntity[Nn]ame RETURN(LogEntityName);
458 [Ll]og[Ff]ile[Ss]ize RETURN(LogFileSize);
460 [Ll]og[Ff]ile[Nn]umber RETURN(LogFileNumber);
462 [Dd]isk[Ff]ull[Aa]ction RETURN(DiskFullAction);
464 [Mm]atching[Hh]ints RETURN(MatchingHints);
466 [Ll]ogger[Pp]lugins RETURN(LoggerPlugins);
468 LOG_NOTHING RETURN(LoggingBit);
485 LOG_ALL RETURN(LoggingBitCollection);
494 DEFAULTOP_DEACTIVATE |
496 DEFAULTOP_UNQUALIFIED |
499 EXECUTOR_CONFIGDATA |
500 EXECUTOR_EXTCOMMAND |
501 EXECUTOR_LOGOPTIONS |
503 EXECUTOR_UNQUALIFIED |
505 FUNCTION_UNQUALIFIED |
517 MATCHING_UNQUALIFIED |
521 PARALLEL_UNQUALIFIED |
535 PORTEVENT_UNQUALIFIED |
536 STATISTICS_UNQUALIFIED |
540 TESTCASE_UNQUALIFIED |
546 TIMEROP_UNQUALIFIED |
549 VERDICTOP_GETVERDICT |
550 VERDICTOP_SETVERDICT |
551 VERDICTOP_UNQUALIFIED |
552 WARNING_UNQUALIFIED RETURN(LoggingBit);
554 [Tt][Ii][Mm][Ee] {yylval.ts_val=TSF_TIME; RETURN(TimestampValue);}
555 [Dd][Aa][Tt][Ee][Tt][Ii][Mm][Ee] {yylval.ts_val=TSF_DATE_TIME; RETURN(TimestampValue);}
556 [Ss][Ee][Cc][Oo][Nn][Dd][Ss] {yylval.ts_val=TSF_SEC; RETURN(TimestampValue);}
559 [Ss][Ii][Nn][Gg][Ll][Ee] |
560 [Ss][Tt][Aa][Cc][Kk] RETURN(SourceInfoValue);
563 [Nn][Oo] RETURN(YesNo);
565 [Dd]etailed RETURN(Detailed);
566 [Cc]ompact RETURN(Compact);
567 [Ss]ub[Cc]ategories RETURN(SubCategories);
569 [Ee]rror RETURN(Error);
571 [Ss]top RETURN(Stop);
573 [Rr]etry RETURN(Re_try);
575 [Dd]elete RETURN(Delete);
580 [Dd]isable[Pp]rofiler RETURN(DisableProfilerKeyword);
581 [Dd]isable[Cc]overage RETURN(DisableCoverageKeyword);
582 [Dd]ata[Bb]ase[Ff]ile RETURN(DatabaseFileKeyword);
583 [Aa]ggregate[Dd]ata RETURN(AggregateDataKeyword);
584 [Ss]tatistics[Ff]ile RETURN(StatisticsFileKeyword);
585 [Dd]isable[Ss]tatistics RETURN(DisableStatisticsKeyword);
586 [Ss]tatistics[Ff]ilter RETURN(StatisticsFilterKeyword);
587 [Ss]tart[Aa]utomatically RETURN(StartAutomaticallyKeyword);
588 [Nn]et[Ll]ine[Tt]imes RETURN(NetLineTimesKeyword);
589 [Nn]et[Ff]unction[Tt]imes RETURN(NetFunctionTimesKeyword);
591 /* statistics filters */
592 [Nn]umber[Oo]f[Ll]ines |
593 [Ll]ine[Dd]ata[Rr]aw |
594 [Ff]unc[Dd]ata[Rr]aw |
595 [Ll]ine[Aa]vg[Rr]aw |
596 [Ff]unc[Aa]vg[Rr]aw |
597 [Ll]ine[Tt]imes[Ss]orted[Bb]y[Mm]od |
598 [Ff]unc[Tt]imes[Ss]orted[Bb]y[Mm]od |
599 [Ll]ine[Tt]imes[Ss]orted[Tt]otal |
600 [Ff]unc[Tt]imes[Ss]orted[Tt]otal |
601 [Ll]ine[Cc]ount[Ss]orted[Bb]y[Mm]od |
602 [Ff]unc[Cc]ount[Ss]orted[Bb]y[Mm]od |
603 [Ll]ine[Cc]ount[Ss]orted[Tt]otal |
604 [Ff]unc[Cc]ount[Ss]orted[Tt]otal |
605 [Ll]ine[Aa]vg[Ss]orted[Bb]y[Mm]od |
606 [Ff]unc[Aa]vg[Ss]orted[Bb]y[Mm]od |
607 [Ll]ine[Aa]vg[Ss]orted[Tt]otal |
608 [Ff]unc[Aa]vg[Ss]orted[Tt]otal |
609 [Tt]op10[Ll]ine[Tt]imes |
610 [Tt]op10[Ff]unc[Tt]imes |
611 [Tt]op10[Ll]ine[Cc]ount |
612 [Tt]op10[Ff]unc[Cc]ount |
613 [Tt]op10[Ll]ine[Aa]vg |
614 [Tt]op10[Ff]unc[Aa]vg |
617 [Aa]ll[Rr]aw[Dd]ata |
618 [Ll]ine[Dd]ata[Ss]orted[Bb]y[Mm]od |
619 [Ff]unc[Dd]ata[Ss]orted[Bb]y[Mm]od |
620 [Ll]ine[Dd]ata[Ss]orted[Tt]otal |
621 [Ff]unc[Dd]ata[Ss]orted[Tt]otal |
622 [Ll]ine[Dd]ata[Ss]orted |
623 [Ff]unc[Dd]ata[Ss]orted |
624 [Aa]ll[Dd]ata[Ss]orted |
625 [Tt]op10[Ll]ine[Dd]ata |
626 [Tt]op10[Ff]unc[Dd]ata |
627 [Tt]op10[Aa]ll[Dd]ata |
629 [Aa]ll RETURN(ProfilerStatsFlag);
632 <SC_EXECUTE>control RETURN(ControlKeyword);
634 <SC_EXTERNAL_COMMANDS>
636 [Bb]egin[Cc]ontrol[Pp]art RETURN(BeginControlPart);
637 [Ee]nd[Cc]ontrol[Pp]art RETURN(EndControlPart);
638 [Bb]egin[Tt]est[Cc]ase RETURN(BeginTestCase);
639 [Ee]nd[Tt]est[Cc]ase RETURN(EndTestCase);
644 [Ll]ocal[Aa]ddress RETURN(LocalAddress);
645 [Tt][Cc][Pp][Pp]ort RETURN(TCPPort);
646 [Kk]ill[Tt]imer RETURN(KillTimer);
647 [Nn]um[Hh][Cc]s RETURN(NumHCs);
648 [Uu]nix[Ss]ockets[Ee]nabled RETURN(UnixSocketEnabled);
649 [Yy][Ee][Ss] RETURN(YesToken);
650 [Nn][Oo] RETURN(NoToken);
658 case SC_MAIN_CONTROLLER:
659 yylval.str_val = (char*)Malloc(yyleng + 1);
660 memcpy(yylval.str_val, yytext, yyleng + 1);
663 yylval.str_val = NULL;
668 <SC_MODULE_PARAMETERS>{ASN1LOWERIDENTIFIER} {
669 char *ttcn3_id = (char*)Malloc(yyleng + 1);
670 for (size_t i = 0; i < yyleng; i++) {
671 if (yytext[i] == '-') ttcn3_id[i] = '_';
672 else ttcn3_id[i] = yytext[i];
674 ttcn3_id[yyleng] = '\0';
675 config_read_warning("`%s' is not a valid TTCN-3 identifier. Did you mean "
676 "`%s'?", yytext, ttcn3_id);
677 cfg->config_read_buffer = mputprintf(cfg->config_read_buffer, "%s ", ttcn3_id);
679 return ASN1LowerIdentifier;
682 <SC_GROUPS,SC_COMPONENTS,SC_MAIN_CONTROLLER>{DNSNAME}|{IPV6} {
683 yylval.str_val = (char*)Malloc(yyleng + 1);
684 for (size_t i = 0; i < yyleng; i++) yylval.str_val[i] = tolower(yytext[i]);
685 yylval.str_val[yyleng] = '\0';
690 char *macroname = get_macro_id_from_ref(yytext);
692 const char *macrovalue =
693 string_map_get_bykey(config_defines, macroname, ¯olen);
695 if (macrovalue != NULL) {
696 if (!strcmp(macrovalue, "true")) bool_val = TRUE;
697 else if (!strcmp(macrovalue, "false")) bool_val = FALSE;
699 config_read_error("Macro `%s' cannot be interpreted as boolean value: "
700 "`%s'", macroname, macrovalue);
704 config_read_error("No macro or environmental variable defined with name "
709 if (whether_update_buffer()) cfg->config_read_buffer =
710 mputprintf(cfg->config_read_buffer, "%s ", bool_val ? "true" : "false");
715 char *macroname = get_macro_id_from_ref(yytext);
717 BIGNUM *BN_0 = BN_new();
718 BN_set_word(BN_0, 0);
719 const char *macrovalue =
720 string_map_get_bykey(config_defines, macroname, ¯olen);
721 if (macrovalue != NULL) {
722 if (string_is_int(macrovalue, macrolen)) {
723 yylval.int_val = NULL;
724 BN_dec2bn(&yylval.int_val,
725 *macrovalue == '+' ? macrovalue + 1 : macrovalue);
727 config_read_error("Macro `%s' cannot be interpreted as integer value: "
728 "`%s'", macroname, macrovalue);
729 yylval.int_val = BN_dup(BN_0);
732 config_read_error("No macro or environmental variable defined with name "
734 yylval.int_val = BN_dup(BN_0);
738 char *int_val_str = BN_bn2dec(yylval.int_val);
739 if (whether_update_buffer())
740 cfg->config_read_buffer = mputprintf(cfg->config_read_buffer, "%s ", int_val_str);
741 OPENSSL_free(int_val_str);
742 if (YY_START == SC_MODULE_PARAMETERS) {
749 char *macroname = get_macro_id_from_ref(yytext);
751 const char *macrovalue =
752 string_map_get_bykey(config_defines, macroname, ¯olen);
753 if (macrovalue != NULL) {
754 if (string_is_float(macrovalue, macrolen))
755 yylval.float_val = atof(macrovalue);
757 config_read_error("Macro `%s' cannot be interpreted as float value: "
758 "`%s'", macroname, macrovalue);
759 yylval.float_val = 0.0;
762 config_read_error("No macro or environmental variable defined"
763 " with name `%s'", macroname);
764 yylval.float_val = 0.0;
767 if (whether_update_buffer()) cfg->config_read_buffer =
768 mputprintf(cfg->config_read_buffer, "%f ", yylval.float_val);
769 if (YY_START == SC_MODULE_PARAMETERS) {
776 char *macroname = get_macro_id_from_ref(yytext);
778 const char *macrovalue =
779 string_map_get_bykey(config_defines, macroname, ¯olen);
780 boolean is_asn = FALSE;
781 if (macrovalue != NULL) {
782 if (string_is_id(macrovalue, macrolen)) {
783 yylval.str_val = mcopystr(macrovalue);
784 for (size_t i = 0; i < macrolen; i++) {
785 if (yylval.str_val[i] == '-') {
787 yylval.str_val[i] = '_';
790 if (is_asn) config_read_warning("`%s' is not a valid TTCN-3 identifier. "
791 "Did you mean `%s'?", macrovalue, yylval.str_val);
792 if (whether_update_buffer()) cfg->config_read_buffer =
793 mputprintf(cfg->config_read_buffer, "%s ", yylval.str_val);
795 config_read_error("Macro `%s' cannot be interpreted as identifier: `%s'",
796 macroname, macrovalue);
797 yylval.str_val = NULL;
800 config_read_error("No macro or environmental variable defined with name "
802 yylval.str_val = NULL;
810 if (yytext[1] == '{') macroname = get_macro_id_from_ref(yytext);
811 else macroname = mcopystr(yytext + 1);
813 const char *macrovalue = string_map_get_bykey
814 (config_defines, macroname, ¯olen);
815 if (macrovalue == NULL) {
816 config_read_error("No macro or environmental variable defined with "
817 "name `%s'", macroname);
818 yylval.str_val = memptystr();
820 if (YY_START == SC_MODULE_PARAMETERS) {
826 if (macrolen > 0 && macrovalue[0] == '{') { // structured
827 main_buffer = YY_CURRENT_BUFFER;
828 expansion_buffer = yy_scan_string(macrovalue);
829 yy_switch_to_buffer(expansion_buffer);
832 if (whether_update_buffer()) {
833 cfg->config_read_buffer=mputc(cfg->config_read_buffer, '"');
834 for (size_t i = 0; i < macrolen; i++) {
835 switch (macrovalue[i]) {
837 cfg->config_read_buffer = mputstr(cfg->config_read_buffer, "\\\"");
840 cfg->config_read_buffer = mputstr(cfg->config_read_buffer, "\\\\");
843 cfg->config_read_buffer = mputstr(cfg->config_read_buffer, "\\000");
846 cfg->config_read_buffer = mputc(cfg->config_read_buffer, macrovalue[i]);
849 cfg->config_read_buffer=mputstr(cfg->config_read_buffer, "\" ");
852 yylval.str_val = mcopystr(macrovalue);
853 if (YY_START == SC_MODULE_PARAMETERS) {
861 char *macroname = get_macro_id_from_ref(yytext);
863 const char *macrovalue =
864 string_map_get_bykey(config_defines, macroname, ¯olen);
865 if (macrovalue != NULL) {
866 if (string_is_bstr(macrovalue, macrolen)) {
867 if (whether_update_buffer()) cfg->config_read_buffer =
868 mputprintf(cfg->config_read_buffer, "'%s'B ", macrovalue);
869 } else config_read_error("Macro `%s' cannot be interpreted as bitstring "
870 "value: `%s'", macroname, macrovalue);
871 } else config_read_error("No macro or environmental variable defined with "
872 "name `%s'", macroname);
878 char *macroname = get_macro_id_from_ref(yytext);
880 const char *macrovalue =
881 string_map_get_bykey(config_defines, macroname, ¯olen);
882 if (macrovalue != NULL) {
883 if (string_is_hstr(macrovalue, macrolen)) {
884 if (whether_update_buffer()) cfg->config_read_buffer =
885 mputprintf(cfg->config_read_buffer, "'%s'H ", macrovalue);
886 } else config_read_error("Macro `%s' cannot be interpreted as hexstring "
887 "value: `%s'", macroname, macrovalue);
888 } else config_read_error("No macro or environmental variable defined with "
889 "name `%s'", macroname);
895 char *macroname = get_macro_id_from_ref(yytext);
897 const char *macrovalue =
898 string_map_get_bykey(config_defines, macroname, ¯olen);
899 if (macrovalue != NULL) {
900 if (string_is_ostr(macrovalue, macrolen)) {
901 if (whether_update_buffer()) cfg->config_read_buffer =
902 mputprintf(cfg->config_read_buffer, "'%s'O ", macrovalue);
903 } else config_read_error("Macro `%s' cannot be interpreted as octetstring "
904 "value: `%s'", macroname, macrovalue);
905 } else config_read_error("No macro or environmental variable defined with "
906 "name `%s'", macroname);
912 char *macroname = get_macro_id_from_ref(yytext);
914 const char *macrovalue =
915 string_map_get_bykey(config_defines, macroname, ¯olen);
916 if (macrovalue != NULL) {
917 if (whether_update_buffer()) {
918 cfg->config_read_buffer = mputc(cfg->config_read_buffer, '\'');
919 for (size_t i = 0; i < macrolen; i++) {
920 cfg->config_read_buffer = mputprintf(cfg->config_read_buffer, "%02X",
923 cfg->config_read_buffer = mputstr(cfg->config_read_buffer, "'O ");
925 } else config_read_error("No macro or environmental variable defined with "
926 "name `%s'", macroname);
932 char *macroname = get_macro_id_from_ref(yytext);
934 const char *macrovalue =
935 string_map_get_bykey(config_defines, macroname, ¯olen);
936 if (macrovalue != NULL) {
937 if (string_is_hostname(macrovalue, macrolen)) {
938 if (whether_update_buffer()) {
939 for (size_t i = 0; i < macrolen; i++) {
940 cfg->config_read_buffer =
941 mputc(cfg->config_read_buffer, tolower(macrovalue[i]));
943 yylval.str_val = NULL;
945 yylval.str_val = (char*)Malloc(macrolen + 1);
946 for (size_t i = 0; i < macrolen; i++)
947 yylval.str_val[i] = tolower(macrovalue[i]);
948 yylval.str_val[macrolen] = '\0';
951 config_read_error("Macro `%s' cannot be interpreted as host name: "
952 "`%s'", macroname, macrovalue);
953 yylval.str_val = NULL;
956 config_read_error("No macro or environmental variable defined with "
957 "name `%s'", macroname);
958 yylval.str_val = NULL;
964 ":="|"=" RETURN(AssignmentChar);
965 "&=" RETURN(ConcatChar);
970 if (expansion_buffer) {
971 yy_switch_to_buffer(main_buffer);
972 yy_delete_buffer(expansion_buffer);
973 expansion_buffer = NULL;
975 if (YY_START == SC_blockcomment) {
976 config_read_error("Unterminated block "
977 "comment (missing */ at the end of file).");
980 if (include_chain->size() > 1) {
981 yy_delete_buffer(YY_CURRENT_BUFFER);
982 fclose(include_chain->back().fp);
983 include_chain->pop_back();
984 yy_switch_to_buffer(include_chain->back().buffer_state);
985 yylineno = include_chain->back().line_number;
986 BEGIN(SC_ORDERED_INCLUDE);
996 static void update_buffer()
998 if (whether_update_buffer()) {
999 cfg->config_read_buffer = mputstr(cfg->config_read_buffer, yytext);
1000 cfg->config_read_buffer = mputc (cfg->config_read_buffer, ' ');
1004 static boolean whether_update_buffer()
1007 case SC_MODULE_PARAMETERS:
1009 case SC_TESTPORT_PARAMETERS:
1010 case SC_EXTERNAL_COMMANDS:
1018 void config_read_reset(const char* current_filename_) {
1019 if (!include_chain) {
1020 include_chain = new std::deque<IncludeElem<YY_BUFFER_STATE> >();
1023 include_chain->clear();
1024 include_chain->push_back(
1025 IncludeElem<YY_BUFFER_STATE>(std::string(current_filename_), config_read_in));
1028 void config_read_close() {
1029 delete include_chain;
1030 include_chain = NULL;