git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dmitry Ivankov <divanorama@gmail.com>
To: git@vger.kernel.org
Cc: Jonathan Nieder <jrnieder@gmail.com>,
	David Barr <davidbarr@google.com>,
	Ramkumar Ramachandra <artagnon@gmail.com>,
	Dmitry Ivankov <divanorama@gmail.com>
Subject: [PATCH v2 02/11] test-svn-fe: use parse-options
Date: Wed, 13 Jul 2011 18:21:04 +0600	[thread overview]
Message-ID: <1310559673-5026-3-git-send-email-divanorama@gmail.com> (raw)
In-Reply-To: <1310559673-5026-1-git-send-email-divanorama@gmail.com>

There was custom options parsing. As more options arise it will
be easier to add and document new options with parse-options api.

Signed-off-by: Dmitry Ivankov <divanorama@gmail.com>
---
 test-svn-fe.c |   42 ++++++++++++++++++++++++++++--------------
 1 files changed, 28 insertions(+), 14 deletions(-)

diff --git a/test-svn-fe.c b/test-svn-fe.c
index 332a5f7..0aab245 100644
--- a/test-svn-fe.c
+++ b/test-svn-fe.c
@@ -3,28 +3,38 @@
  */
 
 #include "git-compat-util.h"
+#include "parse-options.h"
 #include "vcs-svn/svndump.h"
 #include "vcs-svn/svndiff.h"
 #include "vcs-svn/sliding_window.h"
 #include "vcs-svn/line_buffer.h"
 
-static const char test_svnfe_usage[] =
-	"test-svn-fe (<dumpfile> | [-d] <preimage> <delta> <len>)";
+static const char * const test_svnfe_usage[] = {
+	"test-svn-fe (<dumpfile> | -d <preimage> <delta> <len>)",
+	NULL
+};
 
-static int apply_delta(int argc, char *argv[])
+static int d;
+
+static struct option test_svnfe_options[] = {
+	OPT_SET_INT('d', NULL, &d, "test apply_delta", 1),
+	OPT_END()
+};
+
+static int apply_delta(int argc, const char *argv[])
 {
 	struct line_buffer preimage = LINE_BUFFER_INIT;
 	struct line_buffer delta = LINE_BUFFER_INIT;
 	struct sliding_view preimage_view = SLIDING_VIEW_INIT(&preimage, -1);
 
-	if (argc != 5)
-		usage(test_svnfe_usage);
+	if (argc != 3)
+		usage_with_options(test_svnfe_usage, test_svnfe_options);
 
-	if (buffer_init(&preimage, argv[2]))
+	if (buffer_init(&preimage, argv[0]))
 		die_errno("cannot open preimage");
-	if (buffer_init(&delta, argv[3]))
+	if (buffer_init(&delta, argv[1]))
 		die_errno("cannot open delta");
-	if (svndiff0_apply(&delta, (off_t) strtoull(argv[4], NULL, 0),
+	if (svndiff0_apply(&delta, (off_t) strtoull(argv[2], NULL, 0),
 					&preimage_view, stdout))
 		return 1;
 	if (buffer_deinit(&preimage))
@@ -37,10 +47,16 @@ static int apply_delta(int argc, char *argv[])
 	return 0;
 }
 
-int main(int argc, char *argv[])
+int main(int argc, const char *argv[])
 {
-	if (argc == 2) {
-		if (svndump_init(argv[1]))
+	argc = parse_options(argc, argv, NULL, test_svnfe_options,
+						test_svnfe_usage, 0);
+
+	if (d)
+		return apply_delta(argc, argv);
+
+	if (argc == 1) {
+		if (svndump_init(argv[0]))
 			return 1;
 		svndump_read(NULL);
 		svndump_deinit();
@@ -48,7 +64,5 @@ int main(int argc, char *argv[])
 		return 0;
 	}
 
-	if (argc >= 2 && !strcmp(argv[1], "-d"))
-		return apply_delta(argc, argv);
-	usage(test_svnfe_usage);
+	usage_with_options(test_svnfe_usage, test_svnfe_options);
 }
-- 
1.7.3.4

  parent reply	other threads:[~2011-07-13 12:20 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-13 12:21 [PATCH v2 00/11] vcs-svn,svn-fe add a couple of options Dmitry Ivankov
2011-07-13 12:21 ` [PATCH v2 01/11] svn-fe: add man target to Makefile Dmitry Ivankov
2011-07-24 12:52   ` Jonathan Nieder
2011-07-13 12:21 ` Dmitry Ivankov [this message]
2011-07-24 13:04   ` [PATCH v2 02/11] test-svn-fe: use parse-options Jonathan Nieder
2011-07-13 12:21 ` [PATCH v2 03/11] svn-fe: add EXTLIBS needed for parse-options Dmitry Ivankov
2011-07-24 13:14   ` Jonathan Nieder
2011-07-13 12:21 ` [PATCH v2 04/11] svn-fe: add usage and unpositional arguments versions Dmitry Ivankov
2011-07-24 13:25   ` Jonathan Nieder
2011-07-13 12:21 ` [PATCH v2 05/11] vcs-svn: move url parameter from _read to _init Dmitry Ivankov
2011-07-24 13:40   ` Jonathan Nieder
2011-07-13 12:21 ` [PATCH v2 06/11] vcs-svn: move commit parameters logic to svndump.c Dmitry Ivankov
2011-07-24 13:58   ` Jonathan Nieder
2011-07-13 12:21 ` [PATCH v2 07/11] vcs-svn,svn-fe: allow to specify dump destination ref Dmitry Ivankov
2011-07-25  8:57   ` Jonathan Nieder
2011-07-13 12:21 ` [PATCH v2 08/11] vcs-svn,svn-fe: convert REPORT_FILENO to an option Dmitry Ivankov
2011-07-25 21:26   ` Jonathan Nieder
2011-07-13 12:21 ` [PATCH v2 09/11] vcs-svn,svn-fe: allow to disable 'progress' lines Dmitry Ivankov
2011-07-13 12:21 ` [PATCH v2 10/11] vcs-svn,svn-fe: add --incremental option Dmitry Ivankov
2011-07-25 21:35   ` Jonathan Nieder
2011-07-13 12:21 ` [PATCH v2 11/11] vcs-svn,svn-fe: add an option to write svnrev notes Dmitry Ivankov
2011-07-25 21:39   ` Jonathan Nieder
2011-07-28  6:03     ` Dmitry Ivankov
2011-07-28 10:27       ` Jonathan Nieder

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1310559673-5026-3-git-send-email-divanorama@gmail.com \
    --to=divanorama@gmail.com \
    --cc=artagnon@gmail.com \
    --cc=davidbarr@google.com \
    --cc=git@vger.kernel.org \
    --cc=jrnieder@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).