Esempio n. 1
0
STATIC const char *doInclude( const char *str ) {

    int     fh;
    char    *file;
    char    *file_name;
    const char *env_var;

/**/myassert( str != NULL );
    if( isBreakChar( *str ) ) unrecognized( '@' );
    file_name = getFile( &str );
    env_var = getenv( file_name );
    if( env_var != NULL ) {
        MemFree( file_name );
        parseString( env_var );
    } else {
        /* both these functions use a lot of stack, so we separate them */
        fh = openIncludeFile( file_name );
        MemFree( file_name );
        file = readIncludeFile( fh );
        if( file != NULL ) {
            parseString( file );
            MemFree( file );
        }
    }
    return( str );
}
Esempio n. 2
0
void TestContextMenuPrivate::onOpenIncludeFile()
{
    emit openIncludeFile(m_includeFile);
}
Esempio n. 3
0
    bool GLProgram::parseProgramSource(InputStream* input,
        std::vector<std::string>& vertex, std::vector<std::string>& fragment,
        std::vector<std::string>* what) const
    {
        bool success = true;
        int lineNumber = 0;

        Z_CHECK(input != nullptr);
        if (!input)
            return false;

        static const std::string VERTEX = "%vertex";
        static const std::string VERTEX_LF = "%vertex\n";
        static const std::string FRAGMENT = "%fragment";
        static const std::string FRAGMENT_LF = "%fragment\n";
        static const std::string BOTH = "%both";
        static const std::string BOTH_LF = "%both\n";
        static const std::string INCLUDE = "%include ";
        static const std::string LF = "\n";

        while (!input->atEnd()) {
            std::string line = input->readLine(true);
            ++lineNumber;

            size_t index = line.find("//");
            if (index != std::string::npos) {
                bool endsWithLF = false;
                size_t length = line.length();
                if (length > 1 && line[length - 1] == '\n')
                    endsWithLF = true;

                line = line.substr(0, index);

                if (endsWithLF)
                    line += '\n';
            }

            if (*line.c_str() == '%') {
                if (line == VERTEX_LF || line == VERTEX)
                    what = &vertex;
                else if (line == FRAGMENT_LF || line == FRAGMENT)
                    what = &fragment;
                else if (line == BOTH_LF || line == BOTH)
                    what = nullptr;
                else if (line.substr(0, INCLUDE.length()) == INCLUDE) {
                    auto include = openIncludeFile(line.substr(INCLUDE.length()), input->name());
                    success = parseProgramSource(include.get(), vertex, fragment, what) && success;
                } else {
                    Z_LOG(input->name() << "(" << lineNumber << "): invalid directive.");
                    what = nullptr;
                    success = false;
                }
                continue;
            }

            if (what)
                what->emplace_back(std::move(line));
            else {
                vertex.emplace_back(line);
                fragment.emplace_back(std::move(line));
            }
        }

        return success;
    }