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

Last change on this file since 19105 was 19105, checked in by Mathieu Morlighem, 10 years ago

merged trunk-jpl and trunk for revision 19103

  • Property svn:executable set to *
File size: 6.9 KB
Line 
1#!/bin/bash
2#Synchronize EnumToStringx.cpp and StringToEnumx.cpp and matlab Enums
3
4#Get all lines of EnumDefinitions2.h which hold Enum | remove all commas > put everything in file temp
5cat 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
6
7#Removed existing files
8rm $ISSM_DIR/src/m/enum/*.m
9rm $ISSM_DIR/src/m/enum/*.py
10rm $ISSM_DIR/src/c/shared/Enum/EnumToStringx.cpp
11rm $ISSM_DIR/src/c/shared/Enum/StringToEnumx.cpp
12
13#Get number of enums
14NUMENUMS=$(wc -l temp | awk '{printf("%s",$1);}');
15
16#Deal with Analyses
17#Build EnumToAnalysis.cpp {{{
18#Header
19cat <<END > $ISSM_DIR/src/c/analyses/EnumToAnalysis.cpp
20/*
21* \file EnumToAnalysis.cpp
22* \brief: output class depending on enum
23*
24* WARNING: DO NOT MODIFY THIS FILE
25* this file has been automatically generated by Synchronize.sh
26* Please read README for more information
27*/
28
29#include "./analyses.h"
30#include "../shared/shared.h"
31
32Analysis* EnumToAnalysis(int analysis_enum){
33
34 switch(analysis_enum){
35END
36#core
37cat temp | grep [a-zA-Z0-9]Analysis | \
38 grep -v DefaultAnalysis | grep -v FlaimAnalysis | grep -v SurfaceSlopeAnalysis | grep -v BedSlopeAnalysis | \
39 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"}' \
40 >> $ISSM_DIR/src/c/analyses/EnumToAnalysis.cpp
41
42#Footer
43cat <<END >> $ISSM_DIR/src/c/analyses/EnumToAnalysis.cpp
44 default : _error_("enum provided not supported ("<<EnumToStringx(analysis_enum)<<")");
45 }
46}
47END
48#}}}
49#Build analyses.m4{{{
50#Header
51cat <<END > $ISSM_DIR/m4/analyses.m4
52
53dnl WARNING: DO NOT MODIFY THIS FILE
54dnl this file has been automatically generated by Synchronize.sh
55dnl Please read README for more information
56
57# AX_ANALYSES_SELECTION
58# -----------------
59# Check for analyses compilation
60AC_DEFUN([AX_ANALYSES_SELECTION],
61[
62
63END
64#core
65cat temp | grep [a-zA-Z0-9]Analysis | \
66 grep -v DefaultAnalysis | grep -v FlaimAnalysis | grep -v SurfaceSlopeAnalysis | grep -v BedSlopeAnalysis | \
67 sed -e "s/AnalysisEnum//g" | \
68 awk '{print "dnl with-" $1"{{{\n\
69AC_ARG_WITH([" $1"],\n\
70\tAS_HELP_STRING([--with-" $1" = YES], [compile with " $1" capabilities (default is yes)]),\n\
71\t[" toupper($1)"=$withval],[" toupper($1)"=yes])\n\
72AC_MSG_CHECKING(for " $1" capability compilation)\n\n\
73HAVE_" toupper($1)"=no \n\
74if test \"x$" toupper($1)"\" = \"xyes\"; then\n\
75 HAVE_" toupper($1)"=yes\n\
76 AC_DEFINE([_HAVE_" toupper($1)"_],[1],[with " $1" capability])\n\
77fi\n\
78AM_CONDITIONAL([" toupper($1)"], [test x$HAVE_" toupper($1)" = xyes])\n\
79AC_MSG_RESULT($HAVE_" toupper($1)")\n\
80dnl }}}"}' \
81 >> $ISSM_DIR/m4/analyses.m4
82
83#Footer
84cat <<END >> $ISSM_DIR/m4/analyses.m4
85
86])
87END
88#}}}
89
90#Enum to String conversions
91#Build EnumToStringx.cpp {{{
92#Header
93cat <<END > $ISSM_DIR/src/c/shared/Enum/EnumToStringx.cpp
94/*
95* \file EnumToStringx.cpp:
96* \brief: output string associated with enum
97*
98* WARNING: DO NOT MODIFY THIS FILE
99* this file has been automatically generated by Synchronize.sh
100* Please read README for more information
101*/
102
103#include <cstring>
104#include "./Enum.h"
105#include "../Exceptions/exceptions.h"
106#include "../MemOps/MemOps.h"
107
108const char* EnumToStringx(int en){
109
110 switch(en){
111
112END
113#core
114cat temp | awk '{print "\t\t" "case " $1" : return \"" substr($1,1,length($1)-4) "\";"}' >> $ISSM_DIR/src/c/shared/Enum/EnumToStringx.cpp
115#Footer
116cat <<END >> $ISSM_DIR/src/c/shared/Enum/EnumToStringx.cpp
117 default : return "unknown";
118
119 }
120}
121void EnumToStringx(char** pstring,int enum_in){
122 char *string = NULL;
123 int len = 0;
124
125 len=strlen(EnumToStringx(enum_in));
126 string=xNew<char>(len+1);
127 memcpy(string,EnumToStringx(enum_in),(len+1)*sizeof(char));
128
129 /*Assign output pointer*/
130 *pstring=string;
131}
132END
133#}}}
134#Build StringToEnumx.cpp {{{
135#Header
136cat <<END > $ISSM_DIR/src/c/shared/Enum/StringToEnumx.cpp
137/*
138* \file StringToEnumx.cpp:
139* \brief: output enum associated with string
140*
141* WARNING: DO NOT MODIFY THIS FILE
142* this file has been automatically generated by Synchronize.sh
143* Please read README for more information
144*/
145
146#include <cstring>
147#include "./Enum.h"
148#include "../Exceptions/exceptions.h"
149
150int StringToEnumx(const char* name,bool notfounderror){
151
152 int stage=1;
153
154END
155
156#core
157i1=1;
158i2=120;
159for (( i=1 ; i<=100 ; i++ )); do
160 echo " if(stage==$i){" >> $ISSM_DIR//src/c/shared/Enum/StringToEnumx.cpp
161 awk -v i1=$i1 -v i2=$i2 '{if(NR>=i1 && NR<=i2) print $0 }' temp |
162 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
163 echo " else stage=$(($i+1));" >> $ISSM_DIR//src/c/shared/Enum/StringToEnumx.cpp
164 echo " }" >> $ISSM_DIR//src/c/shared/Enum/StringToEnumx.cpp
165
166 if [ $i2 -ge $NUMENUMS ]; then break; fi
167 let i1=$i1+120
168 let i2=$i2+120
169done
170
171#footer
172cat <<END >> $ISSM_DIR/src/c/shared/Enum/StringToEnumx.cpp
173 /*If we reach this point, the string provided has not been found*/
174 if(notfounderror)
175 _error_("Enum " << name << " not found");
176 else
177 return -1;
178}
179END
180#}}}
181
182#Deal with Python Enums
183#Build EnumDefinitions.py{{{
184cat <<END > $ISSM_DIR/src/m/enum/EnumDefinitions.py
185from StringToEnum import StringToEnum
186
187"""
188
189WARNING: DO NOT MODIFY THIS FILE
190this file has been automatically generated by src/c/shared/Enum/Synchronize.sh
191Please read src/c/shared/Enum/README for more information
192
193"""
194
195END
196#core
197cat temp | awk '{print "def " $1"(): return StringToEnum(\"" substr($1,1,length($1)-4) "\")[0]"}' >> $ISSM_DIR/src/m/enum/EnumDefinitions.py
198#}}}
199
200#Deal with Matlab Enums`
201ENUM=0;
202
203for NAMEENUM in $(cat temp); do
204
205 #Get name and enum of the line i
206 NAME=$(echo $NAMEENUM | sed -e "s/Enum//g")
207 #offset Enum by one (Enum begins with 0 and not 1!)
208 let ENUM=$ENUM+1
209
210 #print info {{{
211 if [ $ENUM -lt 10 ]
212 then
213 printf "\r "
214 printf "\r $ENUM/$NUMENUMS Adding "$NAME"..."
215 else
216 if [ $ENUM -lt 100 ]
217 then
218 printf "\r "
219 printf "\r $ENUM/$NUMENUMS Adding "$NAME"..."
220 else
221 printf "\r "
222 printf "\r$ENUM/$NUMENUMS Adding "$NAME"..."
223 fi
224 fi
225 #}}}
226 #Add case to matlabenum file{{{
227 cat <<END > $ISSM_DIR"/src/m/enum/"$(echo $NAMEENUM".m")
228function macro=$(echo $NAMEENUM)()
229%$(echo $NAMEENUM | awk {'print toupper($1)'}) - Enum of $(echo $NAME)
230%
231% WARNING: DO NOT MODIFY THIS FILE
232% this file has been automatically generated by src/c/shared/Enum/Synchronize.sh
233% Please read src/c/shared/Enum/README for more information
234%
235% Usage:
236% macro=$NAMEENUM()
237
238macro=StringToEnum('$NAME');
239END
240#}}}
241
242done
243#clean up{{{
244rm temp
245#}}}
246#print info {{{
247printf "\r "
248printf "\rdone!\n"
249#}}}
Note: See TracBrowser for help on using the repository browser.