Fix bug in message type header file
[ric-plt/lib/rmr.git] / doc / src / rtd / scrape_types.sh
1 # :vim setet ts=4 sw=4:
2 #==================================================================================
3 #        Copyright (c) 2020 Nokia
4 #        Copyright (c) 2020 AT&T Intellectual Property.
5 #
6 #   Licensed under the Apache License, Version 2.0 (the "License");
7 #   you may not use this file except in compliance with the License.
8 #   You may obtain a copy of the License at
9 #
10 #       http://www.apache.org/licenses/LICENSE-2.0
11 #
12 #   Unless required by applicable law or agreed to in writing, software
13 #   distributed under the License is distributed on an "AS IS" BASIS,
14 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 #   See the License for the specific language governing permissions and
16 #   limitations under the License.
17 #==================================================================================
18
19 #       Mnemonic:       scrape_types.sh
20 #       Abstract:       This parses the RIC_msg_types header file and geneates
21 #                               some doc.  See the header file for a description of what
22 #                               is recognised by this parser.
23 #       Date:           23 June 2020
24 #       Author:         E. Scott Daniels
25 # ----------------------------------------------------------------------------------
26
27
28 sdir="../../../docs"                    # dir where RTD scraper looks
29 input=../../../src/rmr/common/include/RIC_message_types.h
30 xsrc=/tmp/PID$$.xfm
31 export XFM_OUTPUT_TYPE=rst              # it should be this
32 out_suffix=rst
33
34 while [[ $1 == -* ]]
35 do
36         case $1 in
37                 -o)     export XFM_OUTPUT_TYPE=$2
38                         out_suffix=$2
39                         shift
40                         ;;
41
42                 -t) sdir=$2; shift;;
43         esac
44
45         shift
46 done
47
48 export OUTPUT_TYPE=$XFM_OUTPUT_TYPE                     # compat with project setup
49
50 cat <<endKat >$xsrc
51 .**  CAUTION:
52 .**  This {X}fm source is generated by $0 in $PWD. Any edits
53 .**  are very likely to be lost.
54 .**
55
56 .dv doc_title RIC Message Types
57 .im setup.im
58
59 endKat
60
61 sed 's/^ *//' $input | awk '
62         BEGIN {
63                 space_ok = 1
64
65                 off = 0                         # snarf types
66                 anything = 1
67                 desc = 2
68         }
69
70         # starting with token stk, build remaining tokens into a record
71         function build_rec( stk ) {
72                 rec = ""
73                 for( ; stk <= NF; stk++ ) {
74                         rec = rec $(stk) " "
75                 }
76                 return rec
77         }
78
79         # ------------------------------------------------------------------------
80
81         snarf && /^$/ && space_ok {
82                 printf( "&space\n\n" );
83                 space_ok = 0                                            # eat multiple blank lines
84                 if( snarf == desc ) {
85                         snarf = off
86                 }
87                 next
88         }
89
90         $1 == "/*+" {
91                 expect_header = 1
92                 snarf = anything
93                 space_ok = 1
94                 next
95         }
96
97         expect_header {
98                 if( dl_open ) {
99                         printf( "&end_dlist\n" );
100                         dl_open = 0
101                 }
102                 printf( "\n&h2(%s)\n", $0 )
103                 space_ok = 1
104                 expect_header = 0
105                 next
106         }
107
108         snarf && $1 == "*/" {
109                 snarf = off
110                 space_ok = 0
111                 next
112         }
113
114         /^#[ ]*define/ {
115                 if( $4 == "//--" ) {                            # ignored completely
116                         next
117                 }
118
119                 if( ! dl_open ) {
120                         printf( "\n&beg_dlist( 1.5i Helvetica-bold : : 30,70) \n" )
121                         dl_open = 1
122                 }
123
124                 if( $4 == "//+" ) {
125                         printf( "&di(%s) %s\n", $2, build_rec( 5 ) )
126                 } else {
127                         if( $4 == "//-" ) {
128                                 printf( "&di(%s) deprecated\n", $2 )
129                         } else {
130                                 printf( "&di(%s) &break\n", $2 )
131                         }
132                 }
133
134                 snarf = desc;                                           # snarf next only if //+ is the first token
135                 next
136         }
137
138         snarf == desc {
139                 if( $1 == "//+" ) {                                     # continued description, add it on
140                         printf( "%s\n", build_rec( 5 ) )
141                 } else {
142                         snarf = off
143                 }
144                 next
145         }
146
147         snarf == anything {
148                 print
149                 next
150         }
151
152         END {
153                 if( dl_open ) {
154                         printf( "&end_dlist\n" );
155                 }
156
157                 printf( ".qu\n" )
158         }
159 ' >>$xsrc
160
161 tfm $xsrc stdout | sed 's/^ //; s/ *$//' >$sdir/msg_types.$out_suffix
162
163
164 rm -f /tmp/PID$$.*
165
166