Skip to content

Commit

Permalink
Added show-all-categories
Browse files Browse the repository at this point in the history
  • Loading branch information
imilh committed May 28, 2012
1 parent 29f623f commit 9bfdabe
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
20120528
Added show-all-categories
unlink() before symlink()

20120525
Dynamically read PKG_DBDIR from pkg_admin

Expand Down
3 changes: 2 additions & 1 deletion actions.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $Id: actions.c,v 1.47 2012/04/24 13:23:27 imilh Exp $ */
/* $Id: actions.c,v 1.48 2012/05/28 10:56:27 imilh Exp $ */

/*
* Copyright (c) 2009, 2010, 2011 The NetBSD Foundation, Inc.
Expand Down Expand Up @@ -118,6 +118,7 @@ pkg_download(Plisthead *installhead)

/* if pkg's repo URL is file://, just symlink */
if (strncmp(pkg_url, SCHEME_FILE, strlen(SCHEME_FILE)) == 0) {
(void)unlink(pkg_fs);
if (symlink(&pkg_url[strlen(SCHEME_FILE) + 3], pkg_fs) < 0)
errx(EXIT_FAILURE, MSG_SYMLINK_FAILED, pkg_fs);
printf(MSG_SYMLINKING_PKG, pkg_url);
Expand Down
4 changes: 3 additions & 1 deletion cmd.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $Id: cmd.h,v 1.13 2012/04/17 07:11:38 imilh Exp $ */
/* $Id: cmd.h,v 1.14 2012/05/28 10:56:27 imilh Exp $ */

/*
* Copyright (c) 2009, 2010, 2011 The NetBSD Foundation, Inc.
Expand Down Expand Up @@ -60,6 +60,8 @@ static struct command {
PKG_SHCAT_CMD },
{ "show-pkg-category", "spc", "Show package's category.",
PKG_SHPCAT_CMD },
{ "show-all-categories", "sac", "Show all categories.",
PKG_SHALLCAT_CMD },
{ "keep", "ke", "Mark package as \"non auto-removable\".",
PKG_KEEP_CMD },
{ "unkeep", "uk", "Mark package as \"auto-removable\".",
Expand Down
9 changes: 6 additions & 3 deletions main.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $Id: main.c,v 1.28 2012/05/27 08:24:21 imilh Exp $ */
/* $Id: main.c,v 1.29 2012/05/28 10:56:27 imilh Exp $ */

/*
* Copyright (c) 2009, 2010, 2011 The NetBSD Foundation, Inc.
Expand Down Expand Up @@ -268,7 +268,10 @@ main(int argc, char *argv[])
case PKG_SHPCAT_CMD: /* show package's category */
missing_param(argc, 2, MSG_MISSING_PKGNAME);
show_pkg_category(argv[1]);
break;
break;
case PKG_SHALLCAT_CMD: /* show all categories */
show_all_categories();
break;
case PKG_GINTO_CMD: /* Miod's request */
ginto();
break;
Expand Down Expand Up @@ -325,7 +328,7 @@ usage()

for (i = 0; cmd[i].name != NULL; i++)
if (cmd[i].cmdtype != PKG_GINTO_CMD)
printf("%-17s (%-4s) - %s\n",
printf("%-19s (%-4s) - %s\n",
cmd[i].name, cmd[i].shortcut, cmd[i].descr);

exit(EXIT_FAILURE);
Expand Down
3 changes: 2 additions & 1 deletion messages.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $Id: messages.h,v 1.28 2012/04/17 07:11:38 imilh Exp $ */
/* $Id: messages.h,v 1.29 2012/05/28 10:56:27 imilh Exp $ */

/*
* Copyright (c) 2009, 2010 The NetBSD Foundation, Inc.
Expand Down Expand Up @@ -147,6 +147,7 @@ please re-run %s with a package name matching one of the following:\n"
#define MSG_IS_INSTALLED_CODE "\n=: package is installed and up-to-date\n<: package is installed but newer version is available\n>: installed package has a greater version than available package\n"
#define MSG_NO_SEARCH_RESULTS "No results found for %s\n"
#define MSG_EMPTY_LIST "Requested list is empty.\n"
#define MSG_NO_CATEGORIES "No categories found.\n"

/* fsops.c */
#define MSG_TRANS_FAILED "Failed to translate %s in repository config file"
Expand Down
4 changes: 3 additions & 1 deletion pkgin.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $Id: pkgin.h,v 1.35 2012/05/27 08:24:21 imilh Exp $ */
/* $Id: pkgin.h,v 1.36 2012/05/28 10:56:27 imilh Exp $ */

/*
* Copyright (c) 2009, 2010 The NetBSD Foundation, Inc.
Expand Down Expand Up @@ -116,6 +116,7 @@
#define PKG_SHPKGBDEFS_CMD 22
#define PKG_SHCAT_CMD 23
#define PKG_SHPCAT_CMD 24
#define PKG_SHALLCAT_CMD 25
#define PKG_GINTO_CMD 255

#define PKG_EQUAL '='
Expand Down Expand Up @@ -237,6 +238,7 @@ void list_pkgs(const char *, int);
void search_pkg(const char *);
void show_category(char *);
void show_pkg_category(char *);
void show_all_categories(void);
/* actions.c */
int check_yesno(uint8_t);
void do_pkg_remove(Plisthead *);
Expand Down
3 changes: 2 additions & 1 deletion pkgindb.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $Id: pkgindb.h,v 1.11 2012/04/14 19:24:39 imilh Exp $ */
/* $Id: pkgindb.h,v 1.12 2012/05/28 10:56:27 imilh Exp $ */

/*
* Copyright (c) 2009, 2010 The NetBSD Foundation, Inc.
Expand Down Expand Up @@ -72,6 +72,7 @@ extern const char EXPORT_KEEP_LIST[];
extern const char GET_PKGNAME_BY_PKGPATH[];
extern const char GET_ORPHAN_PACKAGES[];
extern const char COMPAT_CHECK[];
extern const char SHOW_ALL_CATEGORIES[];

#define LOCAL_PKG "LOCAL_PKG"
#define REMOTE_PKG "REMOTE_PKG"
Expand Down
6 changes: 5 additions & 1 deletion pkgindb_queries.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $Id: pkgindb_queries.c,v 1.25 2012/04/24 13:23:27 imilh Exp $ */
/* $Id: pkgindb_queries.c,v 1.26 2012/05/28 10:56:27 imilh Exp $ */

/*
* Copyright (c) 2009, 2010, 2011, 2012 The NetBSD Foundation, Inc.
Expand Down Expand Up @@ -197,3 +197,7 @@ const char GET_ORPHAN_PACKAGES[] =

const char COMPAT_CHECK[] =
"SELECT FULLPKGNAME FROM REMOTE_PKG LIMIT 1;";

const char SHOW_ALL_CATEGORIES[] =
"SELECT DISTINCT CATEGORIES FROM REMOTE_PKG WHERE "
"CATEGORIES NOT LIKE '%% %%' ORDER BY CATEGORIES DESC;";
19 changes: 18 additions & 1 deletion pkglist.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $Id: pkglist.c,v 1.9 2012/04/20 09:15:53 imilh Exp $ */
/* $Id: pkglist.c,v 1.10 2012/05/28 10:56:27 imilh Exp $ */

/*
* Copyright (c) 2009, 2010, 2011 The NetBSD Foundation, Inc.
Expand Down Expand Up @@ -349,3 +349,20 @@ show_pkg_category(char *pkgname)
printf("%-12s - %s\n", plist->category, plist->full);
}
}

void
show_all_categories(void)
{
Plisthead *cathead;
Pkglist *plist;

if ((cathead = rec_pkglist(SHOW_ALL_CATEGORIES)) == NULL) {
fprintf(stderr, MSG_NO_CATEGORIES);
return;
}

SLIST_FOREACH(plist, cathead, next)
printf("%s\n", plist->full);

free_pkglist(&cathead, LIST);
}

0 comments on commit 9bfdabe

Please sign in to comment.