summaryrefslogtreecommitdiffstats
path: root/attach.c
diff options
context:
space:
mode:
authorKevin McCarthy <kevin@8t8.us>2017-08-10 18:18:20 -0700
committerKevin McCarthy <kevin@8t8.us>2017-08-10 18:18:20 -0700
commit7a002ec117886669ba9e1f19bed506847b730c9d (patch)
tree11f11cf6d58c487183398e9f3a8de250d7c44a24 /attach.c
parent3433587a5a77ef94806236cbeb6181df71440928 (diff)
Add helpers to add and remove actx entries. (see #3728)
Use the helper in compose update_idx(), to consolidate the resize logic and simplify the code. Separate out the actx "free" routine from a routine to empty out the idx. The index regeneration routines should flush and rebuild the index without having to renerate the actx structure.
Diffstat (limited to 'attach.c')
-rw-r--r--attach.c35
1 files changed, 29 insertions, 6 deletions
diff --git a/attach.c b/attach.c
index 7a512419..9b4b649e 100644
--- a/attach.c
+++ b/attach.c
@@ -1042,15 +1042,26 @@ int mutt_print_attachment (FILE *fp, BODY *a)
}
}
-void mutt_free_attach_context (ATTACH_CONTEXT **pactx)
+void mutt_actx_add_attach (ATTACH_CONTEXT *actx, ATTACHPTR *attach, MUTTMENU *menu)
{
int i;
- ATTACH_CONTEXT *actx;
- if (!pactx || !*pactx)
- return;
+ if (actx->idxlen == actx->idxmax)
+ {
+ actx->idxmax += 5;
+ safe_realloc (&actx->idx, sizeof (ATTACHPTR *) * actx->idxmax);
+ for (i = actx->idxlen; i < actx->idxmax; i++)
+ actx->idx[i] = NULL;
+ if (menu)
+ menu->data = actx->idx;
+ }
- actx = *pactx;
+ actx->idx[actx->idxlen++] = attach;
+}
+
+void mutt_actx_free_entries (ATTACH_CONTEXT *actx)
+{
+ int i;
for (i = 0; i < actx->idxlen; i++)
{
@@ -1059,7 +1070,19 @@ void mutt_free_attach_context (ATTACH_CONTEXT **pactx)
FREE (&actx->idx[i]->tree);
FREE (&actx->idx[i]);
}
- FREE (&actx->idx);
+ actx->idxlen = 0;
+}
+
+void mutt_free_attach_context (ATTACH_CONTEXT **pactx)
+{
+ ATTACH_CONTEXT *actx;
+
+ if (!pactx || !*pactx)
+ return;
+
+ actx = *pactx;
+ mutt_actx_free_entries (actx);
+ FREE (&actx->idx);
FREE (pactx); /* __FREE_CHECKED__ */
}