faubackup/src faubackup-gather.c,1.3,1.4 faubackup-scatter.c,1.5,1.6
Martin Waitz <[email protected]> Wed, 17 Mar 2004 13:14:43 +0000
| Newsgroups | gmane.comp.sysutils.backup.faubackup.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/faubackup/faubackup/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3532/src
Modified Files:
faubackup-gather.c faubackup-scatter.c
Log Message:
use libpopt for option parsing
faubackup-gather does not preserve atime by default now,
can be activated with --preserve-atime
Index: faubackup-scatter.c
===================================================================
RCS file: /cvsroot/faubackup/faubackup/src/faubackup-scatter.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** faubackup-scatter.c 11 Dec 2003 00:52:13 -0000 1.5
--- faubackup-scatter.c 17 Mar 2004 13:14:41 -0000 1.6
***************
*** 34,37 ****
--- 34,38 ----
#include <unistd.h>
#include <utime.h>
+ #include <popt.h>
#include "faubackup.h"
***************
*** 42,46 ****
int error;
int verbose;
! char* progname;
static char lastdate[MAXDATE];
--- 43,47 ----
int error;
int verbose;
! const char* progname;
static char lastdate[MAXDATE];
***************
*** 733,754 ****
int
! main(int argc, char* argv[])
{
char *path, *workdir;
struct stat *st;
int ret;
error=0;
progname=argv[0];
- verbose=0;
! if( argc==2 && strcmp(argv[1], "-v")==0 ) {
! verbose=1;
! } else if( argc>1 ) {
! fprintf( stderr, "Usage: %s [-v]\n", progname );
! exit( 1 );
}
/* ======================= */
--- 734,784 ----
+ static struct poptOption options[] = {
+ {
+ .longName="verbose", .shortName='v',
+ .argInfo=POPT_ARG_NONE, .arg=&verbose,
+ .descrip = "Print verbose messages"
+ }, {
+ .longName="version", .shortName='V',
+ .val = 'V',
+ .descrip = "Print program version"
+ },
+ POPT_AUTOHELP
+ {}
+ };
+
int
! main(int argc, const char* argv[])
{
char *path, *workdir;
struct stat *st;
int ret;
+ poptContext popt;
+ int rc;
error=0;
progname=argv[0];
! /* argument parsing */
! popt = poptGetContext("faubackup", argc, argv, options, 0);
! while( (rc = poptGetNextOpt(popt)) > 0 ) {
! switch (rc) {
! 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);
}
+ if( poptPeekArg(popt) ) {
+ poptPrintUsage(popt, stderr, 0);
+ fprintf(stderr, "unknown parameter\n");
+ exit(1);
+ }
/* ======================= */
Index: faubackup-gather.c
===================================================================
RCS file: /cvsroot/faubackup/faubackup/src/faubackup-gather.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** faubackup-gather.c 11 Dec 2003 00:52:13 -0000 1.3
--- faubackup-gather.c 17 Mar 2004 13:14:41 -0000 1.4
***************
*** 35,38 ****
--- 35,39 ----
#include <unistd.h>
#include <utime.h>
+ #include <popt.h>
#include "faubackup.h"
***************
*** 40,44 ****
int error;
! char* progname;
--- 41,49 ----
int error;
! const char* progname;
!
! /* variables set by command line */
! static int verbose = 0;
! static int atime_preserve = 0;
***************
*** 187,198 ****
}
! /* reset atime of file */
! times.actime = st->st_atime;
! times.modtime = st->st_mtime;
! ret = utime( path, × );
! if( ret<0 && errno != EROFS && errno != EPERM ) {
! fprintf(stderr, "%s: utime %s: %s\n",
! progname, path, strerror(errno));
! return;
}
}
--- 192,205 ----
}
! if( atime_preserve ) {
! /* reset atime of file */
! times.actime = st->st_atime;
! times.modtime = st->st_mtime;
! ret = utime( path, × );
! if( ret<0 && errno != EROFS && errno != EPERM ) {
! fprintf(stderr, "%s: utime %s: %s\n",
! progname, path, strerror(errno));
! return;
! }
}
}
***************
*** 276,297 ****
}
int
! main(int argc, char* argv[])
{
char path[MAXLEN];
- int verbose;
int c, len;
error=0;
progname=argv[0];
- verbose=0;
! if( argc==2 && strcmp(argv[1], "-v")==0 ) {
! verbose=1;
! } else if( argc>1 ) {
! fprintf(stderr, "Usage: %s [-v]\n", progname);
! exit( 1 );
}
len = 0;
while( (c=fgetc(stdin)) != EOF ) {
--- 283,339 ----
}
+
+ static struct poptOption options[] = {
+ {
+ .longName="verbose", .shortName='v',
+ .argInfo=POPT_ARG_NONE, .arg=&verbose,
+ .descrip = "Print verbose messages"
+ }, {
+ .longName="version", .shortName='V',
+ .val = 'V',
+ .descrip = "Print program version"
+ }, {
+ .longName="atime-preserve",
+ .argInfo=POPT_ARG_NONE, .arg=&atime_preserve,
+ .descrip = "try to preserve access time, will change ctime"
+ },
+ POPT_AUTOHELP
+ {}
+ };
+
int
! main(int argc, const char* argv[])
{
char path[MAXLEN];
int c, len;
+ poptContext popt;
+ int rc;
error=0;
progname=argv[0];
! /* argument parsing */
! popt = poptGetContext("faubackup", argc, argv, options, 0);
! while( (rc = poptGetNextOpt(popt)) > 0 ) {
! switch (rc) {
! 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);
}
+ if( poptPeekArg(popt) ) {
+ poptPrintUsage(popt, stderr, 0);
+ fprintf(stderr, "unknown parameter\n");
+ exit(1);
+ }
+
+ /* process file list from stdin */
len = 0;
while( (c=fgetc(stdin)) != EOF ) {
-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click