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

Last change on this file since 21341 was 21341, checked in by Mathieu Morlighem, 8 years ago

merged trunk-jpl and trunk for revision 21337

  • Property svn:executable set to *
File size: 5.2 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
15#Build EnumToAnalysis.cpp {{{
16#Header
17cat <<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
30Analysis* EnumToAnalysis(int analysis_enum){
31
32 switch(analysis_enum){
33END
34#core
35cat 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
41cat <<END >> $ISSM_DIR/src/c/analyses/EnumToAnalysis.cpp
42 default : _error_("enum provided not supported ("<<EnumToStringx(analysis_enum)<<")");
43 }
44}
45END
46#}}}
47#Build analyses.m4{{{
48#Header
49cat <<END > $ISSM_DIR/m4/analyses.m4
50
51dnl WARNING: DO NOT MODIFY THIS FILE
52dnl this file has been automatically generated by Synchronize.sh
53dnl Please read README for more information
54
55# AX_ANALYSES_SELECTION
56# -----------------
57# Check for analyses compilation
58AC_DEFUN([AX_ANALYSES_SELECTION],
59[
60
61END
62#core
63cat 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\
67AC_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\
70AC_MSG_CHECKING(for " $1" capability compilation)\n\n\
71HAVE_" toupper($1)"=no \n\
72if test \"x$" toupper($1)"\" = \"xyes\"; then\n\
73 HAVE_" toupper($1)"=yes\n\
74 AC_DEFINE([_HAVE_" toupper($1)"_],[1],[with " $1" capability])\n\
75fi\n\
76AM_CONDITIONAL([" toupper($1)"], [test x$HAVE_" toupper($1)" = xyes])\n\
77AC_MSG_RESULT($HAVE_" toupper($1)")\n\
78dnl }}}"}' \
79 >> $ISSM_DIR/m4/analyses.m4
80
81#Footer
82cat <<END >> $ISSM_DIR/m4/analyses.m4
83
84])
85END
86#}}}
87
88#Enum to String conversions
89#Build EnumToStringx.cpp {{{
90#Header
91cat <<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
106const char* EnumToStringx(int en){
107
108 switch(en){
109
110END
111#core
112cat temp | awk '{print "\t\t" "case " $1" : return \"" substr($1,1,length($1)-4) "\";"}' >> $ISSM_DIR/src/c/shared/Enum/EnumToStringx.cpp
113#Footer
114cat <<END >> $ISSM_DIR/src/c/shared/Enum/EnumToStringx.cpp
115 default : return "unknown";
116
117 }
118}
119void 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}
130END
131#}}}
132#Build StringToEnumx.cpp {{{
133#Header
134cat <<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
148int StringToEnumx(const char* name,bool notfounderror){
149
150 int stage=1;
151
152END
153
154#core
155i1=1;
156i2=120;
157for (( 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
167done
168
169#footer
170cat <<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}
177END
178#}}}
179
180#clean up{{{
181rm temp
182#}}}
183#print info {{{
184printf "\r "
185printf "\rdone!\n"
186#}}}
Note: See TracBrowser for help on using the repository browser.