File: x_type_loader.c

package info (click to toggle)
mlterm 3.1.2-1.3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 23,168 kB
  • sloc: ansic: 102,795; sh: 9,676; java: 2,018; perl: 1,601; makefile: 1,595; cpp: 771; sed: 16
file content (121 lines) | stat: -rw-r--r-- 2,036 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121

/*
 *	$Id$
 */

#include  "x_type_loader.h"


#ifndef  NO_DYNAMIC_LOAD_TYPE

#include  <stdio.h>		/* NULL */
#include  <kiklib/kik_dlfcn.h>
#include  <kiklib/kik_debug.h>


#ifndef  LIBDIR
#define  TYPELIB_DIR  "/usr/local/lib/mlterm/"
#else
#define  TYPELIB_DIR  LIBDIR "/mlterm/"
#endif


/* --- global functions --- */

void *
x_load_type_xft_func(
	x_type_id_t  id
	)
{
	static void **  func_table ;
	static int  is_tried ;

	if( ! is_tried)
	{
		kik_dl_handle_t  handle ;

		is_tried = 1 ;

		if( ( ! ( handle = kik_dl_open( TYPELIB_DIR , "type_xft")) &&
		      ! ( handle = kik_dl_open( "" , "type_xft"))))
		{
			kik_error_printf( "xft: Could not load.\n") ;

			return  NULL ;
		}

	#ifdef  DEBUG
		kik_debug_printf( KIK_DEBUG_TAG " Loading libtype_xft.so\n") ;
	#endif

		func_table = kik_dl_func_symbol( handle , "x_type_xft_func_table") ;

		if( (u_int32_t)func_table[TYPE_API_COMPAT_CHECK] != TYPE_API_COMPAT_CHECK_MAGIC)
		{
			kik_dl_close( handle) ;
			func_table = NULL ;
			kik_error_printf( "Incompatible type engine API.\n") ;

			return  NULL ;
		}
	}

	if( func_table)
	{
		return  func_table[id] ;
	}
	else
	{
		return  NULL ;
	}
}

void *
x_load_type_cairo_func(
	x_type_id_t  id
	)
{
	static void **  func_table ;
	static int  is_tried ;

	if( ! is_tried)
	{
		kik_dl_handle_t  handle ;

		is_tried = 1 ;

		if( ( ! ( handle = kik_dl_open( TYPELIB_DIR , "type_cairo")) &&
		      ! ( handle = kik_dl_open( "" , "type_cairo"))))
		{
			kik_error_printf( "cairo: Could not load.\n") ;

			return  NULL ;
		}

	#ifdef  DEBUG
		kik_debug_printf( KIK_DEBUG_TAG " Loading libtype_cairo.so\n") ;
	#endif

		func_table = kik_dl_func_symbol( handle , "x_type_cairo_func_table") ;

		if( (u_int32_t)func_table[TYPE_API_COMPAT_CHECK] != TYPE_API_COMPAT_CHECK_MAGIC)
		{
			kik_dl_close( handle) ;
			func_table = NULL ;
			kik_error_printf( "Incompatible type engine API.\n") ;

			return  NULL ;
		}
	}

	if( func_table)
	{
		return  func_table[id] ;
	}
	else
	{
		return  NULL ;
	}
}

#endif	/* NO_DYNAMIC_LOAD_TYPE */