Fixed read tag merge issue.

This commit is contained in:
brad Arant 2024-07-08 18:38:32 -07:00
commit 666a12e16b
10 changed files with 115 additions and 8 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
*.o
*~
testjet

View File

@ -8,3 +8,6 @@ modifications. Data contained within the tags may modify their
containers before placing any output. The space taken by the tag containers before placing any output. The space taken by the tag
itself is not passwed to the output and will not appear in the output. itself is not passwed to the output and will not appear in the output.
Skip Blank Lines options on containers will skip passing any blank
lines or line containing only whitespace to the output.

View File

@ -7,6 +7,7 @@
#include "__if.h" #include "__if.h"
#include "__read.h" #include "__read.h"
#include "__set.h" #include "__set.h"
#include "__call.h"
#include "__jet.h" #include "__jet.h"
#include "__while.h" #include "__while.h"
#include <iostream> #include <iostream>
@ -114,6 +115,9 @@ namespace jet {
} else if(ifTagName(in, "set")) { } else if(ifTagName(in, "set")) {
__set _set(in, out, global); __set _set(in, out, global);
continue; continue;
} else if(ifTagName(in, "call")) {
__call _set(in, out, global);
continue;
} else if(ifTagName(in, "while")) { } else if(ifTagName(in, "while")) {
__while _while(in, out, global); __while _while(in, out, global);
continue; continue;

37
__call.cpp Normal file
View File

@ -0,0 +1,37 @@
#include "__call.h"
#include "Exception.h"
#include "MString.h"
#include <limits.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
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);
}
}

24
__call.h Normal file
View File

@ -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

12
__comment.cpp Normal file
View File

@ -0,0 +1,12 @@
#include "__cpmment.h"
#include "Exception.h"
namespace jet {
__comment::__comment(coreutils::ZString &in, coreutils::MString &out, Global &global) : Tag(in, out, global) {
if(!hasContainer)
throw coreutils::Exception("comment must have a container.");
output = false;
}
}

17
__comment.h Normal file
View File

@ -0,0 +1,17 @@
#ifndef ____comment_h__
#define ____comment_h__
#include "Tag.h"
namespace jet {
class __comment : public Tag {
public:
__comment(coreutils::ZString &in, coreutils::MString &out, Global &global);
};
}
#endif

View File

@ -1,17 +1,21 @@
#include "__read.h" #include "__read.h"
#include "Exception.h" #include "Exception.h"
#include <fcntl.h>
#include <stdio.h>
namespace jet { namespace jet {
__read::__read(coreutils::ZString &in, coreutils::MString &parent, Global &global) : Tag(in, parent, global) { __read::__read(coreutils::ZString &in, coreutils::MString &parent, Global &global) : Tag(in, parent, global) {
if(!variableDefined(coreutils::ZString("file"))) if(!variableDefined(coreutils::ZString("file")))
throw coreutils::Exception("file keyword must be specified."); throw coreutils::Exception("file keyword must be specified.");
if(hasContainer) if(hasContainer)
throw coreutils::Exception("Missing / at end of tag definition. Not a container tag."); throw coreutils::Exception("read tag does not have a container.");
fd = open(variables["file"], O_RDONLY);
// process file request here. while(len = read(fd, &buffer, sizeof(buffer - 1))) {
buffer[len] = 0;
out << buffer;
}
close(fd);
} }
} }

View File

@ -10,6 +10,11 @@ namespace jet {
public: public:
__read(coreutils::ZString &in, coreutils::MString &parent, Global &global); __read(coreutils::ZString &in, coreutils::MString &parent, Global &global);
private:
int fd;
int len;
char buffer[4096];
}; };
} }

View File

@ -1,2 +0,0 @@
*.o
*~