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]
12 * Hack to work around the AIX C compiler's brain-damaged error messages
13 * so that emacs can parse them. It runs /bin/cc as a subprocess, and
14 * tries to rearrange the error messages so that (a) each message contains
15 * both the filename and line number where the error occurred, and (b)
16 * the error message(s) for a particular line get displayed *before* the
21 * cc -o aixcc lex.yy.c
24 * Copyright December 1991 by Keith Moore
26 * This program is free software; you can redistribute it and/or modify
27 * it under the terms of the GNU General Public License as published by
28 * the Free Software Foundation; either version 2 of the License, or
29 * (at your option) any later version.
31 * This program is distributed in the hope that it will be useful,
32 * but WITHOUT ANY WARRANTY; without even the implied warranty of
33 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34 * GNU General Public License for more details.
36 * You should have received a copy of the GNU General Public License
37 * along with this program; if not, write to the Free Software
38 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
41 * TODO: figure out how the compiler counts file numbers for included
42 * files, keep track of which file corresponds to which number, and
43 * always output the right file name.
53 char *bufptr = bigbuf;
54 int last_line_was_error = 0;
67 char *ptr = malloc (strlen (s) + 1);
77 putc (*bufptr++, yyout);
83 ^File\ Line\ Column\ Message\ text[^\n]* {
85 * ignore this. don't treat it as error text
89 ^{DS}{DS}{DS}\ {D5}\ \| {
91 * (optional) nesting level, followed by line number, followed
92 * by the source code fragment that caused the error
96 * save the line number for later
98 line = atoi (yytext+4);
101 fprintf (yyout, "line <= %d\n", line);
102 fprintf (yyout, "%s\n", yytext);
106 * if the last line was an error message, to flush out all of
107 * the old source text before starting to save the new source text.
109 if (last_line_was_error) {
113 putc (*bufptr++, yyout);
115 last_line_was_error = 0;
118 * stuff enough spaces in the text buffer so that the
119 * saved text will line up properly when displayed.
123 BEGIN ErrorText; /* continue below */
130 * Save the text until we see the error message(s), then print it.
131 * This because emacs puts the error message at the top of the
132 * window, and it's nice to be able to see the text below it.
143 ^Processing\ include\ file\ .*$ {
145 * name of a new include file being processed. Increment file number
146 * and remember the file name corresponding to this file number.
149 current_file = strsave (yytext+24);
152 fprintf (yyout, "current_file <= %s\n", current_file);
153 fprintf (yyout, "%s\n", yytext);
157 ^([a-z]\ -)?\ *{EC}: {
159 * error message (which we print immediately) preceeded by an
160 * error code (which we ignore)
163 fprintf (yyout, "\"%s\", line %d: %c -", current_file, line, *yytext);
164 last_line_was_error = 1;
168 ^{D3}\ {D5}\ {D4}\ {EC}: {
170 * (optional) nesting level, followed by line number, followed
171 * by column number, followed by error message text.
175 * save the line number for later
177 line = atoi (yytext+4);
180 fprintf (yyout, "line <= %d\n", line);
181 fprintf (yyout, "%s\n", yytext);
185 * if the last line was an error message, flush out all of
186 * the old source text before printing this error message.
188 if (last_line_was_error) {
192 putc (*bufptr++, yyout);
194 last_line_was_error = 0;
196 fprintf (yyout, "\"%s\", line %d:", current_file, line);
197 last_line_was_error = 1;
201 <ErrorMessage>[^\n]*$ {
202 fprintf (yyout, "%s\n", yytext);
208 /* name of new source file being processed */
214 ptr = strchr (yytext, ':');
216 current_file = strsave (yytext);
221 * other text starting with a newline. We have to break it up this
222 * way to keep this rule from matching any of the above patterns
225 if (last_line_was_error) {
229 putc (*bufptr++, yyout);
231 last_line_was_error = 0;
260 current_file = strsave ("/dev/null");
264 for (i = 1; i < argc; ++i) {
265 char *ptr = strrchr (argv[i], '.');
266 if (ptr && ptr[1] == 'c' && ptr[2] == '\0') {
267 current_file = strsave (argv[i]);
272 if (pipe (pfd) < 0) {
276 if ((child_pid = fork()) > 0) {
280 yyin = fdopen (pfd[0], "r");
285 exit ((status >> 8) & 0xff);
287 else if (child_pid == 0) {
292 execv ("/bin/cc", argv);