source: trunk/IPs/systemC/processor/Morpheo/Behavioural/New_Component.sh @ 76

Last change on this file since 76 was 76, checked in by rosiere, 16 years ago

Add new component : Read_unit (no tested)
Change functionnal_unit : now use type and operation to execute the good function
Change New_Component's script

File size: 6.5 KB
Line 
1#!/bin/sh
2
3SED_SCRIPT=".sed_script";
4SED_FILE=".sed_file";
5SOURCE_FILE="New_Component";
6SOURCE_DIR="./$SOURCE_FILE";
7TMP_DIR="/tmp/$SOURCE_FILE"
8
9TYPE=("vbe" "vst");
10
11#-----[ usage ]------------------------------------------------------
12# input  : -
13# output : -
14
15function usage ()
16{
17    echo "";
18    echo "usage : $0 <directory> <name>";
19    echo " - <directory> : localisation of component";
20    echo " - <name>      : name of component";
21    echo " - <type>      : type of component : ${TYPE[@]}";
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
33function test_usage ()
34{
35    if test ! -d $SOURCE_DIR; then
36        echo "Source directory \"$SOURCE_DIR\" invalid";
37        usage;
38    fi;
39
40    if test   -d $TMP_DIR; then
41        echo "Temporary directory \"$TMP_DIR\" exist already";
42        usage;
43    fi;
44
45    if test -f $SED_SCRIPT; then
46        echo "File \"$SED_SCRIPT\" exist"; 
47        usage;
48    fi;
49    if test -f $SED_FILE; then
50        echo "File \"$SED_FILE\" exist"; 
51        usage;
52    fi;
53
54    if test $# -ne 3; then
55        usage;
56    fi;
57
58    find=0;
59    for type in ${TYPE[@]}; do
60        if test "$3" = "$type"; then
61            find=1;
62            SOURCE_DIR=$SOURCE_DIR"_"$type;
63        fi;
64    done;
65   
66    if test $find -eq 0; then
67        usage;
68    fi;
69
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
80function 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
97function 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
117function 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
198function 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
248function 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
260function translation_directory_rec
261{
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;
273}
274
275#-----[ translation_directory ]--------------------------------------
276# input  : dir component
277# output : -
278
279function 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
295function main ()
296{
297    test_usage $*;
298
299    echo "New             : $2";
300   
301    # Create directory
302    mkdir -p $1/$2;
303   
304    #Copy
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
309   
310    #translation
311    rename_directory      "$1/$2" $SOURCE_FILE $2;
312    translation_directory $1 $2;
313}
314
315#-----[ body ]-------------------------------------------------------
316main $*;
Note: See TracBrowser for help on using the repository browser.