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 _HHList HHList

Functions

void hh_free (HH *)
HHhh_new ()
HHItemhhitem_new ()
HHItemhhitem_new_with_data (HH *)
void hhitem_free (HHItem *entry)
void hhitem_init (HHItem *hhentry)
int hhitem_comp (HHItem *a, HHItem *b)
HHItemhhitem_add_hanja (HHItem *hhentry, unsigned char *utf_hanja)
void hhitem_copy (HHItem *dst, HHItem *src)
void hhlist_init (HHList *hhlist)
void hhlist_add_hhitem (HHList *hhlist, HHItem *hhitem)
HHItemhhlist_add_hh (HHList *hhlist, HH *item)
HHItemhhlist_search_hhitem (HHList *hhlist, HH *hh)
void hhitem_print_string (HHItem *hhitem, FILE *fp)
void hhlist_dump_content (HHList *hhlist, FILE *fp)
void hhitem_read_from_file (FILE *fp, HHItem *entry_return)
int hash (UTFCHAR *string)
HHprocess_hangul_hanja_pair (iconv_t cd, char *str_hangul, char *str_hanja)

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 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;
}

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;
}

Here is the caller graph for this function:

HH* hh_new ( )

Definition at line 28 of file hhentry.c.

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

Definition at line 133 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;
}
int hhitem_comp ( HHItem a,
HHItem b 
)

Definition at line 126 of file hhentry.c.

{
  return strcmp (a->hangul, b->hangul);

}
void hhitem_copy ( HHItem dst,
HHItem src 
)

Definition at line 156 of file hhentry.c.

{
  int n_hanja;
  int utf_len;
  assert (dst != NULL);
  assert (src != NULL);

  if (dst == NULL || src == NULL)
    return ;
  utf_len = strlen (src->hangul);
  if (dst->hangul)
    free (dst->hangul);
  
  dst->hangul = (unsigned char *) calloc (utf_len +1, sizeof (unsigned char));
  strcpy (dst->hangul, src->hangul);
  
  dst->n_hanja = src->n_hanja;

  if (dst->hanja_list)
    free (dst->hanja_list);
  
  dst->hanja_list =
    (unsigned char **) calloc (src->n_hanja, sizeof (unsigned char *));
  for (n_hanja = 0; n_hanja < dst->n_hanja; n_hanja++){
    utf_len = strlen (src->hanja_list[n_hanja]);
    dst->hanja_list[n_hanja] =
      (unsigned char *) calloc (utf_len +1, sizeof (unsigned char));
    strcpy (dst->hanja_list[n_hanja], src->hanja_list[n_hanja]);
  }
}

Here is the caller graph for this function:

void hhitem_free ( HHItem entry)

Definition at line 68 of file hhentry.c.

{
  int i;

  assert (entry != NULL);
  
  if (entry == NULL){
    fprintf (stderr, "hhitem_free error: entry or *entry is null\n");
    return;
  }
  if (entry->hangul){
    free (entry->hangul);
  }
  for (i = 0 ; i < entry->n_hanja; i++){
    free (entry->hanja_list[i]);
  }
  free (entry->hanja_list);
  free (entry);
}

Here is the caller graph for this function:

void hhitem_init ( HHItem hhentry)

Definition at line 109 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;
}

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;
}

Here is the caller graph for this function:

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;
}

Here is the caller graph for this function:

void hhitem_print_string ( HHItem hhitem,
FILE *  fp 
)

Definition at line 514 of file hhentry.c.

{
  int n;
  assert (hhitem != NULL);
  if (fp == NULL)
    fp = stdout;
  
  fprintf (fp, "HANGUL[");
  fprintf (fp, hhitem->hangul);
#if 0
  _utfchar_print (hhitem->hangul);
#endif
  fprintf (fp, "]: HANJA[ ");
  
  for (n = 0 ; n < hhitem->n_hanja; n++){
#if 0
    _utfchar_print (hhitem->hanja_list[n]);
#endif
    fprintf (fp, hhitem->hanja_list[n]);
    fprintf (fp, " ");
  }
  fprintf (fp, "]");
}

Here is the call graph for this function:

Here is the caller graph for this function:

void hhitem_read_from_file ( FILE *  fp,
HHItem entry_return 
)

Definition at line 390 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:

HHItem* 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;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void hhlist_add_hhitem ( HHList hhlist,
HHItem hhitem 
)

Definition at line 460 of file hhentry.c.

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

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

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

Here is the call 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);
    }
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void hhlist_init ( HHList hhlist)

Definition at line 477 of file hhentry.c.

{
  assert (hhlist != NULL);
  hhlist->n_count = 0;
  hhlist = NULL;
}

Here is the caller graph for this function:

HHItem* 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;
}

Here is the caller graph for this function:

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;
  }



}