make: extract low-level character operations into utility function

Suggested by nia.
https://mail-index.netbsd.org/source-changes-d/2022/01/09/msg013564.html

No functional change.
This commit is contained in:
rillig 2022-01-09 18:59:27 +00:00
parent d150208ab6
commit fb272eaa4b
2 changed files with 15 additions and 7 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: for.c,v 1.164 2022/01/09 14:06:00 rillig Exp $ */
/* $NetBSD: for.c,v 1.165 2022/01/09 18:59:27 rillig Exp $ */
/*
* Copyright (c) 1992, The Regents of the University of California.
@ -58,7 +58,7 @@
#include "make.h"
/* "@(#)for.c 8.1 (Berkeley) 6/6/93" */
MAKE_RCSID("$NetBSD: for.c,v 1.164 2022/01/09 14:06:00 rillig Exp $");
MAKE_RCSID("$NetBSD: for.c,v 1.165 2022/01/09 18:59:27 rillig Exp $");
typedef struct ForLoop {
@ -376,11 +376,8 @@ ForLoop_SubstVarLong(ForLoop *f, unsigned int firstItem, Buffer *body,
for (i = 0; i < f->vars.len; i++) {
const char *p = start;
const char *varname = vars[i];
while (*varname != '\0' && *p == *varname)
p++, varname++;
if (*varname != '\0')
if (!cpp_skip_string(&p, vars[i]))
continue;
/* XXX: why test for backslash here? */
if (*p != ':' && *p != endc && *p != '\\')

View File

@ -1,4 +1,4 @@
/* $NetBSD: make.h,v 1.287 2022/01/07 20:50:35 rillig Exp $ */
/* $NetBSD: make.h,v 1.288 2022/01/09 18:59:27 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@ -896,6 +896,17 @@ cpp_skip_hspace(const char **pp)
(*pp)++;
}
MAKE_INLINE bool
cpp_skip_string(const char **pp, const char *s)
{
const char *p = *pp;
while (*p == *s && *s != '\0')
p++, s++;
if (*s == '\0')
*pp = p;
return *s == '\0';
}
MAKE_INLINE void
pp_skip_whitespace(char **pp)
{