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

Last change on this file since 16137 was 16137, checked in by Mathieu Morlighem, 12 years ago

merged trunk-jpl and trunk for revision 16135

  • Property svn:executable set to *
File size: 4.6 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
[11225]75int StringToEnumx(const char* name){
[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*/
[13054]99 _error_("Enum " << name << " not found");
[8239]100}
101END
[5225]102#}}}
[16137]103#Build EnumDefinitions.py{{{
[12670]104cat <<END > $ISSM_DIR/src/m/enum/EnumDefinitions.py
[13056]105from StringToEnum import StringToEnum
106
[12670]107"""
108
[16137]109WARNING: DO NOT MODIFY THIS FILE
110this file has been automatically generated by src/c/shared/Enum/Synchronize.sh
111Please read src/c/shared/Enum/README for more information
[12670]112
113"""
114
115END
[16137]116#core
117cat temp | awk '{print "def " $1"(): return StringToEnum(\"" substr($1,1,length($1)-4) "\")[0]"}' >> $ISSM_DIR/src/m/enum/EnumDefinitions.py
[12671]118#}}}
[12670]119
[16137]120# go through the lines of temp
121ENUM=0;
122
[12264]123for NAMEENUM in $(cat temp); do
[5225]124
125 #Get name and enum of the line i
126 NAME=$(echo $NAMEENUM | sed -e "s/Enum//g")
127 #offset Enum by one (Enum begins with 0 and not 1!)
[12264]128 let ENUM=$ENUM+1
[5225]129
130 #print info {{{
[12264]131 if [ $ENUM -lt 10 ]
[5225]132 then
133 printf "\r "
[12264]134 printf "\r $ENUM/$NUMENUMS Adding "$NAME"..."
[5225]135 else
[12264]136 if [ $ENUM -lt 100 ]
[5225]137 then
138 printf "\r "
[12264]139 printf "\r $ENUM/$NUMENUMS Adding "$NAME"..."
[5225]140 else
141 printf "\r "
[12264]142 printf "\r$ENUM/$NUMENUMS Adding "$NAME"..."
[5225]143 fi
144 fi
145 #}}}
146 #Add case to matlabenum file{{{
[12155]147 cat <<END > $ISSM_DIR"/src/m/enum/"$(echo $NAMEENUM".m")
[5225]148function macro=$(echo $NAMEENUM)()
[5687]149%$(echo $NAMEENUM | awk {'print toupper($1)'}) - Enum of $(echo $NAME)
[5225]150%
151% WARNING: DO NOT MODIFY THIS FILE
[14964]152% this file has been automatically generated by src/c/shared/Enum/Synchronize.sh
153% Please read src/c/shared/Enum/README for more information
[5225]154%
155% Usage:
156% macro=$NAMEENUM()
157
[8224]158macro=StringToEnum('$NAME');
[5225]159END
160#}}}
161
162done
163#clean up{{{
[11407]164rm temp
[5225]165#}}}
166#print info {{{
167printf "\r "
168printf "\rdone!\n"
169#}}}
Note: See TracBrowser for help on using the repository browser.