The following commit has been merged in the master branch:
commit 3e9f202bc125eeaf291c47613f5e42493077fd42
Author: Guillem Jover <[email protected]>
Date: Sat Feb 20 04:40:47 2010 +0100
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()
diff --git a/dpkg-deb/info.c b/dpkg-deb/info.c
index c0480aa..b115a2f 100644
--- a/dpkg-deb/info.c
+++ b/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);
}
diff --git a/lib/dpkg/pkg-format.c b/lib/dpkg/pkg-format.c
index 49dc5cd..7339efe 100644
--- a/lib/dpkg/pkg-format.c
+++ b/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;
diff --git a/lib/dpkg/pkg-format.h b/lib/dpkg/pkg-format.h
index d71cbd0..f0314ae 100644
--- a/lib/dpkg/pkg-format.h
+++ b/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
diff --git a/src/query.c b/src/query.c
index 50ac642..c22c915 100644
--- a/src/query.c
+++ b/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();
}
--
dpkg's main repository
--
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]