[pacman-dev] [PATCH 1/2] pactree: fix --sync getopt value
The long --sync options has apparently never worked. Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com> --- src/util/pactree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/pactree.c b/src/util/pactree.c index 4488645..ab5d90a 100644 --- a/src/util/pactree.c +++ b/src/util/pactree.c @@ -217,7 +217,7 @@ static int parse_options(int argc, char *argv[]) {"help", no_argument, 0, 'h'}, {"linear", no_argument, 0, 'l'}, {"reverse", no_argument, 0, 'r'}, - {"sync", no_argument, 0, 'S'}, + {"sync", no_argument, 0, 's'}, {"unique", no_argument, 0, 'u'}, {"config", required_argument, 0, OP_CONFIG}, -- 1.7.12.2
Also removes the less helpful provides-specific branch tip. Old: New: |--pkg |--pkg +--dep1 provides dep5 |--dep1 provides dep5 | |--dep2 | \--dep2 |--dep3 \--dep3 |--dep4 \--dep4 Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com> --- src/util/pactree.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/util/pactree.c b/src/util/pactree.c index ab5d90a..77be629 100644 --- a/src/util/pactree.c +++ b/src/util/pactree.c @@ -36,8 +36,8 @@ typedef struct tdepth { /* output */ struct graph_style { const char *provides; - const char *tip1; - const char *tip2; + const char *tip; + const char *last; const char *limb; int indent; }; @@ -45,7 +45,7 @@ struct graph_style { static struct graph_style graph_default = { " provides", "|--", - "+--", + "\\--", "|", 3 }; @@ -301,8 +301,10 @@ static void cleanup(void) } /* pkg provides provision */ -static void print_text(const char *pkg, const char *provision, tdepth *depth) +static void print_text(const char *pkg, const char *provision, + tdepth *depth, int last) { + const char* tip = last ? style->last : style->tip; if(!pkg && !provision) { /* not much we can do */ return; @@ -323,14 +325,14 @@ static void print_text(const char *pkg, const char *provision, tdepth *depth) /* print tip */ if(!pkg && provision) { - printf("%s%s%s%s [unresolvable]%s\n", style->tip1, color->leaf1, + printf("%s%s%s%s [unresolvable]%s\n", tip, color->leaf1, provision, color->branch1, color->off); } else if(provision && strcmp(pkg, provision) != 0) { - printf("%s%s%s%s%s %s%s%s\n", style->tip2, color->leaf1, pkg, + printf("%s%s%s%s%s %s%s%s\n", tip, color->leaf1, pkg, color->leaf2, style->provides, color->leaf1, provision, color->off); } else { - printf("%s%s%s%s\n", style->tip1, color->leaf1, pkg, color->off); + printf("%s%s%s%s\n", tip, color->leaf1, pkg, color->off); } } @@ -348,12 +350,13 @@ static void print_graph(const char *parentname, const char *pkgname, const char } /* parent depends on dep which is satisfied by pkg */ -static void print(const char *parentname, const char *pkgname, const char *depname, tdepth *depth) +static void print(const char *parentname, const char *pkgname, + const char *depname, tdepth *depth, int last) { if(graphviz) { print_graph(parentname, pkgname, depname); } else { - print_text(pkgname, depname, depth); + print_text(pkgname, depname, depth, last); } } @@ -369,7 +372,7 @@ static void print_start(const char *pkgname, const char *provname) NULL, 0 }; - print_text(pkgname, provname, &d); + print_text(pkgname, provname, &d, 0); } } @@ -412,6 +415,7 @@ static void walk_deps(alpm_list_t *dblist, alpm_pkg_t *pkg, tdepth *depth, int r for(i = deps; i; i = alpm_list_next(i)) { const char *pkgname = i->data; + int last = alpm_list_next(i) ? 0 : 1; alpm_pkg_t *dep_pkg = alpm_find_dbs_satisfier(handle, dblist, pkgname); @@ -419,10 +423,10 @@ static void walk_deps(alpm_list_t *dblist, alpm_pkg_t *pkg, tdepth *depth, int r /* if we've already seen this package, don't print in "unique" output * and don't recurse */ if(!unique) { - print(alpm_pkg_get_name(pkg), alpm_pkg_get_name(dep_pkg), pkgname, depth); + print(alpm_pkg_get_name(pkg), alpm_pkg_get_name(dep_pkg), pkgname, depth, last); } } else { - print(alpm_pkg_get_name(pkg), alpm_pkg_get_name(dep_pkg), pkgname, depth); + print(alpm_pkg_get_name(pkg), alpm_pkg_get_name(dep_pkg), pkgname, depth, last); if(dep_pkg) { tdepth d = { depth, @@ -431,7 +435,7 @@ static void walk_deps(alpm_list_t *dblist, alpm_pkg_t *pkg, tdepth *depth, int r }; depth->next = &d; /* last dep, cut off the limb here */ - if(!alpm_list_next(i)){ + if(last){ if(depth->prev){ depth->prev->next = &d; d.prev = depth->prev; -- 1.7.12.2
On Mon, Oct 15, 2012 at 02:29:08PM -0400, Andrew Gregory wrote:
Also removes the less helpful provides-specific branch tip.
Old: New: |--pkg |--pkg +--dep1 provides dep5 |--dep1 provides dep5 | |--dep2 | \--dep2 |--dep3 \--dep3 |--dep4 \--dep4
Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com> ---
Hrmmm, I like this -- it's very similar to what util-linux does, with the exception that they use a backquote instead a backslash on the tail, e.g. New: |--pkg |--dep1 provides dep5 | `--dep2 `--dep3 `--dep4 And I think this looks a bit cleaner. I'd like to introduce the option of utf8 line drawing characters along with this -- I can pull this patch (and the previous) if you're cool with this change.
src/util/pactree.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-)
diff --git a/src/util/pactree.c b/src/util/pactree.c index ab5d90a..77be629 100644 --- a/src/util/pactree.c +++ b/src/util/pactree.c @@ -36,8 +36,8 @@ typedef struct tdepth { /* output */ struct graph_style { const char *provides; - const char *tip1; - const char *tip2; + const char *tip; + const char *last; const char *limb; int indent; }; @@ -45,7 +45,7 @@ struct graph_style { static struct graph_style graph_default = { " provides", "|--", - "+--", + "\\--", "|", 3 }; @@ -301,8 +301,10 @@ static void cleanup(void) }
/* pkg provides provision */ -static void print_text(const char *pkg, const char *provision, tdepth *depth) +static void print_text(const char *pkg, const char *provision, + tdepth *depth, int last) { + const char* tip = last ? style->last : style->tip; if(!pkg && !provision) { /* not much we can do */ return; @@ -323,14 +325,14 @@ static void print_text(const char *pkg, const char *provision, tdepth *depth)
/* print tip */ if(!pkg && provision) { - printf("%s%s%s%s [unresolvable]%s\n", style->tip1, color->leaf1, + printf("%s%s%s%s [unresolvable]%s\n", tip, color->leaf1, provision, color->branch1, color->off); } else if(provision && strcmp(pkg, provision) != 0) { - printf("%s%s%s%s%s %s%s%s\n", style->tip2, color->leaf1, pkg, + printf("%s%s%s%s%s %s%s%s\n", tip, color->leaf1, pkg, color->leaf2, style->provides, color->leaf1, provision, color->off); } else { - printf("%s%s%s%s\n", style->tip1, color->leaf1, pkg, color->off); + printf("%s%s%s%s\n", tip, color->leaf1, pkg, color->off); } }
@@ -348,12 +350,13 @@ static void print_graph(const char *parentname, const char *pkgname, const char }
/* parent depends on dep which is satisfied by pkg */ -static void print(const char *parentname, const char *pkgname, const char *depname, tdepth *depth) +static void print(const char *parentname, const char *pkgname, + const char *depname, tdepth *depth, int last) { if(graphviz) { print_graph(parentname, pkgname, depname); } else { - print_text(pkgname, depname, depth); + print_text(pkgname, depname, depth, last); } }
@@ -369,7 +372,7 @@ static void print_start(const char *pkgname, const char *provname) NULL, 0 }; - print_text(pkgname, provname, &d); + print_text(pkgname, provname, &d, 0); } }
@@ -412,6 +415,7 @@ static void walk_deps(alpm_list_t *dblist, alpm_pkg_t *pkg, tdepth *depth, int r
for(i = deps; i; i = alpm_list_next(i)) { const char *pkgname = i->data; + int last = alpm_list_next(i) ? 0 : 1;
alpm_pkg_t *dep_pkg = alpm_find_dbs_satisfier(handle, dblist, pkgname);
@@ -419,10 +423,10 @@ static void walk_deps(alpm_list_t *dblist, alpm_pkg_t *pkg, tdepth *depth, int r /* if we've already seen this package, don't print in "unique" output * and don't recurse */ if(!unique) { - print(alpm_pkg_get_name(pkg), alpm_pkg_get_name(dep_pkg), pkgname, depth); + print(alpm_pkg_get_name(pkg), alpm_pkg_get_name(dep_pkg), pkgname, depth, last); } } else { - print(alpm_pkg_get_name(pkg), alpm_pkg_get_name(dep_pkg), pkgname, depth); + print(alpm_pkg_get_name(pkg), alpm_pkg_get_name(dep_pkg), pkgname, depth, last); if(dep_pkg) { tdepth d = { depth, @@ -431,7 +435,7 @@ static void walk_deps(alpm_list_t *dblist, alpm_pkg_t *pkg, tdepth *depth, int r }; depth->next = &d; /* last dep, cut off the limb here */ - if(!alpm_list_next(i)){ + if(last){ if(depth->prev){ depth->prev->next = &d; d.prev = depth->prev; -- 1.7.12.2
Add a compile time check for langinfo.h so that we can possibly use unicode line drawing characters if the current locale is supportive of them. This can be explicitly disabled at runtime with the use of a new switch: -a, --ascii. Signed-off-by: Dave Reisner <dreisner@archlinux.org> --- configure.ac | 4 ++-- doc/pactree.8.txt | 4 ++++ src/util/pactree.c | 34 +++++++++++++++++++++++++++++++--- 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/configure.ac b/configure.ac index 7fe696a..aa132c6 100644 --- a/configure.ac +++ b/configure.ac @@ -247,8 +247,8 @@ AS_IF([test "x$have_gpgme" = xno -a "x$with_gpgme" = xyes], AM_CONDITIONAL([HAVE_LIBGPGME], [test "x$have_gpgme" = "xyes"]) # Checks for header files. -AC_CHECK_HEADERS([fcntl.h float.h glob.h libintl.h limits.h locale.h \ - mntent.h netinet/in.h netinet/tcp.h \ +AC_CHECK_HEADERS([fcntl.h float.h glob.h langinfo.h libintl.h limits.h \ + locale.h mntent.h netinet/in.h netinet/tcp.h \ stddef.h string.h sys/ioctl.h \ sys/mnttab.h sys/mount.h \ sys/param.h sys/statvfs.h sys/time.h sys/types.h \ diff --git a/doc/pactree.8.txt b/doc/pactree.8.txt index 669a14b..6ecaf23 100644 --- a/doc/pactree.8.txt +++ b/doc/pactree.8.txt @@ -22,6 +22,10 @@ description is generated. Options ------- +*-a, \--ascii*:: + Use ascii characters for tree formatting. By default, pactree will use unicode + line drawing characters if it is able to detect that the locale supports them. + *-b, \--dbpath*:: Specify an alternative database location. diff --git a/src/util/pactree.c b/src/util/pactree.c index 77be629..82c9c0b 100644 --- a/src/util/pactree.c +++ b/src/util/pactree.c @@ -21,7 +21,7 @@ #include <getopt.h> #include <stdio.h> #include <string.h> - +#include <locale.h> #include <alpm.h> #include <alpm_list.h> @@ -42,6 +42,22 @@ struct graph_style { int indent; }; +#define UTF_V "\342\224\202" /* U+2502, Vertical line drawing char */ +#define UTF_VR "\342\224\234" /* U+251C, Vertical and right */ +#define UTF_H "\342\224\200" /* U+2500, Horizontal */ +#define UTF_UR "\342\224\224" /* U+2514, Up and right */ + +#ifdef HAVE_LANGINFO_H +#include <langinfo.h> +static struct graph_style graph_utf8 = { + " provides", + UTF_VR UTF_H, + UTF_UR UTF_H, + UTF_V " ", + 3 +}; +#endif + static struct graph_style graph_default = { " provides", "|--", @@ -95,7 +111,7 @@ alpm_list_t *provisions = NULL; /* options */ struct color_choices *color = &no_color; -struct graph_style *style = &graph_default; +struct graph_style *style = &graph_utf8; int graphviz = 0; int max_depth = -1; int reverse = 0; @@ -210,6 +226,7 @@ static int parse_options(int argc, char *argv[]) char *endptr = NULL; static const struct option opts[] = { + {"ascii", no_argument, 0, 'a'}, {"dbpath", required_argument, 0, 'b'}, {"color", no_argument, 0, 'c'}, {"depth", required_argument, 0, 'd'}, @@ -224,12 +241,22 @@ static int parse_options(int argc, char *argv[]) {0, 0, 0, 0} }; - while((opt = getopt_long(argc, argv, "b:cd:ghlrsu", opts, &option_index))) { +#ifdef HAVE_LANGINFO_H + setlocale(LC_ALL, ""); + if(strcmp(nl_langinfo(CODESET), "UTF-8") == 0) { + style = &graph_utf8; + } +#endif + + while((opt = getopt_long(argc, argv, "ab:cd:ghlrsu", opts, &option_index))) { if(opt < 0) { break; } switch(opt) { + case 'a': + style = &graph_default; + break; case OP_CONFIG: configfile = optarg; break; @@ -281,6 +308,7 @@ static void usage(void) { fprintf(stderr, "pactree v" PACKAGE_VERSION "\n" "Usage: pactree [options] PACKAGE\n\n" + " -a, --ascii use ascii characters for tree formatting\n" " -b, --dbpath <path> set an alternate database location\n" " -c, --color colorize output\n" " -d, --depth <#> limit the depth of recursion\n" -- 1.7.12.3
On Mon, Oct 15, 2012 at 02:29:07PM -0400, Andrew Gregory wrote:
The long --sync options has apparently never worked.
Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com> --- src/util/pactree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/util/pactree.c b/src/util/pactree.c index 4488645..ab5d90a 100644 --- a/src/util/pactree.c +++ b/src/util/pactree.c @@ -217,7 +217,7 @@ static int parse_options(int argc, char *argv[]) {"help", no_argument, 0, 'h'}, {"linear", no_argument, 0, 'l'}, {"reverse", no_argument, 0, 'r'}, - {"sync", no_argument, 0, 'S'}, + {"sync", no_argument, 0, 's'},
wat. Could you give an example of this breaking? Even if it is, I can't possibly understand how this is the correct fix. -s is strictly --search whereas --sync is a toplevel action and must therefore by capitalized. # pacman --sync -yy :: Synchronizing package databases... staging 40.9 KiB 444K/s 00:00 [---------------------] 100% allanbrokeit 876.0 B 0.00B/s 00:00 [---------------------] 100% allanbrokeit.sig 287.0 B 0.00B/s 00:00 [---------------------] 100% etc etc...
{"unique", no_argument, 0, 'u'},
{"config", required_argument, 0, OP_CONFIG}, -- 1.7.12.2
On Mon, Oct 15, 2012 at 02:40:18PM -0400, Dave Reisner wrote:
On Mon, Oct 15, 2012 at 02:29:07PM -0400, Andrew Gregory wrote:
The long --sync options has apparently never worked.
Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com> --- src/util/pactree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/util/pactree.c b/src/util/pactree.c index 4488645..ab5d90a 100644 --- a/src/util/pactree.c +++ b/src/util/pactree.c @@ -217,7 +217,7 @@ static int parse_options(int argc, char *argv[]) {"help", no_argument, 0, 'h'}, {"linear", no_argument, 0, 'l'}, {"reverse", no_argument, 0, 'r'}, - {"sync", no_argument, 0, 'S'}, + {"sync", no_argument, 0, 's'},
wat. Could you give an example of this breaking? Even if it is, I can't possibly understand how this is the correct fix. -s is strictly --search whereas --sync is a toplevel action and must therefore by capitalized.
# pacman --sync -yy :: Synchronizing package databases... staging 40.9 KiB 444K/s 00:00 [---------------------] 100% allanbrokeit 876.0 B 0.00B/s 00:00 [---------------------] 100% allanbrokeit.sig 287.0 B 0.00B/s 00:00 [---------------------] 100% etc etc...
Yay ignore this, I can't read. Your patch is fine.
{"unique", no_argument, 0, 'u'},
{"config", required_argument, 0, OP_CONFIG}, -- 1.7.12.2
participants (3)
-
Andrew Gregory
-
Dave Reisner
-
Dave Reisner