foamToC: Added support for pattern searching using a regular expression
e.g. the simple exact match search
foamToC -allLibs -search VoFTurbulenceDamping
generates:
VoFTurbulenceDamping is in table
fvModel libVoFTurbulenceDamping.so
but the regular expression search
foamToC -allLibs -search "VoF.*"
generates the results for all names in all tables containing the sub-string "VoF":
VoFCavitation is in table
fvModel libVoFCavitation.so
VoFSolidificationMeltingSource is in table
fvModel libVoFSolidificationMeltingSource.so
VoFClouds is in table
fvModel libVoFClouds.so
VoFFilmTransfer is in table
fvModel libfilmVoFTransfer.so
VoFTurbulenceDamping is in table
fvModel libVoFTurbulenceDamping.so
This commit is contained in:
@ -60,8 +60,9 @@ Usage
|
||||
- \par table \<name\>
|
||||
List the contents of the specified table or the list sub-tables
|
||||
|
||||
- \par search \<name\>
|
||||
Search for and list the tables containing the given entry
|
||||
- \par search \<name\> or \"\<regular expression\>\"
|
||||
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<scalar>)
|
||||
@ -373,72 +374,118 @@ int main(int argc, char *argv[])
|
||||
word name;
|
||||
if (args.optionReadIfPresent("search", name))
|
||||
{
|
||||
HashTable<HashTable<word>> 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<word> unsortedNames;
|
||||
|
||||
forAllConstIter
|
||||
(
|
||||
debug::runTimeSelectionToCType,
|
||||
debug::runTimeSelectionToC,
|
||||
iter
|
||||
)
|
||||
{
|
||||
if (!baseTypeNameTables.found(baseTypeName))
|
||||
forAllConstIter(HashTable<word>, iter().second(), iter2)
|
||||
{
|
||||
baseTypeNameTables.insert(baseTypeName, HashTable<word>());
|
||||
}
|
||||
|
||||
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<HashTable<word>> 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<word>()
|
||||
);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user