Date: Sun, 31 May 2009 22:05:50 GMT From: David Forsythe <dforsyth@FreeBSD.org> To: Perforce Change Reviews <perforce@FreeBSD.org> Subject: PERFORCE change 163212 for review Message-ID: <200905312205.n4VM5opZ051537@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=163212 Change 163212 by dforsyth@squirrel on 2009/05/31 22:05:41 Added some action to pkg_info. Affected files ... .. //depot/projects/soc2009/dforsyth_libpkg/Makefile#1 add .. //depot/projects/soc2009/dforsyth_libpkg/info/Makefile#1 add .. //depot/projects/soc2009/dforsyth_libpkg/info/main.c#2 edit .. //depot/projects/soc2009/dforsyth_libpkg/libpkg/Makefile#1 add .. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg.c#2 edit .. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg.h#2 edit .. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_info.c#2 edit .. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_info.h#2 edit .. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_util.c#2 edit .. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_util.h#2 edit .. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkgdb.c#2 edit .. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkgdb.h#2 edit Differences ... ==== //depot/projects/soc2009/dforsyth_libpkg/info/main.c#2 (text+ko) ==== @@ -4,38 +4,99 @@ #include "pkg.h" +#define PKG_DBDIR_DEFAULT "/var/db/pkg" /* Move this. */ + short opt_all = 0; +short opt_glob = 0; +short opt_show_all_info = 0; +short opt_show_index = 0; short opt_show_comment = 0; +char *info_targets; static char opts[] = "a"; static struct option lopts[] = { {"all", no_argument, NULL, 'a'}, + {NULL, 0, NULL, 0}, // <-- something that pkg_add in 7.2 forgot... }; /* Mock pkg_info for testing, */ +void perform_on_db(struct pkgdb *db); +void print_pkg_information(struct pkg *p); +void parse_opts(int argc, char **argv); +void usage(int exit_val); + int main (int argc, char **argv) { - int s; const char *db_root; struct pkgdb *db; if (argc == 1) { opt_all = 1; - opt_show_comment = 1; } - db_root = getenv("PKG_DBDIR"); - if (db_root == NULL) { - printf("..."); - db_root = "/var/db/pkg"; -} + parse_opts(argc, argv); + + db_root = getenv("PKG_DBDIR"); /* User set it */ + if (db_root == NULL) + db_root = PKG_DBDIR_DEFAULT; /* Default */ + db = pkgdb_new_hierdb(db_root); if (db == NULL) { - fprintf(stderr, "Could not attach to database \"%s\"\n"); + fprintf(stderr, "Could not attach to database \"%s\"\n", db_root); } + + perform_on_db(db); pkgdb_free_hierdb(db); return (0); } + +void +usage(int exit_val) +{ + printf("If you don't know how to use me, then you shouldn't be...\n"); + exit(exit_val); +} + +void +parse_opts(int argc, char **argv) +{ + /* Ehh... Worthless to write this at this point. */ + opt_all = 1; +} + +void +perform_on_db(struct pkgdb *db) +{ + int count; + char *target; + struct pkg *p; + + /* There will be cases where an init is useless, but since I haven't + * written that much yet, init regardless. */ + + count = pkgdb_init_hierdb(db); + if (count < 0) + exit(1); + + while ((p = pkgdb_next_pkg(db)) != NULL) { + if (!opt_all) { /* Wont happen at this point. */ + /* Do some matching magic that I haven't written yet. */ + print_pkg_information(p); + } else { + print_pkg_information(p); + } + } +} + +void +print_pkg_information(struct pkg *p) +{ + /* Just print the basic PKGNAME COMMENT scheme right now. Other + * information isn't collected by the library yet. */ + if (!opt_show_all_info) + printf("%s %s\n", pkg_ident(p), pkg_comment(p)); +} + ==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg.c#2 (text+ko) ==== @@ -2,8 +2,6 @@ #include <stdlib.h> #include <string.h> -#include <sys/queue.h> - #include "pkg_util.h" #include "pkgdb.h" #include "pkg.h" @@ -64,14 +62,9 @@ /* Something bad happened... I should probably let people know * about it... */ } - return (p); } - - - -/* Read in contents of comment file. */ char * pkg_ident(struct pkg *p) { @@ -90,6 +83,11 @@ return (p->comment); } + +/* TODO: Make an explicit note in the manual for libpkg that pkg_free + * should NOT be called called on pkgs that are not explicitly created by + * the user. */ + void pkg_free(struct pkg *p) { ==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg.h#2 (text+ko) ==== @@ -1,18 +1,13 @@ #ifndef __PKG_H__ #define __PKG_H__ -#include <sys/queue.h> -#include <dirent.h> - /* pkg */ struct pkg; 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); +struct pkg *pkg_set_comment(struct pkg *p, const char *comment); char *pkg_ident(struct pkg *p); char *pkg_name(struct pkg *p); ==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_info.c#2 (text+ko) ==== @@ -28,3 +28,8 @@ struct pkg_file *files; }; +char * +pkg_info_read_file_to_string(const char *path, const char *filename) +{ + return (NULL); +} ==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_info.h#2 (text+ko) ==== @@ -1,4 +1,11 @@ #ifndef __PKG_INFO_H__ #define __PKG_INFO_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" + #endif ==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_util.c#2 (text+ko) ==== @@ -5,6 +5,8 @@ #include <sys/types.h> #include <dirent.h> +#include "pkg_util.h" + int subdir_sel(struct dirent *ent) { ==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_util.h#2 (text+ko) ==== ==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkgdb.c#2 (text+ko) ==== @@ -15,6 +15,9 @@ /* Everything in here is written with the current database setup in mind. * I'll add some stuff for flat databases later. */ +/* TODO: Move _hierdb functions into a seperate file, add callback + * functionality to pkgdb. */ + /* Allocate and create a new hierdb. */ struct pkgdb * @@ -135,10 +138,16 @@ struct pkg * pkgdb_query_pkg(struct pkgdb *db, const char *ident) { - Need to add callbacks before do this. + Need to add callbacks before I do this. } */ +struct pkg * +pkgdb_query_pkg_hierdb(struct pkgdb *db, const char *ident) +{ + return (NULL); +} + char * pkgdb_pkg_path(struct pkgdb *db, struct pkg *p) { ==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkgdb.h#2 (text+ko) ==== @@ -23,15 +23,8 @@ struct pkg *p_curr; TAILQ_HEAD(pkg_head, pkg) p_head; + /* Callbacks */ - /* tuuuummmmbbbllleeewwwweeeedddddd*/ }; -#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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200905312205.n4VM5opZ051537>
