/[winpt]/trunk/Src/wptUTF8.cpp
ViewVC logotype

Annotation of /trunk/Src/wptUTF8.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 128 - (hide annotations)
Mon Dec 19 13:05:59 2005 UTC (19 years, 2 months ago) by twoaday
File size: 20887 byte(s)
2005-12-17  Timo Schulz  <ts@g10code.com>
 
        * wptUTF8.cpp: Removed unused charset array.
        * wptSigList.cpp (siglist_build): Increase size for 'class'
        column.
        * wptGPG.cpp (get_gnupg_path): Simplified.
        * WinPT.cpp (load_gpg_env): New.
        (check_crypto_engine): Return type is now bool.
        * wptRegistry.cpp (is_gpg4win_installed): New.
        * wptGPGPrefsDlg.cpp (gpgprefs_dlg_proc): More consistent
        dialog design.
        * wptKeyManagerDlg.cpp (translate_menu_strings): New.
        (translate_popupmenu_strings): New.
        * wptKeyEditDlgs.cpp (is_jpg_file): New.


1 twoaday 2 /* wptUTF8.cpp - UTF8 conversation
2 werner 36 * Copyright (C) 1994, 1998-2001 Free Software Foundation, Inc.
3 twoaday 128 * Copyright (C) 2002, 2004, 2005 Timo Schulz
4 twoaday 2 *
5 werner 36 * This file is part of WinPT.
6     *
7     * WinPT 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     * WinPT 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 WinPT; if not, write to the Free Software Foundation,
19 twoaday 2 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
20     */
21    
22 werner 36 #ifdef HAVE_CONFIG_H
23     #include <config.h>
24     #endif
25    
26 twoaday 2 #include <windows.h>
27 werner 36 #include <stdlib.h>
28 twoaday 2 #include <stdio.h>
29     #include <string.h>
30     #include <ctype.h>
31 werner 36
32     #include "wptTypes.h"
33 twoaday 2 #include "wptErrors.h"
34    
35    
36     static u16 latin2_unicode[128] = {
37     0x0080,0x0081,0x0082,0x0083,0x0084,0x0085,0x0086,0x0087,
38     0x0088,0x0089,0x008A,0x008B,0x008C,0x008D,0x008E,0x008F,
39     0x0090,0x0091,0x0092,0x0093,0x0094,0x0095,0x0096,0x0097,
40     0x0098,0x0099,0x009A,0x009B,0x009C,0x009D,0x009E,0x009F,
41     0x00A0,0x0104,0x02D8,0x0141,0x00A4,0x013D,0x015A,0x00A7,
42     0x00A8,0x0160,0x015E,0x0164,0x0179,0x00AD,0x017D,0x017B,
43     0x00B0,0x0105,0x02DB,0x0142,0x00B4,0x013E,0x015B,0x02C7,
44     0x00B8,0x0161,0x015F,0x0165,0x017A,0x02DD,0x017E,0x017C,
45     0x0154,0x00C1,0x00C2,0x0102,0x00C4,0x0139,0x0106,0x00C7,
46     0x010C,0x00C9,0x0118,0x00CB,0x011A,0x00CD,0x00CE,0x010E,
47     0x0110,0x0143,0x0147,0x00D3,0x00D4,0x0150,0x00D6,0x00D7,
48     0x0158,0x016E,0x00DA,0x0170,0x00DC,0x00DD,0x0162,0x00DF,
49     0x0155,0x00E1,0x00E2,0x0103,0x00E4,0x013A,0x0107,0x00E7,
50     0x010D,0x00E9,0x0119,0x00EB,0x011B,0x00ED,0x00EE,0x010F,
51     0x0111,0x0144,0x0148,0x00F3,0x00F4,0x0151,0x00F6,0x00F7,
52     0x0159,0x016F,0x00FA,0x0171,0x00FC,0x00FD,0x0163,0x02D9
53     };
54    
55    
56     static const char *active_charset_name = "iso-8859-1";
57     static u16 *active_charset = NULL;
58     static int no_translation = 0;
59    
60 twoaday 128
61 werner 36 static int
62     ascii_strcasecmp( const char *a, const char *b )
63     {
64     if( a == b )
65     return 0;
66    
67     for (; *a && *b; a++, b++) {
68     if (*a != *b && toupper(*a) != toupper(*b))
69     break;
70     }
71    
72     return *a == *b? 0 : (toupper (*a) - toupper (*b));
73 twoaday 128 }
74 werner 36
75 twoaday 2 int
76     set_native_charset( const char *newset )
77     {
78 werner 36 if( !ascii_strcasecmp( newset, "iso-8859-1" ) ) {
79     active_charset_name = "iso-8859-1";
80 twoaday 2 no_translation = 0;
81 werner 36 active_charset = NULL;
82 twoaday 2 }
83 werner 36 else if( !ascii_strcasecmp( newset, "iso-8859-2" ) ) {
84     active_charset_name = "iso-8859-2";
85     no_translation = 0;
86 twoaday 2 active_charset = latin2_unicode;
87     }
88     else if( !ascii_strcasecmp (newset, "utf8" )
89     || !ascii_strcasecmp(newset, "utf-8") ) {
90     active_charset_name = "utf-8";
91     no_translation = 1;
92     active_charset = NULL;
93     }
94 werner 36 else
95     return WPTERR_GENERAL;
96 twoaday 2
97     return 0;
98 twoaday 128 }
99 twoaday 2
100     const char*
101     get_native_charset( void )
102 werner 36 {
103 twoaday 2 return active_charset_name;
104 twoaday 128 }
105 twoaday 2
106 twoaday 128
107 twoaday 2 /****************
108     * Convert string, which is in native encoding to UTF8 and return the
109     * new allocated UTF8 string.
110     */
111     char *
112     native_to_utf8( const char *string )
113     {
114     const byte *s;
115     char *buffer;
116     byte *p;
117     size_t length=0;
118    
119     if (no_translation)
120     buffer = strdup( string );
121 werner 36 else if( active_charset ) {
122 twoaday 2 for(s=(byte*)string; *s; s++ ) {
123     length++;
124 werner 36 if( *s & 0x80 )
125 twoaday 2 length += 2; /* we may need 3 bytes */
126     }
127     buffer = (char *)malloc( length + 1 );
128     for(p=(byte *)buffer, s=(byte *)string; *s; s++ ) {
129     if( *s & 0x80 ) {
130     u16 val = active_charset[ *s & 0x7f ];
131     if( val < 0x0800 ) {
132     *p++ = 0xc0 | ( (val >> 6) & 0x1f );
133     *p++ = 0x80 | ( val & 0x3f );
134     }
135     else {
136     *p++ = 0xe0 | ( (val >> 12) & 0x0f );
137     *p++ = 0x80 | ( (val >> 6) & 0x3f );
138     *p++ = 0x80 | ( val & 0x3f );
139     }
140 werner 36 }
141     else
142 twoaday 2 *p++ = *s;
143 werner 36 }
144 twoaday 2 *p = 0;
145     }
146     else {
147     for(s=(byte*)string; *s; s++ ) {
148     length++;
149 werner 36 if( *s & 0x80 )
150 twoaday 2 length++;
151     }
152     buffer = (char*)malloc( length + 1 );
153     for(p=(byte*)buffer, s=(byte*)string; *s; s++ ) {
154     if( *s & 0x80 ) {
155     *p++ = 0xc0 | ((*s >> 6) & 3);
156     *p++ = 0x80 | ( *s & 0x3f );
157     }
158 werner 36 else
159 twoaday 2 *p++ = *s;
160     }
161     *p = 0;
162 werner 36 }
163 twoaday 2
164     return buffer;
165 werner 36 } /* native_to_utf8 */
166    
167     /****************
168     * Convert string, which is in UTF8 to native encoding. illegal
169     * encodings by some "\xnn" and quote all control characters. A
170     * character with value DELIM will always be quoted, it must be a
171     * vanilla ASCII character.
172     */
173     char *
174     utf8_to_native( const char *string, size_t length, int delim )
175     {
176     int nleft;
177     int i;
178     byte encbuf[8];
179     int encidx;
180     const byte *s;
181     size_t n;
182     byte *buffer = NULL, *p = NULL;
183     unsigned long val = 0;
184     size_t slen;
185     int resync = 0;
186    
187     /* 1. pass (p==NULL): count the extended utf-8 characters */
188     /* 2. pass (p!=NULL): create string */
189     for( ;; ) {
190     for( slen=length, nleft=encidx=0, n=0, s=(byte*)string; slen; s++, slen-- ) {
191     if( resync ) {
192     if( !(*s < 128 || (*s >= 0xc0 && *s <= 0xfd)) ) {
193     /* still invalid */
194     if( p ) {
195     sprintf((char*)p, "\\x%02x", *s );
196     p += 4;
197     }
198     n += 4;
199     continue;
200     }
201     resync = 0;
202     }
203     if( !nleft ) {
204     if( !(*s & 0x80) ) { /* plain ascii */
205     if( *s < 0x20 || *s == 0x7f || *s == delim) {
206     n++;
207     if( p )
208     *p++ = '\\';
209     switch( *s ) {
210     case '\n': n++; if( p ) *p++ = 'n'; break;
211     case '\r': n++; if( p ) *p++ = 'r'; break;
212     case '\f': n++; if( p ) *p++ = 'f'; break;
213     case '\v': n++; if( p ) *p++ = 'v'; break;
214     case '\b': n++; if( p ) *p++ = 'b'; break;
215     case 0 : n++; if( p ) *p++ = '0'; break;
216     default:
217     n += 3;
218     if ( p ) {
219     sprintf( (char*)p, "x%02x", *s );
220     p += 3;
221     }
222     break;
223     }
224     }
225     else {
226     if( p ) *p++ = *s;
227     n++;
228     }
229     }
230     else if( (*s & 0xe0) == 0xc0 ) { /* 110x xxxx */
231     val = *s & 0x1f;
232     nleft = 1;
233     encidx = 0;
234     encbuf[encidx++] = *s;
235     }
236     else if( (*s & 0xf0) == 0xe0 ) { /* 1110 xxxx */
237     val = *s & 0x0f;
238     nleft = 2;
239     encidx = 0;
240     encbuf[encidx++] = *s;
241     }
242     else if( (*s & 0xf8) == 0xf0 ) { /* 1111 0xxx */
243     val = *s & 0x07;
244     nleft = 3;
245     encidx = 0;
246     encbuf[encidx++] = *s;
247     }
248     else if( (*s & 0xfc) == 0xf8 ) { /* 1111 10xx */
249     val = *s & 0x03;
250     nleft = 4;
251     encidx = 0;
252     encbuf[encidx++] = *s;
253     }
254     else if( (*s & 0xfe) == 0xfc ) { /* 1111 110x */
255     val = *s & 0x01;
256     nleft = 5;
257     encidx = 0;
258     encbuf[encidx++] = *s;
259     }
260     else { /* invalid encoding: print as \xnn */
261     if( p ) {
262     sprintf((char*)p, "\\x%02x", *s );
263     p += 4;
264     }
265     n += 4;
266     resync = 1;
267     }
268     }
269     else if( *s < 0x80 || *s >= 0xc0 ) { /* invalid */
270     if( p ) {
271     for(i=0; i < encidx; i++ ) {
272     sprintf((char*)p, "\\x%02x", encbuf[i] );
273     p += 4;
274     }
275     sprintf((char*)p, "\\x%02x", *s );
276     p += 4;
277     }
278     n += 4 + 4*encidx;
279     nleft = 0;
280     encidx = 0;
281     resync = 1;
282     }
283     else {
284     encbuf[encidx++] = *s;
285     val <<= 6;
286     val |= *s & 0x3f;
287     if( !--nleft ) { /* ready */
288     if (no_translation) {
289     if( p ) {
290     for(i=0; i < encidx; i++ )
291     *p++ = encbuf[i];
292     }
293     n += encidx;
294     encidx = 0;
295     }
296     else if( active_charset ) { /* table lookup */
297     for(i=0; i < 128; i++ ) {
298     if( active_charset[i] == val )
299     break;
300     }
301     if( i < 128 ) { /* we can print this one */
302     if( p ) *p++ = i+128;
303     n++;
304     }
305     else { /* we do not have a translation: print utf8 */
306     if( p ) {
307     for(i=0; i < encidx; i++ ) {
308     sprintf((char*)p, "\\x%02x", encbuf[i] );
309     p += 4;
310     }
311     }
312     n += encidx*4;
313     encidx = 0;
314     }
315     }
316     else { /* native set */
317     if( val >= 0x80 && val < 256 ) {
318     n++; /* we can simply print this character */
319     if( p ) *p++ = val;
320     }
321     else { /* we do not have a translation: print utf8 */
322     if( p ) {
323     for(i=0; i < encidx; i++ ) {
324     sprintf((char*)p, "\\x%02x", encbuf[i] );
325     p += 4;
326     }
327     }
328     n += encidx*4;
329     encidx = 0;
330     }
331     }
332     }
333    
334     }
335     }
336     if( !buffer ) { /* allocate the buffer after the first pass */
337     buffer = p = (byte *)malloc( n + 1 );
338     }
339     else {
340     *p = 0; /* make a string */
341     return (char*)buffer;
342     }
343     }
344 twoaday 2 }
345 werner 36
346    
347     static void
348     conv_charset (byte *string, size_t size, int what)
349     {
350     int i;
351    
352     if( what == 0 ) {
353     for( i = 0; i < size; i++, string++ ) {
354     switch( *string ) {
355     case 0xa0: *string = 0xff; break; /* nobreakspace */
356     case 0xa1: *string = 0xad; break; /* exclamdown */
357     case 0xa2: *string = 0xbd; break; /* cent */
358     case 0xa3: *string = 0x9c; break; /* sterling */
359     case 0xa4: *string = 0xcf; break; /* currency */
360     case 0xa5: *string = 0xbe; break; /* yen */
361     case 0xa6: *string = 0xdd; break; /* brokenbar */
362     case 0xa7: *string = 0xf5; break; /* section */
363     case 0xa8: *string = 0xf9; break; /* diaeresis */
364     case 0xa9: *string = 0xb8; break; /* copyright */
365     case 0xaa: *string = 0xa6; break; /* ordfeminine */
366     case 0xab: *string = 0xae; break; /* guillemotleft */
367     case 0xac: *string = 0xaa; break; /* notsign */
368     case 0xad: *string = 0xf0; break; /* hyphen */
369     case 0xae: *string = 0xa9; break; /* registered */
370     case 0xaf: *string = 0xee; break; /* macron */
371     case 0xb0: *string = 0xf8; break; /* degree */
372     case 0xb1: *string = 0xf1; break; /* plusminus */
373     case 0xb2: *string = 0xfd; break; /* twosuperior */
374     case 0xb3: *string = 0xfc; break; /* threesuperior */
375     case 0xb4: *string = 0xef; break; /* acute */
376     case 0xb5: *string = 0xe6; break; /* mu */
377     case 0xb6: *string = 0xf4; break; /* paragraph */
378     case 0xb7: *string = 0xfa; break; /* periodcentered */
379     case 0xb8: *string = 0xf7; break; /* cedilla */
380     case 0xb9: *string = 0xfb; break; /* onesuperior */
381     case 0xba: *string = 0xa7; break; /* masculine */
382     case 0xbb: *string = 0xaf; break; /* guillemotright */
383     case 0xbc: *string = 0xac; break; /* onequarter */
384     case 0xbd: *string = 0xab; break; /* onehalf */
385     case 0xbe: *string = 0xf3; break; /* threequarters */
386     case 0xbf: *string = 0xa8; break; /* questiondown */
387     case 0xc0: *string = 0xb7; break; /* Agrave */
388     case 0xc1: *string = 0xb5; break; /* Aacute */
389     case 0xc2: *string = 0xb6; break; /* Acircumflex */
390     case 0xc3: *string = 0xc7; break; /* Atilde */
391     case 0xc4: *string = 0x8e; break; /* Adiaeresis */
392     case 0xc5: *string = 0x8f; break; /* Aring */
393     case 0xc6: *string = 0x92; break; /* AE */
394     case 0xc7: *string = 0x80; break; /* Ccedilla */
395     case 0xc8: *string = 0xd4; break; /* Egrave */
396     case 0xc9: *string = 0x90; break; /* Eacute */
397     case 0xca: *string = 0xd2; break; /* Ecircumflex */
398     case 0xcb: *string = 0xd3; break; /* Ediaeresis */
399     case 0xcc: *string = 0xde; break; /* Igrave */
400     case 0xcd: *string = 0xd6; break; /* Iacute */
401     case 0xce: *string = 0xd7; break; /* Icircumflex */
402     case 0xcf: *string = 0xd8; break; /* Idiaeresis */
403     case 0xd0: *string = 0xd1; break; /* Eth */
404     case 0xd1: *string = 0xa5; break; /* Ntilde */
405     case 0xd2: *string = 0xe3; break; /* Ograve */
406     case 0xd3: *string = 0xe0; break; /* Oacute */
407     case 0xd4: *string = 0xe2; break; /* Ocircumflex */
408     case 0xd5: *string = 0xe5; break; /* Otilde */
409     case 0xd6: *string = 0x99; break; /* Odiaeresis */
410     case 0xd7: *string = 0x9e; break; /* multiply */
411     case 0xd8: *string = 0x9d; break; /* Ooblique */
412     case 0xd9: *string = 0xeb; break; /* Ugrave */
413     case 0xda: *string = 0xe9; break; /* Uacute */
414     case 0xdb: *string = 0xea; break; /* Ucircumflex */
415     case 0xdc: *string = 0x9a; break; /* Udiaeresis */
416     case 0xdd: *string = 0xed; break; /* Yacute */
417     case 0xde: *string = 0xe8; break; /* Thorn */
418     case 0xdf: *string = 0xe1; break; /* ssharp */
419     case 0xe0: *string = 0x85; break; /* agrave */
420     case 0xe1: *string = 0xa0; break; /* aacute */
421     case 0xe2: *string = 0x83; break; /* acircumflex */
422     case 0xe3: *string = 0xc6; break; /* atilde */
423     case 0xe4: *string = 0x84; break; /* adiaeresis */
424     case 0xe5: *string = 0x86; break; /* aring */
425     case 0xe6: *string = 0x91; break; /* ae */
426     case 0xe7: *string = 0x87; break; /* ccedilla */
427     case 0xe8: *string = 0x8a; break; /* egrave */
428     case 0xe9: *string = 0x82; break; /* eacute */
429     case 0xea: *string = 0x88; break; /* ecircumflex */
430     case 0xeb: *string = 0x89; break; /* ediaeresis */
431     case 0xec: *string = 0x8d; break; /* igrave */
432     case 0xed: *string = 0xa1; break; /* iacute */
433     case 0xee: *string = 0x8c; break; /* icircumflex */
434     case 0xef: *string = 0x8b; break; /* idiaeresis */
435     case 0xf0: *string = 0xd0; break; /* eth */
436     case 0xf1: *string = 0xa4; break; /* ntilde */
437     case 0xf2: *string = 0x95; break; /* ograve */
438     case 0xf3: *string = 0xa2; break; /* oacute */
439     case 0xf4: *string = 0x93; break; /* ocircumflex */
440     case 0xf5: *string = 0xe4; break; /* otilde */
441     case 0xf6: *string = 0x94; break; /* odiaeresis */
442     case 0xf7: *string = 0xf6; break; /* division */
443     case 0xf8: *string = 0x9b; break; /* oslash */
444     case 0xf9: *string = 0x97; break; /* ugrave */
445     case 0xfa: *string = 0xa3; break; /* uacute */
446     case 0xfb: *string = 0x96; break; /* ucircumflex */
447     case 0xfc: *string = 0x81; break; /* udiaeresis */
448     case 0xfd: *string = 0xec; break; /* yacute */
449     case 0xfe: *string = 0xe7; break; /* thorn */
450     case 0xff: *string = 0x98; break; /* ydiaeresis */
451     default : break;
452     }
453     }
454     }
455     else {
456     for( i = 0; i < size; i++, string++ ) {
457     switch( *string ) {
458     case 0xff: *string = 0xa0; break;
459     case 0xad: *string = 0xa1; break;
460     case 0xbd: *string = 0xa2; break;
461     case 0x9c: *string = 0xa3; break;
462     case 0xcf: *string = 0xa4; break;
463     case 0xbe: *string = 0xa5; break;
464     case 0xdd: *string = 0xa6; break;
465     case 0xf5: *string = 0xa7; break;
466     case 0xf9: *string = 0xa8; break;
467     case 0xb8: *string = 0xa9; break;
468     case 0xa6: *string = 0xaa; break;
469     case 0xae: *string = 0xab; break;
470     case 0xaa: *string = 0xac; break;
471     case 0xf0: *string = 0xad; break;
472     case 0xa9: *string = 0xae; break;
473     case 0xee: *string = 0xaf; break;
474     case 0xf8: *string = 0xb0; break;
475     case 0xf1: *string = 0xb1; break;
476     case 0xfd: *string = 0xb2; break;
477     case 0xfc: *string = 0xb3; break;
478     case 0xef: *string = 0xb4; break;
479     case 0xe6: *string = 0xb5; break;
480     case 0xf4: *string = 0xb6; break;
481     case 0xfa: *string = 0xb7; break;
482     case 0xf7: *string = 0xb8; break;
483     case 0xfb: *string = 0xb9; break;
484     case 0xa7: *string = 0xba; break;
485     case 0xaf: *string = 0xbb; break;
486     case 0xac: *string = 0xbc; break;
487     case 0xab: *string = 0xbd; break;
488     case 0xf3: *string = 0xbe; break;
489     case 0xa8: *string = 0xbf; break;
490     case 0xb7: *string = 0xc0; break;
491     case 0xb5: *string = 0xc1; break;
492     case 0xb6: *string = 0xc2; break;
493     case 0xc7: *string = 0xc3; break;
494     case 0x8e: *string = 0xc4; break;
495     case 0x8f: *string = 0xc5; break;
496     case 0x92: *string = 0xc6; break;
497     case 0x80: *string = 0xc7; break;
498     case 0xd4: *string = 0xc8; break;
499     case 0x90: *string = 0xc9; break;
500     case 0xd2: *string = 0xca; break;
501     case 0xd3: *string = 0xcb; break;
502     case 0xde: *string = 0xcc; break;
503     case 0xd6: *string = 0xcd; break;
504     case 0xd7: *string = 0xce; break;
505     case 0xd8: *string = 0xcf; break;
506     case 0xd1: *string = 0xd0; break;
507     case 0xa5: *string = 0xd1; break;
508     case 0xe3: *string = 0xd2; break;
509     case 0xe0: *string = 0xd3; break;
510     case 0xe2: *string = 0xd4; break;
511     case 0xe5: *string = 0xd5; break;
512     case 0x99: *string = 0xd6; break;
513     case 0x9e: *string = 0xd7; break;
514     case 0x9d: *string = 0xd8; break;
515     case 0xeb: *string = 0xd9; break;
516     case 0xe9: *string = 0xda; break;
517     case 0xea: *string = 0xdb; break;
518     case 0x9a: *string = 0xdc; break;
519     case 0xed: *string = 0xdd; break;
520     case 0xe8: *string = 0xde; break;
521     case 0xe1: *string = 0xdf; break;
522     case 0x85: *string = 0xe0; break;
523     case 0xa0: *string = 0xe1; break;
524     case 0x83: *string = 0xe2; break;
525     case 0xc6: *string = 0xe3; break;
526     case 0x84: *string = 0xe4; break;
527     case 0x86: *string = 0xe5; break;
528     case 0x91: *string = 0xe6; break;
529     case 0x87: *string = 0xe7; break;
530     case 0x8a: *string = 0xe8; break;
531     case 0x82: *string = 0xe9; break;
532     case 0x88: *string = 0xea; break;
533     case 0x89: *string = 0xeb; break;
534     case 0x8d: *string = 0xec; break;
535     case 0xa1: *string = 0xed; break;
536     case 0x8c: *string = 0xee; break;
537     case 0x8b: *string = 0xef; break;
538     case 0xd0: *string = 0xf0; break;
539     case 0xa4: *string = 0xf1; break;
540     case 0x95: *string = 0xf2; break;
541     case 0xa2: *string = 0xf3; break;
542     case 0x93: *string = 0xf4; break;
543     case 0xe4: *string = 0xf5; break;
544     case 0x94: *string = 0xf6; break;
545     case 0xf6: *string = 0xf7; break;
546     case 0x9b: *string = 0xf8; break;
547     case 0x97: *string = 0xf9; break;
548     case 0xa3: *string = 0xfa; break;
549     case 0x96: *string = 0xfb; break;
550     case 0x81: *string = 0xfc; break;
551     case 0xec: *string = 0xfd; break;
552     case 0xe7: *string = 0xfe; break;
553     case 0x98: *string = 0xff; break;
554     default : break;
555     }
556     }
557     }
558     } /* conv_charset */
559    
560    
561 twoaday 128 /* XXX: the conv_charset() call fails when the user-id was created
562     with iso-8859-1 but it is assumed that CP850 (gpg console) is used. */
563    
564     char*
565 werner 36 utf8_to_wincp (const char * s, size_t len)
566     {
567 twoaday 128 char *decs;
568 werner 36 decs = utf8_to_native (s, len, 0);
569     conv_charset ((byte *)decs, strlen (decs), 1);
570     return decs;
571     }
572    
573    
574 twoaday 128 char*
575 werner 36 wincp_to_utf8 (const char * s, size_t len)
576     {
577     char * encs;
578     conv_charset ((byte *)s, len, 0);
579     encs = native_to_utf8 (s);
580     return encs;
581     }
582    
583    
584     int
585     is_8bit_string (const char * str)
586     {
587     size_t i;
588    
589     for (i = 0; i < strlen (str); i++) {
590     if (str[i] & 0x80)
591     return -1;
592     }
593     return 0;
594 twoaday 128 }

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26