Browse Source

Use new str_is_set()/str_is_unset() instead of ad-hoc checks

Guillem Jover 14 years ago
parent
commit
42a2f26ac7
8 changed files with 30 additions and 25 deletions
  1. 3 2
      lib/dpkg/command.c
  2. 7 2
      lib/dpkg/dump.c
  3. 4 3
      lib/dpkg/fields.c
  4. 3 2
      lib/dpkg/parse.c
  5. 3 2
      lib/dpkg/path.c
  6. 7 12
      lib/dpkg/pkg.c
  7. 1 1
      src/configure.c
  8. 2 1
      src/querycmd.c

+ 3 - 2
lib/dpkg/command.c

@@ -2,7 +2,7 @@
  * libdpkg - Debian packaging suite library routines
  * command.c - command execution support
  *
- * Copyright © 2010-2011 Guillem Jover <guillem@debian.org>
+ * Copyright © 2010-2012 Guillem Jover <guillem@debian.org>
  *
  * This is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -27,6 +27,7 @@
 
 #include <dpkg/dpkg.h>
 #include <dpkg/i18n.h>
+#include <dpkg/string.h>
 #include <dpkg/path.h>
 #include <dpkg/command.h>
 
@@ -192,7 +193,7 @@ command_shell(const char *cmd, const char *name)
 	const char *mode;
 
 	shell = getenv("SHELL");
-	if (shell == NULL || shell[0] == '\0')
+	if (str_is_unset(shell))
 		shell = DEFAULTSHELL;
 
 	if (cmd == NULL)

+ 7 - 2
lib/dpkg/dump.c

@@ -42,6 +42,7 @@
 #include <dpkg/i18n.h>
 #include <dpkg/dpkg.h>
 #include <dpkg/dpkg-db.h>
+#include <dpkg/string.h>
 #include <dpkg/dir.h>
 #include <dpkg/parsedump.h>
 
@@ -105,7 +106,9 @@ w_section(struct varbuf *vb,
           enum fwriteflags flags, const struct fieldinfo *fip)
 {
   const char *value = pkg->section;
-  if (!value || !*value) return;
+
+  if (str_is_unset(value))
+    return;
   if (flags&fw_printheader)
     varbuf_add_str(vb, "Section: ");
   varbuf_add_str(vb, value);
@@ -119,7 +122,9 @@ w_charfield(struct varbuf *vb,
             enum fwriteflags flags, const struct fieldinfo *fip)
 {
   const char *value = PKGPFIELD(pkgbin, fip->integer, const char *);
-  if (!value || !*value) return;
+
+  if (str_is_unset(value))
+    return;
   if (flags&fw_printheader) {
     varbuf_add_str(vb, fip->name);
     varbuf_add_str(vb, ": ");

+ 4 - 3
lib/dpkg/fields.c

@@ -4,7 +4,7 @@
  *
  * Copyright © 1995 Ian Jackson <ian@chiark.greenend.org.uk>
  * Copyright © 2001 Wichert Akkerman
- * Copyright © 2006-2011 Guillem Jover <guillem@debian.org>
+ * Copyright © 2006-2012 Guillem Jover <guillem@debian.org>
  * Copyright © 2009 Canonical Ltd.
  * Copyright © 2011 Linaro Limited
  * Copyright © 2011 Raphaël Hertzog <hertzog@debian.org>
@@ -34,6 +34,7 @@
 #include <dpkg/dpkg.h>
 #include <dpkg/dpkg-db.h>
 #include <dpkg/arch.h>
+#include <dpkg/string.h>
 #include <dpkg/path.h>
 #include <dpkg/parsedump.h>
 #include <dpkg/pkg-spec.h>
@@ -75,7 +76,7 @@ parse_nv_last(struct parsedb_state *ps,
   int value;
 
   value = parse_nv_next(ps, what, nv_head, &str);
-  if (str != NULL && str[0] != '\0')
+  if (str_is_set(str))
     parse_error(ps, _("junk after %s"), what);
 
   return value;
@@ -248,7 +249,7 @@ f_revision(struct pkginfo *pkg, struct pkgbin *pkgbin,
   parse_warn(ps,
              _("obsolete `Revision' or `Package-Revision' field used"));
   if (!*value) return;
-  if (pkgbin->version.revision && *pkgbin->version.revision) {
+  if (str_is_set(pkgbin->version.revision)) {
     newversion = nfmalloc(strlen(pkgbin->version.version) +
                           strlen(pkgbin->version.revision) + 2);
     sprintf(newversion, "%s-%s", pkgbin->version.version,

+ 3 - 2
lib/dpkg/parse.c

@@ -41,6 +41,7 @@
 #include <dpkg/i18n.h>
 #include <dpkg/dpkg.h>
 #include <dpkg/dpkg-db.h>
+#include <dpkg/string.h>
 #include <dpkg/pkg.h>
 #include <dpkg/parsedump.h>
 #include <dpkg/fdio.h>
@@ -439,9 +440,9 @@ pkg_parse_copy(struct parsedb_state *ps,
 {
   /* Copy the priority and section across, but don't overwrite existing
    * values if the pdb_weakclassification flag is set. */
-  if (src_pkg->section && *src_pkg->section &&
+  if (str_is_set(src_pkg->section) &&
       !((ps->flags & pdb_weakclassification) &&
-        dst_pkg->section && *dst_pkg->section))
+        str_is_set(dst_pkg->section)))
     dst_pkg->section = src_pkg->section;
   if (src_pkg->priority != pri_unknown &&
       !((ps->flags & pdb_weakclassification) &&

+ 3 - 2
lib/dpkg/path.c

@@ -3,7 +3,7 @@
  * path.c - path handling functions
  *
  * Copyright © 1995 Ian Jackson <ian@chiark.greenend.org.uk>
- * Copyright © 2008-2011 Guillem Jover <guillem@debian.org>
+ * Copyright © 2008-2012 Guillem Jover <guillem@debian.org>
  *
  * This is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -27,6 +27,7 @@
 #include <stdio.h>
 
 #include <dpkg/dpkg.h>
+#include <dpkg/string.h>
 #include <dpkg/path.h>
 
 /**
@@ -43,7 +44,7 @@ path_trim_slash_slashdot(char *path)
 {
 	char *end;
 
-	if (!path || !*path)
+	if (str_is_unset(path))
 		return 0;
 
 	for (end = path + strlen(path) - 1; end - path >= 1; end--) {

+ 7 - 12
lib/dpkg/pkg.c

@@ -25,6 +25,7 @@
 #include <assert.h>
 #include <string.h>
 
+#include <dpkg/string.h>
 #include <dpkg/dpkg-db.h>
 #include <dpkg/pkg.h>
 
@@ -174,12 +175,6 @@ pkgset_installed_instances(struct pkgset *set)
 	return set->installed_instances;
 }
 
-static int
-nes(const char *s)
-{
-	return s && *s;
-}
-
 /**
  * Check if a pkg is informative.
  *
@@ -198,12 +193,12 @@ pkg_is_informative(struct pkginfo *pkg, struct pkgbin *pkgbin)
 		return true;
 
 	if (pkgbin->depends ||
-	    nes(pkgbin->description) ||
-	    nes(pkgbin->maintainer) ||
-	    nes(pkgbin->origin) ||
-	    nes(pkgbin->bugs) ||
-	    nes(pkgbin->installedsize) ||
-	    nes(pkgbin->source) ||
+	    str_is_set(pkgbin->description) ||
+	    str_is_set(pkgbin->maintainer) ||
+	    str_is_set(pkgbin->origin) ||
+	    str_is_set(pkgbin->bugs) ||
+	    str_is_set(pkgbin->installedsize) ||
+	    str_is_set(pkgbin->source) ||
 	    dpkg_version_is_informative(&pkgbin->version) ||
 	    pkgbin->conffiles ||
 	    pkgbin->arbs)

+ 1 - 1
src/configure.c

@@ -553,7 +553,7 @@ showdiff(const char *old, const char *new)
 		char cmdbuf[1024];
 
 		pager = getenv("PAGER");
-		if (!pager || !*pager)
+		if (str_is_unset(pager))
 			pager = DEFAULTPAGER;
 
 		sprintf(cmdbuf, DIFF " -Nu %.250s %.250s | %.250s",

+ 2 - 1
src/querycmd.c

@@ -48,6 +48,7 @@
 #include <dpkg/pkg-spec.h>
 #include <dpkg/pkg-format.h>
 #include <dpkg/pkg-show.h>
+#include <dpkg/string.h>
 #include <dpkg/path.h>
 #include <dpkg/options.h>
 
@@ -412,7 +413,7 @@ enqperpackage(const char *const *argv)
     case act_status:
       if (pkg->status == stat_notinstalled &&
           pkg->priority == pri_unknown &&
-          !(pkg->section && *pkg->section) &&
+          str_is_unset(pkg->section) &&
           !pkg->files &&
           pkg->want == want_unknown &&
           !pkg_is_informative(pkg, &pkg->installed)) {