diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 04:23:18 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 04:23:18 +0000 |
commit | 41b1317ec41265120f7355c60ecd5d103f2257e4 (patch) | |
tree | 4adcd743b92041075b7764abf6f140b7eb4f4332 /tools/lint/main.c | |
parent | Adding debian version 2.1.30-2.1. (diff) | |
download | libyang2-41b1317ec41265120f7355c60ecd5d103f2257e4.tar.xz libyang2-41b1317ec41265120f7355c60ecd5d103f2257e4.zip |
Merging upstream version 2.1.148.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tools/lint/main.c')
-rw-r--r-- | tools/lint/main.c | 52 |
1 files changed, 42 insertions, 10 deletions
diff --git a/tools/lint/main.c b/tools/lint/main.c index 9f0d027..43b90c8 100644 --- a/tools/lint/main.c +++ b/tools/lint/main.c @@ -1,9 +1,10 @@ /** * @file main.c * @author Radek Krejci <rkrejci@cesnet.cz> + * @author Adam Piecek <piecek@cesnet.cz> * @brief libyang's yanglint tool * - * Copyright (c) 2015-2020 CESNET, z.s.p.o. + * Copyright (c) 2015-2023 CESNET, z.s.p.o. * * This source code is licensed under BSD 3-Clause License (the "License"). * You may not use this file except in compliance with the License. @@ -27,6 +28,7 @@ #include "completion.h" #include "configuration.h" #include "linenoise/linenoise.h" +#include "yl_opt.h" int done; struct ly_ctx *ctx = NULL; @@ -37,25 +39,32 @@ int main_ni(int argc, char *argv[]); int main(int argc, char *argv[]) { - char *cmdline; - int cmdlen; + int cmdlen, posc, i, j; + struct yl_opt yo = {0}; + char *empty = NULL, *cmdline; + char **posv; + uint8_t cmd_found; if (argc > 1) { /* run in non-interactive mode */ return main_ni(argc, argv); } + yo.interactive = 1; /* continue in interactive mode */ linenoiseSetCompletionCallback(complete_cmd); load_config(); if (ly_ctx_new(NULL, YL_DEFAULT_CTX_OPTIONS, &ctx)) { - YLMSG_E("Failed to create context.\n"); + YLMSG_E("Failed to create context."); return 1; } while (!done) { - uint8_t executed = 0; + cmd_found = 0; + + posv = ∅ + posc = 0; /* get the command from user */ cmdline = linenoise(PROMPT); @@ -76,25 +85,48 @@ main(int argc, char *argv[]) for (cmdlen = 0; cmdline[cmdlen] && (cmdline[cmdlen] != ' '); cmdlen++) {} /* execute the command if any valid specified */ - for (uint16_t i = 0; commands[i].name; i++) { + for (i = 0; commands[i].name; i++) { if (strncmp(cmdline, commands[i].name, (size_t)cmdlen) || (commands[i].name[cmdlen] != '\0')) { continue; } - commands[i].func(&ctx, cmdline); - executed = 1; + cmd_found = 1; + if (commands[i].opt_func && commands[i].opt_func(&yo, cmdline, &posv, &posc)) { + break; + } + if (commands[i].dep_func && commands[i].dep_func(&yo, posc)) { + break; + } + if (posc) { + for (j = 0; j < posc; j++) { + yo.last_one = (j + 1) == posc; + if (commands[i].exec_func(&ctx, &yo, posv[j])) { + break; + } + } + } else { + commands[i].exec_func(&ctx, &yo, NULL); + } + if (commands[i].fin_func) { + commands[i].fin_func(ctx, &yo); + } + break; } - if (!executed) { + if (!cmd_found) { /* if unknown command specified, tell it to user */ - YLMSG_E("Unknown command \"%.*s\", type 'help' for more information.\n", cmdlen, cmdline); + YLMSG_E("Unknown command \"%.*s\", type 'help' for more information.", cmdlen, cmdline); } linenoiseHistoryAdd(cmdline); free(cmdline); + yl_opt_erase(&yo); } + /* Global variables in commands are freed. */ + cmd_free(); + store_config(); ly_ctx_destroy(ctx); |