From 59c47aaf529df02ec1577fe727c3c84d13592666 Mon Sep 17 00:00:00 2001 From: Allan McRae Date: Sat, 19 Jun 2010 18:55:08 +1000 Subject: Clarify testing within conditional statements Follow the HACKING guidelines and always use != 0 or == 0 rather than negation within conditional statements to improve clarity. Most of these are !strcmp usages which is the example of what not to do in the HACKING document. Signed-off-by: Allan McRae --- lib/libalpm/be_package.c | 34 +++++++++++++++++----------------- lib/libalpm/conflict.c | 4 ++-- lib/libalpm/deps.c | 2 +- lib/libalpm/trans.c | 4 ++-- lib/libalpm/util.c | 2 +- 5 files changed, 23 insertions(+), 23 deletions(-) (limited to 'lib') diff --git a/lib/libalpm/be_package.c b/lib/libalpm/be_package.c index 38cf357a..7b77ae6b 100644 --- a/lib/libalpm/be_package.c +++ b/lib/libalpm/be_package.c @@ -69,19 +69,19 @@ static int parse_descfile(struct archive *a, pmpkg_t *newpkg) } else { key = _alpm_strtrim(key); ptr = _alpm_strtrim(ptr); - if(!strcmp(key, "pkgname")) { + if(strcmp(key, "pkgname") == 0) { STRDUP(newpkg->name, ptr, RET_ERR(PM_ERR_MEMORY, -1)); - } else if(!strcmp(key, "pkgver")) { + } else if(strcmp(key, "pkgver") == 0) { STRDUP(newpkg->version, ptr, RET_ERR(PM_ERR_MEMORY, -1)); - } else if(!strcmp(key, "pkgdesc")) { + } else if(strcmp(key, "pkgdesc") == 0) { STRDUP(newpkg->desc, ptr, RET_ERR(PM_ERR_MEMORY, -1)); - } else if(!strcmp(key, "group")) { + } else if(strcmp(key, "group") == 0) { newpkg->groups = alpm_list_add(newpkg->groups, strdup(ptr)); - } else if(!strcmp(key, "url")) { + } else if(strcmp(key, "url") == 0) { STRDUP(newpkg->url, ptr, RET_ERR(PM_ERR_MEMORY, -1)); - } else if(!strcmp(key, "license")) { + } else if(strcmp(key, "license") == 0) { newpkg->licenses = alpm_list_add(newpkg->licenses, strdup(ptr)); - } else if(!strcmp(key, "builddate")) { + } else if(strcmp(key, "builddate") == 0) { char first = tolower((unsigned char)ptr[0]); if(first > 'a' && first < 'z') { struct tm tmp_tm = {0}; /* initialize to null in case of failure */ @@ -92,27 +92,27 @@ static int parse_descfile(struct archive *a, pmpkg_t *newpkg) } else { newpkg->builddate = atol(ptr); } - } else if(!strcmp(key, "packager")) { + } else if(strcmp(key, "packager") == 0) { STRDUP(newpkg->packager, ptr, RET_ERR(PM_ERR_MEMORY, -1)); - } else if(!strcmp(key, "arch")) { + } else if(strcmp(key, "arch") == 0) { STRDUP(newpkg->arch, ptr, RET_ERR(PM_ERR_MEMORY, -1)); - } else if(!strcmp(key, "size")) { + } else if(strcmp(key, "size") == 0) { /* size in the raw package is uncompressed (installed) size */ newpkg->isize = atol(ptr); - } else if(!strcmp(key, "depend")) { + } else if(strcmp(key, "depend") == 0) { pmdepend_t *dep = _alpm_splitdep(ptr); newpkg->depends = alpm_list_add(newpkg->depends, dep); - } else if(!strcmp(key, "optdepend")) { + } else if(strcmp(key, "optdepend") == 0) { newpkg->optdepends = alpm_list_add(newpkg->optdepends, strdup(ptr)); - } else if(!strcmp(key, "conflict")) { + } else if(strcmp(key, "conflict") == 0) { newpkg->conflicts = alpm_list_add(newpkg->conflicts, strdup(ptr)); - } else if(!strcmp(key, "replaces")) { + } else if(strcmp(key, "replaces") == 0) { newpkg->replaces = alpm_list_add(newpkg->replaces, strdup(ptr)); - } else if(!strcmp(key, "provides")) { + } else if(strcmp(key, "provides") == 0) { newpkg->provides = alpm_list_add(newpkg->provides, strdup(ptr)); - } else if(!strcmp(key, "backup")) { + } else if(strcmp(key, "backup") == 0) { newpkg->backup = alpm_list_add(newpkg->backup, strdup(ptr)); - } else if(!strcmp(key, "makepkgopt")) { + } else if(strcmp(key, "makepkgopt") == 0) { /* not used atm */ } else { _alpm_log(PM_LOG_DEBUG, "%s: syntax error in description file line %d\n", diff --git a/lib/libalpm/conflict.c b/lib/libalpm/conflict.c index e36844a8..236ec1df 100644 --- a/lib/libalpm/conflict.c +++ b/lib/libalpm/conflict.c @@ -88,8 +88,8 @@ int _alpm_conflict_isin(pmconflict_t *needle, alpm_list_t *haystack) char *cpkg2 = conflict->package2; char *npkg1 = needle->package1; char *npkg2 = needle->package2; - if((!strcmp(cpkg1, npkg1) && !strcmp(cpkg2, npkg2)) - || (!strcmp(cpkg1, npkg2) && !strcmp(cpkg2, npkg1))) { + if((strcmp(cpkg1, npkg1) == 0 && strcmp(cpkg2, npkg2) == 0) + || (strcmp(cpkg1, npkg2) == 0 && strcmp(cpkg2, npkg1) == 0)) { return(1); } } diff --git a/lib/libalpm/deps.c b/lib/libalpm/deps.c index 26f9b16d..fd893a63 100644 --- a/lib/libalpm/deps.c +++ b/lib/libalpm/deps.c @@ -546,7 +546,7 @@ pmpkg_t *_alpm_resolvedep(pmdepend_t *dep, alpm_list_t *dbs, for(i = dbs; i; i = i->next) { for(j = _alpm_db_get_pkgcache(i->data); j; j = j->next) { pmpkg_t *pkg = j->data; - if(alpm_depcmp(pkg, dep) && strcmp(pkg->name, dep->name) && + if(alpm_depcmp(pkg, dep) && strcmp(pkg->name, dep->name) != 0 && !_alpm_pkg_find(excluding, pkg->name)) { if(_alpm_pkg_should_ignore(pkg)) { int install = 0; diff --git a/lib/libalpm/trans.c b/lib/libalpm/trans.c index 49fc0f67..c042f099 100644 --- a/lib/libalpm/trans.c +++ b/lib/libalpm/trans.c @@ -107,7 +107,7 @@ static alpm_list_t *check_arch(alpm_list_t *pkgs) for(i = pkgs; i; i = i->next) { pmpkg_t *pkg = i->data; const char *pkgarch = alpm_pkg_get_arch(pkg); - if(strcmp(pkgarch,arch) && strcmp(pkgarch,"any")) { + if(strcmp(pkgarch,arch) != 0 && strcmp(pkgarch,"any") != 0) { char *string; const char *pkgname = alpm_pkg_get_name(pkg); const char *pkgver = alpm_pkg_get_version(pkg); @@ -371,7 +371,7 @@ int _alpm_runscriptlet(const char *root, const char *installfn, /* either extract or copy the scriptlet */ snprintf(scriptfn, PATH_MAX, "%s/.INSTALL", tmpdir); - if(!strcmp(script, "pre_upgrade") || !strcmp(script, "pre_install")) { + if(strcmp(script, "pre_upgrade") == 0 || strcmp(script, "pre_install") == 0) { if(_alpm_unpack_single(installfn, tmpdir, ".INSTALL")) { retval = 1; } diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c index 32eaa442..b033e0a3 100644 --- a/lib/libalpm/util.c +++ b/lib/libalpm/util.c @@ -398,7 +398,7 @@ int _alpm_rmrf(const char *path) for(dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) { if(dp->d_ino) { sprintf(name, "%s/%s", path, dp->d_name); - if(strcmp(dp->d_name, "..") && strcmp(dp->d_name, ".")) { + if(strcmp(dp->d_name, "..") != 0 && strcmp(dp->d_name, ".") != 0) { errflag += _alpm_rmrf(name); } } -- cgit v1.2.3-24-g4f1b