-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathreformat-spec.pl
53 lines (41 loc) · 1.25 KB
/
reformat-spec.pl
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
49
50
51
52
53
#!/bin/perl
#Usage:
# perl reformat-spec.pl ompt-tr.tex > ompt-tr-spec.tex
sub escapeUnderscore {
my $string = shift;
# print $string;
$string =~ s/_/\\_/g;
return $string;
}
sub trueaddplc{
my $string = shift;
$string =~ s#([A-Za-z_][A-Za-z0-9_]*)(\s*,|\s*(?:/\*.*?\*/)?\s*\))#\\plc{${1}}${2}#g;
return $string;
}
sub trueaddplcblock{
my $string = shift;
$string =~ s#([A-Za-z_][A-Za-z0-9_]*)(\s*;)#\\plc{${1}}${2}#g;
return $string;
}
sub addplc{
my $string = shift;
$string =~ s/(while\s*)(\((?>[^()]+|(?2))*\))/"${1}".trueaddplc("${2}").""/esg;
$string =~ s/(\((?>[^()]+|(?1))*\))(\s*;)/"".trueaddplc("${1}")."${2}"/esg;
return $string;
}
sub addplcstruct{
my $string = shift;
$string =~ s/(\{(?>[^{}]+|(?1))*\})/"".trueaddplcblock("${1}").""/esg;
return $string;
}
$string="";
{
local $/ = undef;
open FILE, "$ARGV[0]" or die "Couldn't open file $ARGV[0]: $!";
binmode FILE;
$string = <FILE>;
close FILE;
}
$string =~ s/(\\verb(.))((?:(?!\2).)*)\2/"\\code{". escapeUnderscore("${3}") ."}"/esg;
$string =~ s/(?:\\begin\{quote\}\s*)?\\begin\{verbatim\}\s*((?:(?!\\end).)*)\\end\{verbatim\}(?:\s*\\end\{quote\})?/"\\begin{boxedcode}\n". escapeUnderscore(addplc(addplcstruct("${1}"))) ."\\end{boxedcode}"/esg;
print $string