PERFORCE change 163149 for review

David Forsythe dforsyth at FreeBSD.org
Sun May 31 07:57:52 UTC 2009


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

Change 163149 by dforsyth at squirrel on 2009/05/31 07:57:47

	Moved alot of things around.  Last submit before restructure.

Affected files ...

.. //depot/projects/soc2009/dforsyth_libpkg/pkg.c#6 edit
.. //depot/projects/soc2009/dforsyth_libpkg/pkg.h#5 edit
.. //depot/projects/soc2009/dforsyth_libpkg/pkg_info.c#2 edit
.. //depot/projects/soc2009/dforsyth_libpkg/pkgdb.c#6 edit
.. //depot/projects/soc2009/dforsyth_libpkg/pkgdb.h#3 edit

Differences ...

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

@@ -5,8 +5,10 @@
 #include <sys/queue.h>
 
 #include "pkg_util.h"
+#include "pkgdb.h"
 #include "pkg.h"
 
+
 /* Create a new pkg. */
 
 struct pkg *
@@ -26,7 +28,19 @@
 		return (NULL);
 	}
 	p->ident = new_ident;
+	p->comment = NULL;
+	p->contents = NULL;
+
+	return (p);
+}
 
+struct pkg *
+pkg_set_path(struct pkg *p, const char *path)
+{
+	if (p == NULL || path == NULL)
+		return (p);
+
+	p->path = strdup(path);
 	return (p);
 }
 

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

@@ -1,38 +1,15 @@
 #ifndef __PKG_H__
 #define __PKG_H__
 
-struct pkg_file {
-	char *name;
-	char *path;
-	char *md5;
-};
+#include <sys/queue.h>
+#include <dirent.h>
 
-struct pkg_contents {
-	int rev;
-	char *name;
-	char **file_list; /* place holder */
-	char *cwd;
-	char **conflict;
-};
+/* pkg */
 
-struct pkg {
-	TAILQ_ENTRY(pkg) next; /* Hide meh */
+struct pkg;
 
-	char *ident; /* User given name for this pkg. */
-	char *path;
-	
-	char *comment;
-	struct pkg_contents *contents;
-	
-	int has_comment;
-	int has_contents;
-	int has_display;
-	int has_mtree_dirs;
-	int has_desc;
-	int has_required_by;
-};
-
 struct pkg *pkg_new(const char *ident);
+struct pkg *pkg_set_path(struct pkg *p, const char *path);
 
 int set_pkg_contents(struct pkg *p, char *contents);
 int set_pkg_comment(struct pkg *p, char *comment);
@@ -43,4 +20,30 @@
 
 void pkg_free(struct pkg *p);
 
+/* pkgdb */
+
+struct pkgdb;
+
+struct pkgdb *pkgdb_new_hierdb(const char *db_root);
+
+int pkgdb_init_hierdb(struct pkgdb *db);
+struct pkg *pkgdb_read_pkg_hierdb(struct pkgdb *db, const char *ident);
+struct pkg *pkgdb_next_pkg(struct pkgdb *db);
+
+struct pkg *pkgdb_query_pkg(struct pkgdb *db, const char *ident);
+
+char *pkgdb_pkg_path(struct pkgdb *db, struct pkg *p);
+
+void pkgdb_pkg_list_init(struct pkgdb *db);
+struct pkg *pkgdb_pkg_list_first(struct pkgdb *db);
+void pkgdb_pkg_list_append(struct pkgdb *db, struct pkg *p);
+
+void pkgdb_free_hierdb(struct pkgdb *db);
+void pkgdb_free_pkg_list(struct pkgdb *db);
+
+/* pkg_info */
+struct pkg_info;
+
+int pkg_info_read_comment_file(struct pkg *p, const char *filename);
+
 #endif

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

@@ -1,9 +1,15 @@
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <unistd.h>
 
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <dirent.h>
+
+#include "pkg_info.h"
+#include "pkgdb.h"
+#include "pkg.h"
 
 struct pkg_file {
 	char *name;
@@ -16,7 +22,21 @@
 	char *name;
 	char *orgin;
 	char *cwd;
+	char *conflicts;
 	
 	int f_count;
 	struct pkg_file *files;
 };
+
+struct pkg *
+pkg_info_read_comment_file(struct pkg *p, const char *filename:) {
+	
+	if (p == NULL || filename == NULL)
+		return (NULL);
+	
+	
+	return (p);
+}
+
+	
+	

==== //depot/projects/soc2009/dforsyth_libpkg/pkgdb.c#6 (text+ko) ====

@@ -8,6 +8,7 @@
 #include <dirent.h>
 
 #include "pkg_util.h"
+#include "pkg_info.h"
 #include "pkgdb.h"
 #include "pkg.h"
 
@@ -64,11 +65,11 @@
 	if (db == NULL)
 		return (-1);
 	
-	TAILQ_INIT(&db->p_head);
+	pkgdb_pkg_list_init(db);
 	if (db->dirty == 0) {
 		/* No changes since the last init, don't bother walking the
 		 * database again. */
-		db->p_curr = TAILQ_FIRST(&db->p_head);
+		db->p_curr = pkgdb_pkg_list_first(db);;
 		return (db->p_count);
 	}
 	
@@ -86,12 +87,12 @@
 			free(ents);
 			return (-1);
 		}
-		TAILQ_INSERT_TAIL(&db->p_head, p, next);
+		pkgdb_pkg_list_append(db, p);
 		free(ents[i]);
 	}
 	free(ents);
 	
-	db->p_curr = TAILQ_FIRST(&db->p_head);
+	db->p_curr = pkgdb_pkg_list_first(db);
 	db->p_count = p_count;
 	db->dirty = 0;
 	
@@ -109,11 +110,10 @@
 	char *path;
 	struct stat sb;
 	struct pkg *p;
-	struct dirent *e;
-	struct dirent **ents;
 
 	p = pkg_new(ident);
 	path = pkgdb_pkg_path(db, p);
+	pkg_set_path(p, path);
 	if (p == NULL || path == NULL) {
 		pkg_free(p);
 		free(path);
@@ -126,32 +126,6 @@
 		return (NULL);
 	}
 	
-	c = scandir(path, &ents, subdir_sel, alphasort);
-	for (i = 0; i < c; ++i) {
-		s = 0; /* Reset s */
-		/* Go through all the files in this package, grab the information
-		 * that we need. */
-		e = ents + i;
-		s = pkg_info_identify_file(e);
-		switch (s) {
-		case IS_COMMENTS:
-			/* Read the comments file into the comments field of this
-			 * package. */
-			break;
-		case IS_CONTENTS:
-			/* Do contents parsing stuff.  Like... 
-			p->contents = pkg_info_parse_contents_file(p,
-			CONTENTS_FILE); */
-			break;
-		case IS_MTREE_DIRS:
-			break; 
-		default:
-			/* This is an irrelevant file. */
-		}
-		free(e);
-	}
-
-	free(ents);
 	free(path);
 	return (p);
 }
@@ -170,18 +144,21 @@
 char *
 pkgdb_pkg_path(struct pkgdb *db, struct pkg *p)
 {
+	char *p_ident;
 	char *new_path;
 
 	if (db == NULL || p == NULL) {
 		return (NULL);
 	}
 
-	new_path = malloc(strlen(db->db_root) + strlen(p->ident) + 1);
+	new_path = malloc(strlen(db->db_root) + strlen(pkg_ident(p)) + 1);
 	if (new_path == NULL)
 		return (NULL);
+
+	p_ident = pkg_ident(p);
 	
 	strcpy(new_path, db->db_root);
-	strcat(new_path, p->ident);
+	strcat(new_path, p_ident);
 	
 	return (new_path);
 }
@@ -204,6 +181,32 @@
 	return (p);
 }
 
+/* Giving myself a level of abstraction between queue and pkgdb incase I
+ * decide to change how the package list is done. */
+
+void
+pkgdb_pkg_list_init(struct pkgdb *db) {
+	if (db == NULL)
+		return;
+	TAILQ_INIT(&db->p_head);
+}
+
+struct pkg *
+pkgdb_pkg_list_first(struct pkgdb *db) {
+	if (db == NULL)
+		return (NULL);
+
+	return (TAILQ_FIRST(&db->p_head));
+}
+
+void
+pkgdb_pkg_list_append(struct pkgdb *db, struct pkg *p) {
+	if (db == NULL || p == NULL)
+		return;
+
+	TAILQ_INSERT_TAIL(&db->p_head, p, next);
+}
+
 /* Free a hierdb. */
 
 void

==== //depot/projects/soc2009/dforsyth_libpkg/pkgdb.h#3 (text+ko) ====

@@ -1,14 +1,18 @@
 #ifndef __PKGDB_H__
 #define __PKGDB_H__
 
-#define COMMENT_FILE "+COMMENT"
-#define CONTENTS_FILE "+CONTENTS"
-#define DESC_FILE "+DESC"
-#define DISPLAY_FILE "+DISPLAY"
-#define MTREE_DIRS_FILE "+MTREE_DIRS"
-#define REQUIRED_BY_FILE "+REQUIRED_BY"
+#include "pkg_info.h"
+#include <sys/queue.h>
+
+struct pkg {
+	TAILQ_ENTRY(pkg) next;
 
-#include <sys/queue.h>
+	char *ident; /* User given name for this pkg. */
+	char *path;
+	
+	char *comment; /* Mmmmm, should be 70 or less, right? */
+	struct pkg_contents *contents;
+};
 
 struct pkgdb {
 	int dirty; /* changes have been made to this database. */
@@ -17,24 +21,17 @@
 
 	int p_count;
 	struct pkg *p_curr;
-	TAILQ_HEAD(pkg_head, next) p_head;
 
+	TAILQ_HEAD(pkg_head, pkg) p_head;
 	/* Callbacks */
 	/* tuuuummmmbbbllleeewwwweeeedddddd*/
 };
-// struct pkg_head;
 
-struct pkgdb *pkgdb_new_hierdb(const char *db_root);
-
-int pkgdb_init_hierdb(struct pkgdb *db);
-struct pkg *pkgdb_read_pkg_hierdb(struct pkgdb *db, const char *ident);
-struct pkg *pkgdb_next_pkg(struct pkgdb *db);
-
-struct pkg *pkgdb_query_pkg(struct pkgdb *db, const char *ident);
-
-char *pkgdb_pkg_path(struct pkgdb *db, struct pkg *p);
-
-void pkgdb_free_hierdb(struct pkgdb *db);
-void pkgdb_free_pkg_list(struct pkgdb *db);
+#define COMMENT_FILE "+COMMENT"
+#define CONTENTS_FILE "+CONTENTS"
+#define DESC_FILE "+DESC"
+#define DISPLAY_FILE "+DISPLAY"
+#define MTREE_DIRS_FILE "+MTREE_DIRS"
+#define REQUIRED_BY_FILE "+REQUIRED_BY"
 
 #endif


More information about the p4-projects mailing list