vim72-20100325-kaoriya-w64j.zip
[MacVim/KaoriYa.git] / runtime / tools / efm_perl.pl
blob570d6e766a89eea54a86642b298b8d18092994c5
1 #!/usr/bin/perl -w
3 # vimparse.pl - Reformats the error messages of the Perl interpreter for use
4 # with the quickfix mode of Vim
6 # Copyright (©) 2001 by Jörg Ziefle <joerg.ziefle@gmx.de>
7 # You may use and distribute this software under the same terms as Perl itself.
9 # Usage: put one of the two configurations below in your ~/.vimrc (without the
10 # description and '# ') and enjoy (be sure to adjust the paths to vimparse.pl
11 # before):
13 # Program is run interactively with 'perl -w':
15 # set makeprg=$HOME/bin/vimparse.pl\ %\ $*
16 # set errorformat=%f:%l:%m
18 # Program is only compiled with 'perl -wc':
20 # set makeprg=$HOME/bin/vimparse.pl\ -c\ %\ $*
21 # set errorformat=%f:%l:%m
23 # Usage:
24 # vimparse.pl [-c] [-f <errorfile>] <programfile> [programargs]
26 # -c compile only, don't run (perl -wc)
27 # -f write errors to <errorfile>
29 # Example usages:
30 # * From the command line:
31 # vimparse.pl program.pl
33 # vimparse.pl -c -f errorfile program.pl
34 # Then run vim -q errorfile to edit the errors with Vim.
36 # * From Vim:
37 # Edit in Vim (and save, if you don't have autowrite on), then
38 # type ':mak' or ':mak args' (args being the program arguments)
39 # to error check.
41 # Version history:
42 # 0.2 (04/12/2001):
43 # * First public version (sent to Bram)
44 # * -c command line option for compiling only
45 # * grammatical fix: 'There was 1 error.'
46 # * bug fix for multiple arguments
47 # * more error checks
48 # * documentation (top of file, &usage)
49 # * minor code clean ups
50 # 0.1 (02/02/2001):
51 # * Initial version
52 # * Basic functionality
54 # Todo:
55 # * test on more systems
56 # * use portable way to determine the location of perl ('use Config')
57 # * include option that shows perldiag messages for each error
58 # * allow to pass in program by STDIN
59 # * more intuitive behaviour if no error is found (show message)
61 # Tested under SunOS 5.7 with Perl 5.6.0. Let me know if it's not working for
62 # you.
64 use strict;
65 use Getopt::Std;
67 use vars qw/$opt_c $opt_f $opt_h/; # needed for Getopt in combination with use strict 'vars'
69 use constant VERSION => 0.2;
71 getopts('cf:h');
73 &usage if $opt_h; # not necessarily needed, but good for further extension
75 if (defined $opt_f) {
77 open FILE, "> $opt_f" or do {
78 warn "Couldn't open $opt_f: $!. Using STDOUT instead.\n";
79 undef $opt_f;
84 my $handle = (defined $opt_f ? \*FILE : \*STDOUT);
86 (my $file = shift) or &usage; # display usage if no filename is supplied
87 my $args = (@ARGV ? ' ' . join ' ', @ARGV : '');
89 my @lines = `perl @{[defined $opt_c ? '-c ' : '' ]} -w "$file$args" 2>&1`;
91 my $errors = 0;
92 foreach my $line (@lines) {
94 chomp($line);
95 my ($file, $lineno, $message, $rest);
97 if ($line =~ /^(.*)\sat\s(.*)\sline\s(\d+)(\.|,\snear\s\".*\")$/) {
99 ($message, $file, $lineno, $rest) = ($1, $2, $3, $4);
100 $errors++;
101 $message .= $rest if ($rest =~ s/^,//);
102 print $handle "$file:$lineno:$message\n";
104 } else { next };
108 if (defined $opt_f) {
110 my $msg;
111 if ($errors == 1) {
113 $msg = "There was 1 error.\n";
115 } else {
117 $msg = "There were $errors errors.\n";
121 print STDOUT $msg;
122 close FILE;
123 unlink $opt_f unless $errors;
127 sub usage {
129 (local $0 = $0) =~ s/^.*\/([^\/]+)$/$1/; # remove path from name of program
130 print<<EOT;
131 Usage:
132 $0 [-c] [-f <errorfile>] <programfile> [programargs]
134 -c compile only, don't run (executes 'perl -wc')
135 -f write errors to <errorfile>
137 Examples:
138 * At the command line:
139 $0 program.pl
140 Displays output on STDOUT.
142 $0 -c -f errorfile program.pl
143 Then run 'vim -q errorfile' to edit the errors with Vim.
145 * In Vim:
146 Edit in Vim (and save, if you don't have autowrite on), then
147 type ':mak' or ':mak args' (args being the program arguments)
148 to error check.
151 exit 0;