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
|
---|
5 | 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
|
---|
6 |
|
---|
7 | #Removed existing files
|
---|
8 | rm $ISSM_DIR/src/c/shared/Enum/EnumToStringx.cpp
|
---|
9 | rm $ISSM_DIR/src/c/shared/Enum/StringToEnumx.cpp
|
---|
10 |
|
---|
11 | #Get number of enums
|
---|
12 | NUMENUMS=$(wc -l temp | awk '{printf("%s",$1);}');
|
---|
13 |
|
---|
14 | #Deal with Analyses
|
---|
15 | #Build EnumToAnalysis.cpp {{{
|
---|
16 | #Header
|
---|
17 | cat <<END > $ISSM_DIR/src/c/analyses/EnumToAnalysis.cpp
|
---|
18 | /*
|
---|
19 | * \file EnumToAnalysis.cpp
|
---|
20 | * \brief: output class depending on enum
|
---|
21 | *
|
---|
22 | * WARNING: DO NOT MODIFY THIS FILE
|
---|
23 | * this file has been automatically generated by Synchronize.sh
|
---|
24 | * Please read README for more information
|
---|
25 | */
|
---|
26 |
|
---|
27 | #include "./analyses.h"
|
---|
28 | #include "../shared/shared.h"
|
---|
29 |
|
---|
30 | Analysis* EnumToAnalysis(int analysis_enum){
|
---|
31 |
|
---|
32 | switch(analysis_enum){
|
---|
33 | END
|
---|
34 | #core
|
---|
35 | cat temp | grep [a-zA-Z0-9]Analysis | \
|
---|
36 | grep -v DefaultAnalysis | grep -v FlaimAnalysis | grep -v SurfaceSlopeAnalysis | grep -v BedSlopeAnalysis | \
|
---|
37 | 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"}' \
|
---|
38 | >> $ISSM_DIR/src/c/analyses/EnumToAnalysis.cpp
|
---|
39 |
|
---|
40 | #Footer
|
---|
41 | cat <<END >> $ISSM_DIR/src/c/analyses/EnumToAnalysis.cpp
|
---|
42 | default : _error_("enum provided not supported ("<<EnumToStringx(analysis_enum)<<")");
|
---|
43 | }
|
---|
44 | }
|
---|
45 | END
|
---|
46 | #}}}
|
---|
47 | #Build analyses.m4{{{
|
---|
48 | #Header
|
---|
49 | cat <<END > $ISSM_DIR/m4/analyses.m4
|
---|
50 |
|
---|
51 | dnl WARNING: DO NOT MODIFY THIS FILE
|
---|
52 | dnl this file has been automatically generated by Synchronize.sh
|
---|
53 | dnl Please read README for more information
|
---|
54 |
|
---|
55 | # AX_ANALYSES_SELECTION
|
---|
56 | # -----------------
|
---|
57 | # Check for analyses compilation
|
---|
58 | AC_DEFUN([AX_ANALYSES_SELECTION],
|
---|
59 | [
|
---|
60 |
|
---|
61 | END
|
---|
62 | #core
|
---|
63 | cat temp | grep [a-zA-Z0-9]Analysis | \
|
---|
64 | grep -v DefaultAnalysis | grep -v FlaimAnalysis | grep -v SurfaceSlopeAnalysis | grep -v BedSlopeAnalysis | \
|
---|
65 | sed -e "s/AnalysisEnum//g" | \
|
---|
66 | awk '{print "dnl with-" $1"{{{\n\
|
---|
67 | AC_ARG_WITH([" $1"],\n\
|
---|
68 | \tAS_HELP_STRING([--with-" $1" = YES], [compile with " $1" capabilities (default is yes)]),\n\
|
---|
69 | \t[" toupper($1)"=$withval],[" toupper($1)"=yes])\n\
|
---|
70 | AC_MSG_CHECKING(for " $1" capability compilation)\n\n\
|
---|
71 | HAVE_" toupper($1)"=no \n\
|
---|
72 | if test \"x$" toupper($1)"\" = \"xyes\"; then\n\
|
---|
73 | HAVE_" toupper($1)"=yes\n\
|
---|
74 | AC_DEFINE([_HAVE_" toupper($1)"_],[1],[with " $1" capability])\n\
|
---|
75 | fi\n\
|
---|
76 | AM_CONDITIONAL([" toupper($1)"], [test x$HAVE_" toupper($1)" = xyes])\n\
|
---|
77 | AC_MSG_RESULT($HAVE_" toupper($1)")\n\
|
---|
78 | dnl }}}"}' \
|
---|
79 | >> $ISSM_DIR/m4/analyses.m4
|
---|
80 |
|
---|
81 | #Footer
|
---|
82 | cat <<END >> $ISSM_DIR/m4/analyses.m4
|
---|
83 |
|
---|
84 | ])
|
---|
85 | END
|
---|
86 | #}}}
|
---|
87 |
|
---|
88 | #Enum to String conversions
|
---|
89 | #Build EnumToStringx.cpp {{{
|
---|
90 | #Header
|
---|
91 | cat <<END > $ISSM_DIR/src/c/shared/Enum/EnumToStringx.cpp
|
---|
92 | /*
|
---|
93 | * \file EnumToStringx.cpp:
|
---|
94 | * \brief: output string associated with enum
|
---|
95 | *
|
---|
96 | * WARNING: DO NOT MODIFY THIS FILE
|
---|
97 | * this file has been automatically generated by Synchronize.sh
|
---|
98 | * Please read README for more information
|
---|
99 | */
|
---|
100 |
|
---|
101 | #include <cstring>
|
---|
102 | #include "./Enum.h"
|
---|
103 | #include "../Exceptions/exceptions.h"
|
---|
104 | #include "../MemOps/MemOps.h"
|
---|
105 |
|
---|
106 | const char* EnumToStringx(int en){
|
---|
107 |
|
---|
108 | switch(en){
|
---|
109 |
|
---|
110 | END
|
---|
111 | #core
|
---|
112 | cat temp | awk '{print "\t\t" "case " $1" : return \"" substr($1,1,length($1)-4) "\";"}' >> $ISSM_DIR/src/c/shared/Enum/EnumToStringx.cpp
|
---|
113 | #Footer
|
---|
114 | cat <<END >> $ISSM_DIR/src/c/shared/Enum/EnumToStringx.cpp
|
---|
115 | default : return "unknown";
|
---|
116 |
|
---|
117 | }
|
---|
118 | }
|
---|
119 | void EnumToStringx(char** pstring,int enum_in){
|
---|
120 | char *string = NULL;
|
---|
121 | int len = 0;
|
---|
122 |
|
---|
123 | len=strlen(EnumToStringx(enum_in));
|
---|
124 | string=xNew<char>(len+1);
|
---|
125 | memcpy(string,EnumToStringx(enum_in),(len+1)*sizeof(char));
|
---|
126 |
|
---|
127 | /*Assign output pointer*/
|
---|
128 | *pstring=string;
|
---|
129 | }
|
---|
130 | END
|
---|
131 | #}}}
|
---|
132 | #Build StringToEnumx.cpp {{{
|
---|
133 | #Header
|
---|
134 | cat <<END > $ISSM_DIR/src/c/shared/Enum/StringToEnumx.cpp
|
---|
135 | /*
|
---|
136 | * \file StringToEnumx.cpp:
|
---|
137 | * \brief: output enum associated with string
|
---|
138 | *
|
---|
139 | * WARNING: DO NOT MODIFY THIS FILE
|
---|
140 | * this file has been automatically generated by Synchronize.sh
|
---|
141 | * Please read README for more information
|
---|
142 | */
|
---|
143 |
|
---|
144 | #include <cstring>
|
---|
145 | #include "./Enum.h"
|
---|
146 | #include "../Exceptions/exceptions.h"
|
---|
147 |
|
---|
148 | int StringToEnumx(const char* name,bool notfounderror){
|
---|
149 |
|
---|
150 | int stage=1;
|
---|
151 |
|
---|
152 | END
|
---|
153 |
|
---|
154 | #core
|
---|
155 | i1=1;
|
---|
156 | i2=120;
|
---|
157 | for (( i=1 ; i<=100 ; i++ )); do
|
---|
158 | echo " if(stage==$i){" >> $ISSM_DIR//src/c/shared/Enum/StringToEnumx.cpp
|
---|
159 | awk -v i1=$i1 -v i2=$i2 '{if(NR>=i1 && NR<=i2) print $0 }' temp |
|
---|
160 | 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
|
---|
161 | echo " else stage=$(($i+1));" >> $ISSM_DIR//src/c/shared/Enum/StringToEnumx.cpp
|
---|
162 | echo " }" >> $ISSM_DIR//src/c/shared/Enum/StringToEnumx.cpp
|
---|
163 |
|
---|
164 | if [ $i2 -ge $NUMENUMS ]; then break; fi
|
---|
165 | let i1=$i1+120
|
---|
166 | let i2=$i2+120
|
---|
167 | done
|
---|
168 |
|
---|
169 | #footer
|
---|
170 | cat <<END >> $ISSM_DIR/src/c/shared/Enum/StringToEnumx.cpp
|
---|
171 | /*If we reach this point, the string provided has not been found*/
|
---|
172 | if(notfounderror)
|
---|
173 | _error_("Enum " << name << " not found");
|
---|
174 | else
|
---|
175 | return -1;
|
---|
176 | }
|
---|
177 | END
|
---|
178 | #}}}
|
---|
179 |
|
---|
180 | #clean up{{{
|
---|
181 | rm temp
|
---|
182 | #}}}
|
---|
183 | #print info {{{
|
---|
184 | printf "\r "
|
---|
185 | printf "\rdone!\n"
|
---|
186 | #}}}
|
---|