rc-list - mailing list for the rc(1) shell
 help / color / mirror / Atom feed
From: Byron Rakitzis <byron@rakitzis.com>
To: fosterd@hartwick.edu, tjg@star.le.ac.uk
Cc: rc@hawkwind.utcs.toronto.edu
Subject: Re: Bug#62339: rc bug
Date: Tue, 18 Apr 2000 02:30:00 -0400	[thread overview]
Message-ID: <200004180630.XAA05903@peanut.rakitzis.com> (raw)

Thanks for tracking this down.

I'm the original miscreant as far as the documentation style of rc is
concerned.

Much of this code was written roughly 10 years ago, I'd certainly write
it differently now.

The metacharacter array is properly an array of booleans. Hence the
explicit checks against 0 and 1, which should be cleaned up somehow
to reflect their function. A macro "ismeta(p, i)", perhaps. I don't
know where the tests against '\001' snuck in. I think it's a mistake.

> Now in lmatch() when we go through looking for '*'s, we have this
> loop:
>
> 	for (i = 0; p->w[i] != '\0'; i++)
> 		if (p->w[i] != '*' || p->m[i] != 1) {
>
> Which assumes that m is as big as w (i.e, not NULL). I came up with
> this replacement, which works for all the test cases I can think of:
>
>         if (s == NULL) {
>                 if (p == NULL) /* null matches null */
>                         return TRUE; 
>                 for (; p != NULL; p = p->n) /* one or more stars match null */
>                         if (p->w && strspn(p->w, "*") == strlen(p->w) &&
>                             p->m && strspn(p->m, "\001") == strlen(p->m))
>                                 return TRUE;
>                 return FALSE;
>         }
>
> I was also able to get rid of 'okay', which i found hard to follow.
> The comment about the null string is gone too, because IMO the null
> string fails for the same reason 'foo' fails. There's really no need
> for an explicit check.

This is good.

I'm picking nits here, but since I obsessed over this code a while ago,
I might suggest two small changes to your fix:

>                         if (p->w && strspn(p->w, "*") == strlen(p->w) &&
>                             p->m && strspn(p->m, "\001") == strlen(p->m))

to:

	if (p->m != NULL &&
		strspn(p->w, "*") == strlen(p->w) &&
		strlen(p->m) == strlen(p->w))

Firstly, p->w can not be NULL here; there can be no null words in
a word list, only empty strings which are represented as "".

As long as you are getting sneaky about using the string library to find
zeroes in a character array, you may also rephrase the metacharacter
test as two calls to strlen.

Byron.


             reply	other threads:[~2000-04-18 21:12 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-04-18  6:30 Byron Rakitzis [this message]
2000-04-19 14:39 ` Tim Goodwin
     [not found] <Pine.LNX.3.96.1000425010821.264C-100000@dwarf>
     [not found] ` <QDwAALDY+jgTYAcA@ltsun0.star.le.ac.uk>
2000-04-17 19:59   ` Decklin Foster

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200004180630.XAA05903@peanut.rakitzis.com \
    --to=byron@rakitzis.com \
    --cc=fosterd@hartwick.edu \
    --cc=rc@hawkwind.utcs.toronto.edu \
    --cc=tjg@star.le.ac.uk \
    /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.
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 NNTP newsgroup(s).