OpenOCD
tcl-libjim.c
Go to the documentation of this file.
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 
3 /*
4  * This file collects all the functions to interact with Jim Tcl library.
5  *
6  * The purposes are:
7  * - to decouple the jimtcl error codes (JIM_OK, JIM_ERR, ...) from the error
8  * codes of OpenOCD;
9  * - to decouple the internal Jim_Obj and its garbage collection;
10  * - to concentrate the Jim Tcl CamelCase symbols, now spread in OpenOCD code.
11  *
12  * The Jim Tcl CamelCase symbols used in this file should be reported in the
13  * file 'tools/scripts/camelcase.txt' to prevent errors from checkpatch.
14  */
15 
16 #ifdef HAVE_CONFIG_H
17 #include "config.h"
18 #endif
19 
20 #include <assert.h>
21 #include <string.h>
22 
23 #include <helper/tcl-common.h>
24 
25 char *tcl_escape_alloc(Jim_Interp *interp, const char *s)
26 {
27  assert(s);
28 
29  Jim_Obj *o1 = Jim_NewStringObj(interp, s, -1);
30  Jim_Obj *o2 = Jim_NewListObj(interp, &o1, 1);
31  Jim_IncrRefCount(o2);
32 
33  char *out = strdup(Jim_String(o2));
34 
35  Jim_DecrRefCount(interp, o2);
36 
37  return out;
38 }
char * tcl_escape_alloc(Jim_Interp *interp, const char *s)
Convert a C string to a string that can be used for Tcl list.
Definition: tcl-libjim.c:25