Back to index

im-sdk  12.3.91
Defines | Functions | Variables
lookup_data.c File Reference
#include <stdio.h>
#include <sys/stat.h>
#include "lookup_data.h"
#include "imbean.h"
#include <libxml/xmlmemory.h>
#include <libxml/parser.h>

Go to the source code of this file.

Defines

#define SYMBOL_LIST_NUM_ALLOC   10
#define SYMBOL_GROUP_LIST_NUM_ALLOC   10
#define LOOKUO_DATA_FILE_NAME   "symbol_groups_tw.xml"
#define SYMBOL_GROUPS_CATAGORY   "symbol_groups"

Functions

int lookup_data_read_profile_to_memory (char **info_ptr)
int lookup_data_parse_profile (lookup_data_t *lookup_data, char *xml_str, int size)
symbol_group_tsymbol_group_new ()
void symbol_group_destroy (symbol_group_t *symbol_group)
void symbol_group_print (symbol_group_t *symbol_group)
int symbol_group_pushback_symbol (symbol_group_t *symbol_group, char *symbol)
lookup_data_tlookup_data_new ()
void lookup_data_destroy (lookup_data_t *lookup_data)
void lookup_data_print (lookup_data_t *lookup_data)
int lookup_data_pushback_symbol_group (lookup_data_t *lookup_data, symbol_group_t *symbol_group)
void lookup_data_parse_symbol_group_item (symbol_group_t *symbol_group, IbmlProperty *ibml_property)
void lookup_data_parse_symbol_groups_info (lookup_data_t *lookup_data, IbmlCategory *ibml_category)

Variables

static char utf8_skip_data [256]

Define Documentation

#define LOOKUO_DATA_FILE_NAME   "symbol_groups_tw.xml"

Definition at line 213 of file lookup_data.c.

#define SYMBOL_GROUP_LIST_NUM_ALLOC   10

Definition at line 174 of file lookup_data.c.

#define SYMBOL_GROUPS_CATAGORY   "symbol_groups"

Definition at line 372 of file lookup_data.c.

#define SYMBOL_LIST_NUM_ALLOC   10

Definition at line 77 of file lookup_data.c.


Function Documentation

void lookup_data_destroy ( lookup_data_t lookup_data)

Definition at line 141 of file lookup_data.c.

{
    if (lookup_data == NULL)
        return;

    if (lookup_data->symbol_groups) {
        int i;

        for (i = 0; i < lookup_data->num_symbol_groups; i++) {
            if (lookup_data->symbol_groups[i])
                symbol_group_destroy(lookup_data->symbol_groups[i]);
        }
        free ((char *)lookup_data->symbol_groups);
    }

    free ((char *)lookup_data);
}

Here is the call graph for this function:

Definition at line 118 of file lookup_data.c.

{
    lookup_data_t *lookup_data = NULL;
    char *xml_str = NULL;
    int  len_xml_str;

    lookup_data = (lookup_data_t *) calloc(1, sizeof(lookup_data_t));
    if (lookup_data == NULL)
        return NULL;

    len_xml_str = lookup_data_read_profile_to_memory(&xml_str);
    if (len_xml_str <= 0) {
        return lookup_data;
    }

    lookup_data_parse_profile(lookup_data, xml_str, len_xml_str);

    if (xml_str != NULL)
        free ((char *) xml_str);

    return lookup_data;
}

Here is the call graph for this function:

int lookup_data_parse_profile ( lookup_data_t lookup_data,
char *  xml_str,
int  size 
)
void lookup_data_parse_symbol_group_item ( symbol_group_t symbol_group,
IbmlProperty ibml_property 
)

Definition at line 265 of file lookup_data.c.

{
    char *name, *value;
    char symbol[16], *ptr;

    name = (char *) ibml_property->name;
    if (!name || !*name)
        return;

    value = (char *) ibml_property->value;
    if (!value || !*value)
        return;

    if (!strcasecmp(name, "name")) {
        if (symbol_group->name)
            free ((char *)symbol_group->name);
        symbol_group->name = (char *) strdup(value);
    } else if (!strcasecmp(name, "symbols")) {
        ptr = value;
        while (ptr && *ptr) {
            int len;

            if (*ptr == ' ' ||
                *ptr == '\t' ||
                *ptr == '\n') {
                ptr ++;
                continue;
            }

            memset(symbol, 0, 16);

            /* get byte len of next utf8 character */
            len = utf8_skip_data[*(unsigned char *)ptr];
            strncpy(symbol, ptr, len);

            if (*symbol)
                symbol_group_pushback_symbol(symbol_group, symbol);

            ptr = ptr + len;
        }
    }

    return;
}

Here is the call graph for this function:

void lookup_data_parse_symbol_groups_info ( lookup_data_t lookup_data,
IbmlCategory ibml_category 
)

Definition at line 311 of file lookup_data.c.

{
    symbol_group_t *symbol_group;

    IbmlElement *ibml_element;
    IbmlProperty *ibml_property;

    int ret, i, j;

    char *id, *scope;

    if (ibml_category == NULL)
        return;
    if (ibml_category->num_elements <= 0)
        return;

    for (i = 0; i < ibml_category->num_elements; i++) {
        ibml_element = ibml_category->elements[i];
        if (!ibml_element)
            continue;
        if (ibml_element->num_properties <= 0)
            continue;

        id = (char *) ibml_element->id;
        scope = (char *) ibml_element->scope;
        DEBUG_printf("id:%s, scope:%s\n", id ? id : "NULL",
               scope ? scope : "NULL");
        if (!id || !*id)
            continue;

        symbol_group = (symbol_group_t *) symbol_group_new();
        if (symbol_group == NULL)
            continue;

        symbol_group->id = (char *) strdup(id);

        for (j = 0; j < ibml_element->num_properties; j++) {
            ibml_property = ibml_element->properties[j];
            if (!ibml_property)
                continue;

            lookup_data_parse_symbol_group_item(symbol_group, ibml_property);
        }

        if (symbol_group->id == NULL ||
            symbol_group->name == NULL) {
            symbol_group_destroy (symbol_group);
            continue;
        }

        ret = lookup_data_pushback_symbol_group(lookup_data, symbol_group);
        if (ret == LOOKUP_ERROR) {
            symbol_group_destroy (symbol_group);
            continue;
        }
    }

    return;
}

Here is the call graph for this function:

void lookup_data_print ( lookup_data_t lookup_data)

Definition at line 159 of file lookup_data.c.

{
    if (lookup_data == NULL)
        return;

    if (lookup_data->symbol_groups) {
        int i;

        for (i = 0; i < lookup_data->num_symbol_groups; i++) {
            if (lookup_data->symbol_groups[i])
                symbol_group_print(lookup_data->symbol_groups[i]);
        }
    }
}

Here is the call graph for this function:

int lookup_data_pushback_symbol_group ( lookup_data_t lookup_data,
symbol_group_t symbol_group 
)

Definition at line 175 of file lookup_data.c.

{
    int i, num_symbol_groups;

    if (lookup_data == NULL || symbol_group == NULL)
        return LOOKUP_ERROR;

    if (lookup_data->symbol_groups == NULL) {
        lookup_data->symbol_groups = (symbol_group_t **)
                                          calloc (SYMBOL_GROUP_LIST_NUM_ALLOC,
                                                  sizeof(symbol_group_t *));
        if (lookup_data->symbol_groups == NULL)
            return LOOKUP_ERROR;
    }

    num_symbol_groups = lookup_data->num_symbol_groups;
    if ((num_symbol_groups + 1) % SYMBOL_GROUP_LIST_NUM_ALLOC == 0) {
        int num = num_symbol_groups + 1 + SYMBOL_GROUP_LIST_NUM_ALLOC;

        lookup_data->symbol_groups = (symbol_group_t **)realloc(lookup_data->symbol_groups,
                                                                num * sizeof(symbol_group_t *));
        if (lookup_data->symbol_groups == NULL)
            return LOOKUP_ERROR;

        for (i = num_symbol_groups; i < num; i++)
            lookup_data->symbol_groups[i] = NULL;
    }

    lookup_data->symbol_groups[num_symbol_groups] = symbol_group;
    lookup_data->num_symbol_groups ++;

    return LOOKUP_OK;
}
int lookup_data_read_profile_to_memory ( char **  info_ptr)
void symbol_group_destroy ( symbol_group_t symbol_group)

Definition at line 30 of file lookup_data.c.

{
    if (symbol_group == NULL)
        return;

    if (symbol_group->id)
        free ((char *)symbol_group->id);

    if (symbol_group->name)
        free ((char *)symbol_group->name);

    if (symbol_group->symbols != NULL) {
        int i;
        for (i = 0; i < symbol_group->num_symbols; i ++) {
            if (symbol_group->symbols[i])
                free ((char *) symbol_group->symbols[i]);
        }
        free ((char *)symbol_group->symbols);
    }

    free ((char *)symbol_group);
}

Definition at line 21 of file lookup_data.c.

{
    symbol_group_t *symbol_group = NULL;

    symbol_group = (symbol_group_t *) calloc(1, sizeof(symbol_group_t));

    return symbol_group;
}
void symbol_group_print ( symbol_group_t symbol_group)

Definition at line 53 of file lookup_data.c.

{
#if DEBUG
    if (symbol_group == NULL)
        return;

    printf("Symbol Group: \n");
    if (symbol_group->id)
        printf("    id: %s\n", symbol_group->id);
    if (symbol_group->name)
        printf("    name: %s\n", symbol_group->name);

    if (symbol_group->symbols != NULL) {
        int i;
        printf("    symbols: ");
        for (i = 0; i < symbol_group->num_symbols; i ++) {
            if (symbol_group->symbols[i])
                printf ("%s ", (char *) symbol_group->symbols[i]);
        }
        printf("\n");
    }
#endif
}
int symbol_group_pushback_symbol ( symbol_group_t symbol_group,
char *  symbol 
)

Definition at line 78 of file lookup_data.c.

{
    int i, num_symbols;

    if (symbol_group == NULL || symbol == NULL)
        return LOOKUP_ERROR;

    if (symbol_group->symbols == NULL) {
        symbol_group->symbols = (char **) calloc (SYMBOL_LIST_NUM_ALLOC,
                                                  sizeof(char *));
        if (symbol_group->symbols == NULL)
            return LOOKUP_ERROR;
    }

    num_symbols = symbol_group->num_symbols;
    if ((num_symbols + 1) % SYMBOL_LIST_NUM_ALLOC == 0) {
        int num = num_symbols + 1 + SYMBOL_LIST_NUM_ALLOC;

        symbol_group->symbols = (char **)realloc(symbol_group->symbols,
                                                 num * sizeof(char *));
        if (symbol_group->symbols == NULL)
            return LOOKUP_ERROR;

        for (i = num_symbols; i < num; i++)
            symbol_group->symbols[i] = NULL;
    }

    symbol_group->symbols[num_symbols] = (char *)strdup(symbol);
    if (symbol_group->symbols[num_symbols] == NULL)
        return LOOKUP_ERROR;

    symbol_group->num_symbols ++;

    return LOOKUP_OK;
}

Variable Documentation

char utf8_skip_data[256] [static]
Initial value:
 {
  1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
  1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
  1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
  1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
  1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
  1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
  2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
  3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,6,6,1,1
}

Definition at line 254 of file lookup_data.c.