598
|
1 #!/usr/bin/perl -w -n |
|
2 |
|
3 ## Catches vr_val (x) transforms it into varargout(i++) = x; |
|
4 ## |
|
5 |
|
6 use OctRe; |
|
7 |
|
8 BEGIN { |
|
9 $first = "vr_val_cnt = 1; "; |
|
10 |
|
11 } |
|
12 |
|
13 ## Does necessary changes inplace on $_[0]. |
|
14 sub change_line { |
|
15 |
|
16 if ($_[0] !~ /^\s*\#/) { # Don't do obvious comment lines |
|
17 |
|
18 # Change function declaration |
|
19 if ($_[0] =~ /$defun_rx/) { |
|
20 $_[0] =~ s/\.\.\.(\s*\]\s*\=)/varargout$1/g; |
|
21 } |
|
22 # Change vr_val() |
|
23 |
|
24 # BTW, if 1st vr_val() occurs in a loop, |
|
25 # this will NOT WORK! |
|
26 |
|
27 if ($_[0] =~ |
|
28 s{vr_val\s*\(([^;]*)\)(\s*;)} |
|
29 {"$first" . "varargout\{vr_val_cnt++\} = $1$2"}eg) { |
|
30 |
|
31 $first = ""; |
|
32 } |
|
33 # Did I miss anything? |
|
34 if ($_[0] =~ /vr_val\s*\(/) { |
|
35 $_[0] .= "## TODO : Remove this vr_val\n"; |
|
36 } |
|
37 |
|
38 } |
|
39 $first = "vr_val_cnt = 1; " if $. == 1; |
|
40 } |
|
41 |
|
42 sub comment_line { |
|
43 "" |
|
44 } |
|
45 1; |