diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c6b5688 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*.o +*~ +testjet diff --git a/Tag.cpp b/Tag.cpp index 550e41b..cd9f70a 100644 --- a/Tag.cpp +++ b/Tag.cpp @@ -6,6 +6,7 @@ #include "__if.h" #include "__read.h" #include "__set.h" +#include "__call.h" #include "__jet.h" #include "__while.h" #include @@ -92,6 +93,9 @@ namespace jet { } else if(ifTagName(in, "set")) { __set _set(in, out, global); continue; + } else if(ifTagName(in, "call")) { + __call _set(in, out, global); + continue; } else if(ifTagName(in, "while")) { __while _while(in, out, global); continue; diff --git a/__call.cpp b/__call.cpp new file mode 100644 index 0000000..622f6a0 --- /dev/null +++ b/__call.cpp @@ -0,0 +1,37 @@ +#include "__call.h" +#include "Exception.h" +#include "MString.h" +#include +#include +#include +#include +#include + +namespace jet { + + __call::__call(coreutils::ZString &in, coreutils::MString &out, Global &global) : Tag(in, out, global) { + if(hasContainer) + throw coreutils::Exception("call cannot have a container."); + if(!variableDefined(coreutils::ZString("pgm"))) + throw coreutils::Exception("pgm keyword must be specified."); + pipe[fd]; // TODO: Get these pipes to work with name and input keywords. + dup2(0); + if(pid != fork()) { + argv[0] = variables["pgm"]; // TODO: Need to peel off the program name only and pass as argv[0]. + for(ix = 1; ix <= ARG_MAX; ++ix) { + coreutils::MString arg("arg"); + arg << ix; + if(variableDefined(arg)) + argv[ix] = variables[arg].c_str(); + else + break; + } + argv[ix] == NULL; + execve(variables["pgm"].c_str(), argv, NULL); + exit(-1); + } + waitpid(&status); + + } + +} diff --git a/__call.h b/__call.h new file mode 100644 index 0000000..af91741 --- /dev/null +++ b/__call.h @@ -0,0 +1,24 @@ +#ifndef ____call_h__ +#define ____call_h__ + +#include "Tag.h" + +namespace jet { + + class __call : public Tag { + + public: + __call(coreutils::ZString &in, coreutils::MString &out, Global &global); + + private: + int pid; + int status; + int ix; + int fd[2]; + char *argv[25]; + + }; + +} + +#endif diff --git a/__read.cpp b/__read.cpp index 099aa23..a9ff79f 100644 --- a/__read.cpp +++ b/__read.cpp @@ -1,17 +1,21 @@ #include "__read.h" #include "Exception.h" +#include +#include namespace jet { __read::__read(coreutils::ZString &in, coreutils::MString &out, Global &global) : Tag(in, out, global) { if(!variableDefined(coreutils::ZString("file"))) throw coreutils::Exception("file keyword must be specified."); - if(hasContainer) - throw coreutils::Exception("missing / at end of tag definition."); - - // process file request here. - + throw coreutils::Exception("read tag does not have a container."); + fd = open(variables["file"], O_RDONLY); + while(len = read(fd, &buffer, sizeof(buffer - 1))) { + buffer[len] = 0; + out << buffer; + } + close(fd); } } diff --git a/__read.h b/__read.h index 39a0ced..c048c3e 100644 --- a/__read.h +++ b/__read.h @@ -9,7 +9,12 @@ namespace jet { public: __read(coreutils::ZString &in, coreutils::MString &out, Global &global); - + + private: + int fd; + int len; + char buffer[4096]; + }; } diff --git a/gitignore b/gitignore deleted file mode 100644 index a70237a..0000000 --- a/gitignore +++ /dev/null @@ -1,2 +0,0 @@ -*.o -*~ diff --git a/testjet b/testjet deleted file mode 100755 index 238ca8b..0000000 Binary files a/testjet and /dev/null differ