JetCore/__read.cpp

24 lines
808 B
C++

#include "__read.h"
#include "Exception.h"
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
namespace jet {
__read::__read(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent, Tag *local) : Tag(in, parentOut, global, parent, this) {
if(!keywordDefined("file"))
throw coreutils::Exception("file keyword must be specified.");
if(!keywordDefined("name"))
throw coreutils::Exception("name keyword must be specified.");
if(hasContainer)
throw coreutils::Exception("read tag does not have a container.");
fd = open(keywords[resolveKeyword("file")].c_str(), O_RDONLY);
if(fd < 0)
throw coreutils::Exception("file name is not found.");
global.variables[keywords[resolveKeyword("name")]].read(fd);
close(fd);
}
}