From: pdmef Date: Thu, 16 Jun 2005 11:06:44 +0000 (+0000) Subject: - move some string functions out to lib/str.[ch], add str_eq() X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=commitdiff_plain;h=93f817273e1c70071cd5471594600bc70f12f0ff - move some string functions out to lib/str.[ch], add str_eq() - use str_eq() to better detect which box is currently open (tries to fix bug #4258 + #3972 and feature request #512) git-svn-id: svn://svn.berlios.de/mutt-ng/trunk@313 e385b8ad-14ed-0310-8656-cc95a2468c6d --- diff --git a/buffy.c b/buffy.c index 7290fa6..7c8555a 100644 --- a/buffy.c +++ b/buffy.c @@ -178,7 +178,7 @@ int buffy_lookup (const char* path) { if (list_empty(Incoming) || !path || !*path) return (-1); for (i = 0; i < Incoming->length; i++) { - if (safe_strcmp (((BUFFY*) Incoming->data[i])->path, path) == 0) + if (str_eq (((BUFFY*) Incoming->data[i])->path, path) ) return (i); } return (-1); @@ -198,7 +198,7 @@ int buffy_parse_mailboxes (BUFFER * path, BUFFER * s, unsigned long data, mutt_extract_token (path, s, 0); strfcpy (buf, path->data, sizeof (buf)); - if (data == M_UNMAILBOXES && safe_strcmp (buf, "*") == 0) { + if (data == M_UNMAILBOXES && str_eq (buf, "*") == 0) { list_del (&Incoming, buffy_free); return 0; } @@ -330,8 +330,8 @@ int buffy_check (int force) /* check to see if the folder is the currently selected folder * before polling */ if (!Context || !Context->path || (local ? (sb.st_dev != contex_sb.st_dev || - sb.st_ino != contex_sb.st_ino) : - safe_strcmp (tmp->path, Context->path))) { + sb.st_ino != contex_sb.st_ino) : + !str_eq (tmp->path, Context->path))) { switch (tmp->magic) { case M_MBOX: case M_MMDF: @@ -590,7 +590,8 @@ void buffy_next (char *s, size_t slen) i = 1 + buffy_lookup (s); for (l=0; l < Incoming->length; l++) { c = (l+i) % Incoming->length; - if (((BUFFY*) Incoming->data[c])->new > 0) + if ((!Context || !Context->path || !str_eq (((BUFFY*) Incoming->data[c])->path, Context->path)) && + ((BUFFY*) Incoming->data[c])->new > 0) break; } if (l >= Incoming->length) { diff --git a/compose.c b/compose.c index 960f124..9dc603d 100644 --- a/compose.c +++ b/compose.c @@ -618,8 +618,8 @@ int mutt_compose_menu (HEADER * msg, /* structure for new message */ if (mutt_get_field ("Newsgroups: ", buf, sizeof (buf), 0) == 0 && buf[0]) { FREE (&msg->env->newsgroups); - mutt_remove_trailing_ws (buf); - msg->env->newsgroups = safe_strdup (mutt_skip_whitespace (buf)); + str_skip_trailws (buf); + msg->env->newsgroups = safe_strdup (str_skip_initws (buf)); move (HDR_TO, HDR_XOFFSET); clrtoeol (); if (msg->env->newsgroups) @@ -636,8 +636,8 @@ int mutt_compose_menu (HEADER * msg, /* structure for new message */ if (mutt_get_field ("Followup-To: ", buf, sizeof (buf), 0) == 0 && buf[0]) { FREE (&msg->env->followup_to); - mutt_remove_trailing_ws (buf); - msg->env->followup_to = safe_strdup (mutt_skip_whitespace (buf)); + str_skip_trailws (buf); + msg->env->followup_to = safe_strdup (str_skip_initws (buf)); move (HDR_CC, HDR_XOFFSET); clrtoeol (); if (msg->env->followup_to) diff --git a/curs_main.c b/curs_main.c index ef26f81..4e771f5 100644 --- a/curs_main.c +++ b/curs_main.c @@ -1227,7 +1227,6 @@ int mutt_index_menu (void) else #endif mutt_expand_path (buf, sizeof (buf)); - sidebar_set_current (buf); if (mx_get_magic (buf) <= 0) { mutt_error (_("%s is not a mailbox."), buf); break; @@ -1272,6 +1271,7 @@ int mutt_index_menu (void) } else menu->current = 0; + sidebar_set_current (buf); #ifdef USE_NNTP /* buffy_check() must be done with mail-reader mode! */ diff --git a/imap/browse.c b/imap/browse.c index 9911fe5..e5d009f 100644 --- a/imap/browse.c +++ b/imap/browse.c @@ -55,7 +55,7 @@ int imap_browse (char *path, struct browser_state *state) int i; int nsup; char ctmp; - int nns; + int nns = 0; char *cur_folder; short showparents = 0; int noselect; diff --git a/imap/imap.c b/imap/imap.c index 0aa906b..90eae14 100644 --- a/imap/imap.c +++ b/imap/imap.c @@ -905,7 +905,7 @@ int imap_sync_message (IMAP_DATA *idata, HEADER *hdr, BUFFER *cmd, if (mutt_bit_isset (idata->rights, ACL_WRITE)) imap_add_keywords (flags, hdr, idata->flags, sizeof (flags)); - mutt_remove_trailing_ws (flags); + str_skip_trailws (flags); /* UW-IMAP is OK with null flags, Cyrus isn't. The only solution is to * explicitly revoke all system flags (if we have permission) */ @@ -916,7 +916,7 @@ int imap_sync_message (IMAP_DATA *idata, HEADER *hdr, BUFFER *cmd, imap_set_flag (idata, ACL_WRITE, 1, "\\Answered ", flags, sizeof (flags)); imap_set_flag (idata, ACL_DELETE, 1, "\\Deleted ", flags, sizeof (flags)); - mutt_remove_trailing_ws (flags); + str_skip_trailws (flags); mutt_buffer_addstr (cmd, " -FLAGS.SILENT ("); } else diff --git a/lib.h b/lib.h index b12b8cc..5dc28bf 100644 --- a/lib.h +++ b/lib.h @@ -50,7 +50,6 @@ FILE *safe_fopen (const char *, const char *); char *mutt_concat_path (char *, const char *, const char *, size_t); char *mutt_read_line (char *, size_t *, FILE *, int *); -char *mutt_skip_whitespace (char *); const char *mutt_basename (const char *); @@ -66,7 +65,6 @@ int safe_fclose (FILE **); size_t mutt_quote_filename (char *, size_t, const char *); void mutt_nocurses_error (const char *, ...); -void mutt_remove_trailing_ws (char *); void mutt_sanitize_filename (char *, short); void mutt_unlink (const char *); diff --git a/lib/str.c b/lib/str.c index 8efa126..a9a9beb 100644 --- a/lib/str.c +++ b/lib/str.c @@ -175,14 +175,20 @@ const char *str_isstr (const char *haystack, const char *needle) return NULL; } -char *mutt_skip_whitespace (char *p) -{ - SKIPWS (p); - return p; +int str_eq (const char* s1, const char* s2) { + int l = safe_strlen (s1); + + if (l != safe_strlen (s2)) + return (0); + return (safe_strncmp (s1, s2, l) == 0); } -void mutt_remove_trailing_ws (char *s) -{ +char* str_skip_initws (char* s) { + SKIPWS (s); + return (s); +} + +void str_skip_trailws (char *s) { char *p; for (p = s + safe_strlen (s) - 1; p >= s && ISSPACE (*p); p--) diff --git a/lib/str.h b/lib/str.h index 3dc825e..6c05b15 100644 --- a/lib/str.h +++ b/lib/str.h @@ -60,6 +60,9 @@ char *str_substrcpy (char*, const char*, const char*, size_t); char *str_substrdup (const char*, const char*); void str_replace (char**, const char*); void str_adjust (char**); +int str_eq (const char*, const char*); const char *str_isstr (const char*, const char*); +char* str_skip_initws (char*); +void str_skip_trailws (char*); #endif /* !_LIB_STR_H */ diff --git a/nntp/nntp.c b/nntp/nntp.c index 09a986a..2b5494f 100644 --- a/nntp/nntp.c +++ b/nntp/nntp.c @@ -115,7 +115,7 @@ static int nntp_connect_and_auth (NNTP_SERVER * serv) mutt_message (_("Connected to %s. Posting NOT ok."), conn->account.host); else { mutt_socket_close (conn); - mutt_remove_trailing_ws (buf); + str_skip_trailws (buf); mutt_error ("%s", buf); sleep (2); return -1; diff --git a/parse.c b/parse.c index 65a02b4..d18ef59 100644 --- a/parse.c +++ b/parse.c @@ -1037,8 +1037,8 @@ int mutt_parse_rfc822_line (ENVELOPE * e, HEADER * hdr, char *line, char *p, #ifdef USE_NNTP else if (!safe_strcasecmp (line + 1, "ollowup-to")) { if (!e->followup_to) { - mutt_remove_trailing_ws (p); - e->followup_to = safe_strdup (mutt_skip_whitespace (p)); + str_skip_trailws (p); + e->followup_to = safe_strdup (str_skip_initws (p)); } matched = 1; } @@ -1120,8 +1120,8 @@ int mutt_parse_rfc822_line (ENVELOPE * e, HEADER * hdr, char *line, char *p, case 'n': if (!safe_strcasecmp (line + 1, "ewsgroups")) { FREE (&e->newsgroups); - mutt_remove_trailing_ws (p); - e->newsgroups = safe_strdup (mutt_skip_whitespace (p)); + str_skip_trailws (p); + e->newsgroups = safe_strdup (str_skip_initws (p)); matched = 1; } break; diff --git a/pgp.c b/pgp.c index b971626..acca75d 100644 --- a/pgp.c +++ b/pgp.c @@ -199,7 +199,7 @@ static void pgp_copy_clearsigned (FILE * fpin, STATE * s, char *charset) break; if (armor_header) { - char *p = mutt_skip_whitespace (buf); + char *p = str_skip_initws (buf); if (*p == '\0') armor_header = 0; diff --git a/pop/pop.c b/pop/pop.c index 3213e92..f29240a 100644 --- a/pop/pop.c +++ b/pop/pop.c @@ -49,7 +49,6 @@ static pop_query_status pop_read_header (POP_DATA * pop_data, HEADER * h) FILE *f; int index; pop_query_status ret; - cmd_status status; long length; char buf[LONG_STRING]; char tempfile[_POSIX_PATH_MAX]; diff --git a/pop/pop_lib.c b/pop/pop_lib.c index f63e4f7..637d01b 100644 --- a/pop/pop_lib.c +++ b/pop/pop_lib.c @@ -22,6 +22,7 @@ #include "lib/mem.h" #include "lib/intl.h" #include "lib/debug.h" +#include "lib/str.h" #include #include @@ -73,7 +74,7 @@ void pop_error (POP_DATA * pop_data, char *msg) } strfcpy (t, c, sizeof (pop_data->err_msg) - strlen (pop_data->err_msg)); - mutt_remove_trailing_ws (pop_data->err_msg); + str_skip_trailws (pop_data->err_msg); } /* Parse CAPA output */ diff --git a/rfc1524.c b/rfc1524.c index 75a986b..4247b05 100644 --- a/rfc1524.c +++ b/rfc1524.c @@ -128,18 +128,18 @@ static char *get_field (char *s) break; } } - mutt_remove_trailing_ws (s); + str_skip_trailws (s); return ch; } static int get_field_text (char *field, char **entry, char *type, char *filename, int line) { - field = mutt_skip_whitespace (field); + field = str_skip_initws (field); if (*field == '=') { if (entry) { field++; - field = mutt_skip_whitespace (field); + field = str_skip_initws (field); str_replace (entry, field); } return 1; diff --git a/sidebar.c b/sidebar.c index 305a564..059aa68 100644 --- a/sidebar.c +++ b/sidebar.c @@ -106,7 +106,7 @@ static const char* sidebar_number_format (char* dest, size_t destlen, char op, char tmp[SHORT_STRING]; BUFFY* b = (BUFFY*) Incoming->data[data]; int opt = flags & M_FORMAT_OPTIONAL; - int c = Context && safe_strcmp (Context->path, b->path) == 0; + int c = Context && str_eq (Context->path, b->path); switch (op) { case 'c': @@ -162,8 +162,7 @@ int make_sidebar_entry (char* box, int idx, size_t len) SidebarWidth = COLS; if (option (OPTSIDEBARNEWMAILONLY) && box && Context && Context->path && - safe_strcmp (Context->path, box) != 0 && - ((BUFFY*) Incoming->data[idx])->new == 0) + !str_eq (Context->path, box) && ((BUFFY*) Incoming->data[idx])->new == 0) /* if $sidebar_newmail_only is set, don't display the * box only if it's not the currently opened * (i.e. always display the currently opened) */