From 5dde2f5b0640ac9a7cdde533da84f47b03c7322f Mon Sep 17 00:00:00 2001
From: Mark Olesen <Mark.Olesen@esi-group.com>
Date: Thu, 12 Mar 2020 15:40:00 +0100
Subject: [PATCH] STYLE: foamCreate{Manpage,ModuleInclude} consistency with
 1912

---
 bin/tools/foamCreateManpage       | 127 +++++++++++++++++++++---------
 bin/tools/foamCreateModuleInclude |   8 +-
 2 files changed, 97 insertions(+), 38 deletions(-)

diff --git a/bin/tools/foamCreateManpage b/bin/tools/foamCreateManpage
index 29e38fdb90c..615a16208ad 100755
--- a/bin/tools/foamCreateManpage
+++ b/bin/tools/foamCreateManpage
@@ -3,9 +3,11 @@
 # =========                 |
 # \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
 #  \\    /   O peration     |
-#   \\  /    A nd           | Copyright (C) 2018 OpenCFD Ltd.
+#   \\  /    A nd           | www.openfoam.com
 #    \\/     M anipulation  |
 #------------------------------------------------------------------------------
+#     Copyright (C) 2018-2019 OpenCFD Ltd.
+#------------------------------------------------------------------------------
 # License
 #     This file is part of OpenFOAM, licensed under GNU General Public License
 #     <http://www.gnu.org/licenses/>.
@@ -26,10 +28,11 @@ usage() {
 
 Usage: ${0##*/} [OPTION] [appName .. [appNameN]]
 options:
-  -dir dir          Directory to process
-  -gzip             Compressed output
-  -o DIR            Write to alternative output directory
-  -version VER      Specify an alternative version
+  -dir=DIR          Input directory to process
+  -output=DIR       Write to alternative output directory
+  -pdf              Process as nroff man content and pass to ps2pdf
+  -gz | -gzip       Compress manpage output
+  -version=VER      Specify an alternative version
   -h | -help        Print the usage
 
 Query OpenFOAM applications with -help-man for their manpage content
@@ -37,9 +40,9 @@ and redirect to corresponding directory location.
 Default input:  \$FOAM_APPBIN only.
 Default output: $defaultOutputDir
 
-Uses the search directory if applications are specified.
+Uses the search directory if individual applications are specified.
 
-Copyright (C) 2018 OpenCFD Ltd.
+Copyright (C) 2018-2019 OpenCFD Ltd.
 USAGE
     exit 1
 }
@@ -57,9 +60,18 @@ die()
     exit 1
 }
 
+# Get the option's value (argument), or die on missing or empty argument
+# $1 option
+# $2 value
+getOptionValue()
+{
+   [ -n "$2" ] || die "'$1' option requires an argument"
+   echo "$2"
+}
+
 #-------------------------------------------------------------------------------
 searchDirs="$FOAM_APPBIN"
-unset gzipFilter sedFilter outputDir
+unset sedFilter outputDir outputType
 
 while [ "$#" -gt 0 ]
 do
@@ -67,24 +79,35 @@ do
     -h | -help*)
         usage
         ;;
-    -d | -dir)
-        [ "$#" -ge 2 ] || die "'$1' option requires an argument"
-        searchDirs="$2"
+    -dir=*)
+        searchDirs="${1#*=}"
+        [ -d "$searchDirs" ] || die "directory not found '$searchDirs'"
+        ;;
+    -dir)
+        searchDirs=$(getOptionValue "$@")
         [ -d "$searchDirs" ] || die "directory not found '$searchDirs'"
         shift
         ;;
     -gz | -gzip)
-        gzipFilter="gzip"
+        outputType="gz"
+        ;;
+    -pdf)
+        outputType="pdf"
         ;;
-    -v | -version)
-        [ "$#" -ge 2 ] || die "'$1' option requires an argument"
-        version="$2"
+    -version=*)
+        version="${1#*=}"
+        sedFilter='s/OpenFOAM-[^\"]*/OpenFOAM-'"$version/"
+        ;;
+    -version)
+        version=$(getOptionValue "$@")
         sedFilter='s/OpenFOAM-[^\"]*/OpenFOAM-'"$version/"
         shift
         ;;
-    -o | -output)
-        [ "$#" -ge 2 ] || die "'$1' option requires an argument"
-        outputDir="$2"
+    -output=*)
+        outputDir="${1#*=}"
+        ;;
+    -output)
+        outputDir=$(getOptionValue "$@")
         shift
         ;;
     -*)
@@ -97,7 +120,7 @@ do
     shift
 done
 
-: ${outputDir:=$defaultOutputDir}
+: "${outputDir:=$defaultOutputDir}"
 
 # Verify that output is writeable
 if [ -e "$outputDir" ]
@@ -105,47 +128,79 @@ then
     [ -d "$outputDir" ] && [ -w "$outputDir" ] || \
         die "Cannot write to $outputDir" "Not a directory, or no permission?"
 else
-    mkdir -p "$outputDir" || \
+    mkdir -p "$outputDir" 2>/dev/null || \
         die "Cannot create directory: $outputDir"
 fi
 
-#-------------------------------------------------------------------------------
+echo "Generating manpages from OpenFOAM applications" 1>&2
+echo 1>&2
+
+# Use a tmp file so that we confirm that the content was
+# generated and looks somewhat like a manpage (has a SYNOPSIS)
+tmpFile="$outputDir/${0##*/}-tmp$$"
+trap "rm -fv $tmpFile 2>/dev/null; exit 0" EXIT TERM INT
 
-# Pass through content, filter for version and/or gzip
-#
 
-tmpFile="$outputDir/${0##*/}"
-trap "rm -fv $tmpFile >/dev/null; exit 0" EXIT TERM INT
+# Any special filter requirements?
+# Default extension is "1" for manpage
+outputExt="1"
+
+case "$outputType" in
+    pdf)
+        outputExt="pdf"
+        command -v groff  >/dev/null || die "Missing program: groff"
+        command -v ps2pdf >/dev/null || die "Missing program: ps2pdf"
+        ;;
+    gz)
+        outputExt="1.gz"
+        command -v gzip   >/dev/null || die "Missing program: gzip"
+    ;;
+esac
+
+
+#-------------------------------------------------------------------------------
 
+# Get nroff man content from application, store in tmp file for checking
+# and output / filter
+# 1 = application
 process()
 {
     local appName="$1"
-    local outFile="$outputDir/${appName##*/}.1"
+    local outFile="$outputDir/${appName##*/}"
 
     rm -f "$outFile"*;
 
-    "$appName" -help-man 2>/dev/null >| $tmpFile;
+    "$appName" -help-man | sed -e "${sedFilter}" 2>/dev/null >| "$tmpFile"
 
+    # Check that it looks ok
     if grep -F -q "SYNOPSIS" "$tmpFile" 2>/dev/null
     then
-        cat "$tmpFile" | \
-            sed -e "${sedFilter}" | "${gzipFilter:-cat}" \
-            >| "$outFile${gzipFilter:+.gz}"
+        case "$outputType" in
+        pdf)
+            groff -man "$tmpFile" | ps2pdf - "$outFile.$outputExt"
+            ;;
 
-        echo "$outFile${gzipFilter:+.gz}" 1>&2
+        gz)
+            gzip -c "$tmpFile" >| "$outFile.$outputExt"
+            ;;
+
+        *)
+            \cp -f "$tmpFile" "$outFile.$outputExt"
+            ;;
+        esac
+
+        echo "$outFile.$outputExt" 1>&2
     else
-        echo "Problem with $appName" 1>&2
+        echo "Problem with ${appName##*/}" 1>&2
     fi
 }
 
+
 #------------------------------------------------------------------------------
 
 # Default to standard search directories
 [ "$#" -gt 0 ] || set -- ${searchDirs}
 
-echo "Generating manpages from OpenFOAM applications" 1>&2
-echo 1>&2
-
 for item
 do
     if [ -d "$item" ]
@@ -157,7 +212,7 @@ do
         do
             process $appName
         done
-    elif command -v "$item" > /dev/null 2>&1
+    elif command -v "$item" >/dev/null
     then
         process $item
     else
diff --git a/bin/tools/foamCreateModuleInclude b/bin/tools/foamCreateModuleInclude
index 7074ad5c965..dd616ae30d1 100755
--- a/bin/tools/foamCreateModuleInclude
+++ b/bin/tools/foamCreateModuleInclude
@@ -3,8 +3,11 @@
 # =========                 |
 # \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
 #  \\    /   O peration     |
-#   \\  /    A nd           | Copyright (C) 2017-2019 OpenCFD Ltd.
-#    \\/     M anipulation  | Copyright (C) 2016-2017 CINECA
+#   \\  /    A nd           | www.openfoam.com
+#    \\/     M anipulation  |
+#------------------------------------------------------------------------------
+#     Copyright (C) 2016-2017 CINECA
+#     Copyright (C) 2017-2019 OpenCFD Ltd.
 #------------------------------------------------------------------------------
 # License
 #     This file is part of OpenFOAM.
@@ -263,6 +266,7 @@ unalias wmDP        2>/dev/null
 unalias wmInt32     2>/dev/null
 unalias wmInt64     2>/dev/null
 unalias wmSP        2>/dev/null
+unalias wmSPDP      2>/dev/null
 unalias wmSchedOff  2>/dev/null
 unalias wmSchedOn   2>/dev/null
 unalias wmSet       2>/dev/null
-- 
GitLab