1 /* Hey EMACS -*- linux-c -*- */
2 /* $Id: test_tifiles_2.c 1798 2006-02-03 08:27:54Z roms $ */
3
4 /* libtifiles - charset library, a part of the TiLP project
5 * Copyright (C) 1999-2004 Romain Lievin
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 /*
23 This program contains a lot of routines for testing various part of the
24 library as well as checking file support.
25 */
26
27 #ifdef HAVE_CONFIG_H
28 #include <config.h>
29 #endif
30
31 #include <stdio.h>
32 #include <string.h>
33 #include <glib.h>
34 #ifdef __WIN32__
35 #include <conio.h>
36 #endif
37
38 #ifndef _DEBUG
39 # define _DEBUG
40 #endif
41 #include "../src/ticonv.h"
42
43 const unsigned long* charsets[8];
44
45 /*
46 The main function
47 */
main(int argc,char ** argv)48 int main(int argc, char **argv)
49 {
50 int i, j;
51 unsigned int n = 0;
52 int is_utf8 = g_get_charset(NULL);
53
54 charsets[0] = ti73_charset;
55 charsets[1] = ti82_charset;
56 charsets[2] = ti83_charset;
57 charsets[3] = ti83p_charset;
58 charsets[4] = ti85_charset;
59 charsets[5] = ti86_charset;
60 charsets[6] = ti9x_charset;
61
62 // test ticonv.c
63 printf("Library version : <%s>\n", ticonv_version_get());
64 printf("--\n");
65
66 printf("Choose your charset: ");
67 if (!scanf("%u", &n))
68 {
69 n = 0;
70 }
71 if (n >= 7)
72 {
73 n = 6;
74 }
75
76 printf(" 0 1 2 3 4 5 6 7 8 9 A B C D E F\n");
77
78 for(i = 0; i < 16; i++)
79 {
80 printf("%x ", i);
81 for(j = 0; j < 16; j++)
82 {
83 unsigned long wc = charsets[n][16*i+j];
84 gchar *str = NULL;
85
86 if (wc && wc != '\n')
87 {
88 gunichar2 buf[4] = { 0 };
89
90 buf[0] = (gunichar2)wc;
91 str = ticonv_utf16_to_utf8(buf);
92
93 if (!is_utf8 && str)
94 {
95 gchar *tmp = g_locale_from_utf8(str, -1, NULL, NULL, NULL);
96 ticonv_utf8_free(str);
97 str = tmp;
98 }
99 }
100 else
101 {
102 str = NULL;
103 }
104
105 if (str)
106 {
107 printf("%s ", str);
108 }
109
110 ticonv_utf8_free(str);
111 }
112 printf("\n");
113 }
114
115 {
116 char ti82_varname[9] = { 0 };
117 char ti92_varname[9] = { 0 };
118 char ti84p_varname[36] = { 0 };
119 char *utf8;
120 char *filename;
121 char *varname;
122
123 ti82_varname[0] = 0x5d; // L1
124 ti82_varname[1] = 0x01;
125 ti82_varname[2] = 0;
126
127 ti92_varname[0] = (char)132; // delta
128 ti92_varname[1] = (char)0xE9; // e acute.
129 ti92_varname[2] = 0;
130
131 ti84p_varname[0] = 'L'; // L1 in TI-UTF-8
132 ti84p_varname[1] = (char)0xE2;
133 ti84p_varname[2] = (char)0x82;
134 ti84p_varname[3] = (char)0x81;
135
136 // TI -> UTF-8
137 utf8 = ticonv_varname_to_utf8(CALC_TI82, ti82_varname, -1);
138 printf("UTF-8 varname: <%s> (%i)\n", ti82_varname, (int)strlen(ti82_varname));
139 ticonv_utf8_free(utf8);
140
141 utf8 = ticonv_varname_to_utf8(CALC_TI92, ti92_varname, -1);
142 printf("UTF-8 varname: <%s> (%i)\n", ti92_varname, (int)strlen(ti92_varname));
143 ticonv_utf8_free(utf8);
144
145 utf8 = ticonv_varname_to_utf8(CALC_TI84P_USB, ti84p_varname, -1);
146 printf("UTF-8 varname: <%s> (%i)\n", ti84p_varname, (int)strlen(ti84p_varname));
147 ticonv_utf8_free(utf8);
148
149
150 // TI -> filename
151 printf("raw varname: <%s> (%i)\n", ti92_varname, (int)strlen(ti92_varname));
152 filename = ticonv_varname_to_filename(CALC_TI92, ti92_varname, -1);
153 printf("filename: <%s>\n", filename);
154 ticonv_gfe_free(filename);
155
156 printf("raw varname: <%s> (%i)\n", ti82_varname, (int)strlen(ti82_varname));
157 filename = ticonv_varname_to_filename(CALC_TI82, ti82_varname, -1);
158 printf("filename: <%s>\n", filename);
159 ticonv_gfe_free(filename);
160
161 printf("raw varname: <%s> (%i)\n", ti84p_varname, (int)strlen(ti84p_varname));
162 filename = ticonv_varname_to_filename(CALC_TI84P_USB, ti84p_varname, -1);
163 printf("filename: <%s>\n", filename);
164 ticonv_gfe_free(filename);
165
166 // varname -> varname
167 printf("raw varname: <%s> (%i)\n", ti84p_varname, (int)strlen(ti84p_varname));
168 varname = ticonv_varname_to_tifile(CALC_TI84P_USB, ti84p_varname, -1);
169 printf("varname: <%s>\n", varname);
170 ticonv_gfe_free(varname);
171 }
172
173 #ifdef __WIN32__
174 while(!_kbhit());
175 #endif
176
177 return 0;
178 }
179