static Pipe mkPipe()
{
  Pipe p;
  Cmd c;

  c = mkCmd(Tnil);		// at least one command

  // ignore NULL cmds--generated by empty line or error
  if ( c == NULL || c == &Empty )
    return NULL;

  // allocate the pipe structure
  p = ckmalloc(sizeof(*p));
  p->type = Pout;	// set type to Pout until we know differently
  p->head = c;

  while ( PipeToken(LA) ) {
    if ( LA == TpipeErr )
      p->type = PoutErr;	// reset type
    else if(LA == Tpipe)
      p->type = Pout;     //reset type
    if ( c->out != Tnil ) {
      printf("Ambiguous output redirect.\n");
      // skip to end of command
      do { 
	Next();
      } while ( !EndOfInput(LA) );
      freeCmd(c);
      return NULL;
    } else
      c->out = p->type == Pout ? Tpipe : TpipeErr;
    Next();
    c->next = mkCmd(p->type == Pout ? Tpipe : TpipeErr);
    if ( c->next == NULL || c->next == &Empty ) {
      if ( c->next == &Empty )
	printf("Invalid null command.\n");
      while ( !EndOfInput(LA) )
	Next();
      return NULL;
    }
    c = c->next;
  }

  // read next pipe on the line
  p->next = NULL;
  while ( !EndOfInput(LA) ) {
    p->next = mkPipe();
    if ( !p->next )
      break;
  }
  return p;
} /*---------- End of mkPipe ------------------------------------------------*/
Example #2
0
	void Engine::run() {
		// Environment variables
		String documentRoot = getenv("DOCUMENT_ROOT");
		String requestUri = getenv("REQUEST_URI");

		// Build resource filename
		String resourceFilename;
		resourceFilename << documentRoot << "/www" << requestUri << ".kraft";

		// Build output source filename
		String outputSrcFilename;
		outputSrcFilename << documentRoot << "/src/www" << requestUri << ".cpp";

		// Build output binary filename
		String outputBinFilename;
		outputBinFilename << documentRoot << "/bin/www" << requestUri;

		// Parse resource
		resources::XmlResourceParser parser;
		parser.parseFile(resourceFilename);

		// Generate resource source code
		String source = parser.generateSource();
		if (source.length() < 1) return;

		// Make source directories
		String parentSrcFolder = server::File::getParentFolder(outputSrcFilename);
		String mkCmd("mkdir -p ");
		mkCmd << parentSrcFolder;
		system(mkCmd.toChars());
		// Write source file
		server::File outputSrcFile;
		outputSrcFile.openWrite(outputSrcFilename, false);
		outputSrcFile << source;
		outputSrcFile.close();

		// Make binary directories
		String parentBinFolder = server::File::getParentFolder(outputBinFilename);
		mkCmd = "mkdir -p ";
		mkCmd << parentBinFolder;
		system(mkCmd.toChars());
		// Make binaries
		String binCmd("g++ -Wall");
		binCmd << " -L" << documentRoot << "/bin";
		binCmd << " -I" << documentRoot << "/include";
		binCmd << " -o " << outputBinFilename;
		binCmd << " " << outputSrcFilename;
		binCmd << " -lkrafter -lkrafter-site";
		system(binCmd.toChars());
		// Run compiled binary
		if (server::File::exists(outputBinFilename)) {
			std::cout << server::File::execute(outputBinFilename).toChars();
		}
	}