Código C:
Ver original
/* @author: Alberto Jsé <guzzan0> @package: pkgrmd - This package remove all dependences alone of a applications. */ #include <stdlib.h> #include <stdio.h> #include <string.h> #include <sys/types.h> #include <dirent.h> #define VERSION "Dannie27" void search_package(char *package_name); void depends_parser(FILE *pkgfile_dir); int main(int argc, char *argv[]) { if (argc > 1) { { printf("Written by Alberto Jse <guzzan0>\nVersion: %s\n\nPlease report bug to [email protected]\n", VERSION); } { printf("Usage: pkgrmd <commands> or <package to remove>\nExample: pkgrmd wine, pkgrmd xorg, etc.\n\n"); printf("Commands avaiable: \n\n--help (Show this help) \n--info (Show the current version and author)\n"); } else { { } else { search_package(argv[1]); } } } else { } } void search_package(char *package_name) { char *package_n, package_file_lines[225]; int package_install = 0; if (!package_n) { } if (package_installed != NULL) { { { package_install = 1; break; } else { package_install = 0; } } } else { } if (package_install == 1) { DIR *ports_directory, *package_directory; struct dirent *structure_directory, *structure_package; char ports_base[12] = "/usr/ports/", *package_directories = NULL; if ((ports_directory = opendir(ports_base)) != NULL) { while ((structure_directory = readdir(ports_directory)) != NULL) { if (*structure_directory->d_name == '.') continue; if (!package_directories) { } if ((package_directory = opendir(package_directories)) != NULL) { while ((structure_package = readdir(package_directory)) != NULL) { if (*structure_package->d_name == '.') continue; { FILE *pkgbuild; char *depends; if (!depends) { } { } else { printf("[pkgrmd] The package %s not have file pkgfile. Renew pkgfile with commands \"ports -u\" and try again. \n", structure_package->d_name); } break; } } } else { printf("[pkgrmd] This error no is fatal. But I can't open dir: %s%s", package_directories, structure_package->d_name); } } closedir(ports_directory); closedir(package_directory); } else { } } else { printf("[pkgrmd] The package %s not is installed. \n[pkgrmd] Please verify package with: prt-get search [name_package] \n", package_name); } }
Como una duda adicional, ¿estará mal abusar de la función exit()? y he visto ejemplos donde con malloc se tiene que multiplicar lo que queremos abrir por sizeof(char*) ¿tengo que hacerlo?
Muchas gracias, saludos!