#! /bin/sh -e

# DP: Make gccbug POSIX compliant (patch by David Weinehall)
# DP: http://www.opengroup.org/onlinepubs/009695399/utilities/test.html

dir=
if [ $# -eq 3 -a "$2" = '-d' ]; then
    pdir="-d $3"
    dir="$3/"
elif [ $# -ne 1 ]; then
    echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
    exit 1
fi
case "$1" in
    -patch)
        patch $pdir -f --no-backup-if-mismatch -p0 < $0
        #cd ${dir}gcc && autoconf
        ;;
    -unpatch)
        patch $pdir -f --no-backup-if-mismatch -R -p0 < $0
        #rm ${dir}gcc/configure
        ;;
    *)
        echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
        exit 1
esac
exit 0

--- gcc/gccbug.in~	2004-06-15 04:43:16.000000000 +0200
+++ gcc/gccbug.in	2004-07-04 23:51:38.000000000 +0200
@@ -165,7 +165,7 @@
         ;;
     -f | --file) if [ $# -eq 1 ]; then echo "$USAGE"; $REMOVE_TEMP; exit 1; fi
 	shift ; IN_FILE="$1"
-	if [ "$IN_FILE" != "-" -a ! -r "$IN_FILE" ]; then
+	if [ "$IN_FILE" != "-" ] && [ ! -r "$IN_FILE" ]; then
 	  echo "$COMMAND: cannot read $IN_FILE"
 	  $REMOVE_TEMP
 	  exit 1
@@ -237,7 +237,7 @@
 # Catch some signals. ($xs kludge needed by Sun /bin/sh)
 xs=0
 trap '$REMOVE_TEMP; exit $xs' 0
-trap 'echo "$COMMAND: Aborting ..."; $REMOVE_TEMP; xs=1; exit' 1 3 13 15
+trap 'echo "$COMMAND: Aborting ..."; $REMOVE_TEMP; xs=1; exit' HUP QUIT PIPE TERM
 
 # If they told us to use a specific file, then do so.
 if [ -n "$IN_FILE" ]; then
@@ -258,16 +258,16 @@
   fi
 else
 
-  if [ -n "$PR_FORM" -a -z "$PRINT_INTERN" ]; then
+  if [ -n "$PR_FORM" ] && [ -z "$PRINT_INTERN" ]; then
     # If their PR_FORM points to a bogus entry, then bail.
-    if [ ! -f "$PR_FORM" -o ! -r "$PR_FORM" -o ! -s "$PR_FORM" ]; then
+    if [ ! -f "$PR_FORM" ] || [ ! -r "$PR_FORM" ] || [ ! -s "$PR_FORM" ]; then
       echo "$COMMAND: can't seem to read your template file (\`$PR_FORM'), ignoring PR_FORM"
       sleep 1
       PRINT_INTERN=bad_prform
     fi
   fi
 
-  if [ -n "$PR_FORM" -a -z "$PRINT_INTERN" ]; then
+  if [ -n "$PR_FORM" ] && [ -z "$PRINT_INTERN" ]; then
     cp $PR_FORM $TEMP || 
       ( echo "$COMMAND: could not copy $PR_FORM" ; xs=1; exit )
   else
@@ -359,7 +359,7 @@
     done
   fi
 
-  if [ "$PRINT" = true -o "$PRINT_INTERN" = true ]; then
+  if [ "$PRINT" = true ] || [ "$PRINT_INTERN" = true ]; then
     cat $TEMP
     xs=0; exit
   fi
@@ -467,7 +467,7 @@
     CNT=`expr $CNT + 1`
   fi
 
-  [ $CNT -lt 6 -a -z "$BATCH" ] && 
+  [ $CNT -lt 6 ] && [ -z "$BATCH" ] && 
     echo "Errors were found with the problem report."
 
   while true; do
