PERFORCE change 165728 for review

David Forsythe dforsyth at FreeBSD.org
Tue Jul 7 03:05:44 UTC 2009


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

Change 165728 by dforsyth at squirrel on 2009/07/07 03:05:23

	Some changes to pkg_plist.h.  Most of the code isn't written.

Affected files ...

.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg.c#31 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg.h#29 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_plist.c#23 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_plist.h#19 edit

Differences ...

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

@@ -24,7 +24,8 @@
 	char *display;
 	char *mtree_dirs;
 	char *required_by;
-
+	
+	struct pkg_sub *psub;
 	struct pkg_plist *plist;
 
 	short dirty;
@@ -225,6 +226,74 @@
 	return (pkg_plist_set_origin(p->plist, origin));
 }
 
+/* Retreive the short comment for this package. (Maybe consider moving
+ * this into the plist? */
+
+const char *
+pkg_comment(struct pkg *p)
+{
+	if (p == NULL)
+		arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
+
+	return (p->comment);
+}
+
+/* Retrieve the long description for this package. */
+
+const char *
+pkg_description(struct pkg *p)
+{
+	if (p == NULL)
+		arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
+
+	return (p->description);
+}
+
+/* Set the short comment for this package */
+
+int
+pkg_set_comment(struct pkg *p, const char *comment)
+{
+	char *f;
+
+	if (p == NULL)
+		arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
+	
+	free(p->comment);
+	p->comment = (comment != NULL) ? strdup(comment) : NULL;
+	if (p->comment == NULL)
+		return (PKG_MEMORY_ERR | PKG_NOT_OK);
+	
+	/* Blot out trailing \n, if it's there. */
+	f = strrchr(p->comment, (int)'\n');
+	if (f != NULL && *(f + 1) == '\0')
+		*f = '\0';
+
+	return (PKG_OK);
+}
+
+/* Set the long description for this package. */
+
+int
+pkg_set_description(struct pkg *p, const char *description)
+{
+	char *f;
+
+	if (p == NULL)
+		arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
+
+	free(p->description);
+	p->description = (description != NULL) ? strdup(description) : NULL;
+	if (p->description == NULL)
+		return (PKG_MEMORY_ERR | PKG_NOT_OK);
+
+	f = strrchr(p->description, (int)'\n');
+	if (f != NULL && *(f + 1) == '\0')
+		*f = '\0';
+
+	return (PKG_OK);
+}
+
 /* Maybe I should do these list retrievals in a fashion similar to
  * scandir? */
 
@@ -264,6 +333,9 @@
 	return (pkg_plist_conflicts(p->plist));
 }
 
+/* Add a file to a package. This is fairly useless at this point
+ * because... well, there the hell is the file coming from? */
+
 int
 pkg_add_file(struct pkg *p, const char *path, const char *md5, 
 	const char *owner, const char *group, const char *mode)
@@ -303,92 +375,7 @@
 	return (status);	
 }
 
-/* Set the short comment for this package */
-int
-pkg_set_comment(struct pkg *p, const char *comment)
-{
-	int c;
-	char *f;
-
-	if (p == NULL)
-		arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
-	
-	free(p->comment);
-	p->comment = (comment != NULL) ? strdup(comment) : NULL;
-	if (p->comment != NULL) {
-		/* Blot out trailing \n, if it's there. */
-		c = (int)'\n';
-		f = strrchr(p->comment, c);
-		if (f != NULL && *(f + 1) == '\0')
-			*f = '\0';
-	}
-
-	return (OK);
-}
-
-/* Set the contents for this package. */
-
-int
-pkg_set_contents(struct pkg *p, const char *contents)
-{
-	if (p == NULL)
-		arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
-	
-	/* Yes this makes for 3 copies of the text in memory at once, but just
-	 * until I decide how I want to handle 'dirty' packages. */
-	free(p->contents);
-	p->contents = (contents != NULL) ? strdup(contents) : NULL;
-
-	return (OK);
-}
-
-int
-pkg_set_description(struct pkg *p, const char *description)
-{
-	if (p == NULL)
-		arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
-	
-	free(p->description);
-	p->description = (description != NULL) ? strdup(description) : NULL;
-
-	return (OK);
-}
-
-int
-pkg_set_display(struct pkg *p, const char *display)
-{
-	if (p == NULL)
-		arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
-	
-	free(p->display);
-	p->display = (display != NULL) ? strdup(display) : NULL;
-
-	return (OK);
-}
-
-int
-pkg_set_mtree_dirs(struct pkg *p, const char *mtree_dirs)
-{
-	if (p == NULL)
-		arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
-	
-	free(p->mtree_dirs);
-	p->mtree_dirs = (mtree_dirs != NULL) ? strdup(mtree_dirs) : NULL;
-
-	return (OK);
-}
-
-int
-pkg_set_required_by(struct pkg *p, const char *required_by)
-{
-	if (p == NULL)
-		arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
-
-	free(p->required_by);
-	p->required_by = (required_by != NULL) ? strdup(required_by) : NULL;
-
-	return (OK);
-}
+/* Parse the plist (contents) of a package. */
 
 int
 pkg_parse_plist(struct pkg *p)
@@ -407,124 +394,3 @@
 	status = pkg_plist_parse_contents_from_text(p->plist, p->contents);
 	return (status);
 }
-
-/* ident and name are different, even though they might be the same. */
-
-char *
-pkg_comment(struct pkg *p)
-{
-	if (p == NULL)
-		arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
-
-	return (p->comment);
-}
-
-/* Functions to access information stored in the pkg_plist. */
-
-
-
-char *
-pkg_mtree_file(struct pkg *p)
-{
-	if (p == NULL)
-		arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
-
-	if (pkg_parse_plist(p) != OK)
-		return (NULL);
-	return (pkg_plist_mtree_file(p->plist));
-}
-
-/* Other properties. */
-
-int
-pkg_extract_in_place(struct pkg *p)
-{
-	if (p == NULL)
-		arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
-
-	if (pkg_parse_plist(p) != OK)
-		return (PKG_PARSE_NOT_OK);
-
-	return (pkg_plist_extract_in_place(p->plist));
-}
-
-int
-pkg_preserve(struct pkg *p)
-{
-	if (p == NULL)
-		arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
-
-	if (pkg_parse_plist(p) != OK)
-		return (PKG_PARSE_NOT_OK);
-
-	return (pkg_plist_preserve(p->plist));
-}
-
-int
-pkg_complete(struct pkg *p)
-{
-	if (p == NULL)
-		arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
-
-	if (pkg_parse_plist(p) != OK)
-		return (PKG_PARSE_NOT_OK);
-
-	return (pkg_plist_complete(p->plist));
-}
-
-/* These need to be renamed. */
-
-void
-pkg_pkg_file_list_init(struct pkg *p)
-{
-	if (p == NULL)
-		arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
-
-	pkg_plist_pkg_file_list_reset(p->plist);
-}
-
-struct pkg_file *
-pkg_pkg_file_list_next(struct pkg *p)
-{
-	if (p == NULL)
-		arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
-
-	return (pkg_plist_pkg_file_list_next(p->plist));
-}
-
-void
-pkg_pkg_dep_list_init(struct pkg *p)
-{
-	if (p == NULL)
-		arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
-
-	return (pkg_plist_pkg_dep_list_reset(p->plist));
-}
-
-struct pkg_dep *
-pkg_pkg_dep_list_next(struct pkg *p)
-{
-	if (p == NULL)
-		arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
-
-	return (pkg_plist_pkg_dep_list_next(p->plist));
-}
-
-void
-pkg_pkg_cfl_list_init(struct pkg *p)
-{
-	if (p == NULL)
-		arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
-
-	return (pkg_plist_pkg_cfl_list_reset(p->plist));
-}
-
-struct pkg_cfl *
-pkg_pkg_cfl_list_next(struct pkg *p)
-{
-	if (p == NULL)
-		arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
-	
-	return (pkg_plist_pkg_cfl_list_next(p->plist));
-}
-

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

@@ -74,6 +74,13 @@
 int pkg_set_cwd(struct pkg *p, const char *cwd);
 int pkg_set_origin(struct pkg *p, const char *origin);
 
+const char *pkg_comment(struct pkg *p);
+const char *pkg_description(struct pkg *p);
+
+int pkg_set_comment(struct pkg *p, const char *comment);
+int pkg_set_description(struct pkg *p, const char *description);
+/* Add mtree_dirs, display, etc, etc. */
+
 const char **pkg_files(struct pkg *p);
 const char **pkg_depends(struct pkg *p);
 const char **pkg_conflicts(struct pkg *p);
@@ -96,6 +103,9 @@
 int pkg_remove_conflict(struct pkg *p, const char *name);
 const char *pkg_conflict_version(struct pkg *p, const char *name);
 
+/* TODO: Should I add a function to add names of pkgs that depend on a
+ * pkg? */
+
 /* TODO: Add installation/deinstallation routine modification... routines. */
 
 /* pkgdb */

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

@@ -93,18 +93,6 @@
 }
 
 int
-pkg_plist_new_from_text(const char *text)
-{
-	int status;
-	struct pkg_plist *pl;
-
-	pl = pkg_plist_new();
-	status = pkg_plist_parse_contents_from_text(pl, text);
-	
-	return (status);
-}
-
-int
 pkg_plist_parse_contents_from_text(struct pkg_plist *pl, const char *text)
 {
 	int s;
@@ -410,191 +398,3 @@
 	return (pl->complete);
 }
 
-/* I should really just write a set of generic routine to handle this
- * whole mess. */
-
-/* Temporarily void. */
-void 
-pkg_plist_pkg_file_list_reset(struct pkg_plist *pl)
-{
-	/* If you init again, it clears the list.  So don't. */
-	pl->pkg_file_curr = NULL;
-}
-
-struct pkg_file *
-pkg_plist_pkg_file_list_next(struct pkg_plist *pl)
-{
-	struct pkg_file *pf;
-
-	if (pl == NULL)
-		return (NULL);
-	
-	if (pl->pkg_file_curr == NULL) 
-		pf = pkg_plist_pkg_file_list_first(pl);
-	else
-		pf = TAILQ_NEXT(pl->pkg_file_curr, next);
-	
-	if (pf != NULL)
-		pl->pkg_file_curr = pf;
-	
-	return (pf);
-}
-
-void
-pkg_plist_pkg_file_list_init(struct pkg_plist *pl)
-{
-	if (pl == NULL)
-		return;
-
-	TAILQ_INIT(&pl->pkg_file_head);
-}
-
-struct pkg_file *
-pkg_plist_pkg_file_list_first(struct pkg_plist *pl)
-{
-	if (pl == NULL)
-		return (NULL);
-
-	return (TAILQ_FIRST(&pl->pkg_file_head));
-}
-
-struct pkg_file *
-pkg_plist_pkg_file_list_last(struct pkg_plist *pl)
-{
-	if (pl == NULL)
-		return (NULL);
-
-	return (TAILQ_LAST(&pl->pkg_file_head, pkg_file_head));
-}
-
-void
-pkg_plist_pkg_file_list_append(struct pkg_plist *pl, struct pkg_file *pf)
-{
-	if (pl == NULL || pf == NULL)
-		return;
-	
-	TAILQ_INSERT_TAIL(&pl->pkg_file_head, pf, next);
-}
-
-/* pkg_dep list manipulation and access. */
-/* generalize plz. */
-
-void
-pkg_plist_pkg_dep_list_reset(struct pkg_plist *pl)
-{
-	if (pl == NULL)
-		return;
-
-	pl->pkg_dep_curr = NULL;
-}
-
-void
-pkg_plist_pkg_dep_list_init(struct pkg_plist *pl)
-{
-	if (pl == NULL)
-		return;
-
-	TAILQ_INIT(&pl->pkg_dep_head);
-}
-
-struct pkg_dep *
-pkg_plist_pkg_dep_list_last(struct pkg_plist *pl)
-{
-	if (pl == NULL)
-		arg_rage_quit(__func__, "Not a valid plist.", RAGE_AT_LIBPKG);
-
-	return (TAILQ_LAST(&pl->pkg_dep_head, pkg_dep_head));
-}
-
-void
-pkg_plist_pkg_dep_list_append(struct pkg_plist *pl, struct pkg_dep *pd)
-{
-	if (pl == NULL || pd == NULL)
-		return;
-	
-	TAILQ_INSERT_TAIL(&pl->pkg_dep_head, pd, next);
-}
-
-struct pkg_dep *
-pkg_plist_pkg_dep_list_next(struct pkg_plist *pl)
-{
-	struct pkg_dep *pd;
-
-	if (pl == NULL)
-		return (NULL);
-	
-	if (pl->pkg_dep_curr == NULL) 
-		pd = pkg_plist_pkg_dep_list_first(pl);
-	else
-		pd = TAILQ_NEXT(pl->pkg_dep_curr, next);
-	
-	if (pd != NULL)
-		pl->pkg_dep_curr = pd;
-	
-	return (pd);
-}
-
-struct pkg_dep *
-pkg_plist_pkg_dep_list_first(struct pkg_plist *pl)
-{
-	if (pl == NULL)
-		arg_rage_quit(__func__, "Not a valid plist.", RAGE_AT_LIBPKG);
-	
-	return (TAILQ_FIRST(&pl->pkg_dep_head));
-}
-
-void
-pkg_plist_pkg_cfl_list_init(struct pkg_plist *pl)
-{
-	if (pl == NULL)
-		return;
-
-	TAILQ_INIT(&pl->pkg_cfl_head);
-}
-
-void
-pkg_plist_pkg_cfl_list_append(struct pkg_plist *pl, struct pkg_cfl *pc)
-{
-	if (pl == NULL || pc == NULL)
-		return;
-
-	TAILQ_INSERT_TAIL(&pl->pkg_cfl_head, pc, next);
-}
-
-struct pkg_cfl *
-pkg_plist_pkg_cfl_list_first(struct pkg_plist *pl)
-{
-	if (pl == NULL)
-		arg_rage_quit(__func__, "Not a valid plist.", RAGE_AT_LIBPKG);
-
-	return (TAILQ_FIRST(&pl->pkg_cfl_head));
-}
-
-void 
-pkg_plist_pkg_cfl_list_reset(struct pkg_plist *pl)
-{
-	if (pl == NULL)
-		arg_rage_quit(__func__, "Not a valid plist.", RAGE_AT_LIBPKG);
-
-	pl->pkg_cfl_curr = NULL;
-}
-
-struct pkg_cfl *
-pkg_plist_pkg_cfl_list_next(struct pkg_plist *pl)
-{
-	struct pkg_cfl *pc;
-	
-	if (pl == NULL)
-		arg_rage_quit(__func__, "Not a valid plist.", RAGE_AT_LIBPKG);
-	
-	if (pl->pkg_cfl_curr == NULL) 
-		pc = pkg_plist_pkg_cfl_list_first(pl);
-	else
-		pc = TAILQ_NEXT(pl->pkg_cfl_curr, next);
-	
-	if (pc != NULL)
-		pl->pkg_cfl_curr = pc;
-	
-	return (pc);
-}
-

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

@@ -81,19 +81,6 @@
 
 	char *text; /* The entire plist */
 
-	struct pkg_file *pkg_file_curr;
-	struct pkg_dep *pkg_dep_curr;
-	struct pkg_cfl *pkg_cfl_curr;
-
-	/* Use these lists here so that appending to our list doesnt need a
-	 * bunch of realloc procedures.  This will be convenient for clients
-	 * that want to build plists on the fly, modify plists, etc. */
-	/* No, screw them I hate them and hope they burn. */
-
-	TAILQ_HEAD(pkg_file_head, pkg_file) pkg_file_head; /* pkg_file list. */
-	TAILQ_HEAD(pkg_dep_head, pkg_dep) pkg_dep_head; /* pkg_dep list. */
-	TAILQ_HEAD(pkg_cfl_head, pkg_cfl) pkg_cfl_head; /* pkg_cfl list. */
-	
 	unsigned int pkg_file_cnt;
 	struct pkg_file *pkg_file_list;
 
@@ -107,22 +94,16 @@
 };
 
 struct pkg_plist *pkg_plist_new(void);
+void pkg_plist_delete(struct pkg_plist *pl);
+void pkg_plist_reset(struct pkg_plist *pl);
 
 int pkg_plist_parsed(struct pkg_plist *pl);
-	
-void pkg_plist_reset(struct pkg_plist *pl);
-
-int pkg_plist_new_from_text(const char *text);
 
 int pkg_plist_parse_contents_from_text(struct pkg_plist *pl, 
 	const char *text);
 int pkg_plist_parse_line(struct pkg_plist *pl, char *line, 
 	struct parse_state *st);
 
-void pkg_plist_pkg_file_list_reset(struct pkg_plist *pl);
-
-struct pkg_file *pkg_plist_pkg_file_list_next(struct pkg_plist *pl);
-
 char *pkg_plist_name(struct pkg_plist *pl);
 char *pkg_plist_cwd(struct pkg_plist *pl);
 char *pkg_plist_origin(struct pkg_plist *pl);
@@ -132,37 +113,27 @@
 int pkg_plist_preserve(struct pkg_plist *pl);
 int pkg_plist_complete(struct pkg_plist *pl);
 
-void pkg_plist_pkg_file_list_init(struct pkg_plist *pl);
-struct pkg_file *pkg_plist_pkg_file_list_first(struct pkg_plist *pl);
-struct pkg_file *pkg_plist_pkg_file_list_last(struct pkg_plist *pl);
-void pkg_plist_pkg_file_list_append(struct pkg_plist *pl, 
-	struct pkg_file *pf);
+void set_parse_state_default(struct parse_state *st);
 
-void set_parse_state_default(struct parse_state *st);
+/* pkg_file */
 
-void pkg_plist_delete(struct pkg_plist *pl);
+int pkg_plist_add_file(struct pkg_plist *pl, const char *path, 
+	const char *md5, const char *owner, const char *group, 
+	const char *mode);
+int pkg_plist_remove_file(struct pkg_plist *pl, const char *path);
+const char **pkg_plist_files(struct pkg_plist *pl);
 
 /* pkg_dep */
-void pkg_plist_pkg_dep_list_init(struct pkg_plist *pl);
 
-struct pkg_dep *pkg_plist_pkg_dep_list_last(struct pkg_plist *pl);
-
-void pkg_plist_pkg_dep_list_append(struct pkg_plist *pl, 
-	struct pkg_dep *pd);
+int pkg_plist_add_depend(struct pkg_plist *pl, const char *name, 
+	const char *origin);
+int pkg_plist_remove_depend(struct pkg_plist *pl, const char *name);
+const char **pkg_plist_depends(struct pkg_plist *pl);
 
-void pkg_plist_pkg_dep_list_reset(struct pkg_plist *pl);
-struct pkg_dep *pkg_plist_pkg_dep_list_next(struct pkg_plist *pl);
-struct pkg_dep *pkg_plist_pkg_dep_list_first(struct pkg_plist *pl);
-
 /* pkg_cfl */
 
-void pkg_plist_pkg_cfl_list_init(struct pkg_plist *pl);
-
-void pkg_plist_pkg_cfl_list_append(struct pkg_plist *pl,
-	struct pkg_cfl *pc);
-
-void pkg_plist_pkg_cfl_list_reset(struct pkg_plist *pl);
-struct pkg_cfl *pkg_plist_pkg_cfl_list_next(struct pkg_plist *pl);
-struct pkg_cfl *pkg_plist_pkg_cfl_list_first(struct pkg_plist *pl);
+int pkg_plist_add_conflict(struct pkg_plist *pl, const char *name);
+int pkg_plist_remove_conflict(struct pkg_plist *pl, const char *name);
+const char **pkg_plist_conflicts(struct pkg_plist *pl);
 
 #endif


More information about the p4-projects mailing list