Re: [voidlinux/xbps] Added -P and -u formatting options. Unified commit (#214)

Roman Neuhauser at Mon, 17 Oct 2016 06:34:23 -0700
@ebfe @Gottox @Duncaen how should we approach the compiler warning? https://travis-ci.org/voidlinux/xbps/jobs/168287633#L3067
Roman Neuhauser at Mon, 17 Oct 2016 06:35:13 -0700
@aditya3098 no worries, you're doing fine.
Enno Boland at Mon, 17 Oct 2016 06:40:35 -0700
@roman-neuhauser by fixing it: https://github.com/voidlinux/xbps/blob/969d300c9b809cd264ee5270d30ca4ac68da85b0/bin/xbps-query/main.c#L119 ``` format = ... = NULL; ```
Roman Neuhauser at Mon, 17 Oct 2016 06:45:09 -0700
@aditya3098 you'll have to initialize the `char *format` to `NULL` since it's a local variable.
Roman Neuhauser at Mon, 17 Oct 2016 06:45:57 -0700
@Gottox right, sorry, i'm not very good at C. (and only spotted your comment just now).
Enno Boland at Mon, 17 Oct 2016 06:46:53 -0700
Nobody is ;)
Aditya Goturu at Mon, 17 Oct 2016 08:04:15 -0700
@aditya3098 pushed 1 commit. 00b1696 Fixed null initialization
Aditya Goturu at Mon, 17 Oct 2016 08:06:32 -0700
@aditya3098 pushed 1 commit. e5aafa0 Added Sx in man page. Am I doing that commit-snake thing again?
Roman Neuhauser at Mon, 17 Oct 2016 09:50:59 -0700
roman-neuhauser requested changes on this pull request. looks better, thanks! we'll need feedback from authorities soon. :) > @@ -65,6 +65,9 @@ usage(bool fail) " -o --ownedby FILE Search for package files by matching STRING or REGEX\n" " -S --show PKG Show information for PKG [default mode]\n" " -s --search PKG Search for packages by matching PKG, STRING or REGEX\n" + " -P --printf FORMAT Print as FORMAT, for substitutions see man page\n" + " -u --unformatted Print search output without an formatting or description\n" + " Useful for installing multiple packages using regexs\n" the previous line is still mis-indented. > @@ -52,6 +52,59 @@ struct search_data { }; static void +print_results_formatted(struct xbps_handle *xhp, struct search_data *sd, const char *format) +{ + const char *pkgver, *desc; + char tmp[256], instc; + const char *origformat; + bool process = false; + instc = '+'; + origformat = format; + /* Iterate over results array and find out largest pkgver string */ + for (unsigned int i = 0; i < xbps_array_count(sd->results); i+=2) + xbps_array_get_cstring_nocopy(sd->results, i, &pkgver); shouldn't the above loop be removed completely? it seems to serve no purpose. > + instc = '+'; + while (true) { + if ((char)(*format) == '\0') break; + if (process) { + switch ((char)(*format)) { + case '%': + printf("%%"); + break; + case 'd': + printf("%s", desc); + break; + case 'i': + printf("%c", instc); + break; + case 'n': + printf("\n"); the previous line uses spaces for indentation, it should use tabs like everything else.
Enno Boland at Mon, 17 Oct 2016 12:00:56 -0700
Gottox requested changes on this pull request. > + origformat = format; + /* Iterate over results array and find out largest pkgver string */ + for (unsigned int i = 0; i < xbps_array_count(sd->results); i+=2) { + xbps_array_get_cstring_nocopy(sd->results, i, &pkgver); + len = strlen(pkgver); + if (tlen == 0 || len > tlen) + tlen = len; + } + for (unsigned int i = 0; i < xbps_array_count(sd->results); i+=2) { + xbps_array_get_cstring_nocopy(sd->results, i, &pkgver); + xbps_array_get_cstring_nocopy(sd->results, i+1, &desc); + xbps_strlcpy(tmp, pkgver, sizeof(tmp)); + if (xbps_pkgdb_get_pkg(xhp, pkgver)) + instc = '='; + else + instc = '+'; I prefer the same quantifier as in the default output. > @@ -259,7 +312,10 @@ search(struct xbps_handle *xhp, bool repo_mode, const char *pat, const char *pro } } if (!prop && xbps_array_count(sd.results)) { - print_results(xhp, &sd); + if (format) + print_results_formatted(xhp, &sd, format); + else + print_results(xhp, &sd); please use tabs for indention
Aditya Goturu at Tue, 18 Oct 2016 04:17:42 -0700
Okay I will make the changes
Aditya Goturu at Tue, 15 Nov 2016 05:55:33 -0800
@aditya3098 pushed 1 commit. b5f0b90 Some changes to formatting
Aditya Goturu at Tue, 15 Nov 2016 05:55:43 -0800
Sorry that took a while