Module Name:    src
Committed By:   rillig
Date:           Sun Dec 10 17:45:35 UTC 2023

Modified Files:
        src/tests/usr.bin/indent: t_misc.sh
        src/usr.bin/indent: args.c

Log Message:
indent: be strict about options from profile files

Previously, the "option" 'xdi0' was treated the same as '-xdi0'.


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/tests/usr.bin/indent/t_misc.sh
cvs rdiff -u -r1.86 -r1.87 src/usr.bin/indent/args.c

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

Modified files:

Index: src/tests/usr.bin/indent/t_misc.sh
diff -u src/tests/usr.bin/indent/t_misc.sh:1.27 src/tests/usr.bin/indent/t_misc.sh:1.28
--- src/tests/usr.bin/indent/t_misc.sh:1.27	Mon Jun  5 10:12:21 2023
+++ src/tests/usr.bin/indent/t_misc.sh	Sun Dec 10 17:45:35 2023
@@ -1,5 +1,5 @@
 #! /bin/sh
-# $NetBSD: t_misc.sh,v 1.27 2023/06/05 10:12:21 rillig Exp $
+# $NetBSD: t_misc.sh,v 1.28 2023/12/10 17:45:35 rillig Exp $
 #
 # Copyright (c) 2021 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -88,12 +88,12 @@ verbose_profile_body()
 		profile: -fc1
 	EOF
 
-	# The code in args.c function set_profile suggests that options from
-	# profile files are echoed to stdout during startup. But since the
+	# The code in args.c function load_profile suggests that options from
+	# profile files are echoed to stderr during startup. But since the
 	# command line options are handled after the profile files, a '-v' in
 	# the command line has no effect. That's why '-bacc' is not listed
-	# in stdout, but '-fc1' is. The second round of '-bacc', '-v', '-fc1'
-	# is listed because when running ATF, $HOME equals $PWD.
+	# on stderr, but '-fc1' is. The second round of '-bacc', '-v', '-fc1'
+	# is listed because when running the test via ATF, $HOME equals $PWD.
 
 	atf_check \
 	    -e 'file:stderr.exp' \
@@ -205,15 +205,17 @@ option_P_in_profile_file_body()
 atf_test_case 'option_without_hyphen'
 option_without_hyphen_body()
 {
-	# TODO: Options in profile files should be required to start with
-	#  '-', just like in the command line arguments.
+	# Ensure that options in profile files start with '-', just like
+	# command line options.
 
 	printf ' -i3 xi5 +di0\n' > .indent.pro
 
 	printf '%s\n' 'int var[] = {' '1,' '}' > code.c
 	printf '%s\n' 'int var[] = {' '     1,' '}' > code.exp
 
-	atf_check -o 'file:code.exp' \
+	atf_check \
+	    -s 'exit:1' \
+	    -e "match:/.indent.pro: option \"xi5\" must start with '-'" \
 	    "$indent" < code.c
 }
 

Index: src/usr.bin/indent/args.c
diff -u src/usr.bin/indent/args.c:1.86 src/usr.bin/indent/args.c:1.87
--- src/usr.bin/indent/args.c:1.86	Sun Dec  3 21:44:42 2023
+++ src/usr.bin/indent/args.c	Sun Dec 10 17:45:35 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: args.c,v 1.86 2023/12/03 21:44:42 rillig Exp $	*/
+/*	$NetBSD: args.c,v 1.87 2023/12/10 17:45:35 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: args.c,v 1.86 2023/12/03 21:44:42 rillig Exp $");
+__RCSID("$NetBSD: args.c,v 1.87 2023/12/10 17:45:35 rillig Exp $");
 
 /* Read options from profile files and from the command line. */
 
@@ -293,8 +293,13 @@ load_profile(const char *fname, bool mus
 			buf[n] = '\0';
 			if (opt.verbose)
 				fprintf(stderr, "profile: %s\n", buf);
+			if (buf[0] != '-')
+				errx(1,
+				    "%s: option \"%s\" must start with '-'",
+				    fname, buf);
 			set_option(buf, fname);
-		} else if (ch == EOF)
+		}
+		if (ch == EOF)
 			break;
 	}
 	(void)fclose(f);

Reply via email to