From: Austin Clements <amdragon@MIT.EDU>
To: David Bremner <david@tethera.net>
Cc: Notmuch Mail <notmuch@notmuchmail.org>
Subject: Re: have "notmuch help" call man?
Date: Wed, 28 Dec 2011 21:24:19 -0500 [thread overview]
Message-ID: <20111229022419.GI30150@mit.edu> (raw)
In-Reply-To: <8739c6yhp0.fsf@zancas.localnet>
Quoth David Bremner on Dec 26 at 8:35 pm:
> The following changes since commit d61cef374b3234c2f1327fa74b612b40c196a605:
>
> show: Rewrite show_message_body to use the MIME tree interface. (2011-12-25 22:23:15 -0400)
>
> are available in the git repository at:
> git://pivot.cs.unb.ca/notmuch split-man
>
> HEAD is at 8eaee754e48dc630d83e2f7369bdadde0f34af84
Some comments on "notmuch: replace built-in help with exec of man"
> @@ -534,38 +126,20 @@ notmuch_help_command (unused (void *ctx), int argc, char *argv[])
> for (i = 0; i < ARRAY_SIZE (commands); i++) {
> command = &commands[i];
>
> - if (strcmp (argv[0], command->name) == 0) {
> - printf ("Help for \"notmuch %s\":\n\n", argv[0]);
> - if (command->arguments)
> - printf ("%s %s\n\n\t%s\n\n%s\n\n",
> - command->name, command->arguments,
> - command->summary, command->documentation);
> - else
> - printf ("%s\t%s\n\n%s\n\n", command->name,
> - command->summary, command->documentation);
> - return 0;
> + if (strncmp (argv[0], command->name, strlen (argv[0])) == 0) {
Shouldn't this be strcmp?
> + char *page = malloc (strlen (argv[0]) + strlen ("notmuch-") + 1);
> + strcpy (page, "notmuch-");
> + strcat (page, command->name);
This is fine, but could be cleaner with talloc:
char *page = talloc_asprintf (ctx, "notmuch-%s", command->name);
> +
> + execlp ("man", "man", page, (char *) NULL);
> + /* NOTREACHED */
This certainly *can* be reached if the exec fails. You should print a
helpful error message and exit, maybe something like
fprintf (stderr, "failed to exec man: %s\n", strerror (errno));
exit (1);
> }
> }
>
> - if (strcmp (argv[0], "search-terms") == 0) {
> - printf ("Help for <%s>\n\n", argv[0]);
> - for (i = 0; i < ARRAY_SIZE (commands); i++) {
> - command = &commands[i];
> -
> - if (command->arguments &&
> - strstr (command->arguments, "search-terms"))
> - {
> - printf ("\t%s\t%s\n",
> - command->name, command->arguments);
> - }
> - }
> - printf ("\n");
> - printf (search_terms_help);
> - return 0;
> - } else if (strcmp (argv[0], "hooks") == 0) {
> - printf ("Help for <%s>\n\n", argv[0]);
> - printf (hooks_help);
> - return 0;
> + if (strncmp (argv[0], "search-terms", strlen (argv[0])) == 0) {
> + execlp ("man", "man", "notmuch-search-terms", (char *) NULL);
> + } else if (strncmp (argv[0], "hooks", strlen (argv[0])) == 0) {
> + execlp ("man", "man", "notmuch-hooks", (char *) NULL);
Same comments about strncmp and exec failing for the above four lines.
It might make sense to merge all of the exec calls in to one to
centralize the error handling.
> }
>
> fprintf (stderr,
next prev parent reply other threads:[~2011-12-29 2:23 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-16 16:01 have "notmuch help" call man? David Bremner
2011-12-16 16:41 ` Adam Wolfe Gordon
2011-12-16 18:17 ` Kazuo Teramoto
2011-12-16 21:35 ` Jameson Graef Rollins
2011-12-17 9:56 ` Tomi Ollila
2011-12-20 4:16 ` David Bremner
2011-12-22 3:43 ` David Bremner
2011-12-22 4:53 ` Jameson Graef Rollins
2011-12-22 10:49 ` David Bremner
2011-12-27 0:35 ` David Bremner
2011-12-29 2:24 ` Austin Clements [this message]
2011-12-29 13:11 ` [PATCH v3] notmuch: replace built-in help with exec of man David Bremner
2011-12-29 13:47 ` David Bremner
2011-12-30 18:50 ` Austin Clements
2011-12-31 19:25 ` David Bremner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20111229022419.GI30150@mit.edu \
--to=amdragon@mit.edu \
--cc=david@tethera.net \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).