Skip to content
Snippets Groups Projects
Commit e2148b58 authored by Mark OLESEN's avatar Mark OLESEN
Browse files

CONFIG: inline _foamEval within <etc/config.sh/setup>

- previously a function (unlike the csh version) but since bashrc and
  setup have been split -> replace with inline definition

STYLE: formatting/wording for openfoam starters

TUT: simplify controlDict modification, add default substitution

ENH: accept '/' for end-of-options terminator (etc/openfoam)

- makes the application or service more apparent.
  * eg.  /usr/bin/openfoam / blockMesh
  * vs.  /usr/bin/openfoam -- blockMesh

  Accept lone '-' as the end-of-options terminator, as per bash

- Adjust handling of openfoam '-c' option to flag that a command-string
  will appear, but continue with option parsing.
  Consistent with bash definition.
parent 7d2a9fad
Branches
Tags
No related merge requests found
......@@ -151,10 +151,10 @@ modifyCaseControlDict()
do
cp -f "${dict}" "${dict}.orig"
sed \
-e 's/\(startFrom[ \t]*\)\([A-Za-z]*\);/\1 latestTime;/' \
-e 's/\(stopAt[ \t]*\)\([A-Za-z]*\);/\1 nextWrite;/' \
-e 's/\(writeControl[ \t]*\)\([A-Za-z]*\);/\1 timeStep;/' \
-e 's/\(writeInterval[ \t]*\)\([-.0-9A-Za-z]*\);/\1 '"$optRunLimit"';/' \
-e 's/\(startFrom[ \t]*\)[^ \t;]*;/\1 latestTime;/' \
-e 's/\(stopAt[ \t]*\)[^ \t;]*;/\1 nextWrite;/' \
-e 's/\(writeControl[ \t]*\)[^ \t;]*;/\1 timeStep;/' \
-e 's/\(writeInterval[ \t]*\)[^ \t;]*;/\1 '"${optRunLimit:-1}"';/' \
"${dict}.orig" > "${dict}"
done
}
......
#!/bin/sh
exec "@PROJECT_DIR@"/etc/openfoam "$@"
#------------------------------------------------------------------------------
# ========= |
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
# \\ / O peration |
# \\ / A nd | www.openfoam.com
# \\/ M anipulation |
#------------------------------------------------------------------------------
# Copyright (C) 2020 OpenCFD Ltd.
#------------------------------------------------------------------------------
# License
# This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
# OpenFOAM file (www.openfoam.com)
#
# Copyright (C) 2020-2021 OpenCFD Ltd.
# SPDX-License-Identifier: (GPL-3.0+)
#
# Description
# Forwarding to OpenFOAM etc/openfoam bash session script.
# Uses a hard-code directory path (eg, generated with autoconfig).
# Forward to OpenFOAM etc/openfoam bash session script.
# Uses hard-coded directory path.
#
#------------------------------------------------------------------------------
......@@ -5,7 +5,7 @@
# \\ / A nd | www.openfoam.com
# \\/ M anipulation |
#------------------------------------------------------------------------------
# Copyright (C) 2018-2020 OpenCFD Ltd.
# Copyright (C) 2018-2021 OpenCFD Ltd.
#------------------------------------------------------------------------------
# License
# This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
......@@ -105,7 +105,10 @@ while ( $#argv > 0 )
switch ($argv[1])
case -*:
# Stray option (not meant for us here) -> get out
break
break # Break while
breaksw
case =*:
# Junk
breaksw
case *=:
# name= -> unsetenv name
......
......@@ -6,7 +6,7 @@
# \\/ M anipulation |
#------------------------------------------------------------------------------
# Copyright (C) 2011-2016 OpenFOAM Foundation
# Copyright (C) 2017-2020 OpenCFD Ltd.
# Copyright (C) 2017-2021 OpenCFD Ltd.
#------------------------------------------------------------------------------
# License
# This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
......@@ -159,45 +159,6 @@ then
fi
# Evaluate command-line parameters
unset -f _foamEval 2>/dev/null
_foamEval()
{
for i
do
case "$i" in
-*)
# Stray option (not meant for us here) -> get out
break
;;
*=)
# name= -> unset name
[ -n "$FOAM_VERBOSE" ] && [ -n "$PS1" ] \
&& echo "unset ${1%=}" 1>&2
eval "unset ${1%=}"
;;
*=*)
# name=value -> export name=value
[ -n "$FOAM_VERBOSE" ] && [ -n "$PS1" ] \
&& echo "export $i" 1>&2
eval "export $i"
;;
*)
# Filename: source it
if [ -f "$i" ]
then
[ -n "$FOAM_VERBOSE" ] && [ -n "$PS1" ] \
&& echo "Using: $i" 1>&2
. "$i"
else
_foamEtc -silent "$i"
fi
;;
esac
done
}
#--------------------------------------------------------------------------
# Avoid any ThirdParty settings that may have 'leaked' into the environment
......@@ -221,7 +182,7 @@ else
# Was previously loaded/defined - now unset
unset -f _foamAddPath _foamAddMan _foamAddLib _foamAddLibAuto 2>/dev/null
unset -f _foamClean _foamEcho _foamEtc _foamEval 2>/dev/null
unset -f _foamClean _foamEcho _foamEtc 2>/dev/null
unset foamClean
unset WM_SHELL_FUNCTIONS
......
......@@ -5,7 +5,7 @@
# \\ / A nd | www.openfoam.com
# \\/ M anipulation |
#------------------------------------------------------------------------------
# Copyright (C) 2018-2020 OpenCFD Ltd.
# Copyright (C) 2018-2021 OpenCFD Ltd.
#------------------------------------------------------------------------------
# License
# This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
......@@ -106,19 +106,64 @@ then
fi
# Capture and evaluate any command-line parameters
# These can be used to set/unset values, specify additional files etc.
FOAM_SETTINGS="$@"
#----------------------------------------------------------------------------
# Evaluate the command-line parameters, which were saved as FOAM_SETTINGS.
# These can be used to set/unset values, specify additional files etc.
if [ -z "$FOAM_SETTINGS" ]
# Capture and evaluate command-line parameters
# - set/unset values, specify additional files etc.
# - parameters never start with '-'
if [ "$#" -gt 0 ] && [ "${1#-}" = "${1}" ]
then
unset FOAM_SETTINGS
FOAM_SETTINGS="$@"
if [ -n "$FOAM_SETTINGS" ]
then
export FOAM_SETTINGS
for foamVar_eval
do
case "$foamVar_eval" in
(-*)
# Stray option (not meant for us here) -> get out
break
;;
(=*)
# Junk
;;
(*=)
# name= -> unset name
[ -n "$FOAM_VERBOSE" ] && [ -n "$PS1" ] \
&& echo "unset ${foamVar_eval%=}" 1>&2
eval "unset ${foamVar_eval%=}"
;;
(*=*)
# name=value -> export name=value
[ -n "$FOAM_VERBOSE" ] && [ -n "$PS1" ] \
&& echo "export $foamVar_eval" 1>&2
eval "export $foamVar_eval"
;;
(*)
# Filename: source it
if [ -f "$foamVar_eval" ]
then
[ -n "$FOAM_VERBOSE" ] && [ -n "$PS1" ] \
&& echo "Using: $foamVar_eval" 1>&2
. "$foamVar_eval"
elif [ -n "$foamVar_eval" ]
then
_foamEtc -silent "$foamVar_eval"
fi
;;
esac
done
else
unset FOAM_SETTINGS
fi
else
export FOAM_SETTINGS
_foamEval "$@"
unset FOAM_SETTINGS
fi
unset foamVar_eval
#----------------------------------------------------------------------------
# Verify FOAM_CONFIG_ETC (from calling environment or from prefs)
if [ -n "$FOAM_CONFIG_ETC" ]
......
......@@ -31,7 +31,7 @@
# -int32 | -DWM_LABEL_SIZE=32
# -int64 | -DWM_LABEL_SIZE=64
#
# However, the '-D' options grant more flexibility. For example,
# The '-D' options grant even more flexibility. For example,
# etc/openfoam -DWM_COMPILER=Clang
#
# SeeAlso
......@@ -43,26 +43,30 @@ projectDir="$(\cd "$(dirname "${0%/*}")" && \pwd -L)"
#------------------------------------------------------------------------------
printHelp() {
cat<<USAGE
cat<<HELP_USAGE
Usage: ${0##*/} [OPTION] [application ...]
Usage: ${0##*/} [OPTION] [[--] application ...]
options:
-c command Execute shell commands with OpenFOAM environment
-Dkey[=value] Define key/value to pass as a preference
-sp Single precision
-dp Double precision
-spdp Mixed single/double precision
-int32 | -int64 The label-size
-etc=DIR Additional project etc/ directory
-prefix=DIR Alternative OpenFOAM project directory
-show-api | -version Print META-INFO api value and exit
-show-patch Print META-INFO patch value and exit
-show-prefix Print project directory and exit
-test-tutorial Forward arguments to bin/foamTestTutorial
-init=FILE Alternative initialization file (expert option)
-verbose Set FOAM_VERBOSE=true (interactive only)
-help Print the usage
-c Shell commands read from the first non-option argument
-Dkey[=value] Define key/value to pass as a preference
-sp Single precision
-dp Double precision
-spdp Mixed single/double precision
-int32 Label-size 32
-int64 Label-size 64
-etc=DIR Additional project etc/ directory
-prefix=DIR Alternative OpenFOAM project directory
-show-api Print META-INFO api value and exit
-show-patch Print META-INFO patch value and exit
-show-prefix Print project directory and exit
-test-tutorial Forward arguments to bin/foamTestTutorial
-init=FILE Alternative initialization file (expert option)
-version Same as -show-api
-verbose Set FOAM_VERBOSE=true (interactive only)
-- The end of option processing.
An argument of - or / is equivalent to --.
-help Print the usage
Open an interactive bash session with an OpenFOAM environment,
or run an OpenFOAM application (with arguments) after first sourcing
......@@ -76,7 +80,7 @@ For a persistent OpenFOAM environment, the following can be added to your
For more information: www.openfoam.com
USAGE
HELP_USAGE
exit 0 # A clean exit
}
......@@ -110,7 +114,12 @@ unset optTestTut
while [ "$#" -gt 0 ]
do
case "$1" in
-h | -help* | --help*)
('') ;;
(- | -- | /)
shift
break # Stop option parsing
;;
(-h | -help* | --help*)
printHelp
;;
-show-api | -version | --version) # Show API and exit
......@@ -130,14 +139,8 @@ do
optTestTut=true
;;
-c) # Shell command
_foamScriptCommand="$2"
[ -n "$_foamScriptCommand" ] || {
echo "$0: missing or bad command argument: $2" 1>&2
exit 1
}
shift 2
break
(-c) # Shell command
_foamScriptCommand="-c"
;;
-D*) # Define key/value to pass as preference
......@@ -175,11 +178,6 @@ do
-verbose)
export FOAM_VERBOSE=true
;;
--)
shift
break
;;
-*)
echo "$0: unknown option: '$1'" 1>&2
exit 1
......@@ -217,7 +215,14 @@ fi
unset interactive
if [ "$#" -eq 0 ] && [ -z "$_foamScriptCommand" ] && [ -z "$optTestTut" ]
if [ -n "$_foamScriptCommand" ]
then
if [ "$#" -eq 0 ]
then
echo "$0: -c: option requires an argument" 1>&2
exit 1
fi
elif [ "$#" -eq 0 ] && [ -z "$optTestTut" ]
then
interactive=true
fi
......@@ -283,16 +288,14 @@ sourceBashrc()
if [ -n "$_foamScriptCommand" ]
then
# A shell command
sourceBashrc
exec bash -c "$_foamScriptCommand" "$@"
exec bash -c "$@"
exit $? # Safety
fi
if [ -n "$optTestTut" ]
then
# Test tutorial(s)
sourceBashrc
exec "$WM_PROJECT_DIR"/bin/foamTestTutorial "$@"
exit $? # Safety
......
......@@ -71,7 +71,7 @@ while [ "$#" -gt 0 ]
do
case "$1" in
-h* | -help*) printHelp ;;
-f | -force) optForce=true ;;
-f | -force) optForce=true ;;
-root=*)
rootDir="${1#*=}"
......@@ -148,10 +148,10 @@ modifyCaseControlDict()
do
cp -f "${dict}" "${dict}.orig"
sed \
-e 's/\(startFrom[ \t]*\)\([A-Za-z]*\);/\1 latestTime;/' \
-e 's/\(stopAt[ \t]*\)\([A-Za-z]*\);/\1 nextWrite;/' \
-e 's/\(writeControl[ \t]*\)\([A-Za-z]*\);/\1 timeStep;/' \
-e 's/\(writeInterval[ \t]*\)\([-.0-9A-Za-z]*\);/\1 '"$optRunLimit"';/' \
-e 's/\(startFrom[ \t]*\)[^ \t;]*;/\1 latestTime;/' \
-e 's/\(stopAt[ \t]*\)[^ \t;]*;/\1 nextWrite;/' \
-e 's/\(writeControl[ \t]*\)[^ \t;]*;/\1 timeStep;/' \
-e 's/\(writeInterval[ \t]*\)[^ \t;]*;/\1 '"${optRunLimit:-1}"';/' \
"${dict}.orig" > "${dict}"
done
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment