changeset 37:8256eec598dd

mpffs-cat: more sensible handling of -v
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sun, 30 Jun 2013 17:56:27 +0000
parents 390be89892c4
children e9c6d6615f32
files mpffs/cat.c
diffstat 1 files changed, 9 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/mpffs/cat.c	Sun Jun 30 17:24:21 2013 +0000
+++ b/mpffs/cat.c	Sun Jun 30 17:56:27 2013 +0000
@@ -15,6 +15,8 @@
 extern char *imgfile;
 extern int verbose;
 
+int cat_v;
+
 cat_chunk(chi)
 	struct chunkinfo *chi;
 {
@@ -26,7 +28,7 @@
 	len = chi->len;
 	while (len) {
 		c = *dp++;
-		if (!verbose || c >= ' ' && c <= '~' || c == '\n')
+		if (!cat_v || c >= ' ' && c <= '~' || c == '\n')
 			putchar(c);
 		else {
 			if (c & 0x80) {
@@ -59,8 +61,6 @@
 	}
 	validate_chunk(&obj);
 	size_head_chunk(&obj, &chi);
-	if (verbose)
-		printf("\n--- file content:\n");
 	cat_chunk(&chi);
 	for (ent = obj.descend; ent != 0xFFFF; ent = obj.descend) {
 		obj.entryno = ent;
@@ -75,8 +75,8 @@
 		size_extra_chunk(&obj, &chi);
 		cat_chunk(&chi);
 	}
-	if (verbose)
-		printf("\n-- end quote --\n");
+	if (cat_v)
+		putchar('\n');
 }
 
 usage()
@@ -94,6 +94,10 @@
 	parse_cmdline_options(argc, argv);
 	if (argc - optind != 2)
 		usage();
+	if (verbose) {
+		cat_v = 1;
+		verbose--;
+	}
 	imgfile = argv[optind];
 	preliminaries();
 	idx = find_pathname(argv[optind+1]);