Added call tag. Updated read tag.

This commit is contained in:
Brad Arant 2024-07-08 13:56:27 -07:00
parent d10ed783fa
commit 8443495675
8 changed files with 83 additions and 8 deletions

3
.gitignore vendored Normal file
View File

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

View File

@ -6,6 +6,7 @@
#include "__if.h"
#include "__read.h"
#include "__set.h"
#include "__call.h"
#include "__jet.h"
#include "__while.h"
#include <iostream>
@ -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;

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

View File

@ -1,17 +1,21 @@
#include "__read.h"
#include "Exception.h"
#include <fcntl.h>
#include <stdio.h>
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);
}
}

View File

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

View File

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

BIN
testjet

Binary file not shown.