faubackup2/src Makefile.am,1.12,1.13 main.cpp,1.11,1.12

Martin Waitz <[email protected]> Fri, 10 Jun 2005 14:55:56 +0000
Newsgroups gmane.comp.sysutils.backup.faubackup.cvs
Message-ID <[email protected]>
Update of /cvsroot/faubackup/faubackup2/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29575/src

Modified Files:
	Makefile.am main.cpp 
Log Message:
use argp argument parser

Index: main.cpp
===================================================================
RCS file: /cvsroot/faubackup/faubackup2/src/main.cpp,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** main.cpp	9 Jun 2005 15:39:53 -0000	1.11
--- main.cpp	10 Jun 2005 14:55:53 -0000	1.12
***************
*** 2,6 ****
  
  #include <string>
! #include <popt.h>
  
  #include "common/backup_control.hpp"
--- 2,6 ----
  
  #include <string>
! #include <argp.h>
  
  #include "common/backup_control.hpp"
***************
*** 36,46 ****
  using namespace faubackup;
  
! int main(int argc, const char **argv)
  {
  	setIntHandler();
- 	poptContext popt;
- 	int rc;
- 	char *server_destdir = NULL;
- 	char *client_sourcedir = NULL;
  
  	/* initialize gettext */
--- 36,142 ----
  using namespace faubackup;
  
! static cmdline_data source;
! static cmdline_data destination;
! static char * server_destdir = NULL;
! static char * client_sourcedir = NULL;
! 
! const char OPT_CLIENT = 1;
! const char OPT_SERVER = 2;
! 
! 
! /* documenting ourself */
! const char * argp_program_version = PACKAGE_STRING;
! const char * argp_program_bug_address = PACKAGE_BUGREPORT;
! 
! static const char doc[] =
! 	N_("FauBackup -- backup system using a filesystem for storage"
! 	   "\v"
! 	   "FauBackup uses a filesystem on a hard drive for incremental "
! 	   "and full backups. This enables the backup to be accessable "
! 	   "through standard filesystem tools.");
! 
! static const char args_doc[] =
! 	N_("[host:]srcdir [host:]destdir");
! 
! static const struct argp_option options[] = {
! 	{ "verbose", 'v', 0, 0,
! 		N_("produce verbose output") },
! 	{ "rsync", 'r', 0, 0,
! 		N_("Use Rsync to transfer changed files")},
! 	{ "one-file-system", 'x', 0, 0,
! 		N_("don't cross filesystem boundaries")},
! 	{ "dry-run", 'n', 0, 0,
! 		N_("don't create a new backup, test only")},
! 	{ "client", OPT_CLIENT, 0, OPTION_HIDDEN },
! 	{ "server", OPT_SERVER, 0, OPTION_HIDDEN },
! 	{ 0 }
! };
! 
! /* parse options and arguments */
! static error_t
! parse_opt(int key, char * arg, struct argp_state * state)
! {
! 	switch (key) {
! 	case 'v':
! 		verbose++;
! 		break;
! 	case 'r':
! 		rsync = 1;
! 		break;
! 	case 'x':
! 		boundaries = 1;
! 		break;
! 	case 'n':
! 		do_nothing = 1;
! 		break;
! 	case OPT_SERVER:
! 		server_destdir = arg;
! 		break;
! 	case OPT_CLIENT:
! 		client_sourcedir = arg;
! 		break;
! 	case ARGP_KEY_ARG:
! 		switch (state->arg_num) {
! 		case 0:
! 			source = parseCmdArg(arg);
! 			break;
! 		case 1:
! 			destination = parseCmdArg(arg);
! 			break;
! 		default:
! 			argp_usage(state);
! 		}
! 		break;
! 	case ARGP_KEY_END:
! 		/* we either need two arguments, or src/destdir */
! 		switch (state->arg_num) {
! 		case 0:
! 			if (client_sourcedir && server_destdir)
! 				argp_usage(state);
! 			if (client_sourcedir) break;
! 			if (server_destdir) break;
! 			argp_usage(state);
! 		case 2:
! 			if (client_sourcedir || server_destdir)
! 				argp_usage(state);
! 			break;
! 		default:
! 			argp_usage(state);
! 		}
! 		break;
! 	default:
! 		return ARGP_ERR_UNKNOWN;
! 	}
! 
! 	return 0;
! }
! 
! static const struct argp argp = { options, parse_opt, args_doc, doc };
! 
! 
! 
! int main(int argc, char **argv)
  {
  	setIntHandler();
  
  	/* initialize gettext */
***************
*** 49,92 ****
  	textdomain(PACKAGE);
  
! 	struct poptOption options[] = {
! 		                              { "verbose", 'v', POPT_ARG_NONE, 0, 'v'
! 		                              },
! 		                              { "rsync", 'r', POPT_ARG_NONE, &rsync, 0,
! 		                                _("Use Rsync to transfer changed files")},
! 		                              { "one-file-system", 'x', POPT_ARG_NONE, &boundaries, 0,
! 		                                _("don't cross filesystem boundaries")},
! 		                              { "dry-run", 'n', POPT_ARG_NONE, &do_nothing, 0,
! 		                                _("don't create a new backup, test only")},
! 		                              { "server", '\0', POPT_ARG_STRING | POPT_ARGFLAG_DOC_HIDDEN,
! 		                                &server_destdir},
! 		                              { "client", '\0', POPT_ARG_STRING | POPT_ARGFLAG_DOC_HIDDEN,
! 		                                &client_sourcedir},
! 		                              { "version", 0, POPT_ARG_NONE, 0, 'V'},
! 		                              POPT_AUTOHELP
! 		                              POPT_TABLEEND
! 	                              };
  
- 	/* argument parsing */
- 	popt = poptGetContext("faubackup", argc, argv, options, 0);
- 	poptSetOtherOptionHelp(popt,
- 	                       _("[OPTION...] [host:]source [host:]destination"));
- 	while ((rc = poptGetNextOpt(popt))  != -1) {
- 		switch (rc) {
- 		case 'v':
- 			verbose++;
- 			break;
- 		case 'V':
- 			printf("%s\n", PACKAGE_STRING);
- 			exit(0);
- 		}
- 	}
- 	if (rc < -1) {
- 		poptPrintUsage(popt, stderr, 0);
- 		fprintf(stderr, "%s: %s\n",
- 		        poptBadOption(popt, 0), poptStrerror(rc));
- 		exit(1);
- 	}
- 	//verbose = 1;
- 	//rsync = 1;
  	if (server_destdir) {
  		instance_name = "ssh-server";
--- 145,150 ----
  	textdomain(PACKAGE);
  
! 	argp_parse(&argp, argc, argv, 0, 0, NULL);
  
  	if (server_destdir) {
  		instance_name = "ssh-server";
***************
*** 107,127 ****
  			exit(0);
  		}
- 	const char* temp;
- 	if ((temp = poptGetArg(popt)) == NULL) {
- 		poptPrintUsage(popt, stderr, 0);
- 		exit (-1);
- 	}
- 	struct cmdline_data source = parseCmdArg(temp);
- 
- 	if ((temp = poptGetArg(popt)) == NULL) {
- 		poptPrintUsage(popt, stderr, 0);
- 		exit (-1);
- 	}
- 	struct cmdline_data destination = parseCmdArg(temp);
- 	if (poptPeekArg(popt)) {
- 		poptPrintUsage(popt, stderr, 0);
- 		fprintf(stderr, "too many parameters\n");
- 		exit(1);
- 	}
  
  	output.information("Source: Dir: " + source.directory  + " host: "
--- 165,168 ----

Index: Makefile.am
===================================================================
RCS file: /cvsroot/faubackup/faubackup2/src/Makefile.am,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** Makefile.am	9 Jun 2005 11:25:09 -0000	1.12
--- Makefile.am	10 Jun 2005 14:55:53 -0000	1.13
***************
*** 4,8 ****
  # build the main 'faubackup' executable
  faubackup_SOURCES = main.cpp
! faubackup_LDADD = libfaubackup.a $(LIBINTL)
  
  libfaubackup_a_SOURCES = \
--- 4,8 ----
  # build the main 'faubackup' executable
  faubackup_SOURCES = main.cpp
! faubackup_LDADD = libfaubackup.a $(ARGP_LDADD) $(LIBINTL)
  
  libfaubackup_a_SOURCES = \
***************
*** 37,41 ****
  
  # use bundled intl headers in case libintl is not yet installed
! AM_CXXFLAGS = -I ${top_builddir}/intl -I ${top_srcdir}/intl
  
  # add header files to distribution
--- 37,41 ----
  
  # use bundled intl headers in case libintl is not yet installed
! AM_CXXFLAGS = $(ARGP_CFLAGS) -I ${top_builddir}/intl -I ${top_srcdir}/intl
  
  # add header files to distribution



-------------------------------------------------------
This SF.Net email is sponsored by: NEC IT Guy Games.  How far can you shotput
a projector? How fast can you ride your desk chair down the office luge track?
If you want to score the big prize, get to know the little guy.  
Play to win an NEC 61" plasma display: http://www.necitguy.com/?r=20