~ubuntu-branches/ubuntu/intrepid/stfl/intrepid

« back to all changes in this revision

Viewing changes to spl/mod_stfl.c

  • Committer: Bazaar Package Importer
  • Author(s): Nico Golde
  • Date: 2007-08-07 13:06:54 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20070807130654-fmvsraotulj0nbri
Tags: 0.15-3
Again added fPIC to CFLAGS. Hopefully all build issues
are fixed now.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 *  STFL - The Structured Terminal Forms Language/Library
3
 
 *  Copyright (C) 2006  Clifford Wolf <clifford@clifford.at>
4
 
 *
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.
9
 
 *
10
 
 *  This program is distributed in the hope that it will be useful,
 
3
 *  Copyright (C) 2006, 2007  Clifford Wolf <clifford@clifford.at>
 
4
 *
 
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.
 
9
 *  
 
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.
14
 
 *
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.
 
14
 *  
 
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,
 
18
 *  MA 02110-1301 USA
18
19
 *
19
20
 *  mod_stfl.c: STFL bindings for SPL
20
21
 */
26
27
 * Language/Library (STFL).
27
28
 */
28
29
 
29
 
#define _GNU_SOURCE
30
 
 
31
30
#include "stfl.h"
32
31
 
33
32
#include <spl.h>
34
33
#include <stdlib.h>
 
34
#include <locale.h>
 
35
 
 
36
static struct stfl_ipool *ipool = 0;
35
37
 
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);
60
62
 
61
63
static struct spl_node *spl_new_nullable_ascii(const char *text)
62
64
{
63
 
        return text ? SPL_NEW_STRING(spl_utf8_import(text, "ascii")) : spl_get(0);
 
65
        return text ? SPL_NEW_STRING_DUP(text) : spl_get(0);
64
66
}
65
67
 
66
68
/**
78
80
{
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);
82
85
        return n;
83
86
}
84
87
 
89
92
static struct spl_node *handler_stfl_run(struct spl_task *task, void *data)
90
93
{
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);
 
97
        return ret;
93
98
}
94
99
 
95
100
/**
109
114
static struct spl_node *handler_stfl_get(struct spl_task *task, void *data)
110
115
{
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);
 
119
        return ret;
113
120
}
114
121
 
115
122
/**
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);
125
133
        return 0;
126
134
}
127
135
 
132
140
static struct spl_node *handler_stfl_get_focus(struct spl_task *task, void *data)
133
141
{
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);
 
145
        return ret;
136
146
}
137
147
 
138
148
/**
142
152
static struct spl_node *handler_stfl_set_focus(struct spl_task *task, void *data)
143
153
{
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);
146
157
        return 0;
147
158
}
148
159
 
152
163
// builtin stfl_quote(text)
153
164
static struct spl_node *handler_stfl_quote(struct spl_task *task, void *data)
154
165
{
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);
157
168
        return n;
158
169
}
159
170
 
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);
172
184
        return n;
173
185
}
174
186
 
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);
186
199
        return 0;
187
200
}
188
201
 
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);
 
213
        return ret;
199
214
}
200
215
 
201
216
/**
204
219
// builtin stfl_error()
205
220
static struct spl_node *handler_stfl_error(struct spl_task *task, void *data)
206
221
{
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);
 
224
        return ret;
208
225
}
209
226
 
210
227
/**
214
231
static struct spl_node *handler_stfl_error_action(struct spl_task *task, void *data)
215
232
{
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);
218
236
        return 0;
219
237
}
220
238
 
 
239
static void destroy_ipool_atexit()
 
240
{
 
241
        stfl_ipool_destroy(ipool);
 
242
        ipool = 0;
 
243
}
 
244
 
221
245
void SPL_ABI(spl_mod_stfl_init)(struct spl_vm *vm, struct spl_module *mod, int restore)
222
246
{
 
247
        if (!ipool) {
 
248
                ipool = stfl_ipool_create("UTF8");
 
249
                atexit(destroy_ipool_atexit);
 
250
                setlocale(LC_ALL,"");
 
251
        }
 
252
 
223
253
        spl_hnode_reg(vm, "stfl_form", handler_stfl_form_node, 0);
224
254
 
225
255
        spl_clib_reg(vm, "stfl_create", handler_stfl_create, 0);