#include "util.hpp" #include #include #include #include #include std::string indenting_string="\t"; std::string indent(int n) { std::string ret; for(int i=0; i split(std::string const& in, char c) { uint32_t i=0,j=0; std::vector ret; while(j const& args) { std::vector rargs; for(auto it=args.begin(); it!=args.end(); it++) rargs.push_back((char*) it->c_str()); rargs.push_back(NULL); pid_t pid; // forking if((pid = fork()) == -1) { perror("fork"); exit(1); } // child process if(pid == 0) { setpgid(pid, pid); //Needed so negative PIDs can kill children of /bin/sh execvp(bin.c_str(), rargs.data()); exit(1); // exec didn't work } int stat; // wait for end and get return value while (waitpid(pid, &stat, 0) == -1) { if (errno != EINTR) { stat = -1; break; } } return stat; } std::string stringReplace(std::string subject, const std::string& search, const std::string& replace) { size_t pos = 0; while ((pos = subject.find(search, pos)) != std::string::npos) { subject.replace(pos, search.length(), replace); pos += replace.length(); } return subject; } void printFormatError(ztd::format_error const& e, bool print_line) { printErrorIndex(e.data(), e.where(), e.what(), e.origin(), print_line); } std::string repeatString(std::string const& str, uint32_t n) { std::string ret; for(uint32_t i=0; i= 0) { while(i < in_size && i < index) { if(in[i] == '\n') { line++; j=i+1; } i++; } while(i < in_size && in[i]!='\n') { i++; } } if(origin != "") { fprintf(stderr, "%s:%u:%u: %s\n", origin.c_str(), line, index-j+1, message.c_str()); if(print_line) { std::cerr << std::string(in+j, i-j) << std::endl; std::cerr << repeatString(" ", index-j) << '^' << std::endl; } } }