shithub: rgbds

Download patch

ref: bdc6401ebae00ab1f063a5ecb07512b678efe5ec
parent: 21d0b402d3c895056721d12b259edfe1d985d353
author: Anthony J. Bentley <[email protected]>
date: Wed Jan 7 18:07:09 EST 2015

rgbfix: deal with options and arguments in the right order.

--- a/src/fix/main.c
+++ b/src/fix/main.c
@@ -41,17 +41,6 @@
 	char *ep;
 
 	/*
-	 * Open the ROM file
-	 */
-
-	if (argc < 2)
-		usage();
-
-	if ((rom = fopen(argv[argc - 1], "rb+")) == NULL) {
-		err(1, "Error opening file %s", argv[argc - 1]);
-	}
-
-	/*
 	 * Parse command-line options
 	 */
 
@@ -195,6 +184,20 @@
 			usage();
 			/* NOTREACHED */
 		}
+	}
+
+	argc -= optind;
+	argv += optind;
+
+	if (argc == 0)
+		usage();
+
+	/*
+	 * Open the ROM file
+	 */
+
+	if ((rom = fopen(argv[argc - 1], "rb+")) == NULL) {
+		err(1, "Error opening file %s", argv[argc - 1]);
 	}
 
 	/*