Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tools/host-mkdep Rewrite argument processing to deal with sp...



details:   https://anonhg.NetBSD.org/src/rev/448bdd7e16a0
branches:  trunk
changeset: 752237:448bdd7e16a0
user:      joerg <joerg%NetBSD.org@localhost>
date:      Sat Feb 20 15:04:03 2010 +0000

description:
Rewrite argument processing to deal with spaces and other meta
characters in options. This was exposed by the "NetBSD 5.99" argument of
mandoc.

diffstat:

 tools/host-mkdep/host-mkdep.in |  37 +++++++++++++++++++++++++++++--------
 1 files changed, 29 insertions(+), 8 deletions(-)

diffs (98 lines):

diff -r 06ab83be34e6 -r 448bdd7e16a0 tools/host-mkdep/host-mkdep.in
--- a/tools/host-mkdep/host-mkdep.in    Sat Feb 20 14:52:22 2010 +0000
+++ b/tools/host-mkdep/host-mkdep.in    Sat Feb 20 15:04:03 2010 +0000
@@ -1,6 +1,6 @@
 #!@BSHELL@ -
 #
-#      $NetBSD: host-mkdep.in,v 1.17 2007/07/09 15:27:10 jmmv Exp $
+#      $NetBSD: host-mkdep.in,v 1.18 2010/02/20 15:04:03 joerg Exp $
 #
 # Copyright (c) 1991, 1993
 #      The Regents of the University of California.  All rights reserved.
@@ -117,43 +117,63 @@
 if $MERGE; then
        SRCS="$*"
 else
-       while [ $# -gt 0 ]; do
+       #
+       # Process argument list.
+       # This is tricky, because arguments may contain spaces and other
+       # escapes characters.  The argument list is used like a tail queue.
+       # $cppargs has one x for each unprocessed argument, so when an
+       # argument is processed, it is shifted and the corresponding number
+       # of x's is removed.  The advantage to counting is that suffix removal
+       # works without fork.
+       #
+       cppargs=
+       for arg; do
+               cppargs="x$cppargs"
+       done
+       while [ -n "$cppargs" ]; do
                case "$1" in
                -L)                     # takes an arg, but ignored
                                shift 2
+                               cppargs=${cppargs%xx}
                                ;;
 
                -c|-[lLMOW]*)           # takes no extra args
                                shift
+                               cppargs=${cppargs%x}
                                ;;
 
                -[IDU]*)
-                               CPPFLAGS="$CPPFLAGS $1"
+                               set -- "$@" "$1"
                                shift
+                               cppargs=${cppargs%x}
                                ;;
 
                -[IDU]|-include|-isystem)
-                               CPPFLAGS="$CPPFLAGS $1 $2"
+                               set -- "$@" "$1" "$2"
                                shift 2
+                               cppargs=${cppargs%xx}
                                ;;
                                
                -isystem-cxx|-cxx-isystem)
-                               CPPFLAGS="$CPPFLAGS -isystem $2"
+                               set -- "$@" "-isystem" "$2"
                                shift 2
+                               cppargs=${cppargs%xx}
                                ;;
 
                -no-cpp-precomp)        # This is a Darwin-specific option.
-                               CPPFLAGS="$CPPFLAGS $1"
+                               set -- "$@" "$1"
                                shift
+                               cppargs=${cppargs%x}
                                ;;
 
                -nostdinc*)     # This is a gcc/g++ ism; ignore if not gcc/g++
                                case "@CFLAGS@" in
                                *-O2*)  # Autoconf puts -O2 when gcc only
-                                       CPPFLAGS="$CPPFLAGS $1"
+                                       set -- "$@" "$1"
                                        ;;
                                esac    
                                shift
+                               cppargs=${cppargs%x}
                                ;;
 
                -*)             
@@ -164,6 +184,7 @@
                *)      
                                SRCS="$SRCS $1" # source file
                                shift
+                               cppargs=${cppargs%x}
                                ;;
                esac
        done
@@ -202,7 +223,7 @@
                file=${file%.*}
                set_objlist $file
 
-               @CPP@ $CPPFLAGS $f | @AWK@ '
+               @CPP@ "$@" $f | @AWK@ '
                        /^#/ {
                                # Be as tolerant as possible.
                                sub(/^#(line)? [ 0-9]*\"?/, "")



Home | Main Index | Thread Index | Old Index