Commit 1f414ac4 by Bruce Korb

Merge from fixincl-branch

From-SVN: r25558
parent 9a9f6326
# Makefile for GNU C++ compiler. # Makefile for GNU compilers.
# Copyright (C) 1987, 88, 90-5, 1998 Free Software Foundation, Inc. # Copyright (C) 1998, 1999 Free Software Foundation, Inc.
#This file is part of GNU CC. #This file is part of GNU CC.
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
# Its purpose is to build the any-platforms fixinc.sh script. # Its purpose is to build the any-platforms fixinc.sh script.
CFLAGS = -g CFLAGS = -g
FIXINC_DEFS = @fixinc_defs@
CC = @CC@ CC = @CC@
SHELL = /bin/sh SHELL = /bin/sh
...@@ -39,11 +40,11 @@ default : gen ...@@ -39,11 +40,11 @@ default : gen
# Specify the directories to be searched for header files. # Specify the directories to be searched for header files.
# Both . and srcdir are used, in that order. # Both . and srcdir are used, in that order.
INCLUDES = -I. -I.. -I$(srcdir) -I$(srcdir)/.. -I$(srcdir)/../config INCLUDES = -I. -I.. -I$(srcdir) -I$(srcdir)/.. -I$(srcdir)/../config -I$(srcdir)/../../include
# Always use -I$(srcdir)/config when compiling. # Always use -I$(srcdir)/config when compiling.
.c.o: .c.o:
$(CC) -c $(CFLAGS) $(CPPFLAGS) $(INCLUDES) $< $(CC) -c $(CFLAGS) $(FIXINC_DEFS) $(CPPFLAGS) $(INCLUDES) $<
# The only suffixes we want for implicit rules are .c and .o. # The only suffixes we want for implicit rules are .c and .o.
.SUFFIXES: .SUFFIXES:
...@@ -55,12 +56,11 @@ INCLUDES = -I. -I.. -I$(srcdir) -I$(srcdir)/.. -I$(srcdir)/../config ...@@ -55,12 +56,11 @@ INCLUDES = -I. -I.. -I$(srcdir) -I$(srcdir)/.. -I$(srcdir)/../config
## ##
## Makefile for constructing the "best" include fixer we can ## Makefile for constructing the "best" include fixer we can
## ##
## $Id: Makefile.in,v 1.2 1998/12/16 21:18:54 law Exp $
##
## # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # ## # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
OBJ = fixincl.o server.o regex.o OBJ = fixincl.o server.o regex.o
HDR = server.h regex.h HDR = server.h regex.h
LIBERTY = ../../libiberty/libiberty.a
SH_TARGET = inclhack.sh fixincl.sh SH_TARGET = inclhack.sh fixincl.sh
BIN_TARGET = fixincl BIN_TARGET = fixincl
...@@ -75,13 +75,13 @@ gen : $(SH_TARGET) fixincl.x ...@@ -75,13 +75,13 @@ gen : $(SH_TARGET) fixincl.x
$(OBJ): $(HDR) $(OBJ): $(HDR)
fixincl: $(OBJ) fixincl: $(OBJ)
@echo $(CC) -o $@ $(OBJ) $(LIB) ; \ @echo $(CC) -o $@ $(OBJ) $(LIBERTY) $(LIB) ; \
if $(CC) -o $@ $(OBJ) $(LIB) ; then : ; else \ if $(CC) -o $@ $(OBJ) $(LIBERTY) $(LIB) ; then : ; else \
rm -f $@ ; (echo "#! /bin/sh" ; echo exit 1 ) > $@ ; \ rm -f $@ ; (echo "#! /bin/sh" ; echo exit 1 ) > $@ ; \
chmod 777 $@ ; fi chmod 777 $@ ; fi
regex.o: regex.c regex.o: regex.c
-$(CC) $(CFLAGS) -DSTDC_HEADERS=1 -c regex.c -$(CC) $(CFLAGS) $(FIXINC_DEFS) -DSTDC_HEADERS=1 -c $(srcdir)/regex.c
fixincl.o : fixincl.x fixincl.c fixincl.o : fixincl.x fixincl.c
server.o : server.c server.h server.o : server.c server.h
...@@ -92,21 +92,28 @@ fixincl.x: fixincl.tpl inclhack.def ...@@ -92,21 +92,28 @@ fixincl.x: fixincl.tpl inclhack.def
autogen -T $(srcdir)/fixincl.tpl -b fixincl \ autogen -T $(srcdir)/fixincl.tpl -b fixincl \
$(srcdir)/inclhack.def ; \ $(srcdir)/inclhack.def ; \
else echo You need to install autogen ; \ else echo You need to install autogen ; \
$(CP) $(srcdir)/$@ . ; fi if [ `pwd` != `cd $(srcdir) ; pwd` ] ; then \
$(CP) $(srcdir)/$@ . ; \
else touch $@ ; fi ; fi
inclhack.sh: inclhack.def inclhack.tpl hackshell.tpl inclhack.sh: inclhack.def inclhack.tpl hackshell.tpl
@if ( autogen --help > /dev/null 2>&1 ) ; then \ @if ( autogen --help > /dev/null 2>&1 ) ; then \
echo autogen inclhack.def ; \ echo autogen inclhack.def ; \
autogen inclhack.def ; \ autogen -L$(srcdir) $(srcdir)/inclhack.def ; \
else echo You need to install autogen ; \ else echo You need to install autogen ; \
$(CP) $(srcdir)/$@ . ; fi if [ `pwd` != `cd $(srcdir) ; pwd` ] ; then \
$(CP) $(srcdir)/$@ . ; \
else touch $@ ; fi ; fi
fixincl.sh: inclhack.def inclhack.tpl fixincl.sh: inclhack.def inclhack.tpl
@if ( autogen --help > /dev/null 2>&1 ) ; then \ @if ( autogen --help > /dev/null 2>&1 ) ; then \
echo autogen -DPROGRAM=1 -b fixincl inclhack.def ; \ echo autogen -DPROGRAM=1 -b fixincl inclhack.def ; \
autogen -DPROGRAM=1 -b fixincl inclhack.def ; touch $@ ; \ autogen -DPROGRAM=1 -b fixincl -L$(srcdir) \
$(srcdir)/inclhack.def ; touch $@ ; \
else echo You need to install autogen ; \ else echo You need to install autogen ; \
$(CP) $(srcdir)/$@ . ; fi if [ `pwd` != `cd $(srcdir) ; pwd` ] ; then \
$(CP) $(srcdir)/$@ . ; \
else touch $@ ; fi ; fi
clean: clean:
rm -f *.o $(TARGETS) fixincl.x rm -f *.o $(TARGETS) fixincl.x
...@@ -120,13 +127,19 @@ install: $(TARGETS) ...@@ -120,13 +127,19 @@ install: $(TARGETS)
@rm -f ../fixinc.sh ; \ @rm -f ../fixinc.sh ; \
if ( ./fixincl -v > /dev/null 2>&1 ) ; then \ if ( ./fixincl -v > /dev/null 2>&1 ) ; then \
echo cp fixincl.sh ../fixinc.sh ; \ echo cp fixincl.sh ../fixinc.sh ; \
cp fixincl.sh ../fixinc.sh ; \ if [ -f ./fixincl.sh ] ; \
then cp fixincl.sh ../fixinc.sh ; \
else cp $(srcdir)/fixincl.sh ../fixinc.sh ; fi ; \
chmod 555 ../fixinc.sh ; \ chmod 555 ../fixinc.sh ; \
rm -f ../fixincl ; \ rm -f ../fixincl ; \
echo cp fixincl .. ; \ echo cp fixincl .. ; \
cp fixincl .. ; \ cp fixincl .. ; \
chmod 555 ../fixincl ; \ chmod 555 ../fixincl ; \
else \ else \
echo Could not install binary fixincludes. ; \
echo Installing shell script instead. ; \
echo cp inclhack.sh ../fixinc.sh ; \ echo cp inclhack.sh ../fixinc.sh ; \
cp inclhack.sh ../fixinc.sh ; \ if [ -f ./inclhack.sh ] ; \
then cp inclhack.sh ../fixinc.sh ; \
else cp $(srcdir)/inclhack.sh ../fixinc.sh ; fi ; \
fi fi
/*
* $Id: fixincl.c,v 1.2 1998/12/16 21:19:03 law Exp $
*
* Install modified versions of certain ANSI-incompatible system header
* files which are fixed to work correctly with ANSI C and placed in a
* directory that GNU C will search.
*
* See README-fixinc for more information.
*
* fixincl 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.
*
* fixincl 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 fixincl. See the file "COPYING". If not,
* write to: The Free Software Foundation, Inc.,
* 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
/* Install modified versions of certain ANSI-incompatible system header
files which are fixed to work correctly with ANSI C and placed in a
directory that GNU C will search.
Copyright (C) 1997, 1998, 1999 Free Software Foundation, Inc.
This file is part of GNU CC.
GNU CC is free software; you can 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.
GNU CC 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 GNU CC; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#ifdef FIXINC_BROKEN
/* The fixincl program is known to not run properly on this particular
system. Instead of producing a probably broken executable, we force
a compilation error and let the mkfixinc.sh script install the
inclhack.sh shell script instead. */
# include "The fixincl program does not work properly on this system!"
#endif
#include "config.h"
#include <sys/types.h>
#include <sys/param.h> #include <sys/param.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h> #ifdef HAVE_SYS_WAIT_H
#include <sys/wait.h> #include <sys/wait.h>
#endif
#include <signal.h> #include <signal.h>
#include <stdio.h> #include <stdio.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h> #include <unistd.h>
#endif
#include <stdlib.h> #include <stdlib.h>
#include <errno.h> #include <errno.h>
#include <string.h> #include <string.h>
#ifdef HAVE_FCNTL_H
#include <fcntl.h> #include <fcntl.h>
#endif
#include <ctype.h> #include <ctype.h>
#include "regex.h" #include "regex.h"
#include "server.h" #include "server.h"
static const char program_id[] = "fixincl version 1.0";
#define MINIMUM_MAXIMUM_LINES 128
/* If this particular system's header files define the macro `MAXPATHLEN',
we happily take advantage of it; otherwise we use a value which ought
to be large enough. */
#ifndef MAXPATHLEN
# define MAXPATHLEN 4096
#endif
#define NAME_TABLE_SIZE (MINIMUM_MAXIMUM_LINES * MAXPATHLEN)
char *file_name_buf;
#define tSCC static const char #define tSCC static const char
#define tCC const char #define tCC const char
#define tSC static char #define tSC static char
typedef int tSuccess; typedef int t_success;
#define FAILURE (-1)
#define SUCCESS 0
#define PROBLEM 1
#define FAILURE ((tSuccess)-1) #define SUCCEEDED(p) ((p) == SUCCESS)
#define SUCCESS ((tSuccess) 0) #define SUCCESSFUL(p) SUCCEEDED (p)
#define PROBLEM ((tSuccess) 1) #define FAILED(p) ((p) < SUCCESS)
#define HADGLITCH(p) ((p) > SUCCESS)
#define SUCCEEDED( p ) ((p) == SUCCESS) #define NUL '\0'
#define SUCCESSFUL( p ) SUCCEEDED( p )
#define FAILED( p ) ((p) < SUCCESS)
#define HADGLITCH( p ) ((p) > SUCCESS)
#define NUL '\0' /* Test Descriptor
Each fix may have associated tests that determine
whether the fix needs to be applied or not.
Each test has a type (from the te_test_type enumeration);
associated test text; and, if the test is TT_EGREP or
the negated form TT_NEGREP, a pointer to the compiled
version of the text string.
*/
typedef enum typedef enum
{ {
TT_TEST, TT_EGREP, TT_NEGREP TT_TEST, TT_EGREP, TT_NEGREP
} } te_test_type;
teTestType;
typedef struct test_desc tTestDesc; typedef struct test_desc tTestDesc;
struct test_desc struct test_desc
{ {
teTestType type; te_test_type type;
const char *pzTest; const char *pz_test_text;
regex_t *pTestRegex; regex_t *p_test_regex;
}; };
typedef struct patch_desc tPatchDesc; typedef struct patch_desc tPatchDesc;
/* Fix Descriptor
Everything you ever wanted to know about how to apply
a particular fix (which files, how to qualify them,
how to actually make the fix, etc...)
*/
#define FD_MACH_ONLY 0x0000 #define FD_MACH_ONLY 0x0000
#define FD_MACH_IFNOT 0x0001 #define FD_MACH_IFNOT 0x0001
#define FD_SKIP_TEST 0x8000 #define FD_SKIP_TEST 0x8000
typedef struct fix_desc tFixDesc; typedef struct fix_desc tFixDesc;
struct fix_desc struct fix_desc
{ {
const char* pzFixName; /* Name of the fix */ const char* fix_name; /* Name of the fix */
const char* pzFileList; /* List of files it applies to */ const char* file_list; /* List of files it applies to */
const char** papzMachs; /* List of machine/os-es it applies to */ const char** papz_machs; /* List of machine/os-es it applies to */
regex_t* pListRegex; regex_t* unused;
int testCt; int test_ct;
int fdFlags; int fd_flags;
tTestDesc* pTestDesc; tTestDesc* p_test_desc;
const char** papzPatchArgs; const char** patch_args;
}; };
char *pzDestDir = (char *) NULL; /* Working environment strings. Essentially, invocation 'options'. */
char *pzSrcDir = (char *) NULL; char *pz_dest_dir = NULL;
char *pzMachine = (char *) NULL; char *pz_src_dir = NULL;
char *pz_machine = NULL;
pid_t chainHead = (pid_t) - 1;
pid_t process_chain_head = (pid_t) -1;
const char zInclQuote[] = "^[ \t]*#[ \t]*include[ \t]*\"[^/]";
regex_t inclQuoteRegex; const char incl_quote_pat[] = "^[ \t]*#[ \t]*include[ \t]*\"[^/]";
regex_t incl_quote_re;
char zFileNameBuf[0x8000];
char *load_file (const char *pzFile);
char *loadFile (const char *pzFile); void process (char *data, const char *file);
void process (char *data, const char *dir, const char *file); void run_compiles (void);
void runCompiles (void);
#include "fixincl.x" #include "fixincl.x"
/* * * * * * * * * * * * * * * * * * *
*
* MAIN ROUTINE
*/
int int
main (argc, argv) main (argc, argv)
int argc; int argc;
char **argv; char **argv;
{ {
static const char zGnuLib[] = static const char gnu_lib_mark[] =
"This file is part of the GNU C Library"; "This file is part of the GNU C Library";
static const char zVarNotFound[] = static const char var_not_found[] =
"fixincl ERROR: %s environment variable not defined\n"; "fixincl ERROR: %s environment variable not defined\n";
#ifndef NO_BOGOSITY_LIMITS #ifndef NO_BOGOSITY_LIMITS
# define BOGUS_LIMIT 256 # define BOGUS_LIMIT MINIMUM_MAXIMUM_LINES
size_t loopCt; size_t loop_ct;
#endif #endif
char *apzNames[BOGUS_LIMIT]; char *apz_names[BOGUS_LIMIT];
size_t fileNameCt; size_t file_name_ct;
if (argc != 1) /* Before anything else, ensure we can allocate our file name buffer. */
file_name_buf = (char *) malloc (NAME_TABLE_SIZE);
if (file_name_buf == (char *) NULL)
{ {
if (argc != 2) fprintf (stderr, "fixincl cannot allocate 0x%08X bytes\n",
{ NAME_TABLE_SIZE);
fputs ("fixincl ERROR: too many command line arguments\n", stderr); exit (EXIT_FAILURE);
exit (EXIT_FAILURE); }
}
switch (argc)
{
case 1:
break;
case 2:
if (strcmp (argv[1], "-v") == 0) if (strcmp (argv[1], "-v") == 0)
{ {
fputs ("$Id: fixincl.c,v 1.2 1998/12/16 21:19:03 law Exp $\n", stderr); static const char zFmt[] = "echo '%s'";
exit (EXIT_SUCCESS);
/* The 'version' option is really used to test that:
1. The program loads correctly (no missing libraries)
2. we can correctly run our server shell process
3. that we can compile all the regular expressions.
*/
run_compiles ();
sprintf (file_name_buf, zFmt, program_id);
fputs (file_name_buf + 5, stdout);
exit (strcmp (run_shell (file_name_buf), program_id));
} }
freopen (argv[1], "r", stdin); freopen (argv[1], "r", stdin);
break;
default:
fputs ("fixincl ERROR: too many command line arguments\n", stderr);
exit (EXIT_FAILURE);
} }
{ {
static const char zVar[] = "TARGET_MACHINE"; static const char var[] = "TARGET_MACHINE";
pzMachine = getenv( zVar ); pz_machine = getenv (var);
if (pzMachine == (char *)NULL) if (pz_machine == (char *) NULL)
{ {
fprintf( stderr, zVarNotFound, zVar ); fprintf (stderr, var_not_found, var);
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
} }
} }
{ {
static const char zVar[] = "DESTDIR"; static const char var[] = "DESTDIR";
pzDestDir = getenv( zVar ); pz_dest_dir = getenv (var);
if (pzDestDir == (char *)NULL) if (pz_dest_dir == (char *) NULL)
{ {
fprintf( stderr, zVarNotFound, zVar ); fprintf (stderr, var_not_found, var);
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
} }
} }
{ {
static const char zVar[] = "SRCDIR"; static const char var[] = "SRCDIR";
pzSrcDir = getenv( zVar ); pz_src_dir = getenv (var);
if (pzSrcDir == (char *)NULL) if (pz_src_dir == (char *) NULL)
{ {
fprintf( stderr, zVarNotFound, zVar ); fprintf (stderr, var_not_found, var);
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
} }
} }
runCompiles (); /* Compile all the regular expressions now.
That way, it is done only once for the whole run.
*/
run_compiles ();
signal ( SIGQUIT, SIG_IGN ); signal (SIGQUIT, SIG_IGN);
signal ( SIGIOT, SIG_IGN ); signal (SIGIOT, SIG_IGN);
signal ( SIGPIPE, SIG_IGN ); signal (SIGPIPE, SIG_IGN);
signal ( SIGALRM, SIG_IGN ); signal (SIGALRM, SIG_IGN);
signal ( SIGTERM, SIG_IGN ); signal (SIGTERM, SIG_IGN);
signal ( SIGCHLD, SIG_IGN );
#ifndef NO_BOGOSITY_LIMITS #ifndef NO_BOGOSITY_LIMITS
/* Some systems only allow so many calls to fork(2).
This is inadequate for this program. Consequently,
we must let a grandfather process spawn children
that then spawn all the processes that do the real work.
*/
for (;;) for (;;)
{ {
char *pzBuf; char *pz_buf;
pid_t child; pid_t child;
/* /* Only the parent process can read from stdin without confusing
* Only the parent process can read from stdin without the world. (How does the child tell the parent to skip
* confusing the world. (How does the child tell the forward? Pipes and files behave differently.) */
* parent to skip forward? Pipes and files behave differently.) file_name_ct = 0;
*/ pz_buf = file_name_buf;
for (fileNameCt = 0, pzBuf = zFileNameBuf; while ( (file_name_ct < BOGUS_LIMIT)
(fileNameCt < BOGUS_LIMIT) && (pz_buf < (file_name_buf + NAME_TABLE_SIZE - MAXPATHLEN)))
&& (pzBuf
< (zFileNameBuf + sizeof (zFileNameBuf) - MAXPATHLEN));
)
{ {
if (fgets (pz_buf, MAXPATHLEN, stdin) == (char *) NULL)
if (fgets (pzBuf, MAXPATHLEN, stdin) == (char *) NULL)
break; break;
while (isspace (*pzBuf)) while (isspace (*pz_buf))
pzBuf++; pz_buf++;
apzNames[fileNameCt++] = pzBuf; if ((*pz_buf == '\0') || (*pz_buf == '#'))
pzBuf += strlen (pzBuf); continue;
while (isspace (pzBuf[-1])) apz_names[file_name_ct++] = pz_buf;
pzBuf--; pz_buf += strlen (pz_buf);
*pzBuf++ = '\0'; while (isspace (pz_buf[-1]))
pz_buf--;
*pz_buf++ = '\0';
} }
if (fileNameCt == 0) /* IF we did not get any files this time thru
THEN we must be done. */
if (file_name_ct == 0)
return EXIT_SUCCESS; return EXIT_SUCCESS;
child = fork (); child = fork ();
...@@ -226,37 +298,53 @@ main (argc, argv) ...@@ -226,37 +298,53 @@ main (argc, argv)
errno, strerror (errno)); errno, strerror (errno));
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
} }
#ifdef DEBUG
fprintf (stderr, "Waiting for %d to complete %d files\n",
child, file_name_ct);
#endif
{
int status;
pid_t dead_kid = wait (&status);
waitpid (child, (int *) NULL, 0); if (dead_kid != child)
fprintf (stderr, "fixincl woke up from a strange child %d (not %d)\n",
dead_kid, child);
#ifdef DEBUG
else
fprintf (stderr, "child finished %d files %s\n", file_name_ct,
status ? strerror (status & 0xFF) : "ok");
#endif
}
} }
#else #else
#error "NON-BOGUS LIMITS NOT SUPPORTED?!?!" #error "NON-BOGUS LIMITS NOT SUPPORTED?!?!"
#endif #endif
/* #ifdef DEBUG
* For every file specified in stdandard in fprintf (stderr, "Child start -- processing %d files\n",
* (except as throttled for bogus reasons)... file_name_ct);
*/ #endif
for (loopCt = 0; loopCt < fileNameCt; loopCt++)
/* For every file specified in stdandard in
(except as throttled for bogus reasons)...
*/
for (loop_ct = 0; loop_ct < file_name_ct; loop_ct++)
{ {
char *pzData; char *pz_data;
char *pzFile = apzNames[loopCt]; char *pz_file_name = apz_names[loop_ct];
if (access (pzFile, R_OK) != 0) if (access (pz_file_name, R_OK) != 0)
{ {
int erno = errno; int erno = errno;
fprintf (stderr, "Cannot access %s from %s\n\terror %d (%s)\n", fprintf (stderr, "Cannot access %s from %s\n\terror %d (%s)\n",
pzFile, getcwd ((char *) NULL, MAXPATHLEN), pz_file_name, getcwd ((char *) NULL, MAXPATHLEN),
erno, strerror (erno)); erno, strerror (erno));
} }
else if (pzData = loadFile (pzFile), else if (pz_data = load_file (pz_file_name), (pz_data != (char *) NULL))
(pzData != (char *) NULL))
{ {
if (strstr (pz_data, gnu_lib_mark) == (char *) NULL)
if (strstr (pzData, zGnuLib) == (char *) NULL) process (pz_data, pz_file_name);
process (pzData, pzDestDir, pzFile); free ((void *) pz_data);
free ((void *) pzData);
} }
} }
...@@ -264,50 +352,57 @@ main (argc, argv) ...@@ -264,50 +352,57 @@ main (argc, argv)
} }
/* * * * * * * * * * * * *
load_file loads all the contents of a file into malloc-ed memory.
Its argument is the name of the file to read in; the returned
result is the NUL terminated contents of the file. The file
is presumed to be an ASCII text file containing no NULs. */
char * char *
loadFile (pzFile) load_file (pz_file_name)
const char *pzFile; const char *pz_file_name;
{ {
char *pzDta; char *pz_data;
size_t fileSize; size_t file_size;
{ {
struct stat stbf; struct stat stbf;
if (stat (pzFile, &stbf) != 0)
if (stat (pz_file_name, &stbf) != 0)
{ {
fprintf (stderr, "error %d (%s) stat-ing %s\n", fprintf (stderr, "error %d (%s) stat-ing %s\n",
errno, strerror (errno), pzFile); errno, strerror (errno), pz_file_name);
return (char *) NULL; return (char *) NULL;
} }
fileSize = stbf.st_size; file_size = stbf.st_size;
} }
if (fileSize == 0) if (file_size == 0)
return (char *) NULL; return (char *) NULL;
pzDta = (char *) malloc ((fileSize + 16) & ~0x00F); pz_data = (char *) malloc ((file_size + 16) & ~0x00F);
if (pzDta == (char *) NULL) if (pz_data == (char *) NULL)
{ {
fprintf (stderr, "error: could not malloc %d bytes\n", fprintf (stderr, "error: could not malloc %d bytes\n",
fileSize); file_size);
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
} }
{ {
FILE *fp = fopen (pzFile, "r"); FILE *fp = fopen (pz_file_name, "r");
size_t sizeLeft = fileSize; size_t size_left = file_size;
char *readPtr = pzDta; char *read_ptr = pz_data;
if (fp == (FILE *) NULL) if (fp == (FILE *) NULL)
{ {
fprintf (stderr, "error %d (%s) opening %s\n", errno, fprintf (stderr, "error %d (%s) opening %s\n", errno,
strerror (errno), pzFile); strerror (errno), pz_file_name);
free ((void *) pzDta); free ((void *) pz_data);
return (char *) NULL; return (char *) NULL;
} }
do do
{ {
size_t sizeRead = fread ((void *) readPtr, 1, sizeLeft, fp); size_t sizeRead = fread ((void *) read_ptr, 1, size_left, fp);
if (sizeRead == 0) if (sizeRead == 0)
{ {
...@@ -317,164 +412,215 @@ loadFile (pzFile) ...@@ -317,164 +412,215 @@ loadFile (pzFile)
if (ferror (fp)) if (ferror (fp))
{ {
fprintf (stderr, "error %d (%s) reading %s\n", errno, fprintf (stderr, "error %d (%s) reading %s\n", errno,
strerror (errno), pzFile); strerror (errno), pz_file_name);
free ((void *) pzDta); free ((void *) pz_data);
fclose (fp); fclose (fp);
return (char *) NULL; return (char *) NULL;
} }
} }
readPtr += sizeRead; read_ptr += sizeRead;
sizeLeft -= sizeRead; size_left -= sizeRead;
} }
while (sizeLeft != 0); while (size_left != 0);
*readPtr = '\0'; *read_ptr = '\0';
fclose (fp); fclose (fp);
return pzDta;
} }
return pz_data;
} }
/* * * * * * * * * * * * *
run_compiles run all the regexp compiles for all the fixes once.
*/
void void
runCompiles () run_compiles ()
{ {
tSCC zBadComp[] = "fixincl ERROR: cannot compile %s regex for %s\n" tSCC z_bad_comp[] = "fixincl ERROR: cannot compile %s regex for %s\n"
"\texpr = `%s'\n" "\terror %s\n"; "\texpr = `%s'\n" "\terror %s\n";
tFixDesc *pFD = fixDescList; tFixDesc *p_fixd = fixDescList;
int fixCt = FIX_COUNT; int fix_ct = FIX_COUNT;
tTestDesc *pTD; tTestDesc *p_test;
int tstCt; int test_ct;
int reCt = REGEX_COUNT; int re_ct = REGEX_COUNT;
const char *pzErr; const char *pz_err;
regex_t *pRegex = (regex_t *) malloc (REGEX_COUNT * sizeof (regex_t)); regex_t *p_re = (regex_t *) malloc (REGEX_COUNT * sizeof (regex_t));
if (pRegex == (regex_t *) NULL) if (p_re == (regex_t *) NULL)
{ {
fprintf (stderr, "fixincl ERROR: cannot allocate %d bytes for regex\n", fprintf (stderr, "fixincl ERROR: cannot allocate %d bytes for regex\n",
REGEX_COUNT * sizeof (regex_t)); REGEX_COUNT * sizeof (regex_t));
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
} }
/* The patterns we search for are all egrep patterns.
In the shell version of this program, we invoke egrep
with the supplied pattern. Here, we will run
re_compile_pattern, but it must be using the same rules. */
re_set_syntax (RE_SYNTAX_EGREP); re_set_syntax (RE_SYNTAX_EGREP);
pzErr = re_compile_pattern (zInclQuote, strlen (zInclQuote), pz_err = re_compile_pattern (incl_quote_pat, sizeof (incl_quote_pat)-1,
&inclQuoteRegex); &incl_quote_re);
if (pzErr != (char *) NULL) if (pz_err != (char *) NULL)
{ {
fprintf (stderr, zBadComp, "quoted include", "runCompiles", fprintf (stderr, z_bad_comp, "quoted include", "run_compiles",
zInclQuote, pzErr); incl_quote_pat, pz_err);
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
} }
/* /* FOR every fixup, ... */
* FOR every fixup, ...
*/
do do
{ {
pTD = pFD->pTestDesc; p_test = p_fixd->p_test_desc;
tstCt = pFD->testCt; test_ct = p_fixd->test_ct;
if (pFD->papzMachs != (const char**)NULL) {
const char** papzMachs = pFD->papzMachs;
char* pz = zFileNameBuf;
char* pzSep = "";
tCC* pzIfTrue;
tCC* pzIfFalse;
tSCC zSkip[] = "skip";
tSCC zRun[] = "run";
sprintf( pz, "case %s in\n", pzMachine );
pz += strlen( pz );
if (pFD->fdFlags & FD_MACH_IFNOT) {
pzIfTrue = zSkip;
pzIfFalse = zRun;
} else {
pzIfTrue = zRun;
pzIfFalse = zSkip;
}
for (;;) { /* IF the machine type pointer is not NULL (we are not in test mode)
const char* pzMach = *(papzMachs++); AND this test is for or not done on particular machines
if (pzMach == (const char*)NULL) THEN ... */
break;
sprintf( pz, "%s %s", pzSep, pzMach ); if ( (pz_machine != NULL)
pz += strlen( pz ); && (p_fixd->papz_machs != (const char**) NULL) )
pzSep = " | \\\n"; {
} const char **papz_machs = p_fixd->papz_machs;
sprintf( pz, " )\n echo %s ;;\n * )\n echo %s ;;\nesac", char *pz = file_name_buf;
pzIfTrue, pzIfFalse ); char *pz_sep = "";
pz = runShell( zFileNameBuf ); tCC *pz_if_true;
if (*pz == 's') { tCC *pz_if_false;
pFD->fdFlags |= FD_SKIP_TEST; tSCC skip[] = "skip";
continue; tSCC run[] = "run";
/* Construct a shell script that looks like this:
case our-cpu-platform-os in
tests-cpu-platform-os-pattern )
echo run ;;
* )
echo skip ;;
esac
where 'run' and 'skip' may be reversed, depending on
the sense of the test. */
sprintf (pz, "case %s in\n", pz_machine);
pz += strlen (pz);
if (p_fixd->fd_flags & FD_MACH_IFNOT)
{
pz_if_true = skip;
pz_if_false = run;
}
else
{
pz_if_true = run;
pz_if_false = skip;
}
/* FOR any additional machine names to test for,
insert the " | \\\n" glue and the machine pattern. */
for (;;)
{
const char* pz_mach = *(papz_machs++);
if (pz_mach == (const char*) NULL)
break;
sprintf (pz, "%s %s", pz_sep, pz_mach);
pz += strlen (pz);
pz_sep = " | \\\n";
}
sprintf (pz, " )\n echo %s ;;\n * )\n echo %s ;;\nesac",
pz_if_true, pz_if_false);
/* Run the script.
The result will start either with 's' or 'r'. */
pz = run_shell (file_name_buf);
if (*pz == 's')
{
p_fixd->fd_flags |= FD_SKIP_TEST;
continue;
}
} }
}
/* /* FOR every test for the fixup, ... */
* FOR every test for the fixup, ...
*/ while (--test_ct >= 0)
while (--tstCt >= 0)
{ {
switch (pTD->type) switch (p_test->type)
{ {
case TT_EGREP: case TT_EGREP:
case TT_NEGREP: case TT_NEGREP:
if (--reCt < 0) /* You might consider putting the following under #ifdef.
The number of re's used is computed by autogen.
So, it is static and known at compile time. */
if (--re_ct < 0)
{ {
fputs ("out of RE's\n", stderr); fputs ("out of RE's\n", stderr);
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
} }
pTD->pTestRegex = pRegex++; p_test->p_test_regex = p_re++;
pzErr = re_compile_pattern (pTD->pzTest, pz_err = re_compile_pattern (p_test->pz_test_text,
strlen (pTD->pzTest), strlen (p_test->pz_test_text),
pTD->pTestRegex); p_test->p_test_regex);
if (pzErr != (char *) NULL) if (pz_err != (char *) NULL)
{ {
fprintf (stderr, zBadComp, "select test", pFD->pzFixName, fprintf (stderr, z_bad_comp, "select test", p_fixd->fix_name,
pTD->pzTest, pzErr); p_test->pz_test_text, pz_err);
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
} }
} }
pTD++; p_test++;
} }
} }
while (pFD++, --fixCt > 0); while (p_fixd++, --fix_ct > 0);
} }
/* * * * * * * * * * * * *
create_file Create the output modified file.
Input: the name of the file to create
Returns: a file pointer to the new, open file */
#define S_IRALL (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)
FILE * FILE *
createFile (pzFile) create_file (pz_file_name)
const char *pzFile; const char *pz_file_name;
{ {
int fd; int fd;
FILE *pf; FILE *pf;
char fname[MAXPATHLEN]; char fname[MAXPATHLEN];
sprintf (fname, "%s/%s", pzDestDir, pzFile); sprintf (fname, "%s/%s", pz_dest_dir, pz_file_name);
unlink (fname);
fd = open (fname, O_WRONLY | O_CREAT); fd = open (fname, O_WRONLY | O_CREAT | O_TRUNC, S_IRALL);
/* We may need to create the directories needed... */
if ((fd < 0) && (errno == ENOENT)) if ((fd < 0) && (errno == ENOENT))
{ {
char *pzDir = strchr (fname + 1, '/'); char *pz_dir = strchr (fname + 1, '/');
struct stat stbf; struct stat stbf;
while (pzDir != (char *) NULL) while (pz_dir != (char *) NULL)
{ {
*pzDir = NUL; *pz_dir = NUL;
if (stat (fname, &stbf) < 0) if (stat (fname, &stbf) < 0)
{ {
mkdir (fname, S_IFDIR | S_IRWXU | S_IRGRP | S_IXGRP mkdir (fname, S_IFDIR | S_IRWXU | S_IRGRP | S_IXGRP
| S_IROTH | S_IXOTH); | S_IROTH | S_IXOTH);
} }
*pzDir = '/'; *pz_dir = '/';
pzDir = strchr (pzDir + 1, '/'); pz_dir = strchr (pz_dir + 1, '/');
} }
fd = open (fname, O_WRONLY | O_CREAT);
/* Now, lets try the open again... */
fd = open (fname, O_WRONLY | O_CREAT | O_TRUNC, S_IRALL);
} }
if (fd < 0) if (fd < 0)
{ {
...@@ -482,353 +628,410 @@ createFile (pzFile) ...@@ -482,353 +628,410 @@ createFile (pzFile)
errno, strerror (errno), fname); errno, strerror (errno), fname);
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
} }
fprintf (stderr, "Fixed: %s\n", pzFile); fprintf (stderr, "Fixed: %s\n", pz_file_name);
pf = fdopen (fd, "w"); pf = fdopen (fd, "w");
#ifdef LATER #ifdef LATER
{ {
static const char zHdr[] = static const char hdr[] =
"/*\n" "/* DO NOT EDIT THIS FILE.\n\n"
" * DO NOT EDIT THIS FILE.\n" " It has been auto-edited by fixincludes from /usr/include/%s\n"
" *\n" " This had to be done to correct non-standard usages in the\n"
" * It has been auto-edited by fixincludes from /usr/include/%s\n" " original, manufacturer supplied header file. */\n\n";
" * This had to be done to correct non-standard usages in the\n"
" * original, manufacturer supplied header file.\n" fprintf (pf, hdr, pz_file_name);
" */\n\n";
fprintf (pf, zHdr, pzFile);
} }
#endif #endif
return pf; return pf;
} }
tSuccess
testTest (pTest, pzFile)
tTestDesc *pTest;
char* pzFile;
{
char *pzRes;
tSuccess res = FAILURE;
static char zCmdBuf[4096]; /* * * * * * * * * * * * *
tSCC zCmdFmt[] = "file=%s\nif ( test %s ) > /dev/null 2>&1\n"
"then echo TRUE\n" "else echo FALSE\n" "fi";
sprintf (zCmdBuf, zCmdFmt, pzFile, pTest->pzTest); test_test make sure a shell-style test expression passes.
pzRes = runShell (zCmdBuf); Input: a pointer to the descriptor of the test to run and
if (*pzRes == 'T') the name of the file that we might want to fix
Result: SUCCESS or FAILURE, depending on the result of the
shell script we run. */
t_success
test_test (p_test, pz_file_name)
tTestDesc *p_test;
char* pz_file_name;
{
char *pz_res;
t_success res = FAILURE;
static char cmd_buf[4096];
tSCC cmd_fmt[] =
"file=%s\n"
"if ( test %s ) > /dev/null 2>&1\n"
"then echo TRUE\n"
"else echo FALSE\n"
"fi";
sprintf (cmd_buf, cmd_fmt, pz_file_name, p_test->pz_test_text);
pz_res = run_shell (cmd_buf);
if (*pz_res == 'T')
res = SUCCESS; res = SUCCESS;
free ((void *) pzRes); free ((void *) pz_res);
return res; return res;
} }
tSuccess /* * * * * * * * * * * * *
egrepTest (pzDta, pTest)
char *pzDta; egrep_test make sure an egrep expression is found in the file text.
tTestDesc *pTest; Input: a pointer to the descriptor of the test to run and
the pointer to the contents of the file under suspicion
Result: SUCCESS if the pattern is found, FAILURE otherwise
The caller may choose 'FAILURE' as 'SUCCESS' if the sense of the test
is inverted. */
t_success
egrep_test (pz_data, p_test)
char *pz_data;
tTestDesc *p_test;
{ {
regmatch_t match; regmatch_t match;
#ifndef NO_BOGOSITY #ifndef NO_BOGOSITY
if (pTest->pTestRegex == 0) if (p_test->p_test_regex == 0)
fprintf (stderr, "fixincl ERROR RE not compiled: `%s'\n", pTest->pzTest); fprintf (stderr, "fixincl ERROR RE not compiled: `%s'\n",
p_test->pz_test_text);
#endif #endif
if (regexec (pTest->pTestRegex, pzDta, 1, &match, 0) == 0) if (regexec (p_test->p_test_regex, pz_data, 1, &match, 0) == 0)
return SUCCESS; return SUCCESS;
return FAILURE; return FAILURE;
} }
/* * * * * * * * * * * * *
*
extract_quoted_files
The syntax, `#include "file.h"' specifies that the compiler is to
search the local directory of the current file before the include
list. Consequently, if we have modified a header and stored it in
another directory, any files that are included by that modified
file in that fashion must also be copied into this new directory.
This routine finds those flavors of #include and for each one found
emits a triple of:
1. source directory of the original file
2. the relative path file name of the #includ-ed file
3. the full destination path for this file
Input: the text of the file, the file name and a pointer to the
match list where the match information was stored.
Result: internally nothing. The results are written to stdout
for interpretation by the invoking shell */
void void
extractQuotedFiles (pzDta, pzFile, pMatch) extract_quoted_files (pz_data, pz_file_name, p_re_match)
char *pzDta; char *pz_data;
const char *pzFile; const char *pz_file_name;
regmatch_t *pMatch; regmatch_t *p_re_match;
{ {
char *pzDirEnd = strrchr (pzFile, '/'); char *pz_dir_end = strrchr (pz_file_name, '/');
char *pzInclQuot = pzDta; char *pz_incl_quot = pz_data;
fprintf (stderr, "Quoted includes in %s\n", pzFile); fprintf (stderr, "Quoted includes in %s\n", pz_file_name);
/* /* Set "pz_file_name" to point to the containing subdirectory of the source
* Set "pzFile" to point to the containing subdirectory of the source If there is none, then it is in our current direcory, ".". */
* If there is none, then it is in our current direcory, ".".
*/ if (pz_dir_end == (char *) NULL)
if (pzDirEnd == (char *) NULL) pz_file_name = ".";
pzFile = ".";
else else
*pzDirEnd = '\0'; *pz_dir_end = '\0';
for (;;) for (;;)
{ {
pzInclQuot += pMatch->rm_so; pz_incl_quot += p_re_match->rm_so;
/* /* Skip forward to the included file name */
* Skip forward to the included file name while (isspace (*pz_incl_quot))
*/ pz_incl_quot++;
while (isspace (*pzInclQuot)) while (isspace (*++pz_incl_quot))
pzInclQuot++; ;
while (isspace (*++pzInclQuot)); pz_incl_quot += sizeof ("include") - 1;
pzInclQuot += sizeof ("include") - 1; while (*pz_incl_quot++ != '"')
while (*pzInclQuot++ != '"'); ;
/* /* Print the source directory and the subdirectory of the file
* Print the source directory and the subdirectory of the file in question. */
* in question. printf ("%s %s/", pz_src_dir, pz_file_name);
*/ pz_dir_end = pz_incl_quot;
printf ("%s %s/", pzSrcDir, pzFile);
pzDirEnd = pzInclQuot; /* Append to the directory the relative path of the desired file */
while (*pz_incl_quot != '"')
/* putc (*pz_incl_quot++, stdout);
* Append to the directory the relative path of the desired file
*/ /* Now print the destination directory appended with the
while (*pzInclQuot != '"') relative path of the desired file */
putc (*pzInclQuot++, stdout); printf (" %s/%s/", pz_dest_dir, pz_file_name);
while (*pz_dir_end != '"')
/* putc (*pz_dir_end++, stdout);
* Now print the destination directory appended with the relative
* path of the desired file /* End of entry */
*/
printf (" %s/%s/", pzDestDir, pzFile);
while (*pzDirEnd != '"')
putc (*pzDirEnd++, stdout);
/*
* End of entry
*/
putc ('\n', stdout); putc ('\n', stdout);
/* /* Find the next entry */
* Find the next entry if (regexec (&incl_quote_re, pz_incl_quot, 1, p_re_match, 0) != 0)
*/
if (regexec (&inclQuoteRegex, pzInclQuot, 1, pMatch, 0) != 0)
break; break;
} }
} }
/* /* * * * * * * * * * * * *
* Process the potential fixes for a particular include file
*/ Process the potential fixes for a particular include file.
Input: the original text of the file and the file's name
Result: none. A new file may or may not be created. */
void void
process (pzDta, pzDir, pzFile) process (pz_data, pz_file_name)
char *pzDta; char *pz_data;
const char *pzDir; const char *pz_file_name;
const char *pzFile;
{ {
static char zEnvFile[1024] = static char env_current_file[1024] = { "file=" };
{"file="}; tFixDesc *p_fixd = fixDescList;
tFixDesc *pFD = fixDescList; int todo_ct = FIX_COUNT;
int todoCt = FIX_COUNT; t_fd_pair fdp = { -1, -1 };
tFdPair fdp =
{-1, -1};
/* /* IF this is the first time through,
* IF this is the first time through, THEN put the 'file' environment variable into the environment.
* THEN put the 'file' environment variable into the environment. This is used by some of the subject shell scripts and tests. */
* This is used by some of the subject shell scripts and tests.
*/
if (zEnvFile[5] == NUL)
putenv (zEnvFile);
/* if (env_current_file[5] == NUL)
* Ghastly as it is, this actually updates the value of the variable: putenv (env_current_file);
*
* putenv(3C) C Library Functions putenv(3C)
*
* DESCRIPTION
* putenv() makes the value of the environment variable name
* equal to value by altering an existing variable or creating
* a new one. In either case, the string pointed to by string
* becomes part of the environment, so altering the string will
* change the environment. string points to a string of the
* form ``name=value.'' The space used by string is no longer
* used once a new string-defining name is passed to putenv().
*/
strcpy (zEnvFile + 5, pzFile);
chainHead = NOPROCESS;
/* /*
* For every fix in our fix list, ... Ghastly as it is, this actually updates the value of the variable:
putenv(3C) C Library Functions putenv(3C)
DESCRIPTION
putenv() makes the value of the environment variable name
equal to value by altering an existing variable or creating
a new one. In either case, the string pointed to by string
becomes part of the environment, so altering the string will
change the environment. string points to a string of the
form ``name=value.'' The space used by string is no longer
used once a new string-defining name is passed to putenv().
*/ */
for (; todoCt > 0; pFD++, todoCt--) strcpy (env_current_file + 5, pz_file_name);
process_chain_head = NOPROCESS;
/* For every fix in our fix list, ... */
for (; todo_ct > 0; p_fixd++, todo_ct--)
{ {
tTestDesc *pTD; tTestDesc *p_test;
int tstCt; int test_ct;
tSuccess egrepRes;
if (pFD->fdFlags & FD_SKIP_TEST) if (p_fixd->fd_flags & FD_SKIP_TEST)
continue; continue;
/* /* IF there is a file name restriction,
* IF there is a file name restriction, THEN ensure the current file name matches one in the pattern */
* THEN ensure the current file name matches one in the pattern
*/ if (p_fixd->file_list != (char *) NULL)
if (pFD->pzFileList != (char *) NULL)
{ {
const char *pzFil = pzFile; const char *pz_fname = pz_file_name;
const char *pzScn = pFD->pzFileList; const char *pz_scan = p_fixd->file_list;
size_t nmLen; size_t name_len;
while ((pzFil[0] == '.') && (pzFil[1] == '/')) while ((pz_fname[0] == '.') && (pz_fname[1] == '/'))
pzFil += 2; pz_fname += 2;
nmLen = strlen (pzFil); name_len = strlen (pz_fname);
for (;;) for (;;)
{ {
pzScn = strstr (pzScn + 1, pzFil); pz_scan = strstr (pz_scan + 1, pz_fname);
if (pzScn == (char *) NULL) /* IF we can't match the string at all,
goto nextFix; THEN bail */
if (pz_scan == (char *) NULL)
goto next_fix;
if ((pzScn[-1] == '|') && (pzScn[nmLen] == '|')) /* IF the match is surrounded by the '|' markers,
THEN we found a full match -- time to run the tests */
if ((pz_scan[-1] == '|') && (pz_scan[name_len] == '|'))
break; break;
} }
} }
egrepRes = PROBLEM; /* FOR each test, see if it fails.
IF it does fail, then we go on to the next test */
/* for (p_test = p_fixd->p_test_desc, test_ct = p_fixd->test_ct;
* IF there are no tests test_ct-- > 0;
* THEN we always run the fixup p_test++)
*/
for (pTD = pFD->pTestDesc, tstCt = pFD->testCt;
tstCt-- > 0;
pTD++)
{ {
switch (pTD->type) #ifdef DEBUG
static const char z_test_fail[] =
"%16s test %2d failed for %s\n";
#endif
switch (p_test->type)
{ {
case TT_TEST: case TT_TEST:
/* if (!SUCCESSFUL (test_test (p_test, pz_file_name)))
* IF *any* of the shell tests fail, {
* THEN do not process the fix. #ifdef DEBUG
*/ fprintf (stderr, z_test_fail, p_fixd->fix_name,
if (!SUCCESSFUL (testTest (pTD, pzFile))) p_fixd->test_ct - test_ct, pz_file_name);
goto nextFix; #endif
goto next_fix;
}
break; break;
case TT_EGREP: case TT_EGREP:
/* if (!SUCCESSFUL (egrep_test (pz_data, p_test)))
* IF we have not had a successful egrep test {
* *AND* this test does not pass, #ifdef DEBUG
* THEN mark the egrep test as failing. It starts fprintf (stderr, z_test_fail, p_fixd->fix_name,
* out as a "PROBLEM", meaning that if we do not p_fixd->test_ct - test_ct, pz_file_name);
* encounter any egrep tests, then we will let it pass. #endif
*/ goto next_fix;
if ((!SUCCESSFUL (egrepRes)) }
&& (!SUCCESSFUL (egrepTest (pzDta, pTD))))
egrepRes = FAILURE;
break; break;
case TT_NEGREP: case TT_NEGREP:
/* if (SUCCESSFUL (egrep_test (pz_data, p_test)))
* IF *any* of the negative egrep tests fail, {
* THEN do not process the fix. #ifdef DEBUG
*/ fprintf (stderr, z_test_fail, p_fixd->fix_name,
if (SUCCESSFUL (egrepTest (pzDta, pTD))) p_fixd->test_ct - test_ct, pz_file_name);
goto nextFix; #endif
goto next_fix;
}
break; break;
} }
} }
/* fprintf (stderr, "Applying %-32s to %s\n",
* IF there were no egrep tests *OR* at least one passed, ... p_fixd->fix_name, pz_file_name);
*/
if (!FAILED (egrepRes)) /* IF we do not have a read pointer,
{ THEN this is the first fix for the current file.
fprintf (stderr, "Applying %-32s to %s\n", Open the source file. That will be used as stdin for
pFD->pzFixName, pzFile); the first fix. Any subsequent fixes will use the
stdout descriptor of the previous fix as its stdin. */
if (fdp.readFd == -1) if (fdp.read_fd == -1)
{
fdp.read_fd = open (pz_file_name, O_RDONLY);
if (fdp.read_fd < 0)
{ {
fdp.readFd = open (pzFile, O_RDONLY); fprintf (stderr, "Error %d (%s) opening %s\n", errno,
if (fdp.readFd < 0) strerror (errno), pz_file_name);
{ exit (EXIT_FAILURE);
fprintf (stderr, "Error %d (%s) opening %s\n", errno,
strerror (errno), pzFile);
exit (EXIT_FAILURE);
}
} }
}
for (;;) /* This loop should only cycle for 1/2 of one loop.
{ "chain_open" starts a process that uses "fdp.read_fd" as
int newFd = chainOpen (fdp.readFd, its stdin and returns the new fd this process will use
(tpChar *) pFD->papzPatchArgs, for stdout. */
(chainHead == -1)
? &chainHead : (pid_t *) NULL);
if (newFd != -1)
{
fdp.readFd = newFd;
break;
}
fprintf (stderr, "Error %d (%s) starting filter process " for (;;)
"for %s\n", errno, strerror (errno), {
pFD->pzFixName); static int failCt = 0;
int fd = chain_open (fdp.read_fd,
(t_pchar *) p_fixd->patch_args,
(process_chain_head == -1)
? &process_chain_head : (pid_t *) NULL);
if (errno != EAGAIN) if (fd != -1)
exit (EXIT_FAILURE); {
sleep (1); fdp.read_fd = fd;
break;
} }
fprintf (stderr, "Error %d (%s) starting filter process "
"for %s\n", errno, strerror (errno),
p_fixd->fix_name);
if ((errno != EAGAIN) || (++failCt > 10))
exit (EXIT_FAILURE);
sleep (1);
} }
nextFix:; next_fix:
;
} }
/* /* IF after all the tests we did not start any patch programs,
* IF after all the tests we did not start any patch programs, THEN quit now. */
* THEN quit now.
*/ if (fdp.read_fd < 0)
if (fdp.readFd < 0)
return; return;
/* OK. We have work to do. Read back in the output
of the filtering chain. Compare each byte as we read it with
the contents of the original file. As soon as we find any
difference, we will create the output file, write out all
the matched text and then copy any remaining data from the
output of the filter chain.
*/
{ {
FILE *inFp = fdopen (fdp.readFd, "r"); FILE *in_fp = fdopen (fdp.read_fd, "r");
FILE *oFp = (FILE *) NULL; FILE *out_fp = (FILE *) NULL;
char *pzCmp = pzDta; char *pz_cmp = pz_data;
for (;;) for (;;)
{ {
int ch; int ch;
ch = getc (inFp); ch = getc (in_fp);
if (ch == EOF) if (ch == EOF)
break; break;
if (oFp != (FILE *) NULL) /* IF we are emitting the output
putc (ch, oFp); THEN emit this character, too.
*/
if (out_fp != (FILE *) NULL)
putc (ch, out_fp);
else if (ch != *pzCmp) /* ELSE if this character does not match the original,
THEN now is the time to start the output.
*/
else if (ch != *pz_cmp)
{ {
oFp = createFile (pzFile); out_fp = create_file (pz_file_name);
if (pzCmp != pzDta)
/* IF there are matched data, write it all now. */
if (pz_cmp != pz_data)
{ {
char c = *pzCmp; char c = *pz_cmp;
*pzCmp = NUL;
fputs (pzDta, oFp); *pz_cmp = NUL;
*pzCmp = c; fputs (pz_data, out_fp);
*pz_cmp = c;
} }
putc (ch, oFp);
/* Emit the current unmatching character */
putc (ch, out_fp);
} }
else else
pzCmp++; /* ELSE the character matches. Advance the compare ptr */
pz_cmp++;
} }
if (oFp != (FILE *) NULL) /* IF we created the output file, ... */
if (out_fp != (FILE *) NULL)
{ {
regmatch_t match; regmatch_t match;
fchmod (fileno (oFp), S_IRUSR | S_IRGRP | S_IROTH); /* Close the file and see if we have to worry about
fclose (oFp); `#include "file.h"' constructs. */
if (regexec (&inclQuoteRegex, pzDta, 1, &match, 0) == 0) fclose (out_fp);
extractQuotedFiles (pzDta, pzFile, &match); if (regexec (&incl_quote_re, pz_data, 1, &match, 0) == 0)
extract_quoted_files (pz_data, pz_file_name, &match);
} }
fclose (in_fp);
fclose (inFp);
} }
close (fdp.read_fd); /* probably redundant, but I'm paranoid */
close (fdp.readFd);
} }
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
# #
# DO NOT EDIT THIS FILE (fixincl.sh) # DO NOT EDIT THIS FILE (fixincl.sh)
# #
# It has been autogen-ed Friday October 16, 1998 at 07:29:49 AM PDT # It has been autogen-ed Wednesday January 27, 1999 at 09:03:56 AM PST
# From the definitions inclhack.def # From the definitions inclhack.def
# and the template file inclhack.tpl # and the template file inclhack.tpl
# #
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
# files which are fixed to work correctly with ANSI C and placed in a # files which are fixed to work correctly with ANSI C and placed in a
# directory that GNU C will search. # directory that GNU C will search.
# #
# This script contains 104 fixup scripts. # This script contains 105 fixup scripts.
# #
# See README-fixinc for more information. # See README-fixinc for more information.
# #
...@@ -127,10 +127,7 @@ for INPUT in ${INPUTLIST} ; do ...@@ -127,10 +127,7 @@ for INPUT in ${INPUTLIST} ; do
cd ${ORIGDIR} cd ${ORIGDIR}
cd ${INPUT} || { cd ${INPUT} || continue
echo 'fixincludes: input dir `'$INPUT"' is an invalid directory"
exit 1
}
# #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
...@@ -344,18 +341,20 @@ while [ $# != 0 ]; do ...@@ -344,18 +341,20 @@ while [ $# != 0 ]; do
# #
cd ${INPUT} cd ${INPUT}
cd $1 cd $1
if [ -r $2 ] && [ ! -r $3 ]; then if [ -f $2 ] ; then
cp $2 $3 >/dev/null 2>&1 || echo "Can't copy $2" >&2 if [ -r $2 ] && [ ! -r $3 ]; then
chmod +w $3 2>/dev/null cp $2 $3 >/dev/null 2>&1 || echo "Can't copy $2" >&2
chmod a+r $3 2>/dev/null chmod +w $3 2>/dev/null
echo Copied $2 chmod a+r $3 2>/dev/null
for include in `egrep '^[ ]*#[ ]*include[ ]*"[^/]' $3 | echo Copied $2
for include in `egrep '^[ ]*#[ ]*include[ ]*"[^/]' $3 |
sed -e 's/^[ ]*#[ ]*include[ ]*"\([^"]*\)".*$/\1/'` sed -e 's/^[ ]*#[ ]*include[ ]*"\([^"]*\)".*$/\1/'`
do do
dir=`echo $2 | sed -e s'|/[^/]*$||'` dir=`echo $2 | sed -e s'|/[^/]*$||'`
dir2=`echo $3 | sed -e s'|/[^/]*$||'` dir2=`echo $3 | sed -e s'|/[^/]*$||'`
newreq="$newreq $1 $dir/$include $dir2/$include" newreq="$newreq $1 $dir/$include $dir2/$include"
done done
fi
fi fi
shift; shift; shift shift; shift; shift
done done
...@@ -384,6 +383,6 @@ done ...@@ -384,6 +383,6 @@ done
cd $ORIGDIR cd $ORIGDIR
rm -f include/assert.h rm -f include/assert.h
cp ${EGCS_SRCDIR}/assert.h include/assert.h cp ${srcdir}/assert.h include/assert.h || exit 1
chmod a+r include/assert.h chmod a+r include/assert.h
/* /*
* DO NOT EDIT THIS FILE (fixincl.x) * DO NOT EDIT THIS FILE (fixincl.x)
* *
* It has been autogen-ed Friday October 16, 1998 at 07:29:50 AM PDT * It has been autogen-ed Tuesday January 5, 1999 at 09:20:37 AM PST
* From the definitions inclhack.def * From the definitions inclhack.def
* and the template file fixincl.tpl * and the template file fixincl.tpl
* *
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* files which are fixed to work correctly with ANSI C and placed in a * files which are fixed to work correctly with ANSI C and placed in a
* directory that GNU C will search. * directory that GNU C will search.
* *
* This script contains 104 fixup scripts. * This script contains 105 fixup scripts.
* *
* See README-fixinc for more information. * See README-fixinc for more information.
* *
...@@ -3005,7 +3005,41 @@ const char* apzUltrix_Ansi_CompatPatch[] = { "sed", ...@@ -3005,7 +3005,41 @@ const char* apzUltrix_Ansi_CompatPatch[] = { "sed",
/* * * * * * * * * * * * * * * * * * * * * * * * * * /* * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Description 84 - Ultrix_Atof_Param fix * Description 84 - Ultrix_Fix_Fixproto fix
*/
tSCC zUltrix_Fix_FixprotoName[] =
"Ultrix_Fix_Fixproto";
/*
* File name selection pattern
*/
tSCC zUltrix_Fix_FixprotoList[] =
"|" "sys/utsname.h" "|";
/*
* Machine/OS name selection pattern
*/
#define apzUltrix_Fix_FixprotoMachs (const char**)NULL
/*
* content selection pattern
*/
tSCC zUltrix_Fix_FixprotoSelect0[] =
"ULTRIX";
#define ULTRIX_FIX_FIXPROTO_TEST_CT 1
tTestDesc aUltrix_Fix_FixprotoTests[] = {
{ TT_EGREP, zUltrix_Fix_FixprotoSelect0, (regex_t*)NULL } };
/*
* Fix Command Arguments for Ultrix_Fix_Fixproto
*/
const char* apzUltrix_Fix_FixprotoPatch[] = { "sed",
"-e" "/^[ \t]*extern[ \t]*int[ \t]*uname();$/i\\\n"
"struct utsname;\n",
(char*)NULL };
/* * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Description 85 - Ultrix_Atof_Param fix
*/ */
tSCC zUltrix_Atof_ParamName[] = tSCC zUltrix_Atof_ParamName[] =
"Ultrix_Atof_Param"; "Ultrix_Atof_Param";
...@@ -3034,7 +3068,7 @@ const char* apzUltrix_Atof_ParamPatch[] = { "sed", ...@@ -3034,7 +3068,7 @@ const char* apzUltrix_Atof_ParamPatch[] = { "sed",
/* * * * * * * * * * * * * * * * * * * * * * * * * * /* * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Description 85 - Ultrix_Const fix * Description 86 - Ultrix_Const fix
*/ */
tSCC zUltrix_ConstName[] = tSCC zUltrix_ConstName[] =
"Ultrix_Const"; "Ultrix_Const";
...@@ -3067,7 +3101,7 @@ const char* apzUltrix_ConstPatch[] = { "sed", ...@@ -3067,7 +3101,7 @@ const char* apzUltrix_ConstPatch[] = { "sed",
/* * * * * * * * * * * * * * * * * * * * * * * * * * /* * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Description 86 - Ultrix_Ifdef fix * Description 87 - Ultrix_Ifdef fix
*/ */
tSCC zUltrix_IfdefName[] = tSCC zUltrix_IfdefName[] =
"Ultrix_Ifdef"; "Ultrix_Ifdef";
...@@ -3100,7 +3134,7 @@ const char* apzUltrix_IfdefPatch[] = { "sed", ...@@ -3100,7 +3134,7 @@ const char* apzUltrix_IfdefPatch[] = { "sed",
/* * * * * * * * * * * * * * * * * * * * * * * * * * /* * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Description 87 - Ultrix_Nested_Cmnt fix * Description 88 - Ultrix_Nested_Cmnt fix
*/ */
tSCC zUltrix_Nested_CmntName[] = tSCC zUltrix_Nested_CmntName[] =
"Ultrix_Nested_Cmnt"; "Ultrix_Nested_Cmnt";
...@@ -3125,7 +3159,7 @@ const char* apzUltrix_Nested_CmntPatch[] = { "sed", ...@@ -3125,7 +3159,7 @@ const char* apzUltrix_Nested_CmntPatch[] = { "sed",
/* * * * * * * * * * * * * * * * * * * * * * * * * * /* * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Description 88 - Ultrix_Static fix * Description 89 - Ultrix_Static fix
*/ */
tSCC zUltrix_StaticName[] = tSCC zUltrix_StaticName[] =
"Ultrix_Static"; "Ultrix_Static";
...@@ -3160,7 +3194,7 @@ const char* apzUltrix_StaticPatch[] = { "sed", ...@@ -3160,7 +3194,7 @@ const char* apzUltrix_StaticPatch[] = { "sed",
/* * * * * * * * * * * * * * * * * * * * * * * * * * /* * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Description 89 - Undefine_Null fix * Description 90 - Undefine_Null fix
*/ */
tSCC zUndefine_NullName[] = tSCC zUndefine_NullName[] =
"Undefine_Null"; "Undefine_Null";
...@@ -3200,7 +3234,7 @@ const char* apzUndefine_NullPatch[] = { "sed", ...@@ -3200,7 +3234,7 @@ const char* apzUndefine_NullPatch[] = { "sed",
/* * * * * * * * * * * * * * * * * * * * * * * * * * /* * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Description 90 - Va_I960_Macro fix * Description 91 - Va_I960_Macro fix
*/ */
tSCC zVa_I960_MacroName[] = tSCC zVa_I960_MacroName[] =
"Va_I960_Macro"; "Va_I960_Macro";
...@@ -3236,7 +3270,7 @@ const char* apzVa_I960_MacroPatch[] = { "sed", ...@@ -3236,7 +3270,7 @@ const char* apzVa_I960_MacroPatch[] = { "sed",
/* * * * * * * * * * * * * * * * * * * * * * * * * * /* * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Description 91 - Void_Null fix * Description 92 - Void_Null fix
*/ */
tSCC zVoid_NullName[] = tSCC zVoid_NullName[] =
"Void_Null"; "Void_Null";
...@@ -3279,7 +3313,7 @@ const char* apzVoid_NullPatch[] = { "sed", ...@@ -3279,7 +3313,7 @@ const char* apzVoid_NullPatch[] = { "sed",
/* * * * * * * * * * * * * * * * * * * * * * * * * * /* * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Description 92 - Vxworks_Gcc_Problem fix * Description 93 - Vxworks_Gcc_Problem fix
*/ */
tSCC zVxworks_Gcc_ProblemName[] = tSCC zVxworks_Gcc_ProblemName[] =
"Vxworks_Gcc_Problem"; "Vxworks_Gcc_Problem";
...@@ -3327,7 +3361,7 @@ const char* apzVxworks_Gcc_ProblemPatch[] = { "sed", ...@@ -3327,7 +3361,7 @@ const char* apzVxworks_Gcc_ProblemPatch[] = { "sed",
/* * * * * * * * * * * * * * * * * * * * * * * * * * /* * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Description 93 - Vxworks_Needs_Vxtypes fix * Description 94 - Vxworks_Needs_Vxtypes fix
*/ */
tSCC zVxworks_Needs_VxtypesName[] = tSCC zVxworks_Needs_VxtypesName[] =
"Vxworks_Needs_Vxtypes"; "Vxworks_Needs_Vxtypes";
...@@ -3360,7 +3394,7 @@ const char* apzVxworks_Needs_VxtypesPatch[] = { "sed", ...@@ -3360,7 +3394,7 @@ const char* apzVxworks_Needs_VxtypesPatch[] = { "sed",
/* * * * * * * * * * * * * * * * * * * * * * * * * * /* * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Description 94 - Vxworks_Needs_Vxworks fix * Description 95 - Vxworks_Needs_Vxworks fix
*/ */
tSCC zVxworks_Needs_VxworksName[] = tSCC zVxworks_Needs_VxworksName[] =
"Vxworks_Needs_Vxworks"; "Vxworks_Needs_Vxworks";
...@@ -3407,7 +3441,7 @@ const char* apzVxworks_Needs_VxworksPatch[] = { "sed", ...@@ -3407,7 +3441,7 @@ const char* apzVxworks_Needs_VxworksPatch[] = { "sed",
/* * * * * * * * * * * * * * * * * * * * * * * * * * /* * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Description 95 - Vxworks_Time fix * Description 96 - Vxworks_Time fix
*/ */
tSCC zVxworks_TimeName[] = tSCC zVxworks_TimeName[] =
"Vxworks_Time"; "Vxworks_Time";
...@@ -3456,7 +3490,7 @@ const char* apzVxworks_TimePatch[] = { "sed", ...@@ -3456,7 +3490,7 @@ const char* apzVxworks_TimePatch[] = { "sed",
/* * * * * * * * * * * * * * * * * * * * * * * * * * /* * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Description 96 - X11_Class fix * Description 97 - X11_Class fix
*/ */
tSCC zX11_ClassName[] = tSCC zX11_ClassName[] =
"X11_Class"; "X11_Class";
...@@ -3494,7 +3528,7 @@ const char* apzX11_ClassPatch[] = { "sed", ...@@ -3494,7 +3528,7 @@ const char* apzX11_ClassPatch[] = { "sed",
/* * * * * * * * * * * * * * * * * * * * * * * * * * /* * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Description 97 - X11_Class_Usage fix * Description 98 - X11_Class_Usage fix
*/ */
tSCC zX11_Class_UsageName[] = tSCC zX11_Class_UsageName[] =
"X11_Class_Usage"; "X11_Class_Usage";
...@@ -3527,7 +3561,7 @@ const char* apzX11_Class_UsagePatch[] = { "sed", ...@@ -3527,7 +3561,7 @@ const char* apzX11_Class_UsagePatch[] = { "sed",
/* * * * * * * * * * * * * * * * * * * * * * * * * * /* * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Description 98 - X11_New fix * Description 99 - X11_New fix
*/ */
tSCC zX11_NewName[] = tSCC zX11_NewName[] =
"X11_New"; "X11_New";
...@@ -3566,7 +3600,7 @@ const char* apzX11_NewPatch[] = { "sed", ...@@ -3566,7 +3600,7 @@ const char* apzX11_NewPatch[] = { "sed",
/* * * * * * * * * * * * * * * * * * * * * * * * * * /* * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Description 99 - X11_Sprintf fix * Description 100 - X11_Sprintf fix
*/ */
tSCC zX11_SprintfName[] = tSCC zX11_SprintfName[] =
"X11_Sprintf"; "X11_Sprintf";
...@@ -3593,7 +3627,7 @@ const char* apzX11_SprintfPatch[] = { "sed", ...@@ -3593,7 +3627,7 @@ const char* apzX11_SprintfPatch[] = { "sed",
/* * * * * * * * * * * * * * * * * * * * * * * * * * /* * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Description 100 - Zzz_Ki_Iface fix * Description 101 - Zzz_Ki_Iface fix
*/ */
tSCC zZzz_Ki_IfaceName[] = tSCC zZzz_Ki_IfaceName[] =
"Zzz_Ki_Iface"; "Zzz_Ki_Iface";
...@@ -3628,7 +3662,7 @@ const char* apzZzz_Ki_IfacePatch[] = { "sh", "-c", ...@@ -3628,7 +3662,7 @@ const char* apzZzz_Ki_IfacePatch[] = { "sh", "-c",
/* * * * * * * * * * * * * * * * * * * * * * * * * * /* * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Description 101 - Zzz_Ki fix * Description 102 - Zzz_Ki fix
*/ */
tSCC zZzz_KiName[] = tSCC zZzz_KiName[] =
"Zzz_Ki"; "Zzz_Ki";
...@@ -3663,7 +3697,7 @@ const char* apzZzz_KiPatch[] = { "sh", "-c", ...@@ -3663,7 +3697,7 @@ const char* apzZzz_KiPatch[] = { "sh", "-c",
/* * * * * * * * * * * * * * * * * * * * * * * * * * /* * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Description 102 - Zzz_Ki_Calls fix * Description 103 - Zzz_Ki_Calls fix
*/ */
tSCC zZzz_Ki_CallsName[] = tSCC zZzz_Ki_CallsName[] =
"Zzz_Ki_Calls"; "Zzz_Ki_Calls";
...@@ -3698,7 +3732,7 @@ const char* apzZzz_Ki_CallsPatch[] = { "sh", "-c", ...@@ -3698,7 +3732,7 @@ const char* apzZzz_Ki_CallsPatch[] = { "sh", "-c",
/* * * * * * * * * * * * * * * * * * * * * * * * * * /* * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Description 103 - Zzz_Ki_Defs fix * Description 104 - Zzz_Ki_Defs fix
*/ */
tSCC zZzz_Ki_DefsName[] = tSCC zZzz_Ki_DefsName[] =
"Zzz_Ki_Defs"; "Zzz_Ki_Defs";
...@@ -3733,7 +3767,7 @@ const char* apzZzz_Ki_DefsPatch[] = { "sh", "-c", ...@@ -3733,7 +3767,7 @@ const char* apzZzz_Ki_DefsPatch[] = { "sh", "-c",
/* * * * * * * * * * * * * * * * * * * * * * * * * * /* * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Description 104 - Zzz_Time fix * Description 105 - Zzz_Time fix
*/ */
tSCC zZzz_TimeName[] = tSCC zZzz_TimeName[] =
"Zzz_Time"; "Zzz_Time";
...@@ -3770,9 +3804,9 @@ const char* apzZzz_TimePatch[] = { "sh", "-c", ...@@ -3770,9 +3804,9 @@ const char* apzZzz_TimePatch[] = { "sh", "-c",
* *
* List of all fixes * List of all fixes
*/ */
#define REGEX_COUNT 75 #define REGEX_COUNT 76
#define FIX_COUNT 104 #define FIX_COUNT 105
tFixDesc fixDescList[ 104 ] = { tFixDesc fixDescList[ 105 ] = {
{ zAix_SyswaitName, zAix_SyswaitList, { zAix_SyswaitName, zAix_SyswaitList,
apzAix_SyswaitMachs, (regex_t*)NULL, apzAix_SyswaitMachs, (regex_t*)NULL,
AIX_SYSWAIT_TEST_CT, FD_MACH_ONLY, AIX_SYSWAIT_TEST_CT, FD_MACH_ONLY,
...@@ -4188,6 +4222,11 @@ tFixDesc fixDescList[ 104 ] = { ...@@ -4188,6 +4222,11 @@ tFixDesc fixDescList[ 104 ] = {
ULTRIX_ANSI_COMPAT_TEST_CT, FD_MACH_ONLY, ULTRIX_ANSI_COMPAT_TEST_CT, FD_MACH_ONLY,
aUltrix_Ansi_CompatTests, apzUltrix_Ansi_CompatPatch }, aUltrix_Ansi_CompatTests, apzUltrix_Ansi_CompatPatch },
{ zUltrix_Fix_FixprotoName, zUltrix_Fix_FixprotoList,
apzUltrix_Fix_FixprotoMachs, (regex_t*)NULL,
ULTRIX_FIX_FIXPROTO_TEST_CT, FD_MACH_ONLY,
aUltrix_Fix_FixprotoTests, apzUltrix_Fix_FixprotoPatch },
{ zUltrix_Atof_ParamName, zUltrix_Atof_ParamList, { zUltrix_Atof_ParamName, zUltrix_Atof_ParamList,
apzUltrix_Atof_ParamMachs, (regex_t*)NULL, apzUltrix_Atof_ParamMachs, (regex_t*)NULL,
ULTRIX_ATOF_PARAM_TEST_CT, FD_MACH_ONLY, ULTRIX_ATOF_PARAM_TEST_CT, FD_MACH_ONLY,
......
[= autogen template include =] [= autogen template include =]
[= [=
# $Id: hackshell.tpl,v 1.2 1998/12/16 21:19:08 law Exp $
# #
# This file contanes the shell template replacement for the # This file contanes the shell template replacement for the
# fixincl program. It is the repetitive guts of the fixincludes logic. # fixincl program. It is the repetitive guts of the fixincludes logic.
......
/* -*- Mode: C -*- $Id: inclhack.def,v 1.2 1998/12/16 21:19:09 law Exp $ */ /* -*- Mode: C -*- */
autogen definitions inclhack; autogen definitions inclhack;
...@@ -2007,6 +2007,19 @@ fix = { ...@@ -2007,6 +2007,19 @@ fix = {
/* /*
* Ultrix V4.[35] puts the declaration of uname before the definition
* of struct utsname, so the prototype (added by fixproto) causes havoc.
*/
fix = {
hackname = ultrix_fix_fixproto;
files = sys/utsname.h;
select = ULTRIX;
sed = "/^[ \t]*extern[ \t]*int[ \t]*uname();$/i\\\n"
"struct utsname;\n";
};
/*
* parameter to atof not const on DECstation Ultrix V4.0 and NEWS-OS 4.2R. * parameter to atof not const on DECstation Ultrix V4.0 and NEWS-OS 4.2R.
* also get rid of bogus inline definitions in HP-UX 8.0 * also get rid of bogus inline definitions in HP-UX 8.0
*/ */
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
# #
# DO NOT EDIT THIS FILE (inclhack.sh) # DO NOT EDIT THIS FILE (inclhack.sh)
# #
# It has been autogen-ed Friday October 16, 1998 at 07:29:49 AM PDT # It has been autogen-ed Wednesday January 27, 1999 at 09:03:36 AM PST
# From the definitions inclhack.def # From the definitions inclhack.def
# and the template file inclhack.tpl # and the template file inclhack.tpl
# #
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
# files which are fixed to work correctly with ANSI C and placed in a # files which are fixed to work correctly with ANSI C and placed in a
# directory that GNU C will search. # directory that GNU C will search.
# #
# This script contains 104 fixup scripts. # This script contains 105 fixup scripts.
# #
# See README-fixinc for more information. # See README-fixinc for more information.
# #
...@@ -125,10 +125,7 @@ for INPUT in ${INPUTLIST} ; do ...@@ -125,10 +125,7 @@ for INPUT in ${INPUTLIST} ; do
cd ${ORIGDIR} cd ${ORIGDIR}
cd ${INPUT} || { cd ${INPUT} || continue
echo 'fixincludes: input dir `'$INPUT"' is an invalid directory"
exit 1
}
# #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
...@@ -2464,7 +2461,30 @@ extern unsigned int\ ...@@ -2464,7 +2461,30 @@ extern unsigned int\
# #
# Fix 84: Ultrix_Atof_Param # Fix 84: Ultrix_Fix_Fixproto
#
case "$file" in ./sys/utsname.h )
if ( test -n "`egrep 'ULTRIX' $file`"
) > /dev/null 2>&1 ; then
fixlist="${fixlist}
ultrix_fix_fixproto"
if [ ! -r ${DESTDIR}/$file ]
then infile=$file
else infile=${DESTDIR}/$file ; fi
sed -e '/^[ ]*extern[ ]*int[ ]*uname();$/i\
struct utsname;
' \
< $infile > ${DESTDIR}/$file.
mv -f ${DESTDIR}/$file. ${DESTDIR}/$file
fi # end of selection 'if'
;; # case end for file name test
esac
#
# Fix 85: Ultrix_Atof_Param
# #
case "$file" in ./math.h ) case "$file" in ./math.h )
fixlist="${fixlist} fixlist="${fixlist}
...@@ -2486,7 +2506,7 @@ extern unsigned int\ ...@@ -2486,7 +2506,7 @@ extern unsigned int\
# #
# Fix 85: Ultrix_Const # Fix 86: Ultrix_Const
# #
case "$file" in ./stdio.h ) case "$file" in ./stdio.h )
fixlist="${fixlist} fixlist="${fixlist}
...@@ -2512,7 +2532,7 @@ extern unsigned int\ ...@@ -2512,7 +2532,7 @@ extern unsigned int\
# #
# Fix 86: Ultrix_Ifdef # Fix 87: Ultrix_Ifdef
# #
case "$file" in ./sys/file.h ) case "$file" in ./sys/file.h )
if ( test -n "`egrep '#ifdef KERNEL' $file`" if ( test -n "`egrep '#ifdef KERNEL' $file`"
...@@ -2533,7 +2553,7 @@ extern unsigned int\ ...@@ -2533,7 +2553,7 @@ extern unsigned int\
# #
# Fix 87: Ultrix_Nested_Cmnt # Fix 88: Ultrix_Nested_Cmnt
# #
case "$file" in ./rpc/svc.h ) case "$file" in ./rpc/svc.h )
fixlist="${fixlist} fixlist="${fixlist}
...@@ -2551,7 +2571,7 @@ extern unsigned int\ ...@@ -2551,7 +2571,7 @@ extern unsigned int\
# #
# Fix 88: Ultrix_Static # Fix 89: Ultrix_Static
# #
case "$file" in ./machine/cpu.h ) case "$file" in ./machine/cpu.h )
if ( test -n "`egrep '#include \"r[34]_cpu' $file`" if ( test -n "`egrep '#include \"r[34]_cpu' $file`"
...@@ -2574,7 +2594,7 @@ extern unsigned int\ ...@@ -2574,7 +2594,7 @@ extern unsigned int\
# #
# Fix 89: Undefine_Null # Fix 90: Undefine_Null
# #
if ( test -n "`egrep '^#[ ]*define[ ]*[ ]NULL[ ]' $file`" -a \ if ( test -n "`egrep '^#[ ]*define[ ]*[ ]NULL[ ]' $file`" -a \
-z "`egrep '#[ ]*(ifn|un)def[ ]*[ ]NULL($|[ ])' $file`" -z "`egrep '#[ ]*(ifn|un)def[ ]*[ ]NULL($|[ ])' $file`"
...@@ -2595,7 +2615,7 @@ extern unsigned int\ ...@@ -2595,7 +2615,7 @@ extern unsigned int\
# #
# Fix 90: Va_I960_Macro # Fix 91: Va_I960_Macro
# #
case "$file" in ./arch/i960/archI960.h ) case "$file" in ./arch/i960/archI960.h )
if ( test -n "`egrep '__(vsiz|vali|vpad|alignof__)' $file`" if ( test -n "`egrep '__(vsiz|vali|vpad|alignof__)' $file`"
...@@ -2619,7 +2639,7 @@ extern unsigned int\ ...@@ -2619,7 +2639,7 @@ extern unsigned int\
# #
# Fix 91: Void_Null # Fix 92: Void_Null
# #
case "$file" in ./curses.h | \ case "$file" in ./curses.h | \
./dbm.h | \ ./dbm.h | \
...@@ -2650,7 +2670,7 @@ extern unsigned int\ ...@@ -2650,7 +2670,7 @@ extern unsigned int\
# #
# Fix 92: Vxworks_Gcc_Problem # Fix 93: Vxworks_Gcc_Problem
# #
case "$file" in ./types/vxTypesBase.h ) case "$file" in ./types/vxTypesBase.h )
if ( test -n "`egrep '__GNUC_TYPEOF_FEATURE_BROKEN_USE_DEFAULT_UNTIL_FIXED__' $file`" if ( test -n "`egrep '__GNUC_TYPEOF_FEATURE_BROKEN_USE_DEFAULT_UNTIL_FIXED__' $file`"
...@@ -2692,7 +2712,7 @@ extern unsigned int\ ...@@ -2692,7 +2712,7 @@ extern unsigned int\
# #
# Fix 93: Vxworks_Needs_Vxtypes # Fix 94: Vxworks_Needs_Vxtypes
# #
case "$file" in ./time.h ) case "$file" in ./time.h )
if ( test -n "`egrep 'uint_t[ ][ ]*_clocks_per_sec' $file`" if ( test -n "`egrep 'uint_t[ ][ ]*_clocks_per_sec' $file`"
...@@ -2713,7 +2733,7 @@ extern unsigned int\ ...@@ -2713,7 +2733,7 @@ extern unsigned int\
# #
# Fix 94: Vxworks_Needs_Vxworks # Fix 95: Vxworks_Needs_Vxworks
# #
case "$file" in ./sys/stat.h ) case "$file" in ./sys/stat.h )
if ( test -n "`egrep '#[ ]define[ ][ ]*__INCstath' $file`" -a \ if ( test -n "`egrep '#[ ]define[ ][ ]*__INCstath' $file`" -a \
...@@ -2739,7 +2759,7 @@ extern unsigned int\ ...@@ -2739,7 +2759,7 @@ extern unsigned int\
# #
# Fix 95: Vxworks_Time # Fix 96: Vxworks_Time
# #
case "$file" in ./time.h ) case "$file" in ./time.h )
if ( test -n "`egrep 'VOIDFUNCPTR' $file`" -a \ if ( test -n "`egrep 'VOIDFUNCPTR' $file`" -a \
...@@ -2771,7 +2791,7 @@ typedef void (*__gcc_VOIDFUNCPTR) ();\ ...@@ -2771,7 +2791,7 @@ typedef void (*__gcc_VOIDFUNCPTR) ();\
# #
# Fix 96: X11_Class # Fix 97: X11_Class
# #
case "$file" in ./X11/ShellP.h ) case "$file" in ./X11/ShellP.h )
if ( test -z "`egrep '__cplusplus' $file`" if ( test -z "`egrep '__cplusplus' $file`"
...@@ -2799,7 +2819,7 @@ typedef void (*__gcc_VOIDFUNCPTR) ();\ ...@@ -2799,7 +2819,7 @@ typedef void (*__gcc_VOIDFUNCPTR) ();\
# #
# Fix 97: X11_Class_Usage # Fix 98: X11_Class_Usage
# #
case "$file" in ./Xm/BaseClassI.h ) case "$file" in ./Xm/BaseClassI.h )
if ( test -z "`egrep '__cplusplus' $file`" if ( test -z "`egrep '__cplusplus' $file`"
...@@ -2820,7 +2840,7 @@ typedef void (*__gcc_VOIDFUNCPTR) ();\ ...@@ -2820,7 +2840,7 @@ typedef void (*__gcc_VOIDFUNCPTR) ();\
# #
# Fix 98: X11_New # Fix 99: X11_New
# #
case "$file" in ./Xm/Traversal.h ) case "$file" in ./Xm/Traversal.h )
if ( test -z "`egrep '__cplusplus' $file`" if ( test -z "`egrep '__cplusplus' $file`"
...@@ -2849,7 +2869,7 @@ typedef void (*__gcc_VOIDFUNCPTR) ();\ ...@@ -2849,7 +2869,7 @@ typedef void (*__gcc_VOIDFUNCPTR) ();\
# #
# Fix 99: X11_Sprintf # Fix 100: X11_Sprintf
# #
case "$file" in ./X11*/Xmu.h ) case "$file" in ./X11*/Xmu.h )
fixlist="${fixlist} fixlist="${fixlist}
...@@ -2869,7 +2889,7 @@ extern char * sprintf();\ ...@@ -2869,7 +2889,7 @@ extern char * sprintf();\
# #
# Fix 100: Zzz_Ki_Iface # Fix 101: Zzz_Ki_Iface
# #
case "$file" in ./sys/ki_iface.h ) case "$file" in ./sys/ki_iface.h )
if ( test -n "`egrep 'These definitions are for HP Internal developers' $file`" if ( test -n "`egrep 'These definitions are for HP Internal developers' $file`"
...@@ -2896,7 +2916,7 @@ cat > /dev/null ) < $infile > ${DESTDIR}/$file. ...@@ -2896,7 +2916,7 @@ cat > /dev/null ) < $infile > ${DESTDIR}/$file.
# #
# Fix 101: Zzz_Ki # Fix 102: Zzz_Ki
# #
case "$file" in ./sys/ki.h ) case "$file" in ./sys/ki.h )
if ( test -n "`egrep '11.00 HP-UX LP64' $file`" if ( test -n "`egrep '11.00 HP-UX LP64' $file`"
...@@ -2923,7 +2943,7 @@ cat > /dev/null ) < $infile > ${DESTDIR}/$file. ...@@ -2923,7 +2943,7 @@ cat > /dev/null ) < $infile > ${DESTDIR}/$file.
# #
# Fix 102: Zzz_Ki_Calls # Fix 103: Zzz_Ki_Calls
# #
case "$file" in ./sys/ki_calls.h ) case "$file" in ./sys/ki_calls.h )
if ( test -n "`egrep 'KI_MAX_PROCS is an arbitrary number' $file`" if ( test -n "`egrep 'KI_MAX_PROCS is an arbitrary number' $file`"
...@@ -2950,7 +2970,7 @@ cat > /dev/null ) < $infile > ${DESTDIR}/$file. ...@@ -2950,7 +2970,7 @@ cat > /dev/null ) < $infile > ${DESTDIR}/$file.
# #
# Fix 103: Zzz_Ki_Defs # Fix 104: Zzz_Ki_Defs
# #
case "$file" in ./sys/ki_defs.h ) case "$file" in ./sys/ki_defs.h )
if ( test -n "`egrep 'Kernel Instrumentation Definitions' $file`" if ( test -n "`egrep 'Kernel Instrumentation Definitions' $file`"
...@@ -2977,7 +2997,7 @@ cat > /dev/null ) < $infile > ${DESTDIR}/$file. ...@@ -2977,7 +2997,7 @@ cat > /dev/null ) < $infile > ${DESTDIR}/$file.
# #
# Fix 104: Zzz_Time # Fix 105: Zzz_Time
# #
case "$file" in ./sys/time.h ) case "$file" in ./sys/time.h )
if ( test -n "`egrep 'For CASPEC, look in' $file`" if ( test -n "`egrep 'For CASPEC, look in' $file`"
...@@ -3041,18 +3061,20 @@ while [ $# != 0 ]; do ...@@ -3041,18 +3061,20 @@ while [ $# != 0 ]; do
# #
cd ${INPUT} cd ${INPUT}
cd $1 cd $1
if [ -r $2 ] && [ ! -r $3 ]; then if [ -f $2 ] ; then
cp $2 $3 >/dev/null 2>&1 || echo "Can't copy $2" >&2 if [ -r $2 ] && [ ! -r $3 ]; then
chmod +w $3 2>/dev/null cp $2 $3 >/dev/null 2>&1 || echo "Can't copy $2" >&2
chmod a+r $3 2>/dev/null chmod +w $3 2>/dev/null
echo Copied $2 chmod a+r $3 2>/dev/null
for include in `egrep '^[ ]*#[ ]*include[ ]*"[^/]' $3 | echo Copied $2
for include in `egrep '^[ ]*#[ ]*include[ ]*"[^/]' $3 |
sed -e 's/^[ ]*#[ ]*include[ ]*"\([^"]*\)".*$/\1/'` sed -e 's/^[ ]*#[ ]*include[ ]*"\([^"]*\)".*$/\1/'`
do do
dir=`echo $2 | sed -e s'|/[^/]*$||'` dir=`echo $2 | sed -e s'|/[^/]*$||'`
dir2=`echo $3 | sed -e s'|/[^/]*$||'` dir2=`echo $3 | sed -e s'|/[^/]*$||'`
newreq="$newreq $1 $dir/$include $dir2/$include" newreq="$newreq $1 $dir/$include $dir2/$include"
done done
fi
fi fi
shift; shift; shift shift; shift; shift
done done
...@@ -3081,6 +3103,6 @@ done ...@@ -3081,6 +3103,6 @@ done
cd $ORIGDIR cd $ORIGDIR
rm -f include/assert.h rm -f include/assert.h
cp ${EGCS_SRCDIR}/assert.h include/assert.h cp ${srcdir}/assert.h include/assert.h || exit 1
chmod a+r include/assert.h chmod a+r include/assert.h
[= autogen template -*- Mode: ksh -*- [= autogen template -*- Mode: ksh -*-
sh sh
# #
# $Id: inclhack.tpl,v 1.2 1998/12/16 21:19:11 law Exp $
# #
=] =]
#!/bin/sh #!/bin/sh
...@@ -116,10 +115,7 @@ for INPUT in ${INPUTLIST} ; do ...@@ -116,10 +115,7 @@ for INPUT in ${INPUTLIST} ; do
cd ${ORIGDIR} cd ${ORIGDIR}
cd ${INPUT} || { cd ${INPUT} || continue
echo 'fixincludes: input dir `'$INPUT"' is an invalid directory"
exit 1
}
# #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
...@@ -342,18 +338,20 @@ while [ $# != 0 ]; do ...@@ -342,18 +338,20 @@ while [ $# != 0 ]; do
# #
cd ${INPUT} cd ${INPUT}
cd $1 cd $1
if [ -r $2 ] && [ ! -r $3 ]; then if [ -f $2 ] ; then
cp $2 $3 >/dev/null 2>&1 || echo "Can't copy $2" >&2 if [ -r $2 ] && [ ! -r $3 ]; then
chmod +w $3 2>/dev/null cp $2 $3 >/dev/null 2>&1 || echo "Can't copy $2" >&2
chmod a+r $3 2>/dev/null chmod +w $3 2>/dev/null
echo Copied $2 chmod a+r $3 2>/dev/null
for include in `egrep '^[ ]*#[ ]*include[ ]*"[^/]' $3 | echo Copied $2
for include in `egrep '^[ ]*#[ ]*include[ ]*"[^/]' $3 |
sed -e 's/^[ ]*#[ ]*include[ ]*"\([^"]*\)".*$/\1/'` sed -e 's/^[ ]*#[ ]*include[ ]*"\([^"]*\)".*$/\1/'`
do do
dir=`echo $2 | sed -e s'|/[^/]*$||'` dir=`echo $2 | sed -e s'|/[^/]*$||'`
dir2=`echo $3 | sed -e s'|/[^/]*$||'` dir2=`echo $3 | sed -e s'|/[^/]*$||'`
newreq="$newreq $1 $dir/$include $dir2/$include" newreq="$newreq $1 $dir/$include $dir2/$include"
done done
fi
fi fi
shift; shift; shift shift; shift; shift
done done
...@@ -382,7 +380,7 @@ done ...@@ -382,7 +380,7 @@ done
cd $ORIGDIR cd $ORIGDIR
rm -f include/assert.h rm -f include/assert.h
cp ${EGCS_SRCDIR}/assert.h include/assert.h cp ${srcdir}/assert.h include/assert.h || exit 1
chmod a+r include/assert.h chmod a+r include/assert.h
[= [=
......
...@@ -7,8 +7,10 @@ then ...@@ -7,8 +7,10 @@ then
exit 1 exit 1
fi fi
echo constructing fixinc.sh for $machine target=../fixinc.sh
fixincludes="../fixinc.sh"
echo constructing ${target} for $machine
fixincludes="${target}"
case $machine in case $machine in
*-*-gnu*) *-*-gnu*)
...@@ -103,21 +105,47 @@ case $machine in ...@@ -103,21 +105,47 @@ case $machine in
;; ;;
esac esac
# IF there is no include fixing,
# THEN create a no-op fixer and exit
#
if test -z "$fixincludes" if test -z "$fixincludes"
then then
cat > ../fixinc.sh <<- _EOF_ cat > ${target} <<- _EOF_
#! /bin/sh #! /bin/sh
exit 0 exit 0
_EOF_ _EOF_
exit 0 exit 0
fi fi
if test -f "$fixincludes" # IF the fixer is supplied in our source directory,
# THEN copy that into place
#
if test -f ${srcdir}/"${fixincludes}"
then then
echo copying $fixincludes to ../fixinc.sh echo copying ${srcdir}/$fixincludes to ${target}
cp $fixincludes ../fixinc.sh cp ${srcdir}/$fixincludes ${target}
exit 0 exit 0
fi fi
echo $MAKE install # OK. We gotta make the thing.
$MAKE install || cp inclhack.sh .. #
echo $MAKE SHELL=\"$SHELL\" install
# make and install either the binary or the default script
#
$MAKE SHELL="$SHELL" install && exit 0
# Where is our inclhack script? That is the backup
# in case we are unable to make a working binary.
#
if test -f ./inclhack.sh
then
INCLHACK=./inclhack.sh
else
INCLHACK=${srcdir}/inclhack.sh
fi
echo Could not install binary fixincludes.
echo Installing shell script instead.
cp ${INCLHACK} ${target}
/*
* server.c Set up and handle communications with a server process.
*
* Server Handling copyright 1992-1999 The Free Software Foundation
*
* Server Handling 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.
*
* Server Handling 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 Server Handling. See the file "COPYING". If not,
* write to: The Free Software Foundation, Inc.,
* 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
* As a special exception, The Free Software Foundation gives
* permission for additional uses of the text contained in his release
* of ServerHandler.
*
* The exception is that, if you link the ServerHandler library with other
* files to produce an executable, this does not by itself cause the
* resulting executable to be covered by the GNU General Public License.
* Your use of that executable is in no way restricted on account of
* linking the ServerHandler library code into it.
*
* This exception does not however invalidate any other reasons why
* the executable file might be covered by the GNU General Public License.
*
* This exception applies only to the code released by The Free
* Software Foundation under the name ServerHandler. If you copy code
* from other sources under the General Public License into a copy of
* ServerHandler, as the General Public License permits, the exception
* does not apply to the code that you add in this way. To avoid
* misleading anyone as to the status of such modified files, you must
* delete this exception notice from them.
*
* If you write modifications of your own for ServerHandler, it is your
* choice whether to permit this exception to apply to your modifications.
* If you do not wish that, delete this exception notice.
*/
#include "config.h"
#include <sys/types.h>
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#endif
#include <errno.h>
#include <signal.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <sys/param.h>
#include "server.h"
/* If this particular system's header files define the macro `MAXPATHLEN',
we happily take advantage of it; otherwise we use a value which ought
to be large enough. */
#ifndef MAXPATHLEN
# define MAXPATHLEN 4096
#endif
#ifndef STDIN_FILENO
# define STDIN_FILENO 0
#endif
#ifndef STDOUT_FILENO
# define STDOUT_FILENO 1
#endif
#ifdef DEBUG
#define STATIC
#else
#define STATIC static
#endif
#ifndef tSCC
#define tSCC static const char
#endif
#ifndef NUL
#define NUL '\0'
#endif
STATIC t_pchar def_args[] =
{ (char *) NULL, (char *) NULL };
/*
* chain_open
*
* Given an FD for an inferior process to use as stdin,
* start that process and return a NEW FD that that process
* will use for its stdout. Requires the argument vector
* for the new process and, optionally, a pointer to a place
* to store the child's process id.
*/
int
chain_open (stdin_fd, pp_args, p_child)
int stdin_fd;
t_pchar *pp_args;
pid_t *p_child;
{
t_fd_pair stdout_pair = {-1, -1};
pid_t ch_id;
char *pz_cmd;
/*
* Create a pipe it will be the child process' stdout,
* and the parent will read from it.
*/
if (pipe ((int *) &stdout_pair) < 0)
{
if (p_child != (pid_t *) NULL)
*p_child = NOPROCESS;
return -1;
}
/*
* If we did not get an arg list, use the default
*/
if (pp_args == (t_pchar *) NULL)
pp_args = def_args;
/*
* If the arg list does not have a program,
* assume the "SHELL" from the environment, or, failing
* that, then sh. Set argv[0] to whatever we decided on.
*/
if (pz_cmd = *pp_args,
(pz_cmd == (char *) NULL) || (*pz_cmd == '\0'))
{
pz_cmd = getenv ("SHELL");
if (pz_cmd == (char *) NULL)
pz_cmd = "sh";
}
#ifdef DEBUG_PRINT
printf ("START: %s\n", pz_cmd);
{
int idx = 0;
while (pp_args[++idx] != (char *) NULL)
printf (" ARG %2d: %s\n", idx, pp_args[idx]);
}
#endif
/*
* Call fork() and see which process we become
*/
ch_id = fork ();
switch (ch_id)
{
case NOPROCESS: /* parent - error in call */
close (stdout_pair.read_fd);
close (stdout_pair.write_fd);
if (p_child != (pid_t *) NULL)
*p_child = NOPROCESS;
return -1;
default: /* parent - return opposite FD's */
if (p_child != (pid_t *) NULL)
*p_child = ch_id;
#ifdef DEBUG_PRINT
printf ("for pid %d: stdin from %d, stdout to %d\n"
"for parent: read from %d\n",
ch_id, stdin_fd, stdout_pair.write_fd, stdout_pair.read_fd);
#endif
close (stdin_fd);
close (stdout_pair.write_fd);
return stdout_pair.read_fd;
case NULLPROCESS: /* child - continue processing */
break;
}
/*
* Close the pipe end handed back to the parent process
*/
close (stdout_pair.read_fd);
/*
* Close our current stdin and stdout
*/
close (STDIN_FILENO);
close (STDOUT_FILENO);
/*
* Make the fd passed in the stdin, and the write end of
* the new pipe become the stdout.
*/
fcntl (stdout_pair.write_fd, F_DUPFD, STDOUT_FILENO);
fcntl (stdin_fd, F_DUPFD, STDIN_FILENO);
if (*pp_args == (char *) NULL)
*pp_args = pz_cmd;
execvp (pz_cmd, pp_args);
fprintf (stderr, "Error %d: Could not execvp( '%s', ... ): %s\n",
errno, pz_cmd, strerror (errno));
exit (EXIT_PANIC);
}
/*
* proc2_open
*
* Given a pointer to an argument vector, start a process and
* place its stdin and stdout file descriptors into an fd pair
* structure. The "write_fd" connects to the inferior process
* stdin, and the "read_fd" connects to its stdout. The calling
* process should write to "write_fd" and read from "read_fd".
* The return value is the process id of the created process.
*/
pid_t
proc2_open (p_pair, pp_args)
t_fd_pair *p_pair;
t_pchar *pp_args;
{
pid_t ch_id;
/* Create a bi-directional pipe. Writes on 0 arrive on 1 and vice
versa, so the parent and child processes will read and write to
opposite FD's. */
if (pipe ((int *) p_pair) < 0)
return NOPROCESS;
p_pair->read_fd = chain_open (p_pair->read_fd, pp_args, &ch_id);
if (ch_id == NOPROCESS)
close (p_pair->write_fd);
return ch_id;
}
/*
* proc2_fopen
*
* Identical to "proc2_open()", except that the "fd"'s are
* "fdopen(3)"-ed into file pointers instead.
*/
pid_t
proc2_fopen (pf_pair, pp_args)
t_pf_pair *pf_pair;
t_pchar *pp_args;
{
t_fd_pair fd_pair;
pid_t ch_id = proc2_open (&fd_pair, pp_args);
if (ch_id == NOPROCESS)
return ch_id;
pf_pair->pf_read = fdopen (fd_pair.read_fd, "r");
pf_pair->pf_write = fdopen (fd_pair.write_fd, "w");
return ch_id;
}
...@@ -25,8 +25,6 @@ ...@@ -25,8 +25,6 @@
#pragma alloca #pragma alloca
#endif #endif
/* $Id: regex.c,v 1.3 1999/01/11 13:34:23 law Exp $ */
#define _GNU_SOURCE #define _GNU_SOURCE
/* We need this for `regex.h', and perhaps for the Emacs include files. */ /* We need this for `regex.h', and perhaps for the Emacs include files. */
......
...@@ -18,8 +18,6 @@ ...@@ -18,8 +18,6 @@
Foundation, 59 Temple Place - Suite 330, Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */ Boston, MA 02111-1307, USA. */
/* $Id: regex.h,v 1.3 1999/01/11 13:34:25 law Exp $ */
#ifndef __REGEXP_LIBRARY_H__ #ifndef __REGEXP_LIBRARY_H__
#define __REGEXP_LIBRARY_H__ #define __REGEXP_LIBRARY_H__
......
/* /*
* $Id: server.c,v 1.2 1998/12/16 21:19:16 law Exp $ * server.c Set up and handle communications with a server process.
* *
* Server Handling copyright 1992-1998 Bruce Korb * Server Handling copyright 1992-1999 The Free Software Foundation
* *
* Server Handling is free software. * Server Handling is free software.
* You may redistribute it and/or modify it under the terms of the * You may redistribute it and/or modify it under the terms of the
...@@ -20,8 +20,9 @@ ...@@ -20,8 +20,9 @@
* 59 Temple Place - Suite 330, * 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA. * Boston, MA 02111-1307, USA.
* *
* As a special exception, Bruce Korb gives permission for additional * As a special exception, The Free Software Foundation gives
* uses of the text contained in his release of ServerHandler. * permission for additional uses of the text contained in his release
* of ServerHandler.
* *
* The exception is that, if you link the ServerHandler library with other * The exception is that, if you link the ServerHandler library with other
* files to produce an executable, this does not by itself cause the * files to produce an executable, this does not by itself cause the
...@@ -32,19 +33,24 @@ ...@@ -32,19 +33,24 @@
* This exception does not however invalidate any other reasons why * This exception does not however invalidate any other reasons why
* the executable file might be covered by the GNU General Public License. * the executable file might be covered by the GNU General Public License.
* *
* This exception applies only to the code released by Bruce Korb under * This exception applies only to the code released by The Free
* the name ServerHandler. If you copy code from other sources under the * Software Foundation under the name ServerHandler. If you copy code
* General Public License into a copy of ServerHandler, as the General Public * from other sources under the General Public License into a copy of
* License permits, the exception does not apply to the code that you add * ServerHandler, as the General Public License permits, the exception
* in this way. To avoid misleading anyone as to the status of such * does not apply to the code that you add in this way. To avoid
* modified files, you must delete this exception notice from them. * misleading anyone as to the status of such modified files, you must
* delete this exception notice from them.
* *
* If you write modifications of your own for ServerHandler, it is your * If you write modifications of your own for ServerHandler, it is your
* choice whether to permit this exception to apply to your modifications. * choice whether to permit this exception to apply to your modifications.
* If you do not wish that, delete this exception notice. * If you do not wish that, delete this exception notice.
*/ */
#include "config.h"
#include <sys/types.h>
#ifdef HAVE_FCNTL_H
#include <fcntl.h> #include <fcntl.h>
#endif
#include <errno.h> #include <errno.h>
#include <signal.h> #include <signal.h>
#include <stdlib.h> #include <stdlib.h>
...@@ -54,6 +60,20 @@ ...@@ -54,6 +60,20 @@
#include "server.h" #include "server.h"
/* If this particular system's header files define the macro `MAXPATHLEN',
we happily take advantage of it; otherwise we use a value which ought
to be large enough. */
#ifndef MAXPATHLEN
# define MAXPATHLEN 4096
#endif
#ifndef STDIN_FILENO
# define STDIN_FILENO 0
#endif
#ifndef STDOUT_FILENO
# define STDOUT_FILENO 1
#endif
#ifdef DEBUG #ifdef DEBUG
#define STATIC #define STATIC
#else #else
...@@ -66,398 +86,218 @@ ...@@ -66,398 +86,218 @@
#define NUL '\0' #define NUL '\0'
#endif #endif
STATIC bool readPipeTimeout; STATIC bool read_pipe_timeout;
STATIC tpChar defArgs[] = STATIC t_pchar def_args[] =
{(char *) NULL, "-p", (char *) NULL}; { (char *) NULL, (char *) NULL };
STATIC tpfPair serverPair = STATIC t_pf_pair server_pair =
{(FILE *) NULL, (FILE *) NULL}; { (FILE *) NULL, (FILE *) NULL };
STATIC pid_t serverId = NULLPROCESS; STATIC pid_t server_id = NULLPROCESS;
/* /*
* Arbitrary text that should not be found in the shell output. * Arbitrary text that should not be found in the shell output.
* It must be a single line and appear verbatim at the start of * It must be a single line and appear verbatim at the start of
* the terminating output line. * the terminating output line.
*/ */
tSCC zDone[] = "ShElL-OuTpUt-HaS-bEeN-cOmPlEtEd"; tSCC z_done[] = "ShElL-OuTpUt-HaS-bEeN-cOmPlEtEd";
STATIC tpChar pCurDir = (char *) NULL; STATIC t_pchar p_cur_dir = (char *) NULL;
/*
* chainOpen
*
* Given an FD for an inferior process to use as stdin,
* start that process and return a NEW FD that that process
* will use for its stdout. Requires the argument vector
* for the new process and, optionally, a pointer to a place
* to store the child's process id.
*/
int
chainOpen (stdinFd, ppArgs, pChild)
int stdinFd;
tpChar *ppArgs;
pid_t *pChild;
{
tFdPair stdoutPair =
{-1, -1};
pid_t chId;
char *pzCmd;
/*
* Create a pipe it will be the child process' stdout,
* and the parent will read from it.
*/
if ((pipe ((int *) &stdoutPair) < 0))
{
if (pChild != (pid_t *) NULL)
*pChild = NOPROCESS;
return -1;
}
/*
* If we did not get an arg list, use the default
*/
if (ppArgs == (tpChar *) NULL)
ppArgs = defArgs;
/*
* If the arg list does not have a program,
* assume the "SHELL" from the environment, or, failing
* that, then sh. Set argv[0] to whatever we decided on.
*/
if (pzCmd = *ppArgs,
(pzCmd == (char *) NULL) || (*pzCmd == '\0'))
{
pzCmd = getenv ("SHELL");
if (pzCmd == (char *) NULL)
pzCmd = "sh";
}
#ifdef DEBUG_PRINT
printf ("START: %s\n", pzCmd);
{
int idx = 0;
while (ppArgs[++idx] != (char *) NULL)
printf (" ARG %2d: %s\n", idx, ppArgs[idx]);
}
#endif
/*
* Call fork() and see which process we become
*/
chId = fork ();
switch (chId)
{
case NOPROCESS: /* parent - error in call */
close (stdoutPair.readFd);
close (stdoutPair.writeFd);
if (pChild != (pid_t *) NULL)
*pChild = NOPROCESS;
return -1;
default: /* parent - return opposite FD's */
if (pChild != (pid_t *) NULL)
*pChild = chId;
#ifdef DEBUG_PRINT
printf ("for pid %d: stdin from %d, stdout to %d\n"
"for parent: read from %d\n",
chId, stdinFd, stdoutPair.writeFd, stdoutPair.readFd);
#endif
close (stdinFd);
close (stdoutPair.writeFd);
return stdoutPair.readFd;
case NULLPROCESS: /* child - continue processing */
break;
}
/*
* Close the pipe end handed back to the parent process
*/
close (stdoutPair.readFd);
/*
* Close our current stdin and stdout
*/
close (STDIN_FILENO);
close (STDOUT_FILENO);
/*
* Make the fd passed in the stdin, and the write end of
* the new pipe become the stdout.
*/
fcntl (stdoutPair.writeFd, F_DUPFD, STDOUT_FILENO);
fcntl (stdinFd, F_DUPFD, STDIN_FILENO);
if (*ppArgs == (char *) NULL)
*ppArgs = pzCmd;
execvp (pzCmd, ppArgs);
fprintf (stderr, "Error %d: Could not execvp( '%s', ... ): %s\n",
errno, pzCmd, strerror (errno));
exit (EXIT_PANIC);
}
/*
* p2open
*
* Given a pointer to an argument vector, start a process and
* place its stdin and stdout file descriptors into an fd pair
* structure. The "writeFd" connects to the inferior process
* stdin, and the "readFd" connects to its stdout. The calling
* process should write to "writeFd" and read from "readFd".
* The return value is the process id of the created process.
*/
pid_t
p2open (pPair, ppArgs)
tFdPair *pPair;
tpChar *ppArgs;
{
pid_t chId;
/*
* Create a bi-directional pipe. Writes on 0 arrive on 1
* and vice versa, so the parent and child processes will
* read and write to opposite FD's.
*/
if (pipe ((int *) pPair) < 0)
return NOPROCESS;
pPair->readFd = chainOpen (pPair->readFd, ppArgs, &chId);
if (chId == NOPROCESS)
close (pPair->writeFd);
return chId;
}
/* /*
* p2fopen * load_data
*
* Identical to "p2open()", except that the "fd"'s are "fdopen(3)"-ed
* into file pointers instead.
*/
pid_t
p2fopen (pfPair, ppArgs)
tpfPair *pfPair;
tpChar *ppArgs;
{
tFdPair fdPair;
pid_t chId = p2open (&fdPair, ppArgs);
if (chId == NOPROCESS)
return chId;
pfPair->pfRead = fdopen (fdPair.readFd, "r");
pfPair->pfWrite = fdopen (fdPair.writeFd, "w");
return chId;
}
/*
* loadData
* *
* Read data from a file pointer (a pipe to a process in this context) * Read data from a file pointer (a pipe to a process in this context)
* until we either get EOF or we get a marker line back. * until we either get EOF or we get a marker line back.
* The read data are stored in a malloc-ed string that is truncated * The read data are stored in a malloc-ed string that is truncated
* to size at the end. Input is assumed to be an ASCII string. * to size at the end. Input is assumed to be an ASCII string.
*/ */
STATIC char * static char *
loadData (fp) load_data (fp)
FILE *fp; FILE *fp;
{ {
char *pzText; char *pz_text;
size_t textSize; size_t text_size;
char *pzScan; char *pz_scan;
char zLine[1024]; char z_line[1024];
textSize = sizeof (zLine) * 2; text_size = sizeof (z_line) * 2;
pzScan = \ pz_scan = pz_text = malloc (text_size);
pzText = malloc (textSize);
if (pzText == (char *) NULL) if (pz_text == (char *) NULL)
return pzText; return (char *) NULL;
for (;;) for (;;)
{ {
size_t usedCt; size_t used_ct;
alarm (10); alarm (10);
readPipeTimeout = BOOL_FALSE; read_pipe_timeout = BOOL_FALSE;
if (fgets (zLine, sizeof (zLine), fp) == (char *) NULL) if (fgets (z_line, sizeof (z_line), fp) == (char *) NULL)
break; break;
if (strncmp (zLine, zDone, sizeof (zDone) - 1) == 0) if (strncmp (z_line, z_done, sizeof (z_done) - 1) == 0)
break; break;
strcpy (pzScan, zLine); strcpy (pz_scan, z_line);
pzScan += strlen (zLine); pz_scan += strlen (z_line);
usedCt = (size_t) (pzScan - pzText); used_ct = (size_t) (pz_scan - pz_text);
if (textSize - usedCt < sizeof (zLine)) if (text_size - used_ct < sizeof (z_line))
{ {
size_t off = (size_t) (pz_scan - pz_text);
size_t off = (size_t) (pzScan - pzText); void *p;
void *p;
textSize += 4096; text_size += 4096;
p = realloc ((void *) pzText, textSize); p = realloc ((void *) pz_text, text_size);
if (p == (void *) NULL) if (p == (void *) NULL)
{ {
fprintf (stderr, "Failed to get 0x%08X bytes\n", textSize); fprintf (stderr, "Failed to get 0x%08X bytes\n", text_size);
free ((void *) pzText); free ((void *) pz_text);
return (char *) NULL; return (char *) NULL;
} }
pz_text = (char *) p;
pzText = (char *) p; pz_scan = pz_text + off;
pzScan = pzText + off; }
}
} }
alarm (0); alarm (0);
if (readPipeTimeout) if (read_pipe_timeout)
{ {
free ((void *) pzText); free ((void *) pz_text);
return (char *) NULL; return (char *) NULL;
} }
while ((pzScan > pzText) && isspace (pzScan[-1])) while ((pz_scan > pz_text) && isspace (pz_scan[-1]))
pzScan--; pz_scan--;
*pzScan = NUL; *pz_scan = NUL;
return realloc ((void *) pzText, strlen (pzText) + 1); return realloc ((void *) pz_text, strlen (pz_text) + 1);
} }
/* /*
* SHELL SERVER PROCESS CODE * close_server
*
* Make certain the server process is dead, close the
* pipes to it and from it, finally NULL out the file pointers
*/ */
static void
#ifdef DONT_HAVE_SIGSEND close_server ()
typedef enum
{ {
P_ALL, P_PID, P_GID, P_UID, P_PGID, P_SID, P_CID kill ((pid_t) server_id, SIGKILL);
server_id = NULLPROCESS;
fclose (server_pair.pf_read);
fclose (server_pair.pf_write);
server_pair.pf_read = server_pair.pf_write = (FILE *) NULL;
} }
idtype_t;
typedef long id_t;
STATIC int
sigsend (idtype, id, sig)
idtype_t idtype;
id_t id;
int sig;
{
switch (idtype)
{
case P_PID:
kill ((pid_t) id, sig);
break;
case P_ALL:
case P_GID:
case P_UID:
case P_PGID:
case P_SID:
case P_CID:
errno = EINVAL;
return -1;
/*NOTREACHED */
}
return 0;
}
#endif /* HAVE_SIGSEND */
STATIC void /*
closeServer () * sig_handler really only handles the timeout and pipe signals.
{ * This ensures that we do not wait forever on a request
kill( (pid_t) serverId, SIGKILL); * to our server, and also that if the server dies, we do not
serverId = NULLPROCESS; * die from a sigpipe problem.
fclose (serverPair.pfRead); */
fclose (serverPair.pfWrite); static void
serverPair.pfRead = serverPair.pfWrite = (FILE *) NULL; sig_handler (signo)
}
struct sigaction savePipeAction;
struct sigaction saveAlrmAction;
struct sigaction currentAction;
STATIC void
sigHandler (signo)
int signo; int signo;
{ {
closeServer (); close_server ();
readPipeTimeout = BOOL_TRUE; read_pipe_timeout = BOOL_TRUE;
} }
STATIC void /*
serverSetup () * server_setup Establish the signal handler for PIPE and ALARM.
* Also establishes the current directory to give to the
* server process at the start of every server command.
*/
static void
server_setup ()
{ {
#ifndef SA_SIGINFO static int atexit_done = 0;
# define SA_SIGINFO 0
#else if (atexit_done++ == 0)
currentAction.sa_sigaction = atexit (&close_server);
#endif
currentAction.sa_handler = sigHandler;
currentAction.sa_flags = SA_SIGINFO;
sigemptyset( &currentAction.sa_mask );
sigaction( SIGPIPE, &currentAction, &savePipeAction ); signal (SIGPIPE, sig_handler);
sigaction( SIGALRM, &currentAction, &saveAlrmAction ); signal (SIGALRM, sig_handler);
atexit( &closeServer );
fputs ("trap : INT\n", serverPair.pfWrite); fputs ("trap : 1\n", server_pair.pf_write);
fflush (serverPair.pfWrite); fflush (server_pair.pf_write);
pCurDir = getcwd ((char *) NULL, MAXPATHLEN + 1); p_cur_dir = getcwd ((char *) NULL, MAXPATHLEN + 1);
} }
/*
* run_shell
*
* Run a shell command on the server. The command string
* passed in is wrapped inside the sequence:
*
* cd <original directory>
* <command string>
* echo
* echo <end-of-command-marker>
*
* This ensures that all commands start at a known place in
* the directory structure, that any incomplete output lines
* are completed and that our special marker sequence appears on
* a line by itself. We have chosen a marker that is
* excessively unlikely to be reproduced in normal output:
*
* "ShElL-OuTpUt-HaS-bEeN-cOmPlEtEd"
*/
char * char *
runShell (pzCmd) run_shell (pz_cmd)
const char *pzCmd; const char *pz_cmd;
{ {
tSCC zNil[] = ""; /* IF the shell server process is not running yet,
THEN try to start it. */
if (server_id == NULLPROCESS)
{
server_id = proc2_fopen (&server_pair, def_args);
if (server_id > 0)
server_setup ();
}
/* /* IF it is still not running, THEN return the nil string. */
* IF the shell server process is not running yet, if (server_id <= 0)
* THEN try to start it.
*/
if (serverId == NULLPROCESS)
{ {
serverId = p2fopen (&serverPair, defArgs); char *pz = (char *) malloc (1);
if (serverId > 0)
serverSetup (); if (pz != (char *) NULL)
*pz = '\0';
return pz;
} }
/* /* Make sure the process will pay attention to us, send the
* IF it is still not running, supplied command, and then have it output a special marker that
* THEN return the nil string. we can find. */
*/ fprintf (server_pair.pf_write, "\\cd %s\n%s\n\necho\necho %s\n",
if (serverId <= 0) p_cur_dir, pz_cmd, z_done);
return (char *) zNil; fflush (server_pair.pf_write);
/* /* IF the server died and we received a SIGPIPE,
* Make sure the process will pay attention to us, THEN return an empty string. */
* send the supplied command, and then if (server_id == NULLPROCESS)
* have it output a special marker that we can find. {
*/ char *pz = (char *) malloc (1);
fprintf (serverPair.pfWrite, "\\cd %s\n%s\n\necho\necho %s\n",
pCurDir, pzCmd, zDone); if (pz != (char *) NULL)
fflush (serverPair.pfWrite); *pz = '\0';
if (serverId == NULLPROCESS) return pz;
return (char *) NULL; }
/* /* Now try to read back all the data. If we fail due to either a
* Now try to read back all the data. If we fail due to either sigpipe or sigalrm (timeout), we will return the nil string. */
* a sigpipe or sigalrm (timeout), we will return the nil string.
*/
{ {
char *pz = loadData (serverPair.pfRead); char *pz = load_data (server_pair.pf_read);
if (pz == (char *) NULL) if (pz == (char *) NULL)
{ {
fprintf (stderr, "CLOSING SHELL SERVER - command failure:\n\t%s\n", fprintf (stderr, "CLOSING SHELL SERVER - command failure:\n\t%s\n",
pzCmd); pz_cmd);
closeServer (); close_server ();
pz = (char *) zNil; pz = (char *) malloc (1);
if (pz != (char *) NULL)
*pz = '\0';
} }
return pz; return pz;
} }
......
/* /*
* $Id: server.h,v 1.2 1998/12/16 21:19:17 law Exp $ * server.c Set up and handle communications with a server process.
* *
* Server Handling copyright 1992-1998 Bruce Korb * Server Handling copyright 1992-1999 The Free Software Foundation
* *
* Server Handling is free software. * Server Handling is free software.
* You may redistribute it and/or modify it under the terms of the * You may redistribute it and/or modify it under the terms of the
...@@ -20,8 +20,9 @@ ...@@ -20,8 +20,9 @@
* 59 Temple Place - Suite 330, * 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA. * Boston, MA 02111-1307, USA.
* *
* As a special exception, Bruce Korb gives permission for additional * As a special exception, The Free Software Foundation gives
* uses of the text contained in his release of ServerHandler. * permission for additional uses of the text contained in his release
* of ServerHandler.
* *
* The exception is that, if you link the ServerHandler library with other * The exception is that, if you link the ServerHandler library with other
* files to produce an executable, this does not by itself cause the * files to produce an executable, this does not by itself cause the
...@@ -32,12 +33,13 @@ ...@@ -32,12 +33,13 @@
* This exception does not however invalidate any other reasons why * This exception does not however invalidate any other reasons why
* the executable file might be covered by the GNU General Public License. * the executable file might be covered by the GNU General Public License.
* *
* This exception applies only to the code released by Bruce Korb under * This exception applies only to the code released by The Free
* the name ServerHandler. If you copy code from other sources under the * Software Foundation under the name ServerHandler. If you copy code
* General Public License into a copy of ServerHandler, as the General Public * from other sources under the General Public License into a copy of
* License permits, the exception does not apply to the code that you add * ServerHandler, as the General Public License permits, the exception
* in this way. To avoid misleading anyone as to the status of such * does not apply to the code that you add in this way. To avoid
* modified files, you must delete this exception notice from them. * misleading anyone as to the status of such modified files, you must
* delete this exception notice from them.
* *
* If you write modifications of your own for ServerHandler, it is your * If you write modifications of your own for ServerHandler, it is your
* choice whether to permit this exception to apply to your modifications. * choice whether to permit this exception to apply to your modifications.
...@@ -48,47 +50,45 @@ ...@@ -48,47 +50,45 @@
#define FIXINC_SERVER_H #define FIXINC_SERVER_H
#include <stdio.h> #include <stdio.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h> #include <unistd.h>
#endif
/* /*
* Dual pipe opening of a child process * Dual pipe opening of a child process
*/ */
typedef struct typedef struct
{ {
int readFd; int read_fd;
int writeFd; int write_fd;
} } t_fd_pair;
tFdPair;
typedef struct typedef struct
{ {
FILE *pfRead; /* parent read fp */ FILE *pf_read; /* parent read fp */
FILE *pfWrite; /* parent write fp */ FILE *pf_write; /* parent write fp */
} } t_pf_pair;
tpfPair;
typedef char *tpChar; typedef char *t_pchar;
#define NOPROCESS ((pid_t)-1) #define NOPROCESS ((pid_t) -1)
#define NULLPROCESS ((pid_t)0) #define NULLPROCESS ((pid_t)0)
#define EXIT_PANIC 99 #define EXIT_PANIC 99
typedef enum typedef enum
{ {
BOOL_FALSE, BOOL_TRUE BOOL_FALSE, BOOL_TRUE
} } bool;
bool;
#define _P_(p) () #define _P_(p) ()
char *runShell _P_ ((const char *pzCmd)); char *run_shell _P_ (( const char *pzCmd));
pid_t p2fopen _P_ ((tpfPair * pfPair, tpChar * ppArgs)); pid_t proc2_fopen _P_ (( t_pf_pair * p_pair, t_pchar * pp_args));
pid_t p2open _P_ ((tFdPair * pPair, tpChar * ppArgs)); pid_t proc2_open _P_ (( t_fd_pair * p_pair, t_pchar * pp_args));
int int chain_open _P_ (( int in_fd,
chainOpen _P_ ((int stdinFd, t_pchar * pp_args,
tpChar * ppArgs, pid_t * p_child));
pid_t * pChild));
#endif /* FIXINC_SERVER_H */ #endif /* FIXINC_SERVER_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment