2
2
* STFL - The Structured Terminal Forms Language/Library
3
* Copyright (C) 2006 Clifford Wolf <clifford@clifford.at>
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
3
* Copyright (C) 2006, 2007 Clifford Wolf <clifford@clifford.at>
5
* This library is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU Lesser General Public
7
* License as published by the Free Software Foundation; either
8
* version 3 of the License, or (at your option) any later version.
10
* This library is distributed in the hope that it will be useful,
11
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
* Lesser General Public License for more details.
15
* You should have received a copy of the GNU Lesser General Public
16
* License along with this library; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
20
* mod_stfl.c: STFL bindings for SPL
26
27
* Language/Library (STFL).
34
33
#include <stdlib.h>
36
static struct stfl_ipool *ipool = 0;
36
38
extern void SPL_ABI(spl_mod_stfl_init)(struct spl_vm *vm, struct spl_module *mod, int restore);
37
39
extern void SPL_ABI(spl_mod_stfl_done)(struct spl_vm *vm, struct spl_module *mod);
79
81
struct spl_node *n = SPL_NEW_STRING_DUP("STFL Form");
80
82
n->hnode_name = strdup("stfl_form");
81
n->hnode_data = stfl_create(spl_clib_get_string(task));;
83
n->hnode_data = stfl_create(stfl_ipool_towc(ipool, spl_clib_get_string(task)));;
84
stfl_ipool_flush(ipool);
89
92
static struct spl_node *handler_stfl_run(struct spl_task *task, void *data)
91
94
struct stfl_form *f = clib_get_stfl_form(task);
92
return f ? spl_new_nullable_ascii(stfl_run(f, spl_clib_get_int(task))) : 0;
95
struct spl_node *ret = f ? spl_new_nullable_ascii(stfl_ipool_fromwc(ipool, stfl_run(f, spl_clib_get_int(task)))) : 0;
96
stfl_ipool_flush(ipool);
109
114
static struct spl_node *handler_stfl_get(struct spl_task *task, void *data)
111
116
struct stfl_form *f = clib_get_stfl_form(task);
112
return f ? spl_new_nullable_ascii(stfl_get(f, spl_clib_get_string(task))) : 0;
117
struct spl_node *ret = f ? spl_new_nullable_ascii(stfl_ipool_fromwc(ipool, stfl_get(f, stfl_ipool_towc(ipool, spl_clib_get_string(task))))) : 0;
118
stfl_ipool_flush(ipool);
121
128
struct stfl_form *f = clib_get_stfl_form(task);
122
129
char *name = spl_clib_get_string(task);
123
130
char *value = spl_clib_get_string(task);
124
stfl_set(f, name, value);
131
stfl_set(f, stfl_ipool_towc(ipool, name), stfl_ipool_towc(ipool, value));
132
stfl_ipool_flush(ipool);
132
140
static struct spl_node *handler_stfl_get_focus(struct spl_task *task, void *data)
134
142
struct stfl_form *f = clib_get_stfl_form(task);
135
return f ? spl_new_nullable_ascii(stfl_get_focus(f)) : 0;
143
struct spl_node *ret = f ? spl_new_nullable_ascii(stfl_ipool_fromwc(ipool, stfl_get_focus(f))) : 0;
144
stfl_ipool_flush(ipool);
142
152
static struct spl_node *handler_stfl_set_focus(struct spl_task *task, void *data)
144
154
struct stfl_form *f = clib_get_stfl_form(task);
145
stfl_set_focus(f, spl_clib_get_string(task));
155
stfl_set_focus(f, stfl_ipool_towc(ipool, spl_clib_get_string(task)));
156
stfl_ipool_flush(ipool);
152
163
// builtin stfl_quote(text)
153
164
static struct spl_node *handler_stfl_quote(struct spl_task *task, void *data)
155
const char *text = stfl_quote(spl_clib_get_string(task));
156
struct spl_node *n = spl_new_nullable_ascii(text);
166
struct spl_node *n = spl_new_nullable_ascii(stfl_ipool_fromwc(ipool, stfl_quote(stfl_ipool_towc(ipool, spl_clib_get_string(task)))));
167
stfl_ipool_flush(ipool);
167
178
char *name = spl_clib_get_string(task);
168
179
char *prefix = spl_clib_get_string(task);
169
180
int focus = spl_clib_get_int(task);
170
const char *text = stfl_dump(f, name, prefix, focus);
181
const char *text = stfl_ipool_fromwc(ipool, stfl_dump(f, stfl_ipool_towc(ipool, name), stfl_ipool_towc(ipool, prefix), focus));
171
182
struct spl_node *n = spl_new_nullable_ascii(text);
183
stfl_ipool_flush(ipool);
182
194
char *name = spl_clib_get_string(task);
183
195
char *mode = spl_clib_get_string(task);
184
196
char *text = spl_clib_get_string(task);
185
stfl_modify(f, name, mode, text);
197
stfl_modify(f, stfl_ipool_towc(ipool, name), stfl_ipool_towc(ipool, mode), stfl_ipool_towc(ipool, text));
198
stfl_ipool_flush(ipool);
195
208
struct stfl_form *f = clib_get_stfl_form(task);
196
209
char *path = spl_clib_get_string(task);
197
210
char *newname = spl_clib_get_string(task);
198
return spl_new_nullable_ascii(stfl_lookup(f, path, newname));
211
struct spl_node *ret = spl_new_nullable_ascii(stfl_ipool_fromwc(ipool, stfl_lookup(f, stfl_ipool_towc(ipool, path), stfl_ipool_towc(ipool, newname))));
212
stfl_ipool_flush(ipool);
204
219
// builtin stfl_error()
205
220
static struct spl_node *handler_stfl_error(struct spl_task *task, void *data)
207
return spl_new_nullable_ascii(stfl_error());
222
struct spl_node *ret = spl_new_nullable_ascii(stfl_ipool_fromwc(ipool, stfl_error()));
223
stfl_ipool_flush(ipool);
214
231
static struct spl_node *handler_stfl_error_action(struct spl_task *task, void *data)
216
233
char *mode = spl_clib_get_string(task);
217
stfl_error_action(mode);
234
stfl_error_action(stfl_ipool_towc(ipool, mode));
235
stfl_ipool_flush(ipool);
239
static void destroy_ipool_atexit()
241
stfl_ipool_destroy(ipool);
221
245
void SPL_ABI(spl_mod_stfl_init)(struct spl_vm *vm, struct spl_module *mod, int restore)
248
ipool = stfl_ipool_create("UTF8");
249
atexit(destroy_ipool_atexit);
250
setlocale(LC_ALL,"");
223
253
spl_hnode_reg(vm, "stfl_form", handler_stfl_form_node, 0);
225
255
spl_clib_reg(vm, "stfl_create", handler_stfl_create, 0);