21 #include <ccscript-config.h>
22 #include <ucommon/ucommon.h>
23 #include <ucommon/export.h>
38 if(stack[frame].index < 2) {
39 stack[frame].index = 0;
43 stack[frame].index -= 2;
51 const char *tuples = getContent(line->
argv[0]);
56 while(line->
argv[index]) {
60 sym = getVar(line->
argv[index]);
63 return error(
"symbol not found");
66 return error(
"symbol not writable");
69 String::set(sym->
data, sym->
size + 1,
"");
85 unsigned index = stack[frame].index;
88 sym = getVar(line->
argv[0]);
91 return error(
"symbol not found");
94 return error(
"symbol not writable");
98 if(cp && (*cp ==
'%' || *cp ==
'&')) {
103 index = atoi(skip->
data);
105 String::set(skip->
data, 2,
"0");
108 else if(NULL != (cp = getContent(cp))) {
117 stack[frame].index = 0;
123 stack[frame].index = ++index;
131 if(isConditional(0)) {
153 while(stack[frame].line && stack[frame].line->
loop > line->
loop)
158 if(isConditional(0)) {
164 return scrOtherwise();
179 while(stack[frame].line && stack[frame].line->
loop > line->
loop)
221 getParams(line->
sub, line);
225 stack[frame].scope = line->
sub;
227 startScript(line->
sub);
229 mask = stack[frame].resmask |= line->
sub->
resmask;
230 if(mask != stack[frame].resmask) {
231 stack[frame].resmask = mask;
243 while(NULL != (line = stack[frame].line)) {
263 if(isConditional(0)) {
269 while(NULL != (line = stack[frame].line)) {
284 if(isConditional(0)) {
306 while(stack[frame].line && stack[frame].line->
loop >= line->
loop)
312 while(stack[frame].line && stack[frame].line->
loop >= line->
loop)
320 --stack[frame].index;
339 const char *cp = line->
argv[0];
341 if((line->
argc == 1) && eq(cp,
"none"))
342 stack[frame].ignore = NULL;
344 stack[frame].ignore = line;
351 if(!isConditional(0))
361 stack[frame].line = NULL;
367 unsigned mask = stack[frame].resmask;
369 setStack(stack[frame].scr);
370 if(mask == stack[frame].resmask)
381 unsigned mask = stack[frame].resmask;
383 while(!scr && index < line->argc) {
384 cp = line->
argv[index++];
386 if(scriptEvent(++cp))
393 return error(
"label not found");
398 if(mask == stack[frame].resmask)
405 unsigned index = stack[frame].index;
409 unsigned mask = stack[frame].resmask;
412 while(ev == NULL && scr == NULL && index < line->argc) {
413 cp = line->
argv[index++];
416 if(!scr && image->shared.get())
420 ev = scriptMethod(cp);
424 if(!stack[frame].index)
425 return error(
"label not found");
427 stack[frame].index = 0;
432 stack[frame].index = index;
437 stack[frame].base = frame;
438 if(mask == stack[frame].resmask)
442 stack[frame].line = ev->
first;
443 stack[frame].index = 0;
451 unsigned mask = stack[frame].resmask;
455 if(mask == stack[frame].resmask)
463 int result = 0, value;
465 stack[frame].index = 0;
466 result = atoi(getValue());
468 while(NULL != (op = getValue())) {
471 result += atoi(getValue());
474 result -= atoi(getValue());
477 result *= atoi(getValue());
480 value = atoi(getValue());
482 return error(
"div by zero");
486 value = atoi(getValue());
488 return error(
"div by zero");
500 stack[frame].index = --result;
507 const char *cp = stack[frame].line->
argv[0];
516 const char *id, *cp, *op, *aop;
517 double result, value;
522 stack[frame].index = 0;
524 cp = getKeyword(
"decimals");
526 exdecimals = atoi(cp);
530 result = atof(getValue());
532 while(NULL != (op = getValue())) {
535 result += atof(getValue());
538 result -= atof(getValue());
541 result *= atof(getValue());
544 value = atof(getValue());
546 return error(
"div by zero");
551 lvalue = atol(getValue());
553 return error(
"div by zero");
554 result = (long)result % lvalue;
564 else if(eq(aop,
"#="))
565 value = (long)value % (
long)result;
566 else if(eq(aop,
"-="))
568 else if(eq(aop,
"*="))
570 else if(eq(aop,
"/=") && result)
572 else if(eq(aop,
"?=") || eq(aop,
":="))
575 stack[frame].index = 0;
578 cvt[2] =
'0' + exdecimals;
581 snprintf(buf,
sizeof(buf), cvt, value);
584 return error(
"invalid symbol");
596 while(index < line->argc) {
597 id = line->
argv[index++];
599 if(!getVar(++
id, getContent(line->
argv[index++])))
600 return error(
"invalid symbol");
604 return error(
"invalid symbol");
617 while(index < line->argc) {
618 id = line->
argv[index++];
620 if(!setConst(++
id, getContent(line->
argv[index++])))
621 return error(
"invalid constant");
637 while(index < line->argc) {
639 String::add(msg, 65,
" ");
642 cp = line->
argv[index++];
645 String::add(msg, 65, getContent(cp));
657 while(index < line->argc) {
658 id = line->
argv[index++];
661 if(!sym || !sym->
size)
662 return error(
"symbol not found");
678 sym = getVar(line->
argv[0]);
681 return error(
"symbol not found");
684 return error(
"symbol not writable");
686 while(index < line->argc) {
687 cp = getContent(line->
argv[index++]);
688 String::add(sym->
data, sym->
size + 1, cp);
700 char quote[2] = {0,0};
703 sym = getVar(line->
argv[0]);
706 return error(
"symbol not found");
709 return error(
"symbol not writable");
711 while(index < line->argc) {
712 cp = line->
argv[index++];
715 String::add(sym->
data, sym->
size + 1,
",");
717 String::add(sym->
data, sym->
size + 1, ++cp);
718 String::add(sym->
data, sym->
size + 1,
"=");
719 cp = getContent(line->
argv[index++]);
728 String::add(sym->
data, sym->
size + 1,
",");
730 if(!quote[0] && strchr(cp,
',')) {
731 if(*cp !=
'\'' && *cp !=
'\"')
735 if(!quote[0] && *cp ==
'\'')
738 String::add(sym->
data, sym->
size + 1, quote);
739 String::add(sym->
data, sym->
size + 1, cp);
743 String::add(sym->
data, sym->
size + 1, quote);
756 const char *key = NULL, *value;
759 return error(
"invalid symbol id");
762 return error(
"symbol not writable");
766 value = line->
argv[2];
769 value = line->
argv[1];
772 size = strlen(key) + 1;
774 if(*value !=
'\"' && *value !=
'\'') {
778 size += strlen(value);
780 size = strlen(line->
argv[1]) + 3;
782 size += strlen(line->
argv[2]);
784 if(strlen(sym->
data) + size > sym->
size)
785 return error(
"symbol too small");
788 String::add(sym->
data, sym->
size + 1,
",");
790 size = strlen(sym->
data);
792 snprintf(sym->
data + size, sym->
size + 1 - size,
"%s='%s'", key, value);
794 snprintf(sym->
data + size, sym->
size + 1 - size,
"%s=%s", key, value);
796 snprintf(sym->
data + size, sym->
size + 1 - size,
"'%s'", value);
798 String::set(sym->
data + size, sym->
size + 1, value);
811 return error(
"invalid symbol id");
814 return error(
"symbol not writable");
817 while(index < line->argc) {
818 cp = getContent(line->
argv[index++]);
819 String::add(sym->
data, sym->
size + 1, cp);
static const char * get(const char *list, unsigned offset)
static void copy(const char *list, char *item, unsigned size)
char * data
content of symbol
Basic compiled statement.
Contains instance of a runtime symbol.
static unsigned count(const char *list)
static unsigned decimals
default decimal places
static keyword_t * find(const char *id)
Find a keyword from internal command table.
bool(Script::interp::* method_t)(void)
A type for runtime script method invokation.
An event block for a script.
unsigned size
size of data buffer or 0 if const