logo

utils-std

Collection of commonly available Unix tools git clone https://anongit.hacktivis.me/git/utils-std.git
commit: 3de33afe96990755dd10ff262933ffd14c8f72f4
parent d0a54c2647da65ae765854e42aabef8cb7749179
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Fri, 20 Sep 2024 04:49:33 +0200

cmd/uniq: unify error message formatting

Diffstat:

Mcmd/uniq.c27+++++++++++++++------------
1 file changed, 15 insertions(+), 12 deletions(-)

diff --git a/cmd/uniq.c b/cmd/uniq.c @@ -37,7 +37,7 @@ main(int argc, char *argv[]) case 'c': if(mode != UNIQ) { - fprintf(stderr, "uniq: Error: can only pass one of [-c|-d|-u]\n"); + fprintf(stderr, "uniq: error: can only pass one of [-c|-d|-u]\n"); return 1; } mode = COUNT; @@ -45,7 +45,7 @@ main(int argc, char *argv[]) case 'd': if(mode != UNIQ) { - fprintf(stderr, "uniq: Error: can only pass one of [-c|-d|-u]\n"); + fprintf(stderr, "uniq: error: can only pass one of [-c|-d|-u]\n"); return 1; } mode = ONLY_REPEAT; @@ -55,13 +55,13 @@ main(int argc, char *argv[]) field = strtoul(optarg, &endptr, 0); if(errno != 0) { - fprintf(stderr, "uniq: Error: Failed parsing '-f %s': %s\n", optarg, strerror(errno)); + fprintf(stderr, "uniq: error: Failed parsing '-f %s': %s\n", optarg, strerror(errno)); return 1; } if(endptr != NULL && endptr[0] != 0) { fprintf( - stderr, "uniq: Error: Non-numeric characters passed to '-f %s': %s\n", optarg, endptr); + stderr, "uniq: error: Non-numeric characters passed to '-f %s': %s\n", optarg, endptr); return 1; } break; @@ -70,20 +70,20 @@ main(int argc, char *argv[]) shift = strtoul(optarg, &endptr, 0); if(errno != 0) { - fprintf(stderr, "uniq: Error: Failed parsing '-f %s': %s\n", optarg, strerror(errno)); + fprintf(stderr, "uniq: error: Failed parsing '-f %s': %s\n", optarg, strerror(errno)); return 1; } if(endptr != NULL && endptr[0] != 0) { fprintf( - stderr, "uniq: Error: Non-numeric characters passed to '-f %s': %s\n", optarg, endptr); + stderr, "uniq: error: Non-numeric characters passed to '-f %s': %s\n", optarg, endptr); return 1; } break; case 'u': if(mode != UNIQ) { - fprintf(stderr, "uniq: Error: can only pass one of [-c|-d|-u]\n"); + fprintf(stderr, "uniq: error: can only pass one of [-c|-d|-u]\n"); return 1; } mode = NO_REPEAT; @@ -109,7 +109,8 @@ main(int argc, char *argv[]) input = fopen(argv[0], "r"); if(input == NULL) { - fprintf(stderr, "uniq: Failed opening input file '%s': %s\n", argv[0], strerror(errno)); + fprintf( + stderr, "uniq: error: Failed opening input file '%s': %s\n", argv[0], strerror(errno)); return 1; } break; @@ -117,18 +118,20 @@ main(int argc, char *argv[]) input = fopen(argv[0], "r"); if(input == NULL) { - fprintf(stderr, "uniq: Failed opening input file '%s': %s\n", argv[0], strerror(errno)); + fprintf( + stderr, "uniq: error: Failed opening input file '%s': %s\n", argv[0], strerror(errno)); return 1; } output = fopen(argv[1], "w"); if(output == NULL) { - fprintf(stderr, "uniq: Failed opening output file '%s': %s\n", argv[1], strerror(errno)); + fprintf( + stderr, "uniq: error: Failed opening output file '%s': %s\n", argv[1], strerror(errno)); return 1; } break; default: - fprintf(stderr, "uniq: Invalid number of arguments (%d), expected [0..2]\n", argc); + fprintf(stderr, "uniq: error: Invalid number of arguments (%d), expected [0..2]\n", argc); return 1; } @@ -236,7 +239,7 @@ main(int argc, char *argv[]) if(errno != 0) { - fprintf(stderr, "uniq: Read error: %s\n", strerror(errno)); + fprintf(stderr, "uniq: error: Failed reading: %s\n", strerror(errno)); return 1; }