From 0fdc53d54db27853e87b2d85b8255ebc2d562263 Mon Sep 17 00:00:00 2001 From: Roy Marples Date: Thu, 28 Jun 2007 15:44:14 +0000 Subject: Add --nocolor to more programs --- src/_usage.c | 3 --- src/env-update.c | 12 ++++++------ src/fstabinfo.c | 12 ++++-------- src/libeinfo.c | 6 +++--- src/mountinfo.c | 5 +++-- src/rc-status.c | 5 +++-- src/rc.c | 35 +++++++++++++++++++++++++++++------ 7 files changed, 48 insertions(+), 30 deletions(-) diff --git a/src/_usage.c b/src/_usage.c index 533a6672..54e30d96 100644 --- a/src/_usage.c +++ b/src/_usage.c @@ -17,6 +17,3 @@ static void usage (int exit_status) exit (exit_status); } -#define case_RC_COMMON_GETOPT \ - case 'h': usage (EXIT_SUCCESS); \ - default: usage (EXIT_FAILURE); diff --git a/src/env-update.c b/src/env-update.c index 0fc76150..463cdf45 100644 --- a/src/env-update.c +++ b/src/env-update.c @@ -61,10 +61,11 @@ static const char *space_separated[] = { static char *applet = NULL; -#define getoptstring "hL" +#include "_usage.h" +#define getoptstring "L" getoptstring_COMMON static struct option longopts[] = { - { "help", 0, NULL, 'h'}, { "no-ldconfig", 0, NULL, 'L'}, + longopts_COMMON { NULL, 0, NULL, 0} }; #include "_usage.c" @@ -98,12 +99,11 @@ int main (int argc, char **argv) case 'L': ldconfig = false; break; - case 'h': - usage (EXIT_SUCCESS); - default: - usage (EXIT_FAILURE); + + case_RC_COMMON_GETOPT } } + if (! files) eerrorx ("%s: no files in " ENVDIR " to process", applet); diff --git a/src/fstabinfo.c b/src/fstabinfo.c index 15334760..4601c57e 100644 --- a/src/fstabinfo.c +++ b/src/fstabinfo.c @@ -56,13 +56,14 @@ static struct mntent *getmntfile (FILE *fp, const char *file) } #endif -#define getoptstring "f:m:o:p:h" +#include "_usage.h" +#define getoptstring "f:m:o:p:" getoptstring_COMMON static struct option longopts[] = { { "fstype", 1, NULL, 'f'}, { "mountcmd", 1, NULL, 'm'}, { "opts", 1, NULL, 'o'}, { "passno", 1, NULL, 'p'}, - { "help", 0, NULL, 'h'}, + longopts_COMMON { NULL, 0, NULL, 0} }; #include "_usage.c" @@ -139,12 +140,7 @@ int main (int argc, char **argv) } break; - case 'h': - END_ENT; - usage (EXIT_SUCCESS); - default: - END_ENT; - usage (EXIT_FAILURE); + case_RC_COMMON_GETOPT } END_ENT; diff --git a/src/libeinfo.c b/src/libeinfo.c index b5d0fa19..7f80c1dc 100644 --- a/src/libeinfo.c +++ b/src/libeinfo.c @@ -149,14 +149,14 @@ static bool colour_terminal (void) static int in_colour = -1; int i = 0; + if (is_env ("RC_NOCOLOR", "yes")) + return (false); + if (in_colour == 0) return (false); if (in_colour == 1) return (true); - if (is_env ("RC_NOCOLOR", "yes")) - return (false); - if (! term) { term = getenv ("TERM"); if (! term) diff --git a/src/mountinfo.c b/src/mountinfo.c index b56282f4..18243fb3 100644 --- a/src/mountinfo.c +++ b/src/mountinfo.c @@ -130,7 +130,8 @@ static char **find_mounts (regex_t *node_regex, regex_t *fstype_regex, # error "Operating system not supported!" #endif -#define getoptstring "F:N:S:fnrhV" +#include "_usage.h" +#define getoptstring "F:N:S:fnrV" getoptstring_COMMON static struct option longopts[] = { { "fstype-regex", 1, NULL, 'F'}, { "node-regex", 1, NULL, 'N'}, @@ -138,7 +139,7 @@ static struct option longopts[] = { { "fstype", 0, NULL, 'f'}, { "node", 0, NULL, 'n'}, { "reverse", 0, NULL, 'r'}, - { "help", 0, NULL, 'h'}, + longopts_COMMON { NULL, 0, NULL, 0} }; #include "_usage.c" diff --git a/src/rc-status.c b/src/rc-status.c index 358e3439..7c99df7e 100644 --- a/src/rc-status.c +++ b/src/rc-status.c @@ -53,13 +53,14 @@ static void print_service (char *service) ebracket (cols, color, status); } -#define getoptstring "alsuh" +#include "_usage.h" +#define getoptstring "alsu" getoptstring_COMMON const struct option longopts[] = { {"all", 0, NULL, 'a'}, {"list", 0, NULL, 'l'}, {"servicelist", 0, NULL, 's'}, {"unused", 0, NULL, 'u'}, - {"help", 0, NULL, 'h'}, + longopts_COMMON {NULL, 0, NULL, 0} }; #include "_usage.c" diff --git a/src/rc.c b/src/rc.c index 0981f633..2e2a2e04 100644 --- a/src/rc.c +++ b/src/rc.c @@ -11,12 +11,15 @@ Released under the GPLv2 */ +#define APPLET "rc" + #include #include #include #include #include #include +#include #include #include #include @@ -600,6 +603,14 @@ static void run_script (const char *script) { exit (EXIT_FAILURE); } +#include "_usage.h" +#define getoptstring getoptstring_COMMON +static struct option longopts[] = { + longopts_COMMON + { NULL, 0, NULL, 0} +}; +#include "_usage.c" + int main (int argc, char **argv) { char *RUNLEVEL = NULL; @@ -615,6 +626,7 @@ int main (int argc, char **argv) int depoptions = RC_DEP_STRICT | RC_DEP_TRACE; char ksoftbuffer [PATH_MAX]; char pidstr[6]; + int opt; if (argv[0]) applet = rc_xstrdup (basename (argv[0])); @@ -660,13 +672,7 @@ int main (int argc, char **argv) if (strcmp (applet, "rc" ) != 0) eerrorx ("%s: unknown applet", applet); - /* OK, so we really are the main RC process - Only root should be able to run us */ - if (geteuid () != 0) - eerrorx ("%s: root access required", applet); - atexit (cleanup); - newlevel = argv[0]; /* Change dir to / to ensure all scripts don't use stuff in pwd */ chdir ("/"); @@ -712,6 +718,23 @@ int main (int argc, char **argv) /* We don't free our list as that would be null in environ */ } + argc++; + argv--; + while ((opt = getopt_long (argc, argv, getoptstring, + longopts, (int *) 0)) != -1) + { + switch (opt) { + case_RC_COMMON_GETOPT + } + } + + newlevel = argv[optind++]; + + /* OK, so we really are the main RC process + Only root should be able to run us */ + if (geteuid () != 0) + eerrorx ("%s: root access required", applet); + /* Enable logging */ setenv ("RC_ELOG", "rc", 1); -- cgit v1.2.3