This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: fixincl.c uses non-portable #error and string concatenation
- To: egcs-patches at egcs dot cygnus dot com
- Subject: Re: fixincl.c uses non-portable #error and string concatenation
- From: Alexandre Oliva <oliva at dcc dot unicamp dot br>
- Date: 17 May 1999 21:59:26 -0300
- Cc: Bruce Korb <ddsinc09 at ix dot netcom dot com>
- References: <orso8vwb13.fsf@lua.lbi.dcc.unicamp.br>
On May 17, 1999, Alexandre Oliva <oliva@dcc.unicamp.br> wrote:
> The second problem is that cc does not support concatenation of
> adjacent strings, and not only inclhack.def seems to assume this is
> possible, but also fixincl.tpl uses `"|"' strings to separate
> filenames.
I've just written a sed script that will take care of concatenating
strings where needed. It changes fixincl.x like this:
- "|" "sys/wait.h" "|";
+ "|sys/wait.h|";
- "-e", "/^extern pid_t wait3();$/i\\\n"
- "struct rusage;\n",
+ "-e", "/^extern pid_t wait3();$/i\\\n\
+struct rusage;\n",
- "|" "stdio.h"
- "|" "stdlib.h" "|";
+ "|stdio.h\
+|stdlib.h|";
This patch includes the `#error' fix, as well as a few other fixes for
fixincl to compile with a K&R C compiler such as SunOS4's, and to run
afterwards :-)
I've omitted the fixincl.x changes from the patch, since they can
(should?) be easily generated after installing the patch.
Is this ok to install?
--
Alexandre Oliva http://www.dcc.unicamp.br/~oliva IC-Unicamp, Bra[sz]il
{oliva,Alexandre.Oliva}@dcc.unicamp.br aoliva@{acm.org,computer.org}
oliva@{gnu.org,kaffe.org,{egcs,sourceware}.cygnus.com,samba.org}
*** E-mail about software projects will be forwarded to mailing lists
Index: gcc/ChangeLog
from Alexandre Oliva <oliva@dcc.unicamp.br>
* fixinc/concat.sh: New file. Merge adjacent strings.
* fixinc/Makefile.in (gnu-regex.o): Pass $(INCLUDES).
(fixincl.x): Run fixincl.x through concat.sh.
* fixinc/genfixes: Likewise.
* fixinc/fixincl.c: Remove #error, it is not portable.
(EXIT_SUCCESS, EXIT_FAILURE): Define if not defined.
(wait_for_pid): K&R-ize.
(process): Use read_fd instead of fdp; initialize env_current_file
after declaration.
* fixinc/gnu-regex.c: Make it const and volatile safe.
* server.c: Make it volatile safe.
* fixinc/procopen.c: Initialize stdout_pair after declaration.
Index: gcc/fixinc/Makefile.in
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/fixinc/Makefile.in,v
retrieving revision 1.6
diff -u -r1.6 Makefile.in
--- gcc/fixinc/Makefile.in 1999/04/29 14:05:30 1.6
+++ gcc/fixinc/Makefile.in 1999/05/18 00:46:07
@@ -81,7 +81,7 @@
chmod 777 $@ ; fi
gnu-regex.o: gnu-regex.c
- -$(CC) $(CFLAGS) $(FIXINC_DEFS) -DREGEX_MALLOC -DSTDC_HEADERS=1 \
+ -$(CC) $(CFLAGS) $(FIXINC_DEFS) $(INCLUDES) -DREGEX_MALLOC -DSTDC_HEADERS=1 \
-c $(srcdir)/gnu-regex.c
fixincl.o : fixincl.x fixincl.c
@@ -90,9 +90,14 @@
fixincl.x: fixincl.tpl inclhack.def
@if ( autogen --help > /dev/null 2>&1 ) ; then \
- echo autogen -T fixincl.tpl -b fixincl inclhack.def ; \
- autogen -T $(srcdir)/fixincl.tpl -b fixincl \
- $(srcdir)/inclhack.def ; \
+ echo autogen -T fixincl.tpl -b fixinclx inclhack.def ; \
+ autogen -T $(srcdir)/fixincl.tpl -b fixinclx \
+ $(srcdir)/inclhack.def && \
+ rm -f $(srcdir)/fixincl.x && \
+ echo "concat.sh < fixinclx.x > fixincl.x" && \
+ $(SHELL) $(srcdir)/concat.sh < fixinclx.x \
+ > $(srcdir)/fixincl.x ; \
+ rm -f fixinclx.x ; \
else echo You need to install autogen ; \
if [ `pwd` != `cd $(srcdir) ; pwd` ] ; then \
$(CP) $(srcdir)/$@ . ; \
Index: gcc/fixinc/concat.sh
===================================================================
RCS file: concat.sh
diff -N concat.sh
--- gcc/fixinc/concat.sh Sat Dec 5 20:30:03 1998
+++ gcc/fixinc/concat.sh Mon May 17 17:46:07 1999
@@ -0,0 +1,37 @@
+#! /bin/sh
+
+# Copyright (C) 1999 Free Software Foundation
+# by Alexandre Oliva <oliva@dcc.unicamp.br>
+
+# concat.sh: concatenate adjacent "strings". It assumes there are no
+# strings containing only spaces. Adjacent strings must be separated
+# by at least one space or one new-line, followed by zero or more
+# spaces. It reads from standard input and writes to standard output.
+
+# This script is Free Software.
+
+# You may redistribute it and/or modify it under the terms of the
+# GNU General Public License, as published by the Free Software
+# Foundation; either version 2, or (at your option) any later version.
+#
+# fixincludes is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with fixincludes. See the file "COPYING". If not,
+# write to: The Free Software Foundation, Inc.,
+# 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+
+sed '
+: start
+s/" *"//g
+/"$/ {
+ s/"$/\\/
+ n
+ s/^/" /
+ b start
+}
+'
Index: gcc/fixinc/fixincl.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/fixinc/fixincl.c,v
retrieving revision 1.10
diff -u -r1.10 fixincl.c
--- gcc/fixinc/fixincl.c 1999/05/17 12:39:18 1.10
+++ gcc/fixinc/fixincl.c 1999/05/18 00:46:08
@@ -58,6 +58,13 @@
#endif
#define NAME_TABLE_SIZE (MINIMUM_MAXIMUM_LINES * MAXPATHLEN)
+#ifndef EXIT_SUCCESS
+# define EXIT_SUCCESS 0
+#endif
+#ifndef EXIT_FAILURE
+# define EXIT_FAILURE 1
+#endif
+
char *file_name_buf;
#define tSCC static const char
@@ -269,7 +276,7 @@
}
}
#else
-#error "NON-BOGUS LIMITS NOT SUPPORTED?!?!"
+ /*#*/ error "NON-BOGUS LIMITS NOT SUPPORTED?!?!"
#endif
/*
@@ -382,7 +389,9 @@
`waitpid(2)'. We also ensure that the children exit with success. */
void
-wait_for_pid( pid_t child, int file_name_ct )
+wait_for_pid(child, file_name_ct)
+ pid_t child;
+ int file_name_ct;
{
for (;;) {
int status;
@@ -934,18 +943,20 @@
char *pz_data;
const char *pz_file_name;
{
- static char env_current_file[1024] = { "file=" };
+ static char env_current_file[1024];
tFixDesc *p_fixd = fixDescList;
int todo_ct = FIX_COUNT;
- t_fd_pair fdp = { -1, -1 };
+ int read_fd = -1;
int num_children = 0;
/* IF this is the first time through,
THEN put the 'file' environment variable into the environment.
This is used by some of the subject shell scripts and tests. */
- if (env_current_file[5] == NUL)
+ if (env_current_file[0] == NUL) {
+ strcpy (env_current_file, "file=");
putenv (env_current_file);
+ }
/*
Ghastly as it is, this actually updates the value of the variable:
@@ -1059,10 +1070,10 @@
the first fix. Any subsequent fixes will use the
stdout descriptor of the previous fix as its stdin. */
- if (fdp.read_fd == -1)
+ if (read_fd == -1)
{
- fdp.read_fd = open (pz_file_name, O_RDONLY);
- if (fdp.read_fd < 0)
+ read_fd = open (pz_file_name, O_RDONLY);
+ if (read_fd < 0)
{
fprintf (stderr, "Error %d (%s) opening %s\n", errno,
strerror (errno), pz_file_name);
@@ -1071,7 +1082,7 @@
}
/* This loop should only cycle for 1/2 of one loop.
- "chain_open" starts a process that uses "fdp.read_fd" as
+ "chain_open" starts a process that uses "read_fd" as
its stdin and returns the new fd this process will use
for stdout. */
@@ -1079,14 +1090,14 @@
{
tSCC z_err[] = "Error %d (%s) starting filter process for %s\n";
static int failCt = 0;
- int fd = chain_open (fdp.read_fd,
+ int fd = chain_open (read_fd,
(t_pchar *) p_fixd->patch_args,
(process_chain_head == -1)
? &process_chain_head : (pid_t *) NULL);
if (fd != -1)
{
- fdp.read_fd = fd;
+ read_fd = fd;
num_children++;
break;
}
@@ -1106,7 +1117,7 @@
/* IF after all the tests we did not start any patch programs,
THEN quit now. */
- if (fdp.read_fd < 0)
+ if (read_fd < 0)
return;
/* OK. We have work to do. Read back in the output
@@ -1117,7 +1128,7 @@
output of the filter chain.
*/
{
- FILE *in_fp = fdopen (fdp.read_fd, "r");
+ FILE *in_fp = fdopen (read_fd, "r");
FILE *out_fp = (FILE *) NULL;
char *pz_cmp = pz_data;
@@ -1173,7 +1184,7 @@
}
fclose (in_fp);
}
- close (fdp.read_fd); /* probably redundant, but I'm paranoid */
+ close (read_fd); /* probably redundant, but I'm paranoid */
/* Wait for child processes created by chain_open()
to avoid creating zombies. */
Index: gcc/fixinc/genfixes
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/fixinc/genfixes,v
retrieving revision 1.2
diff -u -r1.2 genfixes
--- gcc/fixinc/genfixes 1999/04/05 06:58:30 1.2
+++ gcc/fixinc/genfixes 1999/05/18 00:46:08
@@ -7,7 +7,9 @@
autogen inclhack.def
echo AutoGen-ing fixincl.x
-autogen -T fixincl.tpl -b fixincl inclhack.def
+autogen -T fixincl.tpl -b fixinclx inclhack.def
+./concat.sh < fixinclx.x > fixincl.x
+rm -f fixinclx.x
echo AutoGen-ing fixincl.sh
autogen -DPROGRAM=1 -b fixincl inclhack.def
Index: gcc/fixinc/gnu-regex.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/fixinc/gnu-regex.c,v
retrieving revision 1.1
diff -u -r1.1 gnu-regex.c
--- gcc/fixinc/gnu-regex.c 1999/04/29 14:05:30 1.1
+++ gcc/fixinc/gnu-regex.c 1999/05/18 00:46:09
@@ -80,6 +80,16 @@
#else /* not emacs */
+# include "auto-host.h"
+
+# if !defined(const) && !defined(HAVE_CONST)
+# define const
+# endif
+
+# if !defined(volatile) && !defined(HAVE_VOLATILE)
+# define volatile
+# endif
+
/* If we are not linking with Emacs proper,
we can't use the relocating allocator
even if config.h says that we can. */
Index: gcc/fixinc/procopen.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/fixinc/procopen.c,v
retrieving revision 1.3
diff -u -r1.3 procopen.c
--- gcc/fixinc/procopen.c 1999/03/17 22:03:32 1.3
+++ gcc/fixinc/procopen.c 1999/05/18 00:46:10
@@ -104,9 +104,11 @@
t_pchar *pp_args;
pid_t *p_child;
{
- t_fd_pair stdout_pair = {-1, -1};
+ t_fd_pair stdout_pair;
pid_t ch_id;
char *pz_cmd;
+
+ stdout_pair.read_fd = stdout_pair.write_fd = -1;
/*
* Create a pipe it will be the child process' stdout,
Index: gcc/fixinc/server.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/fixinc/server.c,v
retrieving revision 1.6
diff -u -r1.6 server.c
--- gcc/fixinc/server.c 1999/05/07 08:42:27 1.6
+++ gcc/fixinc/server.c 1999/05/18 00:46:10
@@ -86,6 +86,10 @@
#define NUL '\0'
#endif
+#if !defined(volatile) && !defined(HAVE_VOLATILE)
+# define volatile
+#endif
+
STATIC volatile bool read_pipe_timeout;
static t_pchar def_args[] =