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

Last change on this file since 16560 was 16560, checked in by Mathieu Morlighem, 11 years ago

merged trunk-jpl and trunk for revision 16554

  • Property svn:executable set to *
File size: 5.7 KB
RevLine 
[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]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
[5227]6
[8224]7#Removed existing files
[12155]8rm $ISSM_DIR/src/m/enum/*.m
[12670]9rm $ISSM_DIR/src/m/enum/*.py
[14960]10rm $ISSM_DIR/src/c/shared/Enum/EnumToStringx.cpp
11rm $ISSM_DIR/src/c/shared/Enum/StringToEnumx.cpp
[5225]12
[11407]13#Get number of enums
14NUMENUMS=$(wc -l temp | awk '{printf("%s",$1);}');
15
[12262]16#Build EnumToStringx.cpp {{{
[8239]17#Header
[14960]18cat <<END > $ISSM_DIR/src/c/shared/Enum/EnumToStringx.cpp
[5225]19/*
[8224]20* \file EnumToStringx.cpp:
[5225]21* \brief: output string associated with enum
22*
23* WARNING: DO NOT MODIFY THIS FILE
[5227]24* this file has been automatically generated by Synchronize.sh
[5225]25* Please read README for more information
26*/
27
[12341]28#include <cstring>
[14960]29#include "./Enum.h"
30#include "../Exceptions/exceptions.h"
31#include "../MemOps/MemOps.h"
[5225]32
[11225]33const char* EnumToStringx(int en){
[5225]34
35 switch(en){
36
37END
[8239]38#core
[14960]39cat temp | awk '{print "\t\t" "case " $1" : return \"" substr($1,1,length($1)-4) "\";"}' >> $ISSM_DIR/src/c/shared/Enum/EnumToStringx.cpp
[8239]40#Footer
[14960]41cat <<END >> $ISSM_DIR/src/c/shared/Enum/EnumToStringx.cpp
[8239]42 default : return "unknown";
43
44 }
45}
[11225]46void EnumToStringx(char** pstring,int enum_in){
47 char *string = NULL;
48 int len = 0;
49
50 len=strlen(EnumToStringx(enum_in));
[12450]51 string=xNew<char>(len+1);
[11225]52 memcpy(string,EnumToStringx(enum_in),(len+1)*sizeof(char));
53
54 /*Assign output pointer*/
55 *pstring=string;
56}
[8239]57END
[5225]58#}}}
[12365]59#Build StringToEnumx.cpp {{{
[8239]60#Header
[14960]61cat <<END > $ISSM_DIR/src/c/shared/Enum/StringToEnumx.cpp
[5225]62/*
[8224]63* \file StringToEnumx.cpp:
[5225]64* \brief: output enum associated with string
65*
66* WARNING: DO NOT MODIFY THIS FILE
[5227]67* this file has been automatically generated by Synchronize.sh
[5225]68* Please read README for more information
69*/
70
[12342]71#include <cstring>
[14960]72#include "./Enum.h"
[14964]73#include "../Exceptions/exceptions.h"
[5225]74
[16560]75int StringToEnumx(const char* name,bool notfounderror){
[5225]76
[11404]77 int stage=1;
78
[5225]79END
[11404]80
[8239]81#core
[11404]82i1=1;
83i2=120;
84for (( i=1 ; i<=100 ; i++ )); do
[14960]85 echo " if(stage==$i){" >> $ISSM_DIR//src/c/shared/Enum/StringToEnumx.cpp
[11407]86 awk -v i1=$i1 -v i2=$i2 '{if(NR>=i1 && NR<=i2) print $0 }' temp |
[14960]87 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
88 echo " else stage=$(($i+1));" >> $ISSM_DIR//src/c/shared/Enum/StringToEnumx.cpp
89 echo " }" >> $ISSM_DIR//src/c/shared/Enum/StringToEnumx.cpp
[11404]90
[11407]91 if [ $i2 -ge $NUMENUMS ]; then break; fi
92 let i1=$i1+120
93 let i2=$i2+120
[11404]94done
95
[11407]96#footer
[14960]97cat <<END >> $ISSM_DIR/src/c/shared/Enum/StringToEnumx.cpp
[11407]98 /*If we reach this point, the string provided has not been found*/
[16560]99 if(notfounderror)
100 _error_("Enum " << name << " not found");
101 else
102 return -1;
[8239]103}
104END
[5225]105#}}}
[16560]106##Build EnumToAnalysis.cpp {{{
107##Header
108#cat <<END > $ISSM_DIR/src/c/analyses/EnumToAnalysis.cpp
109#/*
110#* \file EnumToAnalysis.cpp
111#* \brief: output class depending on enum
112#*
113#* WARNING: DO NOT MODIFY THIS FILE
114#* this file has been automatically generated by Synchronize.sh
115#* Please read README for more information
116#*/
117#
118##include "./analyses.h"
119##include "../shared/shared.h"
120#
121#Analysis* EnumToAnalysis(int analysis_enum){
122#
123# switch(analysis_enum){
124#END
125##core
126#cat temp | grep [a-z]Analysis | \
127# grep -v DefaultAnalysis | grep -v FlaimAnalysis | grep -v SurfaceSlopeAnalysis | grep -v BedSlopeAnalysis | \
128# 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"}' \
129# >> $ISSM_DIR/src/c/analyses/EnumToAnalysis.cpp
130#
131##Footer
132#cat <<END >> $ISSM_DIR/src/c/analyses/EnumToAnalysis.cpp
133#default : _error_("enum provided not supported ("<<EnumToStringx(analysis_enum)<<")");
134# }
135#}
136#END
137##}}}
[16137]138#Build EnumDefinitions.py{{{
[12670]139cat <<END > $ISSM_DIR/src/m/enum/EnumDefinitions.py
[13056]140from StringToEnum import StringToEnum
141
[12670]142"""
143
[16137]144WARNING: DO NOT MODIFY THIS FILE
145this file has been automatically generated by src/c/shared/Enum/Synchronize.sh
146Please read src/c/shared/Enum/README for more information
[12670]147
148"""
149
150END
[16137]151#core
152cat temp | awk '{print "def " $1"(): return StringToEnum(\"" substr($1,1,length($1)-4) "\")[0]"}' >> $ISSM_DIR/src/m/enum/EnumDefinitions.py
[12671]153#}}}
[12670]154
[16137]155# go through the lines of temp
156ENUM=0;
157
[12264]158for NAMEENUM in $(cat temp); do
[5225]159
160 #Get name and enum of the line i
161 NAME=$(echo $NAMEENUM | sed -e "s/Enum//g")
162 #offset Enum by one (Enum begins with 0 and not 1!)
[12264]163 let ENUM=$ENUM+1
[5225]164
165 #print info {{{
[12264]166 if [ $ENUM -lt 10 ]
[5225]167 then
168 printf "\r "
[12264]169 printf "\r $ENUM/$NUMENUMS Adding "$NAME"..."
[5225]170 else
[12264]171 if [ $ENUM -lt 100 ]
[5225]172 then
173 printf "\r "
[12264]174 printf "\r $ENUM/$NUMENUMS Adding "$NAME"..."
[5225]175 else
176 printf "\r "
[12264]177 printf "\r$ENUM/$NUMENUMS Adding "$NAME"..."
[5225]178 fi
179 fi
180 #}}}
181 #Add case to matlabenum file{{{
[12155]182 cat <<END > $ISSM_DIR"/src/m/enum/"$(echo $NAMEENUM".m")
[5225]183function macro=$(echo $NAMEENUM)()
[5687]184%$(echo $NAMEENUM | awk {'print toupper($1)'}) - Enum of $(echo $NAME)
[5225]185%
186% WARNING: DO NOT MODIFY THIS FILE
[14964]187% this file has been automatically generated by src/c/shared/Enum/Synchronize.sh
188% Please read src/c/shared/Enum/README for more information
[5225]189%
190% Usage:
191% macro=$NAMEENUM()
192
[8224]193macro=StringToEnum('$NAME');
[5225]194END
195#}}}
196
197done
198#clean up{{{
[11407]199rm temp
[5225]200#}}}
201#print info {{{
202printf "\r "
203printf "\rdone!\n"
204#}}}
Note: See TracBrowser for help on using the repository browser.