PERFORCE change 166431 for review
David Forsythe
dforsyth at FreeBSD.org
Thu Jul 23 06:53:05 UTC 2009
http://perforce.freebsd.org/chv.cgi?CH=166431
Change 166431 by dforsyth at squirrel on 2009/07/23 06:52:15
Fix build, start parse rewrite (soon to be moved).
Affected files ...
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/Makefile#13 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg.c#38 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_command.c#1 add
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_command.h#1 add
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_plist.c#29 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_plist.h#25 edit
.. //depot/projects/soc2009/dforsyth_libpkg/pkg_info/Makefile#5 edit
Differences ...
==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/Makefile#13 (text+ko) ====
@@ -2,7 +2,7 @@
INCS= pkg.h
WARNS= 6
SRCS= pkg_db.c pkg_db_hierdb.c pkg.c pkg_util.c pkg_file.c \
- pkg_depend.c pkg_conflict.c pkg_plist.c
+ pkg_depend.c pkg_conflict.c pkg_command.c pkg_plist.c
NO_MAN= yes
.include <bsd.lib.mk>
==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg.c#38 (text+ko) ====
@@ -82,7 +82,7 @@
p->dirty = 0;
/* Until plist allocation is done properly, we can't free this in
* here. */
- pkg_plist_reset(p->pl);
+ pkg_plist_delete(p->pl);
p->pl = NULL;
}
@@ -199,13 +199,19 @@
return (p->description);
}
-/* Retrieve the contents text for this package. */
+/* Retrieve the contents text for this package. Dumps in plist in current
+ * FreeBSD format. */
const char *
pkg_contents(struct pkg *p)
{
if (p == NULL)
arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
+
+ if (pkg_plist_parsed(p->pl) && pkg_plist_dirty(p->pl)) {
+ free(p->contents);
+ p->contents = pkg_plist_dump_to_text(p->pl);
+ }
return (p->contents);
}
@@ -307,8 +313,21 @@
int
pkg_clone(struct pkg *psrc, struct pkg *pdest)
{
- /* Write this. */
- return 0;
+ int status;
+
+ if (psrc == NULL)
+ arg_rage_quit(__func__, "Not a valid package (src).",
+ RAGE_AT_CLIENT);
+ if (pdest == NULL)
+ arg_rage_quit(__func__, "Not a valid package (dest).",
+ RAGE_AT_CLIENT);
+
+ status = PKG_OK;
+ status |= pkg_set_ident(pdest, pkg_ident(psrc));
+
+ /* Write the rest of this. Need array dup'ing functions. */
+
+ return (status);
}
/* Retrieve a list of file in this package. Return a list of strings
==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_plist.c#29 (text+ko) ====
@@ -9,6 +9,7 @@
#include <limits.h>
#include "pkg_util.h"
+#include "pkg_command.h"
#include "pkg_conflict.h"
#include "pkg_depend.h"
#include "pkg_file.h"
@@ -19,7 +20,9 @@
/* TODO: Create plist setter functions for building packages. */
struct parse_state {
- enum plist_elem last_elem;
+ int ignore_next_file;
+ int last_elem;
+ int last_line;
struct pkg_conflict *last_conflict;
struct pkg_depend *last_depend;
struct pkg_file *last_file;
@@ -35,7 +38,13 @@
if (st == NULL)
return;
+ st->ignore_next_file = 0;
st->last_elem = PLIST_UNKNOWN;
+ st->last_line = PLIST_UNKNOWN;
+ st->last_conflict = NULL;
+ st->last_depend = NULL;
+ st->last_file = NULL;
+ st->cwd = NULL;
st->owner = NULL;
st->group = NULL;
st->mode = NULL;
@@ -97,6 +106,24 @@
return (pl->parsed);
}
+int
+pkg_plist_dirty(struct pkg_plist *pl)
+{
+ if (pl == NULL)
+ arg_rage_quit(__func__, "Not a valid plist.", RAGE_AT_LIBPKG);
+
+ return (pl->dirty);
+}
+
+char *
+pkg_plist_dump_to_text(struct pkg_plist *pl)
+{
+ if (pl == NULL)
+ arg_rage_quit(__func__, "Not a valid plist.", RAGE_AT_LIBPKG);
+
+ return (NULL);
+}
+
void
pkg_plist_reset(struct pkg_plist *pl)
{
@@ -379,6 +406,253 @@
return (s);
}
+#if 0
+int __pkg_plist_parse_line(struct pkg_plist *pl, char *line,
+ struct parse_state *st)
+{
+ int status;
+ size_t line_len;
+ char *command;
+ char *argument;
+ char *buff;
+ char *sep;
+
+ struct pkg_conflict *pc;
+ struct pkg_depend *pd;
+ struct pkg_command *pe;
+ struct pkg_file *pf;
+
+ if (pl == NULL)
+ arg_rage_quit(__func__, "Not a valid plist.", RAGE_AT_LIBPKG);
+ if (line == NULL)
+ arg_rage_quit(__func__, "Null line argument.", RAGE_AT_LIBPKG);
+ if (st == NULL)
+ arg_rage_quit(__func__, "Not a valid parse state.",
+ RAGE_AT_LIBPKG);
+
+ status = OK;
+
+ line_len = strlen(line);
+ if (line_len == 0)
+ return (status);
+
+ if (line[0] == '@') {
+ /* Command. */
+ sep = strchr(line, ' ');
+ if (sep == NULL)
+ sep = strchr(line, '\0');
+ *sep = '\0';
+ command = line + 1;
+ argument = sep + 1;
+ if (strcmp(command, PLIST_CMD_CWD) == 0 ||
+ strcmp(command, PLIST_CMD_CD) == 0) {
+ if (line_len - 1 <= strlen(PLIST_CMD_CWD))
+ st->cwd = NULL;
+ else
+ st->cwd = argument;
+ st->last_elem = PLIST_CWD;
+ } else if (strcmp(command, PLIST_CMD_SRCDIR) == 0) {
+ if (line_len - 1 == strlen(PLIST_CMD_SRCDIR)) {
+ /* For now, just spit errors into stderr. */
+ fprintf(stderr, "pkg_plist: Bad line \"%s\". Needs \
+ argument\n", line);
+ status |= NOT_OK;
+ st->last_line = PLIST_BAD_LINE;
+ } else if (pl->srcdir != NULL) {
+ fprintf(stderr, "pkg_plist: SRCDIR is already set in this \
+ plist (\"%s\").\n", pl->srcdir);
+ status |= NOT_OK;
+ st->last_line = PLIST_BAD_LINE;
+ } else {
+ pl->srcdir = argument;
+ st->last_line = PLIST_SRCDIR;
+ }
+ } else if (strcmp(command, PLIST_CMD_EXEC) == 0) {
+ if (line_len - 1 == strlen(PLIST_CMD_EXEC)) {
+ fprintf(stderr, "pkg_plist: Bad line \"%s\". Empty exec \
+ command.\n", line);
+ status |= NOT_OK;
+ st->last_line = PLIST_BAD_LINE;
+ } else {
+ pe = pkg_command_new();
+ if (pe == NULL) {
+ fprintf(stderr, "pkg_plist: Couldn't allocate.");
+ status |= NOT_OK;
+ status |= MEMORY_ERR;
+ return (status);
+ }
+ status |= pkg_command_set_type(pe, PLIST_EXEC);
+ status |= pkg_command_set_argument(pe, argument);
+ st->last_line = PLIST_EXEC;
+ status |= pkg_plist_add_install(pl, pe);
+ /* Check status and free is there's a mem err? */
+ }
+ } else if (strcmp(command, PLIST_CMD_UNEXEC) == 0) {
+ if (line_len - 1 == strlen(PLIST_CMD_UNEXEC)) {
+ fprintf(stderr, "pkg_plist: Bad line \"%s\". Empty unexec \
+ command.\n", line);
+ status |= NOT_OK;
+ } else {
+ pe = pkg_command_new();
+ if (pe == NULL) {
+ fprintf(stderr, "pkg_plist: Couldn't allocate.");
+ status |= NOT_OK;
+ status |= MEMORY_ERR;
+ return (status);
+ }
+ status |= pkg_command_set_type(pe, PLIST_UNEXEC);
+ status |= pkg_command_set_argument(pe, argument);
+ st->last_line = PLIST_EXEC;
+ status |= pkg_plist_add_deinstall(pl, pe);
+ }
+ } else if (strcmp(command, PLIST_CMD_MODE) == 0) {
+ if (line_len - 1 == strlen(PLIST_CMD_MODE)) /* reset. */
+ st->mode = NULL;
+ else
+ st->mode = argument;
+ } else if (strcmp(command, PLIST_CMD_OPTION) == 0) {
+ if (line_len - 1 == strlen(PLIST_CMD_OPTION)) {
+ fprintf(stderr, "pkg_plist: Bad line \"%s\". Empty option \
+ command.\n", line);
+ status |= NOT_OK;
+ st->last_line = PLIST_BAD_LINE;
+ } else {
+ if (strcmp(argument, PLIST_OPTION_EXTRACT_IN_PLACE) == 0)
+ pl->extract_in_place = 1;
+ else if (strcmp(argument, PLIST_OPTION_PRESERVE) == 0)
+ pl->preserve = 1;
+ else if (strcmp(argument, PLIST_OPTION_COMPLETE) == 0)
+ pl->complete = 1;
+ else {
+ fprintf(stderr, "pkg_plist: Bad line \"%s\". Illegal \
+ option.\n", line);
+ status |= NOT_OK;
+ st->last_line = PLIST_BAD_LINE;
+ }
+ }
+ } else if (strcmp(command, PLIST_CMD_OWNER) == 0) {
+ if (line_len - 1 == strlen(PLIST_CMD_OPTION))
+ st->owner = NULL;
+ else
+ st->owner = argument;
+ } else if (strcmp(command, PLIST_CMD_GROUP) == 0) {
+ if (line_len - 1 == strlen(PLIST_CMD_GROUP))
+ st->group = NULL;
+ else
+ st->group = argument;
+ } else if (strcmp(command, PLIST_CMD_COMMENT) == 0) {
+ /* Comment block. */
+ } else if (strcmp(command, PLIST_CMD_NOINST) == 0) {
+ if (line_len - 1 == strlen(PLIST_CMD_NOINST)) {
+ fprintf(stderr, "pkg_plist: Bad line \"%s\". Empty \
+ noinst command.\n", line);
+ status |= NOT_OK;
+ st->last_line = PLIST_BAD_LINE;
+ } else {
+ sep = strchr(argument, ' ');
+ if (sep == NULL || strlen(sep + 1) == 0) {
+ fprintf(stderr, "pkg_plist: Bad line \"%s\". Bad \
+ noinst command.", line);
+ status |= NOT_OK;
+ st->last_line = PLIST_BAD_LINE;
+ } else {
+ *sep = '\0';
+ /* Not really sure what to do here. Ask Tim. */
+ }
+ }
+ } else if (strcmp(command, PLIST_CMD_IGNORE) == 0) {
+ st->ignore_next_file = 1;
+ } else if (strcmp(command, PLIST_CMD_IGNORE_INST) == 0) {
+ /* ... */
+ } else if (strcmp(command, PLIST_CMD_NAME) == 0) {
+ if (line_len - 1 == strlen(PLIST_CMD_NAME)) {
+ fprintf(stderr, "pkg_plist: Bad line \"%s\". Empty name \
+ command.\n", line);
+ status |= NOT_OK;
+ st->last_line = PLIST_BAD_LINE;
+ } else {
+ pl->name = argument;
+ st->last_line = PLIST_NAME;
+ }
+ } else if (strcmp(command, PLIST_CMD_DIRRM) == 0) {
+ if (line_len - 1 == strlen(PLIST_CMD_DIRRM)) {
+ fprintf(stderr, "pkg_plist: Bad line \"%s\". Empty dirrm \
+ command.\n", line);
+ status |= NOT_OK;
+ st->last_line = PLIST_BAD_LINE;
+ } else {
+ pe = pkg_command_new();
+ if (pe == NULL) {
+ fprintf(stderr, "pkg_plist: Couldn't allocate.\n");
+ status |= NOT_OK;
+ status |= MEMORY_ERR;
+ return (status);
+ }
+ status |= pkg_command_set_type(pe, PLIST_DIRRM);
+ status |= pkg_command_set_argument(pe, argument);
+ st->last_line = PLIST_DIRRM;
+ }
+ } else if (strcmp(command, PLIST_CMD_DIRRMTRY) == 0) {
+ if (line_len - 1 == strlen(PLIST_CMD_DIRRMTRY)) {
+ fprintf(stderr, "pkg_plist: Bad line \"%s\". Empty \
+ dirrmtry command.\n", line);
+ status |= NOT_OK;
+ st->last_line = PLIST_BAD_LINE;
+ } else {
+ pe = pkg_command_new();
+ if (pe == NULL) {
+ fprintf(stderr, "pkg_plist: Couldn't allocate.\n");
+ status |= NOT_OK;
+ status |= MEMORY_ERR;
+ return (status);
+ }
+ status |= pkg_command_set_type(pe, PLIST_UNEXEC);
+ status |= pkg_command_set_argument(pe, argument);
+ st->last_line = PLIST_UNEXEC;
+ }
+ } else if (strcmp(command, PLIST_CMD_MTREE) == 0) {
+ if (line_len - 1 == strlen(PLIST_CMD_MTREE)) {
+ fprintf(stderr, "pkg_plist: Bad line \"%s\". Empty mtree \
+ command.\n", line);
+ status |= NOT_OK;
+ st->last_line = PLIST_BAD_LINE;
+ } else if (pl->mtree_file != NULL) {
+ fprintf(stderr, "pkg_plist: Mtree file already \
+ specified.\n");
+ status |= NOT_OK;
+ st->last_line = PLIST_BAD_LINE;
+ } else {
+ pl->mtree_file = argument;
+ st->last_line = PLIST_MTREE;
+ }
+ } else if (strcmp(command, PLIST_CMD_DISPLAY) == 0) {
+ if (line_len - 1 == strlen(PLIST_CMD_DISPLAY)) {
+ fprintf(stderr, "pkg_plist: Bad line \"%s\". Empty \
+ display command.\n", line);
+ status |= NOT_OK;
+ st->last_line = PLIST_BAD_LINE;
+ } else if (pl->display_file != NULL) {
+ fprintf(stderr, "pkg_plist: Bad line \"%s\". Display file \
+ already specified.\n", line);
+ status |= NOT_OK;
+ st->last_line = PLIST_BAD_LINE;
+ } else {
+ pl->display_file = argument;
+ st->last_line = PLIST_DISPLAY;
+ }
+ }
+ } else {
+ /* File. */
+ pf = pkg_file_new();
+ }
+
+ /* line_len checks are ineffective against whitespace? Fix. */
+ /* Create an error function, give line number of bad line. */
+
+ return (status);
+}
+#endif
+
const char *
pkg_plist_name(struct pkg_plist *pl)
{
@@ -624,14 +898,29 @@
}
int
-pkg_plist_add_install(struct pkg_plist *pl, const char *cmd)
+pkg_plist_add_install(struct pkg_plist *pl, struct pkg_command *pe)
{
if (pl == NULL)
arg_rage_quit(__func__, "Not a valid plist.", RAGE_AT_LIBPKG);
- if (cmd == NULL)
+ if (pe == NULL)
arg_rage_quit(__func__, "Not a valid install command.",
RAGE_AT_LIBPKG);
+ return (OK);
+}
+
+int
+pkg_plist_add_deinstall(struct pkg_plist *pl, struct pkg_command *pe)
+{
+ if (pl == NULL)
+ arg_rage_quit(__func__, "Not a valid plist.", RAGE_AT_LIBPKG);
+ if (pe == NULL)
+ arg_rage_quit(__func__, "Not a valid deinstall command.",
+ RAGE_AT_LIBPKG);
+
+ return (OK);
+}
+
int
pkg_plist_set_name(struct pkg_plist *pl, const char *name)
{
==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_plist.h#25 (text+ko) ====
@@ -18,13 +18,13 @@
PLIST_IGNORE_INST,
PLIST_NAME,
PLIST_DIRRM,
- PLIST_DIRRMTRY,
PLIST_MTREE,
PLIST_DISPLAY,
PLIST_PKGDEP,
PLIST_CONFLICTS,
PLIST_FILE,
- PLIST_UNKNOWN
+ PLIST_UNKNOWN,
+ PLIST_BAD_LINE
};
/* Plist commands. */
@@ -100,6 +100,7 @@
char **pkg_deinstall_list;
short parsed;
+ short dirty;
};
struct pkg_plist *pkg_plist_new(void);
@@ -107,7 +108,10 @@
void pkg_plist_reset(struct pkg_plist *pl);
int pkg_plist_parsed(struct pkg_plist *pl);
+int pkg_plist_dirty(struct pkg_plist *pl);
+char *pkg_plist_dump_to_text(struct pkg_plist *pl);
+
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,
@@ -150,4 +154,8 @@
int pkg_plist_remove_conflict(struct pkg_plist *pl, const char *name);
const char *const *pkg_plist_conflicts(struct pkg_plist *pl);
+/* pkg_command */
+int pkg_plist_add_install(struct pkg_plist *pl, struct pkg_command *pe);
+int pkg_plist_add_deinstall(struct pkg_plist *pl, struct pkg_command *pe);
+
#endif
==== //depot/projects/soc2009/dforsyth_libpkg/pkg_info/Makefile#5 (text+ko) ====
@@ -1,7 +1,7 @@
PROG= pkg_info
SRCS= main.c
WARNS?= 6
-CFLAGS+= -I../libpkg
+CFLAGS+= -I${.CURDIR}/../libpkg
LDADD= -L../libpkg -lpkg
NO_MAN= true
More information about the p4-projects
mailing list