2002-04-26 05:16:26 -07:00
|
|
|
/***********************************************************************/
|
|
|
|
/* */
|
|
|
|
/* 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. */
|
|
|
|
/* */
|
|
|
|
/***********************************************************************/
|
1999-12-16 04:25:11 -08:00
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
2000-04-17 01:55:44 -07:00
|
|
|
#include <string.h>
|
1999-11-30 06:59:39 -08:00
|
|
|
#include <tcl.h>
|
|
|
|
#include <tk.h>
|
2000-04-17 01:55:44 -07:00
|
|
|
#include <mlvalues.h>
|
|
|
|
#include <memory.h>
|
1999-11-30 06:59:39 -08:00
|
|
|
#include "camltk.h"
|
|
|
|
|
|
|
|
/* Parsing results */
|
2001-08-28 07:47:48 -07:00
|
|
|
CAMLprim value camltk_splitlist (value v)
|
1999-11-30 06:59:39 -08:00
|
|
|
{
|
|
|
|
int argc;
|
|
|
|
char **argv;
|
|
|
|
int result;
|
2002-04-26 05:16:26 -07:00
|
|
|
char *utf;
|
1999-11-30 06:59:39 -08:00
|
|
|
|
|
|
|
CheckInit();
|
|
|
|
|
2002-04-26 05:16:26 -07:00
|
|
|
utf = caml_string_to_tcl(v);
|
1999-11-30 06:59:39 -08:00
|
|
|
/* argv is allocated by Tcl, to be freed by us */
|
2002-04-26 05:16:26 -07:00
|
|
|
result = Tcl_SplitList(cltclinterp,utf,&argc,&argv);
|
1999-11-30 06:59:39 -08:00
|
|
|
switch(result) {
|
|
|
|
case TCL_OK:
|
|
|
|
{ value res = copy_string_list(argc,argv);
|
2002-04-26 05:16:26 -07:00
|
|
|
Tcl_Free((char *)argv); /* only one large block was allocated */
|
|
|
|
/* argv points into utf: utf must be freed after argv are freed */
|
|
|
|
stat_free( utf );
|
1999-11-30 06:59:39 -08:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
case TCL_ERROR:
|
|
|
|
default:
|
2002-04-26 05:16:26 -07:00
|
|
|
stat_free( utf );
|
1999-11-30 06:59:39 -08:00
|
|
|
tk_error(cltclinterp->result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Copy a Caml string to the C heap. Should deallocate with stat_free */
|
2000-04-17 01:55:44 -07:00
|
|
|
char *string_to_c(value s)
|
1999-11-30 06:59:39 -08:00
|
|
|
{
|
|
|
|
int l = string_length(s);
|
|
|
|
char *res = stat_alloc(l + 1);
|
2000-11-23 05:45:03 -08:00
|
|
|
memmove (res, String_val (s), l);
|
1999-11-30 06:59:39 -08:00
|
|
|
res[l] = '\0';
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|