Logo Search packages:      
Sourcecode: m17n-lib version File versions  Download package

int mdatabase__init ( void   ) 

The macro M17NDIR specifies a directory where the system-wide MDB_DIR file exists.

Definition at line 484 of file database.c.

References MDatabase::extra_info, MDatabase::loader, M17N_OBJECT_UNREF, and MDatabase::tag.

{
  char *dir;
  int i;
  MPlist *plist;
  FILE *fp;

  Mchar_table = msymbol ("char-table");

  mdb_dir_list = mplist ();
  /** The macro M17NDIR specifies a directory where the system-wide
    MDB_DIR file exists.  */
  if ((dir = duplicate_dirname (M17NDIR)))
    mplist_set (mdb_dir_list, Mt, dir);

  /* The variable mdatabase_dir specifies a directory where an
     application program specific MDB_DIR file exists.  */
  if ((dir = duplicate_dirname (mdatabase_dir)))
    mplist_push (mdb_dir_list, Mt, dir);

  /* The environment variable M17NDIR (if non-NULL) specifies a
     directory where a user specific MDB_DIR file exists.  */
  if ((dir = duplicate_dirname (getenv ("M17NDIR"))))
    mplist_push (mdb_dir_list, Mt, dir);

  MLIST_INIT1 (&mdb_list, mdbs, 256);
  MPLIST_DO (plist, mdb_dir_list)
    {
      MPlist *pl, *p;
      int len;
      char path[PATH_MAX];

      dir = (char *) MPLIST_VAL (plist);
      len = strlen (dir);
      if (len + MDB_DIR_LEN >= PATH_MAX)
      continue;
      memcpy (path, dir, len);
      memcpy (path + len, MDB_DIR, MDB_DIR_LEN);
      if (! (fp = fopen (path, "r")))
      continue;
      pl = mplist__from_file (fp);
      fclose (fp);
      if (! pl)
      continue;
      MPLIST_DO (p, pl)
      {
        MDatabase mdb;
        MPlist *p1;
        int nbytes;

        if (! MPLIST_PLIST_P (p))
          continue;
        for (i = 0, p1 = MPLIST_PLIST (p);
             i < 4 && MPLIST_KEY (p1) == Msymbol;
             i++, p1 = MPLIST_NEXT (p1))
          mdb.tag[i] = MPLIST_SYMBOL (p1);
        if (i == 0
            || ! MPLIST_MTEXT_P (p1))
          continue;
        for (; i < 4; i++)
          mdb.tag[i] = Mnil;
        if (mdatabase_find (mdb.tag[0], mdb.tag[1],
                        mdb.tag[2], mdb.tag[3]))
          continue;

        mdb.loader = load_database;
        nbytes = mconv_encode_buffer (Mcoding_utf_8,  MPLIST_MTEXT (p1),
                              (unsigned char *) path, PATH_MAX);
        if (nbytes < 0 || nbytes >= PATH_MAX)
          continue;
        path[nbytes++] = '\0';
        mdb.extra_info = (void *) strdup (path);
        MLIST_APPEND1 (&mdb_list, mdbs, mdb, MERROR_DB);
      }
      M17N_OBJECT_UNREF (pl);
    }

  mdatabase__finder = ((void *(*) (MSymbol, MSymbol, MSymbol, MSymbol))
                   mdatabase_find);
  mdatabase__loader = (void *(*) (void *)) mdatabase_load;

  return 0;
}


Generated by  Doxygen 1.6.0   Back to index