Subversion Repositories lagranto.arpege

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
3 michaesp 1
#!/usr/bin/perl
2
 
3
# --------------------------------------------------------
4
# Separate different commands out (delimiter & and |)
5
# --------------------------------------------------------
6
 
7
# Get input command and remove all spaces
8
$cmd = $ARGV[0];
9
$_   = $cmd;s/\s+//g;$cmd=$_;
10
$len = length $cmd; 
11
 
12
# Split the command string according to logical operators
13
$nline = 0;
14
while ( $len > 0 )
15
{
16
  # Get the length of the (remaining) command string
17
  $len = length $cmd; 
18
 
19
  # Get the position of the next command separator
20
  $and  = index($cmd,'&');
21
  $or   = index($cmd,'|' );
22
  if ( ($and == -1) && ($or == -1) )
23
     { $next = $len+1; }
24
  elsif ( ($and == -1) && ($or >= 0) )
25
     { $next = $or;  @logop[$nline] = 'OR'; }
26
  elsif ( ($and >= 0) && ($or == -1) )
27
     { $next = $and; @logop[$nline] = 'AND'; }
28
  elsif ($and > $or)
29
     { $next = $or; @logop[$nline] = 'OR';  }
30
  else
31
      { $next = $and; @logop[$nline] = 'AND'; }
32
 
33
  # A logical operator is not allowed to be at position 0
34
  if ( $next == 0) 
35
   {    
36
      die('Invalid expression... Check logical operators & and |');
37
   }   
38
 
39
  # Extract the next substring
40
  $sub = substr($cmd,0,$next);
41
  $cmd = substr($cmd,$next+1,$len-$next-1);
42
  $len = length $cmd; 
43
 
44
  # Save the command in a new line
45
  @field[$nline] = $sub;
46
  $nline = $nline + 1;
47
}
48
 
49
# --------------------------------------------------------
50
# Handle each command line separately
51
# --------------------------------------------------------
52
 
53
# Write start marker
54
print "BEGIN \n";
55
 
56
foreach ( $i = 0; $i < $nline; $i++  )
57
{
58
    # Split the command into its four components
59
    @entry  = split /:/, @field[$i];
60
    $nentry = @entry;
61
 
62
    # Either four or three elements are needed
63
    if ( ($nentry < 3) | ($nentry > 4) )     
64
     {    
65
      die('Each expression needs either 3 or 4 fields...');
66
     }   
67
 
68
    # Write the command
69
    print "@entry[0] \n";
70
 
71
    # Get the variable and the 'mode' for this variable
72
    $left  = index(@entry[1],'(');
73
    $right = index(@entry[1],')');
74
    if ( ($left == -1) && ($right == -1) ) 
75
      { 
76
       $var  = @entry[1];
77
       $mode = 'VALUE';
78
      }
79
    elsif ( ($left > 0) && ($right > $left) ) 
80
      { 
81
       $var  = substr(@entry[1],0,$left);  
82
       $mode = substr(@entry[1],$left+1,$right-$left-1);
83
      }
84
    else
85
      {    
86
       die('Invalid variable specification...');
87
      }   
88
    print "$var  $mode \n";
89
 
90
    # Get the parameter list for this command
91
    @param  = split /,/, @entry[2];
92
    $nparam = @param;
93
    print "$nparam \n";
94
    print "@param \n";
95
 
96
    # If only three parameters are given, the time is assumed to be the first one
97
    if ( $nentry == 3 )
98
    {
99
	@entry[3]='FIRST';
100
    }    
101
 
102
    # Get the variable and the 'mode' for this variable
103
    $left  = index(@entry[3],'(');
104
    $right = index(@entry[3],')');
105
    if ( ($left == -1) && ($right == -1) ) 
106
      { 
107
       $time = @entry[3];
108
       $mode = 'ALL';
109
      }
110
    elsif ( ($left > 0) && ($right > $left) ) 
111
      { 
112
       $time = substr(@entry[3],0,$left);  
113
       $mode = substr(@entry[3],$left+1,$right-$left-1);
114
      }
115
    else
116
      {    
117
       die('Invalid time specification...');
118
      }   
119
 
120
    # Get the time list for this command
121
    if ( $time eq 'ALL' )
122
    {
123
	$time = -999;
124
        print "1 \n";
125
        print "$time \n";
126
    }
127
    elsif ( $time eq 'FIRST' )
128
    {
129
        $time = -996;
130
        print "1 \n";
131
	    print "$time \n";
132
    }
133
    elsif ( $time eq 'LAST' )
134
    {
135
        $time = -995;
136
        print "1 \n";
137
	    print "$time \n";
138
	}
139
	elsif ( $time eq 'TRIGGER' )
140
    {
141
        print "-993 \n";
142
    }
143
    else
144
    {
145
        @times  = split /,/, $time;
146
        $outstr = "";
147
	    $outlen = 0;
148
	    foreach $j ( @times )
149
        {
150
	    $to = index($j,'to');
151
            if ( $to == -1 )
152
               { 
153
		if ( $j eq 'FIRST' )
154
		  {
155
                      $outlen=$outlen+1;
156
		      $outstr=$outstr . " -996 ";
157
                  }
158
                elsif ( $j eq 'LAST' )
159
		  {
160
                      $outlen=$outlen+1;
161
		      $outstr=$outstr . " -995 ";
162
                  }
163
                else
164
		  {
165
                   $outlen=$outlen+1;
166
                   $outstr=$outstr . "$j "; 
167
	          }
168
               }
169
            else
170
	       { 
171
                $outlen = $outlen+3;
172
                $t1 = substr($j,0,$to);
173
		$t2 = substr($j,$to+2,length($j)-$to+1);
174
		if ( $t1 eq 'FIRST' ) 
175
		    { $t1='-996'; };
176
		if ( $t2 eq 'FIRST' ) 
177
		    { $t2='-996'; };
178
		if ( $t1 eq 'LAST'  ) 
179
		    { $t1='-995'; };
180
		if ( $t2 eq 'LAST'  ) 
181
		    { $t2='-995'; };
182
	        $outstr=$outstr . $t1 . " -994 " . $t2 . " "; 
183
	       }
184
        }
185
	print "$outlen \n";
186
        print "$outstr \n";
187
    }
188
 
189
    # Write the time mode
190
    if ( $mode eq 'ALL' )
191
    {
192
        print "$mode \n";
193
    }
194
    elsif ( $mode eq 'ANY' )
195
    {
196
        print "$mode \n";
197
    }
198
    elsif ( $mode eq 'NONE' )
199
    {
200
        print "$mode \n";
201
    }
202
    elsif ( $mode eq 'TRIGGER' )
203
    {
204
        print "$mode \n";
205
    }
206
    else
207
    {    
208
       die('Invalid time mode...');
209
    }   
210
 
211
 
212
    # Write the logical operator
213
    if ( $i < $nline-1 )
214
    {
215
      print "@logop[$i] \n";
216
    } 
217
}
218
 
219
# Write end marker
220
print "END \n";