Back to index

courier  0.68.2
Classes | Defines | Functions
maildirsearch.h File Reference
#include "config.h"
#include "../unicode/unicode.h"
#include <string.h>
#include <stdlib.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  maildir_searchengine

Defines

#define maildir_search_init(sei)   (memset((sei), 0, sizeof(struct maildir_searchengine)))
#define maildir_search_destroy(sei)   do { if ((sei)->string) free((sei)->string); if ( (sei)->r) free( (sei)->r); } while (0)
#define maildir_search_reset(si)   ((si)->i=0, (si)->ptr=(si)->string)
#define maildir_search_found(si)
#define maildir_search_len(si)   ((si)->string_l)
#define maildir_search_step_unicode(sie, ch)
#define maildir_search_step_unicode_lc(sie, ch)
#define maildir_search_step(sie, ch)   maildir_search_step_unicode((sie), ((unsigned char)(ch)))
#define maildir_search_atstart(sie)   ((sie)->i == 0)

Functions

int maildir_search_start_str (struct maildir_searchengine *engine, const char *string)
int maildir_search_start_str_chset (struct maildir_searchengine *engine, const char *string, const char *chset)
int maildir_search_start_unicode (struct maildir_searchengine *engine, const unicode_char *string)

Class Documentation

struct maildir_searchengine

Definition at line 48 of file maildirsearch.h.

Class Members
unsigned i
const unicode_char * ptr
unsigned * r
int spc
unicode_char * string
size_t string_l

Define Documentation

#define maildir_search_atstart (   sie)    ((sie)->i == 0)

Definition at line 116 of file maildirsearch.h.

#define maildir_search_destroy (   sei)    do { if ((sei)->string) free((sei)->string); if ( (sei)->r) free( (sei)->r); } while (0)

Definition at line 59 of file maildirsearch.h.

#define maildir_search_found (   si)
Value:
((si)->ptr && \
                                   (si)->ptr[(si)->i] == '\0')

Definition at line 72 of file maildirsearch.h.

#define maildir_search_init (   sei)    (memset((sei), 0, sizeof(struct maildir_searchengine)))

Definition at line 57 of file maildirsearch.h.

#define maildir_search_len (   si)    ((si)->string_l)

Definition at line 74 of file maildirsearch.h.

#define maildir_search_reset (   si)    ((si)->i=0, (si)->ptr=(si)->string)

Definition at line 70 of file maildirsearch.h.

#define maildir_search_step (   sie,
  ch 
)    maildir_search_step_unicode((sie), ((unsigned char)(ch)))

Definition at line 113 of file maildirsearch.h.

#define maildir_search_step_unicode (   sie,
  ch 
)
Value:
do \
        {\
                if ( (sie)->ptr && (sie)->ptr[(sie)->i]) \
                {\
                        for (;;) \
                        {\
                                if ( (unicode_char)(sie)->ptr[(sie)->i] == (unicode_char)(ch) )\
                                        { (sie)->i++; break; }\
                                if ( (sie)->i == 0) break;\
                                (sie)->i=(sie)->r[(sie)->i];\
                        }\
                }\
        } while (0)

Definition at line 76 of file maildirsearch.h.

#define maildir_search_step_unicode_lc (   sie,
  ch 
)
Value:
do     \
       {                                         \
		unicode_char c=(ch);                    \
              int spc=0;                         \
                                                 \
                                                               \
              if (c == ' ' || c == '\t' || c == '\r' || c == '\n')    \
              {                                                \
                     c=' ';                                    \
                     spc=1;                                    \
              }                                                \
                                                               \
              if (spc && (sie)->spc)                                  \
                     ;                                         \
              else                                             \
              {                                                \
                     c=unicode_lc(c);                          \
                     maildir_search_step_unicode((sie),c);            \
              }                                                \
                                                               \
              (sie)->spc=spc;                                         \
       } while(0)

Definition at line 90 of file maildirsearch.h.


Function Documentation

int maildir_search_start_str ( struct maildir_searchengine engine,
const char *  string 
)

Definition at line 54 of file maildirsearch.c.

{
       unicode_char *uc=malloc((strlen(s)+1) * sizeof(unicode_char));
       size_t n;
       int rc;

       if (!uc)
              return -1;

       for (n=0; (uc[n]=(unsigned char)s[n]) != 0; ++n)
              ;

       rc=maildir_search_start_unicode(sei, uc);
       free(uc);
       return rc;
}

Here is the call graph for this function:

int maildir_search_start_str_chset ( struct maildir_searchengine engine,
const char *  string,
const char *  chset 
)

Definition at line 72 of file maildirsearch.c.

{
#define SPC(s) ((s) == ' '|| (s) == '\t' || (s) == '\r' || (s) == '\n')

       unicode_char *ucptr;
       size_t ucsize;
       libmail_u_convert_handle_t h=libmail_u_convert_tou_init(chset, &ucptr,
                                                        &ucsize, 1);
       size_t i, j;
       int rc;

       if (h == NULL)
              return -1;

       if (libmail_u_convert(h, string, strlen(string)))
       {
              libmail_u_convert_deinit(h, NULL);
              return -1;
       }

       if (libmail_u_convert_deinit(h, NULL))
              return -1;

       for (i=j=0; ucptr[i]; )
       {
              while (SPC(ucptr[i]))
                     ++i;

              if (!ucptr[i])
                     break;

              while (ucptr[i])
              {
                     ucptr[j]=unicode_lc(ucptr[i]);
                     ++j;
                     if (SPC(ucptr[i]))
                            break;

                     ++i;
              }
       }

       while (j > 0 && SPC(ucptr[j-1]))
              --j;
       ucptr[j]=0;

       rc=maildir_search_start_unicode(engine, ucptr);
       free(ucptr);
       return rc;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int maildir_search_start_unicode ( struct maildir_searchengine engine,
const unicode_char string 
)

Definition at line 10 of file maildirsearch.c.

{
       unsigned i, j, *r;

       size_t n;

       for (n=0; s[n]; ++n)
              ;
       ++n;

       if (sei->string)
              free(sei->string);

       sei->string=malloc(n * sizeof(*s));
       if (!sei->string)
              return (-1);
       sei->string_l=n-1;

       memcpy(sei->string, s, n * sizeof(*s));

       if (sei->r)
              free(sei->r);

       sei->i=0;
       if ((sei->r=r=(unsigned *)malloc(sizeof(unsigned)*n)) == 0)
              return (-1);

       for (i=0; s[i]; i++)
              r[i]=0;

       for (i=0; s[i]; i++)
              for (j=0; s[i+j]; j++)
                     if (s[j] != s[i+j])
                     {
                            if (r[i+j] < j)
                                   r[i+j]=j;
                            break;
                     }

       maildir_search_reset(sei);
       return (0);
}

Here is the caller graph for this function: