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 ******************************************************************************/
9 %option never-interactive
14 #include "asn1_preparser.h"
15 #include "../../common/memory.h"
18 /** This inefficient macro is needed to cope with binary files.
19 * The scanner must stop immediately when it encounters a zero byte,
20 * which might cause confusion in the internal algorithm of flex. */
21 #define YY_INPUT(buf,result,max_size) \
24 if (c == EOF || c == '\0') result = YY_NULL; \
31 #define YY_DECL static int yylex(char **module_name)
35 ASN1MODULENAME [A-Z](-?[A-Za-z0-9]+)*
37 WHITESPACE [ \t\n\v\f\r]
38 LINECOMMENT --(-?[^\-\n\v\f\r]+)*(--|-?[\n\v\f\r])
41 %s SC_moduleidentifier SC_definitiveidentifier SC_definitions
44 int blockcomment_caller = INITIAL, comment_depth = 0;
47 {WHITESPACE}|{LINECOMMENT}
50 blockcomment_caller = YY_START;
52 BEGIN(SC_blockcomment);
58 "*/" if (--comment_depth == 0) BEGIN(blockcomment_caller);
62 <INITIAL>{ASN1MODULENAME} {
63 if (module_name != NULL) *module_name = mcopystr(yytext);
64 BEGIN(SC_moduleidentifier);
67 <SC_moduleidentifier>"{" BEGIN(SC_definitiveidentifier);
69 <SC_definitiveidentifier>
71 "}" BEGIN(SC_definitions);
75 <SC_moduleidentifier,SC_definitions>"DEFINITIONS" return 1;
82 int is_asn1_module(const char *file_name, FILE *fp, char **module_name)
85 if (module_name != NULL) *module_name = NULL;
86 if (fseek(fp, 0L, SEEK_SET)) {
87 ERROR("Seeking to the beginning of file `%s' failed: %s", file_name,
93 ret_val = yylex(module_name);
94 yy_flush_buffer(YY_CURRENT_BUFFER);
95 if (ret_val == 0 && module_name != NULL && *module_name != NULL) {