X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=browser.c;h=763a5be6c3d46f5051ece47982499c5aba6a8b2f;hp=75bb211b9596d0651bf33858b06463228f3f498f;hb=c98480f8568e6c1bc927c6c5f2b5e80b4aa6548c;hpb=f0d5ecf432102dc3e6430ceb2a6c692ee856f4d4 diff --git a/browser.c b/browser.c index 75bb211..763a5be 100644 --- a/browser.c +++ b/browser.c @@ -11,6 +11,11 @@ # include "config.h" #endif +#include +#include +#include +#include + #include "mutt.h" #include "enter.h" #include "mx.h" @@ -31,9 +36,6 @@ #endif #include "sidebar.h" -#include "lib/mem.h" -#include "lib/intl.h" -#include "lib/str.h" #include "lib/list.h" #include @@ -49,7 +51,7 @@ static struct mapping_t FolderHelp[] = { {N_("Chdir"), OP_CHANGE_DIRECTORY}, {N_("Mask"), OP_ENTER_MASK}, {N_("Help"), OP_HELP}, - {NULL} + {NULL, OP_NULL} }; #ifdef USE_NNTP @@ -61,7 +63,7 @@ static struct mapping_t FolderNewsHelp[] = { {N_("Catchup"), OP_CATCHUP}, {N_("Mask"), OP_ENTER_MASK}, {N_("Help"), OP_HELP}, - {NULL} + {NULL, OP_NULL} }; #endif @@ -79,14 +81,14 @@ static void destroy_state (struct browser_state *state) int c; for (c = 0; c < state->entrylen; c++) { - mem_free (&((state->entry)[c].name)); - mem_free (&((state->entry)[c].desc)); - mem_free (&((state->entry)[c].st)); + p_delete(&((state->entry)[c].name)); + p_delete(&((state->entry)[c].desc)); + p_delete(&((state->entry)[c].st)); } #ifdef USE_IMAP - mem_free (&state->folder); + p_delete(&state->folder); #endif - mem_free (&state->entry); + p_delete(&state->entry); } static int browser_compare_subject (const void *a, const void *b) @@ -94,7 +96,7 @@ static int browser_compare_subject (const void *a, const void *b) struct folder_file *pa = (struct folder_file *) a; struct folder_file *pb = (struct folder_file *) b; - int r = str_coll (pa->name, pb->name); + int r = strcoll(NONULL(pa->name), NONULL(pb->name)); return ((BrowserSort & SORT_REVERSE) ? -r : r); } @@ -153,7 +155,7 @@ static int link_is_dir (const char *folder, const char *path) struct stat st; char fullpath[_POSIX_PATH_MAX]; - mutt_concat_path (fullpath, folder, path, sizeof (fullpath)); + mutt_concat_path(fullpath, sizeof(fullpath), folder, path); if (stat (fullpath, &st) == 0) return (S_ISDIR (st.st_mode)); @@ -167,8 +169,8 @@ static const char *folder_format_str (char *dest, size_t destlen, char op, const char *elsestring, unsigned long data, format_flag flags) { - char fn[SHORT_STRING], tmp[SHORT_STRING], permission[11]; - char date[16], *t_fmt; + char fn[SHORT_STRING], tmp[SHORT_STRING], permission[11], date[16]; + const char *t_fmt; time_t tnow; FOLDER *folder = (FOLDER *) data; struct passwd *pw; @@ -197,7 +199,7 @@ static const char *folder_format_str (char *dest, size_t destlen, char op, case 'f': { - char *s; + const char *s; #ifdef USE_IMAP if (folder->ff->imap) @@ -348,7 +350,7 @@ static const char *newsgroup_format_str (char *dest, size_t destlen, char op, break; case 'f': - strncpy (fn, folder->ff->name, sizeof (fn) - 1); + m_strcpy(fn, sizeof(fn), folder->ff->name); snprintf (tmp, sizeof (tmp), "%%%ss", fmt); snprintf (dest, destlen, tmp, fn); break; @@ -427,26 +429,22 @@ static void add_folder (MUTTMENU * m, struct browser_state *state, { if (state->entrylen == state->entrymax) { /* need to allocate more space */ - mem_realloc (&state->entry, - sizeof (struct folder_file) * (state->entrymax += 256)); - memset (&state->entry[state->entrylen], 0, - sizeof (struct folder_file) * 256); + p_realloc(&state->entry, state->entrymax += 256); + p_clear(&state->entry[state->entrylen], 256); if (m) m->data = state->entry; } if (s != NULL) { - (state->entry)[state->entrylen].mode = s->st_mode; + (state->entry)[state->entrylen].mode = s->st_mode; (state->entry)[state->entrylen].mtime = s->st_mtime; - (state->entry)[state->entrylen].size = s->st_size; - - (state->entry)[state->entrylen].st = mem_malloc (sizeof (struct stat)); - memcpy ((state->entry)[state->entrylen].st, s, sizeof (struct stat)); + (state->entry)[state->entrylen].size = s->st_size; + (state->entry)[state->entrylen].st = p_dup(s, 1); } (state->entry)[state->entrylen].new = new; - (state->entry)[state->entrylen].name = str_dup (name); - (state->entry)[state->entrylen].desc = str_dup (name); + (state->entry)[state->entrylen].name = m_strdup(name); + (state->entry)[state->entrylen].desc = m_strdup(name); #ifdef USE_IMAP (state->entry)[state->entrylen].imap = 0; #endif @@ -461,9 +459,7 @@ static void init_state (struct browser_state *state, MUTTMENU * menu) { state->entrylen = 0; state->entrymax = 256; - state->entry = - (struct folder_file *) mem_calloc (state->entrymax, - sizeof (struct folder_file)); + state->entry = p_new(struct folder_file, state->entrymax); #ifdef USE_IMAP state->imap_browse = 0; #endif @@ -489,7 +485,7 @@ static int examine_directory (MUTTMENU * menu, struct browser_state *state, continue; nntp_sync_sidebar (data); if (prefix && *prefix && strncmp (prefix, data->group, - str_len (prefix)) != 0) + m_strlen(prefix)) != 0) continue; if (!((regexec (Mask.rx, data->group, 0, NULL, 0) == 0) ^ Mask.not)) continue; @@ -535,16 +531,16 @@ static int examine_directory (MUTTMENU * menu, struct browser_state *state, init_state (state, menu); while ((de = readdir (dp)) != NULL) { - if (str_cmp (de->d_name, ".") == 0) + if (m_strcmp(de->d_name, ".") == 0) continue; /* we don't need . */ if (prefix && *prefix - && str_ncmp (prefix, de->d_name, str_len (prefix)) != 0) + && m_strncmp(prefix, de->d_name, m_strlen(prefix)) != 0) continue; if (!((regexec (Mask.rx, de->d_name, 0, NULL, 0) == 0) ^ Mask.not)) continue; - mutt_concat_path (buffer, d, de->d_name, sizeof (buffer)); + mutt_concat_path(buffer, sizeof(buffer), d, de->d_name); if (lstat (buffer, &s) == -1) continue; @@ -743,7 +739,7 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, buffy = buffy && folder; - memset (&state, 0, sizeof (struct browser_state)); + p_clear(&state, 1); if (!folder) strfcpy (LastDirBackup, LastDir, sizeof (LastDirBackup)); @@ -780,18 +776,16 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, } else { #endif - for (i = str_len (f) - 1; i > 0 && f[i] != '/'; i--); + for (i = m_strlen(f) - 1; i > 0 && f[i] != '/'; i--); if (i > 0) { if (f[0] == '/') { - if (i > sizeof (LastDir) - 1) - i = sizeof (LastDir) - 1; - strncpy (LastDir, f, i); - LastDir[i] = 0; + i = MIN(sizeof(LastDir) - 1, i); + m_strcpy(LastDir, sizeof(LastDir), f); } else { - getcwd (LastDir, sizeof (LastDir)); - str_cat (LastDir, sizeof (LastDir), "/"); - str_ncat (LastDir, sizeof (LastDir), f, i); + getcwd(LastDir, sizeof(LastDir)); + m_strcat(LastDir, sizeof(LastDir), "/"); + m_strncat(LastDir, sizeof(LastDir), f, i); } } else { @@ -821,6 +815,7 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, init_state (&state, NULL); state.imap_browse = 1; imap_browse (LastDir, &state); + browser_sort (&state); } #endif } @@ -855,7 +850,7 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, init_menu (&state, menu, title, sizeof (title), buffy); - FOREVER { + for (;;) { switch (i = mutt_menuLoop (menu)) { case OP_GENERIC_SELECT_ENTRY: @@ -883,8 +878,8 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, } #endif else - mutt_concat_path (buf, LastDir, state.entry[menu->current].name, - sizeof (buf)); + mutt_concat_path(buf, sizeof(buf), LastDir, + state.entry[menu->current].name); if ((mx_get_magic (buf) <= 0) #ifdef USE_IMAP @@ -896,8 +891,8 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, /* save the old directory */ strfcpy (OldLastDir, LastDir, sizeof (OldLastDir)); - if (str_cmp (state.entry[menu->current].name, "..") == 0) { - if (str_cmp ("..", LastDir + str_len (LastDir) - 2) == 0) + if (m_strcmp(state.entry[menu->current].name, "..") == 0) { + if (m_strcmp("..", LastDir + m_strlen(LastDir) - 2) == 0) strcat (LastDir, "/.."); /* __STRCAT_CHECKED__ */ else { char *p = strrchr (LastDir + 1, '/'); @@ -925,7 +920,7 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, strfcpy (LastDir, state.entry[menu->current].name, sizeof (LastDir)); /* tack on delimiter here */ - n = str_len (LastDir) + 1; + n = m_strlen(LastDir) + 1; /* special case "" needs no delimiter */ url_parse_ciss (&url, state.entry[menu->current].name); @@ -940,8 +935,8 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, else { char tmp[_POSIX_PATH_MAX]; - mutt_concat_path (tmp, LastDir, state.entry[menu->current].name, - sizeof (tmp)); + mutt_concat_path(tmp, sizeof(tmp), LastDir, + state.entry[menu->current].name); strfcpy (LastDir, tmp, sizeof (LastDir)); } @@ -956,6 +951,7 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, init_state (&state, NULL); state.imap_browse = 1; imap_browse (LastDir, &state); + browser_sort (&state); menu->data = state.entry; } else @@ -989,7 +985,7 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, strfcpy (f, state.entry[menu->current].name, flen); #endif else - mutt_concat_path (f, LastDir, state.entry[menu->current].name, flen); + mutt_concat_path(f, flen, LastDir, state.entry[menu->current].name); /* Fall through to OP_EXIT */ @@ -1001,24 +997,24 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, if (menu->tagged) { *numfiles = menu->tagged; - tfiles = mem_calloc (*numfiles, sizeof (char *)); + tfiles = p_new(char *, *numfiles); for (i = 0, j = 0; i < state.entrylen; i++) { struct folder_file ff = state.entry[i]; char full[_POSIX_PATH_MAX]; if (ff.tagged) { - mutt_concat_path (full, LastDir, ff.name, sizeof (full)); + mutt_concat_path(full, sizeof(full), LastDir, ff.name); mutt_expand_path (full, sizeof (full)); - tfiles[j++] = str_dup (full); + tfiles[j++] = m_strdup(full); } } *files = tfiles; } else if (f[0]) { /* no tagged entries. return selected entry */ *numfiles = 1; - tfiles = mem_calloc (*numfiles, sizeof (char *)); + tfiles = p_new(char *, *numfiles); mutt_expand_path (f, flen); - tfiles[0] = str_dup (f); + tfiles[0] = m_strdup(f); *files = tfiles; } } @@ -1054,6 +1050,7 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, init_state (&state, NULL); state.imap_browse = 1; imap_browse (LastDir, &state); + browser_sort (&state); menu->data = state.entry; menu->current = 0; menu->top = 0; @@ -1073,6 +1070,7 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, init_state (&state, NULL); state.imap_browse = 1; imap_browse (LastDir, &state); + browser_sort (&state); menu->data = state.entry; menu->current = 0; menu->top = 0; @@ -1096,8 +1094,8 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, if (mutt_yesorno (msg, M_NO) == M_YES) { if (!imap_delete_mailbox (Context, mx)) { /* free the mailbox from the browser */ - mem_free (&((state.entry)[nentry].name)); - mem_free (&((state.entry)[nentry].desc)); + p_delete(&((state.entry)[nentry].name)); + p_delete(&((state.entry)[nentry].desc)); /* and move all other entries up */ if (nentry + 1 < state.entrylen) memmove (state.entry + nentry, state.entry + nentry + 1, @@ -1112,7 +1110,7 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, } else mutt_message _("Mailbox not deleted."); - mem_free (&mx.mbox); + p_delete(&mx.mbox); } break; #endif @@ -1130,7 +1128,7 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, #endif { /* add '/' at the end of the directory name if not already there */ - int len = str_len (LastDir); + int len = m_strlen(LastDir); if (len && LastDir[len - 1] != '/' && sizeof (buf) > len) buf[len] = '/'; @@ -1147,6 +1145,7 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, init_state (&state, NULL); state.imap_browse = 1; imap_browse (LastDir, &state); + browser_sort (&state); menu->data = state.entry; menu->current = 0; menu->top = 0; @@ -1184,7 +1183,7 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, strfcpy (buf, NONULL (Mask.pattern), sizeof (buf)); if (mutt_get_field (_("File Mask: "), buf, sizeof (buf), 0) == 0) { - regex_t *rx = (regex_t *) mem_malloc (sizeof (regex_t)); + regex_t *rx = p_new(regex_t, 1); char *s = buf; int not = 0, err; @@ -1202,13 +1201,13 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, if ((err = REGCOMP (rx, s, REG_NOSUB)) != 0) { regerror (err, rx, buf, sizeof (buf)); regfree (rx); - mem_free (&rx); + p_delete(&rx); mutt_error ("%s", buf); } else { str_replace (&Mask.pattern, buf); regfree (Mask.rx); - mem_free (&Mask.rx); + p_delete(&Mask.rx); Mask.rx = rx; Mask.not = not; @@ -1218,6 +1217,7 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, init_state (&state, NULL); state.imap_browse = 1; imap_browse (LastDir, &state); + browser_sort (&state); menu->data = state.entry; init_menu (&state, menu, title, sizeof (title), buffy); } @@ -1302,6 +1302,7 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, init_state (&state, NULL); state.imap_browse = 1; imap_browse (LastDir, &state); + browser_sort (&state); menu->data = state.entry; } #endif @@ -1356,8 +1357,8 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, BODY *b; char buf[_POSIX_PATH_MAX]; - mutt_concat_path (buf, LastDir, state.entry[menu->current].name, - sizeof (buf)); + mutt_concat_path(buf, sizeof(buf), LastDir, + state.entry[menu->current].name); b = mutt_make_file_attach (buf); if (b != NULL) { mutt_view_attachment (NULL, b, M_REGULAR, NULL, NULL, 0); @@ -1391,11 +1392,11 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, folder.ff->st = NULL; folder.ff->is_new = nd->new; folder.ff->nd = nd; - mem_free (&f->desc); + p_delete(&f->desc); mutt_FormatString (buffer, sizeof (buffer), NONULL(GroupFormat), newsgroup_format_str, (unsigned long) &folder, M_FORMAT_ARROWCURSOR); - f->desc = str_dup (buffer); */ + f->desc = m_strdup(buffer); */ if (menu->current + 1 < menu->max) menu->current++; menu->redraw = REDRAW_MOTION_RESYNCH; @@ -1435,7 +1436,7 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, case OP_SUBSCRIBE_PATTERN: case OP_UNSUBSCRIBE_PATTERN: if (option (OPTNEWS)) { - regex_t *rx = (regex_t *) mem_malloc (sizeof (regex_t)); + regex_t *rx = p_new(regex_t, 1); char *s = buf; int j = menu->current; NNTP_DATA *nd; @@ -1451,14 +1452,14 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, else snprintf (tmp, sizeof (tmp), _("Unsubscribe pattern: ")); if (mutt_get_field (tmp, buf, sizeof (buf), 0) != 0 || !buf[0]) { - mem_free (&rx); + p_delete(&rx); break; } if ((err = REGCOMP (rx, s, REG_NOSUB)) != 0) { regerror (err, rx, buf, sizeof (buf)); regfree (rx); - mem_free (&rx); + p_delete(&rx); mutt_error ("%s", buf); break; } @@ -1489,11 +1490,11 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, folder.f = NULL; folder.new = nd->new; folder.nd = nd; - mem_free (&f->desc); + p_delete(&f->desc); mutt_FormatString (buffer, sizeof (buffer), NONULL(GroupFormat), newsgroup_format_str, (unsigned long) &folder, M_FORMAT_ARROWCURSOR); - f->desc = str_dup (buffer); + f->desc = m_strdup(buffer); } */ } if (i == OP_BROWSER_SUBSCRIBE || i == OP_BROWSER_UNSUBSCRIBE) { @@ -1523,7 +1524,7 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, nntp_clear_cacheindex (news); if (i != OP_BROWSER_SUBSCRIBE && i != OP_BROWSER_UNSUBSCRIBE) regfree (rx); - mem_free (&rx); + p_delete(&rx); } #ifdef USE_IMAP else