[5225] | 1 | #!/bin/bash
|
---|
[8224] | 2 | #Synchronize EnumToStringx.cpp and StringToEnumx.cpp and matlab Enums
|
---|
[5225] | 3 |
|
---|
[12670] | 4 | #Get all lines of EnumDefinitions2.h which hold Enum | remove all commas > put everything in file temp
|
---|
[16137] | 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
|
---|
[5227] | 6 |
|
---|
[8224] | 7 | #Removed existing files
|
---|
[14960] | 8 | rm $ISSM_DIR/src/c/shared/Enum/EnumToStringx.cpp
|
---|
| 9 | rm $ISSM_DIR/src/c/shared/Enum/StringToEnumx.cpp
|
---|
[5225] | 10 |
|
---|
[11407] | 11 | #Get number of enums
|
---|
| 12 | NUMENUMS=$(wc -l temp | awk '{printf("%s",$1);}');
|
---|
| 13 |
|
---|
[17806] | 14 | #Deal with Analyses
|
---|
[23189] | 15 | if true ; then
|
---|
[17806] | 16 | #Build EnumToAnalysis.cpp {{{
|
---|
| 17 | #Header
|
---|
| 18 | cat <<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 |
|
---|
| 31 | Analysis* EnumToAnalysis(int analysis_enum){
|
---|
| 32 |
|
---|
| 33 | switch(analysis_enum){
|
---|
| 34 | END
|
---|
| 35 | #core
|
---|
[17989] | 36 | cat temp | grep [a-zA-Z0-9]Analysis | \
|
---|
[17806] | 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
|
---|
| 42 | cat <<END >> $ISSM_DIR/src/c/analyses/EnumToAnalysis.cpp
|
---|
| 43 | default : _error_("enum provided not supported ("<<EnumToStringx(analysis_enum)<<")");
|
---|
| 44 | }
|
---|
| 45 | }
|
---|
| 46 | END
|
---|
| 47 | #}}}
|
---|
| 48 | #Build analyses.m4{{{
|
---|
| 49 | #Header
|
---|
| 50 | cat <<END > $ISSM_DIR/m4/analyses.m4
|
---|
| 51 |
|
---|
| 52 | dnl WARNING: DO NOT MODIFY THIS FILE
|
---|
| 53 | dnl this file has been automatically generated by Synchronize.sh
|
---|
| 54 | dnl Please read README for more information
|
---|
| 55 |
|
---|
| 56 | # AX_ANALYSES_SELECTION
|
---|
| 57 | # -----------------
|
---|
| 58 | # Check for analyses compilation
|
---|
| 59 | AC_DEFUN([AX_ANALYSES_SELECTION],
|
---|
| 60 | [
|
---|
| 61 |
|
---|
| 62 | END
|
---|
| 63 | #core
|
---|
[17989] | 64 | cat temp | grep [a-zA-Z0-9]Analysis | \
|
---|
[17806] | 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\
|
---|
| 68 | AC_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\
|
---|
| 71 | AC_MSG_CHECKING(for " $1" capability compilation)\n\n\
|
---|
| 72 | HAVE_" toupper($1)"=no \n\
|
---|
| 73 | if test \"x$" toupper($1)"\" = \"xyes\"; then\n\
|
---|
| 74 | HAVE_" toupper($1)"=yes\n\
|
---|
[19105] | 75 | AC_DEFINE([_HAVE_" toupper($1)"_],[1],[with " $1" capability])\n\
|
---|
[17806] | 76 | fi\n\
|
---|
| 77 | AM_CONDITIONAL([" toupper($1)"], [test x$HAVE_" toupper($1)" = xyes])\n\
|
---|
| 78 | AC_MSG_RESULT($HAVE_" toupper($1)")\n\
|
---|
| 79 | dnl }}}"}' \
|
---|
| 80 | >> $ISSM_DIR/m4/analyses.m4
|
---|
| 81 |
|
---|
| 82 | #Footer
|
---|
| 83 | cat <<END >> $ISSM_DIR/m4/analyses.m4
|
---|
| 84 |
|
---|
| 85 | ])
|
---|
| 86 | END
|
---|
| 87 | #}}}
|
---|
[22758] | 88 | fi
|
---|
[17806] | 89 |
|
---|
| 90 | #Enum to String conversions
|
---|
[12262] | 91 | #Build EnumToStringx.cpp {{{
|
---|
[8239] | 92 | #Header
|
---|
[14960] | 93 | cat <<END > $ISSM_DIR/src/c/shared/Enum/EnumToStringx.cpp
|
---|
[5225] | 94 | /*
|
---|
[8224] | 95 | * \file EnumToStringx.cpp:
|
---|
[5225] | 96 | * \brief: output string associated with enum
|
---|
| 97 | *
|
---|
| 98 | * WARNING: DO NOT MODIFY THIS FILE
|
---|
[5227] | 99 | * this file has been automatically generated by Synchronize.sh
|
---|
[5225] | 100 | * Please read README for more information
|
---|
| 101 | */
|
---|
| 102 |
|
---|
[12341] | 103 | #include <cstring>
|
---|
[14960] | 104 | #include "./Enum.h"
|
---|
| 105 | #include "../Exceptions/exceptions.h"
|
---|
| 106 | #include "../MemOps/MemOps.h"
|
---|
[5225] | 107 |
|
---|
[11225] | 108 | const char* EnumToStringx(int en){
|
---|
[5225] | 109 |
|
---|
| 110 | switch(en){
|
---|
| 111 |
|
---|
| 112 | END
|
---|
[8239] | 113 | #core
|
---|
[14960] | 114 | cat temp | awk '{print "\t\t" "case " $1" : return \"" substr($1,1,length($1)-4) "\";"}' >> $ISSM_DIR/src/c/shared/Enum/EnumToStringx.cpp
|
---|
[8239] | 115 | #Footer
|
---|
[14960] | 116 | cat <<END >> $ISSM_DIR/src/c/shared/Enum/EnumToStringx.cpp
|
---|
[8239] | 117 | default : return "unknown";
|
---|
| 118 |
|
---|
| 119 | }
|
---|
| 120 | }
|
---|
[11225] | 121 | void EnumToStringx(char** pstring,int enum_in){
|
---|
| 122 | char *string = NULL;
|
---|
| 123 | int len = 0;
|
---|
| 124 |
|
---|
| 125 | len=strlen(EnumToStringx(enum_in));
|
---|
[12450] | 126 | string=xNew<char>(len+1);
|
---|
[11225] | 127 | memcpy(string,EnumToStringx(enum_in),(len+1)*sizeof(char));
|
---|
| 128 |
|
---|
| 129 | /*Assign output pointer*/
|
---|
| 130 | *pstring=string;
|
---|
| 131 | }
|
---|
[23189] | 132 |
|
---|
| 133 | bool IsInputEnum(int enum_in){
|
---|
| 134 | if(enum_in>InputsSTARTEnum && enum_in<InputsENDEnum) return true;
|
---|
| 135 | return false;
|
---|
| 136 | }
|
---|
| 137 |
|
---|
| 138 | bool IsParamEnum(int enum_in){
|
---|
| 139 | if(enum_in>ParametersSTARTEnum && enum_in<ParametersENDEnum) return true;
|
---|
| 140 | return false;
|
---|
| 141 | }
|
---|
[8239] | 142 | END
|
---|
[5225] | 143 | #}}}
|
---|
[12365] | 144 | #Build StringToEnumx.cpp {{{
|
---|
[8239] | 145 | #Header
|
---|
[14960] | 146 | cat <<END > $ISSM_DIR/src/c/shared/Enum/StringToEnumx.cpp
|
---|
[5225] | 147 | /*
|
---|
[8224] | 148 | * \file StringToEnumx.cpp:
|
---|
[5225] | 149 | * \brief: output enum associated with string
|
---|
| 150 | *
|
---|
| 151 | * WARNING: DO NOT MODIFY THIS FILE
|
---|
[5227] | 152 | * this file has been automatically generated by Synchronize.sh
|
---|
[5225] | 153 | * Please read README for more information
|
---|
| 154 | */
|
---|
| 155 |
|
---|
[12342] | 156 | #include <cstring>
|
---|
[14960] | 157 | #include "./Enum.h"
|
---|
[14964] | 158 | #include "../Exceptions/exceptions.h"
|
---|
[5225] | 159 |
|
---|
[16560] | 160 | int StringToEnumx(const char* name,bool notfounderror){
|
---|
[5225] | 161 |
|
---|
[11404] | 162 | int stage=1;
|
---|
| 163 |
|
---|
[5225] | 164 | END
|
---|
[11404] | 165 |
|
---|
[8239] | 166 | #core
|
---|
[11404] | 167 | i1=1;
|
---|
| 168 | i2=120;
|
---|
| 169 | for (( i=1 ; i<=100 ; i++ )); do
|
---|
[14960] | 170 | echo " if(stage==$i){" >> $ISSM_DIR//src/c/shared/Enum/StringToEnumx.cpp
|
---|
[11407] | 171 | awk -v i1=$i1 -v i2=$i2 '{if(NR>=i1 && NR<=i2) print $0 }' temp |
|
---|
[14960] | 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
|
---|
[11404] | 175 |
|
---|
[11407] | 176 | if [ $i2 -ge $NUMENUMS ]; then break; fi
|
---|
| 177 | let i1=$i1+120
|
---|
| 178 | let i2=$i2+120
|
---|
[11404] | 179 | done
|
---|
| 180 |
|
---|
[11407] | 181 | #footer
|
---|
[14960] | 182 | cat <<END >> $ISSM_DIR/src/c/shared/Enum/StringToEnumx.cpp
|
---|
[11407] | 183 | /*If we reach this point, the string provided has not been found*/
|
---|
[16560] | 184 | if(notfounderror)
|
---|
| 185 | _error_("Enum " << name << " not found");
|
---|
| 186 | else
|
---|
| 187 | return -1;
|
---|
[8239] | 188 | }
|
---|
| 189 | END
|
---|
[5225] | 190 | #}}}
|
---|
[17806] | 191 |
|
---|
[5225] | 192 | #clean up{{{
|
---|
[11407] | 193 | rm temp
|
---|
[5225] | 194 | #}}}
|
---|
| 195 | #print info {{{
|
---|
| 196 | printf "\r "
|
---|
| 197 | printf "\rdone!\n"
|
---|
| 198 | #}}}
|
---|