Changeset 3677


Ignore:
Timestamp:
05/10/10 11:28:57 (15 years ago)
Author:
Mathieu Morlighem
Message:

Added EnumAsString.cpp and StringAsEnum.cpp

Location:
issm/trunk/src/c/EnumDefinitions
Files:
3 added
2 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk/src/c/EnumDefinitions/SynchronizeMatlabEnum.sh

    r3674 r3677  
    1111cat EnumDefinitions.h | grep "Enum," |sed -e "s/,//g" | awk '{ printf "%s %s\n", NR, $0 }' > temp
    1212
    13 #Build File AnalysisTypeFromEnum.m
     13#Build header of AnalysisTypeFromEnum.m{{{
    1414cat <<END > AnalysisTypeFromEnum.m
    1515function string=AnalysisTypeFromEnum(enum)
    1616%ANALYSISASENUM - get analysis type from Enum
    1717%
    18 %   file generated by src/c/SynchronizeMatlabEnum
    19 %   to be synchronized with the corresponding C Enum
    20 %   located in src/c/EnumDefinitions
     18%   WARNING: DO NOT MODIFY THIS FILE
     19%            this file has been automatically generated by src/c/SynchronizeMatlabEnum
     20%            Please read src/c/README for more information
    2121%
    2222%   Usage:
     
    2626string='not found';
    2727END
     28#}}}
    2829
    2930#get number of lines in temp
     
    3940        let ENUM=$ENUM-1
    4041
    41         #write corresponding Matlab file
    42         #print info
     42        #print info {{{
    4343        if [ $i -lt 10 ]
    4444        then
     
    5555                fi
    5656        fi
    57 
     57        #}}}
     58        #Add case to matlabenum file{{{
    5859        cat <<END > $(echo $NAME".m")
    5960function macro=$(echo $NAME)()
    6061%$(echo `echo $NAME | sed -e "s/[a-z]/\U&/g"`) - Enum of $(echo `echo $NAME | sed -e "s/Enum//"`)
    6162%
    62 %   file generated by src/c/EnumDefinitions/SynchronizeMatlabEnum
     63%   WARNING: DO NOT MODIFY THIS FILE
     64%            this file has been automatically generated by src/c/SynchronizeMatlabEnum
     65%            Please read src/c/README for more information
    6366%
    6467%   Usage:
     
    6770macro=$ENUM;
    6871END
    69 
    70         #update AnalysisTypeFromEnum
     72#}}}
     73#Add case to AnalysisTypeFromEnum file{{{
    7174        if [ $(echo $NAME | grep AnalysisEnum) ]
    7275        then
     
    7881END
    7982        fi
     83#}}}
    8084
    8185        #move file to m/enum
     
    8488done
    8589
    86 #end of AnalysisTypeFromEnum
     90#Footer of AnalysisTypeFromEnum.m{{{
    8791cat <<END >> AnalysisTypeFromEnum.m
    8892
     
    9296end
    9397END
     98#}}}
    9499
    95 #clean up
     100#clean up{{{
    96101mv AnalysisTypeFromEnum.m $ISSM_DIR/src/m/enum/
    97102rm temp
    98 
    99 #print info
     103#}}}
     104#print info{{{
    100105printf "\r                                                                      "
    101106printf "\rdone!\n"
     107#}}}
  • issm/trunk/src/c/EnumDefinitions/SynchronizeStringFromEnum.sh

    r3674 r3677  
    11#!/bin/bash
    2 #Synchronize StringFromEnum.cpp from EnumDefinition.h
     2#Synchronize EnumAsString.cpp and StringAsEnum.cpp
    33
    44#first remove existing files
    5 rm StringFromEnum.cpp
    6 rm StringFromEnum.h
     5rm EnumAsString.cpp StringAsEnum.cpp
    76
    8 echo "Synchronizing StringFromEnum..."
     7echo "Synchronizing EnumAsString..."
    98#Get all lines of EnumDefinitions2.h which hold Enum, | remove all comas | add line number in the first column > put everything in file temp
    109cat EnumDefinitions.h | grep "Enum," |sed -e "s/,//g" | awk '{ printf "%s %s\n", NR, $0 }' > temp
    1110
    12 #Build File StringFromEnum.h
    13 cat <<END > StringFromEnum.h
     11#Build header of EnumAsString.cpp {{{1
     12cat <<END > EnumAsString.cpp
    1413/*
    15 * \file StringFromEnum.h:
     14* \file EnumAsString.cpp:
    1615* \brief: output string associated with enum
     16*
     17*   WARNING: DO NOT MODIFY THIS FILE
     18*            this file has been automatically generated by SynchronizeStrings.sh
     19*            Please read README for more information
    1720*/
    1821
    19 #ifndef _STRINGFROMENUM_
    20 #define _STRINGFROMENUM_
     22#include "../shared/shared.h"
     23#include "../include/macros.h"
     24#include "./EnumDefinition.h"
    2125
    22 char* StringFromEnum(int en);
    23 
    24 #endif
    25 END
    26 
    27 #Build File StringFromEnum.cpp
    28 cat <<END > StringFromEnum.cpp
    29 /*
    30 * \file StringFromEnum.cpp:
    31 * \brief: output string associated with enum
    32 */
    33 
    34 #include "./StringFromEnum.h"
    35 
    36 char* StringFromEnum(int en){
     26char* EnumAsString(int en){
    3727
    3828        switch(en){
    3929
    4030END
     31#}}}
     32#Build header of StringAsEnum.cpp {{{1
     33cat <<END > StringAsEnum.cpp
     34/*
     35* \file StringAsEnum.cpp:
     36* \brief: output enum associated with string
     37*
     38*   WARNING: DO NOT MODIFY THIS FILE
     39*            this file has been automatically generated by SynchronizeStrings.sh
     40*            Please read README for more information
     41*/
     42
     43#include "../shared/shared.h"
     44#include "../include/macros.h"
     45#include "./EnumDefinition.h"
     46
     47int  StringAsEnum(char* name){
     48
     49END
     50#}}}
    4151
    4252#get number of lines in temp
     
    4757
    4858        #Get name and enum of the line i
    49         NAME=$(cat temp | grep "^[ ]*$i " | awk '{printf("%s",$2);}' | sed -e "s/Enum//g");
     59        NAMEENUM=$(cat temp | grep "^[ ]*$i " | awk '{printf("%s",$2);}');
     60        NAME=$(echo $NAMEENUM | sed -e "s/Enum//g")
    5061        ENUM=$i;
    5162        #offset Enum by one (Enum begins with 0 and not 1!)
    5263        let ENUM=$ENUM-1
    5364
    54         #print info
     65        #print info {{{
    5566        if [ $i -lt 10 ]
    5667        then
     
    6778                fi
    6879        fi
    69 
    70         #Add corresponding lines
    71         cat <<END >> StringFromEnum.cpp
    72                 case $ENUM :
     80        #}}}
     81        #Add case to EnumAsString.cpp {{{
     82        cat <<END >> EnumAsString.cpp
     83                case $NAMEENUM :
    7384                        return "$NAME";
    7485END
     86#}}}
     87        #Add case to StringAsEnum.cpp {{{
     88        if [ $i -eq 1 ]
     89        then
     90                cat <<END >> StringAsEnum.cpp
     91        if (strcmp(name,"$NAME")==0) return $NAMEENUM;
     92END
     93        else
     94                cat <<END >> StringAsEnum.cpp
     95        else if (strcmp(name,"$NAME")==0) return $NAMEENUM;
     96END
     97        fi
     98#}}}
     99
    75100done
    76101
    77 #end of file
    78 cat <<END >> StringFromEnum.cpp
     102#Add footer of of EnumAsString.cpp{{{1
     103cat <<END >> EnumAsString.cpp
    79104                default :
    80105                        ISSMERROR("Enum %i not found",en);
     
    82107}
    83108END
     109#}}}
     110#Add footer of of StringAsEnum.cpp{{{1
     111cat <<END >> StringAsEnum.cpp
     112        else ISSMERROR("Enum %i not found",en);
    84113
    85 #clean up
     114}
     115END
     116#}}}
     117
     118#clean up{{{
    86119rm temp
    87 
    88 #print info
     120#}}}
     121#print info {{{
    89122printf "\r                                                                      "
    90123printf "\rdone!\n"
     124#}}}
Note: See TracChangeset for help on using the changeset viewer.