Back to index

im-sdk  12.3.91
Defines | Typedefs | Functions | Variables
neima_filter.c File Reference
#include <stdio.h>
#include <iconv.h>
#include "ime.h"
#include "ime_buffer.h"

Go to the source code of this file.

Defines

#define PREFIX_COMPLETE   (0x20000)
#define PREFIX_VALID   (0x10000)
#define HEXCANDIDATES   (0x0FFFF)
#define HEXVALUE(c)   ((c >= 'A')?(c-'A'+10):(c-'0'))

Typedefs

typedef int(* VALIDATE_PREFIX_FUNC )(unsigned char *)

Functions

int validate_prefix_gb2312 (unsigned char *prefix)
int validate_prefix_gbk (unsigned char *prefix)
int validate_prefix_gb18030 (unsigned char *prefix)
int validate_prefix_big5 (unsigned char *prefix)
int validate_prefix_big5hkscs (unsigned char *prefix)
int validate_prefix_euctw (unsigned char *prefix)
int validate_prefix (int encode, unsigned char *prefix)
int commit_all (ImeBufferRec *ime_buffer)
int neima_filter (int encoding, unsigned char key, ImeBufferRec *ime_buffer)

Variables

static unsigned char number_string [] = "0123456789ABCDEF"
VALIDATE_PREFIX_FUNC validators []

Define Documentation

#define HEXCANDIDATES   (0x0FFFF)

Definition at line 9 of file neima_filter.c.

#define HEXVALUE (   c)    ((c >= 'A')?(c-'A'+10):(c-'0'))

Definition at line 42 of file neima_filter.c.

#define PREFIX_COMPLETE   (0x20000)

Definition at line 7 of file neima_filter.c.

#define PREFIX_VALID   (0x10000)

Definition at line 8 of file neima_filter.c.


Typedef Documentation

typedef int(* VALIDATE_PREFIX_FUNC)(unsigned char *)

Definition at line 15 of file neima_filter.c.


Function Documentation

int commit_all ( ImeBufferRec ime_buffer)

Definition at line 43 of file neima_filter.c.

{
    unsigned char *p = ime_buffer->preedit.preedit.text, *dst =ime_buffer->commit_buf;

    for(; *p; p+=2)
        *dst++ = (HEXVALUE(*p) << 4) + HEXVALUE(*(p+1));
    *dst = 0;

    ime_buffer->preedit.preedit.text[0] = '\0';
    ime_buffer->preedit.caret = 0;
    ime_buffer->candidates.count = 0;
    ime_buffer->return_status |= (IME_COMMIT | IME_PREEDIT_AREA | IME_LOOKUP_AREA);
}
int neima_filter ( int  encoding,
unsigned char  key,
ImeBufferRec ime_buffer 
)

Definition at line 57 of file neima_filter.c.

{
    int  i, ret, preedit_len;
    unsigned char *p, *dst;

    ime_buffer->return_status = 0;
    preedit_len = strlen(ime_buffer->preedit.preedit.text);

    DEBUG_printf("    ====>neima: filter key(0x%x)\n", key);
    if ((key >= '0' && key <= '9') || (key >= 'a' && key <= 'f') || (key >= 'A' && key <= 'F')) {
        DEBUG_printf("        ====>neima:ime_buffer->preedit.preedit.text: %s (len=%d) key=%c(0x%x)\n", ime_buffer->preedit.preedit.text, preedit_len, key, key);

        ime_buffer->preedit.preedit.text[preedit_len] = toupper(key);
        ime_buffer->preedit.preedit.text[++preedit_len] = 0;

        ret = validate_prefix(encoding, ime_buffer->preedit.preedit.text);
        DEBUG_printf("        ====>Validating Key...result 0x%x...", ret);
        if (!(ret & PREFIX_VALID)) {
            DEBUG_printf("Invalid\n", key);
            ime_buffer->preedit.preedit.text[--preedit_len] = 0;
            return IME_INVALID_KEY;
        }
        DEBUG_printf("valid Key\n", key);
        DEBUG_printf("        ====>neima:ime_buffer->preedit.preedit.text: %s (len=%d) key=%c(0x%x)\n", ime_buffer->preedit.preedit.text, preedit_len, key, key);

        ime_buffer->preedit.caret = preedit_len;
        ime_buffer->return_status |= IME_PREEDIT_AREA;

        if (ret & PREFIX_COMPLETE) {
            printf("  [Neima IME] Commit all...\n");
            commit_all(ime_buffer);
        } else if (ret & PREFIX_VALID) {
            ime_buffer->candidates.count = 0;
            ime_buffer->candidates.page_state = ImeCandidatesFirstPage | ImeCandidatesLastPage;
            for (i=0; i < 16; ++i) {
                if (ret & 1) {
                    dst = ime_buffer->candidates.candidates[ime_buffer->candidates.count].text;
                    for(p=ime_buffer->preedit.preedit.text; *p && *(p+1); p+=2)
                        *dst++ = (HEXVALUE(*p) << 4) + HEXVALUE(*(p+1));
                    *dst++ = (HEXVALUE(*p) << 4) + i;
                    *dst = 0;
                    ime_buffer->candidates.numbers[ime_buffer->candidates.count] = number_string[i];
                    ime_buffer->candidates.numbers[ime_buffer->candidates.count+1] = 0;
                    ++ime_buffer->candidates.count;
                }
                ret >>= 1;
            }
            printf("    ====%d Candidates\n",  ime_buffer->candidates.count);
            if (ime_buffer->candidates.count) {
                ime_buffer->return_status |= IME_LOOKUP_AREA;

                #ifdef DEBUG
                for (i=0; i < ime_buffer->candidates.count; ++i) {
                    printf("          %c %s\n", 
                          ime_buffer->candidates.numbers[i], 
                          ime_buffer->candidates.candidates[i].text);
                }
                #endif
            }
        }
        return(IME_OK);
    }

    if(key == IME_FILTERED_KEY_ESCAPE && preedit_len > 0) {
        clear_ime_buffer(ime_buffer);
        ime_buffer->return_status |= (IME_PREEDIT_AREA | IME_LOOKUP_AREA);
        return (IME_OK);
    }

    if ((key == IME_FILTERED_KEY_BACKSPACE || key == IME_FILTERED_KEY_DELETE) && (preedit_len > 0)) {
        ime_buffer->preedit.preedit.text[--preedit_len] = '\0';
        ime_buffer->return_status = IME_PREEDIT_AREA;
        ime_buffer->candidates.count = 0;
        ime_buffer->return_status |= IME_LOOKUP_AREA;
        return(IME_OK);
    }

    return (preedit_len == 0)?(IME_UNUSED_KEY):(IME_INVALID_KEY);
}

Here is the call graph for this function:

int validate_prefix ( int  encode,
unsigned char *  prefix 
)

Definition at line 35 of file neima_filter.c.

{
    if (encode >= ENCODE_GB2312 && encode <= ENCODE_EUCTW)
        return validators[encode](prefix);
    return 0;
}
int validate_prefix_big5 ( unsigned char *  prefix)
int validate_prefix_big5hkscs ( unsigned char *  prefix)
int validate_prefix_euctw ( unsigned char *  prefix)
int validate_prefix_gb18030 ( unsigned char *  prefix)
int validate_prefix_gb2312 ( unsigned char *  prefix)
int validate_prefix_gbk ( unsigned char *  prefix)

Variable Documentation

unsigned char number_string[] = "0123456789ABCDEF" [static]

Definition at line 24 of file neima_filter.c.