summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Woodward2018-07-11 01:26:09 +0000
committerJason Woodward2018-07-10 21:28:54 -0400
commit7fd6e2b93df23d80593a8598df6e9e5014746b32 (patch)
treec3b74b4963231ab0fa2b29e16c0222dd257bac58
parent1542c7abc9165097c5fb25c18092c0f81d806a1f (diff)
downloadslapt-get-7fd6e2b93df23d80593a8598df6e9e5014746b32.tar.gz
more bool conversions
-rw-r--r--src/package.c25
-rw-r--r--src/package.h2
-rw-r--r--src/transaction.c66
-rw-r--r--src/transaction.h12
-rw-r--r--t/test_transaction.c10
5 files changed, 54 insertions, 61 deletions
diff --git a/src/package.c b/src/package.c
index 4a384b7..ba6cc14 100644
--- a/src/package.c
+++ b/src/package.c
@@ -1848,7 +1848,7 @@ slapt_pkg_info_t *slapt_get_pkg_by_details(slapt_pkg_list_t *list,
/* update package data from mirror url */
int slapt_update_pkg_cache(const slapt_rc_config *global_config)
{
- uint32_t source_dl_failed = 0;
+ bool source_dl_failed = false;
slapt_pkg_list_t *new_pkgs = slapt_init_pkg_list();
new_pkgs->free_pkgs = true;
@@ -1873,7 +1873,7 @@ int slapt_update_pkg_cache(const slapt_rc_config *global_config)
available_pkgs = slapt_get_pkg_source_packages(global_config, source_url, &compressed);
if (available_pkgs == NULL) {
- source_dl_failed = 1;
+ source_dl_failed = true;
continue;
}
@@ -1911,7 +1911,7 @@ int slapt_update_pkg_cache(const slapt_rc_config *global_config)
printf("%s%s\n", slapt_strerror(verified), gettext(", but accepted as an exception"));
} else {
printf("%s\n", gettext(slapt_strerror(verified)));
- source_dl_failed = 1;
+ source_dl_failed = true;
fclose(tmp_checksum_f);
tmp_checksum_f = NULL;
}
@@ -1929,7 +1929,7 @@ int slapt_update_pkg_cache(const slapt_rc_config *global_config)
}
#endif
- if (source_dl_failed != 1) {
+ if (!source_dl_failed) {
printf(gettext("Retrieving ChangeLog.txt [%s]..."), source_url);
slapt_get_pkg_source_changelog(global_config, source_url, &compressed);
}
@@ -1986,7 +1986,7 @@ int slapt_update_pkg_cache(const slapt_rc_config *global_config)
fclose(tmp_checksum_f);
} else {
- source_dl_failed = 1;
+ source_dl_failed = true;
}
if (available_pkgs)
@@ -1998,7 +1998,7 @@ int slapt_update_pkg_cache(const slapt_rc_config *global_config)
} /* end for loop */
/* if all our downloads where a success, write to SLAPT_PKG_LIST_L */
- if (source_dl_failed != 1) {
+ if (!source_dl_failed) {
FILE *pkg_list_fh;
if ((pkg_list_fh = slapt_open_file(SLAPT_PKG_LIST_L, "w+")) == NULL)
@@ -2783,7 +2783,7 @@ slapt_pkg_list_t *slapt_get_pkg_source_patches(const slapt_rc_config *global_con
fprintf(stderr, gettext("Failed to download: %s\n"), err);
fclose(tmp_patch_f);
/* we don't care if the patch fails, for example current
- doesn't have patches source_dl_failed = 1; */
+ doesn't have patches source_dl_failed = true; */
slapt_clear_head_cache(patch_filename);
}
@@ -2843,7 +2843,7 @@ slapt_pkg_list_t *slapt_get_pkg_source_patches(const slapt_rc_config *global_con
} else {
/* we don't care if the patch fails, for example current
- doesn't have patches source_dl_failed = 1; */
+ doesn't have patches source_dl_failed = true; */
slapt_clear_head_cache(patch_filename);
if (is_interactive)
@@ -3000,7 +3000,7 @@ FILE *slapt_get_pkg_source_checksums(const slapt_rc_config *global_config,
return tmp_checksum_f;
}
-int slapt_get_pkg_source_changelog(const slapt_rc_config *global_config,
+bool slapt_get_pkg_source_changelog(const slapt_rc_config *global_config,
const char *url, bool *compressed)
{
char *changelog_head = NULL;
@@ -3009,7 +3009,6 @@ int slapt_get_pkg_source_changelog(const slapt_rc_config *global_config,
char *location_gz = SLAPT_CHANGELOG_FILE_GZ;
char *location_uncomp = SLAPT_CHANGELOG_FILE;
char *location = location_gz;
- int success = 0, failure = -1;
bool is_interactive = slapt_is_interactive(global_config);
*compressed = 0;
@@ -3025,7 +3024,7 @@ int slapt_get_pkg_source_changelog(const slapt_rc_config *global_config,
if (changelog_head == NULL) {
if (is_interactive)
printf(gettext("Done\n"));
- return success;
+ return true;
}
filename = slapt_gen_filename_from_url(url, location);
@@ -3076,7 +3075,7 @@ int slapt_get_pkg_source_changelog(const slapt_rc_config *global_config,
free(local_head);
if (changelog_head != NULL)
free(changelog_head);
- return failure;
+ return false;
}
}
free(filename);
@@ -3085,7 +3084,7 @@ int slapt_get_pkg_source_changelog(const slapt_rc_config *global_config,
if (changelog_head != NULL)
free(changelog_head);
- return success;
+ return true;
}
void slapt_clean_description(char *description, const char *name)
diff --git a/src/package.h b/src/package.h
index 63852d8..426afb8 100644
--- a/src/package.h
+++ b/src/package.h
@@ -292,7 +292,7 @@ slapt_pkg_list_t *slapt_get_pkg_source_patches(const slapt_rc_config *global_con
const char *url, bool *compressed);
FILE *slapt_get_pkg_source_checksums(const slapt_rc_config *global_config,
const char *url, bool *compressed);
-int slapt_get_pkg_source_changelog(const slapt_rc_config *global_config,
+bool slapt_get_pkg_source_changelog(const slapt_rc_config *global_config,
const char *url, bool *compressed);
/* clean package name from package description */
diff --git a/src/transaction.c b/src/transaction.c
index e1fc8b9..c57d9da 100644
--- a/src/transaction.c
+++ b/src/transaction.c
@@ -114,7 +114,7 @@ int slapt_handle_transaction(const slapt_rc_config *global_config,
len = 0;
slapt_list_t_foreach(s, tran->suggests) {
/* don't show suggestion for something we already have in the transaction */
- if (slapt_search_transaction(tran, s) == 1)
+ if (slapt_search_transaction(tran, s))
continue;
if (len + strlen(s) + 1 < MAX_LINE_LEN) {
@@ -378,7 +378,7 @@ int slapt_handle_transaction(const slapt_rc_config *global_config,
/* download pkgs */
slapt_pkg_list_t_foreach(pkg, tran->install_pkgs) {
- uint32_t failed = 1;
+ bool failed = true;
++dl_counter;
snprintf(dl_note, SLAPT_PKG_DL_NOTE_LEN, "%d/%d", dl_counter, pkg_dl_count);
@@ -387,19 +387,19 @@ int slapt_handle_transaction(const slapt_rc_config *global_config,
const char *err = slapt_download_pkg(global_config, pkg, dl_note);
if (err) {
fprintf(stderr, gettext("Failed to download: %s\n"), err);
- failed = 1;
+ failed = true;
} else {
- failed = 0;
+ failed = false;
break;
}
}
- if (failed == 1)
+ if (failed)
exit(EXIT_FAILURE);
}
slapt_pkg_upgrade_list_t_foreach(upgrade, tran->upgrade_pkgs) {
- uint32_t failed = 1;
+ bool failed = true;
++dl_counter;
snprintf(dl_note, SLAPT_PKG_DL_NOTE_LEN, "%d/%d", dl_counter, pkg_dl_count);
@@ -408,13 +408,13 @@ int slapt_handle_transaction(const slapt_rc_config *global_config,
const char *err = slapt_download_pkg(global_config, upgrade->upgrade, dl_note);
if (err) {
fprintf(stderr, gettext("Failed to download: %s\n"), err);
- failed = 1;
+ failed = true;
} else {
- failed = 0;
+ failed = false;
break;
}
}
- if (failed == 1)
+ if (failed)
exit(EXIT_FAILURE);
}
@@ -462,7 +462,7 @@ void slapt_add_install_to_transaction(slapt_transaction_t *tran,
slapt_pkg_info_t **tmp_list;
/* don't add if already present in the transaction */
- if (slapt_search_transaction_by_pkg(tran, pkg) == 1)
+ if (slapt_search_transaction_by_pkg(tran, pkg))
return;
tmp_list = realloc(
@@ -491,7 +491,7 @@ void slapt_add_remove_to_transaction(slapt_transaction_t *tran,
slapt_pkg_info_t **tmp_list;
/* don't add if already present in the transaction */
- if (slapt_search_transaction_by_pkg(tran, pkg) == 1)
+ if (slapt_search_transaction_by_pkg(tran, pkg))
return;
tmp_list = realloc(
@@ -515,7 +515,7 @@ void slapt_add_exclude_to_transaction(slapt_transaction_t *tran,
slapt_pkg_info_t **tmp_list;
/* don't add if already present in the transaction */
- if (slapt_search_transaction_by_pkg(tran, pkg) == 1)
+ if (slapt_search_transaction_by_pkg(tran, pkg))
return;
tmp_list = realloc(
@@ -555,7 +555,7 @@ static void _slapt_add_upgrade_to_transaction(slapt_transaction_t *tran,
slapt_pkg_upgrade_t **tmp_list;
/* don't add if already present in the transaction */
- if (slapt_search_transaction_by_pkg(tran, slapt_upgrade_pkg) == 1)
+ if (slapt_search_transaction_by_pkg(tran, slapt_upgrade_pkg))
return;
tmp_list = realloc(
@@ -596,44 +596,40 @@ static void _slapt_add_upgrade_to_transaction(slapt_transaction_t *tran,
}
}
-int slapt_search_transaction(slapt_transaction_t *tran, char *pkg_name)
+bool slapt_search_transaction(slapt_transaction_t *tran, char *pkg_name)
{
- uint32_t found = 1, not_found = 0;
-
slapt_pkg_list_t_foreach(pkg, tran->install_pkgs) {
if (strcmp(pkg_name, pkg->name) == 0)
- return found;
+ return true;
}
slapt_pkg_upgrade_list_t_foreach(upgrade, tran->upgrade_pkgs) {
if (strcmp(pkg_name, upgrade->upgrade->name) == 0)
- return found;
+ return true;
}
slapt_pkg_list_t_foreach(remove_pkg, tran->remove_pkgs) {
if (strcmp(pkg_name, remove_pkg->name) == 0)
- return found;
+ return true;
}
slapt_pkg_list_t_foreach(exclude_pkg, tran->exclude_pkgs) {
if (strcmp(pkg_name, exclude_pkg->name) == 0)
- return found;
+ return true;
}
- return not_found;
+ return false;
}
-int slapt_search_upgrade_transaction(slapt_transaction_t *tran,
+bool slapt_search_upgrade_transaction(slapt_transaction_t *tran,
slapt_pkg_info_t *pkg)
{
- uint32_t found = 1, not_found = 0;
-
slapt_pkg_upgrade_list_t_foreach(upgrade, tran->upgrade_pkgs) {
if (strcmp(pkg->name, upgrade->upgrade->name) == 0)
- return found;
+ return true;
}
- return not_found;
+ return false;
}
void slapt_free_transaction(slapt_transaction_t *tran)
@@ -685,7 +681,7 @@ slapt_transaction_t *slapt_remove_from_transaction(slapt_transaction_t *tran,
{
slapt_transaction_t *new_tran = NULL;
- if (slapt_search_transaction_by_pkg(tran, pkg) == 0)
+ if (!slapt_search_transaction_by_pkg(tran, pkg))
return tran;
/* since this is a pointer, slapt_malloc before calling init */
@@ -853,7 +849,7 @@ static void add_suggestion(slapt_transaction_t *tran, slapt_pkg_info_t *pkg)
slapt_list_t_foreach(s, suggests) {
/* no need to add it if we already have it */
- if (slapt_search_transaction(tran, s) == 1)
+ if (slapt_search_transaction(tran, s))
continue;
slapt_add_list_item(tran->suggests, s);
@@ -862,34 +858,32 @@ static void add_suggestion(slapt_transaction_t *tran, slapt_pkg_info_t *pkg)
slapt_free_list(suggests);
}
-int slapt_search_transaction_by_pkg(slapt_transaction_t *tran,
+bool slapt_search_transaction_by_pkg(slapt_transaction_t *tran,
slapt_pkg_info_t *pkg)
{
- uint32_t found = 1, not_found = 0;
-
slapt_pkg_list_t_foreach(install_pkg, tran->install_pkgs) {
if ((strcmp(pkg->name, install_pkg->name) == 0) && (strcmp(pkg->version, install_pkg->version) == 0))
- return found;
+ return true;
}
slapt_pkg_upgrade_list_t_foreach(upgrade, tran->upgrade_pkgs) {
slapt_pkg_info_t *p = upgrade->upgrade;
if ((strcmp(pkg->name, p->name) == 0) && (strcmp(pkg->version, p->version) == 0))
- return found;
+ return true;
}
slapt_pkg_list_t_foreach(remove_pkg, tran->remove_pkgs) {
if ((strcmp(pkg->name, remove_pkg->name) == 0) && (strcmp(pkg->version, remove_pkg->version) == 0))
- return found;
+ return true;
}
slapt_pkg_list_t_foreach(exclude_pkg, tran->exclude_pkgs) {
if ((strcmp(pkg->name, exclude_pkg->name) == 0) && (strcmp(pkg->version, exclude_pkg->version) == 0))
- return found;
+ return true;
}
- return not_found;
+ return false;
}
static slapt_queue_t *slapt_queue_init(void)
diff --git a/src/transaction.h b/src/transaction.h
index 0631671..7765592 100644
--- a/src/transaction.h
+++ b/src/transaction.h
@@ -76,19 +76,19 @@ void slapt_add_exclude_to_transaction(slapt_transaction_t *,
slapt_transaction_t *slapt_remove_from_transaction(slapt_transaction_t *tran,
slapt_pkg_info_t *pkg);
-/* search transaction by package name. returns 1 if found, 0 otherwise */
-int slapt_search_transaction(slapt_transaction_t *, char *pkg_name);
+/* search transaction by package name. returns true if found, false otherwise */
+bool slapt_search_transaction(slapt_transaction_t *, char *pkg_name);
/*
search transaction by package attributes
- returns 1 if found, 0 otherwise
+ returns true if found, false otherwise
*/
-int slapt_search_transaction_by_pkg(slapt_transaction_t *tran,
+bool slapt_search_transaction_by_pkg(slapt_transaction_t *tran,
slapt_pkg_info_t *pkg);
/*
searches the upgrade list of the transaction for the present of the package
- returns 1 if found, 0 if not found
+ returns true if found, false if not found
*/
-int slapt_search_upgrade_transaction(slapt_transaction_t *tran,
+bool slapt_search_upgrade_transaction(slapt_transaction_t *tran,
slapt_pkg_info_t *pkg);
/*
diff --git a/t/test_transaction.c b/t/test_transaction.c
index 698f330..1e0adaa 100644
--- a/t/test_transaction.c
+++ b/t/test_transaction.c
@@ -8,21 +8,21 @@ START_TEST(test_transaction)
slapt_add_install_to_transaction(t, &pkg);
fail_unless(t->install_pkgs->pkg_count == 1);
- fail_unless(slapt_search_transaction(t, "gslapt") == 1);
- fail_unless(slapt_search_transaction_by_pkg(t, &pkg) == 1);
+ fail_unless(slapt_search_transaction(t, "gslapt"));
+ fail_unless(slapt_search_transaction_by_pkg(t, &pkg));
t = slapt_remove_from_transaction(t, &pkg);
slapt_add_remove_to_transaction(t, &pkg);
fail_unless(t->remove_pkgs->pkg_count == 1);
- fail_unless(slapt_search_transaction(t, "gslapt") == 1);
- fail_unless(slapt_search_transaction_by_pkg(t, &pkg) == 1);
+ fail_unless(slapt_search_transaction(t, "gslapt"));
+ fail_unless(slapt_search_transaction_by_pkg(t, &pkg));
t = slapt_remove_from_transaction(t, &pkg);
slapt_add_exclude_to_transaction(t, &pkg);
fail_unless(t->exclude_pkgs->pkg_count == 1);
slapt_add_upgrade_to_transaction(t, &pkg, &pkg);
- /* fail_unless (slapt_search_upgrade_transaction(t, &pkg) == 1); */
+ /* fail_unless (slapt_search_upgrade_transaction(t, &pkg)); */
slapt_free_transaction(t);
}