From 44069c7b69a9cef0725ed8900cec1546f55cae09 Mon Sep 17 00:00:00 2001
From: Joerg Wunsch <j@uriah.heep.sax.de>
Date: Sun, 8 Sep 2013 19:31:48 +0000
Subject: [PATCH] Implement and document the "verbose" terminal mode command.

git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1211 81a1dc3b-b13d-400b-aceb-764788c761c2
---
 ChangeLog        |  6 ++++++
 NEWS             |  3 +++
 avrdude.1        | 12 +++++++++++-
 doc/avrdude.texi |  7 +++++++
 term.c           | 35 +++++++++++++++++++++++++++++++++++
 5 files changed, 62 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index cf6d8158..fbd0c810 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2013-09-08  Joerg Wunsch <j.gnu@uriah.heep.sax.de>
+
+	* term.c: Implement the "verbose" terminal mode command.
+	* avrdude.1: Document this.
+	* doc/avrdude.texi: (Dito.)
+
 2013-09-07  Joerg Wunsch <j.gnu@uriah.heep.sax.de>
 
 	* jtag3.c (jtag3_write_byte): Do not attempt to start the paged
diff --git a/NEWS b/NEWS
index c292315f..88e1e2e4 100644
--- a/NEWS
+++ b/NEWS
@@ -163,6 +163,9 @@ Current:
   * The USBasp programmer implementation now supports detailed traces
     with -vvv, and device communication traces with -vvvv.
 
+  * The "verbose" terminal mode command allows to query or modify the
+    verbosity level.
+
   * Internals:
 
     - Restructuring and compacting programmer definition part of
diff --git a/avrdude.1 b/avrdude.1
index 9a531fbc..f36b5d45 100644
--- a/avrdude.1
+++ b/avrdude.1
@@ -18,7 +18,7 @@
 .\"
 .\" $Id$
 .\"
-.Dd DATE September 3, 2013
+.Dd DATE September 8, 2013
 .Os
 .Dt AVRDUDE 1
 .Sh NAME
@@ -662,6 +662,9 @@ This will only work if
 does not have a colon in it.
 .It Fl v
 Enable verbose output.
+More
+.Fl v
+options increase verbosity level.
 .It Fl V
 Disable automatic verify check when uploading data.
 .It Fl x Ar extended_param
@@ -777,6 +780,13 @@ Display the current voltage and master oscillator parameters.
 .Pp
 .Em JTAG ICE only:
 Display the current target supply voltage and JTAG bit clock rate/period.
+.It Ar verbose Op Ar level
+Change (when
+.Ar level
+is provided), or display the verbosity level.
+The initial verbosity level is controlled by the number of
+.Fl v
+options given on the commandline.
 .It Ar \&?
 .It Ar help
 Give a short on-line summary of the available commands.
diff --git a/doc/avrdude.texi b/doc/avrdude.texi
index a8c16d71..726dfefe 100644
--- a/doc/avrdude.texi
+++ b/doc/avrdude.texi
@@ -699,6 +699,7 @@ This will only work if @var{filename} does not have a colon in it.
 
 @item -v
 Enable verbose output.
+More @code{-v} options increase verbosity level.
 
 @item -V
 Disable automatic verify check when uploading data.
@@ -1116,6 +1117,12 @@ device, read/write timing, etc.
 @item pgm
 Return to programming mode (from direct SPI mode).
 
+@item verbose [@var{level}]
+Change (when @var{level} is provided), or display the verbosity
+level.
+The initial verbosity level is controlled by the number of @code{-v} options
+given on the commandline.
+
 @item ?
 @itemx help
 Give a short on-line summary of the available commands.
diff --git a/term.c b/term.c
index fef870d1..2f4c8da2 100644
--- a/term.c
+++ b/term.c
@@ -93,6 +93,9 @@ static int cmd_spi   (PROGRAMMER * pgm, struct avrpart * p,
 static int cmd_pgm   (PROGRAMMER * pgm, struct avrpart * p,
 		      int argc, char *argv[]);
 
+static int cmd_verbose (PROGRAMMER * pgm, struct avrpart * p,
+		      int argc, char *argv[]);
+
 struct command cmd[] = {
   { "dump",  cmd_dump,  "dump memory  : %s <memtype> <addr> <N-Bytes>" },
   { "read",  cmd_dump,  "alias for dump" },
@@ -108,6 +111,7 @@ struct command cmd[] = {
   { "sck",   cmd_sck,   "set <SCK period> (STK500 only)" },
   { "spi",   cmd_spi,   "enter direct SPI mode" },
   { "pgm",   cmd_pgm,   "return to programming mode" },
+  { "verbose", cmd_verbose, "change verbosity" },
   { "help",  cmd_help,  "help" },
   { "?",     cmd_help,  "help" },
   { "quit",  cmd_quit,  "quit" }
@@ -759,6 +763,37 @@ static int cmd_pgm(PROGRAMMER * pgm, struct avrpart * p,
   return 0;
 }
 
+static int cmd_verbose(PROGRAMMER * pgm, struct avrpart * p,
+		       int argc, char * argv[])
+{
+  int nverb;
+  char *endp;
+
+  if (argc != 1 && argc != 2) {
+    fprintf(stderr, "Usage: verbose [<value>]\n");
+    return -1;
+  }
+  if (argc == 1) {
+    fprintf(stderr, "Verbosity level: %d\n", verbose);
+    return 0;
+  }
+  nverb = strtol(argv[1], &endp, 0);
+  if (endp == argv[2]) {
+    fprintf(stderr, "%s: can't parse verbosity level \"%s\"\n",
+	    progname, argv[2]);
+    return -1;
+  }
+  if (nverb < 0) {
+    fprintf(stderr, "%s: verbosity level must be positive: %d\n",
+	    progname, nverb);
+    return -1;
+  }
+  verbose = nverb;
+  fprintf(stderr, "New verbosity level: %d\n", verbose);
+
+  return 0;
+}
+
 static int tokenize(char * s, char *** argv)
 {
   int     i, n, l, nargs, offset;