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

Last change on this file since 23189 was 23189, checked in by Mathieu Morlighem, 7 years ago

merged trunk-jpl and trunk for revision 23187

  • Property svn:executable set to *
File size: 5.4 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/c/shared/Enum/EnumToStringx.cpp
9rm $ISSM_DIR/src/c/shared/Enum/StringToEnumx.cpp
10
11#Get number of enums
12NUMENUMS=$(wc -l temp | awk '{printf("%s",$1);}');
13
14#Deal with Analyses
15if true ; then
16#Build EnumToAnalysis.cpp {{{
17#Header
18cat <<END > $ISSM_DIR/src/c/analyses/EnumToAnalysis.cpp
19/*
20* \file EnumToAnalysis.cpp
21* \brief: output class depending on enum
22*
23* WARNING: DO NOT MODIFY THIS FILE
24* this file has been automatically generated by Synchronize.sh
25* Please read README for more information
26*/
27
28#include "./analyses.h"
29#include "../shared/shared.h"
30
31Analysis* EnumToAnalysis(int analysis_enum){
32
33 switch(analysis_enum){
34END
35#core
36cat temp | grep [a-zA-Z0-9]Analysis | \
37 grep -v DefaultAnalysis | grep -v FlaimAnalysis | grep -v SurfaceSlopeAnalysis | grep -v BedSlopeAnalysis | \
38 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"}' \
39 >> $ISSM_DIR/src/c/analyses/EnumToAnalysis.cpp
40
41#Footer
42cat <<END >> $ISSM_DIR/src/c/analyses/EnumToAnalysis.cpp
43 default : _error_("enum provided not supported ("<<EnumToStringx(analysis_enum)<<")");
44 }
45}
46END
47#}}}
48#Build analyses.m4{{{
49#Header
50cat <<END > $ISSM_DIR/m4/analyses.m4
51
52dnl WARNING: DO NOT MODIFY THIS FILE
53dnl this file has been automatically generated by Synchronize.sh
54dnl Please read README for more information
55
56# AX_ANALYSES_SELECTION
57# -----------------
58# Check for analyses compilation
59AC_DEFUN([AX_ANALYSES_SELECTION],
60[
61
62END
63#core
64cat temp | grep [a-zA-Z0-9]Analysis | \
65 grep -v DefaultAnalysis | grep -v FlaimAnalysis | grep -v SurfaceSlopeAnalysis | grep -v BedSlopeAnalysis | \
66 sed -e "s/AnalysisEnum//g" | \
67 awk '{print "dnl with-" $1"{{{\n\
68AC_ARG_WITH([" $1"],\n\
69\tAS_HELP_STRING([--with-" $1" = YES], [compile with " $1" capabilities (default is yes)]),\n\
70\t[" toupper($1)"=$withval],[" toupper($1)"=yes])\n\
71AC_MSG_CHECKING(for " $1" capability compilation)\n\n\
72HAVE_" toupper($1)"=no \n\
73if test \"x$" toupper($1)"\" = \"xyes\"; then\n\
74 HAVE_" toupper($1)"=yes\n\
75 AC_DEFINE([_HAVE_" toupper($1)"_],[1],[with " $1" capability])\n\
76fi\n\
77AM_CONDITIONAL([" toupper($1)"], [test x$HAVE_" toupper($1)" = xyes])\n\
78AC_MSG_RESULT($HAVE_" toupper($1)")\n\
79dnl }}}"}' \
80 >> $ISSM_DIR/m4/analyses.m4
81
82#Footer
83cat <<END >> $ISSM_DIR/m4/analyses.m4
84
85])
86END
87#}}}
88fi
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}
132
133bool IsInputEnum(int enum_in){
134 if(enum_in>InputsSTARTEnum && enum_in<InputsENDEnum) return true;
135 return false;
136}
137
138bool IsParamEnum(int enum_in){
139 if(enum_in>ParametersSTARTEnum && enum_in<ParametersENDEnum) return true;
140 return false;
141}
142END
143#}}}
144#Build StringToEnumx.cpp {{{
145#Header
146cat <<END > $ISSM_DIR/src/c/shared/Enum/StringToEnumx.cpp
147/*
148* \file StringToEnumx.cpp:
149* \brief: output enum associated with string
150*
151* WARNING: DO NOT MODIFY THIS FILE
152* this file has been automatically generated by Synchronize.sh
153* Please read README for more information
154*/
155
156#include <cstring>
157#include "./Enum.h"
158#include "../Exceptions/exceptions.h"
159
160int StringToEnumx(const char* name,bool notfounderror){
161
162 int stage=1;
163
164END
165
166#core
167i1=1;
168i2=120;
169for (( i=1 ; i<=100 ; i++ )); do
170 echo " if(stage==$i){" >> $ISSM_DIR//src/c/shared/Enum/StringToEnumx.cpp
171 awk -v i1=$i1 -v i2=$i2 '{if(NR>=i1 && NR<=i2) print $0 }' temp |
172 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
173 echo " else stage=$(($i+1));" >> $ISSM_DIR//src/c/shared/Enum/StringToEnumx.cpp
174 echo " }" >> $ISSM_DIR//src/c/shared/Enum/StringToEnumx.cpp
175
176 if [ $i2 -ge $NUMENUMS ]; then break; fi
177 let i1=$i1+120
178 let i2=$i2+120
179done
180
181#footer
182cat <<END >> $ISSM_DIR/src/c/shared/Enum/StringToEnumx.cpp
183 /*If we reach this point, the string provided has not been found*/
184 if(notfounderror)
185 _error_("Enum " << name << " not found");
186 else
187 return -1;
188}
189END
190#}}}
191
192#clean up{{{
193rm temp
194#}}}
195#print info {{{
196printf "\r "
197printf "\rdone!\n"
198#}}}
Note: See TracBrowser for help on using the repository browser.