diff --git a/applications/utilities/miscellaneous/foamToC/foamToC.C b/applications/utilities/miscellaneous/foamToC/foamToC.C index 818d9d1802..340a8ad0f4 100644 --- a/applications/utilities/miscellaneous/foamToC/foamToC.C +++ b/applications/utilities/miscellaneous/foamToC/foamToC.C @@ -60,8 +60,9 @@ Usage - \par table \ List the contents of the specified table or the list sub-tables - - \par search \ - Search for and list the tables containing the given entry + - \par search \ or \"\\" + Search for and list the tables containing the given name + or all matches to the given regular expression - \par scalarBCs, List scalar field boundary conditions (fvPatchField) @@ -373,72 +374,118 @@ int main(int argc, char *argv[]) word name; if (args.optionReadIfPresent("search", name)) { - HashTable> baseTypeNameTables; + wordList names(name); - forAllConstIter - ( - debug::runTimeSelectionToCType, - debug::runTimeSelectionToC, - iter - ) + // If the name is a regular expression pattern + // search for all matching occurrences + if (wordRe::isPattern(name)) { - const word& baseType = iter.key(); - const word& baseTypeName = iter().first(); + wordRe nameRe(name); + nameRe.compile(); - if (iter().second().found(name)) + HashSet unsortedNames; + + forAllConstIter + ( + debug::runTimeSelectionToCType, + debug::runTimeSelectionToC, + iter + ) { - if (!baseTypeNameTables.found(baseTypeName)) + forAllConstIter(HashTable, iter().second(), iter2) { - baseTypeNameTables.insert(baseTypeName, HashTable()); - } - - baseTypeNameTables[baseTypeName].insert - ( - baseType, - iter().second()[name] - ); - } - } - - if (baseTypeNameTables.size()) - { - Info<< name << " is in tables " << endl; - - const wordList toc(baseTypeNameTables.sortedToc()); - - forAll(toc, i) - { - if - ( - baseTypeNameTables[toc[i]].size() == 1 - && toc[i] == baseTypeNameTables[toc[i]].begin().key() - ) - { - Info<< " " << setf(ios_base::left) << setw(40) << toc[i] - << baseTypeNameTables[toc[i]].begin()() - << endl; - } - else - { - const wordList tocc - ( - baseTypeNameTables[toc[i]].sortedToc() - ); - - Info<< " " << toc[i] << endl; - forAll(tocc, j) + if (nameRe.match(iter2.key())) { - Info<< " " - << setf(ios_base::left) << setw(40) << tocc[j] - << baseTypeNameTables[toc[i]][tocc[j]] - << endl; + unsortedNames.insert(iter2.key()); } } } + + names = unsortedNames.toc(); } - else + + forAll(names, i) { - Info<< name << " not found" << endl; + const word& name = names[i]; + + HashTable> baseTypeNameTables; + + forAllConstIter + ( + debug::runTimeSelectionToCType, + debug::runTimeSelectionToC, + iter + ) + { + const word& baseType = iter.key(); + const word& baseTypeName = iter().first(); + + if (iter().second().found(name)) + { + if (!baseTypeNameTables.found(baseTypeName)) + { + baseTypeNameTables.insert + ( + baseTypeName, + HashTable() + ); + } + + baseTypeNameTables[baseTypeName].insert + ( + baseType, + iter().second()[name] + ); + } + } + + if (baseTypeNameTables.size()) + { + const wordList toc(baseTypeNameTables.sortedToc()); + + if (toc.size() == 1) + { + Info<< name << " is in table " << endl; + } + else if (toc.size() > 1) + { + Info<< name << " is in tables " << endl; + } + + forAll(toc, i) + { + if + ( + baseTypeNameTables[toc[i]].size() == 1 + && toc[i] == baseTypeNameTables[toc[i]].begin().key() + ) + { + Info<< " " << setf(ios_base::left) << setw(40) + << toc[i] << baseTypeNameTables[toc[i]].begin()() + << endl; + } + else + { + const wordList tocc + ( + baseTypeNameTables[toc[i]].sortedToc() + ); + + Info<< " " << toc[i] << endl; + forAll(tocc, j) + { + Info<< " " + << setf(ios_base::left) << setw(40) << tocc[j] + << baseTypeNameTables[toc[i]][tocc[j]] + << endl; + } + } + } + } + else + { + Info<< name << " not found" << endl; + } } done = true;