diff --git a/locale/tr/LC_MESSAGES/pooler.po b/locale/tr/LC_MESSAGES/pooler.po index cd0c63c..b5eb709 100644 --- a/locale/tr/LC_MESSAGES/pooler.po +++ b/locale/tr/LC_MESSAGES/pooler.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2024-07-19 00:28+0300\n" +"POT-Creation-Date: 2024-07-19 22:32+0300\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -72,241 +72,265 @@ msgstr "" msgid "Please answer with y/n" msgstr "" -#: src/main.c:72 +#: src/main.c:74 msgid "Failed to access the root directory, are you running as root?" msgstr "" -#: src/main.c:74 +#: src/main.c:76 #, fuzzy, c-format msgid "Bad root directory (%s): %s" msgstr "Havuz dizini kullanmak başarısız oldu: %s" -#: src/main.c:82 +#: src/main.c:84 #, c-format msgid "Bad datadir (%s): %s" msgstr "" -#: src/main.c:87 +#: src/main.c:89 #, c-format msgid "Bad tmpdir (%s): %s" msgstr "" -#: src/main.c:94 +#: src/main.c:96 #, fuzzy msgid "Failed to add pool " msgstr "Havuzları sekronize etmek başarısız oldu: %s" -#: src/main.c:107 +#: src/main.c:109 msgid "Command not found: " msgstr "" -#: src/main.c:109 +#: src/main.c:111 #, c-format msgid "MatterLinux package manager (version %s)" msgstr "" -#: src/main.c:110 +#: src/main.c:112 msgid "Usage: " msgstr "" -#: src/main.c:112 +#: src/main.c:114 msgid "Here is a list of available commands:" msgstr "" -#: src/main.c:118 +#: src/main.c:120 msgid "To list different options, use commands with " msgstr "" -#: src/main.c:119 +#: src/main.c:121 msgid "Here is a list of available global options:" msgstr "" -#: src/main.c:122 src/main.c:123 src/cmd/info.c:14 src/cmd/info.c:15 -#: src/cmd/info.c:16 src/cmd/install.c:22 src/cmd/install.c:23 -#: src/cmd/list.c:10 src/cmd/list.c:11 src/cmd/remove.c:17 src/cmd/remove.c:18 -#: src/cmd/update.c:23 +#: src/main.c:124 src/main.c:125 src/cmd/info.c:19 src/cmd/info.c:20 +#: src/cmd/info.c:21 src/cmd/install.c:25 src/cmd/install.c:26 +#: src/cmd/list.c:13 src/cmd/list.c:14 src/cmd/remove.c:20 src/cmd/remove.c:21 +#: src/cmd/update.c:25 #, c-format msgid " " msgstr "" -#: src/main.c:125 +#: src/main.c:127 msgid "" "Licensed under GPLv3, see https://www.gnu.org/licenses/ for more information" msgstr "" -#: src/cmd/info.c:13 src/cmd/list.c:9 +#: src/util.c:83 +msgid "No available editor to open " +msgstr "" + +#: src/util.c:90 +#, fuzzy, c-format +msgid "Failed to run the editor: %s" +msgstr "Sunucuyu başlatmak başarısız oldu: %s" + +#: src/util.c:95 +#, fuzzy, c-format +msgid "Failed to open the editor: %s" +msgstr "Sunucuyu başlatmak başarısız oldu: %s" + +#: src/cmd/info.c:18 src/cmd/list.c:12 msgid "Listing options for the list command:" msgstr "" -#: src/cmd/info.c:36 +#: src/cmd/info.c:41 msgid "Please specify only a single package name" msgstr "" -#: src/cmd/info.c:42 +#: src/cmd/info.c:47 #, fuzzy msgid "Please specify a single package" msgstr "Lütfen konfigürasyonda en az bir havuz belirtin" -#: src/cmd/info.c:48 src/cmd/info.c:54 src/cmd/install.c:56 src/cmd/remove.c:42 +#: src/cmd/info.c:53 src/cmd/info.c:59 src/cmd/install.c:59 src/cmd/remove.c:45 msgid "Package " msgstr "" -#: src/cmd/info.c:59 +#: src/cmd/info.c:64 #, fuzzy msgid "Failed to get the changes file for " msgstr "%s: paket listesini yüklemek başarısız oldu (%s)" -#: src/cmd/info.c:91 +#: src/cmd/info.c:70 +#, fuzzy +msgid "Failed to access the changes file, is the package installed?" +msgstr "%s: paket listesini yüklemek başarısız oldu (%s)" + +#: src/cmd/info.c:77 +#, fuzzy +msgid "Failed to get the depends list for " +msgstr "%s: paket listesini yüklemek başarısız oldu (%s)" + +#: src/cmd/info.c:104 #, c-format msgid "Name " msgstr "" -#: src/cmd/info.c:92 +#: src/cmd/info.c:105 #, c-format msgid "Version " msgstr "" -#: src/cmd/info.c:93 +#: src/cmd/info.c:106 #, c-format msgid "Desc " msgstr "" -#: src/cmd/info.c:94 +#: src/cmd/info.c:107 #, c-format msgid "Size " msgstr "" -#: src/cmd/info.c:97 +#: src/cmd/info.c:110 #, c-format msgid "Depends " msgstr "" -#: src/cmd/info.c:100 +#: src/cmd/info.c:113 #, c-format msgid "Changes " msgstr "" -#: src/cmd/info.c:104 src/cmd/info.c:105 +#: src/cmd/info.c:117 src/cmd/info.c:118 #, c-format msgid "Installed " msgstr "" -#: src/cmd/info.c:107 src/cmd/info.c:108 +#: src/cmd/info.c:120 src/cmd/info.c:121 #, c-format msgid "Up-to-date " msgstr "" -#: src/cmd/install.c:21 +#: src/cmd/install.c:24 msgid "Listing options for the install command:" msgstr "" -#: src/cmd/install.c:28 src/cmd/update.c:28 +#: src/cmd/install.c:31 src/cmd/update.c:30 msgid "There are no avaliable pools, have you synced yet?" msgstr "" -#: src/cmd/install.c:48 src/cmd/remove.c:44 +#: src/cmd/install.c:51 src/cmd/remove.c:47 #, fuzzy msgid "Failed to find " msgstr "Havuzları sekronize etmek başarısız oldu: %s" -#: src/cmd/install.c:62 +#: src/cmd/install.c:65 #, fuzzy msgid "Failed to resolve " msgstr "Havuzları sekronize etmek başarısız oldu: %s" -#: src/cmd/install.c:68 +#: src/cmd/install.c:71 msgid "Nothing to do (no packages to install)" msgstr "" -#: src/cmd/install.c:77 src/cmd/remove.c:64 src/cmd/update.c:48 +#: src/cmd/install.c:80 src/cmd/remove.c:67 src/cmd/update.c:50 #, c-format msgid "Following %d package will be " msgstr "" -#: src/cmd/install.c:79 src/cmd/remove.c:66 src/cmd/update.c:50 +#: src/cmd/install.c:82 src/cmd/remove.c:69 src/cmd/update.c:52 #, c-format msgid "Following %d packages will be " msgstr "" -#: src/cmd/install.c:85 src/cmd/remove.c:73 +#: src/cmd/install.c:88 src/cmd/remove.c:76 msgid "Total of " msgstr "" -#: src/cmd/install.c:86 src/cmd/remove.c:74 src/cmd/update.c:56 +#: src/cmd/install.c:89 src/cmd/remove.c:77 src/cmd/update.c:58 msgid "Continue?" msgstr "" -#: src/cmd/install.c:87 src/cmd/remove.c:75 src/cmd/update.c:57 +#: src/cmd/install.c:90 src/cmd/remove.c:78 src/cmd/update.c:59 msgid "Operation cancelled" msgstr "" -#: src/cmd/install.c:93 src/cmd/update.c:67 +#: src/cmd/install.c:96 src/cmd/update.c:69 #, c-format msgid "(%d/%d) Downloading " msgstr "" -#: src/cmd/install.c:99 src/cmd/update.c:72 +#: src/cmd/install.c:102 src/cmd/update.c:74 #, fuzzy msgid "Failed to download " msgstr "Havuzları sekronize etmek başarısız oldu: %s" -#: src/cmd/install.c:108 src/cmd/update.c:85 +#: src/cmd/install.c:111 src/cmd/update.c:87 #, c-format msgid "(%d/%d) Installing " msgstr "" -#: src/cmd/install.c:114 src/cmd/update.c:90 +#: src/cmd/install.c:117 src/cmd/update.c:92 #, fuzzy msgid "Failed to install " msgstr "Havuzları sekronize etmek başarısız oldu: %s" -#: src/cmd/install.c:120 +#: src/cmd/install.c:123 #, c-format msgid "Installed %d package" msgstr "" -#: src/cmd/install.c:120 +#: src/cmd/install.c:123 #, c-format msgid "Installed all of the %d packages" msgstr "" -#: src/cmd/list.c:24 +#: src/cmd/list.c:27 msgid "There no installed packages" msgstr "" -#: src/cmd/list.c:29 +#: src/cmd/list.c:32 msgid "Listing " msgstr "" -#: src/cmd/remove.c:16 +#: src/cmd/remove.c:19 msgid "Listing options for the remove command:" msgstr "" -#: src/cmd/remove.c:49 +#: src/cmd/remove.c:52 #, fuzzy msgid "Cannot remove " msgstr "Havuzları sekronize etmek başarısız oldu: %s" -#: src/cmd/remove.c:57 +#: src/cmd/remove.c:60 msgid "Nothing to do (no packages to remove)" msgstr "" -#: src/cmd/remove.c:82 src/cmd/update.c:76 +#: src/cmd/remove.c:85 src/cmd/update.c:78 #, c-format msgid "(%d/%d) Removing " msgstr "" -#: src/cmd/remove.c:88 src/cmd/update.c:81 +#: src/cmd/remove.c:91 src/cmd/update.c:83 #, fuzzy msgid "Failed to remove " msgstr "Havuzları sekronize etmek başarısız oldu: %s" -#: src/cmd/remove.c:94 +#: src/cmd/remove.c:97 #, c-format msgid "Removed %d package" msgstr "" -#: src/cmd/remove.c:94 +#: src/cmd/remove.c:97 #, c-format msgid "Removed all of the %d packages" msgstr "" @@ -335,20 +359,20 @@ msgstr "Lütfen konfigürasyonda en az bir havuz belirtin" msgid "Failed to sync pools: %s" msgstr "Havuzları sekronize etmek başarısız oldu: %s" -#: src/cmd/update.c:22 +#: src/cmd/update.c:24 msgid "Listing options for the update command:" msgstr "" -#: src/cmd/update.c:38 +#: src/cmd/update.c:40 #, fuzzy, c-format msgid "Failed to get the package update list: %s" msgstr "%s: paket listesini yüklemek başarısız oldu (%s)" -#: src/cmd/update.c:43 +#: src/cmd/update.c:45 msgid "All packages are up-to-date" msgstr "" -#: src/cmd/update.c:63 +#: src/cmd/update.c:65 #, fuzzy msgid "Failed to update " msgstr "Havuzları sekronize etmek başarısız oldu: %s" @@ -393,7 +417,3 @@ msgstr "Havuzları sekronize etmek başarısız oldu: %s" #, c-format #~ msgid "Serving %lu pools on %s" #~ msgstr "%lu tane havuz %s adresinde sunuluyor" - -#, c-format -#~ msgid "Failed to start the server: %s" -#~ msgstr "Sunucuyu başlatmak başarısız oldu: %s" diff --git a/src/args.c b/src/args.c index a806b46..9633a70 100644 --- a/src/args.c +++ b/src/args.c @@ -7,7 +7,7 @@ #include "args.h" #include "util.h" -void args_add(args_t *args, char *name) { +void args_add_name(args_t *args, char *name) { if (NULL == args->list) args->list = malloc(sizeof(arg_t) * (args->count + 1)); else @@ -18,11 +18,6 @@ void args_add(args_t *args, char *name) { } void args_add_value(args_t *args, char *value) { - if (NULL != args->list && args->list[args->count - 1].value == NULL) { - args->list[args->count - 1].value = value; - return; - } - if (NULL == args->list) args->list = malloc(sizeof(arg_t) * (args->count + 1)); else @@ -32,6 +27,34 @@ void args_add_value(args_t *args, char *value) { args->list[args->count++].value = value; } +void args_set_value(args_t *args, char *value) { + if (NULL != args->list && args->list[args->count - 1].value == NULL) { + args->list[args->count - 1].value = value; + return; + } + + args_add_value(args, value); +} + +bool args_split(args_t *args, char *name) { + char *value = NULL; + + for (int i = 0; i < args->count; i++) { + if (NULL == args->list[i].name || !eq(args->list[i].name, name)) + continue; + + value = args->list[i].value; + args->list[i].value = NULL; + break; + } + + if (NULL == value) + return false; + + args_add_value(args, value); + return true; +} + args_t *args_parse(int argc, char *argv[]) { args_t *args = malloc(sizeof(args_t)); bzero(args, sizeof(args_t)); @@ -41,9 +64,9 @@ args_t *args_parse(int argc, char *argv[]) { for (int i = 1; i < argc; i++) { if (startswith(argv[i], "--")) - args_add(args, argv[i] + 2); + args_add_name(args, argv[i] + 2); else - args_add_value(args, argv[i]); + args_set_value(args, argv[i]); } return args; diff --git a/src/args.h b/src/args.h index a2a5cfa..bb74276 100644 --- a/src/args.h +++ b/src/args.h @@ -15,4 +15,5 @@ args_t *args_parse(int argc, char *argv[]); char *args_get_string(args_t *args, char *name); bool args_get_bool(args_t *args, char *name); int args_get_int(args_t *args, char *name); +bool args_split(args_t *args, char *name); void args_free(args_t *args); diff --git a/src/cmd/info.c b/src/cmd/info.c index 342f0d7..6ce3593 100644 --- a/src/cmd/info.c +++ b/src/cmd/info.c @@ -3,12 +3,17 @@ #include #include #include +#include #include "../util.h" #include "../cmd.h" #include "../log.h" bool cmd_info(lm_ctx_t *ctx, config_t *config, args_t *args){ + args_split(args, "grep"); + args_split(args, "changes"); + args_split(args, "database"); + if(args_get_bool(args, "help")){ info(_("Listing options for the list command:")); printf(_(" "FG_BOLD"--grep"FG_RESET":\tmakes the output \"grepable\"\n")); @@ -20,7 +25,7 @@ bool cmd_info(lm_ctx_t *ctx, config_t *config, args_t *args){ if(!args_get_bool(args, "database")) lm_ctx_sync(ctx, false, NULL, NULL); - char *name = NULL, *changes = NULL; + char *name = NULL, *depends = NULL, *changes = NULL; lm_pkg_t pkg, *pkgp = &pkg; for(size_t i = 0; i < args->count; i++){ @@ -57,20 +62,28 @@ bool cmd_info(lm_ctx_t *ctx, config_t *config, args_t *args){ if((changes = lm_ctx_database_changes(ctx, pkgp)) == NULL && LM_ERR_DbChangesNotExists != lm_error()){ error(_("Failed to get the changes file for "FG_BOLD"%s"FG_RESET"_"FG_BOLD FG_GREEN"%s"FG_RESET": %s"), pkgp->name, pkgp->version, lm_strerror()); - return false; + goto end; } - // TODO: open the changes file with the preferred editor if --changes is set + if(args_get_bool(args, "changes")){ + if(NULL == changes) + error(_("Failed to access the changes file, is the package installed?")); + else + editor_open(changes); + goto end; + } - char depends[lm_package_depend_strlen(pkgp)+1]; - lm_package_depend_tostr(pkgp, depends); + if((depends = lm_package_depend_tostr(pkgp, NULL)) == NULL){ + error(_("Failed to get the depends list for "FG_BOLD"%s"FG_RESET"_"FG_BOLD FG_GREEN"%s"FG_RESET": %s"), pkgp->name, pkgp->version, lm_strerror()); + goto end; + } if(args_get_bool(args, "grep")){ printf("NAME:%s\n", pkgp->name); printf("VERSION:%s\n", pkgp->version); printf("DESC:%s\n", pkgp->desc); printf("SIZE:%lu\n", pkgp->size); - + if(lm_package_depend_count(pkgp) > 0) printf("DEPENDS:%s\n", depends); @@ -81,7 +94,7 @@ bool cmd_info(lm_ctx_t *ctx, config_t *config, args_t *args){ printf("INSTALLED:%d\n", lm_ctx_database_is_installed(ctx, pkgp, false)); printf("UPTODATE:%d\n", lm_ctx_database_is_installed(ctx, pkgp, true)); } - + goto end; } @@ -92,18 +105,18 @@ bool cmd_info(lm_ctx_t *ctx, config_t *config, args_t *args){ printf(_(FG_BOLD"Version "FG_BLUE"=>"FG_RESET" %s\n"), pkgp->version); printf(_(FG_BOLD"Desc "FG_BLUE"=>"FG_RESET" %s\n"), pkgp->desc); printf(_(FG_BOLD"Size "FG_BLUE"=>"FG_RESET" %s\n"), ssize); - + if(lm_package_depend_count(pkgp) > 0) printf(_(FG_BOLD"Depends "FG_BLUE"=>"FG_RESET" %s\n"), depends); if(NULL != changes) printf(_(FG_BOLD"Changes "FG_BLUE"=>"FG_RESET" %s\n"), changes); - + if(!args_get_bool(args, "database")){ - printf(lm_ctx_database_is_installed(ctx, pkgp, false) ? + printf(lm_ctx_database_is_installed(ctx, pkgp, false) ? _(FG_BOLD"Installed "FG_BLUE"=>"FG_RESET" "FG_GREEN"yes"FG_RESET"\n") : _(FG_BOLD"Installed "FG_BLUE"=>"FG_RESET" "FG_RED"no"FG_RESET"\n")); - printf(lm_ctx_database_is_installed(ctx, pkgp, true) ? + printf(lm_ctx_database_is_installed(ctx, pkgp, true) ? _(FG_BOLD"Up-to-date "FG_BLUE"=>"FG_RESET" "FG_GREEN"yes"FG_RESET"\n") : _(FG_BOLD"Up-to-date "FG_BLUE"=>"FG_RESET" "FG_RED"no"FG_RESET"\n")); } @@ -111,5 +124,9 @@ bool cmd_info(lm_ctx_t *ctx, config_t *config, args_t *args){ end: if(args_get_bool(args, "database")) lm_package_free(pkgp); + + free(changes); + free(depends); + return true; } diff --git a/src/cmd/install.c b/src/cmd/install.c index bff06a9..0f4b2f1 100644 --- a/src/cmd/install.c +++ b/src/cmd/install.c @@ -6,7 +6,7 @@ #include "../log.h" bool cmd_install_callback(lm_ctx_t *ctx, lm_pkg_t *pkg, char *file, size_t current, size_t total, void *data){ - bar(current, total); + bar(current, total); return true; } @@ -17,6 +17,9 @@ bool cmd_download_callback(lm_ctx_t *ctx, lm_pkg_t *pkg, bool is_archive, size_t } bool cmd_install(lm_ctx_t *ctx, config_t *config, args_t *args){ + args_split(args, "continue"); + args_split(args, "yes"); + if(args_get_bool(args, "help")){ info(_("Listing options for the install command:")); printf(_(" "FG_BOLD"--continue"FG_RESET":\tcontinue even if package is not found\n")); @@ -28,7 +31,7 @@ bool cmd_install(lm_ctx_t *ctx, config_t *config, args_t *args){ error(_("There are no avaliable pools, have you synced yet?")); return false; } - + lm_ctx_resolve_list_t *list = NULL; ssize_t current = 0, size = 0, save = 0; bool ret = false, r = false; @@ -56,7 +59,7 @@ bool cmd_install(lm_ctx_t *ctx, config_t *config, args_t *args){ error(_("Package "FG_BOLD"%s"FG_RESET" ("FG_BLUE"%s"FG_RESET") is already installed"), name, pkg->version); goto end; } - + // resolve the package and depends if((list = lm_ctx_resolve(ctx, pkg, list)) == NULL){ error(_("Failed to resolve "FG_BOLD"%s"FG_RESET": %s"), name, lm_strerror()); @@ -68,7 +71,7 @@ bool cmd_install(lm_ctx_t *ctx, config_t *config, args_t *args){ error(_("Nothing to do (no packages to install)")); goto end; } - + while((pkg = lm_ctx_resolve_next(list)) != NULL) size += pkg->size; size_to_human(ssize, size); @@ -77,7 +80,7 @@ bool cmd_install(lm_ctx_t *ctx, config_t *config, args_t *args){ info(_("Following %d package will be "FG_BOLD"INSTALLED:"FG_RESET), list->count); else info(_("Following %d packages will be "FG_BOLD"INSTALLED:"FG_RESET), list->count); - + while((pkg = lm_ctx_resolve_next(list)) != NULL) package_list(pkg, &save, 0); printf("\n"); diff --git a/src/cmd/list.c b/src/cmd/list.c index daa09a9..eed4c6d 100644 --- a/src/cmd/list.c +++ b/src/cmd/list.c @@ -5,13 +5,16 @@ #include "../log.h" bool cmd_list(lm_ctx_t *ctx, config_t *config, args_t *args){ + args_split(args, "grep"); + args_split(args, "desc"); + if(args_get_bool(args, "help")){ info(_("Listing options for the list command:")); printf(_(" "FG_BOLD"--grep"FG_RESET":\tmakes the output \"grepable\"\n")); printf(_(" "FG_BOLD"--desc"FG_RESET":\tshow package descriptions\n")); return true; } - + ssize_t count = 0; lm_pkg_t pkg; diff --git a/src/cmd/remove.c b/src/cmd/remove.c index 7c54c75..427024f 100644 --- a/src/cmd/remove.c +++ b/src/cmd/remove.c @@ -7,11 +7,14 @@ #include "../log.h" bool cmd_remove_callback(lm_ctx_t *ctx, lm_pkg_t *pkg, char *file, size_t current, size_t total, void *data){ - bar(current, total); + bar(current, total); return true; } bool cmd_remove(lm_ctx_t *ctx, config_t *config, args_t *args){ + args_split(args, "break"); + args_split(args, "yes"); + if(args_get_bool(args, "help")){ info(_("Listing options for the remove command:")); printf(_(" "FG_BOLD"--break"FG_RESET":\tbreak other package depends\n")); @@ -64,7 +67,7 @@ bool cmd_remove(lm_ctx_t *ctx, config_t *config, args_t *args){ info(_("Following %d package will be "FG_BOLD"REMOVED:"FG_RESET), count); else info(_("Following %d packages will be "FG_BOLD"REMOVED:"FG_RESET), count); - + // list all the packages for(int i = 0; i < count; i++) package_list(&pkgs[i], &save, 0); @@ -89,11 +92,11 @@ bool cmd_remove(lm_ctx_t *ctx, config_t *config, args_t *args){ goto end; } } - + if(current == count){ success(count == 1 ? _("Removed %d package") : _("Removed all of the %d packages"), count); ret = true; - } + } ret = true; end: diff --git a/src/cmd/sync.c b/src/cmd/sync.c index b8425aa..7b092ec 100644 --- a/src/cmd/sync.c +++ b/src/cmd/sync.c @@ -9,8 +9,8 @@ bool cmd_sync_callback(lm_ctx_t *ctx, lm_pool_t *pool, lm_ctx_sync_state_t state case SYNC_DOWNLOADING_INFO: bar(current, total); break; - - case SYNC_INFO_SUCCESS: + + case SYNC_INFO_SUCCESS: bar_free(); break; diff --git a/src/cmd/update.c b/src/cmd/update.c index eb32571..7039a1a 100644 --- a/src/cmd/update.c +++ b/src/cmd/update.c @@ -7,7 +7,7 @@ #include "../log.h" bool cmd_update_callback(lm_ctx_t *ctx, lm_pkg_t *pkg, char *file, size_t current, size_t total, void *data){ - bar(current, total); + bar(current, total); return true; } @@ -18,6 +18,8 @@ bool cmd_update_download_callback(lm_ctx_t *ctx, lm_pkg_t *pkg, bool is_archive, } bool cmd_update(lm_ctx_t *ctx, config_t *config, args_t *args){ + args_split(args, "yes"); + if(args_get_bool(args, "help")){ info(_("Listing options for the update command:")); printf(_(" "FG_BOLD"--yes"FG_RESET":\tdon't ask for confirmation\n")); @@ -48,7 +50,7 @@ bool cmd_update(lm_ctx_t *ctx, config_t *config, args_t *args){ info(_("Following %d package will be "FG_BOLD"UPDATED:"FG_RESET), list->count); else info(_("Following %d packages will be "FG_BOLD"UPDATED:"FG_RESET), list->count); - + while((old = lm_ctx_update_list_next(list)) != NULL) package_list(old, &save, 0); printf("\n"); diff --git a/src/main.c b/src/main.c index 8e0addf..ccc3ead 100644 --- a/src/main.c +++ b/src/main.c @@ -34,8 +34,9 @@ #include "config.h" #include "intl.h" #include "log.h" +#include "util.h" -int main(int argc, char *argv[]) { +int main(int argc, char *argv[], char *envp[]) { cmd_t commands[] = { {.name = "info", .desc = "show information about a single package", .func = cmd_info }, {.name = "list", .desc = "list all the installed packages", .func = cmd_list }, @@ -52,6 +53,7 @@ int main(int argc, char *argv[]) { config_t config; lm_ctx_t ctx; + set_env(envp); lm_ctx_init(&ctx); args = args_parse(argc, argv); diff --git a/src/util.c b/src/util.c index 1f45eb8..b4c3323 100644 --- a/src/util.c +++ b/src/util.c @@ -1,9 +1,21 @@ +#include +#include +#include #include #include #include +#include +#include +#include "log.h" #include "util.h" +char **env = NULL; + +void set_env(char **envp) { + env = envp; +} + bool startswith(char *str, char *sub) { size_t strl = strlen(str); size_t subl = strlen(sub); @@ -28,3 +40,63 @@ void size_to_human(char *buf, long size) { sprintf(buf, "%.02lf%s", cursize, suffix[i]); } + +char *exists_in_path(char *file) { + if (NULL == file) + return NULL; + + char *path = NULL, *part = NULL, *save = NULL; + size_t filesz = strlen(file); + + if ((path = getenv("PATH")) == NULL) + path = "/bin"; + + if ((part = strtok_r(path, ":", &save)) == NULL) + return false; + + do { + char fp[strlen(part) + filesz + 1]; + join(fp, part, file); + + if (exists(fp)) + return strdup(fp); + } while ((part = strtok_r(NULL, ":", &save)) != NULL); + + return NULL; +} + +void editor_open(char *file) { + if (NULL == file) + return; + + char *editors[] = {getenv("EDITOR"), "nano", "vi", "vim"}; + int status = 0, i = 0; + char *editor = NULL; + pid_t pid = 0; + + for (; i < sizeof(editors) / sizeof(char *); i++) { + if ((editor = exists_in_path(editors[i])) != NULL) + break; + } + + if (NULL == editor) { + error(_("No available editor to open " FG_BOLD "%s" FG_RESET), file); + return; + } + + char *argv[] = {editor, file, NULL}; + + if (posix_spawnp(&pid, argv[0], NULL, NULL, argv, env) != 0) { + error(_("Failed to run the editor: %s"), strerror(errno)); + goto end; + } + + if (waitpid(pid, &status, 0) < 0) { + error(_("Failed to open the editor: %s"), strerror(errno)); + goto end; + } + +end: + free(editor); + return; +} diff --git a/src/util.h b/src/util.h index 870848c..a78380a 100644 --- a/src/util.h +++ b/src/util.h @@ -3,5 +3,8 @@ #define LONGSTR_MAX 30 -bool startswith(char *str, char *sub); -void size_to_human(char *buf, long size); +void set_env(char **envp); +bool startswith(char *str, char *sub); +void size_to_human(char *buf, long size); +char *exists_in_path(char *file); +void editor_open(char *file);