Back to index

im-sdk  12.3.91
Defines | Functions
iiimpDL.c File Reference
#include <unistd.h>
#include <dlfcn.h>
#include "iiimpDL.h"
#include <sys/types.h>
#include <dirent.h>
#include "genutil.h"
#include "Xlcint.h"

Go to the source code of this file.

Defines

#define XLOCALEDIR   IIIMLIBDIR "/modules"

Functions

static XIMStyles * GetInputStyles (char *, void *)
static void * GetProc (void *, const char *)
static char * lc_path (const char *dl_name, const char *lc_dir)
static const char * has_so_suffix (const char *str)
XIMDLRecOpenDynamicObject (XLCd lcd)
void CloseDynamicObject (XIMDLRec *dl_object)

Define Documentation

#define XLOCALEDIR   IIIMLIBDIR "/modules"

Definition at line 109 of file iiimpDL.c.


Function Documentation

void CloseDynamicObject ( XIMDLRec dl_object)

Definition at line 191 of file iiimpDL.c.

                                        {
  if (dl_object->styles) Xfree(dl_object->styles);
  dlclose(dl_object->dl_module);
  return;
}

Here is the caller graph for this function:

static XIMStyles * GetInputStyles ( char *  lc_name,
void *  module 
) [static]

Definition at line 89 of file iiimpDL.c.

                                            {
  XIMStyles* (*get_styles)() = (XIMStyles*(*)())NULL;
  XIMStyles *values = (XIMStyles*)NULL;

  get_styles = (XIMStyles*(*)())dlsym(module, "GetInputStyles");

  values = (*get_styles)(lc_name);

  return values;
}

Here is the caller graph for this function:

static void * GetProc ( void *  module,
const char *  name 
) [static]

Definition at line 101 of file iiimpDL.c.

                                        {
  void *proc;

  proc = (void*)dlsym(module, name);
  return proc;
}

Here is the caller graph for this function:

static const char* has_so_suffix ( const char *  str) [static]

Definition at line 113 of file iiimpDL.c.

{
  int str_len;
  int suffix_len;
  
  if (str == NULL)
    return NULL;

  str_len = strlen (str);
  suffix_len = strlen (".so");

  if (str_len < suffix_len)
    return False;

  return ((strcmp (str + str_len - suffix_len, ".so") == 0)? str : 0);
         
}

Here is the caller graph for this function:

static char* lc_path ( const char *  dl_name,
const char *  lc_dir 
) [static]

Definition at line 65 of file iiimpDL.c.

                                                 {
  char *path;
  size_t len;

#ifdef _MACH64_NAME
  len = (lc_dir ? strlen(lc_dir) : 0 ) +
    (dl_name ? strlen(dl_name) : 0) + _MACH64_NAME_LEN + 10;
  path = Xmalloc(len + 1);

  strcpy(path, lc_dir); strcat(path, "/");
  strcat(path, _MACH64_NAME); strcat(path, "/");
  strcat(path, dl_name); strcat(path, ".so");
#else
  len = (lc_dir ? strlen(lc_dir) : 0 ) +
    (dl_name ? strlen(dl_name) : 0) + 10;
  path = Xmalloc(len + 1);

  strcpy(path, lc_dir); strcat(path, "/");
  strcat(path, dl_name); strcat(path, ".so");
#endif
  return path;
}

Definition at line 133 of file iiimpDL.c.

                            {
  void *module = NULL;
  XIMDLRec *dl_object = (XIMDLRec*)NULL;
  DIR *dir = NULL;
  struct dirent *entry;
  char *lc_name = lcd->core->name;
  char *filename;
  const size_t xlclocaledir_len = strlen (XLOCALEDIR);

  dir = opendir (XLOCALEDIR);
  if (dir == NULL)
    return NULL;

  while ((entry = readdir (dir)))
    {
      while (entry
            && (0 == strcmp (entry->d_name, ".") ||
               0 == strcmp (entry->d_name, "..")))
       entry = readdir (dir);
      if (entry && (filename = has_so_suffix (entry->d_name)) != NULL)
       {
         size_t len = xlclocaledir_len + strlen (filename) + 2;
         char *path = Xmalloc (len);
         strcpy (path, XLOCALEDIR);
         strcat (path, "/");
         strcat (path, filename);
         module = dlopen((char*)path, RTLD_LAZY);
         XFree (path);
         if (module)
           {
             dl_object = (XIMDLRec*)Xmalloc(sizeof(XIMDLRec));
             dl_object->dl_module = module;
             dl_object->styles = GetInputStyles(lc_name, module);
             dl_object->change_status =
              (ChangeStatusProc)GetProc(module,
                                     "ChangeStatus");
             dl_object->change_preedit =
              (ChangePreeditProc)GetProc(module,
                                      "ChangePreedit");
             dl_object->change_lookup =
              (ChangeLookupProc)GetProc(module,
                                     "ChangeLookup");
             dl_object->register_forwardevent =
              (RegisterForwardEventProc)GetProc(module,
                                            "RegisterForwardEvent");
           }
       }
      if (dl_object)
       break;
    }

  if (dir)
    closedir(dir);

  return dl_object;
}

Here is the call graph for this function:

Here is the caller graph for this function: