From owner-p4-projects@FreeBSD.ORG Tue Jun 9 03:12:27 2009 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 2EBD110656A4; Tue, 9 Jun 2009 03:12:27 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D7CA3106568A for ; Tue, 9 Jun 2009 03:12:26 +0000 (UTC) (envelope-from dforsyth@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id C47158FC14 for ; Tue, 9 Jun 2009 03:12:26 +0000 (UTC) (envelope-from dforsyth@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id n593CQHx087924 for ; Tue, 9 Jun 2009 03:12:26 GMT (envelope-from dforsyth@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id n593CQgT087922 for perforce@freebsd.org; Tue, 9 Jun 2009 03:12:26 GMT (envelope-from dforsyth@FreeBSD.org) Date: Tue, 9 Jun 2009 03:12:26 GMT Message-Id: <200906090312.n593CQgT087922@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to dforsyth@FreeBSD.org using -f From: David Forsythe To: Perforce Change Reviews Cc: Subject: PERFORCE change 163852 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 09 Jun 2009 03:12:28 -0000 http://perforce.freebsd.org/chv.cgi?CH=163852 Change 163852 by dforsyth@squirrel on 2009/06/09 03:12:05 Still building parser. Learned how to spell origin. Affected files ... .. //depot/projects/soc2009/dforsyth_libpkg/libpkg/Makefile#4 edit .. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg.c#11 edit .. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg.h#11 edit .. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_dep.c#1 add .. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_dep.h#1 add .. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_file.c#1 add .. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_file.h#1 add .. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_plist.c#6 edit .. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_plist.h#6 edit .. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_private.h#6 edit .. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_util.c#3 edit .. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_util.h#3 edit .. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkgdb.c#12 edit .. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkgdb.h#7 edit .. //depot/projects/soc2009/dforsyth_libpkg/pkg_info/Makefile#3 edit .. //depot/projects/soc2009/dforsyth_libpkg/pkg_info/main.c#6 edit .. //depot/projects/soc2009/dforsyth_libpkg/pkg_info/pkg_info.h#2 edit Differences ... ==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/Makefile#4 (text+ko) ==== @@ -1,7 +1,7 @@ LIB= pkg INCS= pkg.h WARNS= 6 -SRCS= pkgdb.c pkg_plist.c pkg.c pkg_util.c +SRCS= pkgdb.c pkg_plist.c pkg.c pkg_util.c pkg_file.c pkg_dep.c NO_MAN= yes .include ==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg.c#11 (text+ko) ==== @@ -3,12 +3,13 @@ #include #include "pkg_util.h" +#include "pkg_dep.h" +#include "pkg_file.h" #include "pkg_plist.h" #include "pkgdb.h" #include "pkg_private.h" #include "pkg.h" - /* Create a new pkg. */ struct pkg * @@ -122,13 +123,13 @@ /* Doesn't work correctly yet. */ char * -pkg_orgin(struct pkg *p) +pkg_origin(struct pkg *p) { - char *orgin; + char *origin; - orgin = pkg_plist_orgin(p->plist); + origin = pkg_plist_origin(p->plist); - return (orgin); + return (origin); } /* Temporarily void. */ @@ -142,21 +143,17 @@ } /* Temporarily char. */ -char * +struct pkg_file * pkg_file_list_next(struct pkg *p) { struct pkg_file *pf; - char *file_name; if (p == NULL) return (NULL); pf = pkg_plist_pkg_file_list_next(p->plist); - if (pf == NULL) - return (NULL); - file_name = pkg_file_path(pf); - - return (file_name); + + return (pf); } /* TODO: Make an note in the manual for libpkg that pkg_free should not be ==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg.h#11 (text+ko) ==== @@ -1,6 +1,19 @@ #ifndef __PKG_H__ #define __PKG_H__ +/* TODO: Error codes. */ + +/* pkg_file */ + +struct pkg_file; + +const char *pkg_file_path(struct pkg_file *pf); + +const char *pkg_file_md5(struct pkg_file *pf); + + +/* TODO: Get pkg_plist out of here. */ + /* pkg_plist */ struct pkg_plist; @@ -27,13 +40,13 @@ char *pkg_cwd(struct pkg *p); -char *pkg_orgin(struct pkg *p); +char *pkg_origin(struct pkg *p); char *pkg_comment(struct pkg *p); void pkg_file_list_init(struct pkg *p); -char *pkg_file_list_next(struct pkg *p); +struct pkg_file *pkg_file_list_next(struct pkg *p); void pkg_free(struct pkg *p); ==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_plist.c#6 (text+ko) ==== @@ -9,6 +9,8 @@ #include #include +#include "pkg_dep.h" +#include "pkg_file.h" #include "pkg_plist.h" #include "pkgdb.h" #include "pkg.h" @@ -19,33 +21,26 @@ char *group; }; -struct pkg_file { - char *path; - char *md5; - char *owner; - char *group; - - TAILQ_ENTRY(pkg_file) next; -}; - struct pkg_plist { - int rev; + char * rev; char *cwd; char *srcdir; char *name; - char *orgin; + char *origin; char *display; char *mtree_file; char *text; /* The entire plist */ struct pkg_file *pf_curr; + struct pkg_dep *pd_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. */ TAILQ_HEAD(pf_head, pkg_file) pf_head; /* pkg_file list. */ + TAILQ_HEAD(pd_head, pkg_dep) pd_head; /* pkg_dep list. */ }; void @@ -77,22 +72,6 @@ return (pl); } -struct pkg_file * -pkg_file_new(char *path, char *md5, char *owner, char *group) -{ - struct pkg_file *pf; - - pf = calloc(1, sizeof(*pf)); - if (pf != NULL) { - pf->path = path; - pf->md5 = md5; - pf->owner = owner; - pf->group = group; - } - - return (pf); -} - struct pkg_plist * pkg_plist_parse_contents_from_text(const char *text) { @@ -147,11 +126,14 @@ } /* Parse a command sequence and add an entry based on the findings. */ + +/* TODO: Add richer return values for parse errors. */ int pkg_plist_parse_line(struct pkg_plist *pl, char *line, struct parse_state *st) { int s; + size_t line_len; char *command; char *argument; char *sep; @@ -161,6 +143,7 @@ return (-1); s = 0; + line_len = strlen(line); if (*line == '@') { sep = strchr(line, ' '); if (sep == NULL) @@ -172,10 +155,9 @@ strcmp(command, PLIST_CMD_CD) == 0) { pl->cwd = argument; st->last_elem = PLIST_CWD; - } - else if (strcmp(command, PLIST_CMD_SRCDIR) == 0) { + } else if (strcmp(command, PLIST_CMD_SRCDIR) == 0) { pl->srcdir = argument; - return (0); + st->last_elem = PLIST_SRCDIR; } #if 0 else if (strcmp(command, PLIST_CMD_EXEC) == 0) @@ -186,15 +168,62 @@ ent = pl_entry_new(PLIST_MODE, argument, NULL); else if (strcmp(command, PLIST_CMD_OPTION) == 0) ent = pl_entry_new(PLIST_OPTION, argument, NULL); - else if (strcmp(command, PLIST_CMD_OWNER) == 0) - ent = pl_entry_new(PLIST_OWNER, argument, NULL); - else if (strcmp(command, PLIST_CMD_GROUP) == 0) - ent = pl_entry_new(PLIST_GROUP, argument, NULL); #endif - else if (strcmp(command, PLIST_CMD_COMMENT) == 0) { + else if (strcmp(command, PLIST_CMD_OWNER) == 0) { + if (line_len == strlen(PLIST_CMD_OWNER) + 1) + /* Empty owner line, reset to NULL. */ + st->owner = NULL; + else + st->owner = argument; + + st->last_elem = PLIST_OWNER; + } else if (strcmp(command, PLIST_CMD_GROUP) == 0) { + if (line_len == strlen(PLIST_CMD_OWNER) + 1) + /* Empty group line, reset to NULL. */ + st->owner = NULL; + else + st->owner = argument; + + st->last_elem = PLIST_GROUP; + } else if (strcmp(command, PLIST_CMD_COMMENT) == 0) { /* Lots more stuff needs to go in here... what a terrible file * format... */ - + + /* mmm... should probably pull this out into a different + * function. */ + if (line_len == strlen(PLIST_CMD_COMMENT) + 1) { + /* Empty comment. */ + st->last_elem = PLIST_COMMENT; + return (0); + } + sep = strchr(argument, ':'); + if (sep == NULL) { + /* Still not sure what to do with comments that don't have any + * effect on the package information. For now, just throw + * them out. Maybe later, add a new command that specifies + * comments that should be printed when displaying + * information from the plist. */ + return (0); + } + *sep = '\0'; + if (strcmp(argument, PLIST_COMMENT_PKG_REV) == 0) { + /* TODO: Keeping rev as s string for now. String based + * version comparison is dumb, convert to int. */ + pl->rev = sep + 1; + st->last_elem = PLIST_COMMENT; + } else if (strcmp(argument, PLIST_COMMENT_ORIGIN) == 0) { + pl->origin = sep + 1; + st->last_elem = PLIST_COMMENT; + } else if (strcmp(argument, PLIST_COMMENT_DEPORIGIN) == 0) { + if (st->last_elem != PLIST_PKGDEP) + return (1); + /* add the the dependency list. */ + } else if (strcmp(argument, PLIST_COMMENT_MD5) == 0) { + if (st->last_elem != PLIST_FILE) + return (1); + pf = pkg_plist_pkg_file_list_last(pl); + pkg_file_set_md5(pf, sep + 1); + } } #if 0 else if (strcmp(command, PLIST_CMD_NOINST) == 0) { @@ -208,6 +237,7 @@ #endif else if (strcmp(command, PLIST_CMD_NAME) == 0) { pl->name = argument; + st->last_elem = PLIST_NAME; } #if 0 else if (strcmp(command, PLIST_CMD_DIRRM) == 0) @@ -215,9 +245,11 @@ #endif else if (strcmp(command, PLIST_CMD_MTREE) == 0) { pl->mtree_file = argument; + st->last_elem = PLIST_MTREE; } else if (strcmp(command, PLIST_CMD_DISPLAY) == 0) { pl->display = argument; + st->last_elem = PLIST_DISPLAY; } #if 0 else { @@ -227,7 +259,7 @@ } #endif } else { - pf = pkg_file_new(line, NULL, NULL, NULL); + pf = pkg_file_new(line, NULL, st->owner, st->group); pkg_plist_pkg_file_list_append(pl, pf); st->last_elem = PLIST_FILE; } @@ -254,33 +286,19 @@ } char * -pkg_plist_orgin(struct pkg_plist *pl) +pkg_plist_origin(struct pkg_plist *pl) { if (pl == NULL) return (NULL); - return (pl->orgin); + return (pl->origin); } -/* Will be available. */ -char * -pkg_file_path(struct pkg_file *pf) -{ - if (pf == NULL) - return (NULL); +/* pkg_file list manipulation and access. */ - return (pf->path); -} +/* I should really just write a set of generic routine to handle this + * whole mess. */ -char * -pkg_file_md5(struct pkg_file *pf) -{ - if (pf == NULL) - return (NULL); - - return (pf->md5); -} - /* Temporarily void. */ void pkg_plist_pkg_file_list_reset(struct pkg_plist *pl) @@ -326,6 +344,15 @@ return (TAILQ_FIRST(&pl->pf_head)); } +struct pkg_file * +pkg_plist_pkg_file_list_last(struct pkg_plist *pl) +{ + if (pl == NULL) + return (NULL); + + return (TAILQ_LAST(&pl->pf_head, pf_head)); +} + void pkg_plist_pkg_file_list_append(struct pkg_plist *pl, struct pkg_file *pf) { @@ -335,3 +362,4 @@ TAILQ_INSERT_TAIL(&pl->pf_head, pf, next); } +/* pkg_dep list manipulation and access. */ ==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_plist.h#6 (text+ko) ==== @@ -2,6 +2,7 @@ #define __PKG_PLIST_H__ /* Make these visible to the client. */ + enum plist_elem { PLIST_CWD, PLIST_SRCDIR, @@ -25,6 +26,8 @@ PLIST_UNKNOWN }; +/* Plist commands. */ + #define PLIST_CMD_CWD "cwd" #define PLIST_CMD_CD "cd" #define PLIST_CMD_SRCDIR "srcdir" @@ -45,12 +48,14 @@ #define PLIST_CMD_PKGDEG "pkgdep" #define PLIST_CMD_CONFLICTS "conflicts" -struct parse_state; +/* Meta comments. */ -struct pkg_file; +#define PLIST_COMMENT_PKG_REV "PKG_FORMAT_REVISION" +#define PLIST_COMMENT_ORIGIN "ORIGIN" +#define PLIST_COMMENT_DEPORIGIN "DEPORIGIN" +#define PLIST_COMMENT_MD5 "MD5" -struct pkg_file * -pkg_file_new(char *path, char *md5, char *owner, char *group); +struct parse_state; struct pkg_plist *pkg_plist_parse_contents_from_text(const char *text); int pkg_plist_parse_line(struct pkg_plist *pl, char *line, @@ -61,15 +66,13 @@ char *pkg_plist_name(struct pkg_plist *pl); char *pkg_plist_cwd(struct pkg_plist *pl); -char *pkg_plist_orgin(struct pkg_plist *pl); - -char *pkg_file_path(struct pkg_file *pf); -char *pkg_file_md5(struct pkg_file *pf); +char *pkg_plist_origin(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); -void pkg_plist_pkg_file_list_append(struct pkg_plist *pl, struct pkg_file -*pf); +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); ==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_private.h#6 (text+ko) ==== @@ -9,12 +9,11 @@ #define REQUIRED_BY_FILE "+REQUIRED_BY" struct pkg { - TAILQ_ENTRY(pkg) next; - char *ident; /* User given name for this pkg. */ - char *comment; /* Mmmmm, should be 70 or less, right? */ struct pkg_plist *plist; + + TAILQ_ENTRY(pkg) next; }; #endif ==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_util.c#3 (text+ko) ==== @@ -34,3 +34,10 @@ return (new_path); } + +void +argument_rage_quit(const char *function, const char *message, int ret) +{ + fprintf(stderr, "Bad argument in %s: %s\n", function, message); + exit(ret); +} ==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_util.h#3 (text+ko) ==== @@ -6,4 +6,7 @@ int subdir_sel(struct dirent *ent); char *path_strdup(const char *name); +void argument_rage_quit(const char *function, const char *message, + int ret); + #endif ==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkgdb.c#12 (text+ko) ==== ==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkgdb.h#7 (text+ko) ==== ==== //depot/projects/soc2009/dforsyth_libpkg/pkg_info/Makefile#3 (text+ko) ==== ==== //depot/projects/soc2009/dforsyth_libpkg/pkg_info/main.c#6 (text+ko) ==== @@ -100,7 +100,7 @@ void print_pkg_information(struct pkg *p) { - char *file_name; + struct pkg_file *pf; /* Just print the basic PKGNAME COMMENT scheme right now. Other * information isn't collected by the library yet. */ @@ -111,11 +111,11 @@ /* Testing plist interaction. */ printf("%s:\n", pkg_name(p)); printf("\tcwd: %s\n", pkg_cwd(p)); - printf("\torgin: %s\n", pkg_orgin(p)); + printf("\torigin: %s\n", pkg_origin(p)); printf("\tplist:\n"); pkg_file_list_init(p); - while ((file_name = pkg_file_list_next(p)) != NULL) { - printf("\t\t%s\n", file_name); + while ((pf = pkg_file_list_next(p)) != NULL) { + printf("\t\t%s\n\t\t\tMD5: %s\n", pkg_file_path(pf), pkg_file_md5(pf)); } } } ==== //depot/projects/soc2009/dforsyth_libpkg/pkg_info/pkg_info.h#2 (text+ko) ====