From c39220d39c4f484a3fa6d60a56b9f6de522df243 Mon Sep 17 00:00:00 2001 From: Brad Arant Date: Mon, 18 Nov 2024 10:19:39 -0800 Subject: [PATCH 1/8] improved syntax checking on expr. Laid foundation for expr function. --- Operand.cpp | 15 ++++++++++++--- tests/testexpr.jet | 6 ++++++ tests/testwhile.jet | 4 ++-- 3 files changed, 20 insertions(+), 5 deletions(-) create mode 100755 tests/testexpr.jet diff --git a/Operand.cpp b/Operand.cpp index aee75f0..f24fb93 100644 --- a/Operand.cpp +++ b/Operand.cpp @@ -53,7 +53,16 @@ namespace jet { } else throw coreutils::Exception("Expecting ) at end of LEFT expression."); } else if(in.ifNextIgnoreCase("EXPR")) { - + if(!in.ifNext("(")) + throw coreutils::Exception("Expecting ( for LEFT parameters."); + Operand parm1(in, global, lvariables); + if(in.ifNext(")")) { + Operand op(in, global, lvariables); + string = op.string; + isNumber = op.isNumber; + boolean = op.boolean; + } else + throw coreutils::Exception("Expecting ) at end of EXPR expression."); } else if(in.ifNextIgnoreCase("RIGHT")) { } else if(in.ifNextIgnoreCase("TRIM")) { @@ -90,7 +99,8 @@ namespace jet { string = in.getTokenExclude("'"); in.ifNext("'"); isNumber = false; - } + } else + throw coreutils::Exception("operand is not valid."); in.skipWhitespace(); @@ -284,7 +294,6 @@ namespace jet { throw coreutils::Exception("operand is not a number."); } else return; - } } diff --git a/tests/testexpr.jet b/tests/testexpr.jet new file mode 100755 index 0000000..220ae99 --- /dev/null +++ b/tests/testexpr.jet @@ -0,0 +1,6 @@ +#!../jet-2.0 + + + +$[test2] + diff --git a/tests/testwhile.jet b/tests/testwhile.jet index a3c3628..95b0e3a 100755 --- a/tests/testwhile.jet +++ b/tests/testwhile.jet @@ -1,8 +1,8 @@ #!../jet-2.0 - + -->$[ix]<-- - + From d3b8ab68e6f2567223510793e55b29ba1961da7d Mon Sep 17 00:00:00 2001 From: Brad Arant Date: Mon, 18 Nov 2024 11:37:30 -0800 Subject: [PATCH 2/8] fixed system tag. --- __system.cpp | 26 +++++++++----------------- tests/testcall.jet | 8 ++++++++ tests/testsystem.jet | 8 ++++++++ 3 files changed, 25 insertions(+), 17 deletions(-) create mode 100755 tests/testcall.jet create mode 100755 tests/testsystem.jet diff --git a/__system.cpp b/__system.cpp index 626d2e6..85435be 100644 --- a/__system.cpp +++ b/__system.cpp @@ -11,25 +11,16 @@ namespace jet { __system::__system(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent) : Tag(in, parentOut, global, parent) { if(hasContainer) throw coreutils::Exception("system tag cannot have a container."); - if(!variableDefined(coreutils::ZString("pgm"))) - throw coreutils::Exception("pgm keyword must be specified."); - argv[0] = variables["pgm"].c_str(); // TODO: Need to peel off the program name only and pass as argv[0]. - for(ix = 1; ix <= 50; ++ix) { - coreutils::MString arg("arg"); - arg << ix; - if(variableDefined(arg)) - argv[ix] = variables[arg].c_str(); - else - break; - } - argv[ix] == NULL; + if(!variableDefined(coreutils::ZString("cmd"))) + throw coreutils::Exception("cmd keyword must be specified."); pipe(fdo); pid = fork(); if(pid == 0) { close(fdo[0]); dup2(fdo[1], 1); if(variableDefined("input")) { - coreutils::ZString input(variables[variables["input"]]); + resolveKeyword("input"); + coreutils::ZString input(variables["input"]); pipe(fdi); if(fork() == 0) { close(fdi[0]); @@ -37,12 +28,11 @@ namespace jet { close(fdi[1]); exit(0); } - close(fdi[0]); + close(fdi[1]); dup2(fdi[0], 0); } - rc = execve(variables["pgm"].c_str(), argv, NULL); + rc = system(variables["cmd"].c_str()); close(fdo[1]); - std::cout << "rc: " << rc << std::endl; exit(rc); } close(fdo[1]); @@ -51,7 +41,9 @@ namespace jet { else out.read(fdo[0]); waitpid(pid, &status, 0); - std::cout << "status: " << status << std::endl; + if(variableDefined("status")) + resolveKeyword("status"); + global.variables[variables["status"]] = (status >> 8 & 255); } } diff --git a/tests/testcall.jet b/tests/testcall.jet new file mode 100755 index 0000000..c993031 --- /dev/null +++ b/tests/testcall.jet @@ -0,0 +1,8 @@ +#!../jet-2.0 + + + +test1=$[test1] +name1=#[localname] +status=$[stat] + diff --git a/tests/testsystem.jet b/tests/testsystem.jet new file mode 100755 index 0000000..8de0704 --- /dev/null +++ b/tests/testsystem.jet @@ -0,0 +1,8 @@ +#!../jet-2.0 + + + +test1=$[test1] +name1=#[localname] +status=$[stat] + From 5a7f7f2d18d1cb2e79b573fccb297e0dd22caaf5 Mon Sep 17 00:00:00 2001 From: Brad Arant Date: Mon, 18 Nov 2024 12:44:41 -0800 Subject: [PATCH 3/8] fixed up call tag. Should be complete. --- Global.cpp | 2 +- Global.h | 5 +++-- __call.cpp | 15 ++++++++------- jet-2.0.cpp | 4 ++-- tests/testcall.jet | 4 ++-- 5 files changed, 16 insertions(+), 14 deletions(-) diff --git a/Global.cpp b/Global.cpp index 05fbc56..49e6847 100644 --- a/Global.cpp +++ b/Global.cpp @@ -7,7 +7,7 @@ namespace jet { - Global::Global() { + Global::Global(char **envp) : envp(envp) { } diff --git a/Global.h b/Global.h index 9a055e3..58a4ffe 100644 --- a/Global.h +++ b/Global.h @@ -11,7 +11,7 @@ namespace jet { class Global { public: - Global(); + Global(char **envp); virtual ~Global(); void dump(); @@ -30,7 +30,8 @@ namespace jet { std::map sessions; std::map headers; std::map tags; - coreutils::MString lastConverted; + coreutils::MString lastConverted; + char **envp; }; diff --git a/__call.cpp b/__call.cpp index f3e8b5d..5772756 100644 --- a/__call.cpp +++ b/__call.cpp @@ -33,7 +33,7 @@ namespace jet { dup2(fdo[1], 1); if(variableDefined("input")) { resolveKeyword("input"); - coreutils::ZString input(variables[variables["input"]]); + coreutils::ZString input(variables["input"]); pipe(fdi); if(fork() == 0) { close(fdi[0]); @@ -41,12 +41,12 @@ namespace jet { close(fdi[1]); exit(0); } - close(fdi[0]); + close(fdi[1]); dup2(fdi[0], 0); } - rc = execve(variables["pgm"].c_str(), argv, NULL); + rc = execvpe(variables["pgm"].c_str(), argv, global.envp); close(fdo[1]); - exit(rc); + exit(errno); } close(fdo[1]); if(variableDefined("name")) { @@ -63,9 +63,10 @@ namespace jet { } else out.read(fdo[0]); waitpid(pid, &status, 0); - if(variableDefined("status")) - resolveKeyword("status"); - global.variables[variables["status"]] = (status >> 8 & 255); + if(variableDefined("error")) { + resolveKeyword("error"); + global.variables[variables["error"]] = (status >> 8 & 255); + } } } diff --git a/jet-2.0.cpp b/jet-2.0.cpp index 2b14ce5..0ea6de0 100644 --- a/jet-2.0.cpp +++ b/jet-2.0.cpp @@ -5,14 +5,14 @@ #include "Exception.h" #include "__jet.h" -int main(int argc, char **argv) { +int main(int argc, char **argv, char **envp) { coreutils::File script(argv[1]); script.read(); coreutils::ZString data = script.asZString(); data.goeol(); - jet::Global global; + jet::Global global(envp); try { coreutils::MString out; diff --git a/tests/testcall.jet b/tests/testcall.jet index c993031..be1f8bb 100755 --- a/tests/testcall.jet +++ b/tests/testcall.jet @@ -1,8 +1,8 @@ #!../jet-2.0 - + test1=$[test1] name1=#[localname] -status=$[stat] +error=$[error] From 78001212f8140c4b9c0b913709f000c59827ebd7 Mon Sep 17 00:00:00 2001 From: Brad Arant Date: Mon, 18 Nov 2024 13:05:33 -0800 Subject: [PATCH 4/8] cleaned up system tag. --- __system.cpp | 7 ++----- tests/testsystem.jet | 4 ++-- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/__system.cpp b/__system.cpp index 85435be..1f62b39 100644 --- a/__system.cpp +++ b/__system.cpp @@ -31,9 +31,9 @@ namespace jet { close(fdi[1]); dup2(fdi[0], 0); } - rc = system(variables["cmd"].c_str()); + system(variables["cmd"].c_str()); close(fdo[1]); - exit(rc); + exit(errno); } close(fdo[1]); if(variableDefined("name")) @@ -41,9 +41,6 @@ namespace jet { else out.read(fdo[0]); waitpid(pid, &status, 0); - if(variableDefined("status")) - resolveKeyword("status"); - global.variables[variables["status"]] = (status >> 8 & 255); } } diff --git a/tests/testsystem.jet b/tests/testsystem.jet index 8de0704..9b0e959 100755 --- a/tests/testsystem.jet +++ b/tests/testsystem.jet @@ -1,8 +1,8 @@ #!../jet-2.0 - + test1=$[test1] name1=#[localname] -status=$[stat] +error=$[error] From e249588a1970538fdf0e6883a57ce26be79160e6 Mon Sep 17 00:00:00 2001 From: Brad Arant Date: Mon, 18 Nov 2024 13:08:28 -0800 Subject: [PATCH 5/8] finished expr function. --- Operand.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Operand.cpp b/Operand.cpp index f24fb93..2d9ff01 100644 --- a/Operand.cpp +++ b/Operand.cpp @@ -54,10 +54,10 @@ namespace jet { throw coreutils::Exception("Expecting ) at end of LEFT expression."); } else if(in.ifNextIgnoreCase("EXPR")) { if(!in.ifNext("(")) - throw coreutils::Exception("Expecting ( for LEFT parameters."); + throw coreutils::Exception("Expecting ( for EXPR parameters."); Operand parm1(in, global, lvariables); if(in.ifNext(")")) { - Operand op(in, global, lvariables); + Operand op(parm1.string, global, lvariables); string = op.string; isNumber = op.isNumber; boolean = op.boolean; From b0453fe0cb890f86bffa76fb95798d00c98e6b69 Mon Sep 17 00:00:00 2001 From: Brad Arant Date: Mon, 18 Nov 2024 16:59:32 -0800 Subject: [PATCH 6/8] worked on error output just a little. --- Global.cpp | 2 +- __jet.cpp | 16 ++-------------- jet-2.0.cpp | 3 +++ tests/testexpr.jet | 3 +++ tests/testjet.jet | 4 ++-- 5 files changed, 11 insertions(+), 17 deletions(-) diff --git a/Global.cpp b/Global.cpp index 49e6847..9917c94 100644 --- a/Global.cpp +++ b/Global.cpp @@ -108,7 +108,7 @@ namespace jet { name << getVariable(variable, lvariables); else if(variable.ifNext("]")) return; - else if(!variable.ifNextInclude("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._-")) + else if(!variable.ifNextInclude("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._-")) throw coreutils::Exception("invalid variable name."); } return; diff --git a/__jet.cpp b/__jet.cpp index 275e515..5ad4385 100644 --- a/__jet.cpp +++ b/__jet.cpp @@ -19,26 +19,14 @@ namespace jet { coreutils::IMFRequest request(postdata); coreutils::IMFMessage message(postdata); - - - + if(contentType == "multipart/form-data") std::cout << "output multipart variables to global" << std::endl; else if(contentType == "application/x-www-form-urlencoded") std::cout << "output urlencoded variables to global" << std::endl; } } - - try { - processContainer(container); - } - catch(coreutils::Exception e) { - std::cout << container.parsed() << std::endl; - std::cout << "***** " << e.text << std::endl; - std::cout << container.unparsed() << std::endl; - throw e; - } - + processContainer(container); } } diff --git a/jet-2.0.cpp b/jet-2.0.cpp index 0ea6de0..59191cb 100644 --- a/jet-2.0.cpp +++ b/jet-2.0.cpp @@ -22,6 +22,9 @@ int main(int argc, char **argv, char **envp) { std::cout << out; } catch(coreutils::Exception e) { + std::cout << data.parsed() << std::endl; + std::cout << "******** Error caught: " << e.text << std::endl; + std::cout << data.unparsed() << std::endl; std::cout << "Error caught: " << e.text << std::endl; global.dump(); } diff --git a/tests/testexpr.jet b/tests/testexpr.jet index 220ae99..f159e5a 100755 --- a/tests/testexpr.jet +++ b/tests/testexpr.jet @@ -3,4 +3,7 @@ $[test2] +0123456789 + +$[lefty] diff --git a/tests/testjet.jet b/tests/testjet.jet index 90a1e25..27e7a6d 100755 --- a/tests/testjet.jet +++ b/tests/testjet.jet @@ -19,9 +19,9 @@ - $[nested] + $[$nested] 0123456789 - + lefty=[$[lefty]] substring('abcdefg', 1, 3)=[$[theexpr]] 5+3=($[addition]) From dd90d2c8059238285b1d6fc141f74685ba39f4c6 Mon Sep 17 00:00:00 2001 From: Brad Arant Date: Tue, 19 Nov 2024 08:22:16 -0800 Subject: [PATCH 7/8] fixed scoping issue on resolveKeyword using parents variables. --- Tag.cpp | 2 +- tests/testvar.jet | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Tag.cpp b/Tag.cpp index 50012b0..69a2848 100644 --- a/Tag.cpp +++ b/Tag.cpp @@ -108,7 +108,7 @@ namespace jet { } void Tag::resolveKeyword(coreutils::ZString keyword) { - variables[keyword] = KeywordValue(variables[keyword], global, variables); + variables[keyword] = KeywordValue(variables[keyword], global, parent->variables); } void Tag::processContainer(coreutils::ZString &container, coreutils::ZString container2) { diff --git a/tests/testvar.jet b/tests/testvar.jet index 8527c75..3c79fed 100755 --- a/tests/testvar.jet +++ b/tests/testvar.jet @@ -1,10 +1,14 @@ #!../jet-2.0 + + +test1=[$[test1]] +name1=[#[name1]] $[$[ix]var$[ix];binary] $[var$[ix]] $[var$[ix]var] @@ -15,3 +19,4 @@ $[var$[i$[letterx]]$[i$[letterx]]] $[ix] $[ix] + From b65403243a8524f0ae2367e05bd941a6baa01da4 Mon Sep 17 00:00:00 2001 From: Brad Arant Date: Tue, 19 Nov 2024 16:44:15 -0800 Subject: [PATCH 8/8] updated some documentation. --- JetCore.txt | 106 +++++++++++++++++++++++++++++++++++++++++++--- compile | 2 - tests/testjet.jet | 2 +- 3 files changed, 102 insertions(+), 8 deletions(-) diff --git a/JetCore.txt b/JetCore.txt index bc62a90..c9da8cd 100644 --- a/JetCore.txt +++ b/JetCore.txt @@ -111,15 +111,22 @@ operators, as follows: \section{Function Reference} -\subsection{left(string, number-of-characters)} +\subsection{concat} -\subsection{random()} +\subsection{integer} + +\subsection{left} + +\subsection{random} Use the random function to return a random number between 0 and 1. -\subsection{substring(string, start-position, number-of-characters} +\subsection{round} +Use the round function to round a numeric value to the specified +number of digits after the decimal point. +\subsection{substring} Use the substring operation to extract a portion of a string and return the value as a string. @@ -170,6 +177,8 @@ name input +error + \begin{verbatim} \end{verbatim} @@ -182,26 +191,72 @@ a variable named 'listing'. Use the comment tag to create a section in the jet script that can be used for making comments and is ignored by the jet reader. +The comments tag has no attributes. + \section{for} Use the for tag to iterate a tag container for a logical number of times. +The attributes are: + +start + +end + +step + +name + \section{header} Use the header tag to output a header prior to outputting the process buffer to the requester. +The attributes are: + +name + +expr + +value + +container + \section{if/else} Use the if tag to perform a conditional output on the tag container. An optional else container provides alternate output in the event the condition is not met. +The attributes are: + +value1 + +value2 + +type + +expr + \section{ifrow/else} Use the ifrow tag to output the tag container if a row exists in the -mysql tag. +mysql tag. An optional else container provides alternate output in the +event that there is no row for the sql result. + +The attributes are: + +sessionid + +\section{include} + +Use the include tag to include another content file at the location of +the include tag. + +The attributes are: + +file \section{jet} @@ -213,19 +268,50 @@ to control the output options. Use the mysql tag to specify parameters for connecting to a mysql server. The container of the tag is where you can specify the sql statement and method of processing the result output of the executed -sql statement. +sql statement. The mysql session created is valid only withon the +container of this tag. + +The attributes are: + +host + +database + +user + +password + +sessionid \section{read} Use the read tag to read the contents of a file contained on the local file system into a variable for further output or processing. +The attributes are: + +file + +name + \section{set} Use the set tag to store initialize a variable to a value contained in a value attribute, the result of an expression (expr) attribute or the contents of the set tag container. +The attributes are: + +name + +expr + +value + +container + +scope + \section{sql} Use the sql tag to specify an sql statement to run on the sql server @@ -235,6 +321,12 @@ As long as sql statements are executed within the same mysql containing tag then the same mysql session is used for each sql statement. +The attributes are: + +sessionid + +container + \section{stream} Use stream tag to output data from the server without waiting for the @@ -242,6 +334,10 @@ standard output buffering and processing of the JET script. This is useful for outputting images and streams for audio and video without the server having to load the whole thing into RAM first. +The attributes are: + +file + \section{system} Use the system tag to execute a bash shell command within the JET diff --git a/compile b/compile index 197152f..2df9a61 100755 --- a/compile +++ b/compile @@ -29,5 +29,3 @@ fi rm *.o rm *~ - - diff --git a/tests/testjet.jet b/tests/testjet.jet index 27e7a6d..b326d0e 100755 --- a/tests/testjet.jet +++ b/tests/testjet.jet @@ -1,4 +1,4 @@ -#!../jet-2.0 +#!/home/barant/Development/JetCore/jet-2.0
This is a comment and should not show up in the output.