| 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/m/enum/*.m
|
|---|
| 9 | rm $ISSM_DIR/src/m/enum/*.py
|
|---|
| 10 | rm $ISSM_DIR/src/c/shared/Enum/EnumToStringx.cpp
|
|---|
| 11 | rm $ISSM_DIR/src/c/shared/Enum/StringToEnumx.cpp
|
|---|
| 12 |
|
|---|
| 13 | #Get number of enums
|
|---|
| 14 | NUMENUMS=$(wc -l temp | awk '{printf("%s",$1);}');
|
|---|
| 15 |
|
|---|
| 16 | #Deal with Analyses
|
|---|
| 17 | #Build EnumToAnalysis.cpp {{{
|
|---|
| 18 | #Header
|
|---|
| 19 | cat <<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 |
|
|---|
| 32 | Analysis* EnumToAnalysis(int analysis_enum){
|
|---|
| 33 |
|
|---|
| 34 | switch(analysis_enum){
|
|---|
| 35 | END
|
|---|
| 36 | #core
|
|---|
| 37 | cat 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
|
|---|
| 43 | cat <<END >> $ISSM_DIR/src/c/analyses/EnumToAnalysis.cpp
|
|---|
| 44 | default : _error_("enum provided not supported ("<<EnumToStringx(analysis_enum)<<")");
|
|---|
| 45 | }
|
|---|
| 46 | }
|
|---|
| 47 | END
|
|---|
| 48 | #}}}
|
|---|
| 49 | #Build analyses.m4{{{
|
|---|
| 50 | #Header
|
|---|
| 51 | cat <<END > $ISSM_DIR/m4/analyses.m4
|
|---|
| 52 |
|
|---|
| 53 | dnl WARNING: DO NOT MODIFY THIS FILE
|
|---|
| 54 | dnl this file has been automatically generated by Synchronize.sh
|
|---|
| 55 | dnl Please read README for more information
|
|---|
| 56 |
|
|---|
| 57 | # AX_ANALYSES_SELECTION
|
|---|
| 58 | # -----------------
|
|---|
| 59 | # Check for analyses compilation
|
|---|
| 60 | AC_DEFUN([AX_ANALYSES_SELECTION],
|
|---|
| 61 | [
|
|---|
| 62 |
|
|---|
| 63 | END
|
|---|
| 64 | #core
|
|---|
| 65 | cat 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\
|
|---|
| 69 | AC_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\
|
|---|
| 72 | AC_MSG_CHECKING(for " $1" capability compilation)\n\n\
|
|---|
| 73 | HAVE_" toupper($1)"=no \n\
|
|---|
| 74 | if test \"x$" toupper($1)"\" = \"xyes\"; then\n\
|
|---|
| 75 | HAVE_" toupper($1)"=yes\n\
|
|---|
| 76 | AC_DEFINE([_HAVE_" toupper($1)"_],[1],[with " $1" capability])\n\
|
|---|
| 77 | fi\n\
|
|---|
| 78 | AM_CONDITIONAL([" toupper($1)"], [test x$HAVE_" toupper($1)" = xyes])\n\
|
|---|
| 79 | AC_MSG_RESULT($HAVE_" toupper($1)")\n\
|
|---|
| 80 | dnl }}}"}' \
|
|---|
| 81 | >> $ISSM_DIR/m4/analyses.m4
|
|---|
| 82 |
|
|---|
| 83 | #Footer
|
|---|
| 84 | cat <<END >> $ISSM_DIR/m4/analyses.m4
|
|---|
| 85 |
|
|---|
| 86 | ])
|
|---|
| 87 | END
|
|---|
| 88 | #}}}
|
|---|
| 89 |
|
|---|
| 90 | #Enum to String conversions
|
|---|
| 91 | #Build EnumToStringx.cpp {{{
|
|---|
| 92 | #Header
|
|---|
| 93 | cat <<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 |
|
|---|
| 108 | const char* EnumToStringx(int en){
|
|---|
| 109 |
|
|---|
| 110 | switch(en){
|
|---|
| 111 |
|
|---|
| 112 | END
|
|---|
| 113 | #core
|
|---|
| 114 | cat temp | awk '{print "\t\t" "case " $1" : return \"" substr($1,1,length($1)-4) "\";"}' >> $ISSM_DIR/src/c/shared/Enum/EnumToStringx.cpp
|
|---|
| 115 | #Footer
|
|---|
| 116 | cat <<END >> $ISSM_DIR/src/c/shared/Enum/EnumToStringx.cpp
|
|---|
| 117 | default : return "unknown";
|
|---|
| 118 |
|
|---|
| 119 | }
|
|---|
| 120 | }
|
|---|
| 121 | void 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 | END
|
|---|
| 133 | #}}}
|
|---|
| 134 | #Build StringToEnumx.cpp {{{
|
|---|
| 135 | #Header
|
|---|
| 136 | cat <<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 |
|
|---|
| 150 | int StringToEnumx(const char* name,bool notfounderror){
|
|---|
| 151 |
|
|---|
| 152 | int stage=1;
|
|---|
| 153 |
|
|---|
| 154 | END
|
|---|
| 155 |
|
|---|
| 156 | #core
|
|---|
| 157 | i1=1;
|
|---|
| 158 | i2=120;
|
|---|
| 159 | for (( 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
|
|---|
| 169 | done
|
|---|
| 170 |
|
|---|
| 171 | #footer
|
|---|
| 172 | cat <<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 | }
|
|---|
| 179 | END
|
|---|
| 180 | #}}}
|
|---|
| 181 |
|
|---|
| 182 | #Deal with Python Enums
|
|---|
| 183 | #Build EnumDefinitions.py{{{
|
|---|
| 184 | cat <<END > $ISSM_DIR/src/m/enum/EnumDefinitions.py
|
|---|
| 185 | from StringToEnum import StringToEnum
|
|---|
| 186 |
|
|---|
| 187 | """
|
|---|
| 188 |
|
|---|
| 189 | WARNING: DO NOT MODIFY THIS FILE
|
|---|
| 190 | this file has been automatically generated by src/c/shared/Enum/Synchronize.sh
|
|---|
| 191 | Please read src/c/shared/Enum/README for more information
|
|---|
| 192 |
|
|---|
| 193 | """
|
|---|
| 194 |
|
|---|
| 195 | END
|
|---|
| 196 | #core
|
|---|
| 197 | cat 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`
|
|---|
| 201 | ENUM=0;
|
|---|
| 202 |
|
|---|
| 203 | for 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")
|
|---|
| 228 | function 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 |
|
|---|
| 238 | macro=StringToEnum('$NAME');
|
|---|
| 239 | END
|
|---|
| 240 | #}}}
|
|---|
| 241 |
|
|---|
| 242 | done
|
|---|
| 243 | #clean up{{{
|
|---|
| 244 | rm temp
|
|---|
| 245 | #}}}
|
|---|
| 246 | #print info {{{
|
|---|
| 247 | printf "\r "
|
|---|
| 248 | printf "\rdone!\n"
|
|---|
| 249 | #}}}
|
|---|