Index: tools/config.py
===================================================================
--- tools/config.py	(revision 536ab4fe5a15437f22646a0836af7075f234934d)
+++ tools/config.py	(revision 9675296fe33ff287a6d2d86321c97dbd34619703)
@@ -42,5 +42,9 @@
 import random
 
-RULES_FILE = sys.argv[1]
+ARGPOS_RULES = 1
+ARGPOS_CHOICE = 2
+ARGPOS_PRESET = 3
+
+RULES_FILE = sys.argv[ARGPOS_RULES]
 MAKEFILE = 'Makefile.config'
 MACROS = 'config.h'
@@ -676,8 +680,18 @@
 	parse_rules(RULES_FILE, rules)
 
+	if len(sys.argv) > ARGPOS_CHOICE:
+		choice = sys.argv[ARGPOS_CHOICE]
+	else:
+		choice = None
+
+	if len(sys.argv) > ARGPOS_PRESET:
+		preset = sys.argv[ARGPOS_PRESET]
+	else:
+		preset = None
+
 	# Input configuration file can be specified on command line
 	# otherwise configuration from previous run is used.
-	if len(sys.argv) >= 4:
-		profile = parse_profile_name(sys.argv[3])
+	if preset is not None:
+		profile = parse_profile_name(preset)
 		read_presets(profile, config)
 	elif os.path.exists(MAKEFILE):
@@ -685,5 +699,5 @@
 
 	# Default mode: check values and regenerate configuration files
-	if (len(sys.argv) >= 3) and (sys.argv[2] == 'default'):
+	if choice == 'default':
 		if (infer_verify_choices(config, rules)):
 			preprocess_config(config, rules)
@@ -693,8 +707,8 @@
 	# Hands-off mode: check values and regenerate configuration files,
 	# but no interactive fallback
-	if (len(sys.argv) >= 3) and (sys.argv[2] == 'hands-off'):
-		# We deliberately test sys.argv >= 4 because we do not want
+	if choice == 'hands-off':
+		# We deliberately test this because we do not want
 		# to read implicitly any possible previous run configuration
-		if len(sys.argv) < 4:
+		if preset is None:
 			sys.stderr.write("Configuration error: No presets specified\n")
 			return 2
@@ -709,5 +723,5 @@
 
 	# Check mode: only check configuration
-	if (len(sys.argv) >= 3) and (sys.argv[2] == 'check'):
+	if choice == 'check':
 		if infer_verify_choices(config, rules):
 			return 0
@@ -715,5 +729,5 @@
 
 	# Random mode
-	if (len(sys.argv) == 3) and (sys.argv[2] == 'random'):
+	if choice == 'random':
 		ok = random_choices(config, rules, 0)
 		if not ok:
