diff options
author | Jim Meyering <jim@meyering.net> | 1998-01-04 22:41:02 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 1998-01-04 22:41:02 +0000 |
commit | 63c0f480ade29b20ebf60e1036d61d4dc9670214 (patch) | |
tree | 846ceb963e3f87275f54a9d03e801c4122b9d184 /src | |
parent | e375f4e9c89d30c7823ce715dbc4f008669b7df3 (diff) | |
download | coreutils-63c0f480ade29b20ebf60e1036d61d4dc9670214.tar.xz |
Use a single enumerated type, Verbosity, instead of
the two booleans, verbose and changes_only. This fixes a bug whereby
--change had the same effect as --verbose.
Plus Paul's close_stdout changes.
Diffstat (limited to 'src')
-rw-r--r-- | src/chmod.c | 36 | ||||
-rw-r--r-- | src/chown.c | 37 |
2 files changed, 50 insertions, 23 deletions
diff --git a/src/chmod.c b/src/chmod.c index 8c3927d2f..429546f48 100644 --- a/src/chmod.c +++ b/src/chmod.c @@ -1,5 +1,5 @@ /* chmod -- change permission modes of files - Copyright (C) 89, 90, 91, 95, 96, 1997 Free Software Foundation, Inc. + Copyright (C) 89, 90, 91, 95, 96, 97, 1998 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -24,6 +24,7 @@ #include "modechange.h" #include "system.h" +#include "closeout.h" #include "error.h" #include "savedir.h" @@ -34,6 +35,18 @@ enum Change_status CH_NO_CHANGE_REQUESTED }; +enum Verbosity +{ + /* Print a message for each file that is processed. */ + V_high, + + /* Print a message for each file whose attributes we change. */ + V_changes_only, + + /* Do not be verbose. This is the default. */ + V_off +}; + void mode_string (); void strip_trailing_slashes (); @@ -50,16 +63,13 @@ static int recurse; /* If nonzero, force silence (no error messages). */ static int force_silent; -/* If nonzero, describe the modes we set. */ -static int verbose; +/* Level of verbosity. */ +static enum Verbosity verbosity = V_off; /* The argument to the --reference option. Use the owner and group IDs of this file. This file must exist. */ static char *reference_file; -/* If nonzero, describe only modes that change. */ -static int changes_only; - /* If nonzero, display usage information and exit. */ static int show_help; @@ -148,7 +158,7 @@ change_file_mode (const char *file, const struct mode_change *changes, { int fail = chmod (file, (int) newmode); - if (verbose || (changes_only && !fail)) + if (verbosity == V_high || (verbosity == V_changes_only && !fail)) describe_change (file, newmode, (fail ? CH_FAILED : CH_SUCCEEDED)); if (fail) @@ -158,7 +168,7 @@ change_file_mode (const char *file, const struct mode_change *changes, errors = 1; } } - else if (verbose && changes_only == 0) + else if (verbosity == V_high) describe_change (file, newmode, CH_NO_CHANGE_REQUESTED); if (recurse && S_ISDIR (file_stats.st_mode)) @@ -247,6 +257,7 @@ Each MODE is one or more of the letters ugoa, one of the symbols +-= and\n\ one or more of the letters rwxXstugo.\n\ ")); puts (_("\nReport bugs to <fileutils-bugs@gnu.org>.")); + close_stdout (); } exit (status); } @@ -268,7 +279,7 @@ main (int argc, char **argv) bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); - recurse = force_silent = verbose = changes_only = 0; + recurse = force_silent = 0; while (1) { @@ -307,13 +318,13 @@ main (int argc, char **argv) recurse = 1; break; case 'c': - changes_only = 1; + verbosity = V_changes_only; break; case 'f': force_silent = 1; break; case 'v': - verbose = 1; + verbosity = V_high; break; default: usage (1); @@ -323,6 +334,7 @@ main (int argc, char **argv) if (show_version) { printf ("chmod (%s) %s\n", GNU_PACKAGE, VERSION); + close_stdout (); exit (0); } @@ -354,5 +366,7 @@ main (int argc, char **argv) errors |= change_file_mode (argv[optind], changes, 1); } + if (verbosity != V_off) + close_stdout (); exit (errors); } diff --git a/src/chown.c b/src/chown.c index f83c35073..9fec27aef 100644 --- a/src/chown.c +++ b/src/chown.c @@ -1,5 +1,5 @@ /* chown -- change user and group ownership of files - Copyright (C) 89, 90, 91, 95, 96, 1997 Free Software Foundation, Inc. + Copyright (C) 89, 90, 91, 95, 96, 97, 1998 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -36,6 +36,7 @@ #include <getopt.h> #include "system.h" +#include "closeout.h" #include "error.h" #include "savedir.h" @@ -65,6 +66,18 @@ enum Change_status CH_NO_CHANGE_REQUESTED }; +enum Verbosity +{ + /* Print a message for each file that is processed. */ + V_high, + + /* Print a message for each file whose attributes we change. */ + V_changes_only, + + /* Do not be verbose. This is the default. */ + V_off +}; + static int change_dir_owner PARAMS ((const char *dir, uid_t user, gid_t group, struct stat *statp)); @@ -81,11 +94,8 @@ static int recurse; /* If nonzero, force silence (no error messages). */ static int force_silent; -/* If nonzero, describe the files we process. */ -static int verbose; - -/* If nonzero, describe only owners or groups that change. */ -static int changes_only; +/* Level of verbosity. */ +static enum Verbosity verbosity = V_off; /* The name of the user to which ownership of the files is being given. */ static char *username; @@ -175,7 +185,7 @@ change_file_owner (const char *file, uid_t user, gid_t group) else fail = chown (file, newuser, newgroup); - if (verbose || (changes_only && !fail)) + if (verbosity == V_high || (verbosity == V_changes_only && !fail)) describe_change (file, (fail ? CH_FAILED : CH_SUCCEEDED)); if (fail) @@ -185,7 +195,7 @@ change_file_owner (const char *file, uid_t user, gid_t group) errors = 1; } } - else if (verbose && changes_only == 0) + else if (verbosity == V_high) { describe_change (file, CH_NO_CHANGE_REQUESTED); } @@ -280,6 +290,7 @@ Owner is unchanged if missing. Group is unchanged if missing, but changed\n\ to login group if implied by a period. A colon may replace the period.\n\ ")); puts (_("\nReport bugs to <fileutils-bugs@gnu.org>.")); + close_stdout (); } exit (status); } @@ -298,7 +309,7 @@ main (int argc, char **argv) bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); - recurse = force_silent = verbose = changes_only = 0; + recurse = force_silent = 0; while ((optc = getopt_long (argc, argv, "Rcfhv", long_options, NULL)) != -1) { @@ -313,8 +324,7 @@ main (int argc, char **argv) recurse = 1; break; case 'c': - verbose = 1; - changes_only = 1; + verbosity = V_changes_only; break; case 'f': force_silent = 1; @@ -323,7 +333,7 @@ main (int argc, char **argv) change_symlinks = 1; break; case 'v': - verbose = 1; + verbosity = V_high; break; default: usage (1); @@ -333,6 +343,7 @@ main (int argc, char **argv) if (show_version) { printf ("chown (%s) %s\n", GNU_PACKAGE, VERSION); + close_stdout (); exit (0); } @@ -379,5 +390,7 @@ main (int argc, char **argv) errors |= change_file_owner (argv[optind], user, group); } + if (verbosity != V_off) + close_stdout (); exit (errors); } |