source: trunk/IPs/systemC/processor/Morpheo/Script/execute.sh @ 82

Last change on this file since 82 was 82, checked in by rosiere, 16 years ago
  • support locale (now must "just" translate)
  • update all component with new test format
  • update all component with usage
  • New component : decod queue and prediction_unit
  • Property svn:keywords set to Id
File size: 2.6 KB
Line 
1#!/bin/sh
2#-----------------------------------------------------------
3# $Id: execute.sh 82 2008-05-01 16:48:45Z rosiere $
4#-----------------------------------------------------------
5
6declare -a COMMAND;
7declare -i CPT_OLD;
8declare -i CPT;
9declare    FILE_CMD=;
10declare    FILE_CPT=;
11declare    FILE_CPU=;
12declare    LOCK_CPT="${HOME}/.lock-cpt";
13declare    LOCK_CPU="${HOME}/.lock-cpu";
14
15#-----[ lock ]----------------------------------------------
16function lock ()
17{
18    lockfile -1 $1;
19}
20
21#-----[ unlock ]--------------------------------------------
22function unlock ()
23{
24    rm -f $1;
25}
26
27#-----[ main ]----------------------------------------------
28function main ()
29{
30    # no test, because the script execute_n have make all test
31    FILE_CMD=$1;
32    FILE_CPT=$2;
33    FILE_CPU=$3;
34
35    lock   $LOCK_CPT;
36    if test ! -s $FILE_CPT; then
37        echo "0" > $FILE_CPT;
38    fi;
39    unlock $LOCK_CPT;
40
41    # lit les fichiers ligne par ligne et le place dans un tableau
42    CPT=0;
43
44    while read line; do
45        COMMAND[$CPT]="$line";
46        CPT=$(($CPT+1));
47    done < $1;
48
49    echo "  * <$$> {"`date +"%F %T"`"} is ready";
50
51    # infinite loop
52    CPT_OLD=0;
53    CPT=0;
54
55    while test 1; do
56        # Take a number
57        CPT_OLD=$CPT;
58
59        lock   $LOCK_CPT;
60        CPT=`cat $FILE_CPT`;            # read  the      index
61        echo "$(($CPT+1))" > $FILE_CPT; # write the next index
62        unlock $LOCK_CPT;
63
64        # test if this number is valid
65        if test $CPT -ge ${#COMMAND[*]}; then
66            CPT=${#COMMAND[*]};
67        fi;
68
69        # test if between the cpt_old and cpt, there are a synchronisation command
70
71#       local -i CPT_SYNC=$CPT_OLD;
72#
73#       while test $CPT_SYNC -lt $CPT; do
74#           if test -z "${COMMAND[$CPT_SYNC]}"; then
75#               echo "  * <$$> {"`date +"%F %T"`"} synchronisation [$CPT_SYNC]";
76#           fi;
77#           CPT_SYNC=$(($CPT_SYNC+1));
78#       done;
79
80        # test if this number is valid
81        if test $CPT -eq ${#COMMAND[*]}; then
82            break;
83        fi;
84
85        # Test if command is empty !
86        if test ! -z "${COMMAND[$CPT]}"; then
87            local CUR_DIR=$PWD;
88
89            mkdir "Task_$CPT"       &> /dev/null;
90            cd    "Task_$CPT"       &> /dev/null;
91            echo "  * <$$> {"`date +"%F %T"`"} execute command [$CPT] : ${COMMAND[$CPT]}";
92            echo "${COMMAND[$CPT]}"  >  "command";
93            chmod +x                    "command";
94            eval "${COMMAND[$CPT]}" &"output";
95            cd    $CUR_DIR          &> /dev/null;
96        fi;
97    done;
98
99    echo "  * <$$> {"`date +"%F %T"`"} is done";
100
101    lock   $LOCK_CPU;
102    CPT=`cat $FILE_CPU`;     # read  the      index
103    CPT=$(($CPT-1));
104    echo "$CPT" > $FILE_CPU; # write the next index
105    unlock $LOCK_CPU;
106   
107    if test $CPT -eq 0; then
108        echo "  * <$$> {"`date +"%F %T"`"} All task is executed";
109        rm $FILE_CPU;
110    fi;
111}
112
113#-----[ Corps ]---------------------------------------------
114main $*;
Note: See TracBrowser for help on using the repository browser.