Subversion Repositories lagranto.wrf

Rev

Rev 2 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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