annotate lib-src/=aixcc.lex @ 19784:da913efb39cf

(read-language-name): Doc fix. (set-language-environment): Improve prompt.
author Richard M. Stallman <rms@gnu.org>
date Sun, 07 Sep 1997 03:39:44 +0000
parents 507f64624555
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
468
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1 %Start ErrorText ErrorMessage OtherText
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3 EC [0-9][0-9][0-9][0-9]-[0-9][0-9][0-9]
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4 D [0-9]
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5 D3 [0-9 ][0-9 ][0-9]
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
6 D4 [0-9 ][0-9 ][0-9 ][0-9]
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
7 D5 [0-9 ][0-9 ][0-9 ][0-9 ][0-9]
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8 DS [0-9 ]
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10 %{
469
ffa6d5c9b074 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 468
diff changeset
11 /* moore@wilma.cs.utk.edu
ffa6d5c9b074 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 468
diff changeset
12
468
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13 * Hack to work around the AIX C compiler's brain-damaged error messages
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14 * so that emacs can parse them. It runs /bin/cc as a subprocess, and
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15 * tries to rearrange the error messages so that (a) each message contains
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16 * both the filename and line number where the error occurred, and (b)
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 * the error message(s) for a particular line get displayed *before* the
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 * line itself.
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19 *
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20 * to compile:
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21 * lex aixcc.lex
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22 * cc -o aixcc lex.yy.c
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23 *
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
24 *
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25 * Copyright December 1991 by Keith Moore
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26 *
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27 * This program is free software; you can redistribute it and/or modify
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28 * it under the terms of the GNU General Public License as published by
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29 * the Free Software Foundation; either version 2 of the License, or
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30 * (at your option) any later version.
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31 *
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32 * This program is distributed in the hope that it will be useful,
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35 * GNU General Public License for more details.
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36 *
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37 * You should have received a copy of the GNU General Public License
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38 * along with this program; if not, write to the Free Software
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40 *
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41 *
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
42 * TODO: figure out how the compiler counts file numbers for included
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43 * files, keep track of which file corresponds to which number, and
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44 * always output the right file name.
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45 */
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47 #include <stdio.h>
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48 #include <string.h>
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50 char *current_file;
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51 int line;
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52 int debug = 0;
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53 char bigbuf[10240];
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54 char *bufptr = bigbuf;
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55 int last_line_was_error = 0;
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
57 spaces (s)
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58 char *s;
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59 {
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60 while (*s++)
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61 *bufptr++ = ' ';
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 }
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64 char *
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65 strsave (s)
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66 char *s;
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67 {
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68 char *ptr = malloc (strlen (s) + 1);
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69 strcpy (ptr, s);
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70 return ptr;
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71 }
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73 yywrap ()
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74 {
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75 *bufptr = '\0';
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76 bufptr = bigbuf;
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77 while (*bufptr)
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 putc (*bufptr++, yyout);
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79 return 1;
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80 }
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
82 %}
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
83 %%
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
84 ^File\ Line\ Column\ Message\ text[^\n]* {
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
85 /*
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86 * ignore this. don't treat it as error text
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87 */
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
88 }
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90 ^{DS}{DS}{DS}\ {D5}\ \| {
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91 /*
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
92 * (optional) nesting level, followed by line number, followed
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
93 * by the source code fragment that caused the error
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94 */
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
95
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96 /*
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97 * save the line number for later
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98 */
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
99 line = atoi (yytext+4);
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
100
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101 if (debug) {
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
102 fprintf (yyout, "line <= %d\n", line);
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
103 fprintf (yyout, "%s\n", yytext);
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
104 }
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
105
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
106 /*
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
107 * if the last line was an error message, to flush out all of
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
108 * the old source text before starting to save the new source text.
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
109 */
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
110 if (last_line_was_error) {
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
111 *bufptr = '\0';
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
112 bufptr = bigbuf;
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
113 while (*bufptr)
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
114 putc (*bufptr++, yyout);
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
115 bufptr = bigbuf;
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
116 last_line_was_error = 0;
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
117 }
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118 /*
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
119 * stuff enough spaces in the text buffer so that the
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
120 * saved text will line up properly when displayed.
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
121 */
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
122 spaces (yytext);
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
123
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
124 BEGIN ErrorText; /* continue below */
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
125 }
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
126
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
127 <ErrorText>[^\n]*$ {
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
128 char *ptr;
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
129
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
130 /*
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
131 * Save the text until we see the error message(s), then print it.
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
132 * This because emacs puts the error message at the top of the
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
133 * window, and it's nice to be able to see the text below it.
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
134 */
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
135
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136 ptr = yytext;
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
137 while (*ptr)
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
138 *bufptr++ = *ptr++;
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
139 *bufptr++ = '\n';
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
140
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
141 BEGIN 0;
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
142 }
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
143
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
144 ^Processing\ include\ file\ .*$ {
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
145 /*
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
146 * name of a new include file being processed. Increment file number
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
147 * and remember the file name corresponding to this file number.
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
148 */
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
149
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
150 current_file = strsave (yytext+24);
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
151
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
152 if (debug) {
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
153 fprintf (yyout, "current_file <= %s\n", current_file);
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
154 fprintf (yyout, "%s\n", yytext);
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
155 }
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
156 }
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
157
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
158 ^([a-z]\ -)?\ *{EC}: {
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
159 /*
3591
507f64624555 Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents: 469
diff changeset
160 * error message (which we print immediately) preceded by an
468
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
161 * error code (which we ignore)
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
162 */
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
163
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
164 fprintf (yyout, "\"%s\", line %d: %c -", current_file, line, *yytext);
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
165 last_line_was_error = 1;
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
166 BEGIN ErrorMessage;
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
167 }
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
168
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
169 ^{D3}\ {D5}\ {D4}\ {EC}: {
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
170 /*
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
171 * (optional) nesting level, followed by line number, followed
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
172 * by column number, followed by error message text.
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
173 */
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
174
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
175 /*
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
176 * save the line number for later
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
177 */
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
178 line = atoi (yytext+4);
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
179
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
180 if (debug) {
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
181 fprintf (yyout, "line <= %d\n", line);
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
182 fprintf (yyout, "%s\n", yytext);
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
183 }
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
184
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185 /*
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
186 * if the last line was an error message, flush out all of
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187 * the old source text before printing this error message.
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
188 */
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
189 if (last_line_was_error) {
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190 *bufptr = '\0';
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
191 bufptr = bigbuf;
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192 while (*bufptr)
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193 putc (*bufptr++, yyout);
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
194 bufptr = bigbuf;
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
195 last_line_was_error = 0;
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196 }
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197 fprintf (yyout, "\"%s\", line %d:", current_file, line);
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
198 last_line_was_error = 1;
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
199 BEGIN ErrorMessage;
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
200 }
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
201
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
202 <ErrorMessage>[^\n]*$ {
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
203 fprintf (yyout, "%s\n", yytext);
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
204 BEGIN 0;
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
205 }
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
206
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
207
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
208 ^[^ :]+".c:"\ *$ {
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
209 /* name of new source file being processed */
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
210
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
211 char *ptr;
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
212
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
213 if (current_file)
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
214 free (current_file);
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
215 ptr = strchr (yytext, ':');
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
216 *ptr = '\0';
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
217 current_file = strsave (yytext);
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
218 }
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
219
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
220 ^[^\n] {
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
221 /*
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
222 * other text starting with a newline. We have to break it up this
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
223 * way to keep this rule from matching any of the above patterns
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
224 */
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
225
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
226 if (last_line_was_error) {
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
227 *bufptr = '\0';
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
228 bufptr = bigbuf;
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
229 while (*bufptr)
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
230 putc (*bufptr++, yyout);
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
231 bufptr = bigbuf;
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
232 last_line_was_error = 0;
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
233 }
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
234
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
235 *bufptr++ = *yytext;
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
236 BEGIN OtherText;
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
237 }
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
238
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
239 <OtherText>[^\n]*$ {
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
240 char *ptr;
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
241
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
242 ptr = yytext;
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
243 while (*ptr)
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
244 *bufptr++ = *ptr++;
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
245 *bufptr++ = '\n';
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
246
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
247 BEGIN 0;
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
248 }
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
249
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
250 \n ;
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
251
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
252 %%
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
253
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
254 main (argc, argv)
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
255 char **argv;
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
256 {
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
257 int pfd[2];
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
258 int child_pid;
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
259 int i;
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
260
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
261 current_file = strsave ("/dev/null");
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
262
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
263 line = 0;
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
264
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
265 for (i = 1; i < argc; ++i) {
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
266 char *ptr = strrchr (argv[i], '.');
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
267 if (ptr && ptr[1] == 'c' && ptr[2] == '\0') {
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
268 current_file = strsave (argv[i]);
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
269 break;
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
270 }
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
271 }
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
272
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
273 if (pipe (pfd) < 0) {
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
274 perror ("pipe");
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
275 exit (1);
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
276 }
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
277 if ((child_pid = fork()) > 0) {
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
278 int status;
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
279
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
280 close (pfd[1]);
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
281 yyin = fdopen (pfd[0], "r");
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
282 yyout = stderr;
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
283 yylex();
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
284
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
285 wait (&status);
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
286 exit ((status >> 8) & 0xff);
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
287 }
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
288 else if (child_pid == 0) {
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
289 dup2 (pfd[1], 2);
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
290 close (pfd[0]);
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
291 close (pfd[1]);
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
292 argv[0] = "cc";
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
293 execv ("/bin/cc", argv);
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
294 perror ("/bin/cc");
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
295 exit (1);
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
296 }
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
297 else {
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
298 perror ("fork");
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
299 exit (1);
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
300 }
9b11b9478c68 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
301 }