Commits

Michał Górny  committed 0b63f74

Add '--quiet' option. Now default behavior is to output only progress.
'--quiet' disables that too, '--verbose' adds version & open-messages.

  • Participants
  • Parent commits 7cc6645

Comments (0)

Files changed (2)

File mirage-wrapper.c

 
 #include <mirage.h>
 
-extern bool verbose;
+extern bool quiet;
 
 static MIRAGE_Mirage *mirage = NULL;
 static MIRAGE_Disc *disc = NULL;
 		return false;
 
 	gint i, olen;
-	const int vlen = verbose ? snprintf(NULL, 0, "%d", len) : 0; /* printf() accepts <= 0 */
+	const int vlen = quiet ? 0 : snprintf(NULL, 0, "%d", len); /* printf() accepts <= 0 */
 
 	FILE *f;
 	guint8 *buf;
 
 	len--; /* well, now it's rather 'last' */
 	for (i = sstart; i <= len; i++) {
-		if (verbose && !(i % 64))
+		if (!quiet && !(i % 64))
 			fprintf(stderr, "\rTrack: %2d, sector: %*d of %d (%3d%%)", track_num, vlen, i, len, 100 * i / len);
 
 		if (!mirage_track_read_sector(track, i, FALSE, MIRAGE_MCSB_DATA, 0, buf, &olen, &err)) {
 			g_object_unref(track);
 			if (!use_mmap)
 				free(buf);
-			return miragewrap_err("%sUnable to read sector %d", verbose ? "\n" : "", i);
+			return miragewrap_err("%sUnable to read sector %d", quiet ? "" : "\n", i);
 		}
 
 		if (olen != bufsize) {
 			fprintf(stderr, "%sData read returned %d bytes while %d was expected\n",
-					verbose ? "\n" : "", olen, bufsize);
+					quiet ? "" : "\n", olen, bufsize);
 			g_object_unref(track);
 			if (!use_mmap)
 				free(buf);
 
 		if (!use_mmap) {
 			if (fwrite(buf, olen, 1, f) != 1) {
-				fprintf(stderr, "%sWrite failed on sector %d%s", verbose ? "\n" : "", i,
+				fprintf(stderr, "%sWrite failed on sector %d%s", quiet ? "" : "\n", i,
 						ferror(f) ? ": " : " but error flag not set\n");
 				if (ferror(f))
 					perror(NULL);
 		} else
 			buf += olen;
 	}
-	if (verbose)
+	if (!quiet)
 		fprintf(stderr, "\rTrack: %2d, sector: %d of %d (100%%)\n", track_num, len, len);
 
 	g_object_unref(track);

File mirage2iso.c

 
 #include "mirage-wrapper.h"
 
-bool verbose = false;
+bool quiet = false;
+static bool verbose = false;
 
 #ifndef NO_MMAPIO
 static bool force_stdio = false;
 static const char* const VERSION = "0.0.1_pre";
 
 static const struct option opts[] = {
-	{ "stdout", no_argument, 0, 'c' },
 	{ "force", no_argument, 0, 'f' },
 	{ "help", no_argument, 0, '?' },
+	{ "quiet", no_argument, 0, 'q' },
 	{ "session", required_argument, 0, 's' },
 	{ "stdio", no_argument, 0, 'S' },
+	{ "stdout", no_argument, 0, 'c' },
 	{ "verbose", no_argument, 0, 'v' },
 	{ "version", no_argument, 0, 'V' },
 	{ 0, 0, 0, 0 }
 		"\nOptions:\n"
 		"\t--force, -f\t\tForce replacing guessed output file\n"
 		"\t--help, -?\t\tGuess what\n"
+		"\t--quiet, -q\t\tDisable progress reporting, output only errors\n"
 		"\t--session %%d, -s %%d\tSession to use (default: last one)\n"
 #ifndef NO_MMAPIO
 		"\t--stdio, -S\t\tForce using stdio instead of mmap()\n"
 #endif
 		"\t--stdout, -c\t\tOutput image into STDOUT instead of a file\n"
-		"\t--verbose, -v\t\tReport progress verbosely\n"
+		"\t--verbose, -v\t\tIncrease progress reporting verbosity\n"
 		"\t--version, -V\t\tPrint version number and quit\n"
 		"\n";
 
 
 	int arg;
 
-	while ((arg = getopt_long(argc, argv, "cfs:SvV?", opts, NULL)) != -1) {
+	while ((arg = getopt_long(argc, argv, "cfqs:SvV?", opts, NULL)) != -1) {
 		switch (arg) {
 			case 'c':
 				use_stdout = true;
 			case 'f':
 				force = true;
 				break;
+			case 'q':
+				quiet = true;
+				break;
 			case 's':
 				if (!try_atoi(optarg, &session_num))
 					fprintf(stderr, "--session requires integer argument which '%s' isn't\n", optarg);
 		}
 	}
 
+	if (quiet && verbose) {
+		fprintf(stderr, "--verbose and --quiet are contrary options, --verbose will have precedence\n");
+		quiet = false;
+	}
+
 	if (use_stdout) {
 #ifndef NO_MMAPIO
 		if (force_stdio)