Merge pull request #6372 from gemu2015/scripter-update

scripter update
This commit is contained in:
Theo Arends 2019-09-08 12:38:27 +02:00 committed by GitHub
commit e0b07391c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2031,6 +2031,7 @@ void Replace_Cmd_Vars(char *srcbuf,char *dstbuf,uint16_t dstsize) {
char *cp; char *cp;
uint16_t count; uint16_t count;
uint8_t vtype; uint8_t vtype;
uint8_t dprec=glob_script_mem.script_dprec;
float fvar; float fvar;
cp=srcbuf; cp=srcbuf;
struct T_INDEX ind; struct T_INDEX ind;
@ -2041,13 +2042,16 @@ void Replace_Cmd_Vars(char *srcbuf,char *dstbuf,uint16_t dstsize) {
if (*cp=='%') { if (*cp=='%') {
dstbuf[count]=*cp++; dstbuf[count]=*cp++;
} else { } else {
//char *scp=cp; if (isdigit(*cp)) {
dprec=*cp&0xf;
cp++;
}
cp=isvar(cp,&vtype,&ind,&fvar,string,0); cp=isvar(cp,&vtype,&ind,&fvar,string,0);
if (vtype!=VAR_NV) { if (vtype!=VAR_NV) {
// found variable as result // found variable as result
if (vtype==NUM_RES || (vtype&STYPE)==0) { if (vtype==NUM_RES || (vtype&STYPE)==0) {
// numeric result // numeric result
dtostrfd(fvar,glob_script_mem.script_dprec,string); dtostrfd(fvar,dprec,string);
} else { } else {
// string result // string result
} }
@ -2650,7 +2654,7 @@ int16_t Run_Scripter(const char *type, int8_t tlen, char *js) {
switch (lastop) { switch (lastop) {
case OPER_EQU: case OPER_EQU:
if (glob_script_mem.var_not_found) { if (glob_script_mem.var_not_found) {
if (!js) toLog("var not found\n"); if (!js) toLogEOL("var not found: ",lp);
goto next_line; goto next_line;
} }
*dfvar=fvar; *dfvar=fvar;
@ -3587,23 +3591,21 @@ void ScriptWebShow(void) {
if (!*lp || *lp=='#' || *lp=='>') { if (!*lp || *lp=='#' || *lp=='>') {
break; break;
} }
if (*lp!=';') {
// send this line to web // send this line to web
memcpy(line,lp,sizeof(line)); memcpy(line,lp,sizeof(line));
line[sizeof(line)-1]=0; line[sizeof(line)-1]=0;
char *cp=line; char *cp=line;
for (uint32_t i=0; i<sizeof(line); i++) { for (uint32_t i=0; i<sizeof(line); i++) {
if (!*cp || *cp=='\n' || *cp=='\r') { if (!*cp || *cp=='\n' || *cp=='\r') {
*cp=0; *cp=0;
break; break;
}
cp++;
} }
cp++; Replace_Cmd_Vars(line,tmp,sizeof(tmp));
WSContentSend_PD(PSTR("{s}%s{e}"),tmp);
} }
Replace_Cmd_Vars(line,tmp,sizeof(tmp));
WSContentSend_PD(PSTR("{s}%s{e}"),tmp);
next_line:
if (*lp==SCRIPT_EOL) { if (*lp==SCRIPT_EOL) {
lp++; lp++;
} else { } else {
@ -3630,23 +3632,21 @@ void ScriptJsonAppend(void) {
if (!*lp || *lp=='#' || *lp=='>') { if (!*lp || *lp=='#' || *lp=='>') {
break; break;
} }
if (*lp!=';') {
// send this line to mqtt // send this line to mqtt
memcpy(line,lp,sizeof(line)); memcpy(line,lp,sizeof(line));
line[sizeof(line)-1]=0; line[sizeof(line)-1]=0;
char *cp=line; char *cp=line;
for (uint32_t i=0; i<sizeof(line); i++) { for (uint32_t i=0; i<sizeof(line); i++) {
if (!*cp || *cp=='\n' || *cp=='\r') { if (!*cp || *cp=='\n' || *cp=='\r') {
*cp=0; *cp=0;
break; break;
}
cp++;
} }
cp++; Replace_Cmd_Vars(line,tmp,sizeof(tmp));
ResponseAppend_P(PSTR("%s"),tmp);
} }
Replace_Cmd_Vars(line,tmp,sizeof(tmp));
ResponseAppend_P(PSTR("%s"),tmp);
next_line:
if (*lp==SCRIPT_EOL) { if (*lp==SCRIPT_EOL) {
lp++; lp++;
} else { } else {