From owner-p4-projects@FreeBSD.ORG Mon Jun 8 04:21:12 2009 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id BE9D31065670; Mon, 8 Jun 2009 04:21:11 +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 7408D106566C for ; Mon, 8 Jun 2009 04:21:11 +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 608638FC0C for ; Mon, 8 Jun 2009 04:21:11 +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 n584LB43056737 for ; Mon, 8 Jun 2009 04:21:11 GMT (envelope-from dforsyth@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id n584LBx1056735 for perforce@freebsd.org; Mon, 8 Jun 2009 04:21:11 GMT (envelope-from dforsyth@FreeBSD.org) Date: Mon, 8 Jun 2009 04:21:11 GMT Message-Id: <200906080421.n584LBx1056735@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 163756 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: Mon, 08 Jun 2009 04:21:12 -0000 http://perforce.freebsd.org/chv.cgi?CH=163756 Change 163756 by dforsyth@squirrel on 2009/06/08 04:20:51 Started to divide up information in plist parse. Affected files ... .. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg.c#10 edit .. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg.h#10 edit .. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_plist.c#5 edit .. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_plist.h#5 edit .. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkgdb.c#10 edit Differences ... ==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg.c#10 (text+ko) ==== @@ -75,12 +75,8 @@ if (p == NULL) return (NULL); - if (is_it_empty(pl)) - printf("its empty in set_pkg_plist, before set\n"); + p->plist = pl; - p->plist = pl; - if (is_it_empty(pl)) - printf("its empty in set_pkg_plist, after set\n"); return (p); } @@ -142,29 +138,23 @@ if (p == NULL) return; - if (is_it_empty(p->plist)) - printf("its empty when pkg requests init\n"); - - pkg_plist_file_list_init(p->plist); - if (is_it_empty(p->plist)) - printf("its empty when pkg requests init, after\n"); + pkg_plist_pkg_file_list_reset(p->plist); } /* Temporarily char. */ char * pkg_file_list_next(struct pkg *p) { - struct pl_entry *ent; + struct pkg_file *pf; char *file_name; if (p == NULL) return (NULL); - - if (is_it_empty(p->plist)) - printf("its empty when pkg requests next\n"); - ent = pkg_plist_file_list_next(p->plist); - file_name = pl_entry_info(ent); + pf = pkg_plist_pkg_file_list_next(p->plist); + if (pf == NULL) + return (NULL); + file_name = pkg_file_path(pf); return (file_name); } ==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg.h#10 (text+ko) ==== @@ -49,6 +49,8 @@ struct pkg *pkgdb_next_pkg(struct pkgdb *db); +struct pkg *pkgdb_curr_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); ==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_plist.c#5 (text+ko) ==== @@ -13,12 +13,19 @@ #include "pkgdb.h" #include "pkg.h" -struct pl_entry { - enum plist_elem type; - char *info; - char *option; - - TAILQ_ENTRY(pl_entry) next; +struct parse_state { + enum plist_elem last_elem; + char *owner; + char *group; +}; + +struct pkg_file { + char *path; + char *md5; + char *owner; + char *group; + + TAILQ_ENTRY(pkg_file) next; }; struct pkg_plist { @@ -32,15 +39,26 @@ char *text; /* The entire plist */ - struct pl_entry *file_curr; + struct pkg_file *pf_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(file_head, pl_entry) file_head; /* File list. */ + TAILQ_HEAD(pf_head, pkg_file) pf_head; /* pkg_file list. */ }; +void +set_parse_state_default(struct parse_state *st) +{ + if (st == NULL) + return; + + st->last_elem = PLIST_UNKNOWN; + st->owner = NULL; + st->group = NULL; +} + struct pkg_plist * pkg_plist_new() { @@ -59,29 +77,31 @@ return (pl); } -struct pl_entry * -pl_entry_new(enum plist_elem elem, char *info, char *option) +struct pkg_file * +pkg_file_new(char *path, char *md5, char *owner, char *group) { - struct pl_entry *ent; + struct pkg_file *pf; - ent = calloc(1, sizeof(*ent)); - if (ent != NULL) { - ent->type = elem; - ent->info = info; - ent->option = option; + pf = calloc(1, sizeof(*pf)); + if (pf != NULL) { + pf->path = path; + pf->md5 = md5; + pf->owner = owner; + pf->group = group; } - return (ent); + return (pf); } struct pkg_plist * pkg_plist_parse_contents_from_text(const char *text) { + int s; char *p; char *textp; char *line; struct pkg_plist *pl; - struct pl_entry *ent; + struct parse_state st; /* This function will parse text and create a pkg_plist */ if (text == NULL) @@ -101,40 +121,46 @@ pl->text = textp; - pkg_plist_plist_init(pl); + pkg_plist_pkg_file_list_init(pl); + set_parse_state_default(&st); for (p = textp; *p != '\0'; p++) { if (*p == '\n') { line = textp; line[p - textp] = '\0'; - ent = pkg_plist_parse_line(pl, line); - + s = pkg_plist_parse_line(pl, line, &st); /* For now, just plop everything onto the file list. */ /* TODO: have the append function sort entry types to the * correct list. */ - if (ent != NULL) - pkg_plist_plist_append(pl, ent); + /* Move the actual list assignment out of here to make it + * easier to deal with different types of data. */ + + /* Consider a dirty flag for these lists? */ + if (s != 0) { + /* bad parse. */ + } textp = p + 1; } } - if (is_it_empty(pl)) - printf("its empty in the parse.\n"); - return (pl); } -/* Parse a command sequence and and entry based on the findings. */ -struct pl_entry * -pkg_plist_parse_line(struct pkg_plist *pl, char *line) { +/* Parse a command sequence and add an entry based on the findings. */ +int +pkg_plist_parse_line(struct pkg_plist *pl, char *line, + struct parse_state *st) +{ + int s; char *command; char *argument; char *sep; - struct pl_entry *ent; + struct pkg_file *pf; if (line == NULL) - return (NULL); + return (-1); + s = 0; if (*line == '@') { sep = strchr(line, ' '); if (sep == NULL) @@ -145,12 +171,13 @@ if (strcmp(command, PLIST_CMD_CWD) == 0 || strcmp(command, PLIST_CMD_CD) == 0) { pl->cwd = argument; - return (NULL); + st->last_elem = PLIST_CWD; } else if (strcmp(command, PLIST_CMD_SRCDIR) == 0) { pl->srcdir = argument; - return (NULL); + return (0); } +#if 0 else if (strcmp(command, PLIST_CMD_EXEC) == 0) ent = pl_entry_new(PLIST_EXEC, argument, NULL); else if (strcmp(command, PLIST_CMD_UNEXEC) == 0) @@ -163,11 +190,13 @@ 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) { /* Lots more stuff needs to go in here... what a terrible file * format... */ - ent = pl_entry_new(PLIST_COMMENT, argument, NULL); + } +#if 0 else if (strcmp(command, PLIST_CMD_NOINST) == 0) { if ((sep = strchr(argument, ' ')) != NULL) *sep = '\0'; @@ -176,61 +205,36 @@ ent = pl_entry_new(PLIST_IGNORE, argument, NULL); else if (strcmp(command, PLIST_CMD_IGNORE_INST) == 0) ent = pl_entry_new(PLIST_IGNORE_INST, argument, NULL); +#endif else if (strcmp(command, PLIST_CMD_NAME) == 0) { pl->name = argument; - return (NULL); } +#if 0 else if (strcmp(command, PLIST_CMD_DIRRM) == 0) ent = pl_entry_new(PLIST_DIRRM, argument, NULL); +#endif else if (strcmp(command, PLIST_CMD_MTREE) == 0) { pl->mtree_file = argument; - return (NULL); } else if (strcmp(command, PLIST_CMD_DISPLAY) == 0) { pl->display = argument; - return (NULL); } +#if 0 else { /* If we cant identify the command, set it unknown and gather * whatever information we can. */ ent = pl_entry_new(PLIST_UNKNOWN, argument, NULL); } +#endif } else { - ent = pl_entry_new(PLIST_FILE, argument, NULL); + pf = pkg_file_new(line, NULL, NULL, NULL); + pkg_plist_pkg_file_list_append(pl, pf); + st->last_elem = PLIST_FILE; } - return (ent); + return (s); } -/* Temporarily void. */ -void -pkg_plist_file_list_init(struct pkg_plist *pl) -{ - /* Available to the client. */ - - /* If you init again, it clears the list. So don't. */ - pl->file_curr = NULL; -} - -struct pl_entry * -pkg_plist_file_list_next(struct pkg_plist *pl) -{ - struct pl_entry *ent; - - if (pl == NULL) - return (NULL); - - if (pl->file_curr == NULL) - ent = pkg_plist_plist_first(pl); - else - ent = TAILQ_NEXT(pl->file_curr, next); - - if (ent != NULL) - pl->file_curr = ent; - - return (ent); -} - char * pkg_plist_name(struct pkg_plist *pl) { @@ -258,50 +262,76 @@ return (pl->orgin); } +/* Will be available. */ +char * +pkg_file_path(struct pkg_file *pf) +{ + if (pf == NULL) + return (NULL); + + return (pf->path); +} + char * -pl_entry_info(struct pl_entry *ent) +pkg_file_md5(struct pkg_file *pf) { - if (ent == NULL) + if (pf == NULL) return (NULL); - return (ent->info); + return (pf->md5); +} + +/* 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->pf_curr = NULL; } -/* Don't know if I'll be sticking with this, so... */ +struct pkg_file * +pkg_plist_pkg_file_list_next(struct pkg_plist *pl) +{ + struct pkg_file *pf; + + if (pl == NULL) + return (NULL); + + if (pl->pf_curr == NULL) + pf = pkg_plist_pkg_file_list_first(pl); + else + pf = TAILQ_NEXT(pl->pf_curr, next); + + if (pf != NULL) + pl->pf_curr = pf; + + return (pf); +} void -pkg_plist_plist_init(struct pkg_plist *pl) +pkg_plist_pkg_file_list_init(struct pkg_plist *pl) { if (pl == NULL) return; - TAILQ_INIT(&pl->file_head); + TAILQ_INIT(&pl->pf_head); } -struct pl_entry * -pkg_plist_plist_first(struct pkg_plist *pl) +struct pkg_file * +pkg_plist_pkg_file_list_first(struct pkg_plist *pl) { if (pl == NULL) return (NULL); - return (TAILQ_FIRST(&pl->file_head)); + return (TAILQ_FIRST(&pl->pf_head)); } void -pkg_plist_plist_append(struct pkg_plist *pl, struct pl_entry *ent) +pkg_plist_pkg_file_list_append(struct pkg_plist *pl, struct pkg_file *pf) { - if (pl == NULL || ent == NULL) + if (pl == NULL || pf == NULL) return; - if (ent->type == PLIST_FILE) - TAILQ_INSERT_TAIL(&pl->file_head, ent, next); -} - -int -is_it_empty(struct pkg_plist *pl) -{ - if (TAILQ_EMPTY(&pl->file_head)) - return (1); - - return (0); + + TAILQ_INSERT_TAIL(&pl->pf_head, pf, next); } ==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_plist.h#5 (text+ko) ==== @@ -45,25 +45,32 @@ #define PLIST_CMD_PKGDEG "pkgdep" #define PLIST_CMD_CONFLICTS "conflicts" -struct pl_entry; +struct parse_state; + +struct pkg_file; -struct pl_entry * -pl_entry_new(enum plist_elem elem, char *info, char *option); +struct pkg_file * +pkg_file_new(char *path, char *md5, char *owner, char *group); struct pkg_plist *pkg_plist_parse_contents_from_text(const char *text); -struct pl_entry *pkg_plist_parse_line(struct pkg_plist *pl, char *line); +int pkg_plist_parse_line(struct pkg_plist *pl, char *line, + struct parse_state *st); -void pkg_plist_file_list_init(struct pkg_plist *pl); -struct pl_entry *pkg_plist_file_list_next(struct pkg_plist *pl); +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_orgin(struct pkg_plist *pl); -char *pl_entry_info(struct pl_entry *ent); +char *pkg_file_path(struct pkg_file *pf); +char *pkg_file_md5(struct pkg_file *pf); + +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); -void pkg_plist_plist_init(struct pkg_plist *pl); -struct pl_entry *pkg_plist_plist_first(struct pkg_plist *pl); -void pkg_plist_plist_append(struct pkg_plist *pl, struct pl_entry *ent); +void set_parse_state_default(struct parse_state *st); #endif ==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkgdb.c#10 (text+ko) ==== @@ -208,6 +208,15 @@ return (p); } +struct pkg * +pkgdb_curr_pkg(struct pkgdb *db) +{ + if (db == NULL) + return (NULL); + + return (db->pkg_curr); +} + char * pkgdb_read_file_to_text(struct pkgdb *db, struct pkg *p, const char *filename)