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-2006 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$
17  *
18  * Additional copyrights may follow
19  *
20  * $HEADER$
21  */
22 
23 #include "opal_config.h"
24 
25 #include <stdio.h>
26 #ifdef HAVE_UNISTD_H
27 #include <unistd.h>
28 #endif
29 
30 #include "opal/util/show_help_lex.h"
31 
32 BEGIN_C_DECLS
33 
34 /*
35  * public functions
36  */
37 extern int opal_show_help_finish_parsing(void);
38 
39 /*
40  * local functions
41  */
42 static int opal_show_help_yywrap(void);
43 
44 END_C_DECLS
45 
46 /*
47  * global variables
48  */
49 int opal_show_help_yynewlines = 1;
50 bool opal_show_help_parse_done = false;
51 
52 %}
53 
54 WHITE       [\f\t\v ]
55 CHAR        [A-Za-z0-9_\-\.]
56 
57 %x CHOMP
58 
59 %%
60 
61 #.*\n               ; /* comment line */
62 
63 ^\[.+\]/[^\]\n]*\n { BEGIN(CHOMP); return OPAL_SHOW_HELP_PARSE_TOPIC; }
64 
65 <CHOMP>.*\n { BEGIN(INITIAL); }
66 
67 .*/\n { BEGIN(CHOMP); return OPAL_SHOW_HELP_PARSE_MESSAGE; }
68 
69 %%
70 
71 /* Old flex (2.5.4a? and older) does not define a destroy function */
72 #if !defined(YY_FLEX_SUBMINOR_VERSION)
73 #define YY_FLEX_SUBMINOR_VERSION 0
74 #endif
75 
76 #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)))
77 int opal_show_help_yylex_destroy(void)
78 {
79     if (NULL != YY_CURRENT_BUFFER) {
80         yy_delete_buffer(YY_CURRENT_BUFFER);
81 #if defined(YY_CURRENT_BUFFER_LVALUE)
82         YY_CURRENT_BUFFER_LVALUE = NULL;
83 #else
84         YY_CURRENT_BUFFER = NULL;
85 #endif  /* YY_CURRENT_BUFFER_LVALUE */
86     }
87     return YY_NULL;
88 }
89 #endif
90 
opal_show_help_yywrap(void)91 static int opal_show_help_yywrap(void)
92 {
93     opal_show_help_parse_done = true;
94     return 1;
95 }
96 
97 
98 /*
99  * Ensure that we have a valid yybuffer to use.  Specifically, if this
100  * scanner is invoked a second time, finish_parsing() (above) will
101  * have been executed, and the current buffer will have been freed.
102  * Flex doesn't recognize this fact because as far as it's concerned,
103  * its internal state was already initialized, so it thinks it should
104  * have a valid buffer.  Hence, here we ensure to give it a valid
105  * buffer.
106  */
opal_show_help_init_buffer(FILE * file)107 int opal_show_help_init_buffer(FILE *file)
108 {
109     YY_BUFFER_STATE buf = yy_create_buffer(file, YY_BUF_SIZE);
110     yy_switch_to_buffer(buf);
111 
112     return 0;
113 }
114