Subject: will this change for MAKEDEV.awk cause portability issue?
To: None <tech-toolchain@netbsd.org>
From: enami tsugutomo <enami@but-b.or.jp>
List: tech-toolchain
Date: 03/17/2004 08:17:32
Are there any portability issue if following patch is commited?  As I
sometimes invoke postinstall by hand, I want MAKEDEV creation to be
fast.

enami.

Index: MAKEDEV.awk
===================================================================
RCS file: /cvsroot/src/etc/MAKEDEV.awk,v
retrieving revision 1.13
diff -u -r1.13 MAKEDEV.awk
--- MAKEDEV.awk	16 Mar 2004 23:08:10 -0000	1.13
+++ MAKEDEV.awk	16 Mar 2004 23:08:40 -0000
@@ -261,14 +261,30 @@
 	sub(/%DISKMINOROFFSET%/, DISKMINOROFFSET)
 	sub(/%RAWDISK_OFF%/, RAWDISK_OFF)
 	sub(/%RAWDISK_NAME%/, RAWDISK_NAME)
-	for (u in uid)
-		gsub("%uid_" u "%", uid[u])
-	for (g in gid)
-		gsub("%gid_" g "%", gid[g])
-	if ($0 ~ /%[gu]id_[a-z]*%/) {
-		print "ERROR unmatched gid or uid in `" $0 "'"> "/dev/stderr"
-		exit 1
+	parsed = ""
+	line = $0
+	while (match(line, /%[gu]id_[a-z]*%/)) {
+		typ = substr(line, RSTART + 1, 3);
+		nam = substr(line, RSTART + 5, RLENGTH - 6);
+		if (typ == "uid") {
+			if (!(nam in uid)) {
+				print "ERROR unmatched uid in `" $0 "'" > \
+				    "/dev/stderr"
+				exit 1
+			} else
+				id = uid[nam];
+		} else {
+			if (!(nam in gid)) {
+				print "ERROR unmatched gid in `" $0 "'" > \
+				    "/dev/stderr"
+				exit 1
+			} else
+				id = gid[nam];
+		}
+		parsed = parsed substr(line, 0, RSTART - 1) id
+		line = substr(line, RSTART + RLENGTH)
 	}
+	$0 = parsed line
 
 	# if device substitutions are not active, do nothing more
 	if (!devsubst) {
@@ -284,13 +300,28 @@
 		# character and block devices. If no unknown character
 		# or block device definition remains within the entry,
 		# print it to output, otherwise scrap it.
-		for (c in chr)
-			gsub("%" c "_chr%", chr[c], deventry)
-		for (b in blk)
-			gsub("%" b "_blk%", blk[b], deventry)
+		parsed = ""
+		while (match(deventry, /%[a-z]*_(blk|chr)%/)) {
+			nam = substr(deventry, RSTART + 1, RLENGTH - 6);
+			typ = substr(deventry, RSTART + RLENGTH - 4, 3);
+			if (typ == "blk") {
+				if (!(nam in blk)) {
+					deventry = $0
+					next
+				} else
+					dev = blk[nam];
+			} else {
+				if (!(nam in chr)) {
+					deventry = $0
+					next
+				} else
+					dev = chr[nam];
+			}
+			parsed = parsed substr(deventry, 0, RSTART - 1) dev
+			deventry = substr(deventry, RSTART + RLENGTH)
+		}
 
-		if (deventry !~ /%[a-z]*_(chr|blk)%/)
-			print deventry
+		print parsed deventry
 	}
 	deventry = $0
 	next