From 0ab8ef8408b8200427abac53ad7e13372ce52d2b Mon Sep 17 00:00:00 2001 From: martynas Date: Wed, 16 Jul 2008 14:53:41 +0000 Subject: [PATCH] - use strncmp/strncasecmp instead of comparing by character - simplify istrlcpy, no need to check for isupper - line[0] is redundant, because strcasecmp will take care of it ok millert@ --- usr.bin/mail/aux.c | 12 +++++------- usr.bin/mail/cmd3.c | 8 +++----- usr.bin/mail/collect.c | 6 +++--- usr.bin/mail/head.c | 6 +++--- usr.bin/mail/send.c | 7 +++---- 5 files changed, 17 insertions(+), 22 deletions(-) diff --git a/usr.bin/mail/aux.c b/usr.bin/mail/aux.c index 92b5b54ee7b..15dbb297c79 100644 --- a/usr.bin/mail/aux.c +++ b/usr.bin/mail/aux.c @@ -1,4 +1,4 @@ -/* $OpenBSD: aux.c,v 1.23 2008/07/15 19:23:26 martynas Exp $ */ +/* $OpenBSD: aux.c,v 1.24 2008/07/16 14:53:41 martynas Exp $ */ /* $NetBSD: aux.c,v 1.5 1997/05/13 06:15:52 mikel Exp $ */ /* @@ -34,7 +34,7 @@ #if 0 static const char sccsid[] = "@(#)aux.c 8.1 (Berkeley) 6/6/93"; #else -static const char rcsid[] = "$OpenBSD: aux.c,v 1.23 2008/07/15 19:23:26 martynas Exp $"; +static const char rcsid[] = "$OpenBSD: aux.c,v 1.24 2008/07/16 14:53:41 martynas Exp $"; #endif #endif /* not lint */ @@ -241,9 +241,7 @@ istrlcpy(char *dst, const char *src, size_t dsize) /* Copy as many bytes as will fit */ if (n != 0 && --n != 0) { do { - if (isupper(*s)) - *d++ = tolower(*s++); - else if ((*d++ = *s++) == 0) + if ((*d++ = tolower(*s++)) == 0) break; } while (--n != 0); } @@ -464,10 +462,10 @@ skin(char *name) break; case ' ': - if (cp[0] == 'a' && cp[1] == 't' && cp[2] == ' ') + if (strncmp(cp, "at ", 3) == 0) cp += 3, *cp2++ = '@'; else - if (cp[0] == '@' && cp[1] == ' ') + if (strncmp(cp, "@ ", 2) == 0) cp += 2, *cp2++ = '@'; else lastsp = 1; diff --git a/usr.bin/mail/cmd3.c b/usr.bin/mail/cmd3.c index 8560502735c..bd618857dcf 100644 --- a/usr.bin/mail/cmd3.c +++ b/usr.bin/mail/cmd3.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd3.c,v 1.20 2003/06/03 02:56:11 millert Exp $ */ +/* $OpenBSD: cmd3.c,v 1.21 2008/07/16 14:53:41 martynas Exp $ */ /* $NetBSD: cmd3.c,v 1.8 1997/07/09 05:29:49 mikel Exp $ */ /* @@ -34,7 +34,7 @@ #if 0 static const char sccsid[] = "@(#)cmd3.c 8.2 (Berkeley) 4/20/95"; #else -static const char rcsid[] = "$OpenBSD: cmd3.c,v 1.20 2003/06/03 02:56:11 millert Exp $"; +static const char rcsid[] = "$OpenBSD: cmd3.c,v 1.21 2008/07/16 14:53:41 martynas Exp $"; #endif #endif /* not lint */ @@ -265,9 +265,7 @@ reedit(char *subj) if (subj == NULL) return(NULL); - if ((subj[0] == 'r' || subj[0] == 'R') && - (subj[1] == 'e' || subj[1] == 'E') && - subj[2] == ':') + if (strncasecmp(subj, "re:", 3) == 0) return(subj); len = strlen(subj) + 5; newsubj = salloc(len); diff --git a/usr.bin/mail/collect.c b/usr.bin/mail/collect.c index aca48520a34..edb86cfc65d 100644 --- a/usr.bin/mail/collect.c +++ b/usr.bin/mail/collect.c @@ -1,4 +1,4 @@ -/* $OpenBSD: collect.c,v 1.28 2007/09/10 14:29:53 tobias Exp $ */ +/* $OpenBSD: collect.c,v 1.29 2008/07/16 14:53:41 martynas Exp $ */ /* $NetBSD: collect.c,v 1.9 1997/07/09 05:25:45 mikel Exp $ */ /* @@ -34,7 +34,7 @@ #if 0 static const char sccsid[] = "@(#)collect.c 8.2 (Berkeley) 4/19/94"; #else -static const char rcsid[] = "$OpenBSD: collect.c,v 1.28 2007/09/10 14:29:53 tobias Exp $"; +static const char rcsid[] = "$OpenBSD: collect.c,v 1.29 2008/07/16 14:53:41 martynas Exp $"; #endif #endif /* not lint */ @@ -533,7 +533,7 @@ forward(char *ms, FILE *fp, char *fn, int f) } msgvec[1] = NULL; } - if (f == 'f' || f == 'F') + if (tolower(f) == 'f') tabst = NULL; else if ((tabst = value("indentprefix")) == NULL) tabst = "\t"; diff --git a/usr.bin/mail/head.c b/usr.bin/mail/head.c index 1784947d5f3..0bd9b48d475 100644 --- a/usr.bin/mail/head.c +++ b/usr.bin/mail/head.c @@ -1,4 +1,4 @@ -/* $OpenBSD: head.c,v 1.9 2003/06/03 02:56:11 millert Exp $ */ +/* $OpenBSD: head.c,v 1.10 2008/07/16 14:53:41 martynas Exp $ */ /* $NetBSD: head.c,v 1.6 1996/12/28 07:11:03 tls Exp $ */ /* @@ -34,7 +34,7 @@ #if 0 static const char sccsid[] = "@(#)head.c 8.2 (Berkeley) 4/20/95"; #else -static const char rcsid[] = "$OpenBSD: head.c,v 1.9 2003/06/03 02:56:11 millert Exp $"; +static const char rcsid[] = "$OpenBSD: head.c,v 1.10 2008/07/16 14:53:41 martynas Exp $"; #endif #endif /* not lint */ @@ -114,7 +114,7 @@ parse(char *line, struct headline *hl, char *pbuf) cp = nextword(cp, word); if (*word) hl->l_from = copyin(word, &sp); - if (cp != NULL && cp[0] == 't' && cp[1] == 't' && cp[2] == 'y') { + if (cp != NULL && strncmp(cp, "tty", 3) == 0) { cp = nextword(cp, word); hl->l_tty = copyin(word, &sp); } diff --git a/usr.bin/mail/send.c b/usr.bin/mail/send.c index eaaa66ee82a..eeed4e4bff0 100644 --- a/usr.bin/mail/send.c +++ b/usr.bin/mail/send.c @@ -1,4 +1,4 @@ -/* $OpenBSD: send.c,v 1.18 2007/03/20 21:01:08 millert Exp $ */ +/* $OpenBSD: send.c,v 1.19 2008/07/16 14:53:41 martynas Exp $ */ /* $NetBSD: send.c,v 1.6 1996/06/08 19:48:39 christos Exp $ */ /* @@ -34,7 +34,7 @@ #if 0 static const char sccsid[] = "@(#)send.c 8.1 (Berkeley) 6/6/93"; #else -static const char rcsid[] = "$OpenBSD: send.c,v 1.18 2007/03/20 21:01:08 millert Exp $"; +static const char rcsid[] = "$OpenBSD: send.c,v 1.19 2008/07/16 14:53:41 martynas Exp $"; #endif #endif /* not lint */ @@ -167,8 +167,7 @@ sendmessage(struct message *mp, FILE *obuf, struct ignoretab *doign, *cp2 = 0; /* temporarily null terminate */ if (doign && isign(line, doign)) ignoring = 1; - else if ((line[0] == 's' || line[0] == 'S') && - strcasecmp(line, "status") == 0) { + else if (strcasecmp(line, "status") == 0) { /* * If the field is "status," go compute * and print the real Status: field -- 2.20.1