* Addition of a link to the Apache License 2.0. This is available from
[alpine.git] / pith / search.c
blob10623ba3877badd946d98be2fa2529894be71dcf
1 #if !defined(lint) && !defined(DOS)
2 static char rcsid[] = "$Id: search.c 854 2007-12-07 17:44:43Z hubert@u.washington.edu $";
3 #endif
5 /*
6 * ========================================================================
7 * Copyright 2013-2020 Eduardo Chappa
8 * Copyright 2006 University of Washington
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * ========================================================================
19 #include "../pith/headers.h"
20 #include "../pith/search.h"
23 SEARCHSET *
24 build_searchset(MAILSTREAM *stream)
26 long i, run;
27 SEARCHSET *ret_s = NULL, **set;
28 MESSAGECACHE *mc;
30 if(!stream)
31 return(NULL);
33 for(i = 1L, set = &ret_s, run = 0L; i <= stream->nmsgs; i++){
34 if(!((mc = mail_elt(stream, i)) && mc->sequence)){ /* end of run */
35 if(run){ /* run in progress */
36 set = &(*set)->next;
37 run = 0L;
40 else if(run++){ /* next in run */
41 (*set)->last = i;
43 else{ /* start of new run */
44 *set = mail_newsearchset();
46 * Leave off (*set)->last until we get more than one msg
47 * in the run, to avoid 607:607 in SEARCH.
49 (*set)->first = (*set)->last = i;
53 return(ret_s);
57 int
58 in_searchset(SEARCHSET *srch, long unsigned int num)
60 SEARCHSET *s;
61 unsigned long i;
63 if(srch)
64 for(s = srch; s; s = s->next)
65 for(i = s->first; i <= s->last; i++){
66 if(i == num)
67 return 1;
70 return 0;