annotate runtime/tools/efm_perl.pl @ 5278:d96f16667cc4 v7.4b.015

updated for version 7.4b.015 Problem: Can't compile without the 'acd' feature. Solution: Add #ifdefs. (Kazunobu Kuriyama)
author Bram Moolenaar <bram@vim.org>
date Mon, 05 Aug 2013 22:02:20 +0200
parents 9910cbff5f16
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1 #!/usr/bin/perl -w
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3 # vimparse.pl - Reformats the error messages of the Perl interpreter for use
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4 # with the quickfix mode of Vim
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5 #
3713
9910cbff5f16 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 7
diff changeset
6 # Copyright (c) 2001 by Joerg Ziefle <joerg.ziefle@gmx.de>
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7 # You may use and distribute this software under the same terms as Perl itself.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8 #
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9 # Usage: put one of the two configurations below in your ~/.vimrc (without the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10 # description and '# ') and enjoy (be sure to adjust the paths to vimparse.pl
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
11 # before):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12 #
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
13 # Program is run interactively with 'perl -w':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14 #
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15 # set makeprg=$HOME/bin/vimparse.pl\ %\ $*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16 # set errorformat=%f:%l:%m
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
17 #
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
18 # Program is only compiled with 'perl -wc':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
19 #
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
20 # set makeprg=$HOME/bin/vimparse.pl\ -c\ %\ $*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
21 # set errorformat=%f:%l:%m
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
22 #
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
23 # Usage:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
24 # vimparse.pl [-c] [-f <errorfile>] <programfile> [programargs]
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
25 #
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
26 # -c compile only, don't run (perl -wc)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
27 # -f write errors to <errorfile>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
28 #
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
29 # Example usages:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
30 # * From the command line:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
31 # vimparse.pl program.pl
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
32 #
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
33 # vimparse.pl -c -f errorfile program.pl
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
34 # Then run vim -q errorfile to edit the errors with Vim.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
35 #
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
36 # * From Vim:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
37 # Edit in Vim (and save, if you don't have autowrite on), then
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
38 # type ':mak' or ':mak args' (args being the program arguments)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
39 # to error check.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
40 #
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
41 # Version history:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
42 # 0.2 (04/12/2001):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
43 # * First public version (sent to Bram)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
44 # * -c command line option for compiling only
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
45 # * grammatical fix: 'There was 1 error.'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
46 # * bug fix for multiple arguments
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
47 # * more error checks
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
48 # * documentation (top of file, &usage)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
49 # * minor code clean ups
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
50 # 0.1 (02/02/2001):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
51 # * Initial version
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
52 # * Basic functionality
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
53 #
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
54 # Todo:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
55 # * test on more systems
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
56 # * use portable way to determine the location of perl ('use Config')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
57 # * include option that shows perldiag messages for each error
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
58 # * allow to pass in program by STDIN
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
59 # * more intuitive behaviour if no error is found (show message)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
60 #
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
61 # Tested under SunOS 5.7 with Perl 5.6.0. Let me know if it's not working for
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
62 # you.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
63
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
64 use strict;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
65 use Getopt::Std;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
66
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
67 use vars qw/$opt_c $opt_f $opt_h/; # needed for Getopt in combination with use strict 'vars'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
68
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
69 use constant VERSION => 0.2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
70
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
71 getopts('cf:h');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
72
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
73 &usage if $opt_h; # not necessarily needed, but good for further extension
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
74
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
75 if (defined $opt_f) {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
76
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
77 open FILE, "> $opt_f" or do {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
78 warn "Couldn't open $opt_f: $!. Using STDOUT instead.\n";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
79 undef $opt_f;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
80 };
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
81
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
82 };
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
83
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
84 my $handle = (defined $opt_f ? \*FILE : \*STDOUT);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
85
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
86 (my $file = shift) or &usage; # display usage if no filename is supplied
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
87 my $args = (@ARGV ? ' ' . join ' ', @ARGV : '');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
88
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
89 my @lines = `perl @{[defined $opt_c ? '-c ' : '' ]} -w "$file$args" 2>&1`;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
90
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
91 my $errors = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
92 foreach my $line (@lines) {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
93
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
94 chomp($line);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
95 my ($file, $lineno, $message, $rest);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
96
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
97 if ($line =~ /^(.*)\sat\s(.*)\sline\s(\d+)(\.|,\snear\s\".*\")$/) {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
98
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
99 ($message, $file, $lineno, $rest) = ($1, $2, $3, $4);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
100 $errors++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
101 $message .= $rest if ($rest =~ s/^,//);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
102 print $handle "$file:$lineno:$message\n";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
103
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
104 } else { next };
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
105
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
106 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
107
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
108 if (defined $opt_f) {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
109
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
110 my $msg;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
111 if ($errors == 1) {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
112
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
113 $msg = "There was 1 error.\n";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
114
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
115 } else {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
116
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
117 $msg = "There were $errors errors.\n";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
118
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
119 };
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
120
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
121 print STDOUT $msg;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
122 close FILE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
123 unlink $opt_f unless $errors;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
124
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
125 };
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
126
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
127 sub usage {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
128
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
129 (local $0 = $0) =~ s/^.*\/([^\/]+)$/$1/; # remove path from name of program
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
130 print<<EOT;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
131 Usage:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
132 $0 [-c] [-f <errorfile>] <programfile> [programargs]
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
133
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
134 -c compile only, don't run (executes 'perl -wc')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
135 -f write errors to <errorfile>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
136
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
137 Examples:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
138 * At the command line:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
139 $0 program.pl
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
140 Displays output on STDOUT.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
141
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
142 $0 -c -f errorfile program.pl
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
143 Then run 'vim -q errorfile' to edit the errors with Vim.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
144
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
145 * In Vim:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
146 Edit in Vim (and save, if you don't have autowrite on), then
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
147 type ':mak' or ':mak args' (args being the program arguments)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
148 to error check.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
149 EOT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
150
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
151 exit 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
152
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
153 };