JetCore/__write.cpp
2024-07-18 16:34:11 -07:00

33 lines
1.2 KiB
C++

#include "__write.h"
#include "Exception.h"
#include "Expression.h"
#include <iostream>
namespace jet {
__write::__set(coreutils::ZString &in, coreutils::MString &parent, Global &global) : Tag(in, parent, global) {
output = false;
processContainer(container);
if(!variableDefined("file"))
throw coreutils::Exception("write tag must have file defined.");
if(!variableDefined("expr") && variableDefined("value") && hasContainer)
throw coreutils::Exception("write tag cannot have both value and a container.");
if(variableDefined("expr") && !variableDefined("value") && hasContainer)
throw coreutils::Exception("write tag cannot have both expr and a container.");
if(variableDefined("expr") && variableDefined("value") && !hasContainer)
throw coreutils::Exception("write tag cannot have both expr and value.");
if(!variableDefined("expr") && !variableDefined("value") && !hasContainer)
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);
}
}