source: issm/trunk/src/c/shared/Enum/Synchronize.sh

Last change on this file was 28013, checked in by Mathieu Morlighem, 16 months ago

merged trunk-jpl and trunk for revision 28011

  • Property svn:executable set to *
File size: 8.6 KB
Line 
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#
9cat 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
12rm $ISSM_DIR/src/c/shared/Enum/EnumToStringx.cpp
13rm $ISSM_DIR/src/c/shared/Enum/StringToEnumx.cpp
14
15#Get number of enums
16NUMENUMS=$(wc -l temp | awk '{printf("%s",$1);}');
17
18#Deal with Analyses
19if false; then
20#Build EnumToAnalysis.cpp {{{
21#Header
22cat <<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
35Analysis* EnumToAnalysis(int analysis_enum){
36
37 switch(analysis_enum){
38END
39#core
40cat 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
46cat <<END >> $ISSM_DIR/src/c/analyses/EnumToAnalysis.cpp
47 default : _error_("enum provided not supported ("<<EnumToStringx(analysis_enum)<<")");
48 }
49}
50END
51#}}}
52#Build analyses.m4{{{
53#Header
54cat <<END > $ISSM_DIR/m4/analyses.m4
55
56dnl WARNING: DO NOT MODIFY THIS FILE
57dnl this file has been automatically generated by Synchronize.sh
58dnl Please read README for more information
59
60# AX_ANALYSES_SELECTION
61# -----------------
62# Check for analyses compilation
63AC_DEFUN([AX_ANALYSES_SELECTION],
64[
65
66END
67#core
68cat 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\
72AC_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\
75AC_MSG_CHECKING(for " $1" capability compilation)\n\n\
76HAVE_" toupper($1)"=no \n\
77if test \"x$" toupper($1)"\" = \"xyes\"; then\n\
78 HAVE_" toupper($1)"=yes\n\
79 AC_DEFINE([_HAVE_" toupper($1)"_],[1],[with " $1" capability])\n\
80fi\n\
81AM_CONDITIONAL([" toupper($1)"], [test x$HAVE_" toupper($1)" = xyes])\n\
82AC_MSG_RESULT($HAVE_" toupper($1)")\n\
83dnl }}}"}' \
84 >> $ISSM_DIR/m4/analyses.m4
85
86#Footer
87cat <<END >> $ISSM_DIR/m4/analyses.m4
88
89])
90END
91#}}}
92fi
93
94#Enum to String conversions
95#Build EnumToStringx.cpp {{{
96#Header
97cat <<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
112const char* EnumToStringx(int en){
113
114 switch(en){
115
116END
117#core
118cat temp | awk '{print "\t\t" "case " $1" : return \"" substr($1,1,length($1)-4) "\";"}' >> $ISSM_DIR/src/c/shared/Enum/EnumToStringx.cpp
119#Footer
120cat <<END >> $ISSM_DIR/src/c/shared/Enum/EnumToStringx.cpp
121 default : return "unknown";
122
123 }
124}
125void 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
137bool IsInputEnum(int enum_in){
138 if(enum_in>InputsSTARTEnum && enum_in<InputsENDEnum) return true;
139 return false;
140}
141
142bool IsParamEnum(int enum_in){
143 if(enum_in>ParametersSTARTEnum && enum_in<ParametersENDEnum) return true;
144 return false;
145}
146END
147#}}}
148#Build StringToEnumx.cpp {{{
149#Header
150cat <<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
164int StringToEnumx(const char* name,bool notfounderror){
165
166 int stage=1;
167
168END
169
170#core
171i1=1;
172i2=120;
173for (( 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
183done
184
185#footer
186cat <<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}
193END
194#}}}
195#Build issmenum.jl {{{
196#Header
197cat <<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
203END
204cat temp | awk '{print "\t" $1}' >> $ISSM_DIR/src/c/shared/Enum/issmenums.jl
205#Move on to EnumToString
206cat <<END >> $ISSM_DIR/src/c/shared/Enum/issmenums.jl
207end
208
209function EnumToString(enum::IssmEnum)
210END
211cat 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
213cat <<END >> $ISSM_DIR/src/c/shared/Enum/issmenums.jl
214end
215
216function StringToEnum(name::String)
217END
218cat temp | awk '{print "\tif(name==\"" substr($1,1,length($1)-4) "\") return " $1 " end"}' >> $ISSM_DIR/src/c/shared/Enum/issmenums.jl
219
220cat <<END >> $ISSM_DIR/src/c/shared/Enum/issmenums.jl
221 error("Enum ", name, " not found");
222end
223END
224#}}}
225
226#vim file
227#Build Enum.vim{{{
228#Header
229cat <<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
239syn keyword cType Vec Mat SeqVec SeqMat
240
241"ISSM typedefs
242syn keyword cType mxArray ErrorException QuadtreeBox
243syn keyword cType IssmDouble IssmPDouble
244
245"ISSM Enums
246END
247cat temp | awk '{print "syn keyword cConstant " $1}' >> $ISSM_DIR/src/c/shared/Enum/Enum.vim
248cat <<END >> $ISSM_DIR/src/c/shared/Enum/Enum.vim
249"ISSM Enums end
250END
251
252#Synchronize ISSM objects objects
253cat <<END >> $ISSM_DIR/src/c/shared/Enum/Enum.vim
254
255"ISSM objects
256END
257find $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
258find $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
259echo "\"ISSM objects end" >> $ISSM_DIR/src/c/shared/Enum/Enum.vim
260#}}}
261#Build Enumjl.vim{{{
262#Header
263cat <<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
273END
274cat temp | awk '{print "syn keyword juliaConstC " $1}' >> $ISSM_DIR/src/c/shared/Enum/Enumjl.vim
275cat <<END >> $ISSM_DIR/src/c/shared/Enum/Enumjl.vim
276"ISSM Enums end
277END
278#}}}
279
280#clean up{{{
281rm temp
282#}}}
283#print info {{{
284printf "\r "
285printf "\rdone!\n"
286#}}}
Note: See TracBrowser for help on using the repository browser.