author | Myhailo Danylenko <isbear@ukrpost.net> |
Sun, 11 Apr 2010 22:25:24 +0300 | |
changeset 14 | 026c65e3e7d8 |
parent 13 | f4c15ad3cf93 |
child 17 | f17c162d0c52 |
permissions | -rw-r--r-- |
0 | 1 |
/* |
2 |
* yaubil.c -- Yet Another Useless Built-In Language |
|
3 |
* |
|
4 |
* Copyrigth (C) 2009 Myhailo Danylenko <isbear@ukrpost.net> |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or modify |
|
7 |
* it under the terms of the GNU General Public License as published by |
|
8 |
* the Free Software Foundation; either version 2 of the License, or (at |
|
9 |
* your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, but |
|
12 |
* WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
14 |
* General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
|
19 |
* USA |
|
20 |
*/ |
|
21 |
||
22 |
#include <glib.h> |
|
23 |
#include <string.h> |
|
11
5bbf342f450a
Fix compiler warnings
Myhailo Danylenko <isbear@ukrpost.net>
parents:
10
diff
changeset
|
24 |
#include <stdlib.h> |
0 | 25 |
|
2
6a47079725da
Change mcabber headers naming convention
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
26 |
#include <mcabber/commands.h> |
6a47079725da
Change mcabber headers naming convention
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
27 |
#include <mcabber/compl.h> |
6a47079725da
Change mcabber headers naming convention
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
28 |
#include <mcabber/logprint.h> |
6a47079725da
Change mcabber headers naming convention
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
29 |
#include <mcabber/settings.h> |
8
2033d1c5d226
New module loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
4
diff
changeset
|
30 |
#include <mcabber/modules.h> |
2033d1c5d226
New module loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
4
diff
changeset
|
31 |
|
9
70bb1e988a4a
Use new module info strut with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
8
diff
changeset
|
32 |
#include "config.h" |
70bb1e988a4a
Use new module info strut with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
8
diff
changeset
|
33 |
|
8
2033d1c5d226
New module loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
4
diff
changeset
|
34 |
static void yaubil_init (void); |
2033d1c5d226
New module loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
4
diff
changeset
|
35 |
static void yaubil_uninit (void); |
2033d1c5d226
New module loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
4
diff
changeset
|
36 |
|
9
70bb1e988a4a
Use new module info strut with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
8
diff
changeset
|
37 |
#define DESCRIPTION ( "Yet Another Useless Built-In Language\nProvides commands /multi, /if, /then, /else, /eval, /let" ) |
70bb1e988a4a
Use new module info strut with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
8
diff
changeset
|
38 |
|
70bb1e988a4a
Use new module info strut with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
8
diff
changeset
|
39 |
static module_info_t info_yaubil_experimental = { |
70bb1e988a4a
Use new module info strut with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
8
diff
changeset
|
40 |
.branch = "experimental", |
14
026c65e3e7d8
Add info struct for stable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
41 |
.api = 28, |
9
70bb1e988a4a
Use new module info strut with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
8
diff
changeset
|
42 |
.version = PROJECT_VERSION, |
70bb1e988a4a
Use new module info strut with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
8
diff
changeset
|
43 |
.description = DESCRIPTION, |
70bb1e988a4a
Use new module info strut with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
8
diff
changeset
|
44 |
.requires = NULL, |
70bb1e988a4a
Use new module info strut with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
8
diff
changeset
|
45 |
.init = yaubil_init, |
70bb1e988a4a
Use new module info strut with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
8
diff
changeset
|
46 |
.uninit = yaubil_uninit, |
70bb1e988a4a
Use new module info strut with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
8
diff
changeset
|
47 |
.next = NULL, |
70bb1e988a4a
Use new module info strut with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
8
diff
changeset
|
48 |
}; |
70bb1e988a4a
Use new module info strut with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
8
diff
changeset
|
49 |
|
14
026c65e3e7d8
Add info struct for stable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
50 |
static module_info_t info_yaubil_dev = { |
9
70bb1e988a4a
Use new module info strut with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
8
diff
changeset
|
51 |
.branch = "dev", |
12 | 52 |
.api = 13, |
9
70bb1e988a4a
Use new module info strut with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
8
diff
changeset
|
53 |
.version = PROJECT_VERSION, |
70bb1e988a4a
Use new module info strut with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
8
diff
changeset
|
54 |
.description = DESCRIPTION, |
70bb1e988a4a
Use new module info strut with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
8
diff
changeset
|
55 |
.requires = NULL, |
70bb1e988a4a
Use new module info strut with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
8
diff
changeset
|
56 |
.init = yaubil_init, |
70bb1e988a4a
Use new module info strut with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
8
diff
changeset
|
57 |
.uninit = yaubil_uninit, |
70bb1e988a4a
Use new module info strut with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
8
diff
changeset
|
58 |
.next = &info_yaubil_experimental, |
8
2033d1c5d226
New module loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
4
diff
changeset
|
59 |
}; |
0 | 60 |
|
14
026c65e3e7d8
Add info struct for stable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
61 |
module_info_t info_yaubil = { |
026c65e3e7d8
Add info struct for stable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
62 |
.branch = "0.10.0", |
026c65e3e7d8
Add info struct for stable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
63 |
.api = 1, |
026c65e3e7d8
Add info struct for stable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
64 |
.version = PROJECT_VERSION, |
026c65e3e7d8
Add info struct for stable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
65 |
.description = DESCRIPTION, |
026c65e3e7d8
Add info struct for stable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
66 |
.requires = NULL, |
026c65e3e7d8
Add info struct for stable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
67 |
.init = yaubil_init, |
026c65e3e7d8
Add info struct for stable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
68 |
.uninit = yaubil_uninit, |
026c65e3e7d8
Add info struct for stable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
69 |
.next = &info_yaubil_dev, |
026c65e3e7d8
Add info struct for stable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
70 |
}; |
026c65e3e7d8
Add info struct for stable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
71 |
|
13
f4c15ad3cf93
Use new commands interface
Myhailo Danylenko <isbear@ukrpost.net>
parents:
12
diff
changeset
|
72 |
#ifdef HAVE_CMD_ID |
f4c15ad3cf93
Use new commands interface
Myhailo Danylenko <isbear@ukrpost.net>
parents:
12
diff
changeset
|
73 |
static gpointer yaubil_multi_cmid = NULL; |
f4c15ad3cf93
Use new commands interface
Myhailo Danylenko <isbear@ukrpost.net>
parents:
12
diff
changeset
|
74 |
static gpointer yaubil_if_cmid = NULL; |
f4c15ad3cf93
Use new commands interface
Myhailo Danylenko <isbear@ukrpost.net>
parents:
12
diff
changeset
|
75 |
static gpointer yaubil_then_cmid = NULL; |
f4c15ad3cf93
Use new commands interface
Myhailo Danylenko <isbear@ukrpost.net>
parents:
12
diff
changeset
|
76 |
static gpointer yaubil_else_cmid = NULL; |
f4c15ad3cf93
Use new commands interface
Myhailo Danylenko <isbear@ukrpost.net>
parents:
12
diff
changeset
|
77 |
static gpointer yaubil_eval_cmid = NULL; |
f4c15ad3cf93
Use new commands interface
Myhailo Danylenko <isbear@ukrpost.net>
parents:
12
diff
changeset
|
78 |
static gpointer yaubil_let_cmid = NULL; |
f4c15ad3cf93
Use new commands interface
Myhailo Danylenko <isbear@ukrpost.net>
parents:
12
diff
changeset
|
79 |
#ifdef HAVE_CMD_SAFE |
f4c15ad3cf93
Use new commands interface
Myhailo Danylenko <isbear@ukrpost.net>
parents:
12
diff
changeset
|
80 |
static gboolean yaubil_multi_set_safe = FALSE; |
f4c15ad3cf93
Use new commands interface
Myhailo Danylenko <isbear@ukrpost.net>
parents:
12
diff
changeset
|
81 |
static gboolean yaubil_if_set_safe = FALSE; |
f4c15ad3cf93
Use new commands interface
Myhailo Danylenko <isbear@ukrpost.net>
parents:
12
diff
changeset
|
82 |
static gboolean yaubil_then_set_safe = FALSE; |
f4c15ad3cf93
Use new commands interface
Myhailo Danylenko <isbear@ukrpost.net>
parents:
12
diff
changeset
|
83 |
static gboolean yaubil_else_set_safe = FALSE; |
f4c15ad3cf93
Use new commands interface
Myhailo Danylenko <isbear@ukrpost.net>
parents:
12
diff
changeset
|
84 |
static gboolean yaubil_eval_set_safe = FALSE; |
f4c15ad3cf93
Use new commands interface
Myhailo Danylenko <isbear@ukrpost.net>
parents:
12
diff
changeset
|
85 |
static gboolean yaubil_let_set_safe = FALSE; |
f4c15ad3cf93
Use new commands interface
Myhailo Danylenko <isbear@ukrpost.net>
parents:
12
diff
changeset
|
86 |
#endif |
f4c15ad3cf93
Use new commands interface
Myhailo Danylenko <isbear@ukrpost.net>
parents:
12
diff
changeset
|
87 |
#endif |
f4c15ad3cf93
Use new commands interface
Myhailo Danylenko <isbear@ukrpost.net>
parents:
12
diff
changeset
|
88 |
|
0 | 89 |
static gboolean ifresult = TRUE; |
90 |
||
91 |
#define MSGPREFIX "yaubil: " |
|
92 |
||
93 |
#define TYPE_UNDEF ( 0 ) |
|
94 |
#define TYPE_STR ( 1 ) |
|
95 |
#define TYPE_INT ( 2 ) |
|
96 |
||
97 |
#define STATE_LVALUE ( 1 ) |
|
98 |
#define STATE_OP ( 2 ) |
|
99 |
#define STATE_RVALUE ( 3 ) |
|
100 |
||
101 |
typedef struct { |
|
102 |
int type; |
|
103 |
int int_value; |
|
104 |
char *str_value; |
|
105 |
} value_t; |
|
106 |
||
107 |
typedef struct { |
|
108 |
char op; |
|
109 |
gboolean (*handler) (value_t *l, value_t *r); |
|
110 |
} op_t; |
|
111 |
||
112 |
static int check_value_type (const char *value) |
|
113 |
{ |
|
114 |
if (value) { |
|
115 |
const char *e; |
|
4
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
116 |
gboolean integer = (*value == '-') ? TRUE : (g_ascii_isdigit (*value) ? TRUE : FALSE); |
0 | 117 |
|
118 |
if (integer) { |
|
119 |
for (e = value + 1; *e; ++e) { |
|
120 |
if (g_ascii_isdigit (*e)) |
|
121 |
integer = TRUE; |
|
122 |
else { |
|
123 |
integer = FALSE; |
|
124 |
break; |
|
125 |
} |
|
126 |
} |
|
127 |
} |
|
128 |
||
129 |
if (integer) |
|
130 |
return TYPE_INT; |
|
131 |
else |
|
132 |
return TYPE_STR; |
|
133 |
} else |
|
134 |
return TYPE_UNDEF; |
|
135 |
} |
|
136 |
||
137 |
static gboolean op_concat (value_t *l, value_t *r) |
|
138 |
{ |
|
4
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
139 |
GString *res = g_string_new (NULL); |
0 | 140 |
|
141 |
if (l->type == TYPE_INT) |
|
142 |
g_string_append_printf (res, "%d", l->int_value); |
|
143 |
else if (l->type == TYPE_STR) |
|
144 |
g_string_append (res, l->str_value); |
|
145 |
||
146 |
if (r->type == TYPE_INT) |
|
147 |
g_string_append_printf (res, "%d", r->int_value); |
|
148 |
else if (r->type == TYPE_STR) |
|
149 |
g_string_append (res, r->str_value); |
|
150 |
||
151 |
l->type = TYPE_STR; |
|
152 |
g_free (l->str_value); |
|
153 |
l->str_value = g_string_free (res, FALSE); |
|
154 |
||
155 |
return TRUE; |
|
156 |
} |
|
157 |
||
4
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
158 |
static gboolean op_head (value_t *l, value_t *r) |
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
159 |
{ |
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
160 |
if (l->type == TYPE_UNDEF) { |
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
161 |
l->type = TYPE_INT; |
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
162 |
l->int_value = 0; |
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
163 |
} |
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
164 |
if (r->type == TYPE_UNDEF) { |
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
165 |
r->type = TYPE_INT; |
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
166 |
r->int_value = 0; |
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
167 |
} |
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
168 |
|
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
169 |
if (l -> type == TYPE_INT) { |
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
170 |
l -> type = TYPE_STR; |
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
171 |
if (!l -> str_value) |
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
172 |
l -> str_value = g_strdup_printf ("%d", l -> int_value); |
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
173 |
} |
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
174 |
if (r->type == TYPE_STR && check_value_type (r->str_value) == TYPE_INT) { |
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
175 |
r->type = TYPE_INT; |
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
176 |
r->int_value = atoi (r->str_value); |
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
177 |
g_free (r->str_value); |
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
178 |
r->str_value = NULL; |
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
179 |
} |
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
180 |
|
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
181 |
if (l->type == TYPE_STR && r->type == TYPE_INT) { |
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
182 |
gchar *res = NULL; |
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
183 |
int len = l -> str_value ? strlen (l -> str_value) : 0; // XXX can str_value be NULL? |
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
184 |
int off = r -> int_value; |
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
185 |
if (off < 0 && len + off > 0) |
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
186 |
res = g_strndup (l -> str_value, len + off); |
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
187 |
else if (off > 0 && len > off) |
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
188 |
res = g_strndup (l -> str_value, off); |
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
189 |
else |
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
190 |
res = g_strdup (""); // XXX leave NULL here? |
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
191 |
g_free (l->str_value); |
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
192 |
l->str_value = res; |
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
193 |
} else |
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
194 |
return FALSE; |
11
5bbf342f450a
Fix compiler warnings
Myhailo Danylenko <isbear@ukrpost.net>
parents:
10
diff
changeset
|
195 |
|
5bbf342f450a
Fix compiler warnings
Myhailo Danylenko <isbear@ukrpost.net>
parents:
10
diff
changeset
|
196 |
return TRUE; |
4
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
197 |
} |
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
198 |
|
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
199 |
static gboolean op_tail (value_t *l, value_t *r) |
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
200 |
{ |
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
201 |
if (l->type == TYPE_UNDEF) { |
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
202 |
l->type = TYPE_INT; |
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
203 |
l->int_value = 0; |
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
204 |
} |
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
205 |
if (r->type == TYPE_UNDEF) { |
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
206 |
r->type = TYPE_INT; |
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
207 |
r->int_value = 0; |
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
208 |
} |
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
209 |
|
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
210 |
if (l -> type == TYPE_INT) { |
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
211 |
l -> type = TYPE_STR; |
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
212 |
if (!l -> str_value) |
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
213 |
l -> str_value = g_strdup_printf ("%d", l -> int_value); |
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
214 |
} |
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
215 |
if (r->type == TYPE_STR && check_value_type (r->str_value) == TYPE_INT) { |
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
216 |
r->type = TYPE_INT; |
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
217 |
r->int_value = atoi (r->str_value); |
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
218 |
g_free (r->str_value); |
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
219 |
r->str_value = NULL; |
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
220 |
} |
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
221 |
|
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
222 |
if (l->type == TYPE_STR && r->type == TYPE_INT) { |
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
223 |
gchar *res = NULL; |
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
224 |
int len = l -> str_value ? strlen (l -> str_value) : 0; // XXX can str_value be NULL? |
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
225 |
int off = r -> int_value; |
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
226 |
if (off < 0 && len + off > 0) |
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
227 |
res = g_strdup (l -> str_value + (-off)); |
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
228 |
else if (off > 0 && len > off) |
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
229 |
res = g_strdup (l -> str_value + (len - off)); |
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
230 |
else |
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
231 |
res = g_strdup (""); // XXX leave NULL here? |
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
232 |
g_free (l->str_value); |
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
233 |
l->str_value = res; |
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
234 |
} else |
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
235 |
return FALSE; |
11
5bbf342f450a
Fix compiler warnings
Myhailo Danylenko <isbear@ukrpost.net>
parents:
10
diff
changeset
|
236 |
|
5bbf342f450a
Fix compiler warnings
Myhailo Danylenko <isbear@ukrpost.net>
parents:
10
diff
changeset
|
237 |
return TRUE; |
4
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
238 |
} |
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
239 |
|
0 | 240 |
static gboolean op_plus (value_t *l, value_t *r) |
241 |
{ |
|
242 |
if (l->type == TYPE_UNDEF) { |
|
243 |
l->type = TYPE_INT; |
|
244 |
l->int_value = 0; |
|
245 |
} |
|
246 |
if (r->type == TYPE_UNDEF) { |
|
247 |
r->type = TYPE_INT; |
|
248 |
r->int_value = 0; |
|
249 |
} |
|
250 |
||
251 |
if (l->type == TYPE_STR && check_value_type (l->str_value) == TYPE_INT) { |
|
252 |
l->type = TYPE_INT; |
|
253 |
l->int_value = atoi (l->str_value); |
|
254 |
// not free value here |
|
255 |
} |
|
256 |
if (r->type == TYPE_STR && check_value_type (r->str_value) == TYPE_INT) { |
|
257 |
r->type = TYPE_INT; |
|
258 |
r->int_value = atoi (r->str_value); |
|
259 |
// not free value here |
|
260 |
} |
|
261 |
||
262 |
if (l->type == TYPE_INT && r->type == TYPE_INT) { |
|
263 |
// integer |
|
264 |
l->int_value += r->int_value; |
|
265 |
g_free (l->str_value); |
|
266 |
l->str_value = NULL; |
|
267 |
g_free (r->str_value); |
|
268 |
r->str_value = NULL; |
|
269 |
} else { |
|
270 |
// convert both to strings |
|
271 |
if (l->type == TYPE_INT) { |
|
272 |
l->type = TYPE_STR; |
|
273 |
if (!l->str_value) |
|
274 |
l->str_value = g_strdup_printf ("%d", l->int_value); |
|
275 |
} |
|
276 |
if (r->type == TYPE_INT) { |
|
277 |
r->type = TYPE_STR; |
|
278 |
if (!r->str_value) |
|
279 |
r->str_value = g_strdup_printf ("%d", r->int_value); |
|
280 |
} |
|
281 |
||
282 |
{ |
|
283 |
char *tmp = l->str_value; |
|
284 |
l->str_value = g_strdup_printf ("%s%s", tmp, r->str_value); |
|
285 |
g_free (tmp); |
|
286 |
} |
|
287 |
} |
|
288 |
||
289 |
return TRUE; |
|
290 |
} |
|
291 |
||
292 |
static gboolean op_minus (value_t *l, value_t *r) |
|
293 |
{ |
|
294 |
if (l->type == TYPE_UNDEF) { |
|
295 |
l->type = TYPE_INT; |
|
296 |
l->int_value = 0; |
|
297 |
} |
|
298 |
if (r->type == TYPE_UNDEF) { |
|
299 |
r->type = TYPE_INT; |
|
300 |
r->int_value = 0; |
|
301 |
} |
|
302 |
||
303 |
if (l->type == TYPE_STR && check_value_type (l->str_value) == TYPE_INT) { |
|
304 |
l->type = TYPE_INT; |
|
305 |
l->int_value = atoi (l->str_value); |
|
306 |
g_free (l->str_value); |
|
307 |
l->str_value = NULL; |
|
308 |
} |
|
309 |
if (r->type == TYPE_STR && check_value_type (r->str_value) == TYPE_INT) { |
|
310 |
r->type = TYPE_INT; |
|
311 |
r->int_value = atoi (r->str_value); |
|
312 |
g_free (r->str_value); |
|
313 |
r->str_value = NULL; |
|
314 |
} |
|
315 |
||
316 |
if (l->type == TYPE_INT && r->type == TYPE_INT) |
|
317 |
l->int_value -= r->int_value; |
|
318 |
else |
|
319 |
return FALSE; |
|
320 |
||
321 |
return TRUE; |
|
322 |
} |
|
323 |
||
324 |
static gboolean op_multiply (value_t *l, value_t *r) |
|
325 |
{ |
|
326 |
if (l->type == TYPE_UNDEF) { |
|
327 |
l->type = TYPE_INT; |
|
328 |
l->int_value = 0; |
|
329 |
} |
|
330 |
if (r->type == TYPE_UNDEF) { |
|
331 |
r->type = TYPE_INT; |
|
332 |
r->int_value = 0; |
|
333 |
} |
|
334 |
||
335 |
if (l->type == TYPE_STR && check_value_type (l->str_value) == TYPE_INT) { |
|
336 |
l->type = TYPE_INT; |
|
337 |
l->int_value = atoi (l->str_value); |
|
338 |
// not free value here |
|
339 |
} |
|
340 |
if (r->type == TYPE_STR && check_value_type (r->str_value) == TYPE_INT) { |
|
341 |
r->type = TYPE_INT; |
|
342 |
r->int_value = atoi (r->str_value); |
|
343 |
g_free (r->str_value); |
|
344 |
r->str_value = NULL; |
|
345 |
} |
|
346 |
||
347 |
if (l->type == TYPE_INT && r->type == TYPE_INT) { |
|
348 |
l->int_value *= r->int_value; |
|
349 |
g_free (l->str_value); |
|
350 |
l->str_value = NULL; |
|
351 |
} else if (r->type == TYPE_INT) { |
|
352 |
GString *res = g_string_new (NULL); |
|
353 |
int i; |
|
354 |
for (i = r->int_value; i; --i) |
|
355 |
g_string_append (res, l->str_value); |
|
356 |
g_free (l->str_value); |
|
357 |
l->str_value = g_string_free (res, FALSE); |
|
358 |
} else |
|
359 |
return FALSE; |
|
360 |
||
361 |
return TRUE; |
|
362 |
} |
|
363 |
||
364 |
static gboolean op_divide (value_t *l, value_t *r) |
|
365 |
{ |
|
366 |
if (l->type == TYPE_UNDEF) { |
|
367 |
l->type = TYPE_INT; |
|
368 |
l->int_value = 0; |
|
369 |
} |
|
370 |
if (r->type == TYPE_UNDEF) { |
|
371 |
r->type = TYPE_INT; |
|
372 |
r->int_value = 0; |
|
373 |
} |
|
374 |
||
375 |
if (l->type == TYPE_STR && check_value_type (l->str_value) == TYPE_INT) { |
|
376 |
l->type = TYPE_INT; |
|
377 |
l->int_value = atoi (l->str_value); |
|
378 |
g_free (l->str_value); |
|
379 |
l->str_value = NULL; |
|
380 |
} |
|
381 |
if (r->type == TYPE_STR && check_value_type (r->str_value) == TYPE_INT) { |
|
382 |
r->type = TYPE_INT; |
|
383 |
r->int_value = atoi (r->str_value); |
|
384 |
g_free (r->str_value); |
|
385 |
r->str_value = NULL; |
|
386 |
} |
|
387 |
||
388 |
if (l->type == TYPE_INT && r->type == TYPE_INT) { |
|
389 |
if (r->int_value == 0) { |
|
10
14987412be3b
Use new scr_* functions
Myhailo Danylenko <isbear@ukrpost.net>
parents:
9
diff
changeset
|
390 |
scr_log_print (LPRINT_NORMAL, MSGPREFIX "/: Error: division by zero."); |
0 | 391 |
return FALSE; |
392 |
} |
|
393 |
l->int_value /= r->int_value; |
|
394 |
} else |
|
395 |
return FALSE; |
|
396 |
||
397 |
return TRUE; |
|
398 |
} |
|
399 |
||
400 |
static gboolean op_remain (value_t *l, value_t *r) |
|
401 |
{ |
|
402 |
if (l->type == TYPE_UNDEF) { |
|
403 |
l->type = TYPE_INT; |
|
404 |
l->int_value = 0; |
|
405 |
} |
|
406 |
if (r->type == TYPE_UNDEF) { |
|
407 |
r->type = TYPE_INT; |
|
408 |
r->int_value = 0; |
|
409 |
} |
|
410 |
||
411 |
if (l->type == TYPE_STR && check_value_type (l->str_value) == TYPE_INT) { |
|
412 |
l->type = TYPE_INT; |
|
413 |
l->int_value = atoi (l->str_value); |
|
414 |
g_free (l->str_value); |
|
415 |
l->str_value = NULL; |
|
416 |
} |
|
417 |
if (r->type == TYPE_STR && check_value_type (r->str_value) == TYPE_INT) { |
|
418 |
r->type = TYPE_INT; |
|
419 |
r->int_value = atoi (r->str_value); |
|
420 |
g_free (r->str_value); |
|
421 |
r->str_value = NULL; |
|
422 |
} |
|
423 |
||
424 |
if (l->type == TYPE_INT && r->type == TYPE_INT) { |
|
425 |
if (r->int_value == 0) { |
|
10
14987412be3b
Use new scr_* functions
Myhailo Danylenko <isbear@ukrpost.net>
parents:
9
diff
changeset
|
426 |
scr_log_print (LPRINT_NORMAL, MSGPREFIX "%%: Error: division by zero."); |
0 | 427 |
return FALSE; |
428 |
} |
|
429 |
l->int_value %= r->int_value; |
|
430 |
} else |
|
431 |
return FALSE; |
|
432 |
||
433 |
return TRUE; |
|
434 |
} |
|
435 |
||
436 |
static gboolean op_equal (value_t *l, value_t *r) |
|
437 |
{ |
|
438 |
if (l->type == TYPE_UNDEF) { |
|
439 |
l->type = TYPE_INT; |
|
440 |
l->int_value = 0; |
|
441 |
} |
|
442 |
if (r->type == TYPE_UNDEF) { |
|
443 |
r->type = TYPE_INT; |
|
444 |
r->int_value = 0; |
|
445 |
} |
|
446 |
||
447 |
if (l->type == TYPE_STR && check_value_type (l->str_value) == TYPE_INT) { |
|
448 |
l->type = TYPE_INT; |
|
449 |
l->int_value = atoi (l->str_value); |
|
450 |
// not free value here |
|
451 |
} |
|
452 |
if (r->type == TYPE_STR && check_value_type (r->str_value) == TYPE_INT) { |
|
453 |
r->type = TYPE_INT; |
|
454 |
r->int_value = atoi (r->str_value); |
|
455 |
// not free value here |
|
456 |
} |
|
457 |
||
458 |
if (l->type == TYPE_INT && r->type == TYPE_INT) { |
|
459 |
// integer |
|
460 |
l->int_value = (l->int_value == r->int_value) ? 1 : 0; |
|
461 |
g_free (l->str_value); |
|
462 |
l->str_value = NULL; |
|
463 |
g_free (r->str_value); |
|
464 |
r->str_value = NULL; |
|
465 |
} else { |
|
466 |
// convert both to strings |
|
467 |
if (l->type == TYPE_INT) { |
|
468 |
l->type = TYPE_STR; |
|
469 |
if (!l->str_value) |
|
470 |
l->str_value = g_strdup_printf ("%d", l->int_value); |
|
471 |
} |
|
472 |
if (r->type == TYPE_INT) { |
|
473 |
r->type = TYPE_STR; |
|
474 |
if (!r->str_value) |
|
475 |
r->str_value = g_strdup_printf ("%d", r->int_value); |
|
476 |
} |
|
477 |
||
478 |
{ |
|
479 |
char *tmp = l->str_value; |
|
480 |
l->type = TYPE_INT; |
|
481 |
l->int_value = (g_strcmp0 (l->str_value, r->str_value) == 0) ? 1 : 0; |
|
482 |
g_free (tmp); |
|
483 |
} |
|
484 |
} |
|
485 |
||
486 |
return TRUE; |
|
487 |
} |
|
488 |
||
489 |
static gboolean op_lt (value_t *l, value_t *r) |
|
490 |
{ |
|
491 |
if (l->type == TYPE_UNDEF) { |
|
492 |
l->type = TYPE_INT; |
|
493 |
l->int_value = 0; |
|
494 |
} |
|
495 |
if (r->type == TYPE_UNDEF) { |
|
496 |
r->type = TYPE_INT; |
|
497 |
r->int_value = 0; |
|
498 |
} |
|
499 |
||
500 |
if (l->type == TYPE_STR && check_value_type (l->str_value) == TYPE_INT) { |
|
501 |
l->type = TYPE_INT; |
|
502 |
l->int_value = atoi (l->str_value); |
|
503 |
// not free value here |
|
504 |
} |
|
505 |
if (r->type == TYPE_STR && check_value_type (r->str_value) == TYPE_INT) { |
|
506 |
r->type = TYPE_INT; |
|
507 |
r->int_value = atoi (r->str_value); |
|
508 |
// not free value here |
|
509 |
} |
|
510 |
||
511 |
if (l->type == TYPE_INT && r->type == TYPE_INT) { |
|
512 |
// integer |
|
513 |
l->int_value = (l->int_value < r->int_value) ? 1 : 0; |
|
514 |
g_free (l->str_value); |
|
515 |
l->str_value = NULL; |
|
516 |
g_free (r->str_value); |
|
517 |
r->str_value = NULL; |
|
518 |
} else { |
|
519 |
// convert both to strings |
|
520 |
if (l->type == TYPE_INT) { |
|
521 |
l->type = TYPE_STR; |
|
522 |
if (!l->str_value) |
|
523 |
l->str_value = g_strdup_printf ("%d", l->int_value); |
|
524 |
} |
|
525 |
if (r->type == TYPE_INT) { |
|
526 |
r->type = TYPE_STR; |
|
527 |
if (!r->str_value) |
|
528 |
r->str_value = g_strdup_printf ("%d", r->int_value); |
|
529 |
} |
|
530 |
||
531 |
{ |
|
532 |
char *tmp = l->str_value; |
|
533 |
l->type = TYPE_INT; |
|
534 |
l->int_value = (g_strcmp0 (l->str_value, r->str_value) < 0) ? 1 : 0; |
|
535 |
g_free (tmp); |
|
536 |
} |
|
537 |
} |
|
538 |
||
539 |
return TRUE; |
|
540 |
} |
|
541 |
||
542 |
static gboolean op_gt (value_t *l, value_t *r) |
|
543 |
{ |
|
544 |
if (l->type == TYPE_UNDEF) { |
|
545 |
l->type = TYPE_INT; |
|
546 |
l->int_value = 0; |
|
547 |
} |
|
548 |
if (r->type == TYPE_UNDEF) { |
|
549 |
r->type = TYPE_INT; |
|
550 |
r->int_value = 0; |
|
551 |
} |
|
552 |
||
553 |
if (l->type == TYPE_STR && check_value_type (l->str_value) == TYPE_INT) { |
|
554 |
l->type = TYPE_INT; |
|
555 |
l->int_value = atoi (l->str_value); |
|
556 |
// not free value here |
|
557 |
} |
|
558 |
if (r->type == TYPE_STR && check_value_type (r->str_value) == TYPE_INT) { |
|
559 |
r->type = TYPE_INT; |
|
560 |
r->int_value = atoi (r->str_value); |
|
561 |
// not free value here |
|
562 |
} |
|
563 |
||
564 |
if (l->type == TYPE_INT && r->type == TYPE_INT) { |
|
565 |
// integer |
|
566 |
l->int_value = (l->int_value > r->int_value) ? 1 : 0; |
|
567 |
g_free (l->str_value); |
|
568 |
l->str_value = NULL; |
|
569 |
g_free (r->str_value); |
|
570 |
r->str_value = NULL; |
|
571 |
} else { |
|
572 |
// convert both to strings |
|
573 |
if (l->type == TYPE_INT) { |
|
574 |
l->type = TYPE_STR; |
|
575 |
if (!l->str_value) |
|
576 |
l->str_value = g_strdup_printf ("%d", l->int_value); |
|
577 |
} |
|
578 |
if (r->type == TYPE_INT) { |
|
579 |
r->type = TYPE_STR; |
|
580 |
if (!r->str_value) |
|
581 |
r->str_value = g_strdup_printf ("%d", r->int_value); |
|
582 |
} |
|
583 |
||
584 |
{ |
|
585 |
char *tmp = l->str_value; |
|
586 |
l->type = TYPE_INT; |
|
587 |
l->int_value = (g_strcmp0 (l->str_value, r->str_value) > 0) ? 1 : 0; |
|
588 |
g_free (tmp); |
|
589 |
} |
|
590 |
} |
|
591 |
||
592 |
return TRUE; |
|
593 |
} |
|
594 |
||
595 |
static op_t operators[] = { |
|
596 |
{ '.', op_concat }, |
|
4
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
597 |
{ ':', op_head }, |
faaed3ae3fa8
String head and tail operators
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
598 |
{ '^', op_tail }, |
0 | 599 |
{ '+', op_plus }, |
600 |
{ '-', op_minus }, |
|
601 |
{ '*', op_multiply }, |
|
602 |
{ '/', op_divide }, |
|
603 |
{ '%', op_remain }, |
|
604 |
{ '=', op_equal }, |
|
605 |
{ '<', op_lt }, |
|
606 |
{ '>', op_gt }, |
|
607 |
{ 0, NULL }, |
|
608 |
}; |
|
609 |
||
610 |
static void destroy_value (value_t *value) |
|
611 |
{ |
|
612 |
if (value->str_value) |
|
613 |
g_free (value->str_value); |
|
614 |
g_free (value); |
|
615 |
} |
|
616 |
||
1
320e4393785a
Parentheses now have no restrictions in strings
Myhailo Danylenko <isbear@ukrpost.net>
parents:
0
diff
changeset
|
617 |
static value_t *process_expression (const char *str, gsize *len) |
0 | 618 |
{ |
1
320e4393785a
Parentheses now have no restrictions in strings
Myhailo Danylenko <isbear@ukrpost.net>
parents:
0
diff
changeset
|
619 |
const char *strend = str + *len; |
0 | 620 |
const char *p; |
621 |
op_t *op = NULL; |
|
622 |
int state = STATE_LVALUE; |
|
623 |
value_t val = { |
|
624 |
.type = TYPE_UNDEF, |
|
625 |
.int_value = 0, |
|
626 |
.str_value = NULL, |
|
627 |
}; |
|
628 |
||
1
320e4393785a
Parentheses now have no restrictions in strings
Myhailo Danylenko <isbear@ukrpost.net>
parents:
0
diff
changeset
|
629 |
for (p = str; *p && p < strend && *p != ')'; ++p) { |
0 | 630 |
switch (state) { |
631 |
case STATE_LVALUE: |
|
632 |
case STATE_RVALUE: |
|
633 |
||
634 |
if (*p == ' ') |
|
635 |
break; |
|
636 |
||
637 |
{ |
|
638 |
value_t rval = { |
|
639 |
.type = TYPE_UNDEF, |
|
640 |
.int_value = 0, |
|
641 |
.str_value = NULL, |
|
642 |
}; |
|
643 |
||
644 |
if (g_ascii_isdigit (*p) || *p == '-') { // integer // XXX: no unary operators for now... |
|
645 |
||
646 |
const char *e; |
|
647 |
||
648 |
rval.type = TYPE_INT; |
|
649 |
||
650 |
for (e = p + 1; g_ascii_isdigit (*e) && e < strend; ++e); // TODO: does atoi handle 0x etc? then also allow this? |
|
651 |
||
652 |
{ |
|
653 |
char *v = g_strndup (p, e - p); |
|
654 |
rval.int_value = atoi (v); |
|
655 |
g_free (v); |
|
656 |
} |
|
657 |
||
658 |
p = e - 1; |
|
659 |
||
660 |
} else if (*p == '"') { // string |
|
661 |
||
662 |
const char *e; |
|
663 |
||
664 |
rval.type = TYPE_STR; |
|
665 |
||
666 |
{ |
|
667 |
gboolean finished = FALSE; |
|
668 |
gboolean escape = FALSE; |
|
669 |
GString *v = g_string_new (NULL); |
|
670 |
||
671 |
for (e = p + 1; *e && e < strend; ++e) { |
|
672 |
switch (*e) { |
|
673 |
case '\\': |
|
674 |
if (!escape) |
|
675 |
escape = TRUE; |
|
676 |
else |
|
677 |
escape = FALSE; |
|
678 |
break; |
|
679 |
case '"': |
|
680 |
if (!escape) { |
|
681 |
finished = TRUE; |
|
682 |
break; |
|
683 |
} else |
|
684 |
escape = FALSE; |
|
685 |
break; |
|
686 |
default: |
|
687 |
escape = FALSE; |
|
688 |
break; |
|
689 |
} |
|
690 |
||
691 |
if (finished) |
|
692 |
break; |
|
693 |
||
694 |
if (!escape) |
|
695 |
g_string_append_c (v, *e); |
|
696 |
}; |
|
697 |
||
698 |
if (!finished) { |
|
10
14987412be3b
Use new scr_* functions
Myhailo Danylenko <isbear@ukrpost.net>
parents:
9
diff
changeset
|
699 |
scr_log_print (LPRINT_NORMAL, MSGPREFIX "Error: Unmatched quote."); |
0 | 700 |
g_string_free (v, TRUE); |
701 |
g_free (val.str_value); |
|
702 |
return NULL; |
|
703 |
} |
|
704 |
||
705 |
rval.str_value = g_string_free (v, FALSE); |
|
706 |
} |
|
707 |
||
708 |
p = e; |
|
709 |
||
710 |
} else if (g_ascii_isalpha (*p)) { // variable (MUST start from alpha) |
|
711 |
||
712 |
const char *e; |
|
713 |
||
714 |
for (e = p + 1; (g_ascii_isalnum (*e) || *e == '-' || *e == '_') && e < strend; ++e); |
|
715 |
||
716 |
char *name = g_strndup (p, e - p); |
|
717 |
const char *value = settings_opt_get (name); |
|
718 |
g_free (name); |
|
719 |
||
720 |
rval.type = check_value_type (value); |
|
721 |
if (rval.type == TYPE_INT) |
|
722 |
rval.int_value = atoi (value); |
|
723 |
else if (rval.type == TYPE_STR) |
|
724 |
rval.str_value = g_strdup (value); |
|
725 |
||
726 |
p = e - 1; |
|
727 |
||
728 |
} else if (*p == '(') { |
|
729 |
||
1
320e4393785a
Parentheses now have no restrictions in strings
Myhailo Danylenko <isbear@ukrpost.net>
parents:
0
diff
changeset
|
730 |
gsize len = strend - p - 1; |
320e4393785a
Parentheses now have no restrictions in strings
Myhailo Danylenko <isbear@ukrpost.net>
parents:
0
diff
changeset
|
731 |
value_t *n = process_expression (p + 1, &len); |
320e4393785a
Parentheses now have no restrictions in strings
Myhailo Danylenko <isbear@ukrpost.net>
parents:
0
diff
changeset
|
732 |
|
320e4393785a
Parentheses now have no restrictions in strings
Myhailo Danylenko <isbear@ukrpost.net>
parents:
0
diff
changeset
|
733 |
if (!n) { |
10
14987412be3b
Use new scr_* functions
Myhailo Danylenko <isbear@ukrpost.net>
parents:
9
diff
changeset
|
734 |
scr_log_print (LPRINT_NORMAL, MSGPREFIX "Error: Error in subexpression."); |
1
320e4393785a
Parentheses now have no restrictions in strings
Myhailo Danylenko <isbear@ukrpost.net>
parents:
0
diff
changeset
|
735 |
g_free (val.str_value); |
320e4393785a
Parentheses now have no restrictions in strings
Myhailo Danylenko <isbear@ukrpost.net>
parents:
0
diff
changeset
|
736 |
return NULL; |
0 | 737 |
} |
738 |
||
1
320e4393785a
Parentheses now have no restrictions in strings
Myhailo Danylenko <isbear@ukrpost.net>
parents:
0
diff
changeset
|
739 |
rval.type = n->type; |
320e4393785a
Parentheses now have no restrictions in strings
Myhailo Danylenko <isbear@ukrpost.net>
parents:
0
diff
changeset
|
740 |
rval.int_value = n->int_value; |
320e4393785a
Parentheses now have no restrictions in strings
Myhailo Danylenko <isbear@ukrpost.net>
parents:
0
diff
changeset
|
741 |
rval.str_value = g_strdup (n->str_value); |
320e4393785a
Parentheses now have no restrictions in strings
Myhailo Danylenko <isbear@ukrpost.net>
parents:
0
diff
changeset
|
742 |
destroy_value (n); |
0 | 743 |
|
1
320e4393785a
Parentheses now have no restrictions in strings
Myhailo Danylenko <isbear@ukrpost.net>
parents:
0
diff
changeset
|
744 |
p += len + 1; |
0 | 745 |
|
746 |
} else { |
|
10
14987412be3b
Use new scr_* functions
Myhailo Danylenko <isbear@ukrpost.net>
parents:
9
diff
changeset
|
747 |
scr_log_print (LPRINT_NORMAL, MSGPREFIX "Error: unrecognized symbols."); |
0 | 748 |
g_free (val.str_value); |
749 |
return NULL; |
|
750 |
} |
|
751 |
||
752 |
if (state == STATE_RVALUE) { |
|
753 |
if (op->handler) { |
|
754 |
if (!op->handler (&val, &rval)) { |
|
10
14987412be3b
Use new scr_* functions
Myhailo Danylenko <isbear@ukrpost.net>
parents:
9
diff
changeset
|
755 |
scr_log_print (LPRINT_NORMAL, MSGPREFIX "Error: operand argument types mismatch."); |
0 | 756 |
g_free (val.str_value); |
757 |
g_free (rval.str_value); |
|
758 |
return NULL; |
|
759 |
} |
|
760 |
} |
|
761 |
g_free (rval.str_value); |
|
762 |
} else { |
|
763 |
val.type = rval.type; |
|
764 |
val.int_value = rval.int_value; |
|
765 |
val.str_value = rval.str_value; |
|
766 |
} |
|
767 |
||
768 |
state = STATE_OP; |
|
769 |
} |
|
770 |
||
771 |
break; |
|
772 |
||
773 |
case STATE_OP: |
|
774 |
||
775 |
if (*p == ' ') |
|
776 |
break; |
|
777 |
||
778 |
{ |
|
779 |
op_t *operator; |
|
780 |
gboolean found = FALSE; |
|
781 |
||
782 |
for (operator = operators; operator->op; ++operator) { |
|
783 |
if (operator->op == *p) { |
|
784 |
op = operator; |
|
785 |
found = TRUE; |
|
786 |
break; |
|
787 |
} |
|
788 |
} |
|
789 |
||
790 |
if (!found) { |
|
10
14987412be3b
Use new scr_* functions
Myhailo Danylenko <isbear@ukrpost.net>
parents:
9
diff
changeset
|
791 |
scr_log_print (LPRINT_NORMAL, MSGPREFIX "Error: unknown operator."); |
0 | 792 |
g_free (val.str_value); |
793 |
} |
|
794 |
} |
|
795 |
||
796 |
state = STATE_RVALUE; |
|
797 |
||
798 |
break; |
|
799 |
default: |
|
800 |
break; |
|
801 |
} |
|
802 |
} |
|
803 |
||
804 |
{ // return value |
|
1
320e4393785a
Parentheses now have no restrictions in strings
Myhailo Danylenko <isbear@ukrpost.net>
parents:
0
diff
changeset
|
805 |
*len = p - str; |
0 | 806 |
value_t *rval = g_new (value_t, 1); |
807 |
||
808 |
rval->type = val.type; |
|
809 |
rval->int_value = val.int_value; |
|
810 |
rval->str_value = val.str_value; |
|
811 |
||
812 |
return rval; |
|
813 |
} |
|
814 |
} |
|
815 |
||
816 |
static void do_eval (char *arg) |
|
817 |
{ |
|
1
320e4393785a
Parentheses now have no restrictions in strings
Myhailo Danylenko <isbear@ukrpost.net>
parents:
0
diff
changeset
|
818 |
gsize len = strlen (arg); |
320e4393785a
Parentheses now have no restrictions in strings
Myhailo Danylenko <isbear@ukrpost.net>
parents:
0
diff
changeset
|
819 |
value_t *val = process_expression (arg, &len); |
0 | 820 |
|
821 |
if (!val) { |
|
10
14987412be3b
Use new scr_* functions
Myhailo Danylenko <isbear@ukrpost.net>
parents:
9
diff
changeset
|
822 |
scr_log_print (LPRINT_NORMAL, "eval: Evaluation error."); |
0 | 823 |
return; |
824 |
} |
|
825 |
||
826 |
if (val->type == TYPE_STR) |
|
827 |
process_command (val->str_value, TRUE); |
|
828 |
else |
|
10
14987412be3b
Use new scr_* functions
Myhailo Danylenko <isbear@ukrpost.net>
parents:
9
diff
changeset
|
829 |
scr_log_print (LPRINT_NORMAL, "eval: Expression does not result in string."); |
0 | 830 |
|
831 |
destroy_value (val); |
|
832 |
} |
|
833 |
||
834 |
static void do_let (char *arg) |
|
835 |
{ |
|
836 |
value_t *value; |
|
837 |
int namelen; |
|
838 |
char *val = strchr (arg, '='); |
|
839 |
||
840 |
if (!val) { |
|
10
14987412be3b
Use new scr_* functions
Myhailo Danylenko <isbear@ukrpost.net>
parents:
9
diff
changeset
|
841 |
scr_log_print (LPRINT_NORMAL, "let: Syntax error: no equal sign in line."); |
0 | 842 |
return; |
843 |
} |
|
844 |
||
845 |
{ |
|
846 |
char *p = val; |
|
847 |
||
848 |
for (p = val - 1; p >= arg && *p == ' '; --p); |
|
849 |
if (p < arg) { |
|
10
14987412be3b
Use new scr_* functions
Myhailo Danylenko <isbear@ukrpost.net>
parents:
9
diff
changeset
|
850 |
scr_log_print (LPRINT_NORMAL, "let: Syntax error: no destination variable name specified."); |
0 | 851 |
return; |
852 |
} |
|
853 |
||
854 |
namelen = p + 1 - arg; |
|
855 |
} |
|
856 |
||
1
320e4393785a
Parentheses now have no restrictions in strings
Myhailo Danylenko <isbear@ukrpost.net>
parents:
0
diff
changeset
|
857 |
{ // evaluate expression |
320e4393785a
Parentheses now have no restrictions in strings
Myhailo Danylenko <isbear@ukrpost.net>
parents:
0
diff
changeset
|
858 |
gsize len = strlen (val + 1); |
320e4393785a
Parentheses now have no restrictions in strings
Myhailo Danylenko <isbear@ukrpost.net>
parents:
0
diff
changeset
|
859 |
|
320e4393785a
Parentheses now have no restrictions in strings
Myhailo Danylenko <isbear@ukrpost.net>
parents:
0
diff
changeset
|
860 |
value = process_expression (val + 1, &len); |
320e4393785a
Parentheses now have no restrictions in strings
Myhailo Danylenko <isbear@ukrpost.net>
parents:
0
diff
changeset
|
861 |
} |
0 | 862 |
|
863 |
if (!value) { |
|
10
14987412be3b
Use new scr_* functions
Myhailo Danylenko <isbear@ukrpost.net>
parents:
9
diff
changeset
|
864 |
scr_log_print (LPRINT_NORMAL, "let: Evaluation error."); |
0 | 865 |
return; |
866 |
} |
|
867 |
||
868 |
if (value->type == TYPE_INT) { |
|
869 |
value->type = TYPE_STR; |
|
870 |
value->str_value = g_strdup_printf ("%d", value->int_value); |
|
871 |
} |
|
872 |
||
873 |
{ // assign value |
|
874 |
char *varname = g_strndup (arg, namelen); |
|
875 |
||
876 |
if (value->str_value) |
|
877 |
settings_set (SETTINGS_TYPE_OPTION, varname, value->str_value); |
|
878 |
else |
|
879 |
settings_del (SETTINGS_TYPE_OPTION, varname); |
|
880 |
||
881 |
g_free (varname); |
|
882 |
} |
|
883 |
||
884 |
destroy_value (value); |
|
885 |
} |
|
886 |
||
887 |
static void do_if (char *arg) |
|
888 |
{ |
|
1
320e4393785a
Parentheses now have no restrictions in strings
Myhailo Danylenko <isbear@ukrpost.net>
parents:
0
diff
changeset
|
889 |
gsize len = strlen (arg); |
320e4393785a
Parentheses now have no restrictions in strings
Myhailo Danylenko <isbear@ukrpost.net>
parents:
0
diff
changeset
|
890 |
value_t *val = process_expression (arg, &len); |
0 | 891 |
|
892 |
if (!val) { |
|
10
14987412be3b
Use new scr_* functions
Myhailo Danylenko <isbear@ukrpost.net>
parents:
9
diff
changeset
|
893 |
scr_log_print (LPRINT_NORMAL, "if: Evaluation error."); |
0 | 894 |
return; |
895 |
} |
|
896 |
||
897 |
if (val->type == TYPE_UNDEF) { |
|
898 |
val->type = TYPE_INT; |
|
899 |
val->int_value = 0; |
|
900 |
} |
|
901 |
if (val->type == TYPE_STR && check_value_type (val->str_value) == TYPE_INT) { |
|
902 |
val->type = TYPE_INT; |
|
903 |
val->int_value = atoi (val->str_value); |
|
904 |
g_free (val->str_value); |
|
905 |
val->str_value = NULL; |
|
906 |
} |
|
907 |
||
908 |
if (val->type == TYPE_INT) |
|
909 |
ifresult = val->int_value ? TRUE : FALSE; |
|
910 |
else if (val->str_value) |
|
911 |
ifresult = TRUE; |
|
912 |
else |
|
913 |
ifresult = FALSE; |
|
914 |
||
915 |
destroy_value (val); |
|
916 |
} |
|
917 |
||
918 |
static void do_then (char *arg) |
|
919 |
{ |
|
920 |
if (ifresult) |
|
921 |
process_command (arg, TRUE); |
|
922 |
} |
|
923 |
||
924 |
static void do_else (char *arg) |
|
925 |
{ |
|
926 |
if (!ifresult) |
|
927 |
process_command (arg, TRUE); |
|
928 |
} |
|
929 |
||
930 |
static void do_multi (char *arg) |
|
931 |
{ |
|
932 |
char *end; |
|
933 |
char *start = arg; |
|
934 |
||
935 |
for (end = strchr (start, ';'); end; end = strchr (start, ';')) { |
|
936 |
||
937 |
// execute command |
|
938 |
char *command = g_strndup (start, end - start); |
|
939 |
process_command (command, TRUE); |
|
940 |
g_free (command); |
|
941 |
||
942 |
// skip leading spaces |
|
943 |
for (start = end + 1; *start == ' '; ++start); |
|
944 |
} |
|
945 |
||
946 |
if (*start) |
|
947 |
process_command (start, TRUE); |
|
948 |
} |
|
949 |
||
8
2033d1c5d226
New module loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
4
diff
changeset
|
950 |
static void yaubil_init (void) |
0 | 951 |
{ |
13
f4c15ad3cf93
Use new commands interface
Myhailo Danylenko <isbear@ukrpost.net>
parents:
12
diff
changeset
|
952 |
#ifndef HAVE_CMD_ID |
0 | 953 |
cmd_add ("multi", "", COMPL_CMD, COMPL_CMD, do_multi, NULL); |
954 |
cmd_add ("if", "", 0, 0, do_if, NULL); |
|
955 |
cmd_add ("then", "", COMPL_CMD, COMPL_CMD, do_then, NULL); |
|
956 |
cmd_add ("else", "", COMPL_CMD, COMPL_CMD, do_else, NULL); |
|
957 |
cmd_add ("eval", "", 0, 0, do_eval, NULL); |
|
958 |
cmd_add ("let", "", 0, 0, do_let, NULL); |
|
13
f4c15ad3cf93
Use new commands interface
Myhailo Danylenko <isbear@ukrpost.net>
parents:
12
diff
changeset
|
959 |
#else |
f4c15ad3cf93
Use new commands interface
Myhailo Danylenko <isbear@ukrpost.net>
parents:
12
diff
changeset
|
960 |
yaubil_multi_cmid = cmd_add ("multi", "", COMPL_CMD, COMPL_CMD, do_multi, NULL); |
f4c15ad3cf93
Use new commands interface
Myhailo Danylenko <isbear@ukrpost.net>
parents:
12
diff
changeset
|
961 |
yaubil_if_cmid = cmd_add ("if", "", 0, 0, do_if, NULL); |
f4c15ad3cf93
Use new commands interface
Myhailo Danylenko <isbear@ukrpost.net>
parents:
12
diff
changeset
|
962 |
yaubil_then_cmid = cmd_add ("then", "", COMPL_CMD, COMPL_CMD, do_then, NULL); |
f4c15ad3cf93
Use new commands interface
Myhailo Danylenko <isbear@ukrpost.net>
parents:
12
diff
changeset
|
963 |
yaubil_else_cmid = cmd_add ("else", "", COMPL_CMD, COMPL_CMD, do_else, NULL); |
f4c15ad3cf93
Use new commands interface
Myhailo Danylenko <isbear@ukrpost.net>
parents:
12
diff
changeset
|
964 |
yaubil_eval_cmid = cmd_add ("eval", "", 0, 0, do_eval, NULL); |
f4c15ad3cf93
Use new commands interface
Myhailo Danylenko <isbear@ukrpost.net>
parents:
12
diff
changeset
|
965 |
yaubil_let_cmid = cmd_add ("let", "", 0, 0, do_let, NULL); |
f4c15ad3cf93
Use new commands interface
Myhailo Danylenko <isbear@ukrpost.net>
parents:
12
diff
changeset
|
966 |
#ifdef HAVE_CMD_SAFE |
f4c15ad3cf93
Use new commands interface
Myhailo Danylenko <isbear@ukrpost.net>
parents:
12
diff
changeset
|
967 |
yaubil_multi_set_safe = cmd_set_safe ("multi", TRUE); |
f4c15ad3cf93
Use new commands interface
Myhailo Danylenko <isbear@ukrpost.net>
parents:
12
diff
changeset
|
968 |
yaubil_if_set_safe = cmd_set_safe ("if", TRUE); |
f4c15ad3cf93
Use new commands interface
Myhailo Danylenko <isbear@ukrpost.net>
parents:
12
diff
changeset
|
969 |
yaubil_then_set_safe = cmd_set_safe ("then", TRUE); |
f4c15ad3cf93
Use new commands interface
Myhailo Danylenko <isbear@ukrpost.net>
parents:
12
diff
changeset
|
970 |
yaubil_else_set_safe = cmd_set_safe ("else", TRUE); |
f4c15ad3cf93
Use new commands interface
Myhailo Danylenko <isbear@ukrpost.net>
parents:
12
diff
changeset
|
971 |
yaubil_eval_set_safe = cmd_set_safe ("eval", TRUE); |
f4c15ad3cf93
Use new commands interface
Myhailo Danylenko <isbear@ukrpost.net>
parents:
12
diff
changeset
|
972 |
yaubil_let_set_safe = cmd_set_safe ("let", TRUE); |
f4c15ad3cf93
Use new commands interface
Myhailo Danylenko <isbear@ukrpost.net>
parents:
12
diff
changeset
|
973 |
#endif |
f4c15ad3cf93
Use new commands interface
Myhailo Danylenko <isbear@ukrpost.net>
parents:
12
diff
changeset
|
974 |
#endif |
0 | 975 |
} |
976 |
||
8
2033d1c5d226
New module loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
4
diff
changeset
|
977 |
static void yaubil_uninit (void) |
0 | 978 |
{ |
13
f4c15ad3cf93
Use new commands interface
Myhailo Danylenko <isbear@ukrpost.net>
parents:
12
diff
changeset
|
979 |
#ifndef HAVE_CMD_ID |
0 | 980 |
cmd_del ("multi"); |
981 |
cmd_del ("if"); |
|
982 |
cmd_del ("then"); |
|
983 |
cmd_del ("else"); |
|
984 |
cmd_del ("eval"); |
|
985 |
cmd_del ("let"); |
|
13
f4c15ad3cf93
Use new commands interface
Myhailo Danylenko <isbear@ukrpost.net>
parents:
12
diff
changeset
|
986 |
#else |
f4c15ad3cf93
Use new commands interface
Myhailo Danylenko <isbear@ukrpost.net>
parents:
12
diff
changeset
|
987 |
if (yaubil_multi_cmid) |
f4c15ad3cf93
Use new commands interface
Myhailo Danylenko <isbear@ukrpost.net>
parents:
12
diff
changeset
|
988 |
cmd_del (yaubil_multi_cmid); |
f4c15ad3cf93
Use new commands interface
Myhailo Danylenko <isbear@ukrpost.net>
parents:
12
diff
changeset
|
989 |
if (yaubil_if_cmid) |
f4c15ad3cf93
Use new commands interface
Myhailo Danylenko <isbear@ukrpost.net>
parents:
12
diff
changeset
|
990 |
cmd_del (yaubil_if_cmid); |
f4c15ad3cf93
Use new commands interface
Myhailo Danylenko <isbear@ukrpost.net>
parents:
12
diff
changeset
|
991 |
if (yaubil_then_cmid) |
f4c15ad3cf93
Use new commands interface
Myhailo Danylenko <isbear@ukrpost.net>
parents:
12
diff
changeset
|
992 |
cmd_del (yaubil_then_cmid); |
f4c15ad3cf93
Use new commands interface
Myhailo Danylenko <isbear@ukrpost.net>
parents:
12
diff
changeset
|
993 |
if (yaubil_else_cmid) |
f4c15ad3cf93
Use new commands interface
Myhailo Danylenko <isbear@ukrpost.net>
parents:
12
diff
changeset
|
994 |
cmd_del (yaubil_else_cmid); |
f4c15ad3cf93
Use new commands interface
Myhailo Danylenko <isbear@ukrpost.net>
parents:
12
diff
changeset
|
995 |
if (yaubil_eval_cmid) |
f4c15ad3cf93
Use new commands interface
Myhailo Danylenko <isbear@ukrpost.net>
parents:
12
diff
changeset
|
996 |
cmd_del (yaubil_eval_cmid); |
f4c15ad3cf93
Use new commands interface
Myhailo Danylenko <isbear@ukrpost.net>
parents:
12
diff
changeset
|
997 |
if (yaubil_let_cmid) |
f4c15ad3cf93
Use new commands interface
Myhailo Danylenko <isbear@ukrpost.net>
parents:
12
diff
changeset
|
998 |
cmd_del (yaubil_let_cmid); |
f4c15ad3cf93
Use new commands interface
Myhailo Danylenko <isbear@ukrpost.net>
parents:
12
diff
changeset
|
999 |
#ifdef HAVE_CMD_SAFE |
f4c15ad3cf93
Use new commands interface
Myhailo Danylenko <isbear@ukrpost.net>
parents:
12
diff
changeset
|
1000 |
if (yaubil_multi_set_safe) |
f4c15ad3cf93
Use new commands interface
Myhailo Danylenko <isbear@ukrpost.net>
parents:
12
diff
changeset
|
1001 |
cmd_set_safe ("multi", FALSE); |
f4c15ad3cf93
Use new commands interface
Myhailo Danylenko <isbear@ukrpost.net>
parents:
12
diff
changeset
|
1002 |
if (yaubil_if_set_safe) |
f4c15ad3cf93
Use new commands interface
Myhailo Danylenko <isbear@ukrpost.net>
parents:
12
diff
changeset
|
1003 |
cmd_set_safe ("if", FALSE); |
f4c15ad3cf93
Use new commands interface
Myhailo Danylenko <isbear@ukrpost.net>
parents:
12
diff
changeset
|
1004 |
if (yaubil_then_set_safe) |
f4c15ad3cf93
Use new commands interface
Myhailo Danylenko <isbear@ukrpost.net>
parents:
12
diff
changeset
|
1005 |
cmd_set_safe ("then", FALSE); |
f4c15ad3cf93
Use new commands interface
Myhailo Danylenko <isbear@ukrpost.net>
parents:
12
diff
changeset
|
1006 |
if (yaubil_else_set_safe) |
f4c15ad3cf93
Use new commands interface
Myhailo Danylenko <isbear@ukrpost.net>
parents:
12
diff
changeset
|
1007 |
cmd_set_safe ("else", FALSE); |
f4c15ad3cf93
Use new commands interface
Myhailo Danylenko <isbear@ukrpost.net>
parents:
12
diff
changeset
|
1008 |
if (yaubil_eval_set_safe) |
f4c15ad3cf93
Use new commands interface
Myhailo Danylenko <isbear@ukrpost.net>
parents:
12
diff
changeset
|
1009 |
cmd_set_safe ("eval", FALSE); |
f4c15ad3cf93
Use new commands interface
Myhailo Danylenko <isbear@ukrpost.net>
parents:
12
diff
changeset
|
1010 |
if (yaubil_let_set_safe) |
f4c15ad3cf93
Use new commands interface
Myhailo Danylenko <isbear@ukrpost.net>
parents:
12
diff
changeset
|
1011 |
cmd_set_safe ("let", FALSE); |
f4c15ad3cf93
Use new commands interface
Myhailo Danylenko <isbear@ukrpost.net>
parents:
12
diff
changeset
|
1012 |
#endif |
f4c15ad3cf93
Use new commands interface
Myhailo Danylenko <isbear@ukrpost.net>
parents:
12
diff
changeset
|
1013 |
#endif |
0 | 1014 |
} |
1015 |
||
1016 |
/* The End */ |