summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Woodward2018-06-21 21:37:05 -0400
committerJason Woodward2018-06-21 22:18:30 -0400
commitc62c2b4ac3d3f475c4a5f29d6040c3e2c3509315 (patch)
treea81343111738115ab9d0c9ef3ccc499b2a80091b
parent9588ee992d040e92fb2cd91c88fce32df6441c6f (diff)
downloadslapt-src-c62c2b4ac3d3f475c4a5f29d6040c3e2c3509315.tar.gz
clang-format fixups
-rw-r--r--src/main.c872
-rw-r--r--src/source.c1644
-rw-r--r--src/source.h85
3 files changed, 1302 insertions, 1299 deletions
diff --git a/src/main.c b/src/main.c
index c60bdd0..bdbe53d 100644
--- a/src/main.c
+++ b/src/main.c
@@ -28,7 +28,6 @@
#include <config.h>
#include "source.h"
-
#define BUILD_ONLY_FLAG 1
#define FETCH_ONLY_FLAG 2
@@ -36,53 +35,53 @@
extern char *optarg;
extern int optind, opterr, optopt;
-static int show_summary (slapt_src_slackbuild_list *, slapt_list_t *, int, bool);
-static void clean (slapt_src_config *config);
-static int sb_compare_by_name (const void *a, const void *b);
+static int show_summary(slapt_src_slackbuild_list *, slapt_list_t *, int, bool);
+static void clean(slapt_src_config *config);
+static int sb_compare_by_name(const void *a, const void *b);
-void version (void)
+void version(void)
{
- printf (gettext ("%s version %s\n"), PACKAGE, VERSION);
- printf ("Jason Woodward <woodwardj at jaos dot org>\n");
- printf ("\n");
- printf ("This program is free software; you can redistribute it and/or modify\n");
- printf ("it under the terms of the GNU General Public License as published by\n");
- printf ("the Free Software Foundation; either version 2 of the License, or\n");
- printf ("any later version.\n");
- printf ("This program is distributed in the hope that it will be useful,\n");
- printf ("\n");
- printf ("but WITHOUT ANY WARRANTY; without even the implied warranty of\n");
- printf ("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n");
- printf ("GNU Library General Public License for more details.\n");
- printf ("\n");
- printf ("You should have received a copy of the GNU General Public License\n");
- printf ("along with this program; if not, write to the Free Software\n");
- printf ("Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n");
+ printf(gettext("%s version %s\n"), PACKAGE, VERSION);
+ printf("Jason Woodward <woodwardj at jaos dot org>\n");
+ printf("\n");
+ printf("This program is free software; you can redistribute it and/or modify\n");
+ printf("it under the terms of the GNU General Public License as published by\n");
+ printf("the Free Software Foundation; either version 2 of the License, or\n");
+ printf("any later version.\n");
+ printf("This program is distributed in the hope that it will be useful,\n");
+ printf("\n");
+ printf("but WITHOUT ANY WARRANTY; without even the implied warranty of\n");
+ printf("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n");
+ printf("GNU Library General Public License for more details.\n");
+ printf("\n");
+ printf("You should have received a copy of the GNU General Public License\n");
+ printf("along with this program; if not, write to the Free Software\n");
+ printf("Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n");
}
-void help (void)
+void help(void)
{
- printf (gettext ("%s - A SlackBuild utility\n"), PACKAGE);
- printf (gettext ("Usage: %s [option(s)] [action] [slackbuild(s)]\n"), PACKAGE);
- printf (" -u, --update %s\n", gettext ("update local cache of remote slackbuilds"));
- printf (" -U, --upgrade-all %s\n", gettext ("upgrade all installed slackbuilds"));
- printf (" -l, --list %s\n", gettext ("list available slackbuilds"));
- printf (" -e, --clean %s\n", gettext ("clean build directory"));
- printf (" -s, --search %s\n", gettext ("search available slackbuilds"));
- printf (" -w, --show %s\n", gettext ("show specified slackbuilds"));
- printf (" -i, --install %s\n", gettext ("fetch, build, and install the specified slackbuild(s)"));
- printf (" -b, --build %s\n", gettext ("only fetch and build the specified slackbuild(s)"));
- printf (" -f, --fetch %s\n", gettext ("only fetch the specified slackbuild(s)"));
- printf (" -v, --version\n");
- printf (" -h, --help\n");
- printf (" %s:\n", gettext ("Options") );
- printf (" -y, --yes %s\n", gettext ("do not prompt"));
- printf (" -t, --simulate %s\n", gettext ("show what will be done"));
- printf (" -c, --config=FILE %s\n", gettext ("use the specified configuration file"));
- printf (" -n, --no-dep %s\n", gettext ("do not look for dependencies"));
- printf (" -p, --postprocess=CMD %s\n", gettext ("run specified command on generated package"));
- printf (" -B, --build-only %s\n", gettext ("applicable only to --upgrade-all"));
- printf (" -F, --fetch-only %s\n", gettext ("applicable only to --upgrade-all"));
+ printf(gettext("%s - A SlackBuild utility\n"), PACKAGE);
+ printf(gettext("Usage: %s [option(s)] [action] [slackbuild(s)]\n"), PACKAGE);
+ printf(" -u, --update %s\n", gettext("update local cache of remote slackbuilds"));
+ printf(" -U, --upgrade-all %s\n", gettext("upgrade all installed slackbuilds"));
+ printf(" -l, --list %s\n", gettext("list available slackbuilds"));
+ printf(" -e, --clean %s\n", gettext("clean build directory"));
+ printf(" -s, --search %s\n", gettext("search available slackbuilds"));
+ printf(" -w, --show %s\n", gettext("show specified slackbuilds"));
+ printf(" -i, --install %s\n", gettext("fetch, build, and install the specified slackbuild(s)"));
+ printf(" -b, --build %s\n", gettext("only fetch and build the specified slackbuild(s)"));
+ printf(" -f, --fetch %s\n", gettext("only fetch the specified slackbuild(s)"));
+ printf(" -v, --version\n");
+ printf(" -h, --help\n");
+ printf(" %s:\n", gettext("Options"));
+ printf(" -y, --yes %s\n", gettext("do not prompt"));
+ printf(" -t, --simulate %s\n", gettext("show what will be done"));
+ printf(" -c, --config=FILE %s\n", gettext("use the specified configuration file"));
+ printf(" -n, --no-dep %s\n", gettext("do not look for dependencies"));
+ printf(" -p, --postprocess=CMD %s\n", gettext("run specified command on generated package"));
+ printf(" -B, --build-only %s\n", gettext("applicable only to --upgrade-all"));
+ printf(" -F, --fetch-only %s\n", gettext("applicable only to --upgrade-all"));
}
#define VERSION_OPT 'v'
@@ -106,464 +105,495 @@ void help (void)
struct utsname uname_v; /* for .machine */
-static void init_builddir (slapt_src_config *config)
+static void init_builddir(slapt_src_config *config)
{
- DIR *builddir = NULL;
- mode_t mode = S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH;
+ DIR *builddir = NULL;
+ mode_t mode = S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
- if ( (builddir = opendir (config->builddir)) == NULL ) {
- if ( mkdir (config->builddir, mode) == -1 ) {
- printf (gettext ("Failed to create build directory [%s]\n"), config->builddir);
+ if ((builddir = opendir(config->builddir)) == NULL) {
+ if (mkdir(config->builddir, mode) == -1) {
+ printf(gettext("Failed to create build directory [%s]\n"), config->builddir);
- if (errno)
- perror (config->builddir);
+ if (errno)
+ perror(config->builddir);
- exit (EXIT_FAILURE);
+ exit(EXIT_FAILURE);
+ }
+ } else {
+ closedir(builddir);
}
- } else {
- closedir (builddir);
- }
}
-int main (int argc, char *argv[])
+int main(int argc, char *argv[])
{
- int c = -1, option_index = 0, action = 0, i = 0, rval = 0;
- slapt_list_t *names = slapt_init_list ();
- slapt_src_config *config = NULL;
- slapt_src_slackbuild_list *sbs = NULL;
- slapt_src_slackbuild_list *remote_sbs = NULL;
- slapt_pkg_list_t *installed = NULL;
- bool prompt = true, do_dep = true, simulate = false;
- char *config_file = NULL, *postcmd = NULL;
- int only_flags = 0;
-
- static struct option long_options[] = {
- {"version", no_argument, 0, VERSION_OPT},
- {"help", no_argument, 0, HELP_OPT},
- {"update", no_argument, 0, UPDATE_OPT},
- {"upgrade-all", no_argument, 0, UPGRADE_OPT},
- {"U", no_argument, 0, UPGRADE_OPT},
- {"list", no_argument, 0, LIST_OPT},
- {"clean", no_argument, 0, CLEAN_OPT},
- {"e", no_argument, 0, CLEAN_OPT},
- {"search", required_argument, 0, SEARCH_OPT},
- {"s", required_argument, 0, SEARCH_OPT},
- {"show", required_argument, 0, SHOW_OPT},
- {"w", required_argument, 0, SHOW_OPT},
- {"fetch", required_argument, 0, FETCH_OPT},
- {"build", required_argument, 0, BUILD_OPT},
- {"install", required_argument, 0, INSTALL_OPT},
- {"yes", no_argument, 0, YES_OPT},
- {"simulate", no_argument, 0, SIMULATE_OPT},
- {"t", no_argument, 0, SIMULATE_OPT},
- {"no-dep", no_argument, 0, NODEP_OPT},
- {"config", required_argument, 0, CONFIG_OPT},
- {"c", required_argument, 0, CONFIG_OPT},
- {"postprocess", required_argument, 0, POSTCMD_OPT},
- {"build-only", no_argument, 0, BUILD_ONLY_OPT},
- {"B", no_argument, 0, BUILD_ONLY_OPT},
- {"fetch-only", no_argument, 0, FETCH_ONLY_OPT},
- {"F", no_argument, 0, FETCH_ONLY_OPT},
- {0, 0, 0, 0}
- };
-
- /* initialization */
- setbuf (stdout, NULL);
- #ifdef ENABLE_NLS
- setlocale (LC_ALL,"");
- textdomain (GETTEXT_PACKAGE);
- #endif
- #ifdef SLAPT_HAS_GPGME
- gpgme_check_version (NULL);
- #ifdef ENABLE_NLS
- gpgme_set_locale (NULL, LC_CTYPE, setlocale (LC_CTYPE, NULL));
- #endif
- #endif
- curl_global_init (CURL_GLOBAL_ALL);
- uname (&uname_v);
-
- /* stop early */
- if (argc < 2) {
- help ();
- exit (EXIT_SUCCESS);
- }
-
- while ( (c = getopt_long_only (argc, argv, "", long_options, &option_index)) != -1) {
- switch (c) {
- case HELP_OPT: help (); break;
- case VERSION_OPT: version (); break;
- case UPDATE_OPT: action = UPDATE_OPT; break;
- case UPGRADE_OPT: action = UPGRADE_OPT; break;
- case LIST_OPT: action = LIST_OPT; break;
- case CLEAN_OPT: action = CLEAN_OPT; break;
- case FETCH_OPT: action = FETCH_OPT; slapt_add_list_item (names, optarg); break;
- case SEARCH_OPT: action = SEARCH_OPT; slapt_add_list_item (names, optarg); break;
- case SHOW_OPT: action = SHOW_OPT; slapt_add_list_item (names, optarg); break;
- case BUILD_OPT: action = BUILD_OPT; slapt_add_list_item (names, optarg); break;
- case INSTALL_OPT: action = INSTALL_OPT; slapt_add_list_item (names, optarg); break;
- case YES_OPT: prompt = false; break;
- case SIMULATE_OPT: simulate = true; break;
- case NODEP_OPT: do_dep = false; break;
- case CONFIG_OPT: config_file = strdup (optarg); break;
- case POSTCMD_OPT: postcmd = strdup (optarg); break;
- case BUILD_ONLY_OPT: only_flags |= BUILD_ONLY_FLAG; break;
- case FETCH_ONLY_OPT: only_flags |= FETCH_ONLY_FLAG; break;
- default: help (); exit (EXIT_FAILURE);
+ int c = -1, option_index = 0, action = 0, i = 0, rval = 0;
+ slapt_list_t *names = slapt_init_list();
+ slapt_src_config *config = NULL;
+ slapt_src_slackbuild_list *sbs = NULL;
+ slapt_src_slackbuild_list *remote_sbs = NULL;
+ slapt_pkg_list_t *installed = NULL;
+ bool prompt = true, do_dep = true, simulate = false;
+ char *config_file = NULL, *postcmd = NULL;
+ int only_flags = 0;
+
+ static struct option long_options[] = {
+ {"version", no_argument, 0, VERSION_OPT},
+ {"help", no_argument, 0, HELP_OPT},
+ {"update", no_argument, 0, UPDATE_OPT},
+ {"upgrade-all", no_argument, 0, UPGRADE_OPT},
+ {"U", no_argument, 0, UPGRADE_OPT},
+ {"list", no_argument, 0, LIST_OPT},
+ {"clean", no_argument, 0, CLEAN_OPT},
+ {"e", no_argument, 0, CLEAN_OPT},
+ {"search", required_argument, 0, SEARCH_OPT},
+ {"s", required_argument, 0, SEARCH_OPT},
+ {"show", required_argument, 0, SHOW_OPT},
+ {"w", required_argument, 0, SHOW_OPT},
+ {"fetch", required_argument, 0, FETCH_OPT},
+ {"build", required_argument, 0, BUILD_OPT},
+ {"install", required_argument, 0, INSTALL_OPT},
+ {"yes", no_argument, 0, YES_OPT},
+ {"simulate", no_argument, 0, SIMULATE_OPT},
+ {"t", no_argument, 0, SIMULATE_OPT},
+ {"no-dep", no_argument, 0, NODEP_OPT},
+ {"config", required_argument, 0, CONFIG_OPT},
+ {"c", required_argument, 0, CONFIG_OPT},
+ {"postprocess", required_argument, 0, POSTCMD_OPT},
+ {"build-only", no_argument, 0, BUILD_ONLY_OPT},
+ {"B", no_argument, 0, BUILD_ONLY_OPT},
+ {"fetch-only", no_argument, 0, FETCH_ONLY_OPT},
+ {"F", no_argument, 0, FETCH_ONLY_OPT},
+ {0, 0, 0, 0}};
+
+ /* initialization */
+ setbuf(stdout, NULL);
+#ifdef ENABLE_NLS
+ setlocale(LC_ALL, "");
+ textdomain(GETTEXT_PACKAGE);
+#endif
+#ifdef SLAPT_HAS_GPGME
+ gpgme_check_version(NULL);
+#ifdef ENABLE_NLS
+ gpgme_set_locale(NULL, LC_CTYPE, setlocale(LC_CTYPE, NULL));
+#endif
+#endif
+ curl_global_init(CURL_GLOBAL_ALL);
+ uname(&uname_v);
+
+ /* stop early */
+ if (argc < 2) {
+ help();
+ exit(EXIT_SUCCESS);
+ }
+
+ while ((c = getopt_long_only(argc, argv, "", long_options, &option_index)) != -1) {
+ switch (c) {
+ case HELP_OPT:
+ help();
+ break;
+ case VERSION_OPT:
+ version();
+ break;
+ case UPDATE_OPT:
+ action = UPDATE_OPT;
+ break;
+ case UPGRADE_OPT:
+ action = UPGRADE_OPT;
+ break;
+ case LIST_OPT:
+ action = LIST_OPT;
+ break;
+ case CLEAN_OPT:
+ action = CLEAN_OPT;
+ break;
+ case FETCH_OPT:
+ action = FETCH_OPT;
+ slapt_add_list_item(names, optarg);
+ break;
+ case SEARCH_OPT:
+ action = SEARCH_OPT;
+ slapt_add_list_item(names, optarg);
+ break;
+ case SHOW_OPT:
+ action = SHOW_OPT;
+ slapt_add_list_item(names, optarg);
+ break;
+ case BUILD_OPT:
+ action = BUILD_OPT;
+ slapt_add_list_item(names, optarg);
+ break;
+ case INSTALL_OPT:
+ action = INSTALL_OPT;
+ slapt_add_list_item(names, optarg);
+ break;
+ case YES_OPT:
+ prompt = false;
+ break;
+ case SIMULATE_OPT:
+ simulate = true;
+ break;
+ case NODEP_OPT:
+ do_dep = false;
+ break;
+ case CONFIG_OPT:
+ config_file = strdup(optarg);
+ break;
+ case POSTCMD_OPT:
+ postcmd = strdup(optarg);
+ break;
+ case BUILD_ONLY_OPT:
+ only_flags |= BUILD_ONLY_FLAG;
+ break;
+ case FETCH_ONLY_OPT:
+ only_flags |= FETCH_ONLY_FLAG;
+ break;
+ default:
+ help();
+ exit(EXIT_FAILURE);
+ }
+ }
+
+ if ((action == UPGRADE_OPT) && (optind < argc)) {
+ fprintf(stderr, gettext("Individual packages not accepted when upgrading all slackbuilds\n"));
+ exit(EXIT_FAILURE);
+ }
+
+ if ((only_flags & BUILD_ONLY_FLAG) && (only_flags & FETCH_ONLY_FLAG)) {
+ fprintf(stderr, gettext("build-only and fetch-only options are mutually exclusive\n"));
+ exit(EXIT_FAILURE);
+ }
+
+ /* add extra arguments */
+ while (optind < argc) {
+ slapt_add_list_item(names, argv[optind]);
+ ++optind;
+ }
+
+ if (config_file != NULL)
+ config = slapt_src_read_config(config_file);
+ else
+ config = slapt_src_read_config(SLAPT_SRC_RC);
+ if (config == NULL) {
+ fprintf(stderr, gettext("Failed to read %s\n"), SLAPT_SRC_RC);
+ exit(EXIT_FAILURE);
}
- }
-
- if ((action == UPGRADE_OPT) && (optind < argc)) {
- fprintf (stderr, gettext ("Individual packages not accepted when upgrading all slackbuilds\n"));
- exit (EXIT_FAILURE);
- }
-
- if ((only_flags & BUILD_ONLY_FLAG) && (only_flags & FETCH_ONLY_FLAG)) {
- fprintf (stderr, gettext ("build-only and fetch-only options are mutually exclusive\n"));
- exit (EXIT_FAILURE);
- }
-
- /* add extra arguments */
- while (optind < argc) {
- slapt_add_list_item (names, argv[optind]);
- ++optind;
- }
-
- if (config_file != NULL)
- config = slapt_src_read_config (config_file);
- else
- config = slapt_src_read_config (SLAPT_SRC_RC);
- if (config == NULL) {
- fprintf (stderr, gettext ("Failed to read %s\n"), SLAPT_SRC_RC);
- exit (EXIT_FAILURE);
- }
-
- /* honor command line option */
- config->do_dep = do_dep;
- config->postcmd = postcmd; /* to be freed in slapt_src_config_free */
-
- init_builddir (config);
- if ( (chdir (config->builddir)) != 0) {
- perror (gettext ("Failed to chdir to build directory"));
- exit (EXIT_FAILURE);
- }
-
- /* setup, fetch, and other preperation steps */
- switch (action) {
+
+ /* honor command line option */
+ config->do_dep = do_dep;
+ config->postcmd = postcmd; /* to be freed in slapt_src_config_free */
+
+ init_builddir(config);
+ if ((chdir(config->builddir)) != 0) {
+ perror(gettext("Failed to chdir to build directory"));
+ exit(EXIT_FAILURE);
+ }
+
+ /* setup, fetch, and other preperation steps */
+ switch (action) {
case LIST_OPT:
case SEARCH_OPT:
case SHOW_OPT:
- remote_sbs = slapt_src_get_available_slackbuilds ();
- break;
+ remote_sbs = slapt_src_get_available_slackbuilds();
+ break;
case FETCH_OPT:
case BUILD_OPT:
case INSTALL_OPT:
case UPGRADE_OPT:
- remote_sbs = slapt_src_get_available_slackbuilds ();
- installed = slapt_get_installed_pkgs ();
- /* convert all names to slackbuilds */
- if (names->count > 0) {
- sbs = slapt_src_names_to_slackbuilds (config, remote_sbs, names, installed);
- if (sbs == NULL || sbs->count == 0) {
- printf (gettext ("Unable to find all specified slackbuilds.\n"));
- exit (EXIT_FAILURE);
- }
- } else if (action == UPGRADE_OPT) {
- slapt_src_slackbuild search_key;
- slapt_src_slackbuild *search_key_p[1];
- slapt_src_slackbuild **found;
- slapt_pkg_info_t *pkg;
-
- search_key_p[0] = &search_key;
-
- memset (&search_key, 0, sizeof(search_key));
-
- /* for each entry in 'installed' see if it's available as a slackbuild */
- for (i = 0, pkg = installed->pkgs[0]; i < installed->pkg_count; pkg = installed->pkgs[++i]) {
- /* sb_compare_by_name is only going to examine the 'name' member */
- search_key.name = pkg->name;
- if ((found = bsearch (&search_key_p, remote_sbs->slackbuilds, remote_sbs->count,
- sizeof (remote_sbs->slackbuilds[0]), sb_compare_by_name))) {
-
- if (slapt_cmp_pkg_versions((*found)->version, pkg->version) == 1) {
- slapt_add_list_item (names, search_key.name);
+ remote_sbs = slapt_src_get_available_slackbuilds();
+ installed = slapt_get_installed_pkgs();
+ /* convert all names to slackbuilds */
+ if (names->count > 0) {
+ sbs = slapt_src_names_to_slackbuilds(config, remote_sbs, names, installed);
+ if (sbs == NULL || sbs->count == 0) {
+ printf(gettext("Unable to find all specified slackbuilds.\n"));
+ exit(EXIT_FAILURE);
+ }
+ } else if (action == UPGRADE_OPT) {
+ slapt_src_slackbuild search_key;
+ slapt_src_slackbuild *search_key_p[1];
+ slapt_src_slackbuild **found;
+ slapt_pkg_info_t *pkg;
+
+ search_key_p[0] = &search_key;
+
+ memset(&search_key, 0, sizeof(search_key));
+
+ /* for each entry in 'installed' see if it's available as a slackbuild */
+ for (i = 0, pkg = installed->pkgs[0]; i < installed->pkg_count; pkg = installed->pkgs[++i]) {
+ /* sb_compare_by_name is only going to examine the 'name' member */
+ search_key.name = pkg->name;
+ if ((found = bsearch(&search_key_p, remote_sbs->slackbuilds, remote_sbs->count,
+ sizeof(remote_sbs->slackbuilds[0]), sb_compare_by_name))) {
+ if (slapt_cmp_pkg_versions((*found)->version, pkg->version) == 1) {
+ slapt_add_list_item(names, search_key.name);
+ }
+ }
}
- }
- }
- sbs = slapt_src_names_to_slackbuilds (config, remote_sbs, names, installed);
- }
- /* provide summary */
- if (!simulate)
- action = show_summary (sbs, names, action, prompt);
- break;
- }
+ sbs = slapt_src_names_to_slackbuilds(config, remote_sbs, names, installed);
+ }
+ /* provide summary */
+ if (!simulate)
+ action = show_summary(sbs, names, action, prompt);
+ break;
+ }
- /*
+ /*
** When upgrade-all is specified the sbs list is automatically
** determined. Transform the action flag accord to any additional
** flags.
*/
- if (action == UPGRADE_OPT) {
- if (only_flags & BUILD_ONLY_FLAG) {
- action = BUILD_OPT;
- } else if (only_flags & FETCH_ONLY_FLAG) {
- action = FETCH_OPT;
- } else {
- action = INSTALL_OPT;
+ if (action == UPGRADE_OPT) {
+ if (only_flags & BUILD_ONLY_FLAG) {
+ action = BUILD_OPT;
+ } else if (only_flags & FETCH_ONLY_FLAG) {
+ action = FETCH_OPT;
+ } else {
+ action = INSTALL_OPT;
+ }
}
- }
-
- /* now, actually do what was requested */
- switch (action) {
+ /* now, actually do what was requested */
+ switch (action) {
case UPDATE_OPT:
- rval = slapt_src_update_slackbuild_cache (config);
- break;
+ rval = slapt_src_update_slackbuild_cache(config);
+ break;
case FETCH_OPT:
- for (i = 0; i < sbs->count; i++) {
- if (simulate) {
- printf (gettext ("FETCH: %s\n"), sbs->slackbuilds[i]->name);
- continue;
- } else
- slapt_src_fetch_slackbuild (config, sbs->slackbuilds[i]);
- }
- break;
+ for (i = 0; i < sbs->count; i++) {
+ if (simulate) {
+ printf(gettext("FETCH: %s\n"), sbs->slackbuilds[i]->name);
+ continue;
+ } else
+ slapt_src_fetch_slackbuild(config, sbs->slackbuilds[i]);
+ }
+ break;
case BUILD_OPT:
- for (i = 0; i < sbs->count; i++) {
- slapt_src_slackbuild *sb = sbs->slackbuilds[i];
- int r = 0, nv_len = strlen (sb->name) + strlen (sb->version) + 2;
- char *namever = slapt_malloc (sizeof *namever * nv_len);
- r = snprintf (namever, nv_len, "%s:%s", sb->name, sb->version);
-
- if (r+1 != nv_len)
- exit (EXIT_FAILURE);
-
- if (simulate) {
- printf (gettext ("BUILD: %s\n"), sb->name);
- free (namever);
- continue;
- }
+ for (i = 0; i < sbs->count; i++) {
+ slapt_src_slackbuild *sb = sbs->slackbuilds[i];
+ int r = 0, nv_len = strlen(sb->name) + strlen(sb->version) + 2;
+ char *namever = slapt_malloc(sizeof *namever * nv_len);
+ r = snprintf(namever, nv_len, "%s:%s", sb->name, sb->version);
+
+ if (r + 1 != nv_len)
+ exit(EXIT_FAILURE);
+
+ if (simulate) {
+ printf(gettext("BUILD: %s\n"), sb->name);
+ free(namever);
+ continue;
+ }
- slapt_src_fetch_slackbuild (config, sb);
- slapt_src_build_slackbuild (config, sb);
+ slapt_src_fetch_slackbuild(config, sb);
+ slapt_src_build_slackbuild(config, sb);
- /* XXX we assume if we didn't request the slackbuild, then
+ /* XXX we assume if we didn't request the slackbuild, then
it is a dependency, and needs to be installed */
- if (slapt_search_list (names, sb->name) == NULL && slapt_search_list (names, namever) == NULL)
- slapt_src_install_slackbuild (config, sbs->slackbuilds[i]);
+ if (slapt_search_list(names, sb->name) == NULL && slapt_search_list(names, namever) == NULL)
+ slapt_src_install_slackbuild(config, sbs->slackbuilds[i]);
- free (namever);
- }
- break;
+ free(namever);
+ }
+ break;
case INSTALL_OPT:
- for (i = 0; i < sbs->count; i++) {
- slapt_src_slackbuild *sb = sbs->slackbuilds[i];
+ for (i = 0; i < sbs->count; i++) {
+ slapt_src_slackbuild *sb = sbs->slackbuilds[i];
- if (simulate) {
- printf (gettext ("INSTALL: %s\n"), sb->name);
- continue;
- }
+ if (simulate) {
+ printf(gettext("INSTALL: %s\n"), sb->name);
+ continue;
+ }
- slapt_src_fetch_slackbuild (config, sb);
- slapt_src_build_slackbuild (config, sb);
- slapt_src_install_slackbuild (config, sb);
- }
- break;
+ slapt_src_fetch_slackbuild(config, sb);
+ slapt_src_build_slackbuild(config, sb);
+ slapt_src_install_slackbuild(config, sb);
+ }
+ break;
- case SEARCH_OPT:
- {
- slapt_src_slackbuild_list *search = slapt_src_search_slackbuild_cache (remote_sbs, names);
+ case SEARCH_OPT: {
+ slapt_src_slackbuild_list *search = slapt_src_search_slackbuild_cache(remote_sbs, names);
for (i = 0; i < search->count; i++) {
- slapt_src_slackbuild *sb = search->slackbuilds[i];
- printf ("%s:%s - %s\n",
- sb->name,
- sb->version,
- sb->short_desc != NULL ? sb->short_desc : ""
- );
+ slapt_src_slackbuild *sb = search->slackbuilds[i];
+ printf("%s:%s - %s\n",
+ sb->name,
+ sb->version,
+ sb->short_desc != NULL ? sb->short_desc : "");
}
- slapt_src_slackbuild_list_free (search);
- }
- break;
+ slapt_src_slackbuild_list_free(search);
+ } break;
case LIST_OPT:
- for (i = 0; i < remote_sbs->count; i++) {
- slapt_src_slackbuild *sb = remote_sbs->slackbuilds[i];
- printf ("%s:%s - %s\n",
- sb->name,
- sb->version,
- sb->short_desc != NULL ? sb->short_desc : ""
- );
- }
- break;
+ for (i = 0; i < remote_sbs->count; i++) {
+ slapt_src_slackbuild *sb = remote_sbs->slackbuilds[i];
+ printf("%s:%s - %s\n",
+ sb->name,
+ sb->version,
+ sb->short_desc != NULL ? sb->short_desc : "");
+ }
+ break;
- case SHOW_OPT:
- {
+ case SHOW_OPT: {
int c;
for (i = 0; i < names->count; i++) {
- slapt_src_slackbuild *sb = NULL;
- slapt_list_t *parts = slapt_parse_delimited_list (names->items[i], ':');
- const char *name = parts->items[0];
- const char *ver = NULL;
-
- if (parts->count > 1)
- ver = parts->items[1];
+ slapt_src_slackbuild *sb = NULL;
+ slapt_list_t *parts = slapt_parse_delimited_list(names->items[i], ':');
+ const char *name = parts->items[0];
+ const char *ver = NULL;
- sb = slapt_src_get_slackbuild (remote_sbs, name, ver);
+ if (parts->count > 1)
+ ver = parts->items[1];
- if (sb != NULL) {
+ sb = slapt_src_get_slackbuild(remote_sbs, name, ver);
- printf (gettext ("SlackBuild Name: %s\n"), sb->name);
- printf (gettext ("SlackBuild Version: %s\n"), sb->version);
- printf (gettext ("SlackBuild Category: %s\n"), sb->location);
- printf (gettext ("SlackBuild Description: %s\n"), sb->short_desc != NULL ? sb->short_desc : "");
+ if (sb != NULL) {
+ printf(gettext("SlackBuild Name: %s\n"), sb->name);
+ printf(gettext("SlackBuild Version: %s\n"), sb->version);
+ printf(gettext("SlackBuild Category: %s\n"), sb->location);
+ printf(gettext("SlackBuild Description: %s\n"), sb->short_desc != NULL ? sb->short_desc : "");
- printf (gettext ("SlackBuild Files:\n"));
+ printf(gettext("SlackBuild Files:\n"));
- for (c = 0; c < sb->files->count; c++) {
- printf (" %s\n", sb->files->items[c]);
- }
+ for (c = 0; c < sb->files->count; c++) {
+ printf(" %s\n", sb->files->items[c]);
+ }
- if (sb->requires != NULL)
- printf (gettext ("SlackBuild Requires: %s\n"), sb->requires);
+ if (sb->requires != NULL)
+ printf(gettext("SlackBuild Requires: %s\n"), sb->requires);
- if (i+1 != names->count)
- printf ("\n");
+ if (i + 1 != names->count)
+ printf("\n");
- /* slapt_src_slackbuild_free (sb); NO FREE */
- }
- slapt_free_list (parts);
+ /* slapt_src_slackbuild_free (sb); NO FREE */
+ }
+ slapt_free_list(parts);
}
- }
- break;
+ } break;
case CLEAN_OPT:
- clean (config);
- break;
- }
-
- if (names != NULL)
- slapt_free_list (names);
- if (sbs != NULL)
- slapt_src_slackbuild_list_free (sbs);
- if (remote_sbs != NULL)
- slapt_src_slackbuild_list_free (remote_sbs);
- if (installed != NULL)
- slapt_free_pkg_list (installed);
- if (config_file != NULL)
- free (config_file);
-
- slapt_src_config_free (config);
-
- return rval;
-}
-
-static int show_summary (slapt_src_slackbuild_list *sbs, slapt_list_t *names, int action, bool prompt)
-{
- int i, line_len = 0;
-
- printf (gettext ("The following packages will be %s:\n"),
- action == INSTALL_OPT ? gettext ("installed")
- : action == BUILD_OPT ? gettext ("built")
- : gettext ("fetched")
- );
-
- for (i = 0; i < names->count; i++) {
- slapt_list_t *parts = slapt_parse_delimited_list (names->items[i], ':');
- const char *name = parts->items[0];
- int name_len = strlen (name);
-
- if (line_len == 0) {
- printf (" %s ", name);
- line_len += name_len + 1;
- } else if (line_len < 80 - name_len) {
- printf ("%s ", name);
- line_len += name_len + 1;
- } else {
- printf ("\n %s ", name);
- line_len = name_len + 2;
+ clean(config);
+ break;
}
- slapt_free_list (parts);
- }
- printf ("\n");
+ if (names != NULL)
+ slapt_free_list(names);
+ if (sbs != NULL)
+ slapt_src_slackbuild_list_free(sbs);
+ if (remote_sbs != NULL)
+ slapt_src_slackbuild_list_free(remote_sbs);
+ if (installed != NULL)
+ slapt_free_pkg_list(installed);
+ if (config_file != NULL)
+ free(config_file);
+
+ slapt_src_config_free(config);
- if (names->count < sbs->count) {
- line_len = 0;
+ return rval;
+}
- printf (gettext ("The following dependent slackbuilds will be built and installed:\n"));
+static int show_summary(slapt_src_slackbuild_list *sbs, slapt_list_t *names, int action, bool prompt)
+{
+ int i, line_len = 0;
- for (i = 0; i < sbs->count; i++) {
- const char *name = sbs->slackbuilds[i]->name;
- const char *version = sbs->slackbuilds[i]->version;
- char *namever = slapt_malloc (sizeof *namever * (strlen (name) + strlen (version) + 2));
- sprintf (namever, "%s:%s", name, version);
+ printf(gettext("The following packages will be %s:\n"),
+ action == INSTALL_OPT ? gettext("installed")
+ : action == BUILD_OPT ? gettext("built")
+ : gettext("fetched"));
- if (slapt_search_list (names, name) == NULL && slapt_search_list (names, namever) == NULL) {
- int name_len = strlen (name);
+ for (i = 0; i < names->count; i++) {
+ slapt_list_t *parts = slapt_parse_delimited_list(names->items[i], ':');
+ const char *name = parts->items[0];
+ int name_len = strlen(name);
if (line_len == 0) {
- printf (" %s ", name);
- line_len += name_len + 2;
+ printf(" %s ", name);
+ line_len += name_len + 1;
} else if (line_len < 80 - name_len) {
- printf ("%s ", name);
- line_len += name_len + 1;
+ printf("%s ", name);
+ line_len += name_len + 1;
} else {
- printf ("\n %s ", name);
- line_len = name_len + 2;
+ printf("\n %s ", name);
+ line_len = name_len + 2;
}
- }
+ slapt_free_list(parts);
+ }
+ printf("\n");
+
+ if (names->count < sbs->count) {
+ line_len = 0;
+
+ printf(gettext("The following dependent slackbuilds will be built and installed:\n"));
+
+ for (i = 0; i < sbs->count; i++) {
+ const char *name = sbs->slackbuilds[i]->name;
+ const char *version = sbs->slackbuilds[i]->version;
+ char *namever = slapt_malloc(sizeof *namever * (strlen(name) + strlen(version) + 2));
+ sprintf(namever, "%s:%s", name, version);
+
+ if (slapt_search_list(names, name) == NULL && slapt_search_list(names, namever) == NULL) {
+ int name_len = strlen(name);
+
+ if (line_len == 0) {
+ printf(" %s ", name);
+ line_len += name_len + 2;
+ } else if (line_len < 80 - name_len) {
+ printf("%s ", name);
+ line_len += name_len + 1;
+ } else {
+ printf("\n %s ", name);
+ line_len = name_len + 2;
+ }
+ }
- free (namever);
+ free(namever);
+ }
+ printf("\n");
}
- printf ("\n");
- }
- if ((sbs->count > 0) && (prompt == true)) {
- if (slapt_ask_yes_no (gettext ("Do you want to continue? [y/N] ")) != 1) {
- printf (gettext ("Abort.\n"));
- return 0;
+ if ((sbs->count > 0) && (prompt == true)) {
+ if (slapt_ask_yes_no(gettext("Do you want to continue? [y/N] ")) != 1) {
+ printf(gettext("Abort.\n"));
+ return 0;
+ }
}
- }
- return action;
+ return action;
}
-static void clean (slapt_src_config *config)
+static void clean(slapt_src_config *config)
{
- struct dirent *file = NULL;
- DIR *builddir = opendir (config->builddir);
- if ( builddir != NULL ) {
- while ((file = readdir (builddir)) != NULL) {
- struct stat stat_buf;
-
- if (strcmp (file->d_name, "..") == 0 || strcmp (file->d_name, ".") == 0)
- continue;
-
- if (lstat (file->d_name, &stat_buf) == -1)
- continue;
-
- if ( S_ISDIR (stat_buf.st_mode)) {
- int r = 0, command_len = strlen (file->d_name)+8;
- char *command = slapt_malloc (sizeof *command * command_len);
- r = snprintf (command, command_len, "rm -rf %s", file->d_name);
- if (r+1 == command_len) {
- int sys_r = system (command);
- if (sys_r != 0)
- exit (EXIT_FAILURE);
+ struct dirent *file = NULL;
+ DIR *builddir = opendir(config->builddir);
+ if (builddir != NULL) {
+ while ((file = readdir(builddir)) != NULL) {
+ struct stat stat_buf;
+
+ if (strcmp(file->d_name, "..") == 0 || strcmp(file->d_name, ".") == 0)
+ continue;
+
+ if (lstat(file->d_name, &stat_buf) == -1)
+ continue;
+
+ if (S_ISDIR(stat_buf.st_mode)) {
+ int r = 0, command_len = strlen(file->d_name) + 8;
+ char *command = slapt_malloc(sizeof *command * command_len);
+ r = snprintf(command, command_len, "rm -rf %s", file->d_name);
+ if (r + 1 == command_len) {
+ int sys_r = system(command);
+ if (sys_r != 0)
+ exit(EXIT_FAILURE);
+ }
+ }
}
- }
}
- }
- closedir (builddir);
+ closedir(builddir);
}
-static int sb_compare_by_name (const void *a, const void *b)
+static int sb_compare_by_name(const void *a, const void *b)
{
- const slapt_src_slackbuild * const sb_a = *(slapt_src_slackbuild * const *)a;
- const slapt_src_slackbuild * const sb_b = *(slapt_src_slackbuild * const *)b;
+ const slapt_src_slackbuild *const sb_a = *(slapt_src_slackbuild *const *)a;
+ const slapt_src_slackbuild *const sb_b = *(slapt_src_slackbuild *const *)b;
- return strcmp(sb_a->name, sb_b->name);
+ return strcmp(sb_a->name, sb_b->name);
}
diff --git a/src/source.c b/src/source.c
index 3fc01b4..dd66329 100644
--- a/src/source.c
+++ b/src/source.c
@@ -21,1033 +21,1009 @@
#include "config.h"
#ifdef HAS_FAKEROOT
- #define SLAPTSRC_CMD_LEN 27
- #define SLAPTSRC_CMD "fakeroot -- sh"
- #define SLAPTSRC_SLKBUILD_CMD_LEN 24
- #define SLAPTSRC_SLKBUILD_CMD "fakeroot -- slkbuild -X"
+#define SLAPTSRC_CMD_LEN 27
+#define SLAPTSRC_CMD "fakeroot -- sh"
+#define SLAPTSRC_SLKBUILD_CMD_LEN 24
+#define SLAPTSRC_SLKBUILD_CMD "fakeroot -- slkbuild -X"
#else
- #define SLAPTSRC_CMD_LEN 15
- #define SLAPTSRC_CMD "sh"
- #define SLAPTSRC_SLKBUILD_CMD_LEN 12
- #define SLAPTSRC_SLKBUILD_CMD "slkbuild -X"
+#define SLAPTSRC_CMD_LEN 15
+#define SLAPTSRC_CMD "sh"
+#define SLAPTSRC_SLKBUILD_CMD_LEN 12
+#define SLAPTSRC_SLKBUILD_CMD "slkbuild -X"
#endif
extern struct utsname uname_v;
-static char *filename_from_url (char *url);
-static char *add_part_to_url (char *url, char *part);
+static char *filename_from_url(char *url);
+static char *add_part_to_url(char *url, char *part);
-slapt_src_config *slapt_src_config_init (void)
+slapt_src_config *slapt_src_config_init(void)
{
- slapt_src_config *config = slapt_malloc (sizeof *config);
- config->sources = slapt_init_list ();
- config->builddir = NULL;
- config->pkgext = NULL;
- config->pkgtag = NULL;
- config->postcmd = NULL;
- config->do_dep = false;
- return config;
+ slapt_src_config *config = slapt_malloc(sizeof *config);
+ config->sources = slapt_init_list();
+ config->builddir = NULL;
+ config->pkgext = NULL;
+ config->pkgtag = NULL;
+ config->postcmd = NULL;
+ config->do_dep = false;
+ return config;
}
-void slapt_src_config_free (slapt_src_config *config)
+void slapt_src_config_free(slapt_src_config *config)
{
- slapt_free_list (config->sources);
- if (config->builddir != NULL)
- free (config->builddir);
- if (config->pkgext != NULL)
- free (config->pkgext);
- if (config->pkgtag != NULL)
- free (config->pkgtag);
- if (config->postcmd != NULL)
- free (config->postcmd);
- free (config);
+ slapt_free_list(config->sources);
+ if (config->builddir != NULL)
+ free(config->builddir);
+ if (config->pkgext != NULL)
+ free(config->pkgext);
+ if (config->pkgtag != NULL)
+ free(config->pkgtag);
+ if (config->postcmd != NULL)
+ free(config->postcmd);
+ free(config);
}
-slapt_src_config *slapt_src_read_config (const char *filename)
+slapt_src_config *slapt_src_read_config(const char *filename)
{
- FILE *rc = NULL;
- slapt_src_config *config = NULL;
- char *buffer = NULL;
- size_t gb_length = 0;
- ssize_t g_size;
-
- rc = slapt_open_file (filename, "r");
- if (rc == NULL)
- exit (EXIT_FAILURE);
-
- config = slapt_src_config_init ();
-
- while ( (g_size = getline (&buffer, &gb_length, rc) ) != EOF ) {
- char *token_ptr = NULL;
- buffer[g_size - 1] = '\0';
-
- if (strchr (buffer, '#') != NULL)
- continue;
-
- if ( (token_ptr = strstr (buffer,SLAPT_SRC_SOURCE_TOKEN)) != NULL ) {
-
- if ( strlen (token_ptr) > strlen (SLAPT_SRC_SOURCE_TOKEN) ) {
- char *source = strdup (token_ptr + strlen (SLAPT_SRC_SOURCE_TOKEN));
- if (source[strlen (source)-1] != '/') {
- char *fixed = add_part_to_url (source, "/");
- free (source);
- source = fixed;
+ FILE *rc = NULL;
+ slapt_src_config *config = NULL;
+ char *buffer = NULL;
+ size_t gb_length = 0;
+ ssize_t g_size;
+
+ rc = slapt_open_file(filename, "r");
+ if (rc == NULL)
+ exit(EXIT_FAILURE);
+
+ config = slapt_src_config_init();
+
+ while ((g_size = getline(&buffer, &gb_length, rc)) != EOF) {
+ char *token_ptr = NULL;
+ buffer[g_size - 1] = '\0';
+
+ if (strchr(buffer, '#') != NULL)
+ continue;
+
+ if ((token_ptr = strstr(buffer, SLAPT_SRC_SOURCE_TOKEN)) != NULL) {
+ if (strlen(token_ptr) > strlen(SLAPT_SRC_SOURCE_TOKEN)) {
+ char *source = strdup(token_ptr + strlen(SLAPT_SRC_SOURCE_TOKEN));
+ if (source[strlen(source) - 1] != '/') {
+ char *fixed = add_part_to_url(source, "/");
+ free(source);
+ source = fixed;
+ }
+ slapt_add_list_item(config->sources, source);
+ free(source);
+ }
+
+ } else if ((token_ptr = strstr(buffer, SLAPT_SRC_BUILDDIR_TOKEN)) != NULL) {
+ if (strlen(token_ptr) > strlen(SLAPT_SRC_BUILDDIR_TOKEN))
+ config->builddir = strdup(token_ptr + strlen(SLAPT_SRC_BUILDDIR_TOKEN));
+
+ } else if ((token_ptr = strstr(buffer, SLAPT_SRC_PKGEXT_TOKEN)) != NULL) {
+ if (strlen(token_ptr) > strlen(SLAPT_SRC_PKGEXT_TOKEN))
+ config->pkgext = strdup(token_ptr + strlen(SLAPT_SRC_PKGEXT_TOKEN));
+
+ } else if ((token_ptr = strstr(buffer, SLAPT_SRC_PKGTAG_TOKEN)) != NULL) {
+ if (strlen(token_ptr) > strlen(SLAPT_SRC_PKGTAG_TOKEN))
+ config->pkgtag = strdup(token_ptr + strlen(SLAPT_SRC_PKGTAG_TOKEN));
}
- slapt_add_list_item (config->sources, source);
- free (source);
- }
-
- } else if ( (token_ptr = strstr (buffer,SLAPT_SRC_BUILDDIR_TOKEN)) != NULL ) {
-
- if ( strlen (token_ptr) > strlen (SLAPT_SRC_BUILDDIR_TOKEN) )
- config->builddir = strdup (token_ptr + strlen (SLAPT_SRC_BUILDDIR_TOKEN));
-
- } else if ( (token_ptr = strstr (buffer,SLAPT_SRC_PKGEXT_TOKEN)) != NULL ) {
-
- if ( strlen (token_ptr) > strlen (SLAPT_SRC_PKGEXT_TOKEN) )
- config->pkgext = strdup (token_ptr + strlen (SLAPT_SRC_PKGEXT_TOKEN));
-
- } else if ( (token_ptr = strstr (buffer,SLAPT_SRC_PKGTAG_TOKEN)) != NULL ) {
-
- if ( strlen (token_ptr) > strlen (SLAPT_SRC_PKGTAG_TOKEN) )
- config->pkgtag = strdup (token_ptr + strlen (SLAPT_SRC_PKGTAG_TOKEN));
-
}
- }
-
- /* sanity checks */
- if (config->builddir == NULL) {
- fprintf (stderr, gettext ("No BUILDDIR specified in the configuration\n") );
- exit (EXIT_FAILURE);
- }
+ /* sanity checks */
+ if (config->builddir == NULL) {
+ fprintf(stderr, gettext("No BUILDDIR specified in the configuration\n"));
+ exit(EXIT_FAILURE);
+ }
- fclose (rc);
- if (buffer != NULL)
- free (buffer);
+ fclose(rc);
+ if (buffer != NULL)
+ free(buffer);
- return config;
+ return config;
}
-slapt_src_slackbuild *slapt_src_slackbuild_init (void)
+slapt_src_slackbuild *slapt_src_slackbuild_init(void)
{
- slapt_src_slackbuild *sb = slapt_malloc (sizeof *sb);
- sb->name = NULL;
- sb->version = NULL;
- sb->location = NULL;
- sb->sb_source_url = NULL;
- sb->short_desc = NULL;
- sb->download = NULL;
- sb->download_x86_64 = NULL;
- sb->md5sum = NULL;
- sb->md5sum_x86_64 = NULL;
- sb->requires = NULL;
- sb->files = slapt_init_list ();
-
- return sb;
+ slapt_src_slackbuild *sb = slapt_malloc(sizeof *sb);
+ sb->name = NULL;
+ sb->version = NULL;
+ sb->location = NULL;
+ sb->sb_source_url = NULL;
+ sb->short_desc = NULL;
+ sb->download = NULL;
+ sb->download_x86_64 = NULL;
+ sb->md5sum = NULL;
+ sb->md5sum_x86_64 = NULL;
+ sb->requires = NULL;
+ sb->files = slapt_init_list();
+
+ return sb;
}
-void slapt_src_slackbuild_free (slapt_src_slackbuild *sb)
+void slapt_src_slackbuild_free(slapt_src_slackbuild *sb)
{
- if (sb->name != NULL)
- free (sb->name);
- if (sb->version != NULL)
- free (sb->version);
- if (sb->location != NULL)
- free (sb->location);
- if (sb->sb_source_url != NULL)
- free (sb->sb_source_url);
- if (sb->download != NULL)
- free (sb->download);
- if (sb->download_x86_64 != NULL)
- free (sb->download_x86_64);
- if (sb->md5sum != NULL)
- free (sb->md5sum);
- if (sb->md5sum_x86_64 != NULL)
- free (sb->md5sum_x86_64);
- if (sb->short_desc != NULL)
- free (sb->short_desc);
- if (sb->requires != NULL)
- free (sb->requires);
-
- slapt_free_list (sb->files);
-
- free (sb);
+ if (sb->name != NULL)
+ free(sb->name);
+ if (sb->version != NULL)
+ free(sb->version);
+ if (sb->location != NULL)
+ free(sb->location);
+ if (sb->sb_source_url != NULL)
+ free(sb->sb_source_url);
+ if (sb->download != NULL)
+ free(sb->download);
+ if (sb->download_x86_64 != NULL)
+ free(sb->download_x86_64);
+ if (sb->md5sum != NULL)
+ free(sb->md5sum);
+ if (sb->md5sum_x86_64 != NULL)
+ free(sb->md5sum_x86_64);
+ if (sb->short_desc != NULL)
+ free(sb->short_desc);
+ if (sb->requires != NULL)
+ free(sb->requires);
+
+ slapt_free_list(sb->files);
+
+ free(sb);
}
-slapt_src_slackbuild_list *slapt_src_slackbuild_list_init (void)
+slapt_src_slackbuild_list *slapt_src_slackbuild_list_init(void)
{
- slapt_src_slackbuild_list *sbs = slapt_malloc (sizeof *sbs);
- sbs->slackbuilds = slapt_malloc (sizeof *sbs->slackbuilds);
- sbs->count = 0;
- sbs->free_slackbuilds = false;
+ slapt_src_slackbuild_list *sbs = slapt_malloc(sizeof *sbs);
+ sbs->slackbuilds = slapt_malloc(sizeof *sbs->slackbuilds);
+ sbs->count = 0;
+ sbs->free_slackbuilds = false;
- return sbs;
+ return sbs;
}
-void slapt_src_slackbuild_list_free (slapt_src_slackbuild_list *sbs)
+void slapt_src_slackbuild_list_free(slapt_src_slackbuild_list *sbs)
{
- if (sbs->free_slackbuilds == true) {
- int i;
- for (i = 0; i < sbs->count; i++) {
- slapt_src_slackbuild_free (sbs->slackbuilds[i]);
+ if (sbs->free_slackbuilds == true) {
+ int i;
+ for (i = 0; i < sbs->count; i++) {
+ slapt_src_slackbuild_free(sbs->slackbuilds[i]);
+ }
}
- }
- free (sbs->slackbuilds);
- free (sbs);
+ free(sbs->slackbuilds);
+ free(sbs);
}
-void slapt_src_slackbuild_list_add (slapt_src_slackbuild_list *sbs, slapt_src_slackbuild *sb)
+void slapt_src_slackbuild_list_add(slapt_src_slackbuild_list *sbs, slapt_src_slackbuild *sb)
{
- slapt_src_slackbuild **realloc_tmp = realloc (sbs->slackbuilds, sizeof *sbs->slackbuilds * (sbs->count + 1));
- if (realloc_tmp == NULL) {
- perror ("realloc failed");
- exit (EXIT_FAILURE);
- }
-
- sbs->slackbuilds = realloc_tmp;
- sbs->slackbuilds[sbs->count] = sb;
- ++sbs->count;
+ slapt_src_slackbuild **realloc_tmp = realloc(sbs->slackbuilds, sizeof *sbs->slackbuilds * (sbs->count + 1));
+ if (realloc_tmp == NULL) {
+ perror("realloc failed");
+ exit(EXIT_FAILURE);
+ }
+
+ sbs->slackbuilds = realloc_tmp;
+ sbs->slackbuilds[sbs->count] = sb;
+ ++sbs->count;
}
-int slapt_src_update_slackbuild_cache (slapt_src_config *config)
+int slapt_src_update_slackbuild_cache(slapt_src_config *config)
{
- int i, rval = 0;
- slapt_rc_config *slapt_config = slapt_init_config ();
- slapt_src_slackbuild_list *slackbuilds = slapt_src_slackbuild_list_init ();
-
- for (i = 0; i < config->sources->count; i++) {
- const char *url = config->sources->items[i];
- slapt_src_slackbuild_list *sbs = NULL;
- char *files[] = { SLAPT_SRC_SOURCES_LIST_GZ, SLAPT_SRC_SOURCES_LIST, NULL };
- int fc;
-
- printf (gettext ("Fetching slackbuild list from %s..."), url);
-
- for (fc = 0; files[fc] != NULL; fc++) {
- char *filename = NULL, *local_head = NULL, *head = NULL;
- const char *err = NULL;
- FILE *f = NULL;
-
- filename = slapt_gen_filename_from_url (url, files[fc]);
- local_head = slapt_read_head_cache (filename);
- head = slapt_head_mirror_data (url, files[fc]);
-
- /* is it cached ? */
- if (head != NULL && local_head != NULL && strcmp (head, local_head) == 0) {
- printf (gettext ("Cached\n"));
- sbs = slapt_src_get_slackbuilds_from_file (filename);
- } else if (head != NULL) {
-
- if ((f = slapt_open_file (filename,"w+b")) == NULL)
- exit (EXIT_FAILURE);
-
- err = slapt_get_mirror_data_from_source (f, slapt_config, url, files[fc]);
- fclose (f);
-
- if (! err) {
- printf (gettext ("Done\n"));
- sbs = slapt_src_get_slackbuilds_from_file (filename);
-
- slapt_write_head_cache (head, filename);
-
- } else {
- fprintf (stderr, gettext ("Download failed: %s\n"), err);
- slapt_clear_head_cache (filename);
- rval = 1;
+ int i, rval = 0;
+ slapt_rc_config *slapt_config = slapt_init_config();
+ slapt_src_slackbuild_list *slackbuilds = slapt_src_slackbuild_list_init();
+
+ for (i = 0; i < config->sources->count; i++) {
+ const char *url = config->sources->items[i];
+ slapt_src_slackbuild_list *sbs = NULL;
+ char *files[] = {SLAPT_SRC_SOURCES_LIST_GZ, SLAPT_SRC_SOURCES_LIST, NULL};
+ int fc;
+
+ printf(gettext("Fetching slackbuild list from %s..."), url);
+
+ for (fc = 0; files[fc] != NULL; fc++) {
+ char *filename = NULL, *local_head = NULL, *head = NULL;
+ const char *err = NULL;
+ FILE *f = NULL;
+
+ filename = slapt_gen_filename_from_url(url, files[fc]);
+ local_head = slapt_read_head_cache(filename);
+ head = slapt_head_mirror_data(url, files[fc]);
+
+ /* is it cached ? */
+ if (head != NULL && local_head != NULL && strcmp(head, local_head) == 0) {
+ printf(gettext("Cached\n"));
+ sbs = slapt_src_get_slackbuilds_from_file(filename);
+ } else if (head != NULL) {
+ if ((f = slapt_open_file(filename, "w+b")) == NULL)
+ exit(EXIT_FAILURE);
+
+ err = slapt_get_mirror_data_from_source(f, slapt_config, url, files[fc]);
+ fclose(f);
+
+ if (!err) {
+ printf(gettext("Done\n"));
+ sbs = slapt_src_get_slackbuilds_from_file(filename);
+
+ slapt_write_head_cache(head, filename);
+
+ } else {
+ fprintf(stderr, gettext("Download failed: %s\n"), err);
+ slapt_clear_head_cache(filename);
+ rval = 1;
+ }
+ } else {
+ if (strcmp(files[fc], SLAPT_SRC_SOURCES_LIST_GZ) != 0) {
+ fprintf(stderr, gettext("Download failed: %s\n"), "404");
+ rval = 1;
+ }
+ }
+
+ free(filename);
+ free(local_head);
+ free(head);
+
+ if (sbs != NULL)
+ break;
}
- } else {
- if (strcmp (files[fc], SLAPT_SRC_SOURCES_LIST_GZ) != 0) {
- fprintf (stderr, gettext ("Download failed: %s\n"), "404");
- rval = 1;
- }
- }
-
- free (filename);
- free (local_head);
- free (head);
- if (sbs != NULL)
- break;
- }
-
- if (sbs != NULL) {
- int c;
- for (c = 0; c < sbs->count; c++) {
- if (sbs->slackbuilds[c]->sb_source_url == NULL)
- sbs->slackbuilds[c]->sb_source_url = strdup (url);
- slapt_src_slackbuild_list_add (slackbuilds, sbs->slackbuilds[c]);
- }
- sbs->free_slackbuilds = false; /* don't free the slackbuilds here */
- slapt_src_slackbuild_list_free (sbs);
+ if (sbs != NULL) {
+ int c;
+ for (c = 0; c < sbs->count; c++) {
+ if (sbs->slackbuilds[c]->sb_source_url == NULL)
+ sbs->slackbuilds[c]->sb_source_url = strdup(url);
+ slapt_src_slackbuild_list_add(slackbuilds, sbs->slackbuilds[c]);
+ }
+ sbs->free_slackbuilds = false; /* don't free the slackbuilds here */
+ slapt_src_slackbuild_list_free(sbs);
+ }
}
- }
-
- slapt_src_write_slackbuilds_to_file (slackbuilds, SLAPT_SRC_DATA_FILE);
- slapt_free_rc_config (slapt_config);
- slackbuilds->free_slackbuilds = true; /* free here */
- slapt_src_slackbuild_list_free (slackbuilds);
- return rval;
+ slapt_src_write_slackbuilds_to_file(slackbuilds, SLAPT_SRC_DATA_FILE);
+ slapt_free_rc_config(slapt_config);
+ slackbuilds->free_slackbuilds = true; /* free here */
+ slapt_src_slackbuild_list_free(slackbuilds);
+ return rval;
}
-static int sb_cmp (const void *a, const void *b)
+static int sb_cmp(const void *a, const void *b)
{
- int cmp;
- slapt_src_slackbuild *sb1 = *(slapt_src_slackbuild * const *)a;
- slapt_src_slackbuild *sb2 = *(slapt_src_slackbuild * const *)b;
-
- cmp = strcmp (sb1->name, sb2->name);
- if (cmp != 0)
- return cmp;
- else
- return slapt_cmp_pkg_versions (sb1->version, sb2->version);
-}
-
-void slapt_src_write_slackbuilds_to_file (slapt_src_slackbuild_list *sbs, const char *datafile)
-{
- int i;
- FILE *f = slapt_open_file (datafile, "w+b");
-
- qsort ( sbs->slackbuilds, sbs->count, sizeof (sbs->slackbuilds[0]), sb_cmp );
-
- for (i = 0; i < sbs->count; i++) {
- int c;
- slapt_src_slackbuild *sb = sbs->slackbuilds[i];
- /* write out package data */
- fprintf (f, "SLACKBUILD NAME: %s\n", sb->name);
- fprintf (f, "SLACKBUILD SOURCEURL: %s\n", sb->sb_source_url);
-
- /* fixup locations so they are easier to work with later */
- {
- char *location = strdup (sb->location);
-
- if (location[strlen (location)-1] != '/') {
- char *fixed = add_part_to_url (location, "/");
- free (location);
- location = fixed;
- }
-
- if (strncmp (location, "./", 2) == 0) {
- char *fixed = strdup (location + 2);
- free (location);
- location = fixed;
- }
-
- fprintf (f, "SLACKBUILD LOCATION: %s\n", location);
- free (location);
- }
-
- fprintf (f, "SLACKBUILD FILES: ");
- for (c = 0; c < sb->files->count; c++) {
- if (c == (sb->files->count - 1))
- fprintf (f, "%s\n", sb->files->items[c]);
- else
- fprintf (f, "%s ", sb->files->items[c]);
- }
+ int cmp;
+ slapt_src_slackbuild *sb1 = *(slapt_src_slackbuild *const *)a;
+ slapt_src_slackbuild *sb2 = *(slapt_src_slackbuild *const *)b;
- fprintf (f, "SLACKBUILD VERSION: %s\n", sb->version);
- fprintf (f, "SLACKBUILD DOWNLOAD: %s\n", sb->download ? sb->download : "");
- fprintf (f, "SLACKBUILD DOWNLOAD_x86_64: %s\n", sb->download_x86_64 ? sb->download_x86_64 : "");
- fprintf (f, "SLACKBUILD MD5SUM: %s\n", sb->md5sum ? sb->md5sum : "");
- fprintf (f, "SLACKBUILD MD5SUM_x86_64: %s\n", sb->md5sum_x86_64 ? sb->md5sum_x86_64 : "");
- fprintf (f, "SLACKBUILD REQUIRES: %s\n", sb->requires ? sb->requires : "");
- fprintf (f, "SLACKBUILD SHORT DESCRIPTION: %s\n", sb->short_desc ? sb->short_desc : "");
- fprintf (f, "\n");
- }
-
- fclose (f);
+ cmp = strcmp(sb1->name, sb2->name);
+ if (cmp != 0)
+ return cmp;
+ else
+ return slapt_cmp_pkg_versions(sb1->version, sb2->version);
}
-slapt_src_slackbuild_list *slapt_src_get_slackbuilds_from_file (const char *datafile)
+void slapt_src_write_slackbuilds_to_file(slapt_src_slackbuild_list *sbs, const char *datafile)
{
- FILE *f = NULL;
- char *buffer = NULL;
- size_t gb_length = 0;
- ssize_t g_size;
- slapt_src_slackbuild_list *sbs = slapt_src_slackbuild_list_init ();
- slapt_src_slackbuild *sb = NULL;
- enum { SLAPT_SRC_NOT_PARSING, SLAPT_SRC_PARSING } parse_state;
- parse_state = SLAPT_SRC_NOT_PARSING;
-
- /* support reading from gzip'd files */
- if (strstr (datafile, ".gz") != NULL) {
- gzFile data = NULL;
- char gzbuffer[SLAPT_MAX_ZLIB_BUFFER];
-
- if ((f = tmpfile ()) == NULL)
- exit (EXIT_FAILURE);
-
- if ((data = gzopen (datafile,"rb")) == NULL)
- exit (EXIT_FAILURE);
-
- while (gzgets (data, gzbuffer, SLAPT_MAX_ZLIB_BUFFER) != Z_NULL) {
- fprintf (f, "%s", gzbuffer);
- }
- gzclose (data);
- rewind (f);
-
- } else {
- f = fopen (datafile, "r");
- if (f == NULL) {
- printf (gettext ("Failed to open %s for reading\n"), datafile);
- return sbs;
- }
- }
-
- while ( (g_size = getline (&buffer, &gb_length, f) ) != EOF ) {
- char *token = NULL;
+ int i;
+ FILE *f = slapt_open_file(datafile, "w+b");
- if (strstr (buffer, "SLACKBUILD NAME:") != NULL) {
- parse_state = SLAPT_SRC_PARSING;
- sb = slapt_src_slackbuild_init ();
- }
+ qsort(sbs->slackbuilds, sbs->count, sizeof(sbs->slackbuilds[0]), sb_cmp);
- if ((strcmp (buffer, "\n") == 0) && (parse_state == SLAPT_SRC_PARSING)) {
- slapt_src_slackbuild_list_add (sbs, sb);
- /* do not free, in use in sbs list
- slapt_src_slackbuild_free (sb);
- */
- sb = NULL;
- parse_state = SLAPT_SRC_NOT_PARSING;
- }
+ for (i = 0; i < sbs->count; i++) {
+ int c;
+ slapt_src_slackbuild *sb = sbs->slackbuilds[i];
+ /* write out package data */
+ fprintf(f, "SLACKBUILD NAME: %s\n", sb->name);
+ fprintf(f, "SLACKBUILD SOURCEURL: %s\n", sb->sb_source_url);
+
+ /* fixup locations so they are easier to work with later */
+ {
+ char *location = strdup(sb->location);
+
+ if (location[strlen(location) - 1] != '/') {
+ char *fixed = add_part_to_url(location, "/");
+ free(location);
+ location = fixed;
+ }
+
+ if (strncmp(location, "./", 2) == 0) {
+ char *fixed = strdup(location + 2);
+ free(location);
+ location = fixed;
+ }
+
+ fprintf(f, "SLACKBUILD LOCATION: %s\n", location);
+ free(location);
+ }
- switch (parse_state) {
- case SLAPT_SRC_PARSING:
+ fprintf(f, "SLACKBUILD FILES: ");
+ for (c = 0; c < sb->files->count; c++) {
+ if (c == (sb->files->count - 1))
+ fprintf(f, "%s\n", sb->files->items[c]);
+ else
+ fprintf(f, "%s ", sb->files->items[c]);
+ }
- /* we skip empty fields for odd sscanf bug in older glibcs */
- if (strstr (buffer,": \n") != NULL)
- continue;
+ fprintf(f, "SLACKBUILD VERSION: %s\n", sb->version);
+ fprintf(f, "SLACKBUILD DOWNLOAD: %s\n", sb->download ? sb->download : "");
+ fprintf(f, "SLACKBUILD DOWNLOAD_x86_64: %s\n", sb->download_x86_64 ? sb->download_x86_64 : "");
+ fprintf(f, "SLACKBUILD MD5SUM: %s\n", sb->md5sum ? sb->md5sum : "");
+ fprintf(f, "SLACKBUILD MD5SUM_x86_64: %s\n", sb->md5sum_x86_64 ? sb->md5sum_x86_64 : "");
+ fprintf(f, "SLACKBUILD REQUIRES: %s\n", sb->requires ? sb->requires : "");
+ fprintf(f, "SLACKBUILD SHORT DESCRIPTION: %s\n", sb->short_desc ? sb->short_desc : "");
+ fprintf(f, "\n");
+ }
- if ( (sscanf (buffer, "SLACKBUILD NAME: %as", &token)) == 1) {
- sb->name = strdup (token);
- free (token);
- }
+ fclose(f);
+}
- if ( (sscanf (buffer, "SLACKBUILD SOURCEURL: %as", &token)) == 1) {
- sb->sb_source_url = strdup (token);
- free (token);
- }
+slapt_src_slackbuild_list *slapt_src_get_slackbuilds_from_file(const char *datafile)
+{
+ FILE *f = NULL;
+ char *buffer = NULL;
+ size_t gb_length = 0;
+ ssize_t g_size;
+ slapt_src_slackbuild_list *sbs = slapt_src_slackbuild_list_init();
+ slapt_src_slackbuild *sb = NULL;
+ enum { SLAPT_SRC_NOT_PARSING,
+ SLAPT_SRC_PARSING } parse_state;
+ parse_state = SLAPT_SRC_NOT_PARSING;
- if ( (sscanf (buffer, "SLACKBUILD LOCATION: %as", &token)) == 1) {
- sb->location = strdup (token);
- free (token);
- }
+ /* support reading from gzip'd files */
+ if (strstr(datafile, ".gz") != NULL) {
+ gzFile data = NULL;
+ char gzbuffer[SLAPT_MAX_ZLIB_BUFFER];
- if ( (sscanf (buffer, "SLACKBUILD FILES: %a[^\n]", &token)) == 1) {
- int c;
- slapt_list_t *files = slapt_parse_delimited_list (token, ' ');
- for (c = 0; c < files->count; c++) {
- slapt_add_list_item (sb->files, files->items[c]);
- }
- slapt_free_list (files);
- free (token);
- }
+ if ((f = tmpfile()) == NULL)
+ exit(EXIT_FAILURE);
- if ( (sscanf (buffer, "SLACKBUILD VERSION: %a[^\n]", &token)) == 1) {
- sb->version = strdup (token);
- free (token);
- }
+ if ((data = gzopen(datafile, "rb")) == NULL)
+ exit(EXIT_FAILURE);
- if ( (sscanf (buffer, "SLACKBUILD DOWNLOAD: %a[^\n]", &token)) == 1) {
- sb->download = strdup (token);
- free (token);
+ while (gzgets(data, gzbuffer, SLAPT_MAX_ZLIB_BUFFER) != Z_NULL) {
+ fprintf(f, "%s", gzbuffer);
}
+ gzclose(data);
+ rewind(f);
- if ( (sscanf (buffer, "SLACKBUILD DOWNLOAD_x86_64: %a[^\n]", &token)) == 1) {
- sb->download_x86_64 = strdup (token);
- free (token);
+ } else {
+ f = fopen(datafile, "r");
+ if (f == NULL) {
+ printf(gettext("Failed to open %s for reading\n"), datafile);
+ return sbs;
}
+ }
- if ( (sscanf (buffer, "SLACKBUILD MD5SUM: %a[^\n]", &token)) == 1) {
- sb->md5sum = strdup (token);
- free (token);
- }
+ while ((g_size = getline(&buffer, &gb_length, f)) != EOF) {
+ char *token = NULL;
- if ( (sscanf (buffer, "SLACKBUILD MD5SUM_x86_64: %a[^\n]", &token)) == 1) {
- sb->md5sum_x86_64 = strdup (token);
- free (token);
+ if (strstr(buffer, "SLACKBUILD NAME:") != NULL) {
+ parse_state = SLAPT_SRC_PARSING;
+ sb = slapt_src_slackbuild_init();
}
- if ( (sscanf (buffer, "SLACKBUILD REQUIRES: %a[^\n]", &token)) == 1) {
- sb->requires = strdup (token);
- free (token);
+ if ((strcmp(buffer, "\n") == 0) && (parse_state == SLAPT_SRC_PARSING)) {
+ slapt_src_slackbuild_list_add(sbs, sb);
+ /* do not free, in use in sbs list
+ slapt_src_slackbuild_free (sb);
+ */
+ sb = NULL;
+ parse_state = SLAPT_SRC_NOT_PARSING;
}
- if ( (sscanf (buffer, "SLACKBUILD SHORT DESCRIPTION: %a[^\n]", &token)) == 1) {
- sb->short_desc = strdup (token);
- free (token);
+ switch (parse_state) {
+ case SLAPT_SRC_PARSING:
+
+ /* we skip empty fields for odd sscanf bug in older glibcs */
+ if (strstr(buffer, ": \n") != NULL)
+ continue;
+
+ if ((sscanf(buffer, "SLACKBUILD NAME: %as", &token)) == 1) {
+ sb->name = strdup(token);
+ free(token);
+ }
+
+ if ((sscanf(buffer, "SLACKBUILD SOURCEURL: %as", &token)) == 1) {
+ sb->sb_source_url = strdup(token);
+ free(token);
+ }
+
+ if ((sscanf(buffer, "SLACKBUILD LOCATION: %as", &token)) == 1) {
+ sb->location = strdup(token);
+ free(token);
+ }
+
+ if ((sscanf(buffer, "SLACKBUILD FILES: %a[^\n]", &token)) == 1) {
+ int c;
+ slapt_list_t *files = slapt_parse_delimited_list(token, ' ');
+ for (c = 0; c < files->count; c++) {
+ slapt_add_list_item(sb->files, files->items[c]);
+ }
+ slapt_free_list(files);
+ free(token);
+ }
+
+ if ((sscanf(buffer, "SLACKBUILD VERSION: %a[^\n]", &token)) == 1) {
+ sb->version = strdup(token);
+ free(token);
+ }
+
+ if ((sscanf(buffer, "SLACKBUILD DOWNLOAD: %a[^\n]", &token)) == 1) {
+ sb->download = strdup(token);
+ free(token);
+ }
+
+ if ((sscanf(buffer, "SLACKBUILD DOWNLOAD_x86_64: %a[^\n]", &token)) == 1) {
+ sb->download_x86_64 = strdup(token);
+ free(token);
+ }
+
+ if ((sscanf(buffer, "SLACKBUILD MD5SUM: %a[^\n]", &token)) == 1) {
+ sb->md5sum = strdup(token);
+ free(token);
+ }
+
+ if ((sscanf(buffer, "SLACKBUILD MD5SUM_x86_64: %a[^\n]", &token)) == 1) {
+ sb->md5sum_x86_64 = strdup(token);
+ free(token);
+ }
+
+ if ((sscanf(buffer, "SLACKBUILD REQUIRES: %a[^\n]", &token)) == 1) {
+ sb->requires = strdup(token);
+ free(token);
+ }
+
+ if ((sscanf(buffer, "SLACKBUILD SHORT DESCRIPTION: %a[^\n]", &token)) == 1) {
+ sb->short_desc = strdup(token);
+ free(token);
+ }
+
+ break;
+
+ default:
+ break;
}
-
- break;
-
- default:
- break;
}
+ if (buffer != NULL)
+ free(buffer);
- }
-
- if (buffer != NULL)
- free (buffer);
+ fclose(f);
- fclose (f);
-
- sbs->free_slackbuilds = true;
- return sbs;
+ sbs->free_slackbuilds = true;
+ return sbs;
}
-slapt_src_slackbuild_list *slapt_src_get_available_slackbuilds ()
+slapt_src_slackbuild_list *slapt_src_get_available_slackbuilds()
{
- return slapt_src_get_slackbuilds_from_file (SLAPT_SRC_DATA_FILE);
+ return slapt_src_get_slackbuilds_from_file(SLAPT_SRC_DATA_FILE);
}
-static char *filename_from_url (char *url)
+static char *filename_from_url(char *url)
{
- char *filename = NULL;
- slapt_list_t *parts = slapt_parse_delimited_list (url, '/');
- if (parts->count > 0) {
- filename = strdup (parts->items[parts->count-1]);
- }
- slapt_free_list (parts);
-
- return filename;
+ char *filename = NULL;
+ slapt_list_t *parts = slapt_parse_delimited_list(url, '/');
+ if (parts->count > 0) {
+ filename = strdup(parts->items[parts->count - 1]);
+ }
+ slapt_free_list(parts);
+
+ return filename;
}
-static char *add_part_to_url (char *url, char *part)
+static char *add_part_to_url(char *url, char *part)
{
- char *new = malloc (sizeof *new * (strlen (url) + strlen (part) + 1));
- if (new != NULL) {
- new = strcpy (new, url);
- new = strcat (new, part);
- }
+ char *new = malloc(sizeof *new *(strlen(url) + strlen(part) + 1));
+ if (new != NULL) {
+ new = strcpy(new, url);
+ new = strcat(new, part);
+ }
- return new;
+ return new;
}
-int slapt_src_fetch_slackbuild (slapt_src_config *config, slapt_src_slackbuild *sb)
+int slapt_src_fetch_slackbuild(slapt_src_config *config, slapt_src_slackbuild *sb)
{
- int i;
- slapt_list_t *download_parts = NULL, *md5sum_parts = NULL;
- slapt_rc_config *slapt_config = slapt_init_config ();
- char *sb_location = add_part_to_url (sb->sb_source_url, sb->location);
-
- /* need to mkdir and chdir to sb->location */
- slapt_create_dir_structure (sb->location);
- if (chdir (sb->location) != 0) {
- printf (gettext ("Failed to chdir to %s\n"), sb->location);
- exit (EXIT_FAILURE);
- }
-
- /* download slackbuild files */
- for (i = 0; i < sb->files->count; i++) {
- int curl_rv = 0;
- char *s = NULL, *url = add_part_to_url (sb_location, sb->files->items[i]);
- FILE *f = NULL;
-
- /* some files contain paths, create as necessary */
- if ((s = rindex (sb->files->items[i], '/')) != NULL) {
- char *initial_dir = strndup (sb->files->items[i], strlen (sb->files->items[i]) - strlen (s) +1);
- if (initial_dir != NULL) {
- slapt_create_dir_structure (initial_dir);
- free (initial_dir);
- }
+ int i;
+ slapt_list_t *download_parts = NULL, *md5sum_parts = NULL;
+ slapt_rc_config *slapt_config = slapt_init_config();
+ char *sb_location = add_part_to_url(sb->sb_source_url, sb->location);
+
+ /* need to mkdir and chdir to sb->location */
+ slapt_create_dir_structure(sb->location);
+ if (chdir(sb->location) != 0) {
+ printf(gettext("Failed to chdir to %s\n"), sb->location);
+ exit(EXIT_FAILURE);
}
- f = slapt_open_file (sb->files->items[i], "w+b");
- if (f == NULL) {
- perror ("Cannot open file for writing");
- exit (EXIT_FAILURE);
+ /* download slackbuild files */
+ for (i = 0; i < sb->files->count; i++) {
+ int curl_rv = 0;
+ char *s = NULL, *url = add_part_to_url(sb_location, sb->files->items[i]);
+ FILE *f = NULL;
+
+ /* some files contain paths, create as necessary */
+ if ((s = rindex(sb->files->items[i], '/')) != NULL) {
+ char *initial_dir = strndup(sb->files->items[i], strlen(sb->files->items[i]) - strlen(s) + 1);
+ if (initial_dir != NULL) {
+ slapt_create_dir_structure(initial_dir);
+ free(initial_dir);
+ }
+ }
+ f = slapt_open_file(sb->files->items[i], "w+b");
+
+ if (f == NULL) {
+ perror("Cannot open file for writing");
+ exit(EXIT_FAILURE);
+ }
+
+ /* TODO support file resume */
+ printf(gettext("Fetching %s..."), sb->files->items[i]);
+ curl_rv = slapt_download_data(f, url, 0, NULL, slapt_config);
+ if (curl_rv == 0) {
+ printf(gettext("Done\n"));
+ } else {
+ printf(gettext("Failed\n"));
+ exit(EXIT_FAILURE);
+ }
+
+ free(url);
+ fclose(f);
}
- /* TODO support file resume */
- printf (gettext ("Fetching %s..."), sb->files->items[i]);
- curl_rv = slapt_download_data (f, url, 0, NULL, slapt_config);
- if (curl_rv == 0) {
- printf (gettext ("Done\n"));
+ /* fetch download || download_x86_64 */
+ if (strcmp(uname_v.machine, "x86_64") == 0 && sb->download_x86_64 != NULL && strcmp(sb->download_x86_64, "") != 0 && strcmp(sb->download_x86_64, "UNSUPPORTED") != 0 && strcmp(sb->download_x86_64, "UNTESTED") != 0) {
+ download_parts = slapt_parse_delimited_list(sb->download_x86_64, ' ');
+ md5sum_parts = slapt_parse_delimited_list(sb->md5sum_x86_64, ' ');
} else {
- printf (gettext ("Failed\n"));
- exit (EXIT_FAILURE);
+ if (sb->download != NULL)
+ download_parts = slapt_parse_delimited_list(sb->download, ' ');
+ else
+ download_parts = slapt_init_list(); /* no download files */
+
+ if (sb->md5sum != NULL)
+ md5sum_parts = slapt_parse_delimited_list(sb->md5sum, ' ');
+ else
+ md5sum_parts = slapt_init_list(); /* no md5sum files */
}
- free (url);
- fclose (f);
- }
-
- /* fetch download || download_x86_64 */
- if (strcmp (uname_v.machine, "x86_64") == 0
- && sb->download_x86_64 != NULL
- && strcmp (sb->download_x86_64, "") != 0
- && strcmp (sb->download_x86_64, "UNSUPPORTED") != 0
- && strcmp (sb->download_x86_64, "UNTESTED") != 0) {
- download_parts = slapt_parse_delimited_list (sb->download_x86_64, ' ');
- md5sum_parts = slapt_parse_delimited_list (sb->md5sum_x86_64, ' ');
- } else {
- if (sb->download != NULL)
- download_parts = slapt_parse_delimited_list (sb->download, ' ');
- else
- download_parts = slapt_init_list (); /* no download files */
-
- if (sb->md5sum != NULL)
- md5sum_parts = slapt_parse_delimited_list (sb->md5sum, ' ');
- else
- md5sum_parts = slapt_init_list (); /* no md5sum files */
- }
-
- if (download_parts->count != md5sum_parts->count) {
- printf (gettext ("Mismatch between download files and md5sums\n"));
- exit (EXIT_FAILURE);
- }
-
- for (i = 0; i < download_parts->count; i++) {
- int curl_rv = 0;
- char *md5sum = md5sum_parts->items[i];
- char *filename = filename_from_url (download_parts->items[i]);
- FILE *f = NULL;
- char md5sum_to_prove[SLAPT_MD5_STR_LEN];
- struct stat file_stat;
- size_t file_size = 0;
-
- if (stat (filename,&file_stat) == 0 ) {
- /* if already exists, find out how much we already have */
- file_size = file_stat.st_size;
+ if (download_parts->count != md5sum_parts->count) {
+ printf(gettext("Mismatch between download files and md5sums\n"));
+ exit(EXIT_FAILURE);
}
- f = slapt_open_file (filename, "a+b");
- if (f == NULL) {
- perror ("Cannot open file for writing");
- exit (EXIT_FAILURE);
- }
+ for (i = 0; i < download_parts->count; i++) {
+ int curl_rv = 0;
+ char *md5sum = md5sum_parts->items[i];
+ char *filename = filename_from_url(download_parts->items[i]);
+ FILE *f = NULL;
+ char md5sum_to_prove[SLAPT_MD5_STR_LEN];
+ struct stat file_stat;
+ size_t file_size = 0;
+
+ if (stat(filename, &file_stat) == 0) {
+ /* if already exists, find out how much we already have */
+ file_size = file_stat.st_size;
+ }
- /* check checksum to see if we need to continue */
- slapt_gen_md5_sum_of_file (f, md5sum_to_prove);
- if (strcmp (md5sum_to_prove, md5sum) != 0 ) {
-
- printf (gettext ("Fetching %s..."), download_parts->items[i]);
- /* download/resume */
- curl_rv = slapt_download_data (f, download_parts->items[i], file_size, NULL, slapt_config);
- if (curl_rv == 0) {
- printf (gettext ("Done\n"));
- } else {
- printf (gettext ("Failed\n"));
- exit (EXIT_FAILURE);
- }
-
- /* verify checksum of downloaded file */
- slapt_gen_md5_sum_of_file (f, md5sum_to_prove);
- if (strcmp (md5sum_to_prove, md5sum) != 0 ) {
- printf (gettext ("MD5SUM mismatch for %s\n"), filename);
- exit (EXIT_FAILURE);
- }
+ f = slapt_open_file(filename, "a+b");
+ if (f == NULL) {
+ perror("Cannot open file for writing");
+ exit(EXIT_FAILURE);
+ }
- }
+ /* check checksum to see if we need to continue */
+ slapt_gen_md5_sum_of_file(f, md5sum_to_prove);
+ if (strcmp(md5sum_to_prove, md5sum) != 0) {
+ printf(gettext("Fetching %s..."), download_parts->items[i]);
+ /* download/resume */
+ curl_rv = slapt_download_data(f, download_parts->items[i], file_size, NULL, slapt_config);
+ if (curl_rv == 0) {
+ printf(gettext("Done\n"));
+ } else {
+ printf(gettext("Failed\n"));
+ exit(EXIT_FAILURE);
+ }
+
+ /* verify checksum of downloaded file */
+ slapt_gen_md5_sum_of_file(f, md5sum_to_prove);
+ if (strcmp(md5sum_to_prove, md5sum) != 0) {
+ printf(gettext("MD5SUM mismatch for %s\n"), filename);
+ exit(EXIT_FAILURE);
+ }
+ }
- fclose (f);
- free (filename);
- }
+ fclose(f);
+ free(filename);
+ }
- if (download_parts != NULL)
- slapt_free_list (download_parts);
- if (md5sum_parts != NULL)
- slapt_free_list (md5sum_parts);
+ if (download_parts != NULL)
+ slapt_free_list(download_parts);
+ if (md5sum_parts != NULL)
+ slapt_free_list(md5sum_parts);
- slapt_free_rc_config (slapt_config);
- free (sb_location);
+ slapt_free_rc_config(slapt_config);
+ free(sb_location);
- /* go back */
- if (chdir (config->builddir) != 0) {
- printf (gettext ("Failed to chdir to %s\n"), config->builddir);
- exit (EXIT_FAILURE);
- }
- return 0;
+ /* go back */
+ if (chdir(config->builddir) != 0) {
+ printf(gettext("Failed to chdir to %s\n"), config->builddir);
+ exit(EXIT_FAILURE);
+ }
+ return 0;
}
/* reads directory listing of current directory for a package */
-static char *_get_pkg_filename (const char *version, const char *pkgtag)
+static char *_get_pkg_filename(const char *version, const char *pkgtag)
{
- char *filename = NULL;
- DIR *d = NULL;
- struct dirent *file = NULL;
- struct stat stat_buf;
- slapt_regex_t *pkg_regex = NULL;
-
- d = opendir (".");
- if (d == NULL) {
- printf (gettext ("Failed to open current directory\n"));
- exit (EXIT_FAILURE);
- }
+ char *filename = NULL;
+ DIR *d = NULL;
+ struct dirent *file = NULL;
+ struct stat stat_buf;
+ slapt_regex_t *pkg_regex = NULL;
+
+ d = opendir(".");
+ if (d == NULL) {
+ printf(gettext("Failed to open current directory\n"));
+ exit(EXIT_FAILURE);
+ }
- if ((pkg_regex = slapt_init_regex (SLAPT_PKG_PARSE_REGEX)) == NULL) {
- exit (EXIT_FAILURE);
- }
+ if ((pkg_regex = slapt_init_regex(SLAPT_PKG_PARSE_REGEX)) == NULL) {
+ exit(EXIT_FAILURE);
+ }
- while ((file = readdir (d)) != NULL) {
+ while ((file = readdir(d)) != NULL) {
+ if (strcmp(file->d_name, "..") == 0 || strcmp(file->d_name, ".") == 0)
+ continue;
- if (strcmp (file->d_name, "..") == 0 || strcmp (file->d_name, ".") == 0)
- continue;
+ if (lstat(file->d_name, &stat_buf) == -1)
+ continue;
- if (lstat (file->d_name, &stat_buf) == -1)
- continue;
+ if (!S_ISREG(stat_buf.st_mode))
+ continue;
- if (! S_ISREG (stat_buf.st_mode))
- continue;
+ slapt_execute_regex(pkg_regex, file->d_name);
+ if (pkg_regex->reg_return != 0)
+ continue;
- slapt_execute_regex (pkg_regex,file->d_name);
- if (pkg_regex->reg_return != 0)
- continue;
-
- /* version from .info file may not match resulting
+ /* version from .info file may not match resulting
pkg version
libva: VERSION="0.31.1-1+sds4" and VERSION=0.31.1_1+sds4
if (strstr (file->d_name, version) == NULL)
continue;
*/
- if (pkgtag != NULL)
- if (strstr (file->d_name, pkgtag) == NULL)
- continue;
+ if (pkgtag != NULL)
+ if (strstr(file->d_name, pkgtag) == NULL)
+ continue;
- filename = strdup (file->d_name);
- break;
-
- }
+ filename = strdup(file->d_name);
+ break;
+ }
- closedir (d);
- slapt_free_regex (pkg_regex);
+ closedir(d);
+ slapt_free_regex(pkg_regex);
- return filename;
+ return filename;
}
-int slapt_src_build_slackbuild (slapt_src_config *config, slapt_src_slackbuild *sb)
+int slapt_src_build_slackbuild(slapt_src_config *config, slapt_src_slackbuild *sb)
{
- char *cwd = NULL;
- char *command = NULL;
- int command_len = SLAPTSRC_CMD_LEN, r = 0;
+ char *cwd = NULL;
+ char *command = NULL;
+ int command_len = SLAPTSRC_CMD_LEN, r = 0;
- if (chdir (sb->location) != 0) {
- printf (gettext ("Failed to chdir to %s\n"), sb->location);
- exit (EXIT_FAILURE);
- }
+ if (chdir(sb->location) != 0) {
+ printf(gettext("Failed to chdir to %s\n"), sb->location);
+ exit(EXIT_FAILURE);
+ }
- /*
+ /*
make sure we set locations and other env vars for the slackbuilds to honor
*/
- cwd = get_current_dir_name ();
- setenv ("TMP", cwd, 1);
- setenv ("OUTPUT", cwd, 1);
- free (cwd);
-
- if ( config->pkgext != NULL)
- setenv ("PKGTYPE", config->pkgext, 1);
-
- if ( config->pkgtag != NULL)
- setenv ("TAG", config->pkgtag, 1);
-
- if (strcmp (uname_v.machine, "x86_64") == 0
- && sb->download_x86_64 != NULL
- && strcmp (sb->download_x86_64, "") != 0
- && strcmp (sb->download_x86_64, "UNSUPPORTED") != 0
- && strcmp (sb->download_x86_64, "UNTESTED") != 0) {
- setenv ("ARCH", uname_v.machine, 1);
- }
-
-#if defined (HAS_SLKBUILD)
- if (slapt_search_list (sb->files, "SLKBUILD") != NULL) {
- command_len = SLAPTSRC_SLKBUILD_CMD_LEN;
- command = slapt_malloc (sizeof *command * command_len);
- r = snprintf (command, command_len, "%s", SLAPTSRC_SLKBUILD_CMD);
- } else {
+ cwd = get_current_dir_name();
+ setenv("TMP", cwd, 1);
+ setenv("OUTPUT", cwd, 1);
+ free(cwd);
+
+ if (config->pkgext != NULL)
+ setenv("PKGTYPE", config->pkgext, 1);
+
+ if (config->pkgtag != NULL)
+ setenv("TAG", config->pkgtag, 1);
+
+ if (strcmp(uname_v.machine, "x86_64") == 0 && sb->download_x86_64 != NULL && strcmp(sb->download_x86_64, "") != 0 && strcmp(sb->download_x86_64, "UNSUPPORTED") != 0 && strcmp(sb->download_x86_64, "UNTESTED") != 0) {
+ setenv("ARCH", uname_v.machine, 1);
+ }
+
+#if defined(HAS_SLKBUILD)
+ if (slapt_search_list(sb->files, "SLKBUILD") != NULL) {
+ command_len = SLAPTSRC_SLKBUILD_CMD_LEN;
+ command = slapt_malloc(sizeof *command * command_len);
+ r = snprintf(command, command_len, "%s", SLAPTSRC_SLKBUILD_CMD);
+ } else {
#endif
- command_len += strlen (sb->name);
- command = slapt_malloc (sizeof *command * command_len);
- r = snprintf (command, command_len, "%s %s.SlackBuild", SLAPTSRC_CMD, sb->name);
-#if defined (HAS_SLKBUILD)
- }
+ command_len += strlen(sb->name);
+ command = slapt_malloc(sizeof *command * command_len);
+ r = snprintf(command, command_len, "%s %s.SlackBuild", SLAPTSRC_CMD, sb->name);
+#if defined(HAS_SLKBUILD)
+ }
#endif
- if (r+1 != command_len) {
- printf ("%s (%d,%d,%s)\n", gettext ("Failed to construct command string\n"), r, command_len, command);
- exit (EXIT_FAILURE);
- }
-
- r = system (command);
- if (r != 0) {
- printf ("%s %s\n", command, gettext ("Failed\n"));
- exit (EXIT_FAILURE);
- }
+ if (r + 1 != command_len) {
+ printf("%s (%d,%d,%s)\n", gettext("Failed to construct command string\n"), r, command_len, command);
+ exit(EXIT_FAILURE);
+ }
- free (command);
+ r = system(command);
+ if (r != 0) {
+ printf("%s %s\n", command, gettext("Failed\n"));
+ exit(EXIT_FAILURE);
+ }
- if (config->postcmd != NULL) {
- char *filename = NULL;
- if ( (filename = _get_pkg_filename (sb->version, config->pkgtag)) != NULL) {
- char *command = NULL;
- int r = 0, command_len = strlen (config->postcmd) + strlen (filename) + 2;
- command = slapt_malloc (sizeof *command * command_len);
- r = snprintf (command, command_len, "%s %s", config->postcmd, filename);
- if (r+1 != command_len) {
- printf (gettext ("Failed to construct command string\n"));
- exit (EXIT_FAILURE);
- }
- r = system (command);
- if (r != 0) {
- printf ("%s %s\n", command, gettext ("Failed\n"));
- exit (EXIT_FAILURE);
- }
- free (command);
- } else {
- printf (gettext ("Unable to find generated package\n"));
- exit (EXIT_FAILURE);
+ free(command);
+
+ if (config->postcmd != NULL) {
+ char *filename = NULL;
+ if ((filename = _get_pkg_filename(sb->version, config->pkgtag)) != NULL) {
+ char *command = NULL;
+ int r = 0, command_len = strlen(config->postcmd) + strlen(filename) + 2;
+ command = slapt_malloc(sizeof *command * command_len);
+ r = snprintf(command, command_len, "%s %s", config->postcmd, filename);
+ if (r + 1 != command_len) {
+ printf(gettext("Failed to construct command string\n"));
+ exit(EXIT_FAILURE);
+ }
+ r = system(command);
+ if (r != 0) {
+ printf("%s %s\n", command, gettext("Failed\n"));
+ exit(EXIT_FAILURE);
+ }
+ free(command);
+ } else {
+ printf(gettext("Unable to find generated package\n"));
+ exit(EXIT_FAILURE);
+ }
+ free(filename);
}
- free (filename);
- }
- /* go back */
- if (chdir (config->builddir) != 0) {
- printf (gettext ("Failed to chdir to %s\n"), config->builddir);
- exit (EXIT_FAILURE);
- }
+ /* go back */
+ if (chdir(config->builddir) != 0) {
+ printf(gettext("Failed to chdir to %s\n"), config->builddir);
+ exit(EXIT_FAILURE);
+ }
- return 0;
+ return 0;
}
-int slapt_src_install_slackbuild (slapt_src_config *config, slapt_src_slackbuild *sb)
+int slapt_src_install_slackbuild(slapt_src_config *config, slapt_src_slackbuild *sb)
{
- char *filename = NULL;
- char *command = NULL;
- int command_len = 38, r = 0;
-
- if (chdir (sb->location) != 0) {
- printf (gettext ("Failed to chdir to %s\n"), sb->location);
- exit (EXIT_FAILURE);
- }
-
- if ( (filename = _get_pkg_filename (sb->version, config->pkgtag)) != NULL) {
- command_len += strlen (filename);
- command = slapt_malloc (sizeof *command * command_len);
- r = snprintf (command, command_len, "upgradepkg --reinstall --install-new %s", filename);
- if (r+1 != command_len) {
- printf (gettext ("Failed to construct command string\n"));
- exit (EXIT_FAILURE);
+ char *filename = NULL;
+ char *command = NULL;
+ int command_len = 38, r = 0;
+
+ if (chdir(sb->location) != 0) {
+ printf(gettext("Failed to chdir to %s\n"), sb->location);
+ exit(EXIT_FAILURE);
}
- r = system (command);
- if (r != 0) {
- printf ("%s %s\n", command, gettext ("Failed\n"));
- exit (EXIT_FAILURE);
+ if ((filename = _get_pkg_filename(sb->version, config->pkgtag)) != NULL) {
+ command_len += strlen(filename);
+ command = slapt_malloc(sizeof *command * command_len);
+ r = snprintf(command, command_len, "upgradepkg --reinstall --install-new %s", filename);
+ if (r + 1 != command_len) {
+ printf(gettext("Failed to construct command string\n"));
+ exit(EXIT_FAILURE);
+ }
+
+ r = system(command);
+ if (r != 0) {
+ printf("%s %s\n", command, gettext("Failed\n"));
+ exit(EXIT_FAILURE);
+ }
+
+ free(filename);
+ free(command);
+ } else {
+ printf(gettext("Unable to find generated package\n"));
+ exit(EXIT_FAILURE);
}
- free (filename);
- free (command);
- } else {
- printf (gettext ("Unable to find generated package\n"));
- exit (EXIT_FAILURE);
- }
-
- /* go back */
- if (chdir (config->builddir) != 0) {
- printf (gettext ("Failed to chdir to %s\n"), config->builddir);
- exit (EXIT_FAILURE);
- }
- return 0;
+ /* go back */
+ if (chdir(config->builddir) != 0) {
+ printf(gettext("Failed to chdir to %s\n"), config->builddir);
+ exit(EXIT_FAILURE);
+ }
+ return 0;
}
-slapt_src_slackbuild *slapt_src_get_slackbuild (slapt_src_slackbuild_list *sbs, const char *name, const char *version)
+slapt_src_slackbuild *slapt_src_get_slackbuild(slapt_src_slackbuild_list *sbs, const char *name, const char *version)
{
- int min = 0, max = sbs->count - 1;
+ int min = 0, max = sbs->count - 1;
- while (max >= min) {
- int pivot = (min + max) / 2;
- int name_cmp = strcmp (sbs->slackbuilds[pivot]->name, name);
- int ver_cmp = 0;
+ while (max >= min) {
+ int pivot = (min + max) / 2;
+ int name_cmp = strcmp(sbs->slackbuilds[pivot]->name, name);
+ int ver_cmp = 0;
- if ( name_cmp == 0 ) {
- if (version == NULL)
- return sbs->slackbuilds[pivot];
+ if (name_cmp == 0) {
+ if (version == NULL)
+ return sbs->slackbuilds[pivot];
- ver_cmp = slapt_cmp_pkg_versions (sbs->slackbuilds[pivot]->version, version);
- if (ver_cmp == 0)
- return sbs->slackbuilds[pivot];
+ ver_cmp = slapt_cmp_pkg_versions(sbs->slackbuilds[pivot]->version, version);
+ if (ver_cmp == 0)
+ return sbs->slackbuilds[pivot];
- if (ver_cmp < 0)
- min = pivot + 1;
- else
- max = pivot - 1;
+ if (ver_cmp < 0)
+ min = pivot + 1;
+ else
+ max = pivot - 1;
- } else {
- if ( name_cmp < 0 )
- min = pivot + 1;
- else
- max = pivot - 1;
+ } else {
+ if (name_cmp < 0)
+ min = pivot + 1;
+ else
+ max = pivot - 1;
+ }
}
- }
- return NULL;
+ return NULL;
}
/* for short, unsorted slackbulid_lists */
-static bool _slapt_src_search_slackbuild_cache_linear_by_name (slapt_src_slackbuild_list *sbs, const char *name)
+static bool _slapt_src_search_slackbuild_cache_linear_by_name(slapt_src_slackbuild_list *sbs, const char *name)
{
- int i;
- for (i = 0; i < sbs->count; i++) {
- if (strcmp (sbs->slackbuilds[i]->name, name) == 0)
- return true;
- }
- return false;
+ int i;
+ for (i = 0; i < sbs->count; i++) {
+ if (strcmp(sbs->slackbuilds[i]->name, name) == 0)
+ return true;
+ }
+ return false;
}
-static int slapt_src_resolve_dependencies (
+static int slapt_src_resolve_dependencies(
slapt_src_slackbuild_list *available,
slapt_src_slackbuild *sb,
slapt_src_slackbuild_list *deps,
slapt_pkg_list_t *installed,
slapt_pkg_err_list_t *errors)
{
- int r = 0;
- slapt_list_t *requires = NULL;
- if (sb->requires == NULL)
- return 0;
+ int r = 0;
+ slapt_list_t *requires = NULL;
+ if (sb->requires == NULL)
+ return 0;
- if (strstr(sb->requires,",") != NULL)
- requires = slapt_parse_delimited_list (sb->requires, ',');
- else
- requires = slapt_parse_delimited_list (sb->requires, ' ');
+ if (strstr(sb->requires, ",") != NULL)
+ requires = slapt_parse_delimited_list(sb->requires, ',');
+ else
+ requires = slapt_parse_delimited_list(sb->requires, ' ');
- if (requires == NULL)
- return 0;
+ if (requires == NULL)
+ return 0;
- for (r = 0; r < requires->count; r++) {
- const char *dep_name = requires->items[r];
- slapt_src_slackbuild *sb_dep = NULL;
+ for (r = 0; r < requires->count; r++) {
+ const char *dep_name = requires->items[r];
+ slapt_src_slackbuild *sb_dep = NULL;
- /* skip non-deps */
- if (strcmp (dep_name,"%README%") == 0)
- continue;
+ /* skip non-deps */
+ if (strcmp(dep_name, "%README%") == 0)
+ continue;
- sb_dep = slapt_src_get_slackbuild (available, dep_name, NULL);
-
- /* we will try and resolve its dependencies no matter what,
+ sb_dep = slapt_src_get_slackbuild(available, dep_name, NULL);
+
+ /* we will try and resolve its dependencies no matter what,
in case there are new deps we don't yet have */
- if (sb_dep != NULL) {
- int dep_check = slapt_src_resolve_dependencies (available, sb_dep, deps, installed, errors);
-
- if (dep_check != 0)
- return dep_check;
-
- /* if not installed */
- if (slapt_get_newest_pkg (installed, dep_name) == NULL) {
- /* if not already being tracked */
- if (_slapt_src_search_slackbuild_cache_linear_by_name (deps, dep_name) == false)
- slapt_src_slackbuild_list_add (deps, sb_dep);
- }
- }
- /* we don't have a slackbuild for it */
- else {
- /* if not installed, this is an error */
- if (slapt_get_newest_pkg (installed, dep_name) == NULL) {
- slapt_add_pkg_err_to_list (errors, sb->name, dep_name);
- slapt_free_list (requires);
- return 1;
- }
+ if (sb_dep != NULL) {
+ int dep_check = slapt_src_resolve_dependencies(available, sb_dep, deps, installed, errors);
+
+ if (dep_check != 0)
+ return dep_check;
+
+ /* if not installed */
+ if (slapt_get_newest_pkg(installed, dep_name) == NULL) {
+ /* if not already being tracked */
+ if (_slapt_src_search_slackbuild_cache_linear_by_name(deps, dep_name) == false)
+ slapt_src_slackbuild_list_add(deps, sb_dep);
+ }
+ }
+ /* we don't have a slackbuild for it */
+ else {
+ /* if not installed, this is an error */
+ if (slapt_get_newest_pkg(installed, dep_name) == NULL) {
+ slapt_add_pkg_err_to_list(errors, sb->name, dep_name);
+ slapt_free_list(requires);
+ return 1;
+ }
+ }
}
- }
- slapt_free_list (requires);
- return 0;
+ slapt_free_list(requires);
+ return 0;
}
-slapt_src_slackbuild_list *slapt_src_names_to_slackbuilds (
+slapt_src_slackbuild_list *slapt_src_names_to_slackbuilds(
slapt_src_config *config,
slapt_src_slackbuild_list *available,
slapt_list_t *names,
slapt_pkg_list_t *installed)
{
- int i;
- slapt_src_slackbuild_list *sbs = slapt_src_slackbuild_list_init ();
-
- for (i = 0; i < names->count; i++) {
- slapt_src_slackbuild *sb = NULL;
- slapt_list_t *parts = slapt_parse_delimited_list (names->items[i], ':');
- if (parts->count > 1)
- sb = slapt_src_get_slackbuild (available, parts->items[0], parts->items[1]);
- else
- sb = slapt_src_get_slackbuild (available, names->items[i], NULL);
-
- slapt_free_list (parts);
-
- if (sb != NULL) {
-
- if (config->do_dep == true) {
- int d;
- slapt_src_slackbuild_list *deps = slapt_src_slackbuild_list_init ();
- slapt_pkg_err_list_t *errors = slapt_init_pkg_err_list ();
- int dep_check = slapt_src_resolve_dependencies (available, sb, deps, installed, errors);
-
- if (dep_check != 0) {
- for (d = 0; d < errors->err_count; d++) {
- slapt_pkg_err_t *err = errors->errs[d];
- fprintf (stderr, gettext ("Missing slackbuild: %s requires %s\n"), err->pkg, err->error);
- }
- slapt_src_slackbuild_list_free (deps);
- slapt_free_pkg_err_list (errors);
- continue;
- }
-
- slapt_free_pkg_err_list (errors);
-
- for (d = 0; d < deps->count; d++) {
- if (_slapt_src_search_slackbuild_cache_linear_by_name (sbs, deps->slackbuilds[d]->name) == false)
- slapt_src_slackbuild_list_add (sbs, deps->slackbuilds[d]);
+ int i;
+ slapt_src_slackbuild_list *sbs = slapt_src_slackbuild_list_init();
+
+ for (i = 0; i < names->count; i++) {
+ slapt_src_slackbuild *sb = NULL;
+ slapt_list_t *parts = slapt_parse_delimited_list(names->items[i], ':');
+ if (parts->count > 1)
+ sb = slapt_src_get_slackbuild(available, parts->items[0], parts->items[1]);
+ else
+ sb = slapt_src_get_slackbuild(available, names->items[i], NULL);
+
+ slapt_free_list(parts);
+
+ if (sb != NULL) {
+ if (config->do_dep == true) {
+ int d;
+ slapt_src_slackbuild_list *deps = slapt_src_slackbuild_list_init();
+ slapt_pkg_err_list_t *errors = slapt_init_pkg_err_list();
+ int dep_check = slapt_src_resolve_dependencies(available, sb, deps, installed, errors);
+
+ if (dep_check != 0) {
+ for (d = 0; d < errors->err_count; d++) {
+ slapt_pkg_err_t *err = errors->errs[d];
+ fprintf(stderr, gettext("Missing slackbuild: %s requires %s\n"), err->pkg, err->error);
+ }
+ slapt_src_slackbuild_list_free(deps);
+ slapt_free_pkg_err_list(errors);
+ continue;
+ }
+
+ slapt_free_pkg_err_list(errors);
+
+ for (d = 0; d < deps->count; d++) {
+ if (_slapt_src_search_slackbuild_cache_linear_by_name(sbs, deps->slackbuilds[d]->name) == false)
+ slapt_src_slackbuild_list_add(sbs, deps->slackbuilds[d]);
+ }
+
+ slapt_src_slackbuild_list_free(deps);
+ }
+
+ if (_slapt_src_search_slackbuild_cache_linear_by_name(sbs, sb->name) == false)
+ slapt_src_slackbuild_list_add(sbs, sb);
}
-
- slapt_src_slackbuild_list_free (deps);
- }
-
- if (_slapt_src_search_slackbuild_cache_linear_by_name (sbs, sb->name) == false)
- slapt_src_slackbuild_list_add (sbs, sb);
}
- }
-
- return sbs;
+ return sbs;
}
-slapt_src_slackbuild_list *slapt_src_search_slackbuild_cache (slapt_src_slackbuild_list *remote_sbs, slapt_list_t *names)
+slapt_src_slackbuild_list *slapt_src_search_slackbuild_cache(slapt_src_slackbuild_list *remote_sbs, slapt_list_t *names)
{
- int i, n;
- slapt_src_slackbuild_list *sbs = slapt_src_slackbuild_list_init ();
+ int i, n;
+ slapt_src_slackbuild_list *sbs = slapt_src_slackbuild_list_init();
- for (n = 0; n < names->count; n++) {
- slapt_regex_t *search_regex = slapt_init_regex (names->items[n]);
- if (search_regex == NULL)
- continue;
+ for (n = 0; n < names->count; n++) {
+ slapt_regex_t *search_regex = slapt_init_regex(names->items[n]);
+ if (search_regex == NULL)
+ continue;
- for (i = 0; i < remote_sbs->count; i++) {
- int name_r = -1, version_r = -1, short_desc_r = -1;
+ for (i = 0; i < remote_sbs->count; i++) {
+ int name_r = -1, version_r = -1, short_desc_r = -1;
- if (strcmp (remote_sbs->slackbuilds[i]->name, names->items[n]) == 0) {
- slapt_src_slackbuild_list_add (sbs, remote_sbs->slackbuilds[i]);
- continue;
- }
+ if (strcmp(remote_sbs->slackbuilds[i]->name, names->items[n]) == 0) {
+ slapt_src_slackbuild_list_add(sbs, remote_sbs->slackbuilds[i]);
+ continue;
+ }
- slapt_execute_regex (search_regex, remote_sbs->slackbuilds[i]->name);
- name_r = search_regex->reg_return;
+ slapt_execute_regex(search_regex, remote_sbs->slackbuilds[i]->name);
+ name_r = search_regex->reg_return;
- slapt_execute_regex (search_regex, remote_sbs->slackbuilds[i]->location);
- version_r = search_regex->reg_return;
+ slapt_execute_regex(search_regex, remote_sbs->slackbuilds[i]->location);
+ version_r = search_regex->reg_return;
- if (remote_sbs->slackbuilds[i]->short_desc != NULL) {
- slapt_execute_regex (search_regex, remote_sbs->slackbuilds[i]->short_desc);
- short_desc_r = search_regex->reg_return;
- }
+ if (remote_sbs->slackbuilds[i]->short_desc != NULL) {
+ slapt_execute_regex(search_regex, remote_sbs->slackbuilds[i]->short_desc);
+ short_desc_r = search_regex->reg_return;
+ }
- if (name_r == 0 || version_r == 0 || short_desc_r == 0)
- slapt_src_slackbuild_list_add (sbs, remote_sbs->slackbuilds[i]);
+ if (name_r == 0 || version_r == 0 || short_desc_r == 0)
+ slapt_src_slackbuild_list_add(sbs, remote_sbs->slackbuilds[i]);
+ }
+ slapt_free_regex(search_regex);
}
- slapt_free_regex (search_regex);
- }
-
- return sbs;
+ return sbs;
}
diff --git a/src/source.h b/src/source.h
index 0d0517c..7d6efe7 100644
--- a/src/source.h
+++ b/src/source.h
@@ -30,55 +30,52 @@
#define SLAPT_SRC_SOURCES_LIST_GZ "SLACKBUILDS.TXT.gz"
#define SLAPT_SRC_SOURCES_LIST "SLACKBUILDS.TXT"
-typedef struct _slapt_src_config_
-{
- slapt_list_t *sources;
- char *builddir;
- char *pkgext;
- char *pkgtag;
- char *postcmd;
- bool do_dep;
+typedef struct _slapt_src_config_ {
+ slapt_list_t *sources;
+ char *builddir;
+ char *pkgext;
+ char *pkgtag;
+ char *postcmd;
+ bool do_dep;
} slapt_src_config;
-slapt_src_config *slapt_src_config_init (void);
-void slapt_src_config_free (slapt_src_config *config);
-slapt_src_config *slapt_src_read_config (const char *filename);
+slapt_src_config *slapt_src_config_init(void);
+void slapt_src_config_free(slapt_src_config *config);
+slapt_src_config *slapt_src_read_config(const char *filename);
-typedef struct _slapt_src_slackbuild_
-{
- char *name;
- char *version;
- char *location;
- char *sb_source_url;
- slapt_list_t *files;
- char *download;
- char *download_x86_64;
- char *md5sum;
- char *md5sum_x86_64;
- char *short_desc;
- char *requires;
+typedef struct _slapt_src_slackbuild_ {
+ char *name;
+ char *version;
+ char *location;
+ char *sb_source_url;
+ slapt_list_t *files;
+ char *download;
+ char *download_x86_64;
+ char *md5sum;
+ char *md5sum_x86_64;
+ char *short_desc;
+ char *requires;
} slapt_src_slackbuild;
-slapt_src_slackbuild *slapt_src_slackbuild_init (void);
-void slapt_src_slackbuild_free (slapt_src_slackbuild *);
+slapt_src_slackbuild *slapt_src_slackbuild_init(void);
+void slapt_src_slackbuild_free(slapt_src_slackbuild *);
-typedef struct _slapt_src_slackbuilds_
-{
- slapt_src_slackbuild **slackbuilds;
- unsigned int count;
- bool free_slackbuilds;
+typedef struct _slapt_src_slackbuilds_ {
+ slapt_src_slackbuild **slackbuilds;
+ unsigned int count;
+ bool free_slackbuilds;
} slapt_src_slackbuild_list;
-slapt_src_slackbuild_list *slapt_src_slackbuild_list_init (void);
-void slapt_src_slackbuild_list_free (slapt_src_slackbuild_list *);
-void slapt_src_slackbuild_list_add (slapt_src_slackbuild_list *, slapt_src_slackbuild *);
+slapt_src_slackbuild_list *slapt_src_slackbuild_list_init(void);
+void slapt_src_slackbuild_list_free(slapt_src_slackbuild_list *);
+void slapt_src_slackbuild_list_add(slapt_src_slackbuild_list *, slapt_src_slackbuild *);
-int slapt_src_update_slackbuild_cache (slapt_src_config *);
-slapt_src_slackbuild_list *slapt_src_get_available_slackbuilds (void);
-int slapt_src_fetch_slackbuild (slapt_src_config *, slapt_src_slackbuild *);
-int slapt_src_build_slackbuild (slapt_src_config *, slapt_src_slackbuild *);
-int slapt_src_install_slackbuild (slapt_src_config *, slapt_src_slackbuild *);
-slapt_src_slackbuild_list *slapt_src_names_to_slackbuilds (slapt_src_config *, slapt_src_slackbuild_list *, slapt_list_t *, slapt_pkg_list_t *);
-slapt_src_slackbuild_list *slapt_src_get_slackbuilds_from_file (const char *);
-void slapt_src_write_slackbuilds_to_file (slapt_src_slackbuild_list *, const char *);
-slapt_src_slackbuild_list *slapt_src_search_slackbuild_cache (slapt_src_slackbuild_list *, slapt_list_t *);
-slapt_src_slackbuild *slapt_src_get_slackbuild (slapt_src_slackbuild_list *, const char *, const char *);
+int slapt_src_update_slackbuild_cache(slapt_src_config *);
+slapt_src_slackbuild_list *slapt_src_get_available_slackbuilds(void);
+int slapt_src_fetch_slackbuild(slapt_src_config *, slapt_src_slackbuild *);
+int slapt_src_build_slackbuild(slapt_src_config *, slapt_src_slackbuild *);
+int slapt_src_install_slackbuild(slapt_src_config *, slapt_src_slackbuild *);
+slapt_src_slackbuild_list *slapt_src_names_to_slackbuilds(slapt_src_config *, slapt_src_slackbuild_list *, slapt_list_t *, slapt_pkg_list_t *);
+slapt_src_slackbuild_list *slapt_src_get_slackbuilds_from_file(const char *);
+void slapt_src_write_slackbuilds_to_file(slapt_src_slackbuild_list *, const char *);
+slapt_src_slackbuild_list *slapt_src_search_slackbuild_cache(slapt_src_slackbuild_list *, slapt_list_t *);
+slapt_src_slackbuild *slapt_src_get_slackbuild(slapt_src_slackbuild_list *, const char *, const char *);
#endif