Back to index

im-sdk  12.3.91
Classes | Defines | Typedefs | Functions
hhentry.h File Reference
#include <iconv.h>
#include "utfchar.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _HH
struct  _HHItem
struct  _HHList

Defines

#define HASH_TABLE_NUMBER   256
#define IIIM_KO_LE_DIC   "IIIM-KO-LE-DIC"

Typedefs

typedef struct _HH HH
typedef struct _HHItem HHItem
typedef struct _HHItemHHEntry
typedef struct _HHList HHList

Functions

void hh_free (HH *)
HHhh_new ()
HHEntry hhitem_new ()
HHEntry hhitem_new_with_data (HH *)
void hhitem_init (HHEntry hhentry)
HHEntry hhitem_add_hanja (HHEntry hhentry, unsigned char *utf_hanja)
void hhlist_init (HHList *hhlist)
void hhlist_add_hhitem (HHList *hhlist, HHEntry hhitem)
HHEntry hhlist_add_hh (HHList *hhlist, HH *item)
HHEntry hhlist_search_hhitem (HHList *hhlist, HH *hh)
void hhlist_dump_content (HHList *hhlist, FILE *fp)
void hhlist_read_from_file (FILE *fp, HHList *hhlist)
void hhitem_read_from_file (FILE *fp, HHEntry entry_return)
int hash (UTFCHAR *string)
HHprocess_hangul_hanja_pair (iconv_t cd, char *str_hangul, char *str_hanja)
void hash_table_dump_content (HHList table[], int size, FILE *fp)

Class Documentation

struct _HH

Definition at line 9 of file hhentry.h.

Class Members
unsigned char * utf_hangul
unsigned char * utf_hanja
struct _HHItem

Definition at line 16 of file hhentry.h.

Class Members
unsigned char * hangul
unsigned char ** hanja_list
int n_hanja
struct _HHList

Definition at line 22 of file hhentry.h.

Collaboration diagram for _HHList:
Class Members
HHEntry * list
HHItem ** list
int n_count

Define Documentation

#define HASH_TABLE_NUMBER   256

Definition at line 6 of file hhentry.h.

#define IIIM_KO_LE_DIC   "IIIM-KO-LE-DIC"

Definition at line 7 of file hhentry.h.


Typedef Documentation

typedef struct _HH HH
typedef struct _HHItem * HHEntry
typedef struct _HHItem HHItem
typedef struct _HHList HHList

Function Documentation

int hash ( UTFCHAR string)

Definition at line 565 of file hhentry.c.

{
  UTFCHAR *p;
  int hv = 0;
  
  for (p = string; *p; p++){
    hv += *p;
  }
  hv = (hv >> 2) & 0x00ff;
  return hv;
}
void hash_table_dump_content ( HHList  table[],
int  size,
FILE *  fp 
)

Definition at line 301 of file hhentry.c.

{
  int i;
  char *dict_name = IIIM_KO_LE_DIC;
  int major_version = 1;
  int minor_version = 5;
  int version_signature;

  int table_size  = size;

  version_signature = 0;
  
  version_signature = (major_version & 0x0f);
  version_signature = (version_signature << 8) | (minor_version & 0x0000000f);

  /* write dictionary name to file*/
  fwrite (dict_name, strlen(dict_name) + 1, 1, fp);

  /* write version signature */
  put_int24_to_file (version_signature, fp);

  /* write info for number of tables */
  put_int24_to_file (table_size, fp);
  
  for (i = 0  ; i < table_size; i++){
    hhlist_dump_content (&table[i], fp);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void hh_free ( HH )

Definition at line 16 of file hhentry.c.

{
  assert (hh != NULL);
  if (hh == NULL)
    return;
  free (hh->utf_hangul);
  free (hh->utf_hanja);
  free (hh);
  hh = NULL;
}
HH* hh_new ( )

Definition at line 28 of file hhentry.c.

{
  HH *new_hh;
  new_hh = (HH *) calloc (1, sizeof (HH));
  return new_hh;
}
HHEntry hhitem_add_hanja ( HHEntry  hhentry,
unsigned char *  utf_hanja 
)

Definition at line 118 of file hhentry.c.

{
  int n_hanja;
  unsigned char **tmp;
  
  assert (hhentry != NULL);
  assert (utf_hanja != NULL);
  if (hhentry == NULL || utf_hanja == NULL)
    return NULL;
  n_hanja = hhentry->n_hanja;

  tmp = (unsigned char **) calloc (n_hanja + 1, sizeof (unsigned char *));
  memcpy (tmp, hhentry->hanja_list, n_hanja * sizeof (unsigned char *));
  tmp[n_hanja] = (unsigned char *) strdup (utf_hanja);
  
  free (hhentry->hanja_list);
  hhentry->hanja_list = tmp;
  hhentry->n_hanja += 1;
  return hhentry;
}

Here is the caller graph for this function:

void hhitem_init ( HHEntry  hhentry)

Definition at line 94 of file hhentry.c.

{
  int n;
  assert (hhentry != NULL);
  
  free (hhentry->hangul);
  hhentry->hangul = NULL;
  
  for (n = 0 ; n < hhentry->n_hanja; n++){
    free (hhentry->hanja_list[n]);
  }
  free (hhentry->hanja_list);
  hhentry->hanja_list = NULL;
  hhentry->n_hanja = 0;
}

Here is the caller graph for this function:

Definition at line 60 of file hhentry.c.

{
  HHEntry new_entry;
  new_entry = (HHEntry) calloc (1, sizeof (HHItem));
  new_entry->n_hanja = 0;
  new_entry->hanja_list = NULL;
  new_entry->hangul = NULL;

  return new_entry;
}

Definition at line 72 of file hhentry.c.

{
  HHEntry new_entry;

  assert (hh != NULL);
  assert (hh->utf_hangul != NULL);
  assert (hh->utf_hanja != NULL);
  
  new_entry = (HHEntry) calloc (1, sizeof (HHItem));
  new_entry->n_hanja = 1;
  new_entry->hangul = (unsigned char *) strdup (hh->utf_hangul);
  new_entry->hanja_list =
    (unsigned char **) calloc (1, sizeof (unsigned char *));
  new_entry->hanja_list[0] =
    (unsigned char *) strdup (hh->utf_hanja);;

  return new_entry;
}
void hhitem_read_from_file ( FILE *  fp,
HHEntry  entry_return 
)

Definition at line 353 of file hhentry.c.

{
  int n_hanja;
  int total_length;
  int hangul_length;
  
  int i;
  int j;

  assert (entry_return != NULL);
  /* read length info of this HHItem
     this is not used for now
  */
  get_int24_from_file (&total_length, fp);

  /* read length info of hangul */
  get_int24_from_file (&hangul_length, fp);

  /* read hangul */
  entry_return->hangul =
    (unsigned char *)calloc (hangul_length + 1, sizeof (unsigned char));
  fread (entry_return->hangul, sizeof(unsigned char), hangul_length + 1, fp);

  /* read info for number of hanja */
  get_int24_from_file (&n_hanja, fp);
  entry_return->n_hanja = n_hanja;
  
  entry_return->hanja_list =
    (unsigned char **) calloc (n_hanja, sizeof (unsigned char *));
  for (i = 0 ; i < n_hanja; i++){
    /* now read length info of each hanja string */
    get_int24_from_file (&j, fp);
    entry_return->hanja_list[i] =
      (unsigned char *) calloc (j + 1, sizeof (unsigned char));
    fread (entry_return->hanja_list[i], sizeof (unsigned char), j + 1, fp);
  }
  return;
}

Here is the call graph for this function:

Here is the caller graph for this function:

HHEntry hhlist_add_hh ( HHList hhlist,
HH item 
)

Definition at line 442 of file hhentry.c.

{
  HHEntry hhitem;
  HHEntry *tmp;
  int n_count;

  assert (hhlist != NULL);
  assert (item != NULL);

  if (hhlist == NULL || item == NULL)
    return NULL;

  n_count = hhlist->n_count;
  
  hhitem = hhlist_search_hhitem (hhlist, item);

  if (hhitem == NULL){
    /* need to add new item */
    hhitem = hhitem_new_with_data (item);
    tmp = (HHEntry *) calloc (n_count + 1, sizeof (HHEntry));
    memcpy (tmp, hhlist->list, n_count * sizeof (HHEntry ));
    tmp[n_count] = hhitem;
    free (hhlist->list);
    hhlist->list = tmp;
    hhlist->n_count = n_count +1;
    
  } else {
    /* need to update existing item */
    hhitem_add_hanja (hhitem, item->utf_hanja);
  }

  return hhitem;
}
void hhlist_add_hhitem ( HHList hhlist,
HHEntry  hhitem 
)

Definition at line 423 of file hhentry.c.

{
  
  int n_count;
  HHEntry *tmp;
  assert (hhlist != NULL);
  assert (hhitem != NULL);

  n_count = hhlist->n_count;
  tmp = (HHEntry *) calloc (n_count + 1, sizeof (HHEntry));
  memcpy (tmp, hhlist->list, n_count * sizeof (HHEntry));

  tmp [n_count] =  hhitem_new ();
  hhentry_copy (tmp [n_count], hhitem);
  hhlist->n_count += 1;
  hhlist->list = tmp;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void hhlist_dump_content ( HHList hhlist,
FILE *  fp 
)

Definition at line 234 of file hhentry.c.

{
  int i;
  int i_total;
  HHEntry p_cursor;
  unsigned char buffer_return[1024];
  unsigned char *tmp;
  int dump_return;

  i_total = hhlist->n_count;
  put_int24_to_file (i_total, fp);
  
  for (i = 0 ; i < hhlist->n_count; i++){
    p_cursor = hhlist->list[i];
    dump_return = hhitem_serialize ( p_cursor,
                                 sizeof (buffer_return), buffer_return);
    if (dump_return){
      fwrite (buffer_return, 1, dump_return, fp);
    } else {
      fprintf
       (stderr, "fatal error: hhlist_dump_content, buffer not enough\n");
      exit (-1);
      tmp = (unsigned char *) calloc (2048, sizeof (unsigned char));
      dump_return = hhitem_serialize (p_cursor, 2048, tmp);
      fwrite (tmp, 1, dump_return, fp);
      free (tmp);
    }
  }
}
void hhlist_init ( HHList hhlist)

Definition at line 477 of file hhentry.c.

{
  assert (hhlist != NULL);
  hhlist->n_count = 0;
  hhlist = NULL;
}
void hhlist_read_from_file ( FILE *  fp,
HHList hhlist 
)

Definition at line 332 of file hhentry.c.

{
  int i_total;
  int i;
  HHEntry hhentry;
  hhlist_init (hhlist);

  /* number of hangul-hanja pairs in this bucket */
  get_int24_from_file (&i_total, fp);

  hhentry = hhitem_new ();

  for (i = 0 ; i < i_total; i++){
    hhitem_init (hhentry);
    hhitem_read_from_file (fp, hhentry);
    hhlist_add_hhitem (hhlist, hhentry);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

HHEntry hhlist_search_hhitem ( HHList hhlist,
HH hh 
)

Definition at line 405 of file hhentry.c.

{
  int i;
  assert (hhlist != NULL);
  assert (hh != NULL);

  if (hhlist == NULL || hh == NULL){
    return NULL;
  }

  for (i = 0 ; i < hhlist->n_count; i++){
    if ( strcmp (hhlist->list[i]->hangul, hh->utf_hangul) == 0)
      return hhlist->list[i];
  }
  return NULL;
}
HH* process_hangul_hanja_pair ( iconv_t  cd,
char *  str_hangul,
char *  str_hanja 
)

Definition at line 165 of file md.c.

{
  int len_hangul, len_hanja;
  char *ptr_from, *ptr_to;
  char euc_hangul[100], euc_hanja[100];
  char utf_hangul[100], utf_hanja[100];
  int len_from, len_to;
  size_t iconv_return;


  HH *hh_return;
  
  assert (str_hangul != NULL);
  assert (str_hanja != NULL);
  
  len_hangul = strlen (str_hangul);

  len_hanja = strlen (str_hanja);
  if (cd == (iconv_t)-1){
    hh_return = (HH *) calloc (1, sizeof (HH));
    hh_return->utf_hangul = (unsigned char *)strdup (str_hangul);
    hh_return->utf_hanja = (unsigned char *)strdup (str_hanja);
    return hh_return;
    
  } else {
  
    strcpy (euc_hangul, str_hangul);
    strcpy (euc_hanja, str_hanja);

    hh_return = (HH *) calloc (1, sizeof (HH));
    hh_return->utf_hangul = NULL;
    hh_return->utf_hanja = NULL;
  
    ptr_from = euc_hangul, ptr_to = utf_hangul;
    len_from = strlen (euc_hangul), len_to = sizeof (utf_hangul);
                
    iconv_return =
      iconv (cd, &ptr_from, &len_from, &ptr_to, &len_to);
    if (iconv_return == (size_t) -1){
      fprintf (stderr, "There was an error doing iconv with %s\n",
              euc_hangul);
      perror ("Following error:\n");
      return NULL;
    } else {
      /*
       int u8_len = 0;
      */
      int j;

      j = 100 - len_to;

      hh_return->utf_hangul =
       (unsigned char *) calloc (j +1, sizeof (unsigned char));
      memcpy (hh_return->utf_hangul, utf_hangul, j);
    }
  
    ptr_from = euc_hanja, ptr_to = utf_hanja;
    len_from = strlen (euc_hanja), len_to = sizeof (utf_hanja);
                
    iconv_return =
      iconv (cd, &ptr_from, &len_from, &ptr_to, &len_to);
    if (iconv_return == (size_t) -1){
      fprintf (stderr, "There was an error doing iconv with %s\n",
              euc_hanja);
      perror ("Following error:\n");
      return NULL;
    } else {
      int j;

      j = 100 - len_to;
    
      hh_return->utf_hanja =
       (unsigned char *) calloc (j + 1, sizeof (unsigned char));
      memcpy (hh_return->utf_hanja, utf_hanja, j);
    }
    return hh_return;
  }



}

Here is the caller graph for this function: