forked from mdmoss/shell2python
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCommand.pm
executable file
·48 lines (34 loc) · 1.11 KB
/
Command.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/perl -w
# Matthew Moss
# mdm@cse.unsw.edu.au
# cs2041, 12s2
use strict;
use Translate;
package Command;
sub can_handle {
# Identifies if this module can handle a line
# We can always execute arbitrary commands, even invalid ones
# This module is effectively a catch-all
return (1);
}
sub handle {
# This is the generic entry point for converting a line.
# Should only be called after can_handle returns true
# We can let Translate::arguments handle the majority of special
# characters. The exception is $@, because it must append the array
# For now, we'll assume it's going at the end of the string
# Actually, the order of execution really shouldn't matter that much
my $command = $_[0];
my $num_argslists = 0;
while ($command =~ /\"\$\@\"/) {
$command =~ s/\"\$\@\"//;
$num_argslists++;
}
my $result = 'subprocess.call(['.Translate::arguments($command, "str").'])';
while ($num_argslists != 0) {
$result =~ s/\)$/\+sys\.argv\[1\:\]\)/;
$num_argslists--;
}
return $result;
}
1;