aboutsummaryrefslogtreecommitdiffstats
path: root/mail/e-searching-tokenizer.c
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2009-05-27 22:29:19 +0800
committerMatthew Barnes <mbarnes@redhat.com>2009-05-27 22:29:19 +0800
commit948235c3d1076dbe6ed2e57a24c16a083bbd9f01 (patch)
tree4133b1adfd94d8f889ca7ad4ad851346518f4171 /mail/e-searching-tokenizer.c
parentcc3a98fc1ad5bb87aa7335f3de404ee7feee1541 (diff)
downloadgsoc2013-evolution-948235c3d1076dbe6ed2e57a24c16a083bbd9f01.tar.gz
gsoc2013-evolution-948235c3d1076dbe6ed2e57a24c16a083bbd9f01.tar.zst
gsoc2013-evolution-948235c3d1076dbe6ed2e57a24c16a083bbd9f01.zip
Prefer GLib basic types over C types.
Diffstat (limited to 'mail/e-searching-tokenizer.c')
-rw-r--r--mail/e-searching-tokenizer.c138
1 files changed, 69 insertions, 69 deletions
diff --git a/mail/e-searching-tokenizer.c b/mail/e-searching-tokenizer.c
index 726ae41ed4..277e80ca19 100644
--- a/mail/e-searching-tokenizer.c
+++ b/mail/e-searching-tokenizer.c
@@ -54,10 +54,10 @@ static guint signals[LAST_SIGNAL];
/* This is faster and safer than glib2's utf8 abomination, but isn't exported from camel as yet */
static inline guint32
-camel_utf8_getc(const unsigned char **ptr)
+camel_utf8_getc(const guchar **ptr)
{
- register unsigned char *p = (unsigned char *)*ptr;
- register unsigned char c, r;
+ register guchar *p = (guchar *)*ptr;
+ register guchar c, r;
register guint32 v, m;
again:
@@ -98,11 +98,11 @@ static const gchar *ignored_tags[] = {
"B", "I", "FONT", "TT", "EM", /* and more? */};
static int
-ignore_tag (const char *tag)
+ignore_tag (const gchar *tag)
{
- char *t = alloca(strlen(tag)+1), c, *out;
- const char *in;
- int i;
+ gchar *t = alloca(strlen(tag)+1), c, *out;
+ const gchar *in;
+ gint i;
/* we could use a aho-corasick matcher here too ... but we wont */
@@ -146,7 +146,7 @@ struct _match {
/* tree state node */
struct _state {
struct _match *matches;
- unsigned int final; /* max no of chars we just matched */
+ guint final; /* max no of chars we just matched */
struct _state *fail; /* where to try next if we fail */
struct _state *next; /* next on this level? */
};
@@ -154,7 +154,7 @@ struct _state {
/* base tree structure */
struct _trie {
struct _state root;
- int max_depth;
+ gint max_depth;
EMemChunk *state_chunks;
EMemChunk *match_chunks;
@@ -163,9 +163,9 @@ struct _trie {
/* will be enabled only if debug is enabled */
#if d(1) -1 != -1
static void
-dump_trie (struct _state *s, int d)
+dump_trie (struct _state *s, gint d)
{
- char *p = alloca(d*2+1);
+ gchar *p = alloca(d*2+1);
struct _match *m;
memset(p, ' ', d*2);
@@ -199,15 +199,15 @@ g (struct _state *q, guint32 c)
}
static struct _trie *
-build_trie (int nocase, int len, unsigned char **words)
+build_trie (gint nocase, gint len, guchar **words)
{
struct _state *q, *qt, *r;
- const unsigned char *word;
+ const guchar *word;
struct _match *m, *n = NULL;
- int i, depth;
+ gint i, depth;
guint32 c;
struct _trie *trie;
- int state_depth_max, state_depth_size;
+ gint state_depth_max, state_depth_size;
struct _state **state_depth;
trie = g_malloc(sizeof(*trie));
@@ -325,14 +325,14 @@ free_trie (struct _trie *t)
struct _token {
struct _token *next;
struct _token *prev;
- unsigned int offset;
+ guint offset;
/* we need to copy the token for memory management, so why not copy it whole */
- char tok[1];
+ gchar tok[1];
};
/* stack of submatches currently being scanned, used for merging */
struct _submatch {
- unsigned int offstart, offend; /* in bytes */
+ guint offstart, offend; /* in bytes */
};
/* flags for new func */
@@ -342,17 +342,17 @@ struct _submatch {
struct _searcher {
struct _trie *t;
- char *(*next_token)(); /* callbacks for more tokens */
- void *next_data;
+ gchar *(*next_token)(); /* callbacks for more tokens */
+ gpointer next_data;
- int words; /* how many words */
- char *tags, *tage; /* the tag we used to highlight */
+ gint words; /* how many words */
+ gchar *tags, *tage; /* the tag we used to highlight */
- int flags; /* case sensitive or not */
+ gint flags; /* case sensitive or not */
struct _state *state; /* state is the current trie state */
- int matchcount;
+ gint matchcount;
EDList input; /* pending 'input' tokens, processed but might match */
EDList output; /* output tokens ready for source */
@@ -362,25 +362,25 @@ struct _searcher {
guint32 offset; /* current offset through searchable stream? */
guint32 offout; /* last output position */
- unsigned int lastp; /* current position in rotating last buffer */
+ guint lastp; /* current position in rotating last buffer */
guint32 *last; /* buffer that goes back last 'n' positions */
guint32 last_mask; /* bitmask for efficient rotation calculation */
- unsigned int submatchp; /* submatch stack */
+ guint submatchp; /* submatch stack */
struct _submatch *submatches;
};
static void
-searcher_set_tokenfunc(struct _searcher *s, char *(*next)(), void *data)
+searcher_set_tokenfunc(struct _searcher *s, gchar *(*next)(), gpointer data)
{
s->next_token = next;
s->next_data = data;
}
static struct _searcher *
-searcher_new (int flags, int argc, unsigned char **argv, const char *tags, const char *tage)
+searcher_new (gint flags, gint argc, guchar **argv, const gchar *tags, const gchar *tage)
{
- int i, m;
+ gint i, m;
struct _searcher *s;
s = g_malloc(sizeof(*s));
@@ -433,7 +433,7 @@ searcher_free (struct _searcher *s)
g_free (s);
}
static struct _token *
-append_token(EDList *list, const char *tok, int len)
+append_token(EDList *list, const gchar *tok, gint len)
{
struct _token *token;
@@ -453,8 +453,8 @@ append_token(EDList *list, const char *tok, int len)
static void
output_token(struct _searcher *s, struct _token *token)
{
- int offend;
- int left, pre;
+ gint offend;
+ gint left, pre;
if (token->tok[0] == TAG_ESCAPE) {
if (token->offset >= s->offout) {
@@ -482,7 +482,7 @@ output_token(struct _searcher *s, struct _token *token)
}
static struct _token *
-find_token(struct _searcher *s, int start)
+find_token(struct _searcher *s, gint start)
{
register struct _token *token;
@@ -498,11 +498,11 @@ find_token(struct _searcher *s, int start)
}
static void
-output_match(struct _searcher *s, unsigned int start, unsigned int end)
+output_match(struct _searcher *s, guint start, guint end)
{
register struct _token *token;
struct _token *starttoken, *endtoken;
- char b[8];
+ gchar b[8];
d (printf("output match: %d-%d at %d\n", start, end, s->offout));
@@ -570,7 +570,7 @@ output_match(struct _searcher *s, unsigned int start, unsigned int end)
static void
output_subpending (struct _searcher *s)
{
- int i;
+ gint i;
for (i=s->submatchp-1;i>=0;i--)
output_match(s, s->submatches[i].offstart, s->submatches[i].offend);
@@ -579,9 +579,9 @@ output_subpending (struct _searcher *s)
/* returns true if a merge took place */
static int
-merge_subpending (struct _searcher *s, int offstart, int offend)
+merge_subpending (struct _searcher *s, gint offstart, gint offend)
{
- int i;
+ gint i;
/* merges overlapping or abutting match strings */
if (s->submatchp &&
@@ -604,7 +604,7 @@ merge_subpending (struct _searcher *s, int offstart, int offend)
}
static void
-push_subpending (struct _searcher *s, int offstart, int offend)
+push_subpending (struct _searcher *s, gint offstart, gint offend)
{
/* This is really an assertion, we just ignore the last pending match instead of crashing though */
if (s->submatchp >= s->words) {
@@ -631,11 +631,11 @@ output_pending (struct _searcher *s)
static void
flush_extra(struct _searcher *s)
{
- unsigned int start;
- int i;
+ guint start;
+ gint i;
struct _token *starttoken, *token;
- /* find earliest char that can be in contention */
+ /* find earliest gchar that can be in contention */
start = s->offset - s->t->max_depth;
for (i=0;i<s->submatchp;i++)
if (s->submatches[i].offstart < start)
@@ -652,20 +652,20 @@ flush_extra(struct _searcher *s)
}
}
-static char *
+static gchar *
searcher_next_token(struct _searcher *s)
{
struct _token *token;
- const unsigned char *tok, *stok, *pre_tok;
+ const guchar *tok, *stok, *pre_tok;
struct _trie *t = s->t;
struct _state *q = s->state;
struct _match *m = NULL;
- int offstart, offend;
+ gint offstart, offend;
guint32 c;
while (e_dlist_empty(&s->output)) {
/* get next token */
- tok = (unsigned char *)s->next_token(s->next_data);
+ tok = (guchar *)s->next_token(s->next_data);
if (tok == NULL) {
output_subpending (s);
output_pending (s);
@@ -673,15 +673,15 @@ searcher_next_token(struct _searcher *s)
}
/* we dont always have to copy each token, e.g. if we dont match anything */
- token = append_token(&s->input, (char *)tok, -1);
+ token = append_token(&s->input, (gchar *)tok, -1);
token->offset = s->offset;
- tok = (unsigned char *)token->tok;
+ tok = (guchar *)token->tok;
d (printf("new token %d '%s'\n", token->offset, token->tok[0]==TAG_ESCAPE?token->tok+1:token->tok));
/* tag test, reset state on unknown tags */
if (tok[0] == TAG_ESCAPE) {
- if (!ignore_tag ((char *)tok)) {
+ if (!ignore_tag ((gchar *)tok)) {
/* force reset */
output_subpending (s);
output_pending (s);
@@ -712,7 +712,7 @@ searcher_next_token(struct _searcher *s)
if (q->final) {
s->matchcount++;
- /* use the last buffer to find the real offset of this char */
+ /* use the last buffer to find the real offset of this gchar */
offstart = s->last[(s->lastp - q->final)&s->last_mask];
offend = s->offset + (tok - stok);
@@ -755,10 +755,10 @@ searcher_next_token(struct _searcher *s)
return token ? g_strdup (token->tok) : NULL;
}
-static char *
+static gchar *
searcher_peek_token(struct _searcher *s)
{
- char *tok;
+ gchar *tok;
/* we just get it and then put it back, it's fast enuf */
tok = searcher_next_token(s);
@@ -781,9 +781,9 @@ searcher_pending (struct _searcher *s)
struct _search_info {
GPtrArray *strv;
- char *color;
- unsigned int size:8;
- unsigned int flags:8;
+ gchar *color;
+ guint size:8;
+ guint flags:8;
};
/** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **/
@@ -800,26 +800,26 @@ search_info_new (void)
}
static void
-search_info_set_flags(struct _search_info *si, unsigned int flags, unsigned int mask)
+search_info_set_flags(struct _search_info *si, guint flags, guint mask)
{
si->flags = (si->flags & ~mask) | (flags & mask);
}
static void
-search_info_set_color (struct _search_info *si, const char *color)
+search_info_set_color (struct _search_info *si, const gchar *color)
{
g_free (si->color);
si->color = g_strdup (color);
}
static void
-search_info_add_string (struct _search_info *si, const char *s)
+search_info_add_string (struct _search_info *si, const gchar *s)
{
- const unsigned char *start;
+ const guchar *start;
guint32 c;
if (s && s[0]) {
- const unsigned char *us = (unsigned char *) s;
+ const guchar *us = (guchar *) s;
/* strip leading whitespace */
start = us;
while ((c = camel_utf8_getc (&us))) {
@@ -830,14 +830,14 @@ search_info_add_string (struct _search_info *si, const char *s)
}
/* should probably also strip trailing, but i'm lazy today */
if (start[0])
- g_ptr_array_add (si->strv, g_strdup ((char *)start));
+ g_ptr_array_add (si->strv, g_strdup ((gchar *)start));
}
}
static void
search_info_clear (struct _search_info *si)
{
- int i;
+ gint i;
for (i=0;i<si->strv->len;i++)
g_free (si->strv->pdata[i]);
@@ -848,7 +848,7 @@ search_info_clear (struct _search_info *si)
static void
search_info_free (struct _search_info *si)
{
- int i;
+ gint i;
for (i=0;i<si->strv->len;i++)
g_free (si->strv->pdata[i]);
@@ -862,7 +862,7 @@ static struct _search_info *
search_info_clone (struct _search_info *si)
{
struct _search_info *out;
- int i;
+ gint i;
out = search_info_new ();
for (i=0;i<si->strv->len;i++)
@@ -877,7 +877,7 @@ search_info_clone (struct _search_info *si)
static struct _searcher *
search_info_to_searcher (struct _search_info *si)
{
- char *tags, *tage;
+ gchar *tags, *tage;
const gchar *col;
if (si->strv->len == 0)
@@ -893,7 +893,7 @@ search_info_to_searcher (struct _search_info *si)
tage = alloca(20);
sprintf(tage, "%c</font>", TAG_ESCAPE);
- return searcher_new (si->flags, si->strv->len, (unsigned char **)si->strv->pdata, tags, tage);
+ return searcher_new (si->flags, si->strv->len, (guchar **)si->strv->pdata, tags, tage);
}
/* ********************************************************************** */
@@ -909,7 +909,7 @@ struct _ESearchingTokenizerPrivate {
/* blah blah the htmltokeniser doesn't like being asked
for a token if it doens't hvae any! */
-static char *
+static gchar *
get_token (HTMLTokenizer *tokenizer)
{
HTMLTokenizerClass *class = HTML_TOKENIZER_CLASS (parent_class);
@@ -989,8 +989,8 @@ static gchar *
searching_tokenizer_next_token (HTMLTokenizer *tokenizer)
{
ESearchingTokenizerPrivate *priv;
- int oldmatched;
- char *token;
+ gint oldmatched;
+ gchar *token;
priv = E_SEARCHING_TOKENIZER_GET_PRIVATE (tokenizer);