From c8bdc795a958e1808049e88c55198fdc157ddf17 Mon Sep 17 00:00:00 2001 From: ngn Date: Sun, 5 May 2024 23:26:01 +0300 Subject: [PATCH] update: fix formatting --- src/config.c | 2 +- src/pull.c | 24 ++++++++++++------------ src/run.c | 52 ++++++++++++++++++++++++++-------------------------- 3 files changed, 39 insertions(+), 39 deletions(-) diff --git a/src/config.c b/src/config.c index c3ad1a0..3a188c7 100644 --- a/src/config.c +++ b/src/config.c @@ -185,7 +185,7 @@ bool config_load(config_t *config, char *path) { void config_print(config_t *config) { info(_("Configuration details:\n")); printf(COLOR_BOLD " %s " COLOR_RESET "=> %s\n", _("Name"), config->name); - if(NULL != config->desc) + if (NULL != config->desc) printf(COLOR_BOLD " %s " COLOR_RESET "=> %s\n", _("Desc"), config->desc); printf(COLOR_BOLD " %s " COLOR_RESET "=> %s\n", _("Author"), config->author); diff --git a/src/pull.c b/src/pull.c index 902581a..3927e2f 100644 --- a/src/pull.c +++ b/src/pull.c @@ -4,9 +4,9 @@ #include "error.h" #include "log.h" #include "paths.h" +#include "run.h" #include "url.h" #include "util.h" -#include "run.h" #include #include @@ -110,7 +110,7 @@ COPY: info(_("Copying all the targets")); char **argv = NULL; - int argc = 0, indx = 0; + int argc = 0, indx = 0; while (cur && ++counter > 0) { target_print(cur); @@ -127,35 +127,35 @@ COPY: } argc += cur->require.s; - if(0 == argc) + if (0 == argc) goto NEXT; - if(NULL == argv) - argv = malloc(sizeof(char*)*argc); + if (NULL == argv) + argv = malloc(sizeof(char *) * argc); else - argv = realloc(argv, sizeof(char*)*argc); + argv = realloc(argv, sizeof(char *) * argc); - for(int i = 0; i < cur->require.s; i++){ + for (int i = 0; i < cur->require.s; i++) { argv[indx] = cur->require.c[i]; indx++; } -NEXT: + NEXT: cur = cur->next; } - if(NULL == argv){ + if (NULL == argv) { ret = true; goto END; } argc++; - argv = realloc(argv, sizeof(char*)*argc); + argv = realloc(argv, sizeof(char *) * argc); argv[indx] = NULL; - ret = true; + ret = true; info(_("Installing all the requirements")); - if(!run_cmd_root("mp-install", argv)){ + if (!run_cmd_root("mp-install", argv)) { ret = false; error(_("Failed to run the mp-install command")); details(errch); diff --git a/src/run.c b/src/run.c index 40c136c..9dd7d4a 100644 --- a/src/run.c +++ b/src/run.c @@ -1,33 +1,33 @@ -#include +#include #include -#include +#include #include #include -#include -#include +#include +#include #include "error.h" -#include "util.h" #include "run.h" +#include "util.h" extern char **environ; -char *run_find_cmd(char *cmd){ +char *run_find_cmd(char *cmd) { char *path = getenv("PATH"), *save, *el; - while((el = strtok_r(path, ":", &save)) != NULL){ - char fp[strlen(el)+strlen(cmd)+2]; + while ((el = strtok_r(path, ":", &save)) != NULL) { + char fp[strlen(el) + strlen(cmd) + 2]; join(fp, el, cmd); - if(exists(fp)) + if (exists(fp)) return strdup(fp); } return NULL; } -bool run_cmd(char **all){ +bool run_cmd(char **all) { pid_t pid; - if(posix_spawn(&pid, all[0], NULL, NULL, all, environ) != 0) + if (posix_spawn(&pid, all[0], NULL, NULL, all, environ) != 0) return false; int status; @@ -35,20 +35,20 @@ bool run_cmd(char **all){ return status == 0; } -bool run_cmd_root(char *cmd, char **args){ +bool run_cmd_root(char *cmd, char **args) { char *rootcmd = NULL; - if(NULL == run_find_cmd(cmd)){ + if (NULL == run_find_cmd(cmd)) { error_set("Command not found"); errno = RunCmdNotFound; return false; } - if(getuid()==0) + if (getuid() == 0) goto RUN; - else if((rootcmd = run_find_cmd("doas")) != NULL) + else if ((rootcmd = run_find_cmd("doas")) != NULL) goto RUN; - else if((rootcmd = run_find_cmd("sudo" )) != NULL) + else if ((rootcmd = run_find_cmd("sudo")) != NULL) goto RUN; error_set("There is no doas or sudo installed"); @@ -57,32 +57,32 @@ bool run_cmd_root(char *cmd, char **args){ RUN: int arg_count = 0; - while(args[arg_count] != NULL) + while (args[arg_count] != NULL) arg_count++; arg_count += 2; - if(rootcmd != NULL) + if (rootcmd != NULL) arg_count++; - char **all = malloc(arg_count*sizeof(char*)); - int indx = 0; + char **all = malloc(arg_count * sizeof(char *)); + int indx = 0; - if(rootcmd != NULL){ - all[indx] = rootcmd; + if (rootcmd != NULL) { + all[indx] = rootcmd; all[++indx] = cmd; - }else + } else all[indx] = rootcmd; - for(int i = 0; i < arg_count; i++) + for (int i = 0; i < arg_count; i++) all[++indx] = args[i]; all[++indx] = NULL; bool ret = true; - if(!run_cmd(all)){ + if (!run_cmd(all)) { error_set("Command failed"); errno = RunCmdFail; - ret = false; + ret = false; } free(all);