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