From 16536d59024177409f49134c3f03f69855c144b9 Mon Sep 17 00:00:00 2001 From: Pierre Habouzit Date: Fri, 17 Nov 2006 10:46:22 +0100 Subject: [PATCH] more simplifications. Signed-off-by: Pierre Habouzit --- copy.c | 6 ++--- imap/auth_sasl.c | 2 +- imap/browse.c | 9 +++---- imap/command.c | 4 +-- imap/imap.c | 4 +-- init.c | 8 +++--- lib-lib/Makefile.am | 14 ++++------ lib-lib/ascii.c | 66 --------------------------------------------- lib-lib/ascii.h | 55 ------------------------------------- lib-lib/lib-lib.h | 37 +++++++++++++++++++++++-- lib-lib/macros.h | 57 --------------------------------------- lib-lib/str.c | 38 ++++++++++++++++++++++++++ lib-lib/str.h | 21 +++++++++++++++ lib-mime/rfc3676.c | 2 +- 14 files changed, 115 insertions(+), 208 deletions(-) delete mode 100644 lib-lib/ascii.c delete mode 100644 lib-lib/ascii.h delete mode 100644 lib-lib/macros.h diff --git a/copy.c b/copy.c index 3a010d4..65ed14c 100644 --- a/copy.c +++ b/copy.c @@ -125,9 +125,9 @@ mutt_copy_hdr (FILE* in, FILE* out, off_t off_start, off_t off_end, if (nl && buf[0] != ' ' && buf[0] != '\t') { /* set curline to 1 for To:/Cc:/Bcc: and 0 otherwise */ - curline = (flags & CH_WEED) && (ascii_strncmp ("To:", buf, 3) == 0 || - ascii_strncmp ("Cc:", buf, 3) == 0 || - ascii_strncmp ("Bcc:", buf, 4) == 0); + curline = (flags & CH_WEED) && (m_strncmp("To:", buf, 3) == 0 || + m_strncmp("Cc:", buf, 3) == 0 || + m_strncmp("Bcc:", buf, 4) == 0); /* Do we have anything pending? */ if (this_one) { diff --git a/imap/auth_sasl.c b/imap/auth_sasl.c index 54c972b..a387758 100644 --- a/imap/auth_sasl.c +++ b/imap/auth_sasl.c @@ -52,7 +52,7 @@ imap_auth_res_t imap_auth_sasl (IMAP_DATA * idata, const char *method) if (mutt_bit_isset (idata->capabilities, AUTH_ANON) && (!idata->conn->account.user[0] || - !ascii_strncmp (idata->conn->account.user, "anonymous", 9))) + !m_strncmp(idata->conn->account.user, "anonymous", 9))) rc = sasl_client_start (saslconn, "AUTH=ANONYMOUS", NULL, &pc, &olen, &mech); } diff --git a/imap/browse.c b/imap/browse.c index 46730fd..a3807b6 100644 --- a/imap/browse.c +++ b/imap/browse.c @@ -112,8 +112,7 @@ int imap_browse (char *path, struct browser_state *state) mbox[n] = '\0'; } } - } - while (ascii_strncmp (idata->cmd.buf, idata->cmd.seq, SEQLEN)); + } while (m_strncmp(idata->cmd.buf, idata->cmd.seq, SEQLEN)); } /* if we're descending a folder, mark it as current in browser_state */ @@ -346,8 +345,7 @@ static int browse_add_list_result (IMAP_DATA * idata, const char *cmd, imap_add_folder (idata->delim, name, noselect, noinferiors, state, isparent); } - } - while ((ascii_strncmp (idata->cmd.buf, idata->cmd.seq, SEQLEN) != 0)); + } while ((m_strncmp(idata->cmd.buf, idata->cmd.seq, SEQLEN) != 0)); p_delete(&mx.mbox); return 0; @@ -543,8 +541,7 @@ static int browse_verify_namespace (IMAP_DATA * idata, &nsi->noinferiors, &delim) != 0) return -1; nsi->listable |= (name != NULL); - } - while ((ascii_strncmp (idata->cmd.buf, idata->cmd.seq, SEQLEN) != 0)); + } while ((m_strncmp(idata->cmd.buf, idata->cmd.seq, SEQLEN) != 0)); } return 0; diff --git a/imap/command.c b/imap/command.c index 83ebbe7..8b93712 100644 --- a/imap/command.c +++ b/imap/command.c @@ -125,7 +125,7 @@ int imap_cmd_step (IMAP_DATA * idata) idata->lastread = time (NULL); /* handle untagged messages. The caller still gets its shot afterwards. */ - if (!ascii_strncmp (cmd->buf, "* ", 2) && cmd_handle_untagged (idata)) + if (!m_strncmp(cmd->buf, "* ", 2) && cmd_handle_untagged (idata)) return IMAP_CMD_BAD; /* server demands a continuation response from us */ @@ -133,7 +133,7 @@ int imap_cmd_step (IMAP_DATA * idata) return IMAP_CMD_RESPOND; /* tagged completion code */ - if (!ascii_strncmp (cmd->buf, cmd->seq, SEQLEN)) { + if (!m_strncmp(cmd->buf, cmd->seq, SEQLEN)) { imap_cmd_finish (idata); return imap_code (cmd->buf) ? IMAP_CMD_OK : IMAP_CMD_NO; } diff --git a/imap/imap.c b/imap/imap.c index 3bb4f8a..e426e33 100644 --- a/imap/imap.c +++ b/imap/imap.c @@ -57,7 +57,7 @@ int imap_access (const char *path, int flags __attribute__ ((unused))) imap_fix_path (idata, mx.mbox, mailbox, sizeof (mailbox)); /* we may already be in the folder we're checking */ - if (!ascii_strcmp(idata->mailbox, mx.mbox)) { + if (!m_strcmp(idata->mailbox, mx.mbox)) { p_delete(&mx.mbox); return 0; } @@ -1543,7 +1543,7 @@ int imap_complete (char *dest, size_t dlen, char *path) { completions++; } } - while (ascii_strncmp (idata->cmd.seq, idata->cmd.buf, SEQLEN)); + while (m_strncmp(idata->cmd.seq, idata->cmd.buf, SEQLEN)); if (completions) { /* reformat output */ diff --git a/init.c b/init.c index bf5c64a..9647764 100644 --- a/init.c +++ b/init.c @@ -238,14 +238,14 @@ static void sys_to_string (char* dst, ssize_t dstlen, int clean = 0; /* get some $madmutt_ values dynamically */ - if (ascii_strcmp ("madmutt_pwd", option->option) == 0) { + if (m_strcmp("madmutt_pwd", option->option) == 0) { val = p_new(char, _POSIX_PATH_MAX); val = getcwd (val, _POSIX_PATH_MAX-1); clean = 1; - } else if (ascii_strcmp ("madmutt_folder_path", option->option) == 0 && + } else if (m_strcmp("madmutt_folder_path", option->option) == 0 && CurrentFolder && *CurrentFolder) { val = CurrentFolder; - } else if (ascii_strcmp ("madmutt_folder_name", option->option) == 0 && + } else if (m_strcmp("madmutt_folder_name", option->option) == 0 && CurrentFolder && *CurrentFolder) { ssize_t Maildirlength = m_strlen(Maildir); @@ -1811,7 +1811,7 @@ static int parse_set (BUFFER * tmp, BUFFER * s, unsigned long data, } /* see if we need to add $user_ var */ - if (!option && ascii_strncmp ("user_", tmp->data, 5) == 0) { + if (!option && m_strncmp("user_", tmp->data, 5) == 0) { /* there's no option named like this yet so only add one * if the action isn't any of: reset, unset, query */ if (!(reset || unset || query || *s->dptr != '=')) { diff --git a/lib-lib/Makefile.am b/lib-lib/Makefile.am index d605e34..17c2e93 100644 --- a/lib-lib/Makefile.am +++ b/lib-lib/Makefile.am @@ -1,14 +1,10 @@ noinst_LIBRARIES = liblib.a -liblib_a_SOURCES = lib-lib.h mem.h macros.h \ - str.h ascii.h buffer.h hash.h list.h file.h mapping.h \ - str.c ascii.c buffer.c hash.c list.c file.c mapping.c \ - \ - date.h rx.h url.h \ - date.c rx.c url.c +liblib_a_SOURCES = lib-lib.h mem.h \ + str.h buffer.h hash.h list.h file.h mapping.h date.h rx.h url.h \ + str.c buffer.c hash.c list.c file.c mapping.c date.c rx.c url.c -noinst_HEADERS = lib-lib.h mem.h macros.h \ - str.h ascii.h buffer.h hash.h list.h file.h mapping.h \ - date.h rx.h url.h +noinst_HEADERS = lib-lib.h mem.h \ + str.h buffer.h hash.h list.h file.h mapping.h date.h rx.h url.h -include ../cflags.mk diff --git a/lib-lib/ascii.c b/lib-lib/ascii.c deleted file mode 100644 index 73ffbc8..0000000 --- a/lib-lib/ascii.c +++ /dev/null @@ -1,66 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or (at - * your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301, USA. - * - * Copyright © 2006 Pierre Habouzit - */ -/* - * Copyright notice from original mutt: - * Copyright (C) 2001 Thomas Roessler - */ - -/* - * Versions of the string comparison functions which are locale-insensitive. - */ - -#include "lib-lib.h" - -int ascii_strcasecmp(const char *a, const char *b) -{ - int i; - - if (a == b) - return 0; - if (a == NULL && b) - return -1; - if (b == NULL && a) - return 1; - - for (; *a || *b; a++, b++) { - if ((i = ascii_tolower(*a) - ascii_tolower(*b))) - return i; - } - - return 0; -} - -int ascii_strncasecmp (const char *a, const char *b, int n) -{ - int i, j; - - if (a == b) - return 0; - if (a == NULL && b) - return -1; - if (b == NULL && a) - return 1; - - for (j = 0; (*a || *b) && j < n; a++, b++, j++) { - if ((i = ascii_tolower(*a) - ascii_tolower(*b))) - return i; - } - - return 0; -} diff --git a/lib-lib/ascii.h b/lib-lib/ascii.h deleted file mode 100644 index b449d8d..0000000 --- a/lib-lib/ascii.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or (at - * your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301, USA. - * - * Copyright © 2006 Pierre Habouzit - */ -/* - * Copyright notice from original mutt: - * Copyright (C) 2001 Thomas Roessler - */ - -#ifndef MUTT_LIB_LIB_ASCII_H -#define MUTT_LIB_LIB_ASCII_H - -static inline int ascii_isupper(int c) { - return c >= 'A' && c <= 'Z'; -} - -static inline int ascii_islower(int c) { - return c >= 'a' && c <= 'z'; -} - -static inline int ascii_toupper(int c) { - if (ascii_islower(c)) - return c & ~32; - - return c; -} - -static inline int ascii_tolower(int c) { - if (ascii_isupper(c)) - return c | 32; - - return c; -} - -int ascii_strcasecmp(const char *a, const char *b); -int ascii_strncasecmp(const char *a, const char *b, int n); - -#define ascii_strcmp(a,b) m_strcmp(a,b) -#define ascii_strncmp(a,b,c) m_strncmp(a,b,c) - -#endif /* MUTT_LIB_LIB_ASCII_H */ diff --git a/lib-lib/lib-lib.h b/lib-lib/lib-lib.h index 8cd91c2..90cea2f 100644 --- a/lib-lib/lib-lib.h +++ b/lib-lib/lib-lib.h @@ -24,6 +24,12 @@ # include "../config.h" #endif +#ifndef __GNUC__ +# define __attribute__(a) +#endif + +/* very common and usual headers we just want to have available {{{ */ + #include #include #include @@ -65,11 +71,38 @@ #include #endif +/* }}} */ +/* useful and common macros {{{ */ + +#ifdef _ +# undef _ +#endif + +#ifdef ENABLE_NLS +# include +#define _(a) (gettext(a)) +# ifdef gettext_noop +# define N_(a) gettext_noop(a) +# else +# define N_(a) (a) +# endif +#else +# define _(a) (a) +# define N_(a) (a) +#endif + +#define TRUE 1 +#define FALSE 0 + +#undef MAX +#undef MIN +#define MAX(a,b) ((a) < (b) ? (b) : (a)) +#define MIN(a,b) ((a) < (b) ? (a) : (b)) + +/* }}} */ -#include "macros.h" #include "mem.h" -#include "ascii.h" #include "str.h" #include "buffer.h" #include "date.h" diff --git a/lib-lib/macros.h b/lib-lib/macros.h deleted file mode 100644 index 75c734a..0000000 --- a/lib-lib/macros.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or (at - * your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301, USA. - * - * Copyright © 2006 Pierre Habouzit - */ - -#ifndef MUTT_LIB_LIB_MACROS_H -#define MUTT_LIB_LIB_MACROS_H - -#ifndef __GNUC__ -# define __attribute__(a) -#endif - -/* - * config.h must be included by source file! - */ - -#ifdef _ -# undef _ -#endif - -#ifdef ENABLE_NLS -# include -#define _(a) (gettext(a)) -# ifdef gettext_noop -# define N_(a) gettext_noop(a) -# else -# define N_(a) (a) -# endif -#else -# define _(a) (a) -# define N_(a) (a) -#endif - - -#define TRUE 1 -#define FALSE 0 - -#undef MAX -#undef MIN -#define MAX(a,b) ((a) < (b) ? (b) : (a)) -#define MIN(a,b) ((a) < (b) ? (a) : (b)) - -#endif /* MUTT_LIB_LIB_MACROS_H */ diff --git a/lib-lib/str.c b/lib-lib/str.c index f55aa45..7b57305 100644 --- a/lib-lib/str.c +++ b/lib-lib/str.c @@ -140,3 +140,41 @@ const char *m_stristrn(const char *haystack, const char *needle, ssize_t nlen) haystack++; } } + +int ascii_strcasecmp(const char *a, const char *b) +{ + int i; + + if (a == b) + return 0; + if (a == NULL && b) + return -1; + if (b == NULL && a) + return 1; + + for (; *a || *b; a++, b++) { + if ((i = ascii_tolower(*a) - ascii_tolower(*b))) + return i; + } + + return 0; +} + +int ascii_strncasecmp (const char *a, const char *b, ssize_t n) +{ + int i, j; + + if (a == b) + return 0; + if (a == NULL && b) + return -1; + if (b == NULL && a) + return 1; + + for (j = 0; (*a || *b) && j < n; a++, b++, j++) { + if ((i = ascii_tolower(*a) - ascii_tolower(*b))) + return i; + } + + return 0; +} diff --git a/lib-lib/str.h b/lib-lib/str.h index c9c8c90..a5791c3 100644 --- a/lib-lib/str.h +++ b/lib-lib/str.h @@ -16,6 +16,10 @@ * * Copyright © 2006 Pierre Habouzit */ +/* + * Copyright notice from original mutt: + * Copyright (C) 2001 Thomas Roessler + */ #ifndef MUTT_LIB_LIB_STR_H #define MUTT_LIB_LIB_STR_H @@ -52,6 +56,20 @@ static inline void m_strtolower(char *p) { *p = tolower((unsigned char)*p); } +static inline int ascii_toupper(int c) { + if ('a' <= c && c <= 'z') + return c & ~32; + + return c; +} + +static inline int ascii_tolower(int c) { + if ('A' <= c && c <= 'Z') + return c | 32; + + return c; +} + /****************************************************************************/ /* length related */ /****************************************************************************/ @@ -89,6 +107,9 @@ static inline int m_strncasecmp(const char *a, const char *b, ssize_t n) { return strncasecmp(NONULL(a), NONULL(b), n); } +int ascii_strcasecmp(const char *a, const char *b); +int ascii_strncasecmp(const char *a, const char *b, ssize_t n); + /****************************************************************************/ /* making copies */ /****************************************************************************/ diff --git a/lib-mime/rfc3676.c b/lib-mime/rfc3676.c index 7350188..e9ae0a7 100644 --- a/lib-mime/rfc3676.c +++ b/lib-mime/rfc3676.c @@ -217,7 +217,7 @@ void rfc3676_space_stuff (HEADER* hdr) { } while (fgets (buf, sizeof (buf), in)) { - if (ascii_strncmp ("From ", buf, 4) == 0 || buf[0] == ' ') { + if (m_strncmp("From ", buf, 4) == 0 || buf[0] == ' ') { fputc (' ', out); } fputs (buf, out); -- 2.20.1