From af41baeb91f0225149c68fe4e14c9de61e5a8397 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Sat, 22 Jun 1996 22:27:32 +0000 Subject: (main): New option --print (-p). Detect write failure. Add --bourne-shell and --c-shell aliases for --sh and --csh resp. --- src/dircolors.c | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/src/dircolors.c b/src/dircolors.c index a116d6070..a3f52ab46 100644 --- a/src/dircolors.c +++ b/src/dircolors.c @@ -73,8 +73,10 @@ static const char *const ls_codes[] = static struct option const long_options[] = { + {"bourne-shell", no_argument, NULL, 'b'}, {"sh", no_argument, NULL, 'b'}, {"csh", no_argument, NULL, 'c'}, + {"c-shell", no_argument, NULL, 'c'}, {"help", no_argument, NULL, 'h'}, {"version", no_argument, NULL, 'v'}, }; @@ -91,11 +93,12 @@ usage (int status) { printf (_("Usage: %s [OPTION]... [FILE]\n"), program_name); printf (_("\ - -h, --help display this help and exit\n\ - --version output version information and exit\n\ + -h, --help display this help and exit\n\ + --version output version information and exit\n\ Determine format of output:\n\ - -b, --sh assume Bourne shell\n\ - -c, --csh assume C-shell\n")); + -p, --print output defaults\n\ + -b, --sh, --bourne-shell output Bourne shell code to set LS_COLOR\n\ + -c, --csh, --c-shell output C-shell code to set LS_COLOR\n")); } exit (status); @@ -352,6 +355,7 @@ main (int argc, char *argv[]) enum Shell_syntax syntax = SHELL_SYNTAX_UNKNOWN; char *ls_color_string; char *file; + int print_defaults = 0; program_name = argv[0]; setlocale (LC_ALL, ""); @@ -360,7 +364,7 @@ main (int argc, char *argv[]) parse_long_options (argc, argv, "dircolors", PACKAGE_VERSION, usage); - while ((optc = getopt_long (argc, argv, "bc", long_options, NULL)) + while ((optc = getopt_long (argc, argv, "bcp", long_options, NULL)) != EOF) switch (optc) { @@ -372,17 +376,37 @@ main (int argc, char *argv[]) syntax = SHELL_SYNTAX_C; break; + case 'p': + print_defaults = 1; + break; + default: usage (1); } + /* FIXME: don't allow -b with -c + or -p with anything else. + No file args allowed with -p. + No more than one allowed in any case. + */ + + if (print_defaults) + { + int i; + for (i = 0; i < G_N_LINES; i++) + { + fwrite (G_line[i], 1, G_line_length[i], stdout); + fputc ('\n', stdout); + } + } + /* Use shell to determine mode, if not already done. */ if (syntax == SHELL_SYNTAX_UNKNOWN) { syntax = guess_shell_syntax (); if (syntax == SHELL_SYNTAX_UNKNOWN) { - error (1, 0, + error (EXIT_FAILURE, 0, _("no SHELL environment variable, and no shell type option given")); } } @@ -390,6 +414,9 @@ main (int argc, char *argv[]) file = argv[optind]; err = dc_parse_file (file, &ls_color_string); + if (fclose (stdout) == EOF) + error (EXIT_FAILURE, errno, _("write error")); + if (have_read_stdin && fclose (stdin) == EOF) error (EXIT_FAILURE, errno, _("standard input")); -- cgit v1.2.3-70-g09d2