From e6cd2312d62bc34e430b74e34c2223f38eebe2f3 Mon Sep 17 00:00:00 2001 From: Christopher Faylor Date: Tue, 4 Jun 2002 01:31:28 +0000 Subject: [PATCH] * umount.cc (version): New global variable. (longopts): Accommodate new --version option. (opts): Ditto. (usage): Standardize usage output. (print_version): New function. (main): Accommodate --help, --version options. --- winsup/utils/ChangeLog | 23 +++++++++++++------ winsup/utils/umount.cc | 51 +++++++++++++++++++++++++++++++++++++----- 2 files changed, 61 insertions(+), 13 deletions(-) diff --git a/winsup/utils/ChangeLog b/winsup/utils/ChangeLog index a159ea6c1..94ffcbd4a 100644 --- a/winsup/utils/ChangeLog +++ b/winsup/utils/ChangeLog @@ -1,3 +1,12 @@ +2002-06-03 Joshua Daniel Franklin + + * umount.cc (version): New global variable. + (longopts): Accommodate new --version option. + (opts): Ditto. + (usage): Standardize usage output. + (print_version): New function. + (main): Accommodate --help, --version options. + 2002-06-02 Joshua Daniel Franklin * regtool.cc (prog_name): New global variable. @@ -5,7 +14,7 @@ (opts): Ditto. (usage): Standardize usage output. Rearrange/add descriptions. (print_version): New function. - (main): Accomodate longopts and new --help, --version options. Add + (main): Accommodate longopts and new --help, --version options. Add check for (_argv[optind+1] == NULL). 2002-06-02 Christopher Faylor @@ -38,9 +47,9 @@ * passwd.c (prog_name): New global variable. (longopts): Ditto. (opts): Ditto. - (usage): Standardize output. Accomodate new options. + (usage): Standardize output. Accommodate new options. (print_version): New function. - (main): Accomodate longopts and new --help, --version options. + (main): Accommodate longopts and new --help, --version options. 2002-05-28 Joshua Daniel Franklin @@ -53,7 +62,7 @@ (opts): Ditto. (usage): New function. (print_version): New function. - (main): Accomodate longopts and new --help, --version options. + (main): Accommodate longopts and new --help, --version options. 2002-05-26 Christopher Faylor @@ -82,9 +91,9 @@ 2002-05-22 Joshua Daniel Franklin * mount.cc (version): New global variable. - (usage): Standardize usage output. Accomodate new version option. + (usage): Standardize usage output. Accommodate new version option. (print_version): New function. - (longopts): Accomodate new version option. + (longopts): Accommodate new version option. (opts): Ditto. (main): Ditto. @@ -135,7 +144,7 @@ * kill.cc (prog_name): New global variable. (usage): Standardize usage output. Add descriptions. (print_version): New function. - (longopts): Accomodate new version option. + (longopts): Accommodate new version option. (opts): Ditto. (main): Ditto. diff --git a/winsup/utils/umount.cc b/winsup/utils/umount.cc index 459134dc0..cd508a5e1 100644 --- a/winsup/utils/umount.cc +++ b/winsup/utils/umount.cc @@ -1,6 +1,6 @@ /* umount.cc - Copyright 1996, 1998, 1999, 2000, 2001 Red Hat, Inc. + Copyright 1996, 1998, 1999, 2000, 2001, 2002 Red Hat, Inc. This file is part of Cygwin. @@ -21,6 +21,7 @@ static void remove_all_user_mounts (); static void remove_all_system_mounts (); static void remove_cygdrive_prefix (int flags); +static const char version[] = "$Revision$"; static const char *progname; struct option longopts[] = @@ -32,23 +33,27 @@ struct option longopts[] = {"remove-user-mounts", no_argument, NULL, 'U'}, {"system", no_argument, NULL, 's'}, {"user", no_argument, NULL, 'u'}, + {"version", no_argument, NULL, 'v'}, {NULL, 0, NULL, 0} }; -char opts[] = "hASUsuc"; +char opts[] = "AchsSuUv"; static void -usage (void) +usage (FILE *where = stderr) { - fprintf (stderr, "Usage %s [OPTION] []\n\ + fprintf (where, "\ +Usage: %s [OPTION] []\n\ -A, --remove-all-mounts remove all mounts\n\ -c, --remove-cygdrive-prefix remove cygdrive prefix\n\ + -h, --help output usage information and exit\n\ -s, --system remove system mount (default)\n\ -S, --remove-system-mounts remove all system mounts\n\ -u, --user remove user mount\n\ -U, --remove-user-mounts remove all user mounts\n\ + -v, --version output version information and exit\n\ ", progname); - exit (1); + exit (where == stderr ? 1 : 0); } static void @@ -58,13 +63,34 @@ error (const char *path) exit (1); } +static void +print_version () +{ + const char *v = strchr (version, ':'); + int len; + if (!v) + { + v = "?"; + len = 1; + } + else + { + v += 2; + len = strchr (v, ' ') - v; + } + printf ("\ +%s (cygwin) %.*s\n\ +Filesystem Utility\n\ +Copyright 1996, 1998, 1999, 2000, 2001, 2002\n\ +Compiled on %s", progname, len, v, __DATE__); +} + int main (int argc, char **argv) { int i; int flags = 0; int default_flag = MOUNT_SYSTEM; - progname = argv[0]; enum do_what { nada, @@ -74,6 +100,14 @@ main (int argc, char **argv) saw_remove_all_user_mounts } do_what = nada; + progname = strrchr (argv[0], '/'); + if (progname == NULL) + progname = strrchr (argv[0], '\\'); + if (progname == NULL) + progname = argv[0]; + else + progname++; + if (argc == 1) usage (); @@ -90,6 +124,8 @@ main (int argc, char **argv) usage (); do_what = saw_remove_cygdrive_prefix; break; + case 'h': + usage (stdout); case 's': flags |= MOUNT_SYSTEM; break; @@ -107,6 +143,9 @@ main (int argc, char **argv) usage (); do_what = saw_remove_all_user_mounts; break; + case 'v': + print_version (); + exit (0); default: usage (); }