From 063127c6749871a05fe20b510676387ee88a4789 Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Tue, 31 May 2022 15:25:15 +0200 Subject: Fixed compiler errors of missing updates. --- examples/option_mkdir.c | 94 ------------------------------------------------- src/cregex.c | 11 ++---- 2 files changed, 3 insertions(+), 102 deletions(-) delete mode 100644 examples/option_mkdir.c diff --git a/examples/option_mkdir.c b/examples/option_mkdir.c deleted file mode 100644 index 3c4b8e12..00000000 --- a/examples/option_mkdir.c +++ /dev/null @@ -1,94 +0,0 @@ -#include -#include - -// mkdir option parsing. -struct AppArgs { - const char *mode; - bool parent; - bool verbose; - const char *context; - int index; -}; - -int parseArgs(int argc, char *argv[], struct AppArgs *args) -{ - const char *shortopts = "pvm:Z"; - coption_long longopts[] = { - {"mode", coption_required_argument, 'm'}, - {"parent", coption_no_argument, 'p'}, - {"verbose", coption_no_argument, 'v'}, - {"context", coption_optional_argument, 'Z'}, - {"help", coption_no_argument, 'H'}, - {"version", coption_no_argument, 'V'}, - {NULL} - }; - *args = (struct AppArgs){NULL}; - coption opt = coption_init(); - int c; - while ((c = coption_get(&opt, argc, argv, shortopts, longopts)) != -1) { - switch (c) { - case 'm': args->mode = opt.arg; break; - case 'p': args->parent = true; break; - case 'v': args->verbose = true; break; - case 'Z': args->context = opt.arg? opt.arg : "DEFAULT"; break; - case 'H': - printf("Usage: mkdir [OPTION]... DIRECTORY...\n" - "Create the DIRECTORY(ies), if they do not already exist.\n\n" - "Mandatory arguments to long options are mandatory for short options too.\n" - " -m, --mode=MODE set file mode (as in chmod), not a=rwx - umask\n" - " -p, --parents no error if existing, make parent directories as needed\n" - " -v, --verbose print a message for each created directory\n" - " -Z set SELinux security context of each created directory\n" - " to the default type\n" - " --context[=CTX] like -Z, or if CTX is specified then set the SELinux\n" - " or SMACK security context to CTX\n" - " --help display this help and exit\n" - " --version output version information and exit\n\n" - "GNU coreutils online help: \n" - "Full documentation at: \n" - "or available locally via: info '(coreutils) mkdir invocation'\n"); - return 1; - case 'V': - printf("mkdir (GNU coreutils) 8.30\n" - "Copyright (C) 2018 Free Software Foundation, Inc.\n" - "License GPLv3+: GNU GPL version 3 or later .\n" - "This is free software: you are free to change and redistribute it.\n" - "There is NO WARRANTY, to the extent permitted by law.\n"); - return 1; - case ':': - printf("mkdir: option '%s' requires an argument\n" - "Try 'mkdir --help' for more information.\n", opt.optstr); - return -1; - case '?': - printf("mkdir: invalid option '%s'\n" - "Try 'mkdir --help' for more information.\n", opt.optstr); - return -2; - } - } - - if (opt.ind == argc) { - printf("mkdir: missing operand\n" - "Try 'mkdir --help' for more information.\n"); - return 2; - } - args->index = opt.ind; - return 0; -} - - -int main(int argc, char* argv[]) -{ - struct AppArgs args; - int ret = parseArgs(argc, argv, &args); - if (ret != 0) - return ret < 0? ret : 0; - - printf("mkdir:"); - for (int i=args.index; i < argc; ++i) { - printf(" %s\n", argv[i]); - } - printf(" mode:%s\n parent:%d\n verbose:%d\n context:%s\n", - args.mode? args.mode:"", - args.parent, args.verbose, - args.context? args.context:""); -} diff --git a/src/cregex.c b/src/cregex.c index 99b0fa03..7ca9a336 100644 --- a/src/cregex.c +++ b/src/cregex.c @@ -175,16 +175,11 @@ typedef struct Reljunk static int chartorune(Rune *rune, const char *s) { - utf8_decode_t ctx = {UTF8_OK}; + utf8_decode_t ctx = {.state=0}; const uint8_t *b = (const uint8_t*)s; - utf8_decode(&ctx, *b++); - switch (ctx.size) { - case 4: utf8_decode(&ctx, *b++); - case 3: utf8_decode(&ctx, *b++); - case 2: utf8_decode(&ctx, *b++); - } + do { utf8_decode(&ctx, *b++); } while (ctx.state); *rune = ctx.codep; - return ctx.size; + return (const char*)b - s; } static const char* -- cgit v1.2.3