From: Michael Tremer Date: Wed, 27 Sep 2023 15:19:40 +0000 (+0000) Subject: libpakfire: Drop old CLI functions X-Git-Tag: 0.9.30~1626 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b9dd20735801fc267db44f2b735b2db16881f727;p=pakfire.git libpakfire: Drop old CLI functions Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index df06fd713..4234668b8 100644 --- a/Makefile.am +++ b/Makefile.am @@ -251,7 +251,6 @@ libpakfire_la_SOURCES = \ src/libpakfire/solution.c \ src/libpakfire/string.c \ src/libpakfire/transaction.c \ - src/libpakfire/ui.c \ src/libpakfire/util.c pkginclude_HEADERS += \ @@ -292,7 +291,6 @@ pkginclude_HEADERS += \ src/libpakfire/include/pakfire/solution.h \ src/libpakfire/include/pakfire/string.h \ src/libpakfire/include/pakfire/transaction.h \ - src/libpakfire/include/pakfire/ui.h \ src/libpakfire/include/pakfire/util.h libpakfire_la_CFLAGS = \ diff --git a/src/libpakfire/include/pakfire/ui.h b/src/libpakfire/include/pakfire/ui.h deleted file mode 100644 index c319930a6..000000000 --- a/src/libpakfire/include/pakfire/ui.h +++ /dev/null @@ -1,32 +0,0 @@ -/*############################################################################# -# # -# Pakfire - The IPFire package management system # -# Copyright (C) 2021 Pakfire development team # -# # -# This program is free software: you can redistribute it and/or modify # -# it under the terms of the GNU General Public License as published by # -# the Free Software Foundation, either version 3 of the License, or # -# (at your option) any later version. # -# # -# This program is distributed in the hope that it will be useful, # -# but WITHOUT ANY WARRANTY; without even the implied warranty of # -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # -# GNU General Public License for more details. # -# # -# You should have received a copy of the GNU General Public License # -# along with this program. If not, see . # -# # -#############################################################################*/ - -#ifndef PAKFIRE_UI_H -#define PAKFIRE_UI_H - -#ifdef PAKFIRE_PRIVATE - -#include - -int pakfire_ui_pick_solution(struct pakfire* pakfire, struct pakfire_transaction* transaction); - -#endif - -#endif /* PAKFIRE_UI_H */ diff --git a/src/libpakfire/pakfire.c b/src/libpakfire/pakfire.c index d8e5fa61f..a1a4d203e 100644 --- a/src/libpakfire/pakfire.c +++ b/src/libpakfire/pakfire.c @@ -59,7 +59,6 @@ #include #include #include -#include #include #define LOCK_PATH PAKFIRE_PRIVATE_DIR "/.lock" diff --git a/src/libpakfire/transaction.c b/src/libpakfire/transaction.c index 3f1f24ec2..b2e7d54ef 100644 --- a/src/libpakfire/transaction.c +++ b/src/libpakfire/transaction.c @@ -42,7 +42,6 @@ #include #include #include -#include #include struct pakfire_transaction { diff --git a/src/libpakfire/ui.c b/src/libpakfire/ui.c deleted file mode 100644 index 1e47500af..000000000 --- a/src/libpakfire/ui.c +++ /dev/null @@ -1,197 +0,0 @@ -/*############################################################################# -# # -# Pakfire - The IPFire package management system # -# Copyright (C) 2021 Pakfire development team # -# # -# This program is free software: you can redistribute it and/or modify # -# it under the terms of the GNU General Public License as published by # -# the Free Software Foundation, either version 3 of the License, or # -# (at your option) any later version. # -# # -# This program is distributed in the hope that it will be useful, # -# but WITHOUT ANY WARRANTY; without even the implied warranty of # -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # -# GNU General Public License for more details. # -# # -# You should have received a copy of the GNU General Public License # -# along with this program. If not, see . # -# # -#############################################################################*/ - -#include -#include -#include - -#include -#include -#include -#include -#include - -static int pakfire_ui_is_interactive(struct pakfire* pakfire) { - if (!isatty(STDIN_FILENO)) - return 1; - - if (!isatty(STDOUT_FILENO)) - return 1; - - if (!isatty(STDERR_FILENO)) - return 1; - - return 0; -} - -static int pakfire_ui_enter_number(struct pakfire* pakfire, const char* question, - unsigned int* choice, unsigned int min, unsigned int max) { - char* line = NULL; - size_t length = 0; - char* remainder = NULL; - int r = 1; - - while (1) { - // Print question - printf("%s ", question); - - // Do not wait for any input if the terminal isn't interactive - if (!pakfire_ui_is_interactive(pakfire)) - break; - - // Wait for the user to enter something - ssize_t bytes_read = getline(&line, &length, stdin); - if (bytes_read < 0) - goto ERROR; - - // Convert input into an integer - unsigned long int value = strtoul(line, &remainder, 10); - - // The remainder must point to newline - if (!remainder || *remainder != '\n') - goto AGAIN; - - // The value must be within bounds - if (value < min || value > max) - goto AGAIN; - - // Store choice - *choice = value; - r = 0; - break; - -AGAIN: - printf(_("Invalid value\n")); - } - -ERROR: - if (line) - free(line); - - return r; -} - -static struct pakfire_solution** pakfire_ui_append_solution( - struct pakfire_solution** list, struct pakfire_solution* solution) { - unsigned int length = 0; - - // Count length of list - if (list) { - for (struct pakfire_solution** s = list; *s; s++) - length++; - } - - // Increase array size - list = reallocarray(list, length + 2, sizeof(*list)); - if (!list) - return NULL; - - // Append the new element to the list - list[length] = pakfire_solution_ref(solution); - - // Terminate the list - list[length + 1] = NULL; - - return list; -} - -int pakfire_ui_pick_solution(struct pakfire* pakfire, struct pakfire_transaction* transaction) { -#if 0 - struct pakfire_problem* problem = NULL; - struct pakfire_solution** solutions = NULL; - struct pakfire_solution* solution = NULL; - unsigned int num_solutions = 0; - int r; - - // Print a headline - printf("%s\n", _("One or more problems have occurred solving your request:")); - - // Print all problems - for (;;) { - r = pakfire_transaction_next_problem(transaction, &problem); - if (r) - goto ERROR; - - // No more problems - if (!problem) - break; - - const char* s = pakfire_problem_to_string(problem); - - printf(" * %s\n", s); - - // Show a little headline - printf(" %s\n", _("Possible solutions:")); - - for (;;) { - r = pakfire_problem_next_solution(problem, &solution); - if (r) - goto ERROR; - - // No more solutions - if (!solution) - break; - - // Append the solution to the list - solutions = pakfire_ui_append_solution(solutions, solution); - if (!solutions) - goto ERROR; - - s = pakfire_solution_to_string(solution); - - printf(" [%d] %s\n", ++num_solutions, s); - } - - // Empty line - printf("\n"); - } - - unsigned int choice = 0; - - // Let the user choose which solution they want - r = pakfire_ui_enter_number(pakfire, _("Please select a solution:"), - &choice, 1, num_solutions); - if (r) - goto ERROR; - - // Choice is invalid - if (!choice) - goto ERROR; - - // Fetch selected solution into the solver - r = pakfire_transaction_take_solution(transaction, solutions[choice - 1]); - if (r) - goto ERROR; - - // Success - r = 0; - -ERROR: - if (solutions) { - for (struct pakfire_solution** s = solutions; *s; s++) - pakfire_solution_unref(*s); - free(solutions); - } - - return r; -#endif - - return 0; -}