Commit 7d9ccd90 by Bruce Korb

Reworked method for traversing sym-linked directory hierarchies

From-SVN: r26086
parent 5877286e
...@@ -139,6 +139,8 @@ struct fix_desc ...@@ -139,6 +139,8 @@ struct fix_desc
char *pz_dest_dir = NULL; char *pz_dest_dir = NULL;
char *pz_src_dir = NULL; char *pz_src_dir = NULL;
char *pz_machine = NULL; char *pz_machine = NULL;
char *pz_find_base = NULL;
int find_base_len = 0;
pid_t process_chain_head = (pid_t) -1; pid_t process_chain_head = (pid_t) -1;
...@@ -240,6 +242,17 @@ main (argc, argv) ...@@ -240,6 +242,17 @@ main (argc, argv)
} }
} }
{
static const char var[] = "FIND_BASE";
pz_find_base = getenv (var);
if (pz_find_base == (char *) NULL)
{
fprintf (stderr, var_not_found, var);
exit (EXIT_FAILURE);
}
find_base_len = strlen( pz_find_base );
}
/* Compile all the regular expressions now. /* Compile all the regular expressions now.
That way, it is done only once for the whole run. That way, it is done only once for the whole run.
*/ */
...@@ -298,10 +311,15 @@ main (argc, argv) ...@@ -298,10 +311,15 @@ main (argc, argv)
errno, strerror (errno)); errno, strerror (errno));
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
} }
#ifdef DEBUG #ifndef DEBUG
{
int status;
(void)wait (&status);
}
#else
fprintf (stderr, "Waiting for %d to complete %d files\n", fprintf (stderr, "Waiting for %d to complete %d files\n",
child, file_name_ct); child, file_name_ct);
#endif
{ {
int status; int status;
pid_t dead_kid = wait (&status); pid_t dead_kid = wait (&status);
...@@ -309,17 +327,18 @@ main (argc, argv) ...@@ -309,17 +327,18 @@ main (argc, argv)
if (dead_kid != child) if (dead_kid != child)
fprintf (stderr, "fixincl woke up from a strange child %d (not %d)\n", fprintf (stderr, "fixincl woke up from a strange child %d (not %d)\n",
dead_kid, child); dead_kid, child);
#ifdef DEBUG
else else
fprintf (stderr, "child finished %d files %s\n", file_name_ct, fprintf (stderr, "child finished %d files %s\n", file_name_ct,
status ? strerror (status & 0xFF) : "ok"); status ? strerror (status & 0xFF) : "ok");
#endif
} }
#endif
} }
#else #else
#error "NON-BOGUS LIMITS NOT SUPPORTED?!?!" #error "NON-BOGUS LIMITS NOT SUPPORTED?!?!"
#endif #endif
signal (SIGCLD, SIG_IGN);
#ifdef DEBUG #ifdef DEBUG
fprintf (stderr, "Child start -- processing %d files\n", fprintf (stderr, "Child start -- processing %d files\n",
file_name_ct); file_name_ct);
...@@ -411,8 +430,10 @@ load_file (pz_file_name) ...@@ -411,8 +430,10 @@ load_file (pz_file_name)
if (ferror (fp)) if (ferror (fp))
{ {
fprintf (stderr, "error %d (%s) reading %s\n", errno, int err = errno;
strerror (errno), pz_file_name); if (err != EISDIR)
fprintf (stderr, "error %d (%s) reading %s\n", err,
strerror (err), pz_file_name);
free ((void *) pz_data); free ((void *) pz_data);
fclose (fp); fclose (fp);
return (char *) NULL; return (char *) NULL;
...@@ -596,7 +617,16 @@ create_file (pz_file_name) ...@@ -596,7 +617,16 @@ create_file (pz_file_name)
FILE *pf; FILE *pf;
char fname[MAXPATHLEN]; char fname[MAXPATHLEN];
sprintf (fname, "%s/%s", pz_dest_dir, pz_file_name); #ifdef DEBUG
if (strncmp( pz_file_name, pz_find_base, find_base_len ) != 0)
{
fprintf (stderr, "Error: input file %s does not match %s/*\n",
pz_file_name, pz_find_base );
exit (1);
}
#endif
sprintf (fname, "%s/%s", pz_dest_dir, pz_file_name + find_base_len);
fd = open (fname, O_WRONLY | O_CREAT | O_TRUNC, S_IRALL); fd = open (fname, O_WRONLY | O_CREAT | O_TRUNC, S_IRALL);
...@@ -911,7 +941,7 @@ process (pz_data, pz_file_name) ...@@ -911,7 +941,7 @@ process (pz_data, pz_file_name)
} }
} }
fprintf (stderr, "Applying %-32s to %s\n", fprintf (stderr, "Applying %-24s to %s\n",
p_fixd->fix_name, pz_file_name); p_fixd->fix_name, pz_file_name);
/* IF we do not have a read pointer, /* IF we do not have a read pointer,
......
...@@ -5,19 +5,15 @@ ...@@ -5,19 +5,15 @@
# fixincl program. It is the repetitive guts of the fixincludes logic. # fixincl program. It is the repetitive guts of the fixincludes logic.
# #
=] =]
if $LINKS; then
files=`find . -name '*.h' \( -type f -o -type l \) -print`
else
files=`find . -name '*.h' -type f -print`
fi
echo Checking header files echo Checking header files
for file in $files; do for file in $files; do
if ( test ! -r $file -o \ if ( test ! -r ${file} -o \
-n "`fgrep 'This file is part of the GNU C Library' $file`" ) -n "`fgrep 'This file is part of the GNU C Library' ${file}`" )
then continue ; fi then continue ; fi
fixlist="" fixlist=""
DESTFILE=${DESTDIR}/`echo ${file} | sed "s;${FIND_BASE}/;;" `
[= [=
# #
# FOR every fix description, # FOR every fix description,
...@@ -30,7 +26,7 @@ _FOR fix "\n\n" =] ...@@ -30,7 +26,7 @@ _FOR fix "\n\n" =]
# Fix [=_eval _index 1 + #%3d _printf=]: [=hackname _Cap=] # Fix [=_eval _index 1 + #%3d _printf=]: [=hackname _Cap=]
#[= #[=
_IF files _exist=] _IF files _exist=]
case "$file" in [=_FOR files " | \\\n\t"=]./[=files=][=/files=] )[= case "${file}" in [=_FOR files " | \\\n\t"=]./[=files=][=/files=] )[=
_ENDIF=][= _ENDIF=][=
_IF mach _exist=] _IF mach _exist=]
...@@ -52,8 +48,8 @@ _FOR fix "\n\n" =] ...@@ -52,8 +48,8 @@ _FOR fix "\n\n" =]
true or false. It is enclosed in parenthesis to avoid true or false. It is enclosed in parenthesis to avoid
precedence problems. The output looks like this: precedence problems. The output looks like this:
if ( test -n "`egrep 'find-expr' $file`" -a if ( test -n "`egrep 'find-expr' ${file}`" -a
-z "`egrep 'not-find' $file`" -a -z "`egrep 'not-find' ${file}`" -a
'(' <some-test-expression> ')' '(' <some-test-expression> ')'
) > /dev/null 2>&1 ; then ) > /dev/null 2>&1 ; then
...@@ -62,13 +58,13 @@ _FOR fix "\n\n" =] ...@@ -62,13 +58,13 @@ _FOR fix "\n\n" =]
_IF select _exist =] _IF select _exist =]
if ( test [= if ( test [=
_FOR select " -a \\\n " _FOR select " -a \\\n "
=]-n [=select _shrstr "#`egrep %s $file`" =]-n [=select _shrstr "#`egrep %s ${file}`"
_printf _shstr =][= _printf _shstr =][=
/select=][= /select=][=
_IF bypass _exist =][= _IF bypass _exist =][=
_FOR bypass=] -a \ _FOR bypass=] -a \
-z [=bypass _shrstr "#`egrep %s $file`" -z [=bypass _shrstr "#`egrep %s ${file}`"
_printf _shstr =][= _printf _shstr =][=
/bypass=][= /bypass=][=
_ENDIF=][= _ENDIF=][=
...@@ -89,7 +85,7 @@ _FOR fix "\n\n" =] ...@@ -89,7 +85,7 @@ _FOR fix "\n\n" =]
_IF bypass _exist=][= _IF bypass _exist=][=
_FOR bypass=] -a \ _FOR bypass=] -a \
-z [=bypass _shrstr "#`egrep %s $file`" -z [=bypass _shrstr "#`egrep %s ${file}`"
_printf _shstr=][= _printf _shstr=][=
/bypass=][= /bypass=][=
_ENDIF=] _ENDIF=]
...@@ -98,16 +94,16 @@ _FOR fix "\n\n" =] ...@@ -98,16 +94,16 @@ _FOR fix "\n\n" =]
_ELIF bypass _exist =] _ELIF bypass _exist =]
if ( test [=_FOR bypass " -a \\\n " if ( test [=_FOR bypass " -a \\\n "
=]-z [=bypass _shrstr "#`egrep %s $file`" =]-z [=bypass _shrstr "#`egrep %s ${file}`"
_printf _shstr=][=/bypass=] _printf _shstr=][=/bypass=]
) > /dev/null 2>&1 ; then[= ) > /dev/null 2>&1 ; then[=
_ENDIF=] _ENDIF=]
fixlist="${fixlist} fixlist="${fixlist}
[=hackname=]" [=hackname=]"
if [ ! -r ${DESTDIR}/$file ] if [ ! -r ${DESTFILE} ]
then infile=$file then infile=${file}
else infile=${DESTDIR}/$file ; fi [= else infile=${DESTFILE} ; fi [=
_IF sed _exist=][= _IF sed _exist=][=
_IF shell _exist =][= _IF shell _exist =][=
...@@ -118,16 +114,16 @@ _FOR fix "\n\n" =] ...@@ -118,16 +114,16 @@ _FOR fix "\n\n" =]
sed [= sed [=
_FOR sed =]-e [=sed _shrstr=] \ _FOR sed =]-e [=sed _shrstr=] \
[= [=
/sed=] < $infile > ${DESTDIR}/$file.[= /sed=] < $infile > ${DESTFILE}.[=
_ELIF shell _exist =] _ELIF shell _exist =]
( [=shell=] ) < $infile > ${DESTDIR}/$file. ( [=shell=] ) < $infile > ${DESTDIR}/FIXINC.tmp
# Shell scripts have the potential of removing the output # Shell scripts have the potential of removing the output
# We interpret that to mean the file is not to be altered # We interpret that to mean the file is not to be altered
# #
if test ! -f ${DESTDIR}/$file. if test ! -f ${DESTDIR}/fixinc.tmp
then continue ; fi [= then continue ; fi [=
...@@ -135,8 +131,8 @@ _FOR fix "\n\n" =] ...@@ -135,8 +131,8 @@ _FOR fix "\n\n" =]
_ERROR hackname _get "ERROR: %s has no fixup" _printf=][= _ERROR hackname _get "ERROR: %s has no fixup" _printf=][=
_ENDIF=] _ENDIF=]
rm -f ${DESTFILE}
mv -f ${DESTDIR}/$file. ${DESTDIR}/$file[= mv -f ${DESTDIR}/fixinc.tmp ${DESTFILE}[=
# Close off any opened "if" or "case" statements in reverse order # Close off any opened "if" or "case" statements in reverse order
...@@ -165,21 +161,23 @@ _FOR fix "\n\n" =] ...@@ -165,21 +161,23 @@ _FOR fix "\n\n" =]
# THEN ensure the output is gone # THEN ensure the output is gone
# ELSE look for local directory include syntax # ELSE look for local directory include syntax
# #
if ( test ! -f ${DESTDIR}/$file || \ if ( test ! -f ${DESTFILE} || \
cmp $file ${DESTDIR}/$file ) > /dev/null 2>&1 cmp ${file} ${DESTFILE} ) > /dev/null 2>&1
then then
rm -f ${DESTDIR}/$file rm -f ${DESTFILE}
else else
echo "Fixed $file:${fixlist}" echo "Fixed ${file}:${fixlist}"
# Find any include directives that use "file". # Find any include directives that use "file".
# #
dir=`echo ${file} | sed -e s';/[^/]*$;;'`
ddir=`echo ${DESTDIR} | sed 's;/[^/]*$;;'`/$dir
for include in ` for include in `
egrep '^[ ]*#[ ]*include[ ]*"[^/]' ${DESTDIR}/$file | egrep '^[ ]*#[ ]*include[ ]*"[^/]' ${DESTFILE} |
sed -e 's/^[ ]*#[ ]*include[ ]*"\([^"]*\)".*$/\1/'` sed -e 's/^[ ]*#[ ]*include[ ]*"\([^"]*\)".*$/\1/'`
do do
dir=`echo $file | sed -e s'|/[^/]*$||'` required="$required ${SRCDIR} $dir/$include ${ddir}/$include"
required="$required ${SRCDIR} $dir/$include ${DESTDIR}/$dir/$include"
done done
fi fi
done # for file in $files done # for file in $files
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