PERFORCE change 166152 for review

David Forsythe dforsyth at FreeBSD.org
Thu Jul 16 03:27:32 UTC 2009


http://perforce.freebsd.org/chv.cgi?CH=166152

Change 166152 by dforsyth at squirrel on 2009/07/16 03:26:54

	Fixed some plist stuff, dropped pkg_dump into pkg.h for debugging.
	Sorts and searches still aren't in place.

Affected files ...

.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg.c#36 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg.h#33 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_conflict.c#4 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_db.c#5 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_db_hierdb.c#5 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_db_private.h#5 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_depend.c#3 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_file.c#9 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_file.h#8 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_plist.c#27 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_plist.h#23 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_util.c#11 edit
.. //depot/projects/soc2009/dforsyth_libpkg/pkg_info/main.c#23 edit

Differences ...

==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg.c#36 (text+ko) ====

@@ -41,7 +41,6 @@
 	p->display = NULL;
 	p->mtree_dirs = NULL;
 	p->required_by = NULL;
-	p->pl = NULL;
 	p->dirty = 0;
 
 	return (p);
@@ -111,7 +110,7 @@
 	if (p == NULL)
 		arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
 	
-	if (pkg_parse_plist(p) | NOT_OK)
+	if (pkg_parse_plist(p) & NOT_OK)
 		return (NULL);
 	
 	return (pkg_plist_name(p->pl));
@@ -126,7 +125,7 @@
 	if (p == NULL)
 		arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
 
-	if (pkg_parse_plist(p) | NOT_OK)
+	if (pkg_parse_plist(p) & NOT_OK)
 		return (NULL);
 
 	return (pkg_plist_origin(p->pl));
@@ -354,6 +353,7 @@
 	const char *group, const char *md5, const char *mode, 
 	const char *owner)
 {
+	struct pkg_file *pf;
 	int status;
 
 	if (p == NULL)
@@ -372,12 +372,91 @@
 
 	/* TODO: Add some sanity checks in here. */
 
-	status = pkg_plist_add_file(p->pl, path, cwd, group, md5, mode,
-		owner);
+	pf = pkg_file_new();
+	pkg_file_set_path(pf, path);
+	pkg_file_set_cwd(pf, cwd);
+	pkg_file_set_group(pf, group);
+	pkg_file_set_md5(pf, md5);
+	pkg_file_set_mode(pf, mode);
+	pkg_file_set_owner(pf, owner);
+
+	status = pkg_plist_add_pkg_file(p->pl, pf);
 
 	return (status);	
 }
 
+const char *
+pkg_file_get_cwd(struct pkg *p, const char *path)
+{
+	struct pkg_file *pf;
+
+	pf = pkg_plist_get_pkg_file(p->pl, path);
+	if (pf == NULL)
+		return (NULL);
+	
+	return (pkg_file_cwd(pf));
+}
+
+const char *
+pkg_file_get_group(struct pkg *p, const char *path)
+{
+	struct pkg_file *pf;
+
+	pf = pkg_plist_get_pkg_file(p->pl, path);
+	if (pf == NULL)
+		return (NULL);
+
+	return (pkg_file_group(pf));
+}
+
+const char *
+pkg_file_get_md5(struct pkg *p, const char *path)
+{
+	struct pkg_file *pf;
+
+	pf = pkg_plist_get_pkg_file(p->pl, path);
+	if (pf == NULL)
+		return (NULL);
+
+	return (pkg_file_md5(pf));
+}
+
+const char *
+pkg_file_get_mode(struct pkg *p, const char *path)
+{
+	struct pkg_file *pf;
+
+	pf = pkg_plist_get_pkg_file(p->pl, path);
+	if (pf == NULL)
+		return (NULL);
+
+	return (pkg_file_mode(pf));
+}
+
+const char *
+pkg_file_get_owner(struct pkg *p, const char *path)
+{
+	struct pkg_file *pf;
+
+	pf = pkg_plist_get_pkg_file(p->pl, path);
+	if (pf == NULL)
+		return (NULL);
+
+	return (pkg_file_owner(pf));
+}
+
+const char *
+pkg_depend_get_origin(struct pkg *p, const char *name)
+{
+	struct pkg_depend *pd;
+
+	pd = pkg_plist_get_pkg_depend(p->pl, name);
+	if (pd == NULL)
+		return (NULL);
+
+	return (pkg_depend_origin(pd));
+}
+
 /* Parse the plist (contents) of a package. */
 
 int

==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg.h#33 (text+ko) ====

@@ -148,4 +148,8 @@
 struct pkg_archive *pkg_archive_new(void);
 void pkg_archive_delete(struct pkg_archive *pa);
 
+/* pkg_util */
+
+void pkg_dump(struct pkg *p, FILE *stream);
+
 #endif

==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_conflict.c#4 (text+ko) ====

@@ -14,8 +14,10 @@
 	struct pkg_conflict *pc;
 
 	pc = calloc(1, sizeof(*pc));
-	if (pc != NULL)
-		pc->name = NULL;
+	if (pc == NULL)
+		return (NULL);
+
+	pc->name = NULL;
 
 	return (pc);
 }
@@ -23,7 +25,11 @@
 void
 pkg_conflict_delete(struct pkg_conflict *pc)
 {
-	return;
+	if (pc == NULL)
+		arg_rage_quit(__func__, "Not a valid conflict.", RAGE_AT_LIBPKG);
+
+	free(pc->name);
+	free(pc);
 }
 
 int

==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_db.c#5 (text+ko) ====

@@ -36,7 +36,6 @@
 	switch (db_type) {
 	case (HIER_DB):
 		db->pkg_db_db_open = pkg_db_hierdb_db_open;
-		db->pkg_db_db_init_pkg_in_db = pkg_db_hierdb_init_pkg_in_db;
 		db->pkg_db_db_read_pkg_from_db = pkg_db_hierdb_read_pkg_from_db;
 		/* db->pkg_db_db_close = pkg_db_hierdb_db_close; */
 		break;
@@ -85,7 +84,7 @@
 {
 	if (db == NULL)
 		arg_rage_quit(__func__, "Not a valid database.", RAGE_AT_CLIENT);
-	return (db->pkg_list);
+	return ((const char *const *)db->pkg_list);
 }
 
 struct pkg *

==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_db_hierdb.c#5 (text+ko) ====

@@ -52,7 +52,7 @@
 
 	for (i = 0; i < c; ++i) {
 		p = pkg_new();
-		s |= pkg_db_hierdb_init_pkg_in_db(db, p, ents[i]->d_name);
+		s |= pkg_set_ident(p, ents[i]->d_name);
 		s |= pkg_db_add_pkg_entry(db, p);
 		if (s & DB_NOT_OK) {
 			pkg_db_clear_pkg_entries(db);
@@ -120,24 +120,6 @@
 }
 
 int
-pkg_db_hierdb_init_pkg_in_db(struct pkg_db *db, struct pkg *p, 
-	const char *ident)
-{
-	int status;
-
-	if (db == NULL)
-		arg_rage_quit(__func__, "Not a valid database.", RAGE_AT_LIBPKG);
-
-	pkg_reset(p);
-	status = PKG_OK;
-	status |= pkg_set_ident(p, ident);
-
-	if (status & PKG_MEMORY_ERR)
-		return (DB_NOT_OK | DB_MEMORY_ERR);
-	return (DB_OK);
-}
-
-int
 pkg_db_hierdb_read_pkg_from_db(struct pkg_db *db, struct pkg *p)
 {
 	char *ident;

==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_db_private.h#5 (text+ko) ====

@@ -15,8 +15,6 @@
 	struct pkg **pkg_entries;
 
 	int (*pkg_db_db_open) (struct pkg_db *db, const char *db_root);
-	int (*pkg_db_db_init_pkg_in_db) (struct pkg_db *db, struct pkg *p,
-		const char *ident);
 	int (*pkg_db_db_read_pkg_from_db) (struct pkg_db *db, struct pkg *p);
 	int (*pkg_db_db_close) (struct pkg_db *db);
 	int (*pkg_db_db_sync) (struct pkg_db *db);

==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_depend.c#3 (text+ko) ====

@@ -2,6 +2,7 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include "pkg_util.h"
 #include "pkg_depend.h"
 #include "pkg.h"
 
@@ -11,14 +12,25 @@
 	struct pkg_depend *pd;
 
 	pd = calloc(1, sizeof(*pd));
+	if (pd == NULL)
+		return (NULL);
 
+	pd->name = NULL;
+	pd->origin = NULL;
+
 	return (pd);
 }
 
 void
 pkg_depend_delete(struct pkg_depend *pd)
 {
-	return;
+	if (pd == NULL)
+		arg_rage_quit(__func__, "Not a valid package dependency.",
+			RAGE_AT_LIBPKG);
+	
+	free(pd->name);
+	free(pd->origin);
+	free(pd);
 }
 
 struct pkg_depend *

==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_file.c#9 (text+ko) ====

@@ -103,16 +103,34 @@
 	return (pf->owner);
 }
 
+const char *
+pkg_file_path(struct pkg_file *pf)
+{
+	if (pf == NULL)
+		return (NULL);
+
+	return (pf->path);
+}
+
 /* These should return either OK, or MEMORY_ERR | NOT_OK. */
 
 int
+pkg_file_set_cwd(struct pkg_file *pf, const char *cwd)
+{
+	if (pf == NULL)
+		return (NOT_OK);
+
+	pf->cwd = cwd;
+	return (OK);
+}
+
+int
 pkg_file_set_md5(struct pkg_file *pf, const char *md5)
 {
 	if (pf == NULL)
 		return (NOT_OK);
 	
-	free(pf->md5);
-	pf->md5 = (md5 != NULL ? strdup(md5) : NULL);
+	pf->md5 = md5;
 	return (OK);
 }
 
@@ -122,8 +140,7 @@
 	if (pf == NULL)
 		return (NOT_OK);
 	
-	free(pf->path);
-	pf->path = (path != NULL ? strdup(path) : NULL);
+	pf->path = path;
 	return (OK);
 }
 
@@ -133,8 +150,7 @@
 	if (pf == NULL)
 		return (NOT_OK);
 
-	free(pf->owner);
-	pf->owner = (owner != NULL ? strdup(owner) : NULL);
+	pf->owner = owner;
 	return (OK);
 }
 
@@ -144,8 +160,7 @@
 	if (pf == NULL)
 		return (NOT_OK);
 	
-	free(pf->group);
-	pf->group = (group != NULL ? strdup(group) : NULL);
+	pf->group = group;
 	return (OK);
 }
 
@@ -155,7 +170,6 @@
 	if (pf == NULL)
 		return (NOT_OK);
 	
-	free(pf->mode);
-	pf->mode = (mode != NULL ? strdup(mode) : NULL);
+	pf->mode = mode;
 	return (OK);
 }

==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_file.h#8 (text+ko) ====

@@ -21,11 +21,13 @@
 const char *pkg_file_md5(struct pkg_file *pf);
 const char *pkg_file_mode(struct pkg_file *pf);
 const char *pkg_file_owner(struct pkg_file *pf);
+const char *pkg_file_path(struct pkg_file *pf);
 
 int pkg_file_set_cwd(struct pkg_file *pf, const char *cwd);
 int pkg_file_set_group(struct pkg_file *pf, const char *group);
 int pkg_file_set_md5(struct pkg_file *pf, const char *md5);
 int pkg_file_set_mode(struct pkg_file *pf, const char *mode);
 int pkg_file_set_owner(struct pkg_file *pf, const char *owner);
+int pkg_file_set_path(struct pkg_file *pf, const char *path);
 
 #endif

==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_plist.c#27 (text+ko) ====

@@ -44,6 +44,36 @@
 	struct pkg_plist *pl;
 
 	pl = calloc(1, sizeof(*pl));
+	if (pl == NULL)
+		return (NULL);
+
+	pl->rev = NULL;
+	pl->name = NULL;
+	pl->origin = NULL;
+	pl->srcdir = NULL;
+
+	pl->mtree_file = NULL;
+	pl->display_file = NULL;
+
+	pl->extract_in_place = 0;
+	pl->preserve = 0;
+	pl->complete = 0;
+
+	pl->text = NULL; /* am i still using this? */
+
+	pl->pkg_file_count = 0;
+	pl->pkg_file_entries = NULL;
+	pl->pkg_file_list = NULL;
+	
+	pl->pkg_depend_count = 0;
+	pl->pkg_depend_entries = NULL;
+	pl->pkg_depend_list = NULL;
+
+	pl->pkg_conflict_count = 0;
+	pl->pkg_conflict_entries = NULL;
+	pl->pkg_conflict_list = NULL;
+
+
 	return (pl);
 }
 
@@ -78,17 +108,20 @@
 	free(pl->srcdir);
 
 	for (c = 0; c < pl->pkg_file_count; ++c)
-		pkg_file_delete(pl->pkg_file_list[c]);
+		pkg_file_delete(pl->pkg_file_entries[c]);
+	free(pl->pkg_file_entries);
 	free(pl->pkg_file_list);
 	pl->pkg_file_count = 0;
 
 	for (c = 0; c < pl->pkg_depend_count; ++c)
-		pkg_depend_delete(pl->pkg_depend_list[c]);
+		pkg_depend_delete(pl->pkg_depend_entries[c]);
+	free(pl->pkg_depend_entries);
 	free(pl->pkg_depend_list);
 	pl->pkg_depend_count = 0;
 
 	for (c = 0; c < pl->pkg_conflict_count; ++c)
-		pkg_conflict_delete(pl->pkg_conflict_list[c]);
+		pkg_conflict_delete(pl->pkg_conflict_entries[c]);
+	free(pl->pkg_conflict_entries);
 	free(pl->pkg_conflict_list);
 	pl->pkg_conflict_count = 0;
 
@@ -125,9 +158,7 @@
 
 	pl->text = textp;
 
-	/* TODO: Use fgets(), and have the different lists have their own copy
-	 * of information so that packages can be freely manipulated without
-	 * worrying about ruining other instances of a package. */
+	/* TODO: Use fgets() */
 	set_parse_state_default(&st);
 	for (p = textp; *p != '\0'; p++) {
 		if (*p == '\n') {
@@ -153,7 +184,7 @@
 		}
 	}
 	
-	free(textp);
+	// free(textp);
 	pl->parsed = 1;
 	
 	return (OK);
@@ -171,6 +202,9 @@
 	char *command;
 	char *argument;
 	char *sep;
+	struct pkg_file *pf;
+	struct pkg_depend *pd;
+	struct pkg_conflict *pc;
 
 	if (pl == NULL || line == NULL || st == NULL)
 		return (-1);
@@ -260,14 +294,14 @@
 				 * deal with package versioning in dependencies. */
 				if (st->last_elem != PLIST_PKGDEP)
 					return (PARSE_FAIL);
-				pkg_depend_set_origin(
-					pl->pkg_depend_list[pl->pkg_depend_count],
-					sep + 1);
+					pkg_depend_set_origin(
+						pl->pkg_depend_entries[pl->pkg_depend_count - 1], 
+						sep + 1);
 			} else if (strcmp(argument, PLIST_COMMENT_MD5) == 0) {
 				if (st->last_elem != PLIST_FILE)
 					return (PARSE_FAIL);
 				pkg_file_set_md5(
-					pl->pkg_file_list[pl->pkg_file_count],
+					pl->pkg_file_entries[pl->pkg_file_count - 1],
 					sep + 1);
 			} else {
 				/* Comment we don't know anything about. */
@@ -278,10 +312,16 @@
 		} else if (strcmp(command, PLIST_CMD_PKGDEP) == 0) {
 			/* I should really be checking the name setting return values
 			 * for errors. */
-			s |= pkg_plist_add_depend(pl, argument, NULL);
+			pd = pkg_depend_new();
+			pkg_depend_set_name(pd, argument);
+			
+			s |= pkg_plist_add_pkg_depend(pl, pd);
 			st->last_elem = PLIST_PKGDEP;
 		} else if (strcmp(command, PLIST_CMD_CONFLICTS) == 0) {
-			s |= pkg_plist_add_conflict(pl, argument);
+			pc = pkg_conflict_new();
+			pkg_conflict_set_name(pc, argument);
+
+			s |= pkg_plist_add_pkg_conflict(pl, pc);
 			st->last_elem = PLIST_CONFLICTS;
 		}
 #if 0
@@ -322,8 +362,14 @@
 		}
 #endif
 	} else {
-		pkg_plist_add_file(pl, line, st->cwd, st->group, NULL, st->mode,
-			st->owner);
+		pf = pkg_file_new();
+		pkg_file_set_path(pf, line);
+		pkg_file_set_cwd(pf, st->cwd);
+		pkg_file_set_group(pf, st->group);
+		pkg_file_set_mode(pf, st->mode);
+		pkg_file_set_owner(pf, st->owner);
+		
+		pkg_plist_add_pkg_file(pl, pf);
 		st->last_elem = PLIST_FILE;
 	}
 
@@ -403,31 +449,172 @@
 }
 
 int
-pkg_plist_add_file(struct pkg_plist *pl, const char *path, 
-	const char *cwd, const char *group, const char *md5, const char *mode,
-	const char *owner)
+pkg_plist_add_pkg_file(struct pkg_plist *pl, struct pkg_file *pf)
+{
+	struct pkg_file **pkg_file_entries_tmp;
+	char **pkg_file_list_tmp;
+
+	if (pl == NULL)
+		arg_rage_quit(__func__, "Not a valid plist.", RAGE_AT_LIBPKG);
+	if (pf == NULL)
+		arg_rage_quit(__func__, "Not a valid package file.",
+			RAGE_AT_LIBPKG);
+	
+	/* Check for existing file in list that may conflict with new pf. */
+
+	if (pl->pkg_file_count % 10 == 0) {
+		pkg_file_entries_tmp = pl->pkg_file_entries;
+		pkg_file_list_tmp = pl->pkg_file_list;
+		pl->pkg_file_entries = realloc(pkg_file_entries_tmp,
+			sizeof(struct pkg_file *) * (pl->pkg_file_count + (10 + 1)));
+		pl->pkg_file_list = realloc(pkg_file_list_tmp, 
+			sizeof(char *) * (pl->pkg_file_count + (10 + 1)));
+		if (pl->pkg_file_entries == NULL || pl->pkg_file_list == NULL) {
+			printf("need moar memory\n");
+			exit(100);
+		}
+	}
+	
+	pl->pkg_file_entries[pl->pkg_file_count] = pf;
+	pl->pkg_file_list[pl->pkg_file_count] = pf->path;
+	pl->pkg_file_count++;
+	pl->pkg_file_entries[pl->pkg_file_count] = NULL;
+	pl->pkg_file_list[pl->pkg_file_count] = NULL;
+	/* sort. */
+
+	return (OK);
+}
+
+struct pkg_file *
+pkg_plist_get_pkg_file(struct pkg_plist *pl, const char *path)
 {
-	if (pl || path || cwd || group || md5 || mode || owner)
-		return 0;
+	int i;
+	struct pkg_file *pf;
+
+	if (pl == NULL)
+		arg_rage_quit(__func__, "Not a valid plist.", RAGE_AT_LIBPKG);
+	if (path == NULL)
+		arg_rage_quit(__func__, "Not a valid path.", RAGE_AT_LIBPKG);
 
-	return 0;
+	pf = NULL;
+	for (i = 0; i < pl->pkg_file_count; ++i) {
+		if (strcmp(pl->pkg_file_entries[i]->path, path) == 0)
+			pf = pl->pkg_file_entries[i];
+	}
+	
+	return (pf);
 }
 
 int
-pkg_plist_add_depend(struct pkg_plist *pl, const char *name, 
-	const char *origin)
+pkg_plist_add_pkg_depend(struct pkg_plist *pl, struct pkg_depend *pd)
+{
+	struct pkg_depend **pkg_depend_entries_tmp;
+	char **pkg_depend_list_tmp;
+
+	if (pl == NULL)
+		arg_rage_quit(__func__, "Not a valid plist.", RAGE_AT_LIBPKG);
+	if (pd == NULL)
+		arg_rage_quit(__func__, "Not a valid package dependency.",
+			RAGE_AT_LIBPKG);
+	
+	/* Checj for existing dep that may conflict. */
+
+	if (pl->pkg_depend_count % 10 == 0) {
+		pkg_depend_entries_tmp = pl->pkg_depend_entries;
+		pkg_depend_list_tmp = pl->pkg_depend_list;
+		pl->pkg_depend_entries = realloc(pkg_depend_entries_tmp,
+			sizeof(struct pkg_depend *) * (pl->pkg_depend_count + (10 + 1)));
+		pl->pkg_depend_list = realloc(pkg_depend_list_tmp, 
+			sizeof(char *) * (pl->pkg_depend_count + (10 + 1)));
+		if (pl->pkg_depend_entries == NULL || pl->pkg_depend_list == NULL) {
+			printf("need moar memory\n");
+			exit(100);
+		}
+	}
+	
+	pl->pkg_depend_entries[pl->pkg_depend_count] = pd;
+	pl->pkg_depend_list[pl->pkg_depend_count] = pd->name;
+	pl->pkg_depend_count++;
+	pl->pkg_depend_entries[pl->pkg_depend_count] = NULL;
+	pl->pkg_depend_list[pl->pkg_depend_count] = NULL;
+
+	return (OK);
+}
+
+struct pkg_depend *
+pkg_plist_get_pkg_depend(struct pkg_plist *pl, const char *name)
 {
-	if (pl || name || origin)
-		return 0;
-	return 0;
+	int i;
+	struct pkg_depend *pd;
+
+	if (pl == NULL)
+		arg_rage_quit(__func__, "Not a valid plist.", RAGE_AT_LIBPKG);
+	if (name == NULL)
+		arg_rage_quit(__func__, "Not a valid path.", RAGE_AT_LIBPKG);
+
+	pd = NULL;
+	for (i = 0; i < pl->pkg_depend_count; ++i) {
+		if (strcmp(pl->pkg_depend_entries[i]->name, name) == 0)
+			pd = pl->pkg_depend_entries[i];
+	}
+	
+	return (pd);
 }
 
 int
-pkg_plist_add_conflict(struct pkg_plist *pl, const char *name)
+pkg_plist_add_pkg_conflict(struct pkg_plist *pl, struct pkg_conflict *pc)
+{
+	struct pkg_conflict **pkg_conflict_entries_tmp;
+	char **pkg_conflict_list_tmp;
+
+	if (pl == NULL)
+		arg_rage_quit(__func__, "Not a valid plist.", RAGE_AT_LIBPKG);
+	if (pc == NULL)
+		arg_rage_quit(__func__, "Not a valid package conflict.",
+			RAGE_AT_LIBPKG);
+	
+	/* Checj for existing dep that may conflict. */
+
+	if (pl->pkg_conflict_count % 10 == 0) {
+		pkg_conflict_entries_tmp = pl->pkg_conflict_entries;
+		pkg_conflict_list_tmp = pl->pkg_conflict_list;
+		pl->pkg_conflict_entries = realloc(pkg_conflict_entries_tmp,
+			sizeof(struct pkg_conflict *) * (pl->pkg_conflict_count + (10 + 1)));
+		pl->pkg_conflict_list = realloc(pkg_conflict_list_tmp, 
+			sizeof(char *) * (pl->pkg_conflict_count + (10 + 1)));
+		if (pl->pkg_conflict_entries == NULL || pl->pkg_conflict_list == NULL) {
+			printf("need moar memory\n");
+			exit(100);
+		}
+	}
+	
+	pl->pkg_conflict_entries[pl->pkg_conflict_count] = pc;
+	pl->pkg_conflict_list[pl->pkg_conflict_count] = pc->name;
+	pl->pkg_conflict_count++;
+	pl->pkg_conflict_entries[pl->pkg_conflict_count] = NULL;
+	pl->pkg_conflict_list[pl->pkg_conflict_count] = NULL;
+	
+	return (OK);
+}
+
+struct pkg_conflict *
+pkg_plist_get_pkg_conflict(struct pkg_plist *pl, const char *name)
 {
-	if (pl || name)
-		return 0;
-	return 0;
+	int i;
+	struct pkg_conflict *pc;
+
+	if (pl == NULL)
+		arg_rage_quit(__func__, "Not a valid plist.", RAGE_AT_LIBPKG);
+	if (name == NULL)
+		arg_rage_quit(__func__, "Not a valid path.", RAGE_AT_LIBPKG);
+
+	pc = NULL;
+	for (i = 0; i < pl->pkg_conflict_count; ++i) {
+		if (strcmp(pl->pkg_conflict_entries[i]->name, name) == 0)
+			pc = pl->pkg_conflict_entries[i];
+	}
+	
+	return (pc);
 }
 
 int

==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_plist.h#23 (text+ko) ====

@@ -82,13 +82,16 @@
 	char *text; /* The entire plist */
 
 	int pkg_file_count;
-	struct pkg_file **pkg_file_list;
+	char **pkg_file_list;
+	struct pkg_file **pkg_file_entries;
 
 	int pkg_depend_count;
-	struct pkg_depend **pkg_depend_list;
+	char **pkg_depend_list;
+	struct pkg_depend **pkg_depend_entries;
 
 	int pkg_conflict_count;
-	struct pkg_conflict **pkg_conflict_list;
+	char **pkg_conflict_list;
+	struct pkg_conflict **pkg_conflict_entries;
 
 	short parsed;
 };
@@ -118,22 +121,26 @@
 
 /* pkg_file */
 
-int pkg_plist_add_file(struct pkg_plist *pl, const char *path, 
-	const char *cwd, const char *group, const char *md5, 
-	const char *mode, const char *owner);
+int pkg_plist_add_pkg_file(struct pkg_plist *pl, struct pkg_file *pf); 
+struct pkg_file *pkg_plist_get_pkg_file(struct pkg_plist *pl, 
+	const char *path);
 int pkg_plist_remove_file(struct pkg_plist *pl, const char *path);
 const char *const *pkg_plist_files(struct pkg_plist *pl);
 
 /* pkg_depend */
 
-int pkg_plist_add_depend(struct pkg_plist *pl, const char *name, 
-	const char *origin);
+int pkg_plist_add_pkg_depend(struct pkg_plist *pl, struct pkg_depend *pd);
+struct pkg_depend *pkg_plist_get_pkg_depend(struct pkg_plist *pl,
+	const char *name);
 int pkg_plist_remove_depend(struct pkg_plist *pl, const char *name);
 const char *const *pkg_plist_depends(struct pkg_plist *pl);
 
 /* pkg_conflict */
 
-int pkg_plist_add_conflict(struct pkg_plist *pl, const char *name);
+int pkg_plist_add_pkg_conflict(struct pkg_plist *pl, 
+	struct pkg_conflict *pc);
+struct pkg_conflict *pkg_plist_get_pkg_conflict(struct pkg_plist *pl,
+	const char *name);
 int pkg_plist_remove_conflict(struct pkg_plist *pl, const char *name);
 const char *const *pkg_plist_conflicts(struct pkg_plist *pl);
 

==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_util.c#11 (text+ko) ====

@@ -76,33 +76,36 @@
 }
 
 
-#if 0
 void
 pkg_dump(struct pkg *p, FILE *stream)
 {
-	struct pkg_depend*pd;
-	struct pkg_conflict *pc;
-	struct pkg_file *pf;
+	const char *const *files;
+	const char *const *conflicts;
+	const char *const *depends;
 
 	const char *ident;
 	const char *comment;
 	const char *name;
-	const char *cwd;
 	const char *origin;
 	const char *mtree_file;
+
+	const char *cwd;
 	const char *path;
 	const char *md5;
 	const char *owner;
 	const char *group;
 	const char *mode;
+	
+	const char *file;
+	const char *conflict;
+	const char *depend;
 
 	ident = pkg_ident(p);
 	comment = pkg_comment(p);
 	
 	name = pkg_name(p);
-	cwd = pkg_cwd(p);
 	origin = pkg_origin(p);
-	mtree_file = pkg_mtree_file(p);
+	/* mtree_file = pkg_mtree_file(p); */
 	
 
 	fprintf(stream, "IDENT: %s\n\n",
@@ -112,10 +115,9 @@
 
 	fprintf(stream, "\tname: %s\n", 
 		(name != NULL ? name : BAD_OR_UNKNOWN_VALUE));
-	fprintf(stream, "\tcwd: %s\n", 
-		(cwd != NULL ? name : BAD_OR_UNKNOWN_VALUE));
 	fprintf(stream, "\torigin: %s\n", 
 		(origin != NULL ? origin : BAD_OR_UNKNOWN_VALUE));
+	/*
 	fprintf(stream, "\tmtree file: %s\n",
 		(mtree_file != NULL ? mtree_file : BAD_OR_UNKNOWN_VALUE));
 	fprintf(stream, "\textract in place: %s\n",
@@ -124,16 +126,22 @@
 		(pkg_preserve(p) ? "YES" : "NO"));
 	fprintf(stream, "\tcomplete: %s\n",
 		(pkg_complete(p) ? "YES" : "NO"));
+	*/
+
 	fprintf(stream, "\tfiles:\n");
-	pkg_pkg_file_list_init(p);
-	while ((pf = pkg_pkg_file_list_next(p)) != NULL) {
-		path = pkg_file_path(pf);
-		md5 = pkg_file_md5(pf);
-		owner = pkg_file_owner(pf);
-		group = pkg_file_group(pf);
-		mode = pkg_file_mode(pf);
+	files = pkg_files(p);
+	while ((file = *files++) != NULL) {
+		path = file;
+		cwd = pkg_file_get_cwd(p, file);
+		md5 = pkg_file_get_md5(p, file);
+		owner = pkg_file_get_owner(p, file);
+		group = pkg_file_get_group(p, file);
+		mode = pkg_file_get_mode(p, file);
+
 		fprintf(stream, "\t\t%s\n", 
 			(path != NULL ? path : BAD_OR_UNKNOWN_VALUE));
+		fprintf(stream, "\t\t\tCWD: %s\n",
+			(cwd != NULL ? cwd : BAD_OR_UNKNOWN_VALUE));
 		fprintf(stream, "\t\t\tMD5: %s\n", 
 			(md5 != NULL ? md5 : BAD_OR_UNKNOWN_VALUE));
 		fprintf(stream, "\t\t\tOWNER: %s\n", 
@@ -145,18 +153,17 @@
 	}
 
 	fprintf(stream, "\tdepends:\n");
-	pkg_pkg_dep_list_init(p);
-	while ((pd = pkg_pkg_dep_list_next(p)) != NULL) {
-		name = pkg_dep_name(pd);
-		origin = pkg_dep_origin(pd);
+	depends = pkg_depends(p);
+	while ((depend = *depends++) != NULL) {
+		name = depends;
+		origin = pkg_depend_get_origin(p, depends);
 		fprintf(stream, "\t\t%s : %s\n", name, origin);
 	}
 
 	fprintf(stream, "\tconflicts:\n");
-	pkg_pkg_conflict_list_init(p);
-	while ((pc = pkg_pkg_conflict_list_next(p)) != NULL) {
-		name = pkg_conflict_name(pc);
+	conflicts = pkg_conflicts(p);
+	while ((conflict = *conflicts++) != NULL) {
+		name = conflict;
 		fprintf(stream, "\t\t%s\n", name);
 	}
 }
-#endif

==== //depot/projects/soc2009/dforsyth_libpkg/pkg_info/main.c#23 (text+ko) ====

@@ -88,23 +88,21 @@
 perform_on_db(struct pkg_db *db)
 {
 	const char *ident;
-	const char *const *keys;
+	const char *const *files;
 	struct pkg *p;
 
 	/* There will be cases where an init is useless, but since I haven't
 	 * written that much yet, init regardless. */
 	
-	keys = pkg_db_all_pkgs(db);
+	files = pkg_db_all_pkgs(db);
 
-	while ((ident = *keys++) != NULL) {
+	while ((ident = *files++) != NULL) {
 		p = pkg_db_select_pkg(db, ident);
 		if (!opt_all)
 			print_pkg_information(p);
 		else
 			print_pkg_information(p);
 	}
-
-	pkg_delete(p);
 }
 
 void
@@ -123,7 +121,7 @@
 			(ident != NULL ? ident : BAD_OR_UNKNOWN_VALUE), 
 			(comment != NULL ? comment : BAD_OR_UNKNOWN_VALUE));
 	} else {
-		printf("wat.\n");
+		pkg_dump(p, stdout);
 	}
 }
 


More information about the p4-projects mailing list