This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
fixinc patch for BeOS
- To: Daniel Berlin <dberlin at cygnus dot com>
- Subject: fixinc patch for BeOS
- From: Bruce Korb <bkorb at sco dot COM>
- Date: Thu, 30 Nov 2000 11:10:49 -0800
- CC: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Organization: The Santa Cruz Operation
Hi Dan,
How does this look for you?
2000-11-30 Daniel Berlin <dberlin@redhat.com>
Bruce Korb <bkorb@gnu.org>
* fixinc/*: global substitute /__MSDOS__/SEPARATE_FIX_PROC/
* fixinc/Makefile.BEOS: new file
* fixinc/mkfixinc.sh: use the above for *-*-beos*
* fixinc/Makefile.DOS: define SEPARATE_FIX_PROC for build
* fixinc/fixfix.c(wrap_fix): avoid wrapping files that
use the "__need_" hackery. It breaks them.
* fixinc/fixincl.c(process - SEPARATE_FIX_PROC):
Sometimes on DOS and BeOS the temp output file cannot be opened.
Skip the file noisily. Ought to be fixed instead.
Index: Makefile.DOS
===================================================================
RCS file: /cvs/gcc/egcs/gcc/fixinc/Makefile.DOS,v
retrieving revision 1.1
diff -u -r1.1 Makefile.DOS
--- Makefile.DOS 2000/08/21 16:17:35 1.1
+++ Makefile.DOS 2000/11/30 18:43:29
@@ -24,7 +24,8 @@
# the DJGPP (aka MS-DOS) port of GCC.
CFLAGS = -Wall -g -O2
-FIXINC_DEFS = -DIN_GCC -D__MSDOS__ $(CFLAGS) $(CPPFLAGS) $(INCLUDES)
+FIXINC_DEFS = -DIN_GCC $(CFLAGS) $(CPPFLAGS) $(INCLUDES) \
+ -D__MSDOS__ -DSEPARATE_FIX_PROC
CC = gcc
SHELL = /bin/sh
Index: fixfixes.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/fixinc/fixfixes.c,v
retrieving revision 1.36
diff -u -r1.36 fixfixes.c
--- fixfixes.c 2000/11/22 02:23:40 1.36
+++ fixfixes.c 2000/11/30 18:43:30
@@ -60,7 +60,7 @@
#include "fixlib.h"
#define GTYPE_SE_CT 1
-#ifdef __MSDOS__
+#ifdef SEPARATE_FIX_PROC
#include "fixincl.x"
#endif
@@ -595,12 +595,20 @@
FIX_PROC_HEAD( wrap_fix )
{
+ tSCC z_no_wrap_pat[] = "^#if.*__need_";
+ static regex_t no_wrapping_re = { NULL, 0, 0 };
+
char z_fixname[ 64 ];
tCC* pz_src = p_fixd->fix_name;
tCC* pz_name = z_fixname;
char* pz_dst = z_fixname;
+ int do_end = 0;
size_t len = 0;
+ if (no_wrapping_re.allocated == 0)
+ compile_re( z_no_wrap_pat, &no_wrapping_re, 0, "no-wrap pattern",
+ "wrap-fix" );
+
for (;;) {
char ch = *(pz_src++);
@@ -625,8 +633,16 @@
}
}
- printf( "#ifndef FIXINC_%s_CHECK\n", pz_name );
- printf( "#define FIXINC_%s_CHECK 1\n\n", pz_name );
+ /*
+ * IF we do *not* match the no-wrap re, then we have a double negative.
+ * A double negative means YES.
+ */
+ if (regexec (&no_wrapping_re, text, 0, NULL, 0) != 0)
+ {
+ printf( "#ifndef FIXINC_%s_CHECK\n", pz_name );
+ printf( "#define FIXINC_%s_CHECK 1\n\n", pz_name );
+ do_end = 1;
+ }
if (p_fixd->patch_args[1] == (tCC*)NULL)
fputs( text, stdout );
@@ -637,8 +653,10 @@
if (p_fixd->patch_args[2] != (tCC*)NULL)
fputs( p_fixd->patch_args[2], stdout );
}
+
+ if (do_end != 0)
+ printf( "\n#endif /* FIXINC_%s_CHECK */\n", pz_name );
- printf( "\n#endif /* FIXINC_%s_CHECK */\n", pz_name );
if (pz_name != z_fixname)
free( (void*)pz_name );
}
@@ -729,7 +747,7 @@
(*pfe->fix_proc)( filname, buf, p_fixd );
}
-#ifdef __MSDOS__
+#ifdef SEPARATE_FIX_PROC
tSCC z_usage[] =
"USAGE: applyfix <fix-name> <file-to-fix> <file-source> <file-destination>\n";
tSCC z_reopen[] =
@@ -748,7 +766,7 @@
if (argc != 5)
{
usage_failure:
- fputs( z_usage, stderr );
+ fputs (z_usage, stderr);
return EXIT_FAILURE;
}
@@ -759,15 +777,15 @@
if (! isdigit( *pz ))
goto usage_failure;
- idx = strtol( pz, &pz, 10 );
+ idx = strtol (pz, &pz, 10);
if ((*pz != NUL) || ((unsigned)idx >= FIX_COUNT))
goto usage_failure;
pFix = fixDescList + idx;
}
- if (freopen( argv[3], "r", stdin ) != stdin)
+ if (freopen (argv[3], "r", stdin) != stdin)
{
- fprintf( stderr, z_reopen, errno, strerror( errno ), argv[3], "in" );
+ fprintf (stderr, z_reopen, errno, strerror( errno ), argv[3], "in");
return EXIT_FAILURE;
}
@@ -781,23 +799,23 @@
pz_tmp_dot = strchr( pz_tmp_base, '.' );
if (pathconf( pz_tmptmp, _PC_NAME_MAX ) <= 12 /* is this DOS or Windows9X? */
&& pz_tmp_dot != (char*)NULL)
- strcpy( pz_tmp_dot+1, "X" ); /* nuke the original extension */
+ strcpy (pz_tmp_dot+1, "X"); /* nuke the original extension */
else
- strcat( pz_tmptmp, ".X" );
- if (freopen( pz_tmptmp, "w", stdout ) != stdout)
+ strcat (pz_tmptmp, ".X");
+ if (freopen (pz_tmptmp, "w", stdout) != stdout)
{
- fprintf( stderr, z_reopen, errno, strerror( errno ), pz_tmptmp, "out" );
+ fprintf (stderr, z_reopen, errno, strerror( errno ), pz_tmptmp, "out");
return EXIT_FAILURE;
}
- apply_fix( pFix, argv[1] );
- close( STDOUT_FILENO );
- close( STDIN_FILENO );
- unlink( argv[4] );
- if (rename( pz_tmptmp, argv[4] ) != 0)
+ apply_fix (pFix, argv[1]);
+ fclose (stdout);
+ fclose (stdin);
+ unlink (argv[4]);
+ if (rename (pz_tmptmp, argv[4]) != 0)
{
- fprintf( stderr, "error %d (%s) renaming %s to %s\n", errno,
- strerror( errno ), pz_tmptmp, argv[4] );
+ fprintf (stderr, "error %d (%s) renaming %s to %s\n", errno,
+ strerror( errno ), pz_tmptmp, argv[4]);
return EXIT_FAILURE;
}
Index: fixincl.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/fixinc/fixincl.c,v
retrieving revision 1.42
diff -u -r1.42 fixincl.c
--- fixincl.c 2000/11/17 04:16:55 1.42
+++ fixincl.c 2000/11/30 18:43:31
@@ -30,7 +30,7 @@
#endif
#include <signal.h>
-#ifndef __MSDOS__
+#ifndef SEPARATE_FIX_PROC
#include "server.h"
#endif
@@ -181,7 +181,7 @@
}
#endif /* DO_STATS */
-# ifdef __MSDOS__
+# ifdef SEPARATE_FIX_PROC
unlink( pz_temp_file );
# endif
return EXIT_SUCCESS;
@@ -201,7 +201,7 @@
*/
run_compiles ();
sprintf (zBuf, zFmt, program_id);
-#ifndef __MSDOS__
+#ifndef SEPARATE_FIX_PROC
puts (zBuf + 5);
exit (strcmp (run_shell (zBuf), program_id));
#else
@@ -297,7 +297,7 @@
*/
run_compiles ();
-# ifdef __MSDOS__
+# ifdef SEPARATE_FIX_PROC
/* NULL as the first argument to `tempnam' causes it to DTRT
wrt the temporary directory where the file will be created. */
pz_temp_file = tempnam( NULL, "fxinc" );
@@ -380,7 +380,7 @@
machine_matches( p_fixd )
tFixDesc *p_fixd;
{
-# ifndef __MSDOS__
+# ifndef SEPARATE_FIX_PROC
tSCC case_fmt[] = "case %s in\n"; /* 9 bytes, plus string */
tSCC esac_fmt[] =
" )\n echo %s ;;\n* ) echo %s ;;\nesac";/* 4 bytes */
@@ -447,7 +447,7 @@
}
return BOOL_TRUE;
-# else /* is __MSDOS__ */
+# else /* is SEPARATE_FIX_PROC */
const char **papz_machs = p_fixd->papz_machs;
int invert = (p_fixd->fd_flags & FD_MACH_IFNOT) != 0;
for (;;)
@@ -610,7 +610,7 @@
the name of the file that we might want to fix
Result: APPLY_FIX or SKIP_FIX, depending on the result of the
shell script we run. */
-#ifndef __MSDOS__
+#ifndef SEPARATE_FIX_PROC
int
test_test (p_test, pz_test_file)
tTestDesc *p_test;
@@ -805,7 +805,7 @@
Somebody wrote a *_fix subroutine that we must call.
*/
-#ifndef __MSDOS__
+#ifndef SEPARATE_FIX_PROC
int
internal_fix (read_fd, p_fixd)
int read_fd;
@@ -871,10 +871,10 @@
apply_fix (p_fixd, pz_curr_file);
exit (0);
}
-#endif /* !__MSDOS__ */
+#endif /* !SEPARATE_FIX_PROC */
-#ifdef __MSDOS__
+#ifdef SEPARATE_FIX_PROC
static void
fix_with_system (p_fixd, pz_fix_file, pz_file_source, pz_temp_file)
tFixDesc* p_fixd;
@@ -914,16 +914,25 @@
else /* NOT an "internal" fix: */
{
size_t parg_size;
+#ifdef __MSDOS__
/* Don't use the "src > dstX; rm -f dst; mv -f dstX dst" trick:
dst is a temporary file anyway, so we know there's no other
file by that name; and DOS's system(3) doesn't mind to
clobber existing file in redirection. Besides, with DOS 8+3
limited file namespace, we can easily lose if dst already has
an extension that is 3 or more characters long.
- The following bizarre use of 'cat' only works on DOS boxes.
+
+ I do not think the 8+3 issue is relevant because all the files
+ we operate on are named "*.h", making 8+2 adequate. Anyway,
+ the following bizarre use of 'cat' only works on DOS boxes.
It is causing the file to be dropped into a temporary file for
'cat' to read (pipes do not work on DOS). */
tSCC z_cmd_fmt[] = " %s | cat > %s";
+#else
+ /* Don't use positional formatting arguments because some lame-o
+ implementations cannot cope :-(. */
+ tSCC z_cmd_fmt[] = " %s > %sX ; rm -f %s; mv -f %sX %s";
+#endif
tCC** ppArgs = p_fixd->patch_args;
argsize = sizeof( z_cmd_fmt ) + strlen( pz_temp_file )
@@ -998,7 +1007,12 @@
/*
* add the file machinations.
*/
- sprintf( pz_scan, z_cmd_fmt, pz_file_source, pz_temp_file );
+#ifdef __MSDOS__
+ sprintf (pz_scan, z_cmd_fmt, pz_file_source, pz_temp_file );
+#else
+ sprintf (pz_scan, z_cmd_fmt, pz_file_source, pz_temp_file,
+ pz_temp_file, pz_temp_file, pz_temp_file);
+#endif
}
system( pz_cmd );
free( (void*)pz_cmd );
@@ -1011,7 +1025,7 @@
its stdin and returns the new fd this process will use
for stdout. */
-#else /* is *NOT* __MSDOS__ */
+#else /* is *NOT* SEPARATE_FIX_PROC */
int
start_fixer (read_fd, p_fixd, pz_fix_file)
int read_fd;
@@ -1095,7 +1109,7 @@
int test_ct;
tTestDesc *p_test;
-# ifdef __MSDOS__
+# ifdef SEPARATE_FIX_PROC
/*
* There is only one fix that uses a shell script as of this writing.
* I hope to nuke it anyway, it does not apply to DOS and it would
@@ -1302,9 +1316,9 @@
tFixDesc *p_fixd = fixDescList;
int todo_ct = FIX_COUNT;
int read_fd = -1;
-# ifndef __MSDOS__
+# ifndef SEPARATE_FIX_PROC
int num_children = 0;
-# else /* is __MSDOS__ */
+# else /* is SEPARATE_FIX_PROC */
char* pz_file_source = pz_curr_file;
# endif
@@ -1327,7 +1341,7 @@
if (VLEVEL( VERB_PROGRESS ) && have_tty)
fprintf (stderr, "%6d %-50s \r", data_map_size, pz_curr_file );
-# ifndef __MSDOS__
+# ifndef SEPARATE_FIX_PROC
process_chain_head = NOPROCESS;
/* For every fix in our fix list, ... */
@@ -1388,7 +1402,7 @@
} while (--num_children > 0);
}
-# else /* is __MSDOS__ */
+# else /* is SEPARATE_FIX_PROC */
for (; todo_ct > 0; p_fixd++, todo_ct--)
{
@@ -1409,12 +1423,20 @@
pz_file_source = pz_temp_file;
}
- read_fd = open( pz_temp_file, O_RDONLY );
- test_for_changes( read_fd );
- /* Unlinking a file while it is still open is a Bad Idea on
- DOS/Windows. */
- close( read_fd );
- unlink( pz_temp_file );
+ read_fd = open (pz_temp_file, O_RDONLY);
+ if (read_fd < 0)
+ {
+ fprintf (stderr, "error %d (%s) opening output (%s) for read\n",
+ errno, xstrerror (errno), pz_temp_file);
+ }
+ else
+ {
+ test_for_changes (read_fd);
+ /* Unlinking a file while it is still open is a Bad Idea on
+ DOS/Windows. */
+ close (read_fd);
+ unlink (pz_temp_file);
+ }
# endif
UNLOAD_DATA();
Index: fixlib.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/fixinc/fixlib.c,v
retrieving revision 1.14
diff -u -r1.14 fixlib.c
--- fixlib.c 2000/11/17 04:16:55 1.14
+++ fixlib.c 2000/11/30 18:43:31
@@ -244,7 +244,7 @@
#endif
-#ifdef __MSDOS__
+#ifdef SEPARATE_FIX_PROC
char*
make_raw_shell_str( pz_d, pz_s, smax )
Index: fixlib.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/fixinc/fixlib.h,v
retrieving revision 1.18
diff -u -r1.18 fixlib.h
--- fixlib.h 2000/09/12 14:28:27 1.18
+++ fixlib.h 2000/11/30 18:43:31
@@ -209,7 +209,7 @@
apply_fix_p_t
run_test PARAMS(( tCC* t_name, tCC* f_name, tCC* text ));
-#ifdef __MSDOS__
+#ifdef SEPARATE_FIX_PROC
char* make_raw_shell_str
PARAMS(( char* pz_d, tCC* pz_s, size_t smax ));
#endif
Index: mkfixinc.sh
===================================================================
RCS file: /cvs/gcc/egcs/gcc/fixinc/mkfixinc.sh,v
retrieving revision 1.28
diff -u -r1.28 mkfixinc.sh
--- mkfixinc.sh 2000/11/17 23:48:15 1.28
+++ mkfixinc.sh 2000/11/30 18:43:31
@@ -45,6 +45,10 @@
fixincludes=fixinc.ptx
;;
+ *-*-beos* )
+ MAKE="${MAKE} -f Makefile.BEOS"
+ ;;
+
alpha*-dec-vms* | \
arm-semi-aout | armel-semi-aout | \
arm-semi-aof | armel-semi-aof | \
@@ -55,7 +59,6 @@
hppa1.1-*-bsd* | \
hppa1.0-*-bsd* | \
hppa*-*-lites* | \
- *-*-beos* | \
*-*-gnu* | \
i?86-moss-msdos* | i?86-*-moss* | \
i?86-*-osf1* | \