File: tifiles.c

package info (click to toggle)
libtifiles 1.1.1-1
  • links: PTS
  • area: main
  • in suites: squeeze, wheezy
  • size: 3,088 kB
  • ctags: 1,531
  • sloc: ansic: 11,997; sh: 9,149; makefile: 184; sed: 16
file content (124 lines) | stat: -rw-r--r-- 2,996 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
122
123
124
/* Hey EMACS -*- linux-c -*- */
/* $Id: tifiles.c 4022 2007-11-11 18:49:02Z kevinkofler $ */

/*  libtifiles - file format library, a part of the TiLP project
 *  Copyright (C) 1999-2005  Romain Lievin
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

/*
  This unit contains the interface of the libtifiles library.
*/

#ifdef HAVE_CONFIG_H
#  include <config.h>
#endif

#include <stdio.h>
#include <string.h>
#ifdef ENABLE_NLS
#include <locale.h>
#endif
#ifdef __WIN32__
#include <windows.h>
#endif

#include "gettext.h"
#include "tifiles.h"
#include "logging.h"

/****************/
/* Entry points */
/****************/

// not static, must be shared between instances
int tifiles_instance = 0;	// counts # of instances

/**
 * tifiles_library_init:
 *
 * This function must be the first one to call. It inits library internals.
 *
 * Return value: the handle count.
 **/
TIEXPORT2 int TICALL tifiles_library_init()
{
	char locale_dir[65536];
	
#ifdef __WIN32__
  	HANDLE hDll;
  	int i;
  	
	hDll = GetModuleHandle("libtifiles2-5.dll");
  	GetModuleFileName(hDll, locale_dir, 65535);

  	for (i = strlen(locale_dir); i >= 0; i--) 
	{
    		if (locale_dir[i] == '\\')
      			break;
  	}  	
  	locale_dir[i] = '\0';

#ifdef __MINGW32__
   strcat(locale_dir, "\\..\\share\\locale");
#else
   strcat(locale_dir, "\\locale");
#endif
#else
	strcpy(locale_dir, LOCALEDIR);
#endif

	if (tifiles_instance)
		return (++tifiles_instance);
	tifiles_info( _("tifiles library version %s"), LIBFILES_VERSION);

#if defined(ENABLE_NLS)
	tifiles_info("setlocale: %s", setlocale(LC_ALL, ""));
  	tifiles_info("bindtextdomain: %s", bindtextdomain(PACKAGE, locale_dir));
  	//bind_textdomain_codeset(PACKAGE, "UTF-8"/*"ISO-8859-15"*/);
  	tifiles_info("textdomain: %s", textdomain(PACKAGE));
#endif

  	return (++tifiles_instance);
}

/**
 * tifiles_library_exit:
 *
 * This function must be the last one to call. Used to release internal resources.
 *
 * Return value: the handle count.
 **/
TIEXPORT2 int TICALL tifiles_library_exit()
{
  	return (--tifiles_instance);
}

/***********/
/* Methods */
/***********/

/**
 * tifiles_version_get:
 *
 * This function returns the library version like "X.Y.Z".
 *
 * Return value: a string.
 **/
TIEXPORT2 const char *TICALL tifiles_version_get(void)
{
	return LIBFILES_VERSION;
}