Add --nocolor to more programs

This commit is contained in:
Roy Marples 2007-06-28 15:44:14 +00:00
parent 10c3592147
commit 0fdc53d54d
7 changed files with 48 additions and 30 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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;

View File

@ -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)

View File

@ -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"

View File

@ -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"

View File

@ -11,12 +11,15 @@
Released under the GPLv2
*/
#define APPLET "rc"
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/utsname.h>
#include <sys/wait.h>
#include <errno.h>
#include <ctype.h>
#include <getopt.h>
#include <libgen.h>
#include <limits.h>
#include <stdbool.h>
@ -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);