From f9a122387716a5c3fb3200e545c255c07235562f Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 4 Sep 2003 15:46:59 +0000 Subject: new help text git-svn-id: file:///home/lennart/svn/public/syrep/trunk@22 07ea20a6-d2c5-0310-9e02-9ef735347d72 --- doc/todo.txt | 2 +- src/Makefile | 4 +-- src/package.c | 11 +++++-- src/syrep.c | 100 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--- src/syrep.ggo | 4 +++ 5 files changed, 111 insertions(+), 10 deletions(-) diff --git a/doc/todo.txt b/doc/todo.txt index 2196bfb..95ea9b0 100644 --- a/doc/todo.txt +++ b/doc/todo.txt @@ -17,8 +17,8 @@ pre-0.1: - package.c: gzip support DONE - package.c: atomicity DONE - fix makepatch to not include already existing files DONE +- better usage info on --help DONE -- better usage info on --help - documentation/man pages - autoconf - testing diff --git a/src/Makefile b/src/Makefile index 8aefef0..97994b5 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,4 +1,4 @@ -CFLAGS=-Wall -pipe -O0 -g -DARCH_IS_BIG_ENDIAN=0 -D_FILE_OFFSET_BITS=64 +CFLAGS=-Wall -pipe -O0 -g -DARCH_IS_BIG_ENDIAN=0 -D_FILE_OFFSET_BITS=64 -DPACKAGE_VERSION=\"0.1\" CC=gcc all: syrep @@ -7,7 +7,7 @@ syrep: cache.o update.o util.o syrep.o md5.o md5util.o context.o package.o dbuti $(CC) -g $^ -o $@ -ldb -lz cmdline.c cmdline.h: syrep.ggo Makefile - gengetopt --unamed-opts < $< + gengetopt --unamed-opts --no-handle-help --no-handle-version < $< update.o: cmdline.h diff --git a/src/package.c b/src/package.c index c78adc9..63ca432 100644 --- a/src/package.c +++ b/src/package.c @@ -417,6 +417,9 @@ static int read_item(struct package *p) { if (p->x_endianess) l = X64(l); + if (args.verbose_flag) + fprintf(stderr, "Reading %s (%llu) from package.\n", name, l); + size = (off_t) l; snprintf(path, sizeof(path), "%s/%i", p->base, p->count++); @@ -473,10 +476,14 @@ static int write_item(struct package *p, struct package_item *i) { if ((size = filesize(fd)) == (off_t) -1) return -1; - + l = (uint64_t) size; + memset(name, 0, sizeof(name)); strncpy(name, i->name, PACKAGE_ITEMNAMELEN); + if (args.verbose_flag) + fprintf(stderr, "Writing %s (%llu bytes) to package.\n", name, l); + if ((r = package_write(p, name, PACKAGE_ITEMNAMELEN)) != PACKAGE_ITEMNAMELEN) { if (r >= 0) fprintf(stderr, "Short write\n"); @@ -484,7 +491,7 @@ static int write_item(struct package *p, struct package_item *i) { goto fail; } - l = (uint64_t) size; + if ((r = package_write(p, &l, 8)) != 8) { if (r >= 0) fprintf(stderr, "Short write\n"); diff --git a/src/syrep.c b/src/syrep.c index 534c62b..446c2c9 100644 --- a/src/syrep.c +++ b/src/syrep.c @@ -20,7 +20,6 @@ #include #include -#include #include #include #include @@ -33,6 +32,9 @@ #include #include +#include +#include + #include "md5util.h" #include "md5.h" #include "context.h" @@ -461,10 +463,94 @@ static void free_args(void) { free(args.inputs); } -#include "package.h" + +static int help(const char *argv0) { + + fprintf(stderr, + "%s -- Synchronize Repositories\n\n" + + "Usage: %s [options] [argument...]\n\n" + + "General options:\n" + " -v --verbose Enable verbose operation\n" + " -T --local-temp Use temporary directory inside repository\n" + " --ignore-origin Don't warn if snapshot not local in update, merge, makepatch\n" + " -z --compress Compress snapshots or patches\n" + " -p --progress Show progress\n\n" + + "General commands:\n" + " -h --help Print help and exit\n" + " -V --version Print version and exit\n\n" + + "Specific commands:\n" + " --list List a repository snapshot\n" + " --show-deleted Show deleted entries of repository snapshot\n" + " --show-by-md Show files by message digests\n" + " --show-times Show first and last seen times\n\n" + + " --info Show information about a repository or snapshot\n\n" + + " --history Show history of a repository or snapshot\n\n" + + " --dump Show a structure dump of a repository or snapshot\n\n" + + " --update Update a repository snapshot\n" + " -SSTRING --snapshot=STRING Use the specified snapshot file instead of the one contained in the repository\n" + " -CSTRING --cache=STRING Use the specified cache file instead of the one contained in the repository\n" + " --no-cache Don't use a message digest cache\n" + " --no-purge Don't purge obsolete entries from cache after update run\n" + " --ro-cache Use read only cache\n\n" + + " --diff Show difference between two repositories or snapshots\n\n" + + " --merge Merge a snapshot or a patch into a repository\n" + " -q --question Ask a question before each action\n" + " --prune-empty Prune empty directories\n" + " --keep-trash Don't empty trash\n\n" + + " --makepatch Make a patch against the specified repository\n" + " -oSTRING --output-file=STRING Write output to specified file instead of STDOUT\n" + " --include-all Include files in patch which do exist on the other side under a different name\n\n" + + " --extract Extract the contents of a snapshot or patch\n" + " -DSTRING --output-directory=STRING Write output to specified directory\n\n" + + " --cleanup Remove syrep info from repository\n" + " -lINT --cleanup-level=INT 1 - just remove temporary data and trash (default)\n" + " 2 - remove MD cache as well\n" + " 3 - remove all syrep data\n", + argv0, argv0); + + return 0; +} + +static int version(const char *argv0) { + int major, minor, patch; + + db_version(&major, &minor, &patch); + + fprintf(stderr, + "%s "PACKAGE_VERSION"\n" + "Compiled with %i Bit off_t.\n" + "Compiled with zlib %s, linked to zlib %s.\n" + "Compiled with libdb %i.%i.%i, linked to libdb %i.%i.%i\n", + argv0, + sizeof(off_t)*8, + ZLIB_VERSION, zlibVersion(), + DB_VERSION_MAJOR, DB_VERSION_MINOR, DB_VERSION_PATCH, + major, minor, patch); + + return 0; +} int main(int argc, char *argv[]) { struct sigaction sa; + char *bn; + + if ((bn = strrchr(argv[0], '/'))) + bn++; + else + bn = argv[0]; memset(&sa, 0, sizeof(sa)); sa.sa_handler = sigint; @@ -472,8 +558,12 @@ int main(int argc, char *argv[]) { cmdline_parser(argc, argv, &args); atexit(free_args); - - if (args.list_flag) + + if (args.help_given) + return help(bn); + else if (args.version_given) + return version(bn); + else if (args.list_flag) return do_foreach(list, 0); else if (args.info_flag) return do_foreach(info, 0); @@ -494,7 +584,7 @@ int main(int argc, char *argv[]) { else if (args.cleanup_flag) return do_cleanup(); - cmdline_parser_print_help(); + help(bn); return 1; } diff --git a/src/syrep.ggo b/src/syrep.ggo index fea530c..e2ce98a 100644 --- a/src/syrep.ggo +++ b/src/syrep.ggo @@ -25,6 +25,10 @@ option "local-temp" T "Use temporary directory inside repository" flag off option "ignore-origin" - "Don't warn if snapshot not local in update, merge, makepatch" flag off option "compress" z "Compress snapshots or patches" flag off +#option "version" V "Print version and exit" flag off + +#option "help" h "Print help and exit" flag off + option "list" - "List a repository snapshot" flag off option "show-deleted" - "list: Show deleted entries of repository snapshot" flag off option "show-by-md" - "list: Show files by message digests" flag off -- cgit