]> git.marmaro.de Git - mmh/commitdiff
Renamed ssequal() to isprefix(), because that's what it checks.
authormarkus schnalke <meillo@marmaro.de>
Sat, 5 Nov 2011 10:47:42 +0000 (11:47 +0100)
committermarkus schnalke <meillo@marmaro.de>
Sat, 5 Nov 2011 10:47:42 +0000 (11:47 +0100)
12 files changed:
h/prototypes.h
sbr/Makefile.in
sbr/isprefix.c [new file with mode: 0644]
sbr/m_convert.c
sbr/path.c
sbr/print_sw.c
sbr/seq_read.c
sbr/ssequal.c [deleted file]
uip/flist.c
uip/folder.c
uip/rmf.c
uip/show.c

index 81c4801d64987b6b45318ab491a1a262a438694a..6200ea66234f495d63bc806a7640e8e946b9b791 100644 (file)
@@ -113,7 +113,7 @@ void seq_setunseen(struct msgs *, int);
 int showfile(char **, char *);
 int smatch(char *, struct swit *);
 char *snprintb(char *, size_t, unsigned, char *);
-int ssequal(char *, char *);
+int isprefix(char *, char *);
 int stringdex(char *, char *);
 char *trimcpy(unsigned char *);
 int unputenv(char *);
index 65a62617a6d77c6691e270357df9a26dfebe1325..0cb7488a19cdd09e8a2a4c4431351388cc79de71 100644 (file)
@@ -72,7 +72,7 @@ SRCS = addrsbr.c ambigsw.c atooi.c brkstring.c  \
        seq_del.c seq_getnum.c seq_list.c seq_nameok.c  \
        seq_print.c seq_read.c seq_save.c seq_setcur.c  \
        seq_setprev.c seq_setunseen.c showfile.c signals.c  \
-       smatch.c snprintb.c ssequal.c strcasecmp.c  \
+       smatch.c snprintb.c isprefix.c strcasecmp.c  \
        strindex.c trimcpy.c uprf.c vfgets.c fmt_def.c  \
        m_msgdef.c mf.c utils.c m_mktemp.c
 
diff --git a/sbr/isprefix.c b/sbr/isprefix.c
new file mode 100644 (file)
index 0000000..33c0699
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+** isprefix.c -- check if a string is a PREFIX of another
+**
+** This code is Copyright (c) 2002, by the authors of nmh.  See the
+** COPYRIGHT file in the root directory of the nmh distribution for
+** complete copyright information.
+*/
+
+#include <h/mh.h>
+
+/*
+** This function had been named ssequal(). It had advertised it would
+** check for substring matching, but actually checked prefix matching.
+** The latter being the thing wanted. Hence, only the name and the
+** descriptions were wrong. I fixed this.
+** -- markus schnalke <meillo@marmaro.de>, 2011-11
+*/
+
+/*
+** Check if s1 is a PREFIX of s2.
+** If yes, then return 1, else return 0.
+*/
+int
+isprefix(char *s1, char *s2)
+{
+       if (!s1)
+               s1 = "";
+       if (!s2)
+               s2 = "";
+
+       while (*s1)
+               if (*s1++ != *s2++)
+                       return 0;
+       return 1;
+}
index 89da537d7202ebab34ba1497d38643d76d9ccc8e..a67305bba4126c7434ef6f9511948187bf02c9f4 100644 (file)
@@ -335,11 +335,12 @@ attr(struct msgs *mp, char *cp)
        /* hack for "cur-name", "cur-n", etc. */
        if (!strcmp(cp, "cur"))
                return 0;
-       if (ssequal("cur:", cp))  /* this code need to be rewritten... */
+       if (isprefix("cur:", cp))  /* this code need to be rewritten... */
                return 0;
 
        /* Check for sequence negation */
-       if ((dp = context_find(nsequence)) && *dp != '\0' && ssequal(dp, cp)) {
+       if ((dp = context_find(nsequence)) && *dp != '\0' &&
+                       isprefix(dp, cp)) {
                inverted = 1;
                cp += strlen(dp);
        }
index b19415ab5eedb74d703569776c5e996ab6c670fc..b13c5fe660b35822d8abb6b3d8998cadaf5a9867 100644 (file)
@@ -54,7 +54,7 @@ expath(char *name, int flag)
                name = m_mailpath(buffer);
                compath(name);
                snprintf(buffer, sizeof(buffer), "%s/", m_maildir(""));
-               if (ssequal(buffer, name)) {
+               if (isprefix(buffer, name)) {
                        cp = name;
                        name = getcpy(name + strlen(buffer));
                        free(cp);
index 6f0c9816287e4357b3ec072474567032815b5eb5..7924fbc7b190d61a3e75591bb6e81a51a195067f 100644 (file)
@@ -20,7 +20,7 @@ print_sw(char *substr, struct swit *swp, char *prefix, FILE *fp)
        len = strlen(substr);
        for (; swp->sw; swp++) {
                /* null matches all strings */
-               if (!*substr || (ssequal(substr, swp->sw) && len >= swp->minchars)) {
+               if (!*substr || (isprefix(substr, swp->sw) && len >= swp->minchars)) {
                        optno = 0;
                        /* next switch */
                        if ((sp = (&swp[1])->sw)) {
index 141c1a2e66b3aedc35b88ad82470ca0fb85b3945..1c231dd66b10f1b73a8767c17af72a6c58f6ceba 100644 (file)
@@ -131,7 +131,7 @@ seq_private(struct msgs *mp)
        plen = strlen(mp->foldpath) + 1;
 
        for (np = m_defs; np; np = np->n_next) {
-               if (ssequal("atr-", np->n_name)
+               if (isprefix("atr-", np->n_name)
                                && (j = strlen(np->n_name) - plen) > alen
                                && *(np->n_name + j) == '-'
                                && strcmp(mp->foldpath, np->n_name + j + 1)
diff --git a/sbr/ssequal.c b/sbr/ssequal.c
deleted file mode 100644 (file)
index 99b1249..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
-** ssequal.c -- check if a string is a substring of another
-**
-** This code is Copyright (c) 2002, by the authors of nmh.  See the
-** COPYRIGHT file in the root directory of the nmh distribution for
-** complete copyright information.
-*/
-
-#include <h/mh.h>
-
-/*
-** THIS CODE DOES NOT WORK AS ADVERTISED.
-** It is actually checking if s1 is a PREFIX of s2.
-** All calls to this function need to be checked to see
-** if that needs to be changed. Prefix checking is cheaper, so
-** should be kept if it's sufficient.
-*/
-
-/*
-** Check if s1 is a substring of s2.
-** If yes, then return 1, else return 0.
-*/
-
-int
-ssequal(char *s1, char *s2)
-{
-       if (!s1)
-               s1 = "";
-       if (!s2)
-               s2 = "";
-
-       while (*s1)
-               if (*s1++ != *s2++)
-                       return 0;
-       return 1;
-}
index 0f44555de992721e0105393a1c06a18d6e0aa41a..a86d226c8430ad3dc592a341bad879f3b4e7b662 100644 (file)
@@ -691,7 +691,7 @@ do_readonly_folders(void)
        atrlen = strlen(atrcur);
 
        for (np = m_defs; np; np = np->n_next)
-               if (ssequal(atrcur, np->n_name)
-                               && !ssequal(nmhdir, np->n_name + atrlen))
+               if (isprefix(atrcur, np->n_name)
+                               && !isprefix(nmhdir, np->n_name + atrlen))
                        BuildFolderList(np->n_name + atrlen, 0);
 }
index 06788b28eb210d9a448f34b764ce4925595bc987..ac931ce349592456c7d4b95aa2666292daf08b10 100644 (file)
@@ -658,7 +658,7 @@ readonly_folders(void)
        atrlen = strlen(atrcur);
 
        for (np = m_defs; np; np = np->n_next)
-               if (ssequal(atrcur, np->n_name)
-                               && !ssequal(nmhdir, np->n_name + atrlen))
+               if (isprefix(atrcur, np->n_name)
+                               && !isprefix(nmhdir, np->n_name + atrlen))
                        get_folder_info(np->n_name + atrlen, NULL);
 }
index 38a93ff86bd9adca00899107acf22bdf6c55d773..fff4abb72aea33b27fcc4d581d0968cc8d78f46b 100644 (file)
--- a/uip/rmf.c
+++ b/uip/rmf.c
@@ -241,7 +241,7 @@ rma(char *folder)
        ** "atr-something-folderpath", and remove them.
        */
        for (np = m_defs, pp = NULL; np; np = np->n_next) {
-               if (ssequal("atr-", np->n_name) &&
+               if (isprefix("atr-", np->n_name) &&
                                (j = strlen(np->n_name) - plen) > alen &&
                                *(np->n_name + j) == '-' &&
                                strcmp(cp, np->n_name + j + 1) == 0) {
index dc6d24e625b3ce64c7ec5c5d84d0b4b751ab3da8..f536af7cfb02da047558b7993a9966a04de96530 100644 (file)
@@ -338,7 +338,7 @@ go_to_it: ;
                        && chdir(maildir =
                        concat(m_maildir(""), "/", NULL)) != NOTOK) {
                mp->foldpath = concat(mp->foldpath, "/", NULL);
-               cp = ssequal(maildir, mp->foldpath)
+               cp = isprefix(maildir, mp->foldpath)
                        ? mp->foldpath + strlen(maildir)
                        : mp->foldpath;
                for (msgnum = procp; msgnum < vecp; msgnum++)