1 %Start ErrorText ErrorMessage OtherText
3 EC [0-9][0-9][0-9][0-9]-[0-9][0-9][0-9]
6 D4 [0-9 ][0-9 ][0-9 ][0-9]
7 D5 [0-9 ][0-9 ][0-9 ][0-9 ][0-9]
11 /* moore@wilma.cs.utk.edu
13 * Hack to work around the AIX C compiler's brain-damaged error messages
14 * so that emacs can parse them. It runs /bin/cc as a subprocess, and
15 * tries to rearrange the error messages so that (a) each message contains
16 * both the filename and line number where the error occurred, and (b)
17 * the error message(s) for a particular line get displayed *before* the
22 * cc -o aixcc lex.yy.c
25 * Copyright December 1991 by Keith Moore
27 * This program is free software; you can redistribute it and/or modify
28 * it under the terms of the GNU General Public License as published by
29 * the Free Software Foundation; either version 2 of the License, or
30 * (at your option) any later version.
32 * This program is distributed in the hope that it will be useful,
33 * but WITHOUT ANY WARRANTY; without even the implied warranty of
34 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35 * GNU General Public License for more details.
37 * You should have received a copy of the GNU General Public License
38 * along with this program; if not, write to the Free Software
39 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
42 * TODO: figure out how the compiler counts file numbers for included
43 * files, keep track of which file corresponds to which number, and
44 * always output the right file name.
54 char *bufptr = bigbuf;
55 int last_line_was_error = 0;
68 char *ptr = malloc (strlen (s) + 1);
78 putc (*bufptr++, yyout);
84 ^File\ Line\ Column\ Message\ text[^\n]* {
86 * ignore this. don't treat it as error text
90 ^{DS}{DS}{DS}\ {D5}\ \| {
92 * (optional) nesting level, followed by line number, followed
93 * by the source code fragment that caused the error
97 * save the line number for later
99 line = atoi (yytext+4);
102 fprintf (yyout, "line <= %d\n", line);
103 fprintf (yyout, "%s\n", yytext);
107 * if the last line was an error message, to flush out all of
108 * the old source text before starting to save the new source text.
110 if (last_line_was_error) {
114 putc (*bufptr++, yyout);
116 last_line_was_error = 0;
119 * stuff enough spaces in the text buffer so that the
120 * saved text will line up properly when displayed.
124 BEGIN ErrorText; /* continue below */
131 * Save the text until we see the error message(s), then print it.
132 * This because emacs puts the error message at the top of the
133 * window, and it's nice to be able to see the text below it.
144 ^Processing\ include\ file\ .*$ {
146 * name of a new include file being processed. Increment file number
147 * and remember the file name corresponding to this file number.
150 current_file = strsave (yytext+24);
153 fprintf (yyout, "current_file <= %s\n", current_file);
154 fprintf (yyout, "%s\n", yytext);
158 ^([a-z]\ -)?\ *{EC}: {
160 * error message (which we print immediately) preceded by an
161 * error code (which we ignore)
164 fprintf (yyout, "\"%s\", line %d: %c -", current_file, line, *yytext);
165 last_line_was_error = 1;
169 ^{D3}\ {D5}\ {D4}\ {EC}: {
171 * (optional) nesting level, followed by line number, followed
172 * by column number, followed by error message text.
176 * save the line number for later
178 line = atoi (yytext+4);
181 fprintf (yyout, "line <= %d\n", line);
182 fprintf (yyout, "%s\n", yytext);
186 * if the last line was an error message, flush out all of
187 * the old source text before printing this error message.
189 if (last_line_was_error) {
193 putc (*bufptr++, yyout);
195 last_line_was_error = 0;
197 fprintf (yyout, "\"%s\", line %d:", current_file, line);
198 last_line_was_error = 1;
202 <ErrorMessage>[^\n]*$ {
203 fprintf (yyout, "%s\n", yytext);
209 /* name of new source file being processed */
215 ptr = strchr (yytext, ':');
217 current_file = strsave (yytext);
222 * other text starting with a newline. We have to break it up this
223 * way to keep this rule from matching any of the above patterns
226 if (last_line_was_error) {
230 putc (*bufptr++, yyout);
232 last_line_was_error = 0;
261 current_file = strsave ("/dev/null");
265 for (i = 1; i < argc; ++i) {
266 char *ptr = strrchr (argv[i], '.');
267 if (ptr && ptr[1] == 'c' && ptr[2] == '\0') {
268 current_file = strsave (argv[i]);
273 if (pipe (pfd) < 0) {
277 if ((child_pid = fork()) > 0) {
281 yyin = fdopen (pfd[0], "r");
286 exit ((status >> 8) & 0xff);
288 else if (child_pid == 0) {
293 execv ("/bin/cc", argv);