3 * folder_realloc.c -- realloc a folder/msgs structure
7 * This code is Copyright (c) 2002, by the authors of nmh. See the
8 * COPYRIGHT file in the root directory of the nmh distribution for
9 * complete copyright information.
15 * Reallocate some of the space in the folder
16 * structure (currently just message status array).
18 * Return pointer to new folder structure.
19 * If error, return NULL.
23 folder_realloc (struct msgs *mp, int lo, int hi)
29 adios (NULL, "BUG: called folder_realloc with lo (%d) < 1", lo);
31 adios (NULL, "BUG: called folder_realloc with hi (%d) < 1", hi);
32 if (mp->nummsg > 0 && lo > mp->lowmsg)
33 adios (NULL, "BUG: called folder_realloc with lo (%d) > mp->lowmsg (%d)",
35 if (mp->nummsg > 0 && hi < mp->hghmsg)
36 adios (NULL, "BUG: called folder_realloc with hi (%d) < mp->hghmsg (%d)",
39 /* Check if we really need to reallocate anything */
40 if (lo == mp->lowoff && hi == mp->hghoff)
43 if (lo == mp->lowoff) {
45 * We are just extending (or shrinking) the end of message
46 * status array. So we don't have to move anything and can
47 * just realloc the message status array.
49 if (!(mp->msgstats = realloc (mp->msgstats, MSGSTATSIZE(mp, lo, hi)))) {
50 advise (NULL, "unable to reallocate message storage");
55 * We are changing the offset of the message status
56 * array. So we will need to shift everything.
60 /* first allocate the new message status space */
61 if (!(tmpstats = malloc (MSGSTATSIZE(mp, lo, hi)))) {
62 advise (NULL, "unable to reallocate message storage");
66 /* then copy messages status array with shift */
68 for (msgnum = mp->lowmsg; msgnum <= mp->hghmsg; msgnum++)
69 tmpstats[msgnum - lo] = mp->msgstats[msgnum - mp->lowoff];
72 mp->msgstats = tmpstats;
79 * Clear all the flags for entries outside
80 * the current message range for this folder.
83 for (msgnum = mp->lowoff; msgnum < mp->lowmsg; msgnum++)
84 clear_msg_flags (mp, msgnum);
85 for (msgnum = mp->hghmsg + 1; msgnum <= mp->hghoff; msgnum++)
86 clear_msg_flags (mp, msgnum);
88 /* no messages, so clear entire range */
89 for (msgnum = mp->lowoff; msgnum <= mp->hghoff; msgnum++)
90 clear_msg_flags (mp, msgnum);