1 /* Hey EMACS -*- linux-c -*- */
2 /* $Id$ */
3 
4 /*  libTICONV - charset library, a part of the TiLP project
5  *  Copyright (C) 1999-2006  Romain Lievin and Kevin Kofler
6  *
7  *  This program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation; either version 2 of the License, or
10  *  (at your option) any later version.
11  *
12  *  This program is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *  GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with this program; if not, write to the Free Software Foundation,
19  *  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #ifndef __TICONV_H__
23 #define __TICONV_H__
24 
25 #ifdef HAVE_CONFIG_H
26 #  include <config.h>
27 #endif
28 
29 #define TICONV_ICONV_INTERFACE
30 
31 // Need size_t declaration.
32 #ifdef __cplusplus
33 #include <cstddef>
34 #else
35 #include <stddef.h>
36 #endif
37 
38 // Need iconv_t declaration.
39 #if defined(TICONV_ICONV_INTERFACE)
40 #include <iconv.h>
41 #endif
42 
43 #include "export4.h"
44 #include "stdints4.h"
45 
46 	/***********************/
47 	/* Types & Definitions */
48 	/***********************/
49 
50 /* Versioning */
51 
52 #ifdef __WIN32__
53 # define LIBCONV_VERSION "1.1.5"
54 #else
55 # define LIBCONV_VERSION VERSION
56 #endif
57 
58 /**
59  * CalcModel:
60  *
61  * An enumeration which contains several calculator models.
62  *
63  **/
64 typedef enum
65 {
66 	CALC_NONE = 0,
67 	CALC_TI73, CALC_TI82, CALC_TI83, CALC_TI83P, CALC_TI84P, CALC_TI85, CALC_TI86,
68 	CALC_TI89, CALC_TI89T, CALC_TI92, CALC_TI92P, CALC_V200,
69 	CALC_TI84P_USB, CALC_TI89T_USB, CALC_NSPIRE, CALC_TI80,
70 	CALC_TI84PC, CALC_TI84PC_USB, CALC_TI83PCE_USB, CALC_TI84PCE_USB, CALC_TI82A_USB, CALC_TI84PT_USB, CALC_MAX
71 } CalcModel;
72 
73 #if defined(TICONV_ICONV_INTERFACE)
74 /**
75  * ticonv_iconv_t:
76  * @src_calc:
77  * @iconv_desc:
78  * @dest_calc:
79  * @lossy_count:
80  * @lookahead_result:
81  * @lookahead_errno:
82  * @lookahead:
83  *
84  * A structure which is an identifier for conversion method from one codeset to another.
85  * Exported if ICONV_INTERFACE is enabled.
86  *
87  **/
88 typedef struct
89 {
90 	CalcModel src_calc;
91 	iconv_t iconv_desc;
92 	CalcModel dest_calc;
93 	size_t lossy_count;
94 	size_t lookahead_result;
95 	int lookahead_errno;
96 	unsigned short lookahead;
97 } ticonv_iconv_t;
98 #endif
99 
100 /* Functions */
101 
102 // namespace scheme: library_class_function like ticonv_library_init
103 // functions suffixed with _s means 'static', no memory allocation
104 // TODO functions suffixed with _sn means 'static with length limit', no memory allocation
105 
106 #ifdef __cplusplus
107 extern "C" {
108 #endif
109 
110 	/****************/
111 	/* Entry points */
112 	/****************/
113 
114 	//TIEXPORT4 int TICALL ticonv_library_init(void);
115 	//TIEXPORT4 int TICALL ticonv_library_exit(void);
116 
117 	/*********************/
118 	/* General functions */
119 	/*********************/
120 
121 	// ticonv.c
122 	TIEXPORT4 const char* TICALL ticonv_version_get (void);
123 
124 	TIEXPORT4 size_t TICALL ticonv_utf16_strlen(const unsigned short *str);
125 
126 	TIEXPORT4 unsigned short* TICALL ticonv_utf8_to_utf16(const char *str);
127 	TIEXPORT4 void TICALL ticonv_utf16_free(unsigned short *str);
128 	TIEXPORT4 char* TICALL ticonv_utf16_to_utf8(const unsigned short *str);
129 	TIEXPORT4 void TICALL ticonv_utf8_free(char *str);
130 
131 	// TODO TIEXPORT4 char* TICALL ticonv_charset_utf16_to_ti_sn(CalcModel model, const unsigned short *utf16, char *ti, uint32_t maxlen);
132 	/* TODO TILIBS_DEPRECATED */ TIEXPORT4 char* TICALL ticonv_charset_utf16_to_ti_s(CalcModel model, const unsigned short *utf16, char *ti);
133 	TIEXPORT4 char* TICALL ticonv_charset_utf16_to_ti(CalcModel model, const unsigned short *utf16);
134 	TIEXPORT4 void  TICALL ticonv_ti_free(char * ti);
135 
136 	// TODO TIEXPORT4 unsigned short* TICALL ticonv_charset_ti_to_utf16_sn(CalcModel model, const char *ti, unsigned short *utf16, uint32_t maxlen);
137 	/* TODO TILIBS_DEPRECATED */ TIEXPORT4 unsigned short* TICALL ticonv_charset_ti_to_utf16_s(CalcModel model, const char *ti, unsigned short *utf16);
138 	TIEXPORT4 unsigned short* TICALL ticonv_charset_ti_to_utf16(CalcModel model, const char *ti);
139 	// The free function corresponding to ticonv_charset_ti_to_utf16() is ticonv_utf16_free().
140 
141 	TIEXPORT4 int TICALL ticonv_model_uses_utf8(CalcModel model);
142 	TIEXPORT4 int TICALL ticonv_model_is_tiz80(CalcModel model);
143 	TIEXPORT4 int TICALL ticonv_model_is_tiez80(CalcModel model);
144 	TIEXPORT4 int TICALL ticonv_model_is_ti68k(CalcModel model);
145 	TIEXPORT4 int TICALL ticonv_model_is_tinspire(CalcModel model);
146 	TIEXPORT4 int TICALL ticonv_model_has_legacy_ioport(CalcModel model);
147 	TIEXPORT4 int TICALL ticonv_model_has_usb_ioport(CalcModel model);
148 
149 	// TODO TIEXPORT4 unsigned short* TICALL ticonv_varname_to_utf16_sn(CalcModel model, const char *src, unsigned short *dst, uint32_t maxlen, unsigned char type);
150 	/* TODO TILIBS_DEPRECATED */ TIEXPORT4 unsigned short* TICALL ticonv_varname_to_utf16_s(CalcModel model, const char *src, unsigned short *dst, unsigned char type);
151 	TIEXPORT4 unsigned short* TICALL ticonv_varname_to_utf16  (CalcModel model, const char *src, unsigned char type);
152 	// The free function corresponding to ticonv_varname_to_utf16() is ticonv_utf16_free().
153 
154 	TIEXPORT4 char* TICALL ticonv_varname_to_utf8_sn(CalcModel model, const char *src, char *dst, uint32_t maxlen, unsigned char type);
155 	TILIBS_DEPRECATED TIEXPORT4 char* TICALL ticonv_varname_to_utf8_s(CalcModel model, const char *src, char *dst, unsigned char type);
156 	TIEXPORT4 char* TICALL ticonv_varname_to_utf8  (CalcModel model, const char *src, unsigned char type);
157 	// The free function corresponding to ticonv_varname_to_utf8() is ticonv_utf8_free().
158 
159 	TIEXPORT4 char* TICALL ticonv_varname_to_filename_sn(CalcModel model, const char *src, char *dst, uint32_t maxlen, unsigned char type);
160 	TILIBS_DEPRECATED TIEXPORT4 char* TICALL ticonv_varname_to_filename_s(CalcModel model, const char *src, char *dst, unsigned char type);
161 	TIEXPORT4 char* TICALL ticonv_varname_to_filename  (CalcModel model, const char *src, unsigned char type);
162 	// The free function corresponding to ticonv_varname_to_filename() is ticonv_gfe_free().
163 
164 	TIEXPORT4 char* TICALL ticonv_varname_to_tifile_sn(CalcModel model, const char *src, char *dst, uint32_t maxlen, unsigned char type);
165 	TILIBS_DEPRECATED TIEXPORT4 char* TICALL ticonv_varname_to_tifile_s(CalcModel model, const char *src, char *dst, unsigned char type);
166 	TIEXPORT4 char* TICALL ticonv_varname_to_tifile  (CalcModel model, const char *src, unsigned char type);
167 	// The free function corresponding to ticonv_varname_to_tifile() is ticonv_varname_free().
168 	TIEXPORT4 char* TICALL ticonv_varname_from_tifile_sn(CalcModel model, const char *src, char *dst, uint32_t maxlen, unsigned char type);
169 	TILIBS_DEPRECATED TIEXPORT4 char* TICALL ticonv_varname_from_tifile_s(CalcModel model, const char *src, char *dst, unsigned char type);
170 	TIEXPORT4 char* TICALL ticonv_varname_from_tifile  (CalcModel model, const char *src, unsigned char type);
171 	// The free function corresponding to ticonv_varname_from_tifile() is ticonv_ti_free().
172 
173 	// type2str.c
174 	TIEXPORT4 const char* TICALL ticonv_model_to_string(CalcModel type);
175 	TIEXPORT4 CalcModel   TICALL ticonv_string_to_model(const char *str);
176 
177 	// charset.c
178 	extern TIEXPORT4 const unsigned long TICALL ti73_charset[256];
179 	extern TIEXPORT4 const unsigned long TICALL ti80_charset[256];
180 	extern TIEXPORT4 const unsigned long TICALL ti82_charset[256];
181 	extern TIEXPORT4 const unsigned long TICALL ti83_charset[256];
182 	extern TIEXPORT4 const unsigned long TICALL ti83p_charset[256];
183 	extern TIEXPORT4 const unsigned long TICALL ti85_charset[256];
184 	extern TIEXPORT4 const unsigned long TICALL ti86_charset[256];
185 	extern TIEXPORT4 const unsigned long TICALL ti9x_charset[256];
186 
187 	// tokens.c
188 	// TODO TIEXPORT4 char* TICALL ticonv_varname_detokenize_sn(CalcModel model, const char *src, char *dst, uint32_t maxlen, unsigned char type);
189 	TIEXPORT4 char* TICALL ticonv_varname_detokenize(CalcModel model, const char *src, unsigned char type);
190 	// TODO TIEXPORT4 char* TICALL ticonv_varname_tokenize_sn(CalcModel model, const char *src, char *dst, uint32_t maxlen, unsigned char type);
191 	TIEXPORT4 char* TICALL ticonv_varname_tokenize  (CalcModel model, const char *src, unsigned char type);
192 	TIEXPORT4 void  TICALL ticonv_varname_free      (char *varname);
193 
194 	// filename.c
195 	TIEXPORT4 char* TICALL ticonv_utf16_to_gfe(CalcModel model, const unsigned short *src);
196 	TIEXPORT4 void  TICALL ticonv_gfe_free(char *src);
197 	TIEXPORT4 char* TICALL ticonv_gfe_to_zfe(CalcModel model, const char *src);
198 	TIEXPORT4 void  TICALL ticonv_zfe_free(char *src);
199 
200 	// iconv.c: exported if ICONV_INTERFACE has been enabled from configure.
201 #if defined(TICONV_ICONV_INTERFACE)
202 	/* Allocate descriptor for code conversion from codeset FROMCODE to codeset TOCODE.  */
203 	TIEXPORT4 ticonv_iconv_t TICALL ticonv_iconv_open (const char *tocode, const char *fromcode);
204 	/* Convert at most *INBYTESLEFT bytes from *INBUF according to the
205 	   code conversion algorithm specified by CD and place up to
206 	   *OUTBYTESLEFT bytes in buffer at *OUTBUF.  */
207 	TIEXPORT4 size_t TICALL ticonv_iconv (ticonv_iconv_t cd, char **__restrict inbuf,
208 	                                      size_t *__restrict inbytesleft,
209 	                                      char **__restrict outbuf,
210 	                                      size_t *__restrict outbytesleft);
211 	/* Free resources allocated for descriptor CD for code conversion.  */
212 	TIEXPORT4 int TICALL ticonv_iconv_close (ticonv_iconv_t cd);
213 #endif
214 
215 	/************************/
216 	/* Deprecated functions */
217 	/************************/
218 
219 #ifdef __cplusplus
220 }
221 #endif
222 
223 #endif
224