ENH: support search modes for etcFiles()

- similar to the foamEtcFile script -mode=... option, the specific
  search location (user/group/other) can now also specified for
  string expansions and as a numerical value for etcFile()

  For example, if searching for group or other (project) controlDict,
  but not wishing to see the user controlDict:

    1.  foamEtcFile -mode=go controlDict

    2.  fileName dictFile("<etc:go>/controlDict");
        dictFile.expand();

    3.  etcFile(controlDict, false, 0077);

  The default behaviour for searching all contexts is unchanged.

    1.  foamEtcFile controlDict

    2.  fileName dictFile("<etc>/controlDict");
        dictFile.expand();

    3.  etcFile(controlDict);
This commit is contained in:
Mark Olesen
2018-12-12 13:45:32 +01:00
parent 67140f6b07
commit 172c36c29a
7 changed files with 220 additions and 71 deletions

View File

@ -219,30 +219,45 @@ namespace stringOps
// -# environment variables
// - "$VAR", "${VAR}"
// -# current directory
// - leading "./" : the current directory
// - leading "./"
// : the current directory - Foam::cwd()
// -# leading tag expansion for commonly used directories
// - \<etc\>/ : user/group/other OpenFOAM directory
// - \<case\>/ : FOAM_CASE directory
// - \<constant\>/ : FOAM_CASE/constant directory
// - \<system\>/ : FOAM_CASE/system directory
// - <b> \<etc\>/ </b>
// : user/group/other OpenFOAM etc directory
// - <b> \<etc:</b><em>[ugo]+</em>)<b>\>/ </b>
// : user/group/other etc with specified location mode
// - <b> \<case\>/ </b>
// : The \c $FOAM_CASE directory
// - <b> \<constant\>/ </b>
// : The \c $FOAM_CASE/constant directory
// - <b> \<system\>/ </b>
// : The \c $FOAM_CASE/system directory
// -# tilde expansion
// - leading "~/" : home directory
// - leading "~user" : home directory for specified user
//
// Supports default and alternative values as per the POSIX shell.
// \code
// a) "${parameter:-defValue}"
// b) "${parameter:+altValue}"
// 1. "${parameter:-defValue}"
// 2. "${parameter:+altValue}"
// \endcode
// a) If parameter is unset or null, the \c defValue is substituted.
// Otherwise, the value of parameter is substituted.
//
// b) If parameter is unset or null, nothing is substituted.
// Otherwise the \c altValue is substituted.
// -# If parameter is unset or null, the \c defValue is substituted.
// Otherwise, the value of parameter is substituted.
// -# If parameter is unset or null, nothing is substituted.
// Otherwise the \c altValue is substituted.
// .
//
// General behavior:
// - Any unknown entries are removed silently, if allowEmpty is true.
// - Malformed entries (eg, brace mismatch, sigil followed by bad chars)
// are left as is.
// are left as is.
//
// An example of using the specified location mode
// \code
// fileName controlDict(stringOps::expand("<etc:o>/controlDict"));
// // OR
// fileName controlDict(findEtcFile("controlDict", false, 0007));
// \endcode
//
// \note Deprecated(2018-11) Use "<etc>" instead of the rarely used
// "~OpenFOAM" expansion
@ -263,28 +278,35 @@ namespace stringOps
// -# current directory
// - leading "./" : the current directory
// -# leading tag expansion for commonly used directories
// - \<etc\>/ : user/group/other OpenFOAM directory
// - \<case\>/ : FOAM_CASE directory
// - \<constant\>/ : FOAM_CASE/constant directory
// - \<system\>/ : FOAM_CASE/system directory
// - <b> \<etc\>/ </b>
// : user/group/other OpenFOAM etc directory
// - <b> \<etc:</b><em>[ugo]+</em>)<b>\>/ </b>
// : user/group/other etc with specified location mode
// - <b> \<case\>/ </b>
// : The \c $FOAM_CASE directory
// - <b> \<constant\>/ </b>
// : The \c $FOAM_CASE/constant directory
// - <b> \<system\>/ </b>
// : The \c $FOAM_CASE/system directory
// -# tilde expansion
// - leading "~/" : home directory
// - leading "~user" : home directory for specified user
//
// Supports default and alternative values as per the POSIX shell.
// \code
// a) "${parameter:-defValue}"
// b) "${parameter:+altValue}"
// 1. "${parameter:-defValue}"
// 2. "${parameter:+altValue}"
// \endcode
// a) If parameter is unset or null, the \c defValue is substituted.
// Otherwise, the value of parameter is substituted.
//
// b) If parameter is unset or null, nothing is substituted.
// Otherwise the \c altValue is substituted.
// -# If parameter is unset or null, the \c defValue is substituted.
// Otherwise, the value of parameter is substituted.
// -# If parameter is unset or null, nothing is substituted.
// Otherwise the \c altValue is substituted.
// .
//
// General behavior:
// - Any unknown entries are removed silently if allowEmpty is true.
// - Malformed entries (eg, brace mismatch, sigil followed by bad chars)
// are left as is.
// are left as is.
//
// \note Deprecated(2018-11) Use "<etc>" instead of the rarely used
// "~OpenFOAM" expansion