NeoMutt  2024-12-12-19-ge4b57e
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
sort.c File Reference

Address book sorting functions. More...

#include "config.h"
#include <stdbool.h>
#include <stddef.h>
#include "mutt/lib.h"
#include "address/lib.h"
#include "config/lib.h"
#include "sort.h"
#include "alias.h"
#include "gui.h"
+ Include dependency graph for sort.c:

Go to the source code of this file.

Functions

static int alias_sort_alias (const void *a, const void *b, void *sdata)
 Compare two Aliases by their short names - Implements sort_t -.
 
static int alias_sort_email (const void *a, const void *b, void *sdata)
 Compare two Aliases by their Email Addresses - Implements sort_t -.
 
static int alias_sort_name (const void *a, const void *b, void *sdata)
 Compare two Aliases by their Names - Implements sort_t -.
 
static int alias_sort_unsorted (const void *a, const void *b, void *sdata)
 Compare two Aliases by their original configuration position - Implements sort_t -.
 
static sort_t alias_get_sort_function (short sort)
 Sorting function decision logic.
 
void alias_array_sort (struct AliasViewArray *ava, const struct ConfigSubset *sub)
 Sort and reindex an AliasViewArray.
 

Detailed Description

Address book sorting functions.

Authors
  • Romeu Vieira
  • Richard Russon
  • Dennis Schön

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file sort.c.

Function Documentation

◆ alias_get_sort_function()

static sort_t alias_get_sort_function ( short  sort)
static

Sorting function decision logic.

Parameters
sortSort method, e.g. ALIAS_SORT_ALIAS

Definition at line 209 of file sort.c.

210{
211 switch ((sort & SORT_MASK))
212 {
213 case ALIAS_SORT_ALIAS:
214 return alias_sort_alias;
215
216 case ALIAS_SORT_EMAIL:
217 return alias_sort_email;
218
219 case ALIAS_SORT_NAME:
220 return alias_sort_name;
221
223 return alias_sort_unsorted;
224
225 default:
226 return alias_sort_alias;
227 }
228}
@ ALIAS_SORT_UNSORTED
Sort by the order the Aliases were configured.
Definition: sort.h:34
@ ALIAS_SORT_NAME
Sort by Real Name.
Definition: sort.h:33
@ ALIAS_SORT_EMAIL
Sort by Email Address.
Definition: sort.h:32
@ ALIAS_SORT_ALIAS
Sort by Alias short name.
Definition: sort.h:31
#define SORT_MASK
Mask for the sort id.
Definition: sort.h:38
static int alias_sort_unsorted(const void *a, const void *b, void *sdata)
Compare two Aliases by their original configuration position - Implements sort_t -.
Definition: sort.c:189
static int alias_sort_email(const void *a, const void *b, void *sdata)
Compare two Aliases by their Email Addresses - Implements sort_t -.
Definition: sort.c:67
static int alias_sort_alias(const void *a, const void *b, void *sdata)
Compare two Aliases by their short names - Implements sort_t -.
Definition: sort.c:46
static int alias_sort_name(const void *a, const void *b, void *sdata)
Compare two Aliases by their Names - Implements sort_t -.
Definition: sort.c:128
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ alias_array_sort()

void alias_array_sort ( struct AliasViewArray *  ava,
const struct ConfigSubset sub 
)

Sort and reindex an AliasViewArray.

Parameters
avaArray of Aliases
subConfig items

Definition at line 235 of file sort.c.

236{
237 if (!ava || ARRAY_EMPTY(ava))
238 return;
239
240 short c_sort_alias = cs_subset_sort(sub, "alias_sort");
241 if (c_sort_alias == ALIAS_SORT_ALIAS)
242 {
243 struct AliasView *av = ARRAY_GET(ava, 0);
244 struct Alias *a = av->alias;
245
246 if (!a->name) // We've got a Query
247 c_sort_alias = ALIAS_SORT_NAME;
248 }
249
250 bool sort_reverse = (c_sort_alias & SORT_REVERSE);
251 ARRAY_SORT(ava, alias_get_sort_function(c_sort_alias), &sort_reverse);
252
253 struct AliasView *avp = NULL;
254 ARRAY_FOREACH(avp, ava)
255 {
256 avp->num = ARRAY_FOREACH_IDX;
257 }
258}
static sort_t alias_get_sort_function(short sort)
Sorting function decision logic.
Definition: sort.c:209
#define ARRAY_SORT(head, fn, sdata)
Sort an array.
Definition: array.h:279
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition: array.h:212
#define ARRAY_EMPTY(head)
Check if an array is empty.
Definition: array.h:74
#define ARRAY_GET(head, idx)
Return the element at index.
Definition: array.h:109
short cs_subset_sort(const struct ConfigSubset *sub, const char *name)
Get a sort config item by name.
Definition: helpers.c:266
#define SORT_REVERSE
Reverse the order of the sort.
Definition: sort.h:39
GUI data wrapping an Alias.
Definition: gui.h:38
struct Alias * alias
Alias.
Definition: gui.h:46
int num
Index number in list.
Definition: gui.h:39
A shortcut for an email address or addresses.
Definition: alias.h:35
char * name
Short name.
Definition: alias.h:36
+ Here is the call graph for this function:
+ Here is the caller graph for this function: