From 6b64788a107c346c571af801c8b1d51326778a20 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Tue, 13 Aug 2024 16:33:12 -0500 Subject: [PATCH] Move anystart() to lib/lib.c --- lib/lib.c | 10 ++++++++++ lib/lib.h | 1 + toys/pending/sh.c | 10 ---------- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/lib/lib.c b/lib/lib.c index dc578804..75ac51dc 100644 --- a/lib/lib.c +++ b/lib/lib.c @@ -522,6 +522,16 @@ int strcasestart(char **a, char *b) return i; } +// return length of match found at this point (try is null terminated array) +int anystart(char *s, char **try) +{ + char *ss = s; + + while (*try) if (strstart(&s, *try++)) return s-ss; + + return 0; +} + int same_file(struct stat *st1, struct stat *st2) { return st1->st_ino==st2->st_ino && st1->st_dev==st2->st_dev; diff --git a/lib/lib.h b/lib/lib.h index 23b1e680..dd18cdf2 100644 --- a/lib/lib.h +++ b/lib/lib.h @@ -232,6 +232,7 @@ int unescape2(char **c, int echo); char *strend(char *str, char *suffix); int strstart(char **a, char *b); int strcasestart(char **a, char *b); +int anystart(char *s, char **try); int same_file(struct stat *st1, struct stat *st2); int same_dev_ino(struct stat *st, struct dev_ino *di); off_t fdlength(int fd); diff --git a/toys/pending/sh.c b/toys/pending/sh.c index 5ae18d3f..87a4633a 100644 --- a/toys/pending/sh.c +++ b/toys/pending/sh.c @@ -815,16 +815,6 @@ static int utf8chr(char *wc, char *chrs, int *len) return 0; } -// return length of match found at this point (try is null terminated array) -static int anystart(char *s, char **try) -{ - char *ss = s; - - while (*try) if (strstart(&s, *try++)) return s-ss; - - return 0; -} - // does this entire string match one of the strings in try[] static int anystr(char *s, char **try) { -- 2.39.2