Example #1
0
void shade::FileAccumulator::add_file(const std::string& file)
{
  if (file.empty())
    return;

  if (m_seen_files.find(file) == m_seen_files.end())
  {
    std::string content = m_resolver.load(file);
    m_seen_files.insert(file);

    typedef std::map<std::string, std::string> Keywords;
    Keywords keywords;
    std::istringstream input(content);
    m_content += io::parse_input(input, keywords);

    Keywords::const_iterator glsl_version = keywords.find("glsl_version");
    if (glsl_version != keywords.end())
    {
      m_glsl_version = std::max(m_glsl_version, boost::lexical_cast<int>(glsl_version->second));
    }

    Keywords::const_iterator gpu_shader4_ext = keywords.find("GL_EXT_gpu_shader4");
    if (gpu_shader4_ext != keywords.end())
    {
      if (gpu_shader4_ext->second == "require")
        m_requires_gpu_shader4_ext = true;
    }
  }
}
Example #2
0
std::string FormatBlock(const ParserDefinition *pd, Keywords& keywords, const std::string &format)
{
	std::stringstream ss;
	std::vector<std::string> lines;
	std::vector<std::string> params = keywords["$PARAM"];
	std::string format_copy(format);
	const char *eol = getEolStr();

	// Replace keywords
	stringReplace(format_copy, "$@", pd->command_prefix);
	stringReplace(format_copy, "$FILENAME", keywords["$FILENAME"][0]);
	
	// $FUNCTION may not exist
	if(keywords.find("$FUNCTION") != keywords.end())
		stringReplace(format_copy, "$FUNCTION", keywords["$FUNCTION"][0]);
	else
		stringReplace(format_copy, "$FUNCTION", "");

	lines = splitLines(format_copy, "\r\n");

	for(unsigned int i = 0; i < lines.size(); ++i)
	{
		if(lines[i].find("$PARAM") != std::string::npos)
		{
			// Duplicate the current line for each $PARAM
			std::vector<std::string> formatted_lines;
			for(unsigned int j = 0; j < params.size(); ++j)
			{
				// Make a copy of lines[i] before calling stringReplace
				std::string line = lines[i];
				stringReplace(line, "$PARAM", params[j]);
				formatted_lines.push_back(line);
			}

			// If the align flag is set, align the lines, else remove all "$|" flags
			if(pd->align)
				alignLines(formatted_lines);
			else
				for(unsigned int j = 0; j < formatted_lines.size(); ++j)
					stringReplace(formatted_lines[j], "$|", "");

			// Insert the lines
			for(unsigned int j = 0; j < formatted_lines.size(); ++j)
			{
				if(i == 0 && j == 0)
					ss << pd->doc_start << formatted_lines[j] << eol;
				else if(i == lines.size() - 1 && j == formatted_lines.size() - 1)
					ss << pd->doc_end << formatted_lines[j] << eol;
				else
					ss << pd->doc_line << formatted_lines[j] << eol;
			}
		}
		else
		{
			if(i == 0)
				ss << pd->doc_start << lines[i] << eol;
			else if(i == lines.size() -1)
				ss << pd->doc_end << lines[i];
			else
				ss << pd->doc_line << lines[i] << eol;
		}
	}

	return ss.str();
}