]> git.marmaro.de Git - mmh/commitdiff
Removed isprefix() and replaced it with strncmp().
authormarkus schnalke <meillo@marmaro.de>
Thu, 5 Jan 2012 11:26:09 +0000 (12:26 +0100)
committermarkus schnalke <meillo@marmaro.de>
Thu, 5 Jan 2012 11:26:09 +0000 (12:26 +0100)
isprefix() had been ssequal(), which had not been what it advertised to be.
Now, all this is gone.
We could get problems if one of the arguments is NULL, as isprefix()
handled this situation, but strncmp() does not. It appears as if this case
does not show up in the code.

h/prototypes.h
sbr/Makefile.in
sbr/isprefix.c [deleted file]
sbr/m_convert.c
sbr/print_sw.c
sbr/seq_read.c
uip/flist.c
uip/folder.c
uip/rmf.c
uip/show.c

index 5e5672ce4ae9263af4b47c121c23170d22e5a6ee..0b191f06412355fc272ec82acb4f014acce3a8fc 100644 (file)
@@ -111,7 +111,6 @@ void seq_setunseen(struct msgs *, int);
 int showfile(char **, char *);
 int smatch(char *, struct swit *);
 char *snprintb(char *, size_t, unsigned, char *);
-int isprefix(char *, char *);
 int stringdex(char *, char *);
 char *toabsdir(char *);
 char *trimcpy(unsigned char *);
index b42dd49b07a00dab485f7c7972d8b27fbaecf7d6..95ff94c0f64b1e87fbe64876d6b8d43c32585e46 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 isprefix.c strcasecmp.c  \
+       smatch.c snprintb.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
deleted file mode 100644 (file)
index 33c0699..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
-** 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 b535fe3a9b20b4e26d13fb02803bea83d3b2f69a..df128d7dd9e9e1c80064e6adb8e6348c5e055ba7 100644 (file)
@@ -354,7 +354,7 @@ attr(struct msgs *mp, char *cp)
        if (!(dp = context_find(nsequence))) {
                dp = seq_neg;  /* use default */
        }
-       if (dp && *dp && isprefix(dp, cp)) {
+       if (*dp && strncmp(cp, dp, strlen(dp))==0) {
                inverted = 1;
                cp += strlen(dp);
        }
index 7924fbc7b190d61a3e75591bb6e81a51a195067f..3a70c5455859a58b327ffdab872f6a250fe496e2 100644 (file)
@@ -20,7 +20,8 @@ print_sw(char *substr, struct swit *swp, char *prefix, FILE *fp)
        len = strlen(substr);
        for (; swp->sw; swp++) {
                /* null matches all strings */
-               if (!*substr || (isprefix(substr, swp->sw) && len >= swp->minchars)) {
+               if (!*substr || (strncmp(swp->sw, substr, len)==0 &&
+                               len >= swp->minchars)) {
                        optno = 0;
                        /* next switch */
                        if ((sp = (&swp[1])->sw)) {
index c1ac9fa72ad593e54e19f74df16a633f3ec8622f..3a9633eb205ee9daa0052e07f9b9a5b3e09b7244 100644 (file)
@@ -132,7 +132,7 @@ seq_private(struct msgs *mp)
        plen = strlen(mp->foldpath) + 1;
 
        for (np = m_defs; np; np = np->n_next) {
-               if (isprefix("atr-", np->n_name)
+               if (strncmp(np->n_name, "atr-", alen)==0
                                && (j = strlen(np->n_name) - plen) > alen
                                && *(np->n_name + j) == '-'
                                && strcmp(mp->foldpath, np->n_name + j + 1)
index 847bb3652d20d7dcd3ef9422e8a75af319ed1478..c4d9a3b1f33f883d55c69480cf0f4c64d86bb1f9 100644 (file)
@@ -687,7 +687,8 @@ do_readonly_folders(void)
        atrlen = strlen(atrcur);
 
        for (np = m_defs; np; np = np->n_next)
-               if (isprefix(atrcur, np->n_name)
-                               && !isprefix(nmhdir, np->n_name + atrlen))
+               if (strncmp(np->n_name, atrcur, atrlen)==0
+                               && strncmp(np->n_name+atrlen, nmhdir, strlen(nmhdir))!=0)
+                       /* Why do we exclude absolute path names? --meillo */
                        BuildFolderList(np->n_name + atrlen, 0);
 }
index 224bb03479a53681ac3e2517ca3e07b995be55e1..ae7bac5362054d276adaca5151fb9ee0910a22ff 100644 (file)
@@ -656,7 +656,8 @@ readonly_folders(void)
        atrlen = strlen(atrcur);
 
        for (np = m_defs; np; np = np->n_next)
-               if (isprefix(atrcur, np->n_name)
-                               && !isprefix(nmhdir, np->n_name + atrlen))
+               if (strncmp(np->n_name, atrcur, atrlen)==0 &&
+                               strncmp(np->n_name+atrlen, nmhdir, strlen(nmhdir))!=0)
+                       /* Why do we exclude absolute path names? --meillo */
                        get_folder_info(np->n_name + atrlen, NULL);
 }
index 923f23aed377c6887da6f151efe83719e86d45ba..48a555e9bd89da605f93e7f51217196e86677214 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 (isprefix("atr-", np->n_name) &&
+               if (strncmp(np->n_name, "atr-", alen)==0 &&
                                (j = strlen(np->n_name) - plen) > alen &&
                                *(np->n_name + j) == '-' &&
                                strcmp(cp, np->n_name + j + 1) == 0) {
index 671a4419eccd3d4a73fb7a69550bf730f61191d5..999272b0aa766e2e6e5799d5632725cfca9bc72d 100644 (file)
@@ -340,9 +340,9 @@ go_to_it: ;
                        && chdir(maildir =
                        concat(toabsdir("+"), "/", NULL)) != NOTOK) {
                mp->foldpath = concat(mp->foldpath, "/", NULL);
-               cp = isprefix(maildir, mp->foldpath)
-                       ? mp->foldpath + strlen(maildir)
-                       mp->foldpath;
+               cp = (strncmp(mp->foldpath, maildir, strlen(maildir))==0) ?
+                       mp->foldpath + strlen(maildir) :
+                       mp->foldpath;
                for (msgnum = procp; msgnum < vecp; msgnum++)
                        vec[msgnum] = concat(cp, vec[msgnum], NULL);
        }