Module Name:    src
Committed By:   joerg
Date:           Sat Feb 20 15:04:04 UTC 2010

Modified Files:
        src/tools/host-mkdep: host-mkdep.in

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


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/tools/host-mkdep/host-mkdep.in

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tools/host-mkdep/host-mkdep.in
diff -u src/tools/host-mkdep/host-mkdep.in:1.17 src/tools/host-mkdep/host-mkdep.in:1.18
--- src/tools/host-mkdep/host-mkdep.in:1.17	Mon Jul  9 15:27:10 2007
+++ src/tools/host-mkdep/host-mkdep.in	Sat Feb 20 15:04:03 2010
@@ -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]*\"?/, "")

Reply via email to