From: Ralph Corderoy Date: Wed, 19 Oct 2016 17:13:10 +0000 (+0100) Subject: Add EndsWithC(char *s, int c) and call it in some initial places. X-Git-Url: https://diplodocus.org/git/nmh/commitdiff_plain/f34427874df972004ce8a285145f6fc738f08595?ds=inline;hp=40009883832750cb536db4d41f500c0ad41005de Add EndsWithC(char *s, int c) and call it in some initial places. EndsWithC returns true if non-NULL string s ends with a c before the terminating NUL. --- diff --git a/h/utils.h b/h/utils.h index edb2ab03..db563cb4 100644 --- a/h/utils.h +++ b/h/utils.h @@ -63,6 +63,7 @@ char *find_str (const char [], size_t, const char *); char *rfind_str (const char [], size_t, const char *); char *nmh_strcasestr (const char *, const char *); +bool EndsWithC(char *s, int c); void TrimSuffixC(char *s, int c); /* diff --git a/sbr/utils.c b/sbr/utils.c index d9b903e7..73061709 100644 --- a/sbr/utils.c +++ b/sbr/utils.c @@ -360,6 +360,14 @@ nmh_strcasestr (const char *s1, const char *s2) { } +/* EndsWithC returns true if non-NULL string s ends with a c before the + * terminating NUL. */ +bool EndsWithC(char *s, int c) +{ + return *s && s[strlen(s) - 1] == c; +} + + /* TrimSuffixC deletes c from the end of non-NULL string s if it's * present, shortening s by 1. Only one instance of c is removed. */ void TrimSuffixC(char *s, int c) diff --git a/uip/flist.c b/uip/flist.c index 68dd3f79..84f6ba29 100644 --- a/uip/flist.c +++ b/uip/flist.c @@ -118,8 +118,7 @@ main(int argc, char **argv) * If program was invoked with name ending * in `s', then add switch `-all'. */ - if (argv[0][strlen (argv[0]) - 1] == 's') - all = TRUE; + all = EndsWithC(argv[0], 's'); arguments = getarguments (invo_name, argc, argv, 1); argp = arguments; diff --git a/uip/folder.c b/uip/folder.c index c077f7c2..85e0c53b 100644 --- a/uip/folder.c +++ b/uip/folder.c @@ -118,8 +118,7 @@ main (int argc, char **argv) * If program was invoked with name ending * in `s', then add switch `-all'. */ - if (argv[0][strlen (argv[0]) - 1] == 's') - all = 1; + all = EndsWithC(argv[0], 's'); arguments = getarguments (invo_name, argc, argv, 1); argp = arguments;