changeset 269:0a2be000bf66

Arguments were not checked properly, this caused a segfault if certain parameters were not provided in a certain mode of operation. Fixed!
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 07 Jun 2007 04:18:32 +0000
parents 651b9bafd198
children f467243ca315
files mkloc.c
diffstat 1 files changed, 23 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/mkloc.c	Tue Jun 05 11:59:25 2007 +0000
+++ b/mkloc.c	Thu Jun 07 04:18:32 2007 +0000
@@ -865,8 +865,20 @@
 	th_args_process(argc, argv, optList, optListN,
 		argHandleOpt, NULL, FALSE);
 	
-	if ((srcFile == NULL && optGetUpdateLoc) || (locFile == NULL && !optGetUpdateLoc)) {
-		THERR("Nothing to do. (try --help)\n");
+	/* Check the mode and arguments */
+	if (srcFile == NULL && optGetUpdateLoc && optOutput == OUTFMT_LOCFILE) {
+		THERR("Map file required for location update mode!\n");
+		exit(0);
+	}
+	
+		
+	if (optOutput == OUTFMT_LOCFILE && locFile == NULL && !optGetUpdateLoc) {
+		THERR("Location file or location update mode required for location file output!\n");
+		exit(0);
+	}
+	
+	if (srcFile == NULL && optOutput == OUTFMT_MAP) {
+		THERR("Mapfile required for map generation.\n");
 		exit(0);
 	}
 	
@@ -919,15 +931,19 @@
 	}
 
 	/* Output results */
-	if (optOutput == OUTFMT_SCRIPT) {
+	switch (optOutput) {
+	case OUTFMT_SCRIPT:
 		THMSG(1, "Generating ImageMagick script ...\n");
 		outputLocationScript(outFile, &worldLoc);
-	} else
-	if (optOutput == OUTFMT_LOCFILE) {
+		break;
+
+	case OUTFMT_LOCFILE:
 		THMSG(1, "Outputting generated location list ...\n");
 		outputLocationFile(outFile, &worldLoc);
 		THMSG(2, "%d locations\n", worldLoc.numLocations);
-	} else {
+		break;
+	
+	case OUTFMT_MAP:
 		THMSG(1, "Outputting generated map of (%d x %d) ...\n",
 			worldMap->w, worldMap->h);
 
@@ -935,6 +951,7 @@
 		adjustLocInfoCoords(worldMap, &worldLoc);
 		
 		outputMapCTRL(outFile, worldMap, &worldLoc);
+		break;
 	}
 	
 	fclose(outFile);