Просмотр исходного кода

Make show1package() take a struct pkginfoperfile

Instead of hardcoding the usage of the pkginfo installed member,
pass it as an argument of a pointer to a struct pkginfoperfile, so
that we can choose what to show.
Guillem Jover лет назад: 16
Родитель
Сommit
630dc73ddb
4 измененных файлов с 12 добавлено и 10 удалено
  1. 1 1
      dpkg-deb/info.c
  2. 2 1
      lib/dpkg/dpkg-db.h
  3. 7 6
      lib/dpkg/showpkg.c
  4. 2 2
      src/query.c

+ 1 - 1
dpkg-deb/info.c

@@ -241,7 +241,7 @@ void do_showinfo(const char* const* argv) {
   info_prepare(&argv,&debar,&directory,1);
 
   parsedb(CONTROLFILE, pdb_ignorefiles, &pkg, NULL, NULL);
-  show1package(fmt,pkg);
+  show1package(fmt, pkg, &pkg->installed);
 }
 
 

+ 2 - 1
lib/dpkg/dpkg-db.h

@@ -407,7 +407,8 @@ struct lstitem;
 
 struct lstitem* parseformat(const char* fmt);
 void freeformat(struct lstitem* head);
-void show1package(const struct lstitem* head, struct pkginfo *pkg);
+void show1package(const struct lstitem* head,
+                  struct pkginfo *pkg, struct pkginfoperfile *pif);
 
 DPKG_END_DECLS
 

+ 7 - 6
lib/dpkg/showpkg.c

@@ -199,13 +199,14 @@ parseformat(const char *fmt)
 }
 
 void
-show1package(const struct lstitem *head, struct pkginfo *pkg)
+show1package(const struct lstitem *head,
+             struct pkginfo *pkg, struct pkginfoperfile *pif)
 {
 	struct varbuf vb = VARBUF_INIT, fb = VARBUF_INIT, wb = VARBUF_INIT;
 
 	/* Make sure we have package info available, even if it's all empty. */
-	if (!pkg->installed.valid)
-		blankpackageperfile(&pkg->installed);
+	if (!pif->valid)
+		blankpackageperfile(pif);
 
 	while (head) {
 		int ok;
@@ -227,7 +228,7 @@ show1package(const struct lstitem *head, struct pkginfo *pkg)
 
 			for (fip = fieldinfos; fip->name; fip++)
 				if (strcasecmp(head->data, fip->name) == 0) {
-					fip->wcall(&wb, pkg, &pkg->installed, 0, fip);
+					fip->wcall(&wb, pkg, pif, 0, fip);
 
 					varbufaddc(&wb, '\0');
 					varbufprintf(&fb, fmt, wb.buf);
@@ -236,10 +237,10 @@ show1package(const struct lstitem *head, struct pkginfo *pkg)
 					break;
 				}
 
-			if (!fip->name && pkg->installed.valid) {
+			if (!fip->name && pif->valid) {
 				const struct arbitraryfield *afp;
 
-				for (afp = pkg->installed.arbs; afp; afp = afp->next)
+				for (afp = pif->arbs; afp; afp = afp->next)
 					if (strcasecmp(head->data, afp->name) == 0) {
 						varbufprintf(&fb, fmt, afp->value);
 						ok = 1;

+ 2 - 2
src/query.c

@@ -399,7 +399,7 @@ void showpackages(const char *const *argv) {
     for (i = 0; i < array.n_pkgs; i++) {
       pkg = array.pkgs[i];
       if (pkg->status == stat_notinstalled) continue;
-      show1package(fmt,pkg);
+      show1package(fmt, pkg, &pkg->installed);
     }
   } else {
     int argc, ip, *found;
@@ -412,7 +412,7 @@ void showpackages(const char *const *argv) {
       pkg = array.pkgs[i];
       for (ip = 0; ip < argc; ip++) {
         if (!fnmatch(argv[ip], pkg->name, 0)) {
-          show1package(fmt, pkg);
+          show1package(fmt, pkg, &pkg->installed);
           found[ip]++;
           break;
         }