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

Last change on this file since 27035 was 27035, checked in by Mathieu Morlighem, 3 years ago

merged trunk-jpl and trunk for revision 27033

  • Property svn:executable set to *
File size: 8.3 KB
RevLine 
[5225]1#!/bin/bash
[25836]2################################################################################
3# Synchronize EnumToStringx.cpp and StringToEnumx.cpp and MATLAB Enums
4#
5# Get all lines of EnumDefinitions.h which hold Enum | remove all commas > put everything in file temp
6#
7# NOTE: Even when run from this directory, ISSM_DIR must be defined correctly.
8#
[16137]9cat 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]10
[8224]11#Removed existing files
[14960]12rm $ISSM_DIR/src/c/shared/Enum/EnumToStringx.cpp
13rm $ISSM_DIR/src/c/shared/Enum/StringToEnumx.cpp
[5225]14
[11407]15#Get number of enums
16NUMENUMS=$(wc -l temp | awk '{printf("%s",$1);}');
17
[17806]18#Deal with Analyses
[24313]19if false ; then
[17806]20#Build EnumToAnalysis.cpp {{{
21#Header
22cat <<END > $ISSM_DIR/src/c/analyses/EnumToAnalysis.cpp
23/*
24* \file EnumToAnalysis.cpp
25* \brief: output class depending on enum
26*
27* WARNING: DO NOT MODIFY THIS FILE
28* this file has been automatically generated by Synchronize.sh
29* Please read README for more information
30*/
31
32#include "./analyses.h"
33#include "../shared/shared.h"
34
35Analysis* EnumToAnalysis(int analysis_enum){
36
37 switch(analysis_enum){
38END
39#core
[17989]40cat temp | grep [a-zA-Z0-9]Analysis | \
[26744]41 grep -v DefaultAnalysis | grep -v RecoveryAnalysis | grep -v FlaimAnalysis | grep -v SurfaceSlopeAnalysis | grep -v BedSlopeAnalysis | \
[17806]42 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"}' \
43 >> $ISSM_DIR/src/c/analyses/EnumToAnalysis.cpp
44
45#Footer
46cat <<END >> $ISSM_DIR/src/c/analyses/EnumToAnalysis.cpp
47 default : _error_("enum provided not supported ("<<EnumToStringx(analysis_enum)<<")");
48 }
49}
50END
51#}}}
52#Build analyses.m4{{{
53#Header
54cat <<END > $ISSM_DIR/m4/analyses.m4
55
56dnl WARNING: DO NOT MODIFY THIS FILE
57dnl this file has been automatically generated by Synchronize.sh
58dnl Please read README for more information
59
60# AX_ANALYSES_SELECTION
61# -----------------
62# Check for analyses compilation
63AC_DEFUN([AX_ANALYSES_SELECTION],
64[
65
66END
67#core
[17989]68cat temp | grep [a-zA-Z0-9]Analysis | \
[17806]69 grep -v DefaultAnalysis | grep -v FlaimAnalysis | grep -v SurfaceSlopeAnalysis | grep -v BedSlopeAnalysis | \
70 sed -e "s/AnalysisEnum//g" | \
71 awk '{print "dnl with-" $1"{{{\n\
72AC_ARG_WITH([" $1"],\n\
73\tAS_HELP_STRING([--with-" $1" = YES], [compile with " $1" capabilities (default is yes)]),\n\
74\t[" toupper($1)"=$withval],[" toupper($1)"=yes])\n\
75AC_MSG_CHECKING(for " $1" capability compilation)\n\n\
76HAVE_" toupper($1)"=no \n\
77if test \"x$" toupper($1)"\" = \"xyes\"; then\n\
78 HAVE_" toupper($1)"=yes\n\
[19105]79 AC_DEFINE([_HAVE_" toupper($1)"_],[1],[with " $1" capability])\n\
[17806]80fi\n\
81AM_CONDITIONAL([" toupper($1)"], [test x$HAVE_" toupper($1)" = xyes])\n\
82AC_MSG_RESULT($HAVE_" toupper($1)")\n\
83dnl }}}"}' \
84 >> $ISSM_DIR/m4/analyses.m4
85
86#Footer
87cat <<END >> $ISSM_DIR/m4/analyses.m4
88
89])
90END
91#}}}
[22758]92fi
[17806]93
94#Enum to String conversions
[12262]95#Build EnumToStringx.cpp {{{
[8239]96#Header
[14960]97cat <<END > $ISSM_DIR/src/c/shared/Enum/EnumToStringx.cpp
[5225]98/*
[8224]99* \file EnumToStringx.cpp:
[5225]100* \brief: output string associated with enum
101*
102* WARNING: DO NOT MODIFY THIS FILE
[5227]103* this file has been automatically generated by Synchronize.sh
[5225]104* Please read README for more information
105*/
106
[12341]107#include <cstring>
[14960]108#include "./Enum.h"
109#include "../Exceptions/exceptions.h"
110#include "../MemOps/MemOps.h"
[5225]111
[11225]112const char* EnumToStringx(int en){
[5225]113
114 switch(en){
115
116END
[8239]117#core
[14960]118cat temp | awk '{print "\t\t" "case " $1" : return \"" substr($1,1,length($1)-4) "\";"}' >> $ISSM_DIR/src/c/shared/Enum/EnumToStringx.cpp
[8239]119#Footer
[14960]120cat <<END >> $ISSM_DIR/src/c/shared/Enum/EnumToStringx.cpp
[8239]121 default : return "unknown";
122
123 }
124}
[11225]125void EnumToStringx(char** pstring,int enum_in){
126 char *string = NULL;
127 int len = 0;
128
129 len=strlen(EnumToStringx(enum_in));
[12450]130 string=xNew<char>(len+1);
[11225]131 memcpy(string,EnumToStringx(enum_in),(len+1)*sizeof(char));
132
133 /*Assign output pointer*/
134 *pstring=string;
135}
[23189]136
137bool IsInputEnum(int enum_in){
138 if(enum_in>InputsSTARTEnum && enum_in<InputsENDEnum) return true;
139 return false;
140}
141
142bool IsParamEnum(int enum_in){
143 if(enum_in>ParametersSTARTEnum && enum_in<ParametersENDEnum) return true;
144 return false;
145}
[8239]146END
[5225]147#}}}
[12365]148#Build StringToEnumx.cpp {{{
[8239]149#Header
[14960]150cat <<END > $ISSM_DIR/src/c/shared/Enum/StringToEnumx.cpp
[5225]151/*
[8224]152* \file StringToEnumx.cpp:
[5225]153* \brief: output enum associated with string
154*
155* WARNING: DO NOT MODIFY THIS FILE
[5227]156* this file has been automatically generated by Synchronize.sh
[5225]157* Please read README for more information
158*/
159
[12342]160#include <cstring>
[14960]161#include "./Enum.h"
[14964]162#include "../Exceptions/exceptions.h"
[5225]163
[16560]164int StringToEnumx(const char* name,bool notfounderror){
[5225]165
[11404]166 int stage=1;
167
[5225]168END
[11404]169
[8239]170#core
[11404]171i1=1;
172i2=120;
173for (( i=1 ; i<=100 ; i++ )); do
[14960]174 echo " if(stage==$i){" >> $ISSM_DIR//src/c/shared/Enum/StringToEnumx.cpp
[11407]175 awk -v i1=$i1 -v i2=$i2 '{if(NR>=i1 && NR<=i2) print $0 }' temp |
[14960]176 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
177 echo " else stage=$(($i+1));" >> $ISSM_DIR//src/c/shared/Enum/StringToEnumx.cpp
178 echo " }" >> $ISSM_DIR//src/c/shared/Enum/StringToEnumx.cpp
[24313]179
[11407]180 if [ $i2 -ge $NUMENUMS ]; then break; fi
181 let i1=$i1+120
182 let i2=$i2+120
[11404]183done
184
[11407]185#footer
[14960]186cat <<END >> $ISSM_DIR/src/c/shared/Enum/StringToEnumx.cpp
[11407]187 /*If we reach this point, the string provided has not been found*/
[16560]188 if(notfounderror)
189 _error_("Enum " << name << " not found");
190 else
191 return -1;
[8239]192}
193END
[5225]194#}}}
[27035]195#Build issmenum.jl {{{
196#Header
197cat <<END > $ISSM_DIR/src/c/shared/Enum/issmenums.jl
198# WARNING: DO NOT MODIFY THIS FILE
199# this file has been automatically generated by Synchronize.sh
200# Please read README for more information
[17806]201
[27035]202@enum IssmEnum begin
203END
204cat temp | awk '{print "\t" $1}' >> $ISSM_DIR/src/c/shared/Enum/issmenums.jl
205#Move on to EnumToString
206cat <<END >> $ISSM_DIR/src/c/shared/Enum/issmenums.jl
207end
208
209function EnumToString(enum::IssmEnum)
210END
211cat temp | awk '{print "\tif(enum==" $1 ") return \"" substr($1,1,length($1)-4) "\" end"}' >> $ISSM_DIR/src/c/shared/Enum/issmenums.jl
212#Move on to StringToEnumx
213cat <<END >> $ISSM_DIR/src/c/shared/Enum/issmenums.jl
214end
215END
216#}}}
217
[24313]218#vim file
219#Build Enum.vim{{{
220#Header
221cat <<END > $ISSM_DIR/src/c/shared/Enum/Enum.vim
222""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
223" ISSM specific c syntax highlighting
224"
225" WARNING: DO NOT MODIFY THIS FILE
226" this file has been automatically generated by Synchronize.sh
227" Please read README for more information
228""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
229
230"PETSc
231syn keyword cType Vec Mat SeqVec SeqMat
232
233"ISSM typedefs
234syn keyword cType mxArray ErrorException QuadtreeBox
235syn keyword cType IssmDouble IssmPDouble
236
237"ISSM Enums
238END
239cat temp | awk '{print "syn keyword cConstant " $1}' >> $ISSM_DIR/src/c/shared/Enum/Enum.vim
240cat <<END >> $ISSM_DIR/src/c/shared/Enum/Enum.vim
241"ISSM Enums end
242END
243
244#Synchronize ISSM objects objects
245cat <<END >> $ISSM_DIR/src/c/shared/Enum/Enum.vim
246
247"ISSM objects
248END
249find $ISSM_DIR/src/c/classes -name "*.cpp" -o -name "*.h" | sed -e "s/\// /g" -e "s/\.cpp//" -e "s/\.h//" | awk '{print $(NF)}' | sort | uniq | awk '{ printf "syn keyword cType " $1 "\n"}'>> $ISSM_DIR/src/c/shared/Enum/Enum.vim
250find $ISSM_DIR/src/c/analyses -name "*Analysis.h" | sed -e "s/\// /g" -e "s/\.cpp//" -e "s/\.h//" | awk '{print $(NF)}' | sort | uniq | awk '{ printf "syn keyword cType " $1 "\n"}'>> $ISSM_DIR/src/c/shared/Enum/Enum.vim
251echo "\"ISSM objects end" >> $ISSM_DIR/src/c/shared/Enum/Enum.vim
252#}}}
[26744]253#Build Enumjl.vim{{{
254#Header
255cat <<END > $ISSM_DIR/src/c/shared/Enum/Enumjl.vim
256""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
257" ISSM specific julia syntax highlighting
258"
259" WARNING: DO NOT MODIFY THIS FILE
260" this file has been automatically generated by Synchronize.sh
261" Please read README for more information
262""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
[24313]263
[26744]264"ISSM Enums
265END
266cat temp | awk '{print "syn keyword juliaConstC " $1}' >> $ISSM_DIR/src/c/shared/Enum/Enumjl.vim
267cat <<END >> $ISSM_DIR/src/c/shared/Enum/Enumjl.vim
268"ISSM Enums end
269END
270#}}}
271
[5225]272#clean up{{{
[11407]273rm temp
[5225]274#}}}
275#print info {{{
276printf "\r "
277printf "\rdone!\n"
278#}}}
Note: See TracBrowser for help on using the repository browser.