1 /*************************************************************************
2 * Copyright (C) 2023 Francesco Palumbo <phranz@subfc.net>, Naples (Italy)
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 *************************************************************************/
24 #include "tokenizer.h"
25 #include "sourcedriver.h"
27 #include "evaluator.h"
30 extern vec_strline_t
* strace
;
31 extern unsigned long flags
;
32 extern unsigned long options
;
34 extern map_widwidget_t
* widgets
;
36 extern map_widloci_t
* widlines
;
37 extern map_widloci_t
* widareas
;
38 extern map_widarcssets_t
* widarcssets
;
39 extern map_widarcssets_t
* widarcsareas
;
40 extern map_widloci_t
* widloci
;
41 extern map_widloci_t
* widpixels
;
42 extern map_widnamedpoints_t
* widnamedpoints
;
44 static cmd
valid_subphrase(element E
, cmd c
, vec_token_t
* v
) {
45 if (!it
|| (E
!= E_ALL
&& (element
)it
->etype
!= E
))
48 return ((int)v
->count
- (int)(cargs(c
))) >= 0 ? c
: CMD_NONE
;
51 static int load_subject(vec_token_t
* v
) {
56 if (!v
->first(v
, &ft
))
59 wid
= strtoul(ft
->data
, NULL
, 10);
60 if (errno
!= EINVAL
&& errno
!= ERANGE
&& wid
) {
61 if (!widgets
->get(widgets
, wid
, &w
))
62 err(ft
->source
, ft
->lineno
, "error, unknown window id '%lu'.\n", wid
);
64 debug("subject loaded: %lu\n", it
->wid
);
72 size_t exec(vec_token_t
* v
) {
80 if (o
->type
== T_BLOCK
) {
82 o
->block
->data
->first(o
->block
->data
, &t
);
83 err(t
->source
, t
->lineno
, "error, cannot execute a block as a command!\n");
95 err(o
->source
, o
->lineno
, "error, no implied subject or unknown command '%s'.\n", o
->data
);
99 c
= cidbe(it
->etype
, o
->data
);
100 debug("cidbe for e: '%d' data: '%s', c: %d\n", it
->etype
, o
->data
, c
);
103 debug("from token '%s', command: %d\n", o
->data
, c
);
105 // generic widget commands
108 if(!valid_subphrase(E_ALL
, c
, v
))
113 if(!valid_subphrase(E_ALL
, c
, v
))
118 if(!valid_subphrase(E_ALL
, c
, v
))
123 if(!valid_subphrase(E_ALL
, c
, v
))
128 if(!valid_subphrase(E_ALL
, c
, v
))
135 if (widlines
&& widlines
->get(widlines
, it
->wid
, &l
)) {
136 widlines
->remove(widlines
, it
->wid
);
140 if (widarcssets
&& widarcssets
->get(widarcssets
, it
->wid
, &a
)) {
141 widarcssets
->remove(widarcssets
, it
->wid
);
144 if (widarcsareas
&& widarcsareas
->get(widarcsareas
, it
->wid
, &a
)) {
145 widarcsareas
->remove(widarcsareas
, it
->wid
);
148 if (widareas
&& widareas
->get(widareas
, it
->wid
, &l
)) {
149 widareas
->remove(widareas
, it
->wid
);
152 if (widloci
&& widloci
->get(widloci
, it
->wid
, &l
)) {
153 widloci
->remove(widloci
, it
->wid
);
156 if (widpixels
&& widpixels
->get(widpixels
, it
->wid
, &l
)) {
157 widpixels
->remove(widpixels
, it
->wid
);
161 if (widnamedpoints
&& widnamedpoints
->get(widnamedpoints
, it
->wid
, &n
)) {
162 widnamedpoints
->remove(widnamedpoints
, it
->wid
);
170 assert_notblock(b
, "draw operation", o
->data
);
180 map_widloci_t
** set
= NULL
;
181 void (*op
)(widget_t
*, char*, vec_int_t
*) = NULL
;
183 case 'l': set
= &widlines
; op
= addlines
; break;
184 case 'p': set
= &widloci
; op
= addpoints
; break;
185 case 'x': set
= &widpixels
; op
= addpixels
; break;
187 case 'P': set
= &widareas
; op
= addarea
; break;
191 if (*set
&& (*set
)->get(*set
, it
->wid
, &l
)) {
192 (*set
)->remove(*set
, it
->wid
);
202 v
->pop_back(v
, &col
);
203 assert_notblock(col
, "color", o
->data
);
205 vec_int_t
* ps
= alloc(vec_int_t
);
208 assert_notblock(b
, "coord", o
->data
);
211 if (!v
->pop_back(v
, &b
))
212 err(sn
, ln
, "error, missing coord.\n");
213 assert_notblock(b
, "coord", o
->data
);
219 op(it
, col
->data
, ps
);
227 map_widarcssets_t
** set
= (c
== 'a' ? &widarcssets
: &widarcsareas
);
229 if (*set
&& (*set
)->get(*set
, it
->wid
, &a
)) {
230 (*set
)->remove(*set
, it
->wid
);
240 v
->pop_back(v
, &col
);
241 assert_notblock(col
, "color", o
->data
);
242 vec_int_t
* arcs
= alloc(vec_int_t
);
247 assert_notblock(b
, "coord", o
->data
);
251 assert_notblock(b
, "coord", o
->data
);
255 assert_notblock(b
, "width", o
->data
);
259 assert_notblock(b
, "height", o
->data
);
263 assert_notblock(b
, "angle", o
->data
);
264 int angle1
= tolong(b
);
267 assert_notblock(b
, "angle", o
->data
);
268 int angle2
= tolong(b
);
273 arcs
->push(arcs
, ww
);
274 arcs
->push(arcs
, hh
);
275 arcs
->push(arcs
, angle1
);
276 arcs
->push(arcs
, angle2
);
278 addarcs(it
, type
== 'A', col
->data
, arcs
);
286 if (widnamedpoints
&& widnamedpoints
->get(widnamedpoints
, it
->wid
, &l
)) {
287 widnamedpoints
->remove(widnamedpoints
, it
->wid
);
298 v
->pop_back(v
, &col
);
299 assert_notblock(col
, "color", o
->data
);
301 v
->pop_back(v
, &name
);
302 assert_notblock(name
, "name", o
->data
);
305 assert_notblock(b
, "coord", o
->data
);
309 assert_notblock(b
, "coord", o
->data
);
312 addnamedpoint(it
, col
->data
, name
->data
, x
, y
);
318 err(sn
, ln
, "error, unknown draw operation '%c'.\n", type
);
323 if(!valid_subphrase(E_ALL
, c
, v
))
328 if(!valid_subphrase(E_ALL
, c
, v
))
333 if(!valid_subphrase(E_ALL
, c
, v
))
338 if(!valid_subphrase(E_ALL
, c
, v
))
343 if(!valid_subphrase(E_ALL
, c
, v
))
348 if(!valid_subphrase(E_ALL
, c
, v
))
350 trigger(it
->wid
, SIG_CLICKED
);
353 if(!valid_subphrase(E_ALL
, c
, v
))
358 if(!valid_subphrase(E_ALL
, c
, v
))
363 if(!valid_subphrase(E_ALL
, c
, v
))
368 if(!valid_subphrase(E_ALL
, c
, v
))
373 if(!valid_subphrase(E_ALL
, c
, v
))
378 if(!valid_subphrase(E_ALL
, c
, v
))
383 if(!valid_subphrase(E_ALL
, c
, v
))
387 case CMD_FILLNOLIMIT
:
388 if(!valid_subphrase(E_ALL
, c
, v
))
393 if(!valid_subphrase(E_ALL
, c
, v
))
397 case CMD_FILLRIGHTNOLIMIT
:
398 if(!valid_subphrase(E_ALL
, c
, v
))
403 if(!valid_subphrase(E_ALL
, c
, v
))
407 case CMD_FILLBOTTOMNOLIMIT
:
408 if(!valid_subphrase(E_ALL
, c
, v
))
413 if(!valid_subphrase(E_ALL
, c
, v
))
418 if(!valid_subphrase(E_ALL
, c
, v
))
421 if (it
->flags
& F_VISIBLE
) {
427 if(!valid_subphrase(E_ALL
, c
, v
))
430 if (it
->flags
& F_VISIBLE
) {
436 if(!valid_subphrase(E_ALL
, c
, v
))
441 if(!valid_subphrase(E_ALL
, c
, v
))
445 settext(it
, b
->data
);
449 if(!valid_subphrase(E_ALL
, c
, v
))
453 addtext(it
, b
->data
);
457 if(!valid_subphrase(E_ALL
, c
, v
))
460 assert_notblock(b
, "first", o
->data
);
461 token_t
* val
= alloc(token_t
);
463 val
->lineno
= b
->lineno
;
464 val
->source
= b
->source
;
465 val
->data
= salloc(it
->data
);
466 define(b
, val
, NULL
, NULL
);
471 if(!valid_subphrase(E_ALL
, c
, v
))
475 entitle(it
, b
->data
);
479 if(!valid_subphrase(E_ALL
, c
, v
))
487 if(!valid_subphrase(E_ALL
, c
, v
))
490 assert_notblock(b
, "first", o
->data
);
494 assert_notblock(b
, "second", o
->data
);
501 if(!valid_subphrase(E_ALL
, c
, v
))
504 assert_notblock(b
, "first", o
->data
);
508 assert_notblock(b
, "second", o
->data
);
514 case CMD_MOVEALIGN
: {
515 if(!valid_subphrase(E_ALL
, c
, v
))
518 assert_notblock(b
, "first", o
->data
);
519 unsigned long wid
= tolong(b
);
521 if (!wid
|| !widgets
->get(widgets
, wid
, &r
)) {
522 err(b
->source
, b
->lineno
, "error, no widget with id '%lu'.\n", wid
);
527 assert_notblock(b
, "second", o
->data
);
528 movealigns(it
, r
, b
->data
);
534 if(!valid_subphrase(E_ALL
, c
, v
))
539 if(!valid_subphrase(E_ALL
, c
, v
))
544 if(!valid_subphrase(E_ALL
, c
, v
))
549 if(!valid_subphrase(E_INPUT
, c
, v
))
554 if(!valid_subphrase(E_INPUT
, c
, v
))
559 if(!valid_subphrase(E_INPUT
, c
, v
))
564 if(!valid_subphrase(E_INPUT
, c
, v
))
569 if(!valid_subphrase(E_PAGE
, c
, v
))
574 if(!valid_subphrase(E_PAGE
, c
, v
))
578 stylesubs(it
, b
->data
);
582 if(!valid_subphrase(E_PAGE
, c
, v
))
587 if(!valid_subphrase(E_PAGE
, c
, v
))
592 if(!valid_subphrase(E_PAGE
, c
, v
))
597 assert_notblock(fw
, "first", o
->data
);
599 assert_notblock(sw
, "second", o
->data
);
600 swap(it
, fw
->data
, sw
->data
);
605 if(!valid_subphrase(E_PAGE
, c
, v
))
610 if(!valid_subphrase(E_PAGE
, c
, v
))
615 if(!valid_subphrase(E_PAGE
, c
, v
))
618 assert_notblock(b
, "first", o
->data
);
623 if(!valid_subphrase(E_PAGE
, c
, v
))
626 assert_notblock(b
, "first", o
->data
);
627 fitembed(it
, b
->data
);
631 if(!valid_subphrase(E_PAGE
, c
, v
))
634 assert_notblock(b
, "first", o
->data
);
639 if(!valid_subphrase(E_PAGE
, c
, v
))
642 assert_notblock(b
, "first", o
->data
);
643 fituntie(it
, b
->data
);
647 if(!valid_subphrase(E_CHECKBOX
, c
, v
))
652 if(!valid_subphrase(E_CHECKBOX
, c
, v
))
657 err(o
->source
, o
->lineno
, "error, unknown command '%s'\n", o
->data
);
664 err(sn
, ln
, "error, invalid number of parameters for command '%s'\n", o
->data
);