1 /* -*- c-basic-offset:2; tab-width:2; indent-tabs-mode:nil -*- */ 2 3 #include "ui_type_loader.h" 4 5 #ifndef NO_DYNAMIC_LOAD_TYPE 6 7 #include <stdio.h> /* NULL */ 8 #include <pobl/bl_dlfcn.h> 9 #include <pobl/bl_debug.h> 10 11 #ifndef LIBDIR 12 #define TYPELIB_DIR "/usr/local/lib/mlterm/" 13 #else 14 #define TYPELIB_DIR LIBDIR "/mlterm/" 15 #endif 16 17 /* --- global functions --- */ 18 ui_load_type_xft_func(ui_type_id_t id)19void *ui_load_type_xft_func(ui_type_id_t id) { 20 static void **func_table; 21 static int is_tried; 22 23 if (!is_tried) { 24 bl_dl_handle_t handle; 25 26 is_tried = 1; 27 28 if ((!(handle = bl_dl_open(TYPELIB_DIR, "type_xft")) && 29 !(handle = bl_dl_open("", "type_xft")))) { 30 bl_error_printf("xft: Could not load.\n"); 31 32 return NULL; 33 } 34 35 #ifdef DEBUG 36 bl_debug_printf(BL_DEBUG_TAG " Loading libtype_xft.so\n"); 37 #endif 38 39 bl_dl_close_at_exit(handle); 40 41 func_table = bl_dl_func_symbol(handle, "ui_type_xft_func_table"); 42 43 if ((u_int32_t)func_table[TYPE_API_COMPAT_CHECK] != TYPE_API_COMPAT_CHECK_MAGIC) { 44 bl_dl_close(handle); 45 func_table = NULL; 46 bl_error_printf("Incompatible type engine API.\n"); 47 48 return NULL; 49 } 50 } 51 52 if (func_table) { 53 return func_table[id]; 54 } else { 55 return NULL; 56 } 57 } 58 ui_load_type_cairo_func(ui_type_id_t id)59void *ui_load_type_cairo_func(ui_type_id_t id) { 60 static void **func_table; 61 static int is_tried; 62 63 if (!is_tried) { 64 bl_dl_handle_t handle; 65 66 is_tried = 1; 67 68 if ((!(handle = bl_dl_open(TYPELIB_DIR, "type_cairo")) && 69 !(handle = bl_dl_open("", "type_cairo")))) { 70 bl_error_printf("cairo: Could not load.\n"); 71 72 return NULL; 73 } 74 75 #ifdef DEBUG 76 bl_debug_printf(BL_DEBUG_TAG " Loading libtype_cairo.so\n"); 77 #endif 78 79 bl_dl_close_at_exit(handle); 80 81 func_table = bl_dl_func_symbol(handle, "ui_type_cairo_func_table"); 82 83 if ((u_int32_t)func_table[TYPE_API_COMPAT_CHECK] != TYPE_API_COMPAT_CHECK_MAGIC) { 84 bl_dl_close(handle); 85 func_table = NULL; 86 bl_error_printf("Incompatible type engine API.\n"); 87 88 return NULL; 89 } 90 } 91 92 if (func_table) { 93 return func_table[id]; 94 } else { 95 return NULL; 96 } 97 } 98 99 #endif /* NO_DYNAMIC_LOAD_TYPE */ 100