Add verbose and dry-run options to ziptorrent.

--HG--
branch : HEAD
diff --git a/TODO b/TODO
index 25a971f..cbf5d08 100644
--- a/TODO
+++ b/TODO
@@ -1,4 +1,3 @@
-! [bug] ziptorrent not changving archive on Solaris
 ! [doc] document that no empty archives will be created
 ! [test] ziptorrent support
 + [portability] no off_t in API
diff --git a/man/ziptorrent.mdoc b/man/ziptorrent.mdoc
index 71d1e1a..5134488 100644
--- a/man/ziptorrent.mdoc
+++ b/man/ziptorrent.mdoc
@@ -29,7 +29,7 @@
 .\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
 .\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd June 4, 2008
+.Dd July 24, 2008
 .Dt ZIPTORRENT 1
 .Os
 .Sh NAME
@@ -37,7 +37,7 @@
 .Nd torrentzip zip archives
 .Sh SYNOPSIS
 .Nm
-.Op Fl hV
+.Op Fl hVvn
 .Ar archive Op Ar ...
 .Sh DESCRIPTION
 .Nm
@@ -53,6 +53,11 @@
 .Bl -tag -width MMM
 .It Fl h
 Display a short help message and exit.
+.It Fl n
+Don't actually change archives, just print what would be done.
+.It Fl v
+Be verbose: print which archives are already torrentzipped and which
+need to be rezipped.
 .It Fl V
 Display version information and exit.
 .El
diff --git a/src/ziptorrent.c b/src/ziptorrent.c
index 0ca7197..d0becdd 100644
--- a/src/ziptorrent.c
+++ b/src/ziptorrent.c
@@ -45,17 +45,22 @@
 
 
 
+#define FLAG_DRYRUN	1
+#define FLAG_VERBOSE	2
+
 const char *prg;
 
 #define PROGRAM	"ziptorrent"
 
-char *usage = "usage: %s [-hV] zip [...]\n";
+char *usage = "usage: %s [-hVnv] zip [...]\n";
 
 char help_head[] =
     PROGRAM " (" PACKAGE ") by Dieter Baron and Thomas Klausner\n\n";
 
 char help[] = "\n\
   -h       display this help message\n\
+  -n       don't actually change archives, just print what would be done\n\
+  -v       verbose\n\
   -V       display version number\n\
 \n\
 Report bugs to <libzip@nih.at>.\n";
@@ -64,9 +69,9 @@
 Copyright (C) 2008 Dieter Baron and Thomas Klausner\n\
 " PACKAGE " comes with ABSOLUTELY NO WARRANTY, to the extent permitted by law.\n";
 
-#define OPTIONS "hV"
+#define OPTIONS "hnVv"
 
-static int torrentzip(const char *);
+static int torrentzip(const char *, int);
 
 
 
@@ -75,8 +80,10 @@
 {
     int err;
     int c;
+    int flags;
 
     prg = argv[0];
+    flags = 0;
 
     while ((c=getopt(argc, argv, OPTIONS)) != -1) {
 	switch (c) {
@@ -85,9 +92,15 @@
 	    printf(usage, prg);
 	    fputs(help, stdout);
 	    exit(0);
+	case 'n':
+	    flags |= FLAG_DRYRUN|FLAG_VERBOSE;
+	    break;
 	case 'V':
 	    fputs(version_string, stdout);
 	    exit(0);
+	case 'v':
+	    flags |= FLAG_VERBOSE;
+	    break;
 
 	default:
 	    fprintf(stderr, usage, prg);
@@ -102,7 +115,7 @@
 
     err = 0;
     while (optind < argc) {
-	err |= torrentzip(argv[optind++]);
+	err |= torrentzip(argv[optind++], flags);
     }
 
     return (err ? 1 : 0);
@@ -111,7 +124,7 @@
 
 
 static int
-torrentzip(const char *fname)
+torrentzip(const char *fname, int flags)
 {
     struct zip *za;
     int err;
@@ -124,11 +137,20 @@
 	return -1;
     }
 
-    if (zip_set_archive_flag(za, ZIP_AFL_TORRENT, 1) < 0) {
-	fprintf(stderr,	"%s: cannot set torrentzip flag in `%s': %s\n",
-		prg, fname, zip_strerror(za));
-	zip_close(za);
-	return -1;
+    if (flags & FLAG_VERBOSE) {
+	if (zip_get_archive_flag(za, ZIP_AFL_TORRENT, 0))
+	    printf("%s: already torrentzipped\n", fname);
+	else
+	    printf("%s: torrentzipping\n", fname);
+    }
+
+    if ((flags & FLAG_DRYRUN) == 0) {
+        if (zip_set_archive_flag(za, ZIP_AFL_TORRENT, 1) < 0) {
+	    fprintf(stderr,	"%s: cannot set torrentzip flag in `%s': %s\n",
+		    prg, fname, zip_strerror(za));
+	    zip_close(za);
+	    return -1;
+        }
     }
 
     if (zip_close(za) < 0) {