diff options
Diffstat (limited to 'utils.c')
-rw-r--r-- | utils.c | 60 |
1 files changed, 32 insertions, 28 deletions
@@ -4,85 +4,89 @@ #include <string.h> #include <unistd.h> -int checkIfFileExists(char *path) +int +checkIfFileExists (char *path) { - return access(path, F_OK); + return access (path, F_OK); } -int detectOsType() +int +detectOsType () { int exists = ERROR; - for ( int i = 0; i < ENUMSIZE && exists == ERROR; i++ ) + for (int i = 0; i < ENUMSIZE && exists == ERROR; i++) { switch (i) { - case apt: - if ( checkIfFileExists("/usr/bin/apt" ) == 0 ) - { - exists = i; - } - break; - case dnf: - if ( checkIfFileExists("/usr/bin/dnf" ) == 0 ) + if (checkIfFileExists ("/usr/bin/dnf") == 0) { exists = i; } break; case emerge: - if ( checkIfFileExists("/usr/bin/emerge" ) == 0 ) + if (checkIfFileExists ("/usr/bin/emerge") == 0) { exists = i; } break; case pacman: - if ( checkIfFileExists("/usr/bin/pacman" ) == 0 ) + if (checkIfFileExists ("/usr/bin/pacman") == 0) { exists = i; } break; case xbps: - if ( checkIfFileExists("/usr/bin/xbps-install" ) == 0 ) + if (checkIfFileExists ("/usr/bin/xbps-install") == 0) { exists = i; } break; case zypper: - if ( checkIfFileExists("/usr/bin/zypper" ) == 0 ) + if (checkIfFileExists ("/usr/bin/zypper") == 0) + { + exists = i; + } + break; + + case apt: + if (checkIfFileExists ("/usr/bin/apt") == 0) { exists = i; } break; default: - puts("Unrecognized Package Manager" ); + puts ("Unrecognized Package Manager"); } } return exists; } -char* stringedArgument(int argc, char** argv) +char * +stringedArgument (int argc, char **argv) { int numberOfTotalPackages = argc - 2; - char* arg = (char *) calloc((numberOfTotalPackages * 80), sizeof(char)); + char *arg = (char *)calloc ((numberOfTotalPackages * 80), sizeof (char)); - for( int i = 2; i < argc; i++ ) + for (int i = 2; i < argc; i++) { - strcat(arg, argv[i]); - strcat(arg, " "); + strcat (arg, argv[i]); + strcat (arg, " "); } return arg; } -void commandProcessor(char* packages, char* initCommand) +void +commandProcessor (char *packages, char *initCommand) { - char* command = (char *) calloc(strlen(packages) + 80, sizeof(char)); - strcpy(command, initCommand); - strcat(command, packages); - system(command); - free(command); + char *command = (char *)calloc (strlen (packages) + 80, sizeof (char)); + strcpy (command, initCommand); + strcat (command, packages); + system (command); + free (command); } |