1 | #!/bin/bash
|
---|
2 | ################################################################################
|
---|
3 | # Synchronize EnumToStringx.cpp and StringToEnumx.cpp and MATLAB Enums
|
---|
4 | #
|
---|
5 | # Get all lines of EnumDefinitions.h which hold Enum | remove all commas > put everything in file temp
|
---|
6 | #
|
---|
7 | # NOTE: Even when run from this directory, ISSM_DIR must be defined correctly.
|
---|
8 | #
|
---|
9 | cat EnumDefinitions.h | grep -e "[0-9]Enum," -e "[a-zA-Z]Enum," -e "MaximumNumberOfDefinitionsEnum" | grep -v include | sed -e "s/,/ /g" | awk '{print $1}' > temp
|
---|
10 |
|
---|
11 | #Removed existing files
|
---|
12 | rm $ISSM_DIR/src/c/shared/Enum/EnumToStringx.cpp
|
---|
13 | rm $ISSM_DIR/src/c/shared/Enum/StringToEnumx.cpp
|
---|
14 |
|
---|
15 | #Get number of enums
|
---|
16 | NUMENUMS=$(wc -l temp | awk '{printf("%s",$1);}');
|
---|
17 |
|
---|
18 | #Deal with Analyses
|
---|
19 | if false; then
|
---|
20 | #Build EnumToAnalysis.cpp {{{
|
---|
21 | #Header
|
---|
22 | cat <<END > $ISSM_DIR/src/c/analyses/EnumToAnalysis.cpp
|
---|
23 | /*
|
---|
24 | * \file EnumToAnalysis.cpp
|
---|
25 | * \brief: output class depending on enum
|
---|
26 | *
|
---|
27 | * WARNING: DO NOT MODIFY THIS FILE
|
---|
28 | * this file has been automatically generated by Synchronize.sh
|
---|
29 | * Please read README for more information
|
---|
30 | */
|
---|
31 |
|
---|
32 | #include "./analyses.h"
|
---|
33 | #include "../shared/shared.h"
|
---|
34 |
|
---|
35 | Analysis* EnumToAnalysis(int analysis_enum){
|
---|
36 |
|
---|
37 | switch(analysis_enum){
|
---|
38 | END
|
---|
39 | #core
|
---|
40 | cat temp | grep [a-zA-Z0-9]Analysis | \
|
---|
41 | grep -v DefaultAnalysis | grep -v RecoveryAnalysis | grep -v FlaimAnalysis | grep -v SurfaceSlopeAnalysis | grep -v BedSlopeAnalysis | \
|
---|
42 | awk '{print "\t\t#ifdef _HAVE_"toupper(substr($1,1,length($1)-12))"_\n\t\t" "case " $1" : return new " substr($1,1,length($1)-4) "();\n\t\t#endif"}' \
|
---|
43 | >> $ISSM_DIR/src/c/analyses/EnumToAnalysis.cpp
|
---|
44 |
|
---|
45 | #Footer
|
---|
46 | cat <<END >> $ISSM_DIR/src/c/analyses/EnumToAnalysis.cpp
|
---|
47 | default : _error_("enum provided not supported ("<<EnumToStringx(analysis_enum)<<")");
|
---|
48 | }
|
---|
49 | }
|
---|
50 | END
|
---|
51 | #}}}
|
---|
52 | #Build analyses.m4{{{
|
---|
53 | #Header
|
---|
54 | cat <<END > $ISSM_DIR/m4/analyses.m4
|
---|
55 |
|
---|
56 | dnl WARNING: DO NOT MODIFY THIS FILE
|
---|
57 | dnl this file has been automatically generated by Synchronize.sh
|
---|
58 | dnl Please read README for more information
|
---|
59 |
|
---|
60 | # AX_ANALYSES_SELECTION
|
---|
61 | # -----------------
|
---|
62 | # Check for analyses compilation
|
---|
63 | AC_DEFUN([AX_ANALYSES_SELECTION],
|
---|
64 | [
|
---|
65 |
|
---|
66 | END
|
---|
67 | #core
|
---|
68 | cat temp | grep [a-zA-Z0-9]Analysis | \
|
---|
69 | grep -v DefaultAnalysis | grep -v FlaimAnalysis | grep -v SurfaceSlopeAnalysis | grep -v BedSlopeAnalysis | \
|
---|
70 | sed -e "s/AnalysisEnum//g" | \
|
---|
71 | awk '{print "dnl with-" $1"{{{\n\
|
---|
72 | AC_ARG_WITH([" $1"],\n\
|
---|
73 | \tAS_HELP_STRING([--with-" $1" = YES], [compile with " $1" capabilities (default is yes)]),\n\
|
---|
74 | \t[" toupper($1)"=$withval],[" toupper($1)"=yes])\n\
|
---|
75 | AC_MSG_CHECKING(for " $1" capability compilation)\n\n\
|
---|
76 | HAVE_" toupper($1)"=no \n\
|
---|
77 | if test \"x$" toupper($1)"\" = \"xyes\"; then\n\
|
---|
78 | HAVE_" toupper($1)"=yes\n\
|
---|
79 | AC_DEFINE([_HAVE_" toupper($1)"_],[1],[with " $1" capability])\n\
|
---|
80 | fi\n\
|
---|
81 | AM_CONDITIONAL([" toupper($1)"], [test x$HAVE_" toupper($1)" = xyes])\n\
|
---|
82 | AC_MSG_RESULT($HAVE_" toupper($1)")\n\
|
---|
83 | dnl }}}"}' \
|
---|
84 | >> $ISSM_DIR/m4/analyses.m4
|
---|
85 |
|
---|
86 | #Footer
|
---|
87 | cat <<END >> $ISSM_DIR/m4/analyses.m4
|
---|
88 |
|
---|
89 | ])
|
---|
90 | END
|
---|
91 | #}}}
|
---|
92 | fi
|
---|
93 |
|
---|
94 | #Enum to String conversions
|
---|
95 | #Build EnumToStringx.cpp {{{
|
---|
96 | #Header
|
---|
97 | cat <<END > $ISSM_DIR/src/c/shared/Enum/EnumToStringx.cpp
|
---|
98 | /*
|
---|
99 | * \file EnumToStringx.cpp:
|
---|
100 | * \brief: output string associated with enum
|
---|
101 | *
|
---|
102 | * WARNING: DO NOT MODIFY THIS FILE
|
---|
103 | * this file has been automatically generated by Synchronize.sh
|
---|
104 | * Please read README for more information
|
---|
105 | */
|
---|
106 |
|
---|
107 | #include <cstring>
|
---|
108 | #include "./Enum.h"
|
---|
109 | #include "../Exceptions/exceptions.h"
|
---|
110 | #include "../MemOps/MemOps.h"
|
---|
111 |
|
---|
112 | const char* EnumToStringx(int en){
|
---|
113 |
|
---|
114 | switch(en){
|
---|
115 |
|
---|
116 | END
|
---|
117 | #core
|
---|
118 | cat temp | awk '{print "\t\t" "case " $1" : return \"" substr($1,1,length($1)-4) "\";"}' >> $ISSM_DIR/src/c/shared/Enum/EnumToStringx.cpp
|
---|
119 | #Footer
|
---|
120 | cat <<END >> $ISSM_DIR/src/c/shared/Enum/EnumToStringx.cpp
|
---|
121 | default : return "unknown";
|
---|
122 |
|
---|
123 | }
|
---|
124 | }
|
---|
125 | void EnumToStringx(char** pstring,int enum_in){
|
---|
126 | char *string = NULL;
|
---|
127 | int len = 0;
|
---|
128 |
|
---|
129 | len=strlen(EnumToStringx(enum_in));
|
---|
130 | string=xNew<char>(len+1);
|
---|
131 | memcpy(string,EnumToStringx(enum_in),(len+1)*sizeof(char));
|
---|
132 |
|
---|
133 | /*Assign output pointer*/
|
---|
134 | *pstring=string;
|
---|
135 | }
|
---|
136 |
|
---|
137 | bool IsInputEnum(int enum_in){
|
---|
138 | if(enum_in>InputsSTARTEnum && enum_in<InputsENDEnum) return true;
|
---|
139 | return false;
|
---|
140 | }
|
---|
141 |
|
---|
142 | bool IsParamEnum(int enum_in){
|
---|
143 | if(enum_in>ParametersSTARTEnum && enum_in<ParametersENDEnum) return true;
|
---|
144 | return false;
|
---|
145 | }
|
---|
146 | END
|
---|
147 | #}}}
|
---|
148 | #Build StringToEnumx.cpp {{{
|
---|
149 | #Header
|
---|
150 | cat <<END > $ISSM_DIR/src/c/shared/Enum/StringToEnumx.cpp
|
---|
151 | /*
|
---|
152 | * \file StringToEnumx.cpp:
|
---|
153 | * \brief: output enum associated with string
|
---|
154 | *
|
---|
155 | * WARNING: DO NOT MODIFY THIS FILE
|
---|
156 | * this file has been automatically generated by Synchronize.sh
|
---|
157 | * Please read README for more information
|
---|
158 | */
|
---|
159 |
|
---|
160 | #include <cstring>
|
---|
161 | #include "./Enum.h"
|
---|
162 | #include "../Exceptions/exceptions.h"
|
---|
163 |
|
---|
164 | int StringToEnumx(const char* name,bool notfounderror){
|
---|
165 |
|
---|
166 | int stage=1;
|
---|
167 |
|
---|
168 | END
|
---|
169 |
|
---|
170 | #core
|
---|
171 | i1=1;
|
---|
172 | i2=120;
|
---|
173 | for (( i=1 ; i<=100 ; i++ )); do
|
---|
174 | echo " if(stage==$i){" >> $ISSM_DIR//src/c/shared/Enum/StringToEnumx.cpp
|
---|
175 | awk -v i1=$i1 -v i2=$i2 '{if(NR>=i1 && NR<=i2) print $0 }' temp |
|
---|
176 | awk '{print "\t" ((NR==1)?" if":" else if") " (strcmp(name,\"" substr($1,1,length($1)-4) "\")==0) return " $1 ";"}' >> $ISSM_DIR//src/c/shared/Enum/StringToEnumx.cpp
|
---|
177 | echo " else stage=$(($i+1));" >> $ISSM_DIR//src/c/shared/Enum/StringToEnumx.cpp
|
---|
178 | echo " }" >> $ISSM_DIR//src/c/shared/Enum/StringToEnumx.cpp
|
---|
179 |
|
---|
180 | if [ $i2 -ge $NUMENUMS ]; then break; fi
|
---|
181 | let i1=$i1+120
|
---|
182 | let i2=$i2+120
|
---|
183 | done
|
---|
184 |
|
---|
185 | #footer
|
---|
186 | cat <<END >> $ISSM_DIR/src/c/shared/Enum/StringToEnumx.cpp
|
---|
187 | /*If we reach this point, the string provided has not been found*/
|
---|
188 | if(notfounderror)
|
---|
189 | _error_("Enum " << name << " not found");
|
---|
190 | else
|
---|
191 | return -1;
|
---|
192 | }
|
---|
193 | END
|
---|
194 | #}}}
|
---|
195 | #Build issmenum.jl {{{
|
---|
196 | #Header
|
---|
197 | cat <<END > $ISSM_DIR/src/c/shared/Enum/issmenums.jl
|
---|
198 | # WARNING: DO NOT MODIFY THIS FILE
|
---|
199 | # this file has been automatically generated by Synchronize.sh
|
---|
200 | # Please read README for more information
|
---|
201 |
|
---|
202 | @enum IssmEnum begin
|
---|
203 | END
|
---|
204 | cat temp | awk '{print "\t" $1}' >> $ISSM_DIR/src/c/shared/Enum/issmenums.jl
|
---|
205 | #Move on to EnumToString
|
---|
206 | cat <<END >> $ISSM_DIR/src/c/shared/Enum/issmenums.jl
|
---|
207 | end
|
---|
208 |
|
---|
209 | function EnumToString(enum::IssmEnum)
|
---|
210 | END
|
---|
211 | cat temp | awk '{print "\tif(enum==" $1 ") return \"" substr($1,1,length($1)-4) "\" end"}' >> $ISSM_DIR/src/c/shared/Enum/issmenums.jl
|
---|
212 | #Move on to StringToEnumx
|
---|
213 | cat <<END >> $ISSM_DIR/src/c/shared/Enum/issmenums.jl
|
---|
214 | end
|
---|
215 |
|
---|
216 | function StringToEnum(name::String)
|
---|
217 | END
|
---|
218 | cat temp | awk '{print "\tif(name==\"" substr($1,1,length($1)-4) "\") return " $1 " end"}' >> $ISSM_DIR/src/c/shared/Enum/issmenums.jl
|
---|
219 |
|
---|
220 | cat <<END >> $ISSM_DIR/src/c/shared/Enum/issmenums.jl
|
---|
221 | error("Enum ", name, " not found");
|
---|
222 | end
|
---|
223 | END
|
---|
224 | #}}}
|
---|
225 |
|
---|
226 | #vim file
|
---|
227 | #Build Enum.vim{{{
|
---|
228 | #Header
|
---|
229 | cat <<END > $ISSM_DIR/src/c/shared/Enum/Enum.vim
|
---|
230 | """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
---|
231 | " ISSM specific c syntax highlighting
|
---|
232 | "
|
---|
233 | " WARNING: DO NOT MODIFY THIS FILE
|
---|
234 | " this file has been automatically generated by Synchronize.sh
|
---|
235 | " Please read README for more information
|
---|
236 | """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
---|
237 |
|
---|
238 | "PETSc
|
---|
239 | syn keyword cType Vec Mat SeqVec SeqMat
|
---|
240 |
|
---|
241 | "ISSM typedefs
|
---|
242 | syn keyword cType mxArray ErrorException QuadtreeBox
|
---|
243 | syn keyword cType IssmDouble IssmPDouble
|
---|
244 |
|
---|
245 | "ISSM Enums
|
---|
246 | END
|
---|
247 | cat temp | awk '{print "syn keyword cConstant " $1}' >> $ISSM_DIR/src/c/shared/Enum/Enum.vim
|
---|
248 | cat <<END >> $ISSM_DIR/src/c/shared/Enum/Enum.vim
|
---|
249 | "ISSM Enums end
|
---|
250 | END
|
---|
251 |
|
---|
252 | #Synchronize ISSM objects objects
|
---|
253 | cat <<END >> $ISSM_DIR/src/c/shared/Enum/Enum.vim
|
---|
254 |
|
---|
255 | "ISSM objects
|
---|
256 | END
|
---|
257 | find $ISSM_DIR/src/c/classes -name "*.cpp" -o -name "*.h" | sed -e "s/\// /g" -e "s/\.cpp//" -e "s/\.h//" | awk '{print $(NF)}' | sort | uniq | awk '{ printf "syn keyword cType " $1 "\n"}'>> $ISSM_DIR/src/c/shared/Enum/Enum.vim
|
---|
258 | find $ISSM_DIR/src/c/analyses -name "*Analysis.h" | sed -e "s/\// /g" -e "s/\.cpp//" -e "s/\.h//" | awk '{print $(NF)}' | sort | uniq | awk '{ printf "syn keyword cType " $1 "\n"}'>> $ISSM_DIR/src/c/shared/Enum/Enum.vim
|
---|
259 | echo "\"ISSM objects end" >> $ISSM_DIR/src/c/shared/Enum/Enum.vim
|
---|
260 | #}}}
|
---|
261 | #Build Enumjl.vim{{{
|
---|
262 | #Header
|
---|
263 | cat <<END > $ISSM_DIR/src/c/shared/Enum/Enumjl.vim
|
---|
264 | """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
---|
265 | " ISSM specific julia syntax highlighting
|
---|
266 | "
|
---|
267 | " WARNING: DO NOT MODIFY THIS FILE
|
---|
268 | " this file has been automatically generated by Synchronize.sh
|
---|
269 | " Please read README for more information
|
---|
270 | """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
---|
271 |
|
---|
272 | "ISSM Enums
|
---|
273 | END
|
---|
274 | cat temp | awk '{print "syn keyword juliaConstC " $1}' >> $ISSM_DIR/src/c/shared/Enum/Enumjl.vim
|
---|
275 | cat <<END >> $ISSM_DIR/src/c/shared/Enum/Enumjl.vim
|
---|
276 | "ISSM Enums end
|
---|
277 | END
|
---|
278 | #}}}
|
---|
279 |
|
---|
280 | #clean up{{{
|
---|
281 | rm temp
|
---|
282 | #}}}
|
---|
283 | #print info {{{
|
---|
284 | printf "\r "
|
---|
285 | printf "\rdone!\n"
|
---|
286 | #}}}
|
---|