From: Jani Nikula <jani@nikula.org>
To: Ethan Glasser-Camp <ethan.glasser.camp@gmail.com>,
notmuch@notmuchmail.org
Subject: Re: [PATCH v4 2/9] parse-time-string: add a date/time parser to notmuch
Date: Wed, 17 Oct 2012 09:48:16 +0200 [thread overview]
Message-ID: <87zk3lzghr.fsf@nikula.org> (raw)
In-Reply-To: <87hapw9x99.fsf@betacantrips.com>
On Mon, 15 Oct 2012, Ethan Glasser-Camp <ethan.glasser.camp@gmail.com> wrote:
>> +/* Parse a previously postponed number if one exists. */
>> +static int parse_postponed_number (struct state *state, int v, int n, char d);
>> +static int
>> +handle_postponed_number (struct state *state, enum field next_field)
>> +{
>> + int v = state->postponed_value;
>> + int n = state->postponed_length;
>> + char d = state->postponed_delim;
>> + int r;
>> +
>> + if (!n)
>> + return 0;
>> +
>> + state->postponed_value = 0;
>> + state->postponed_length = 0;
>> + state->postponed_delim = 0;
>
> This could be refactored to be a call to get_postponed_number. Also,
> I'd prefer parse_postponed_number be up here, closer to its sole
> caller (handle_postponed_number).
I decided to nuke the intermediate handle_postponed_number altogether,
and fix parse_postponed_number to call get_postponed_number. Thanks for
pointing this out.
>> +/*
>> + * Postpone a number to be handled later. If one exists already,
>> + * handle it first. n may be -1 to indicate a keyword that has no
>> + * number length.
>> + */
>> +static int
>> +set_postponed_number (struct state *state, int v, int n)
>> +{
>> + int r;
>> + char d = state->delim;
>> +
>> + /* Parse a previously postponed number, if any. */
>> + r = handle_postponed_number (state, TM_NONE);
>> + if (r)
>> + return r;
>
> I would love a comment explaining under what circumstances this could
> occur and what the caller is expected to do.
Any errors anywhere the caller is expected to pop up all the way to the
main entry point. I did not verify, but, for example, I'd expect a
sequence of "2012 2012 2012" to fail right here.
>> +/*
>> + * Accepted keywords.
>> + */
>> +static struct keyword keywords[] = {
>> + /* Weekdays. */
>> + { N_("sun|day"), TM_ABS_WDAY, 0, NULL },
>> + { N_("mon|day"), TM_ABS_WDAY, 1, NULL },
>
> Maybe it's just my history with Python, but I'd prefer keywords, which
> is a global and a constant, to be written in all caps (KEYWORDS).
It's just your history with Python. ;) IMO it's more in line with
notmuch coding style as it is. It could be made const though.
>> +/*
>> + * Compare strings s and keyword. Return number of matching chars on
>> + * match, 0 for no match. Match must be at least n chars, or all of
>> + * keyword if n < 0, otherwise it's not a match. Use match_case for
>> + * case sensitive matching.
>> + */
>> +static size_t
>> +stringcmp (const char *s, const char *keyword, ssize_t n, bool match_case)
>> +{
>
> The name of this function makes it look uncomfortably like strcmp(3),
> which has a very different calling semantics (specifically the -1, 0, 1
> return value). I'd prefer a name like string_match_keyword.
Agreed.
BR,
Jani.
next prev parent reply other threads:[~2012-10-17 7:48 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-13 22:09 [PATCH v4 0/9] notmuch search date:since..until query support Jani Nikula
2012-10-13 22:09 ` [PATCH v4 1/9] build: drop the -Wswitch-enum warning Jani Nikula
2012-10-13 22:09 ` [PATCH v4 2/9] parse-time-string: add a date/time parser to notmuch Jani Nikula
2012-10-15 4:26 ` Ethan Glasser-Camp
2012-10-17 7:48 ` Jani Nikula [this message]
2012-10-13 22:09 ` [PATCH v4 3/9] test: add new test tool parse-time for date/time parser Jani Nikula
2012-10-13 22:09 ` [PATCH v4 4/9] test: add smoke tests for the date/time parser module Jani Nikula
2012-10-13 22:09 ` [PATCH v4 5/9] build: build parse-time-string as part of the notmuch lib and static cli Jani Nikula
2012-10-13 22:09 ` [PATCH v4 6/9] lib: add date range query support Jani Nikula
2012-10-13 22:09 ` [PATCH v4 7/9] test: add tests for date:since..until range queries Jani Nikula
2012-10-13 22:09 ` [PATCH v4 8/9] man: document the " Jani Nikula
2012-10-13 22:09 ` [PATCH v4 9/9] NEWS: date range search support Jani Nikula
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=87zk3lzghr.fsf@nikula.org \
--to=jani@nikula.org \
--cc=ethan.glasser.camp@gmail.com \
--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).