]> diplodocus.org Git - nmh/commitdiff
Add EndsWithC(char *s, int c) and call it in some initial places.
authorRalph Corderoy <ralph@inputplus.co.uk>
Wed, 19 Oct 2016 17:13:10 +0000 (18:13 +0100)
committerRalph Corderoy <ralph@inputplus.co.uk>
Wed, 19 Oct 2016 17:13:10 +0000 (18:13 +0100)
EndsWithC returns true if non-NULL string s ends with a c before the
terminating NUL.

h/utils.h
sbr/utils.c
uip/flist.c
uip/folder.c

index edb2ab03d31ca0be32436e8cbdc3fa1cf62a7e2b..db563cb4568f21b13a4b7b72d3b2a75b583c97db 100644 (file)
--- 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);
 
 /*
index d9b903e70e01978630d85bf75f364890106ae71c..7306170952591eefc98f2ea019919d999930db1f 100644 (file)
@@ -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)
index 68dd3f79ee7e9518674a165461513c99c4a9c8f7..84f6ba29427ecbd3619e6dde96343683a9aa3311 100644 (file)
@@ -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;
index c077f7c2ae457ab823b61e62bdd58128215c7119..85e0c53b3d3123c6ca9aa90ea8ba8c41ab25d274 100644 (file)
@@ -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;