More work on call tag.

This commit is contained in:
Brad Arant 2024-07-09 13:11:41 -07:00
parent 49edce1f34
commit 632e6979ba
5 changed files with 44 additions and 21 deletions

View File

@ -13,24 +13,44 @@ namespace jet {
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(fd[0], 1);
if(pid != fork()) {
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;
execve(variables["pgm"].c_str(), argv, NULL);
exit(-1);
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;
pipe(fdo);
if(pid != fork()) {
close(fdo[0]);
dup2(fdo[1], 1);
if(variableDefined("input")) {
coreutils::ZString input(variables[variables["input"]]);
pipe(fdi);
if(fork() == 0) {
close(fdi[0]);
write(fdi[1], input.getData(), input.getLength());
close(fdi[1]);
exit(0);
}
close(fdi[0]);
dup2(fdi[0], 0);
}
rc = execve(variables["pgm"].c_str(), argv, NULL);
close(fdo[1]);
std::cout << "rc: " << rc << std::endl;
exit(rc);
}
close(fdo[1]);
if(variableDefined("name"))
global.variables[variables["name"]].read(fdo[0]);
else
out.read(fdo[0]);
waitpid(pid, &status,0);
std::cout << "status: " << status << std::endl;
}
}

View File

@ -14,8 +14,10 @@ namespace jet {
int pid;
int status;
int ix;
int fd[2];
char *argv[25];
int fdi[2];
int fdo[2];
int rc;
char *argv[50];
};

View File

@ -5,7 +5,7 @@ do
filename="${file%.*}"
list="$list $filename.o"
echo -n "Compiling $filename..."
g++ -g -c -std=c++17 -I../CoreUtils $file &
g++ -g -c -std=c++23 -I../CoreUtils $file &
if [ $? = '0' ]
then
echo "OK"
@ -18,7 +18,7 @@ done
wait
echo -n "Building executable testjet..."
g++ -g -o testjet $list -std=c++17 -L../CoreUtils -lCoreUtils
g++ -g -o testjet $list -std=c++23 -L../CoreUtils -lCoreUtils
if [ $? = '0' ]
then
echo "OK"

BIN
testjet

Binary file not shown.

View File

@ -26,9 +26,10 @@ int main(int argc, char **argv) {
" </if>\n"
" </if>\n"
" </mysql>\n"
" <for name=\"ix\" start=\"1\" end=\"5\" step=\".1\">\n"
" <for name=\"ix\" start=\"1\" end=\"5\" step=\"1\">\n"
" -->#[ix]<--\n"
" </for>\n"
" <call pgm=\"/usr/bin/ls\" arg1=\"-al\" />"
" </html>\n"
"</jet>\n");