소스 검색

libdpkg: Unify and namespace pkg-format functions and types

Renames:

  struct lstitem → struct pkg_format_node
  itemtype_t → enum pkg_format_type
  alloclstitem() → pkg_format_node_new()
  parseformat() → pkg_format_parse()
  freeformat() → pkg_format_free()
  show1package() → pkg_format_show()
Guillem Jover 16 년 전
부모
커밋
3e9f202bc1
4개의 변경된 파일35개의 추가작업 그리고 35개의 파일을 삭제
  1. 2 2
      dpkg-deb/info.c
  2. 24 24
      lib/dpkg/pkg-format.c
  3. 5 5
      lib/dpkg/pkg-format.h
  4. 4 4
      src/query.c

+ 2 - 2
dpkg-deb/info.c

@@ -244,7 +244,7 @@ static void info_field(const char *debar, const char *directory,
 void do_showinfo(const char* const* argv) {
   const char *debar, *directory;
   struct pkginfo *pkg;
-  struct lstitem* fmt = parseformat(showformat);
+  struct pkg_format_node *fmt = pkg_format_parse(showformat);
 
   if (!fmt)
     ohshit(_("Error in format"));
@@ -252,7 +252,7 @@ void do_showinfo(const char* const* argv) {
   info_prepare(&argv,&debar,&directory,1);
 
   parsedb(CONTROLFILE, pdb_ignorefiles, &pkg, NULL, NULL);
-  show1package(fmt, pkg, &pkg->installed);
+  pkg_format_show(fmt, pkg, &pkg->installed);
 }
 
 

+ 24 - 24
lib/dpkg/pkg-format.c

@@ -31,27 +31,27 @@
 #include <dpkg/parsedump.h>
 #include <dpkg/pkg-format.h>
 
-typedef enum {
+enum pkg_format_type {
 	invalid,
 	string,
 	field,
-} itemtype_t;
+};
 
-struct lstitem {
-	itemtype_t type;
+struct pkg_format_node {
+	struct pkg_format_node *next;
+	enum pkg_format_type type;
 	size_t width;
 	int pad;
 	char *data;
-	struct lstitem *next;
 };
 
 
-static struct lstitem *
-alloclstitem(void)
+static struct pkg_format_node *
+pkg_format_node_new(void)
 {
-	struct lstitem *buf;
+	struct pkg_format_node *buf;
 
-	buf = m_malloc(sizeof(struct lstitem));
+	buf = m_malloc(sizeof(*buf));
 	buf->type = invalid;
 	buf->next = NULL;
 	buf->data = NULL;
@@ -62,7 +62,7 @@ alloclstitem(void)
 }
 
 static int
-parsefield(struct lstitem *cur, const char *fmt, const char *fmtend)
+parsefield(struct pkg_format_node *cur, const char *fmt, const char *fmtend)
 {
 	int len;
 	const char *ws;
@@ -100,7 +100,7 @@ parsefield(struct lstitem *cur, const char *fmt, const char *fmtend)
 }
 
 static int
-parsestring(struct lstitem *cur, const char *fmt, const char *fmtend)
+parsestring(struct pkg_format_node *cur, const char *fmt, const char *fmtend)
 {
 	int len;
 	char *write;
@@ -138,9 +138,9 @@ parsestring(struct lstitem *cur, const char *fmt, const char *fmtend)
 }
 
 void
-freeformat(struct lstitem *head)
+pkg_format_free(struct pkg_format_node *head)
 {
-	struct lstitem *next;
+	struct pkg_format_node *next;
 
 	while (head) {
 		next = head->next;
@@ -150,32 +150,32 @@ freeformat(struct lstitem *head)
 	}
 }
 
-struct lstitem *
-parseformat(const char *fmt)
+struct pkg_format_node *
+pkg_format_parse(const char *fmt)
 {
-	struct lstitem *head;
-	struct lstitem *cur;
+	struct pkg_format_node *head;
+	struct pkg_format_node *cur;
 	const char *fmtend;
 
 	head = cur = NULL;
 
 	while (*fmt) {
 		if (cur)
-			cur = cur->next = alloclstitem();
+			cur = cur->next = pkg_format_node_new();
 		else
-			head = cur = alloclstitem();
+			head = cur = pkg_format_node_new();
 
 		if (fmt[0] == '$' && fmt[1] == '{') {
 			fmtend = strchr(fmt, '}');
 			if (!fmtend) {
 				fprintf(stderr,
 				      _("Closing brace missing in format\n"));
-				freeformat(head);
+				pkg_format_free(head);
 				return NULL;
 			}
 
 			if (!parsefield(cur, fmt + 2, fmtend - 1)) {
-				freeformat(head);
+				pkg_format_free(head);
 				return NULL;
 			}
 			fmt = fmtend + 1;
@@ -190,7 +190,7 @@ parseformat(const char *fmt)
 				fmtend = fmt + strlen(fmt);
 
 			if (!parsestring(cur, fmt, fmtend - 1)) {
-				freeformat(head);
+				pkg_format_free(head);
 				return NULL;
 			}
 			fmt = fmtend;
@@ -201,8 +201,8 @@ parseformat(const char *fmt)
 }
 
 void
-show1package(const struct lstitem *head,
-             struct pkginfo *pkg, struct pkginfoperfile *pif)
+pkg_format_show(const struct pkg_format_node *head,
+                struct pkginfo *pkg, struct pkginfoperfile *pif)
 {
 	struct varbuf vb = VARBUF_INIT, fb = VARBUF_INIT, wb = VARBUF_INIT;
 

+ 5 - 5
lib/dpkg/pkg-format.h

@@ -26,12 +26,12 @@
 
 DPKG_BEGIN_DECLS
 
-struct lstitem;
+struct pkg_format_node;
 
-struct lstitem *parseformat(const char *fmt);
-void freeformat(struct lstitem *head);
-void show1package(const struct lstitem *head,
-                  struct pkginfo *pkg, struct pkginfoperfile *pif);
+struct pkg_format_node *pkg_format_parse(const char *fmt);
+void pkg_format_free(struct pkg_format_node *head);
+void pkg_format_show(const struct pkg_format_node *head,
+                     struct pkginfo *pkg, struct pkginfoperfile *pif);
 
 DPKG_END_DECLS
 

+ 4 - 4
src/query.c

@@ -383,8 +383,8 @@ void enqperpackage(const char *const *argv) {
 void showpackages(const char *const *argv) {
   struct pkg_array array;
   struct pkginfo *pkg;
+  struct pkg_format_node *fmt = pkg_format_parse(showformat);
   int i;
-  struct lstitem* fmt = parseformat(showformat);
 
   if (!fmt) {
     failures++;
@@ -400,7 +400,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, &pkg->installed);
+      pkg_format_show(fmt, pkg, &pkg->installed);
     }
   } else {
     int argc, ip, *found;
@@ -413,7 +413,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, &pkg->installed);
+          pkg_format_show(fmt, pkg, &pkg->installed);
           found[ip]++;
           break;
         }
@@ -434,7 +434,7 @@ void showpackages(const char *const *argv) {
   m_output(stderr, _("<standard error>"));
 
   pkg_array_destroy(&array);
-  freeformat(fmt);
+  pkg_format_free(fmt);
   modstatdb_shutdown();
 }