1 /****************************************************************************
2 Copyright (C) 1987-2015 by Jeffery P. Hansen
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation, Inc.,
16 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18 Last edit by hansen on Mon Aug 30 21:38:50 2004
19 ****************************************************************************/
20 #include "tkgate.h"
21 #include <stdio.h>
22 #include <string.h>
23 #include <pwd.h>
24 #include <sys/types.h>
25 #include <sys/stat.h>
26 #include <assert.h>
27
28 /* from Xlib tutorial http://www.quixquax.at/bleichling_php/references/x11-tutorial.html */
utf8toXChar2b(XChar2b * output_r,int outsize,const char * input,int inlen)29 int utf8toXChar2b(XChar2b *output_r, int outsize, const char *input, int inlen) {
30 int j, k;
31 for(j =0, k=0; j < inlen && k < outsize; j ++) {
32 unsigned char c = input[j];
33 if (c < 128) {
34 output_r[k].byte1 = 0;
35 output_r[k].byte2 = c;
36 k++;
37 } else if (c < 0xC0) {
38 /* we're inside a character we don't know */
39 continue;
40 } else switch(c&0xF0){
41 case 0xC0: case 0xD0: /* two bytes 5+6 = 11 bits */
42 if (inlen < j+1) { return k; }
43 output_r[k].byte1 = (c&0x1C) >> 2;
44 j++;
45 output_r[k].byte2 = ((c&0x3) << 6) + (input[j]&0x3F);
46 k++;
47 break;
48 case 0xE0: /* three bytes 4+6+6 = 16 bits */
49 if (inlen < j+2) { return k; }
50 j++;
51 output_r[k].byte1 = ((c&0xF) << 4) + ((input[j]&0x3C) >> 2);
52 c = input[j];
53 j++;
54 output_r[k].byte2 = ((c&0x3) << 6) + (input[j]&0x3F);
55 k++;
56 break;
57 case 0xFF:
58 /* the character uses more than 16 bits */
59 continue;
60 }
61 }
62 return k;
63 }
64
Locale_print(const Locale * locale,FILE * fp)65 void Locale_print(const Locale *locale,FILE *fp) {
66 fprintf(fp, "\nLocale: ");
67 fprintf(fp, "\n\tcode: %s", locale->l_code);
68 fprintf(fp, "\n\tname: %s", locale->l_name);
69 fprintf(fp, "\n\tmessages:%s", locale->l_messages);
70 fprintf(fp, "\n\tenc font:%s", locale->l_encFont);
71 fprintf(fp, "\n\tenc disp:%s", locale->l_encDisplay);
72 fprintf(fp, "\n\tenc mess:%s", locale->l_encMessages);
73 fprintf(fp, "\n\tenc vrlg:%s", locale->l_encVerilog);
74 }
75