Author | Jamozed <[email protected]> |
Date | 2020-07-06 09:59:53 |
Commit | f9068a8b71e64d2fe6019c9f7318a4f5322d8c2b |
Parent | d980a30d3f4c0597653b720264f2999eeea9a9a8 |
basename: Use libokv error reporting
Diffstat
M | src/basename.c | | | 23 | +++++++++++++---------- |
1 files changed, 13 insertions, 10 deletions
diff --git a/src/basename.c b/src/basename.c index bf1454e..d4dd717 100644 --- a/src/basename.c +++ b/src/basename.c @@ -1,4 +1,4 @@ -// basename.c, version 1.0.0 +// basename.c, version 1.0.1 // OMKOV coreutils implementation of POSIX basename // Copyright (C) 2020, Jakob Wakeling // All rights reserved. @@ -33,15 +33,18 @@ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE. */ -#include "error.h" #include "optget.h" +#include <error.h> + #include <stdio.h> +#define VERSION "1.0.1" + static void help(void); static void version(void); -int main(int argc, char *argv[]) { +int main(int ac, char *av[]) { A0 = av[0]; lop_t lops[] = { { "help", ARG_NUL, 256 }, { "version", ARG_NUL, 257 }, @@ -49,23 +52,23 @@ int main(int argc, char *argv[]) { }; opt_t opt = OPTGET_INIT; opt.str = ""; opt.lops = lops; int o; - while ((o = optget(&opt, argv, 1)) != -1) switch (o) { + while ((o = optget(&opt, av, 1)) != -1) switch (o) { case 256: { help(); return 0; } case 257: { version(); return 0; } default: { return 1; } } - if (opt.ind == argc) { error(1, "%s: missing operand", argv[0]); } + if (opt.ind == ac) { error(1, "missing operand"); } - register char *p = argv[opt.ind]; + register char *p = av[opt.ind]; if (!*p) { fputc('.', stdout); fputc('\n', stdout); return 0; } for (++p; *p; ++p) {} for (--p; *p == '/'; --p); - if (p + 1 == argv[opt.ind]) { fputs("/\n", stdout); return 0; } + if (p + 1 == av[opt.ind]) { fputs("/\n", stdout); return 0; } else { p[1] = 0; } - if (argv[opt.ind + 1]) { - register char *s = argv[opt.ind + 1]; for (; *s; ++s); + if (av[opt.ind + 1]) { + register char *s = av[opt.ind + 1]; for (; *s; ++s); for (--s; *p && *p != '/' && *s && *p == *s; --p, --s); if (!*s && *p && *p != '/') { p[1] = 0; } } @@ -85,7 +88,7 @@ static void help(void) { } static void version(void) { - puts("OMKOV coreutils basename, version 1.0.0"); + puts("OMKOV coreutils basename, version " VERSION); puts("Copyright (C) 2020, Jakob Wakeling"); puts("All rights reserved."); puts("OMKOV Permissive Licence (https://www.omkov.net/OLPE)");