diff options
author | Jim Meyering <jim@meyering.net> | 2003-05-02 19:37:23 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 2003-05-02 19:37:23 +0000 |
commit | cfed14f3cc289b1770ef61b7b909c5661f26e13c (patch) | |
tree | 71b81b0bad828440ba9916b64a70fcf618a81fad | |
parent | d500b3f1e6a1a0394e814b1f9a1c7bb1d8834b3e (diff) | |
download | coreutils-cfed14f3cc289b1770ef61b7b909c5661f26e13c.tar.xz |
Include "quote.h".
Use quote() in diagnostics, rather than literal `' marks.
(main): Exit nonzero when unable to open an input file.
-rw-r--r-- | src/fmt.c | 21 |
1 files changed, 15 insertions, 6 deletions
@@ -29,6 +29,7 @@ #include "system.h" #include "closeout.h" #include "error.h" +#include "quote.h" #include "xstrtol.h" /* The official name of this program (e.g., no `g' prefix). */ @@ -318,6 +319,7 @@ int main (register int argc, register char **argv) { int optchar; + int fail; program_name = argv[0]; setlocale (LC_ALL, ""); @@ -346,7 +348,8 @@ main (register int argc, register char **argv) } if (*s) - error (EXIT_FAILURE, 0, _("invalid width option: `%s'"), argv[1]); + error (EXIT_FAILURE, 0, _("invalid width option: %s"), + quote (argv[1])); /* Make the options we just parsed invisible to getopt. */ argv[1] = argv[0]; @@ -386,8 +389,7 @@ main (register int argc, register char **argv) long int tmp_long; if (xstrtol (optarg, NULL, 10, &tmp_long, "") != LONGINT_OK || tmp_long <= 0 || tmp_long > INT_MAX) - error (EXIT_FAILURE, 0, _("invalid width: `%s'"), - optarg); + error (EXIT_FAILURE, 0, _("invalid width: %s"), quote (optarg)); max_width = (int) tmp_long; } break; @@ -404,6 +406,7 @@ main (register int argc, register char **argv) best_width = max_width * (2 * (100 - LEEWAY) + 1) / 200; + fail = 0; if (optind == argc) fmt (stdin); else @@ -421,15 +424,21 @@ main (register int argc, register char **argv) { fmt (in_stream); if (fclose (in_stream) == EOF) - error (EXIT_FAILURE, errno, "%s", file); + { + error (0, errno, "%s", file); + fail = 1; + } } else - error (0, errno, "%s", file); + { + error (0, errno, "cannot open %s for reading", quote (file)); + fail = 1; + } } } } - exit (EXIT_SUCCESS); + exit (fail ? EXIT_FAILURE : EXIT_SUCCESS); } /* Trim space from the front and back of the string P, yielding the prefix, |