sync
This commit is contained in:
parent
a63b60bab7
commit
ea3d1a7ad0
35
__write.cpp
35
__write.cpp
@ -2,11 +2,15 @@
|
||||
#include "Exception.h"
|
||||
#include "Expression.h"
|
||||
#include <iostream>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace jet {
|
||||
|
||||
__write::__set(coreutils::ZString &in, coreutils::MString &parent, Global &global) : Tag(in, parent, global) {
|
||||
__write::__write(coreutils::ZString &in, coreutils::MString &parent, Global &global) : Tag(in, parent, global) {
|
||||
output = false;
|
||||
int mode = 0;
|
||||
int len;
|
||||
processContainer(container);
|
||||
if(!variableDefined("file"))
|
||||
throw coreutils::Exception("write tag must have file defined.");
|
||||
@ -20,13 +24,24 @@ namespace jet {
|
||||
throw coreutils::Exception("write tag must have a value, expr or a container.");
|
||||
if(variableDefined("scope"))
|
||||
throw coreutils::Exception("Cannot use scope with write tag.");
|
||||
|
||||
|
||||
int fd = open(variables["file"], O_APPEND | O_TRUNC); // <--- options go here need to pick one
|
||||
|
||||
|
||||
|
||||
close(fd);
|
||||
|
||||
}
|
||||
if(!variableDefined("mode"))
|
||||
throw coreutils::Exception("write tag must have a mode keyword.");
|
||||
if(variables["mode"] == "append")
|
||||
mode = O_APPEND;
|
||||
else if(variables["mode"] == "overwrite")
|
||||
mode = O_TRUNC;
|
||||
else
|
||||
throw coreutils::Exception("mode keyword must be 'overwrite' or 'append'.");
|
||||
int fd = open(variables["file"].c_str(), mode, 0644); // Need to add O_CREAT and AUTH flags.
|
||||
if(hasContainer && !evaluate)
|
||||
len = write(fd, container.getData(), container.getLength());
|
||||
else if(hasContainer && evaluate)
|
||||
len = write(fd, out.getData(), out.getLength());
|
||||
else if(!hasContainer && variableDefined("value"))
|
||||
len = write(fd, variables["value"].getData(), variables["value"].getLength());
|
||||
else if(!hasContainer && variableDefined("expr"))
|
||||
len = write(fd, variables["expr"].getData(), variables["expr"].getLength());
|
||||
close(fd);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user