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
|
/***********************************************************************/
/* */
/* MLTk, Tcl/Tk interface of Objective Caml */
/* */
/* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis */
/* projet Cristal, INRIA Rocquencourt */
/* Jacques Garrigue, Kyoto University RIMS */
/* */
/* Copyright 2002 Institut National de Recherche en Informatique et */
/* en Automatique and Kyoto University. All rights reserved. */
/* This file is distributed under the terms of the GNU Library */
/* General Public License, with the special exception on linking */
/* described in file LICENSE found in the Objective Caml source tree. */
/* */
/***********************************************************************/
/* $Id$ */
#include <stdlib.h>
#include <string.h>
#include <tcl.h>
#include <tk.h>
#include <mlvalues.h>
#include <alloc.h>
#include <memory.h>
#ifdef HAS_UNISTD
#include <unistd.h>
#endif
#include "camltk.h"
#if (TCL_MAJOR_VERSION > 8 || \
(TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION >= 1)) /* 8.1 */
# define UTFCONVERSION
#endif
#ifdef UTFCONVERSION
char *external_to_utf( char *str ){
char *res;
Tcl_DString dstr;
int length;
Tcl_ExternalToUtfDString(NULL, str, strlen(str), &dstr);
length = Tcl_DStringLength(&dstr);
res = stat_alloc(length + 1);
memmove( res, Tcl_DStringValue(&dstr), length+1);
Tcl_DStringFree(&dstr);
return res;
}
char *utf_to_external( char *str ){
char *res;
Tcl_DString dstr;
int length;
Tcl_UtfToExternalDString(NULL, str, strlen(str), &dstr);
length = Tcl_DStringLength(&dstr);
res = stat_alloc(length + 1);
memmove( res, Tcl_DStringValue(&dstr), length+1);
Tcl_DStringFree(&dstr);
return res;
}
char *caml_string_to_tcl( value s )
{
return external_to_utf( String_val(s) );
}
value tcl_string_to_caml( char *s )
{
CAMLparam0();
CAMLlocal1(res);
char *str;
str = utf_to_external( s );
res = copy_string(str);
stat_free(str);
CAMLreturn(res);
}
#else
char *caml_string_to_tcl(value s){ return string_to_c(s); }
value tcl_string_to_caml(char *s){ return copy_string(s); }
#endif
|