Sebastian Götte <ja...@physik.tu-berlin.de> writes:

>  static void parse_gpg_output(struct signature_check *sigc)
>  {
> -     const char *buf = sigc->gpg_status;
>       int i;
>  
> +     /* Iterate over all search strings */
>       for (i = 0; i < ARRAY_SIZE(sigcheck_gpg_status); i++) {
> +             const char *found = sigc->gpg_status;
> +
> +             /* Iterate over all lines */
> +             do {
> +                     if (!prefixcmp(found, sigcheck_gpg_status[i].check)) {
> +                             const char *next;
> +                             
> +                             found += strlen(sigcheck_gpg_status[i].check);
> +                             sigc->check_result = 
> sigcheck_gpg_status[i].result;
> +                             sigc->key = xmemdupz(found, 16);
> +                             found += 17;
> +                             next = strchrnul(found, '\n');
> +                             sigc->signer = xmemdupz(found, next - found);
> +                             return;
> +                     }
> +                     found = strchr(found, '\n')+1;
> +             } while(found-1);

Yuck.  That termination condition is horrible.

Honestly speaking, I find the one I suggested the other day (which
has been queued on 'pu') much nicer than this loop.

If you really really want to do a line at a time, discarding the
"allow strstr() to scan over multiple lines" optimization, it is
more natural to iterate over buffer one line at a time, and check
for each expected output with an inner loop, perhaps like this:

        const char *cp = buf;
        while (*cp) {
                for (i = 0; i < ARRAY_SIZE(sig_check); i++) {
                        if (!prefixcmp(cp, sig_check[i].check) &&
                            parse_gpg_status(sigc, cp, &sig_check[i]))
                                return;
                }
                cp = strchrnul(cp, '\n');
                if (*cp)
                        cp++;
        }

But I do not see much point in doing so.

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to