Beispiel #1
0
void help(string syntax,dictionary<string> options)
{
 //help

 options.add("--help","Prints this help");  
 
 //syntax
 
 log();
 log("Syntax is:");
 
 log(syntax.indent(1));
 
 //option
 
 options.update(options.keys().text().justify_left().lines().me(),options.values().me());
 
 log();
 log("Options are:");
   
 for(int i=0;i<options.count();i++)
 {
  auto& current=options.item(i);
  
  log(concat(current._first," ",current._second).indent(1));
 }
}
Beispiel #2
0
// Dictionary merging/editing.
// literalRE:
// - true: behave like dictionary::merge, i.e. add regexps just like
//   any other key.
// - false : interpret wildcard as a rule for items to be matched.
bool merge
(
    dictionary& thisDict,
    const dictionary& mergeDict,
    const bool literalRE
)
{
    static bool wildCardInMergeDict = false;

    bool changed = false;

    // Save current (non-wildcard) keys before adding items.
    HashSet<word> thisKeysSet;
    {
        List<keyType> keys = thisDict.keys(false);
        forAll(keys, i)
        {
            thisKeysSet.insert(keys[i]);
        }
    }
void setScoped
(
    dictionary& dict,
    const word& keyword,
    const bool overwrite,
    entry* d
)
{
    if (keyword[0] == ':')
    {
        // Go up to top level and recurse to find entries
        setScoped
        (
            const_cast<dictionary&>(dict.topDict()),
            keyword.substr(1, keyword.size()-1),
            overwrite,
            d
        );
        return;
    }
    else
    {
        string::size_type dotPos = keyword.find('.');

        if (dotPos == string::npos)
        {
            // Non-scoped lookup
            if (overwrite)
            {
                dict.set(d);
            }
            else
            {
                dict.add(d, false);
            }
            return;
        }
        else
        {
            if (dotPos == 0)
            {
                // Starting with a '.'. Go up for every 2nd '.' found

                const dictionary* dictPtr = &dict;

                string::size_type begVar = dotPos + 1;
                string::const_iterator iter =
                    keyword.begin() + begVar;
                string::size_type endVar = begVar;
                while
                (
                    iter != keyword.end()
                    && *iter == '.'
                )
                {
                    ++iter;
                    ++endVar;

                    // Go to parent
                    if (&dictPtr->parent() == &dictionary::null)
                    {
                        FatalIOErrorInFunction(dict)
                                << "No parent of current dictionary"
                                << " when searching for "
                                <<  keyword.substr
                                (
                                    begVar,
                                    keyword.size() - begVar
                                )
                                << exit(FatalIOError);
                    }
                    dictPtr = &dictPtr->parent();
                }

                setScoped
                (
                    const_cast<dictionary&>(*dictPtr),
                    keyword.substr(endVar),
                    overwrite,
                    d
                );
                return;
            }
            else
            {
                // Extract the first word
                word firstWord = keyword.substr(0, dotPos);

                const entry* entPtr = dict.lookupScopedEntryPtr
                                      (
                                          firstWord,
                                          false,          // Recursive
                                          false
                                      );

                if (!entPtr || !entPtr->isDict())
                {
                    FatalIOErrorInFunction(dict)
                            << "keyword " << firstWord
                            << " is undefined in dictionary "
                            << dict.name() << " or is not a dictionary"
                            << endl
                            << "Valid keywords are " << dict.keys()
                            << exit(FatalIOError);
                }

                const dictionary& firstDict = entPtr->dict();

                setScoped
                (
                    const_cast<dictionary&>(firstDict),
                    keyword.substr(dotPos, keyword.size()-dotPos),
                    overwrite,
                    d
                );
                return;
            }
        }
    }
}