示例#1
0
/*!
 * \param[in,out] sc    Selection collection to use for output.
 * \param[in]     nr    Number of selections to parse
 *   (if -1, parse as many as provided by the user).
 * \param[in]     grps  External index groups (can be NULL).
 * \param[in]     bInteractive Whether the parser should behave interactively.
 * \returns       0 on success, -1 on error.
 *
 * The number of selections parsed can be accessed with
 * gmx_ana_selcollection_get_count() (note that if you call the parser
 * multiple times, this function returns the total count).
 */
int
gmx_ana_selcollection_parse_stdin(gmx_ana_selcollection_t *sc, int nr,
                                  gmx_ana_indexgrps_t *grps, bool bInteractive)
{
    gmx_sel_lexer_t *scanner;

    _gmx_sel_init_lexer(&scanner, sc, bInteractive);
    _gmx_sel_set_lex_input_file(scanner, stdin);
    return _gmx_sel_run_parser(scanner, sc, grps, nr);
}
示例#2
0
/*!
 * \param[in,out] sc    Selection collection to use for output.
 * \param[in]     fnm   Name of the file to parse selections from.
 * \param[in]     grps  External index groups (can be NULL).
 * \returns       0 on success, -1 on error.
 *
 * The number of selections parsed can be accessed with
 * gmx_ana_selcollection_get_count() (note that if you call the parser
 * multiple times, this function returns the total count).
 */
int
gmx_ana_selcollection_parse_file(gmx_ana_selcollection_t *sc, char *fnm,
                                 gmx_ana_indexgrps_t *grps)
{
    gmx_sel_lexer_t *scanner;
    FILE *fp;
    int   rc;

    _gmx_sel_init_lexer(&scanner, sc, FALSE);
    fp = ffopen(fnm, "r");
    _gmx_sel_set_lex_input_file(scanner, fp);
    rc = _gmx_sel_run_parser(scanner, sc, grps, -1);
    fclose(fp);
    return rc;
}
示例#3
0
SelectionList
SelectionCollection::parseFromFile(const std::string &filename)
{

    try
    {
        yyscan_t scanner;
        File     file(filename, "r");
        // TODO: Exception-safe way of using the lexer.
        _gmx_sel_init_lexer(&scanner, &impl_->sc_, false, -1,
                            impl_->bExternalGroupsSet_,
                            impl_->grps_);
        _gmx_sel_set_lex_input_file(scanner, file.handle());
        return runParser(scanner, false, -1, std::string());
    }
    catch (GromacsException &ex)
    {
        ex.prependContext(formatString(
                                  "Error in parsing selections from file '%s'",
                                  filename.c_str()));
        throw;
    }
}
void
SelectionCollection::parseFromFile(const std::string &filename,
                                   std::vector<Selection *> *output)
{
    yyscan_t scanner;
    FILE *fp;

    _gmx_sel_init_lexer(&scanner, &_impl->_sc, false, -1,
                        _impl->hasFlag(Impl::efExternalGroupsSet),
                        _impl->_grps);
    fp = ffopen(filename.c_str(), "r");
    _gmx_sel_set_lex_input_file(scanner, fp);
    // TODO: Use RAII
    try
    {
        _impl->runParser(scanner, -1, output);
    }
    catch (...)
    {
        ffclose(fp);
        throw;
    }
    ffclose(fp);
}