1 %option nounput
2 %option noinput
3 
4 %{ /* -*- C -*- */
5 /*
6  * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
7  *                         University Research and Technology
8  *                         Corporation.  All rights reserved.
9  * Copyright (c) 2004-2005 The University of Tennessee and The University
10  *                         of Tennessee Research Foundation.  All rights
11  *                         reserved.
12  * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
13  *                         University of Stuttgart.  All rights reserved.
14  * Copyright (c) 2004-2005 The Regents of the University of California.
15  *                         All rights reserved.
16  * Copyright (c) 2006      Cisco Systems, Inc.  All rights reserved.
17  * Copyright (c) 2012      Los Alamos National Security, LLC. All rights
18  *                         reserved.
19  * $COPYRIGHT$
20  *
21  * Additional copyrights may follow
22  *
23  * $HEADER$
24  */
25 
26 #include "opal_config.h"
27 
28 #include <stdio.h>
29 #ifdef HAVE_UNISTD_H
30 #include <unistd.h>
31 #endif
32 
33 #include "btl_openib_lex.h"
34 
35 BEGIN_C_DECLS
36 
37 /*
38  * local functions
39  */
40 static int btl_openib_ini_yywrap(void);
41 
42 END_C_DECLS
43 
44 /*
45  * global variables
46  */
47 int btl_openib_ini_yynewlines = 1;
48 bool btl_openib_ini_parse_done = false;
49 char *btl_openib_ini_string = NULL;
50 
51 %}
52 
53 WHITE       [\f\t\v ]
54 CHAR        [A-Za-z0-9_\-\.]
55 NAME_CHAR   [A-Za-z0-9_\-\.\\\/]
56 
57 %x comment
58 %x section_name
59 %x section_end
60 %x value
61 
62 %%
63 
64 {WHITE}*\n          { ++btl_openib_ini_yynewlines;
65                       return BTL_OPENIB_INI_PARSE_NEWLINE; }
66 #.*\n               { ++btl_openib_ini_yynewlines;
67                       return BTL_OPENIB_INI_PARSE_NEWLINE; }
68 "//".*\n            { ++btl_openib_ini_yynewlines;
69                       return BTL_OPENIB_INI_PARSE_NEWLINE; }
70 
71 "/*"                { BEGIN(comment);
72                       return BTL_OPENIB_INI_PARSE_NEWLINE; }
73 <comment>[^*\n]*       ; /* Eat up non '*'s */
74 <comment>"*"+[^*/\n]*  ; /* Eat '*'s not followed by a '/' */
75 <comment>\n         { ++btl_openib_ini_yynewlines;
76                       return BTL_OPENIB_INI_PARSE_NEWLINE; }
77 <comment>"*"+"/"    { BEGIN(INITIAL); /* Done with block comment */
78                       return BTL_OPENIB_INI_PARSE_NEWLINE; }
79 
80 {WHITE}*\[{WHITE}*  { BEGIN(section_name); }
81 <section_name>({NAME_CHAR}|{WHITE})*{NAME_CHAR}/{WHITE}*\] {
82                       BEGIN(section_end);
83                       return BTL_OPENIB_INI_PARSE_SECTION; }
84 <section_name>\n    { ++btl_openib_ini_yynewlines;
85                       return BTL_OPENIB_INI_PARSE_ERROR; }
86 <section_name>.     { return BTL_OPENIB_INI_PARSE_ERROR; }
87 <section_end>{WHITE}*\]{WHITE}*\n { BEGIN(INITIAL);
88                       ++btl_openib_ini_yynewlines;
89                       return BTL_OPENIB_INI_PARSE_NEWLINE; }
90 
91 {WHITE}*"="{WHITE}* { BEGIN(value);
92                       return BTL_OPENIB_INI_PARSE_EQUAL; }
93 {WHITE}+            ; /* whitespace */
94 {CHAR}+             { return BTL_OPENIB_INI_PARSE_SINGLE_WORD; }
95 
96 <value>{WHITE}*\n   { BEGIN(INITIAL);
97                       ++btl_openib_ini_yynewlines;
98                       return BTL_OPENIB_INI_PARSE_NEWLINE; }
99 <value>[^\n]*[^\t \n]/[\t ]* {
100                       return BTL_OPENIB_INI_PARSE_VALUE; }
101 
102 .                   { return BTL_OPENIB_INI_PARSE_ERROR; }
103 
104 %%
105 
106 /* Old flex (2.5.4a? and older) does not define a destroy function */
107 #if !defined(YY_FLEX_SUBMINOR_VERSION)
108 #define YY_FLEX_SUBMINOR_VERSION 0
109 #endif
110 
111 #if (YY_FLEX_MAJOR_VERSION < 2) || (YY_FLEX_MAJOR_VERSION == 2 && (YY_FLEX_MINOR_VERSION < 5 || (YY_FLEX_MINOR_VERSION == 5 && YY_FLEX_SUBMINOR_VERSION < 5)))
112 int btl_openib_ini_yylex_destroy(void)
113 {
114     if (NULL != YY_CURRENT_BUFFER) {
115         yy_delete_buffer(YY_CURRENT_BUFFER);
116 #if defined(YY_CURRENT_BUFFER_LVALUE)
117         YY_CURRENT_BUFFER_LVALUE = NULL;
118 #else
119         YY_CURRENT_BUFFER = NULL;
120 #endif  /* YY_CURRENT_BUFFER_LVALUE */
121     }
122     return YY_NULL;
123 }
124 #endif
125 
126 static int btl_openib_ini_yywrap(void)
127 {
128     btl_openib_ini_parse_done = true;
129     return 1;
130 }
131 
132 
133 /*
134  * Ensure that we have a valid yybuffer to use.  Specifically, if this
135  * scanner is invoked a second time, finish_parsing() (above) will
136  * have been executed, and the current buffer will have been freed.
137  * Flex doesn't recognize this fact because as far as it's concerned,
138  * its internal state was already initialized, so it thinks it should
139  * have a valid buffer.  Hence, here we ensure to give it a valid
140  * buffer.
141  */
142 int btl_openib_ini_init_buffer(FILE *file)
143 {
144     YY_BUFFER_STATE buf = yy_create_buffer(file, YY_BUF_SIZE);
145     yy_switch_to_buffer(buf);
146 
147     return 0;
148 }
149