[2] | 1 | #!/bin/sh |
---|
| 2 | |
---|
| 3 | SED_SCRIPT=".sed_script"; |
---|
| 4 | SED_FILE=".sed_file"; |
---|
| 5 | SOURCE_FILE="New_Component"; |
---|
| 6 | SOURCE_DIR="./$SOURCE_FILE"; |
---|
[15] | 7 | TMP_DIR="/tmp/$SOURCE_FILE" |
---|
[2] | 8 | |
---|
[76] | 9 | TYPE=("vbe" "vst"); |
---|
| 10 | |
---|
[2] | 11 | #-----[ usage ]------------------------------------------------------ |
---|
| 12 | # input : - |
---|
| 13 | # output : - |
---|
| 14 | |
---|
| 15 | function usage () |
---|
| 16 | { |
---|
| 17 | echo ""; |
---|
[113] | 18 | echo "usage : $0 <directory> <name> <type>"; |
---|
[2] | 19 | echo " - <directory> : localisation of component"; |
---|
| 20 | echo " - <name> : name of component"; |
---|
[76] | 21 | echo " - <type> : type of component : ${TYPE[@]}"; |
---|
[2] | 22 | echo ""; |
---|
| 23 | echo " Note : This script must be execute in directory's script"; |
---|
| 24 | echo ""; |
---|
| 25 | |
---|
| 26 | exit; |
---|
| 27 | } |
---|
| 28 | |
---|
| 29 | #-----[ test_usage ]------------------------------------------------- |
---|
| 30 | # input : all parameters |
---|
| 31 | # output : - |
---|
| 32 | |
---|
| 33 | function test_usage () |
---|
| 34 | { |
---|
[15] | 35 | if test -d $TMP_DIR; then |
---|
| 36 | echo "Temporary directory \"$TMP_DIR\" exist already"; |
---|
| 37 | usage; |
---|
| 38 | fi; |
---|
| 39 | |
---|
[2] | 40 | if test -f $SED_SCRIPT; then |
---|
| 41 | echo "File \"$SED_SCRIPT\" exist"; |
---|
| 42 | usage; |
---|
| 43 | fi; |
---|
| 44 | if test -f $SED_FILE; then |
---|
| 45 | echo "File \"$SED_FILE\" exist"; |
---|
| 46 | usage; |
---|
| 47 | fi; |
---|
| 48 | |
---|
[76] | 49 | if test $# -ne 3; then |
---|
[2] | 50 | usage; |
---|
| 51 | fi; |
---|
| 52 | |
---|
[76] | 53 | find=0; |
---|
| 54 | for type in ${TYPE[@]}; do |
---|
| 55 | if test "$3" = "$type"; then |
---|
| 56 | find=1; |
---|
| 57 | SOURCE_DIR=$SOURCE_DIR"_"$type; |
---|
| 58 | fi; |
---|
| 59 | done; |
---|
| 60 | |
---|
| 61 | if test $find -eq 0; then |
---|
| 62 | usage; |
---|
| 63 | fi; |
---|
| 64 | |
---|
[77] | 65 | if test ! -d $SOURCE_DIR; then |
---|
| 66 | echo "Source directory \"$SOURCE_DIR\" invalid"; |
---|
| 67 | usage; |
---|
| 68 | fi; |
---|
| 69 | |
---|
[2] | 70 | # if test -d $1/$2; then |
---|
| 71 | # echo "Component in Directory \"$1/$2\" already exist"; |
---|
| 72 | # usage; |
---|
| 73 | # fi; |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | #-----[ rename_file ]------------------------------------------------ |
---|
| 77 | # input : file_old name_old name_new |
---|
| 78 | # output : - |
---|
| 79 | |
---|
| 80 | function rename_file () |
---|
| 81 | { |
---|
| 82 | FILE_OLD=$1; |
---|
| 83 | NAME_OLD=$2; |
---|
| 84 | NAME_NEW=$3; |
---|
| 85 | |
---|
| 86 | FILE_NEW="`dirname $FILE_OLD`/`basename $FILE_OLD |sed s/"$NAME_OLD"/"$NAME_NEW"/`"; |
---|
| 87 | |
---|
| 88 | if test $FILE_NEW != $FILE_OLD; then |
---|
| 89 | mv $FILE_OLD $FILE_NEW; |
---|
| 90 | fi; |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | #-----[ rename_directory ]------------------------------------------- |
---|
| 94 | # input : dir name_old name_new |
---|
| 95 | # output : - |
---|
| 96 | |
---|
| 97 | function rename_directory () |
---|
| 98 | { |
---|
| 99 | NAME_OLD=$2; |
---|
| 100 | NAME_NEW=$3; |
---|
| 101 | |
---|
| 102 | # recursion |
---|
| 103 | for ENTRY in $1/*; do |
---|
| 104 | |
---|
| 105 | if test -d $ENTRY; then |
---|
| 106 | rename_directory $ENTRY $2 $3; |
---|
| 107 | else |
---|
| 108 | rename_file $ENTRY $2 $3; |
---|
| 109 | fi; |
---|
| 110 | done; |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | #-----[ directory_to ]----------------------------------------------- |
---|
| 114 | # input : directory cmd |
---|
| 115 | # output : - |
---|
| 116 | |
---|
| 117 | function directory_to () |
---|
| 118 | { |
---|
| 119 | res=""; |
---|
| 120 | |
---|
| 121 | for i in `echo "$1" |tr \/ ' '`; do |
---|
| 122 | j=`echo $i |tr [:upper:] [:lower:]`; |
---|
| 123 | case $2 in |
---|
| 124 | "dir_morpheo") |
---|
| 125 | if test -z "$res"; then |
---|
| 126 | res="..\/.."; |
---|
| 127 | else |
---|
| 128 | res="..\/$res"; |
---|
| 129 | fi; |
---|
| 130 | ;; |
---|
| 131 | "component_lower") |
---|
| 132 | res="$j"; |
---|
| 133 | ;; |
---|
| 134 | "component") |
---|
| 135 | res="$i"; |
---|
| 136 | ;; |
---|
| 137 | "directory") |
---|
| 138 | if test -z "$res"; then |
---|
| 139 | res=$i; |
---|
| 140 | else |
---|
| 141 | res="$res\/$i"; |
---|
| 142 | fi; |
---|
| 143 | ;; |
---|
| 144 | "define") |
---|
| 145 | if test -z "$res"; then |
---|
| 146 | res=$j; |
---|
| 147 | else |
---|
| 148 | res="${res}_${j}"; |
---|
| 149 | fi; |
---|
| 150 | ;; |
---|
| 151 | "namespace_begin") |
---|
| 152 | prefixe="namespace "; |
---|
| 153 | postfixe=" {\n"; |
---|
| 154 | if test -z "$res"; then |
---|
| 155 | res="$prefixe$j$postfixe"; |
---|
| 156 | else |
---|
| 157 | res="$res$prefixe$j$postfixe"; |
---|
| 158 | fi; |
---|
| 159 | ;; |
---|
| 160 | "namespace_end") |
---|
| 161 | prefixe="}; \/\/ end namespace "; |
---|
| 162 | postfixe="\n"; |
---|
| 163 | if test -z "$res"; then |
---|
| 164 | res="$prefixe$j$postfixe"; |
---|
| 165 | else |
---|
| 166 | res="$prefixe$j$postfixe$res"; |
---|
| 167 | fi; |
---|
| 168 | ;; |
---|
| 169 | "namespace_use") |
---|
| 170 | if test -z "$res"; then |
---|
| 171 | res="$j"; |
---|
| 172 | else |
---|
| 173 | res="$res::$j"; |
---|
| 174 | fi; |
---|
| 175 | ;; |
---|
| 176 | "namespace_using") |
---|
| 177 | prefixe="using namespace morpheo::behavioural::"; |
---|
| 178 | postfixe=";\n"; |
---|
| 179 | if test -z "$res"; then |
---|
| 180 | res="$prefixe$j$postfixe"; |
---|
| 181 | namespace="$j"; |
---|
| 182 | else |
---|
| 183 | res="$res$prefixe$namespace::$j$postfixe"; |
---|
| 184 | namespace="$namespace::$j"; |
---|
| 185 | fi; |
---|
| 186 | ;; |
---|
| 187 | *) |
---|
| 188 | esac; |
---|
| 189 | done; |
---|
| 190 | |
---|
| 191 | echo $res; |
---|
| 192 | } |
---|
| 193 | |
---|
| 194 | #-----[ translation_script ]----------------------------------------- |
---|
| 195 | # input : dir component |
---|
| 196 | # output : - |
---|
| 197 | |
---|
| 198 | function translation_script () |
---|
| 199 | { |
---|
| 200 | # All example is the component Generic/RegisterFile |
---|
| 201 | |
---|
| 202 | #@DIR_MORPHEO ../../ |
---|
| 203 | SED=`directory_to $1/$2 "dir_morpheo"`; |
---|
| 204 | echo "s/@DIR_MORPHEO/$SED/g" >> $SED_SCRIPT; |
---|
| 205 | |
---|
| 206 | #@COMPONENT_LOWER registerfile |
---|
| 207 | SED=`directory_to $2 "component_lower"`; |
---|
| 208 | echo "s/@COMPONENT_LOWER/$SED/g" >> $SED_SCRIPT; |
---|
| 209 | |
---|
| 210 | #@COMPONENT RegisterFile |
---|
| 211 | SED=`directory_to $2 "component"`; |
---|
| 212 | echo "s/@COMPONENT/$SED/g" >> $SED_SCRIPT; |
---|
| 213 | |
---|
| 214 | #@DIRECTORY Generic/RegisterFile |
---|
| 215 | SED=`directory_to $1/$2 "directory"`; |
---|
| 216 | echo "s/@DIRECTORY/$SED/g" >> $SED_SCRIPT; |
---|
| 217 | |
---|
| 218 | #@DEFINE generic_registerfile |
---|
| 219 | SED=`directory_to $1/$2 "define"`; |
---|
| 220 | echo "s/@DEFINE/$SED/g" >> $SED_SCRIPT; |
---|
| 221 | |
---|
| 222 | #@NAMESPACE_BEGIN namespace generic { |
---|
| 223 | # namespace registerfile { |
---|
| 224 | SED=`directory_to $1/$2 "namespace_begin"`; |
---|
| 225 | echo "s/@NAMESPACE_BEGIN/$SED/g" >> $SED_SCRIPT; |
---|
| 226 | |
---|
| 227 | #@NAMESPACE_END }; // end namespace registerfile |
---|
| 228 | # }; // end namespace generic |
---|
| 229 | SED=`directory_to $1/$2 "namespace_end"`; |
---|
| 230 | echo "s/@NAMESPACE_END/$SED/g" >> $SED_SCRIPT; |
---|
| 231 | |
---|
| 232 | #@NAMESPACE_USE generic::registerfile |
---|
| 233 | SED=`directory_to $1/$2 "namespace_use"`; |
---|
| 234 | echo "s/@NAMESPACE_USE/$SED/g" >> $SED_SCRIPT; |
---|
| 235 | |
---|
| 236 | #@NAMESPACE_USING using namespace morpheo::behavioural::generic; |
---|
| 237 | SED=`directory_to $1 "namespace_using"`; |
---|
| 238 | echo "s/@NAMESPACE_USING/$SED/g" >> $SED_SCRIPT; |
---|
| 239 | |
---|
| 240 | } |
---|
| 241 | |
---|
| 242 | |
---|
| 243 | |
---|
| 244 | #-----[ translation_file ]------------------------------------------- |
---|
| 245 | # input : file |
---|
| 246 | # output : - |
---|
| 247 | |
---|
| 248 | function translation_file () |
---|
| 249 | { |
---|
| 250 | echo "Translation : $1"; |
---|
| 251 | |
---|
| 252 | cat $1 |sed -f $SED_SCRIPT $1 > $SED_FILE; |
---|
| 253 | mv $SED_FILE $1; |
---|
| 254 | } |
---|
| 255 | |
---|
| 256 | #-----[ translation_directory_rec ]---------------------------------- |
---|
| 257 | # input : dir |
---|
| 258 | # output : - |
---|
| 259 | |
---|
| 260 | function translation_directory_rec |
---|
| 261 | { |
---|
[15] | 262 | if test `ls $1|grep -c ""` -ne 0; then |
---|
| 263 | # recursion |
---|
| 264 | for ENTRY in $1/*; do |
---|
| 265 | |
---|
| 266 | if test -d $ENTRY; then |
---|
| 267 | translation_directory_rec $ENTRY; |
---|
| 268 | else |
---|
| 269 | translation_file $ENTRY |
---|
| 270 | fi; |
---|
| 271 | done; |
---|
| 272 | fi; |
---|
[2] | 273 | } |
---|
| 274 | |
---|
| 275 | #-----[ translation_directory ]-------------------------------------- |
---|
| 276 | # input : dir component |
---|
| 277 | # output : - |
---|
| 278 | |
---|
| 279 | function translation_directory () |
---|
| 280 | { |
---|
| 281 | touch $SED_SCRIPT; |
---|
| 282 | |
---|
| 283 | translation_script $1 $2; |
---|
| 284 | translation_directory_rec $1/$2; |
---|
| 285 | |
---|
| 286 | #cat $SED_SCRIPT; |
---|
| 287 | rm $SED_SCRIPT; |
---|
| 288 | } |
---|
| 289 | |
---|
| 290 | |
---|
| 291 | #-----[ main ]------------------------------------------------------- |
---|
| 292 | # input : all parameters |
---|
| 293 | # output : - |
---|
| 294 | |
---|
| 295 | function main () |
---|
| 296 | { |
---|
| 297 | test_usage $*; |
---|
| 298 | |
---|
| 299 | echo "New : $2"; |
---|
| 300 | |
---|
| 301 | # Create directory |
---|
| 302 | mkdir -p $1/$2; |
---|
| 303 | |
---|
| 304 | #Copy |
---|
[15] | 305 | cp -r $SOURCE_DIR $TMP_DIR; |
---|
| 306 | find $TMP_DIR -iname ".svn" -type d -exec rm -fr '{}' \; &> /dev/null |
---|
| 307 | mv $TMP_DIR/* $1/$2; |
---|
| 308 | rmdir $TMP_DIR |
---|
[2] | 309 | |
---|
| 310 | #translation |
---|
| 311 | rename_directory "$1/$2" $SOURCE_FILE $2; |
---|
| 312 | translation_directory $1 $2; |
---|
| 313 | } |
---|
| 314 | |
---|
| 315 | #-----[ body ]------------------------------------------------------- |
---|
| 316 | main $*; |
---|