]>
diplodocus.org Git - nmh/blob - sbr/folder_realloc.c
753da2ec0b8867de2154c8fbf3509aaae93218d3
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.
16 * Reallocate some of the space in the folder
17 * structure (currently just message status array).
19 * Return pointer to new folder structure.
20 * If error, return NULL.
24 folder_realloc (struct msgs
*mp
, int lo
, int hi
)
30 adios (NULL
, "BUG: called folder_realloc with lo (%d) < 1", lo
);
32 adios (NULL
, "BUG: called folder_realloc with hi (%d) < 1", hi
);
33 if (mp
->nummsg
> 0 && lo
> mp
->lowmsg
)
34 adios (NULL
, "BUG: called folder_realloc with lo (%d) > mp->lowmsg (%d)",
36 if (mp
->nummsg
> 0 && hi
< mp
->hghmsg
)
37 adios (NULL
, "BUG: called folder_realloc with hi (%d) < mp->hghmsg (%d)",
40 /* Check if we really need to reallocate anything */
41 if (lo
== mp
->lowoff
&& hi
== mp
->hghoff
)
44 if (lo
== mp
->lowoff
) {
46 * We are just extending (or shrinking) the end of message
47 * status array. So we don't have to move anything and can
48 * just realloc the message status array.
50 if (!(mp
->msgstats
= realloc (mp
->msgstats
, MSGSTATSIZE(mp
, lo
, hi
)))) {
51 advise (NULL
, "unable to reallocate message storage");
56 * We are changing the offset of the message status
57 * array. So we will need to shift everything.
61 /* first allocate the new message status space */
62 tmpstats
= mh_xmalloc (MSGSTATSIZE(mp
, lo
, hi
));
64 /* then copy messages status array with shift */
66 for (msgnum
= mp
->lowmsg
; msgnum
<= mp
->hghmsg
; msgnum
++)
67 tmpstats
[msgnum
- lo
] = mp
->msgstats
[msgnum
- mp
->lowoff
];
70 mp
->msgstats
= tmpstats
;
77 * Clear all the flags for entries outside
78 * the current message range for this folder.
81 for (msgnum
= mp
->lowoff
; msgnum
< mp
->lowmsg
; msgnum
++)
82 clear_msg_flags (mp
, msgnum
);
83 for (msgnum
= mp
->hghmsg
+ 1; msgnum
<= mp
->hghoff
; msgnum
++)
84 clear_msg_flags (mp
, msgnum
);
86 /* no messages, so clear entire range */
87 for (msgnum
= mp
->lowoff
; msgnum
<= mp
->hghoff
; msgnum
++)
88 clear_msg_flags (mp
, msgnum
);