diff --git a/wmake/scripts/dirToString b/wmake/scripts/dirToString new file mode 100755 index 0000000000000000000000000000000000000000..bf8f5b9093fe3dbf36daca8286e778238fd6bc4b --- /dev/null +++ b/wmake/scripts/dirToString @@ -0,0 +1,90 @@ +#!/bin/sh +#------------------------------------------------------------------------------ +# ========= | +# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox +# \\ / O peration | +# \\ / A nd | Copyright (C) 2019 OpenCFD Ltd. +# \\/ M anipulation | +#------------------------------------------------------------------------------- +# License +# This file is part of OpenFOAM, licensed under GNU General Public License +# <http://www.gnu.org/licenses/>. +# +# Script +# dirToString +# +# Usage +# dirToString path/to/file +# +# Description +# Converts a directory path into a camelCase string. +# Leading [./] characters are stripped by default. +# +# For example, +# input: dir1/dir2/dir3 +# output: dir1Dir2Dir3 +# +#------------------------------------------------------------------------------ +usage() { + exec 1>&2 + while [ "$#" -ge 1 ]; do echo "$1"; shift; done + cat<<USAGE + +Usage: ${0##*/} [OPTION] dir + +options: + -no-strip Do not ignore leading [./] characters + -strip Ignore leading [./] characters (default) + -h, -help Print the usage + +Converts a directory path into a camelCase string + +USAGE + exit 1 +} + + +#------------------------------------------------------------------------------ +# Parse arguments and options +#------------------------------------------------------------------------------ + +optStrip=true + +while [ "$#" -gt 0 ] +do + case "$1" in + # Print help + (-h | -help*) + usage + ;; + (-s | -strip) + optStrip=true + ;; + (-no-strip) + unset optStrip + ;; + (--) + shift + break + ;; + (*) + break + ;; + esac + shift +done + +if [ -z "$optStrip" ] +then + dirName="$1" +else + # Ignore any leading ./ characters + dirName="$(echo ""$1"" | sed -e 's@^[./]*@@')" +fi + +dirName=$(echo "$dirName" | \ +awk 'BEGIN{FS="";RS="/";ORS=""} {if (FNR>1) {$0=toupper(substr($0,1,1))substr($0,2)}} 1') + +echo "$dirName" + +#------------------------------------------------------------------------------ diff --git a/wmake/scripts/makeFiles b/wmake/scripts/makeFiles index ec21af1a6ef1ba2c1f5f4368b08e6a16b8865639..33203310d962422ac106c5312b4f0556e65031a1 100755 --- a/wmake/scripts/makeFiles +++ b/wmake/scripts/makeFiles @@ -33,7 +33,8 @@ # Usage : makeFiles # #------------------------------------------------------------------------------ -dirToString="${WM_DIR:-$WM_PROJECT_DIR/wmake}/platforms/$WM_ARCH$WM_COMPILER/dirToString" +scriptDir="${0%/*}" # The script dir +dirToString="$scriptDir/dirToString" if [ -r Make/files ] then @@ -60,7 +61,7 @@ do # Skip special directories ;; *) - echo "$(echo $dir | $dirToString -strip) = ${dir#./}" + echo "$($dirToString "$dir") = ${dir#./}" ;; esac done > Make/files @@ -68,7 +69,7 @@ done > Make/files for file in $(find . -name "*.[cCylLfF]" -type f -print) do - pathName=$(echo ${file%/*} | $dirToString -strip) + pathName="$($dirToString "${file%/*}")" if [ -n "$pathName" ] then diff --git a/wmake/src/Makefile b/wmake/src/Makefile index 1f2e2fe19880349b730884f1a5b27983a38d3e80..feb4bb248e19848d3a1ff85685c8818e5f0fa9b9 100644 --- a/wmake/src/Makefile +++ b/wmake/src/Makefile @@ -2,7 +2,7 @@ # ========= | # \\ / F ield | OpenFOAM: The Open Source CFD Toolbox # \\ / O peration | -# \\ / A nd | +# \\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd. # \\/ M anipulation | #------------------------------------------------------------------------------ # | Copyright (C) 2011-2016 OpenFOAM Foundation @@ -62,8 +62,6 @@ include $(GENERAL_RULES)/general .PHONY: all clean all: \ - $(WMAKE_BIN)/dirToString$(EXT_EXE) \ - $(WMAKE_BIN)/wmkdep$(EXT_EXE) \ $(WMAKE_BIN)/wmkdepend$(EXT_EXE) @echo "built wmake-bin for $(WM_ARCH)$(WM_COMPILER)" @@ -72,11 +70,6 @@ clean: @rm -rf $(WMAKE_BIN) 2>/dev/null @rmdir $(shell dirname $(WMAKE_BIN)) 2>/dev/null || true -$(WMAKE_BIN)/dirToString$(EXT_EXE): dirToString.c - @mkdir -p $(WMAKE_BIN) - $(call QUIET_MESSAGE,compile,$(<F)) - $E $(cc) $(cFLAGS) $(<F) -o $@ - $(WMAKE_BIN)/wmkdep$(EXT_EXE): wmkdep.l @mkdir -p $(WMAKE_BIN) $(call QUIET_MESSAGE,flex,$(<F)) diff --git a/wmake/src/dirToString.c b/wmake/src/dirToString.c deleted file mode 100644 index 6e2f7541ca6adf06acb4b0d69475697a0302ce73..0000000000000000000000000000000000000000 --- a/wmake/src/dirToString.c +++ /dev/null @@ -1,115 +0,0 @@ -/*----------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 2017 OpenCFD Ltd. - \\/ M anipulation | -------------------------------------------------------------------------------- - | Copyright (C) 2011 OpenFOAM Foundation -------------------------------------------------------------------------------- -License - This file is part of OpenFOAM. - - OpenFOAM is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - OpenFOAM is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - for more details. - - You should have received a copy of the GNU General Public License - along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. - -Application - dirToString - -Description - Converts a directory path into a camelCase string. - e.g. dir1/dir2/dir3 becomes dir1Dir2Dir3 - -Usage - echo dirName | dirToString - - e.g. - using sh - baseDirName=$(echo $dir | $bin/dirToString -strip) - - using csh - set baseDirName=`echo $dir | $bin/dirToString -strip` - -\*----------------------------------------------------------------------------*/ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <ctype.h> - -/* The executable name (for messages), without requiring access to argv[] */ -#define EXENAME "dirToString" - -int main(int argc, char* argv[]) -{ - int c; - - if (argc > 1) - { - if (!strncmp(argv[1], "-h", 2)) - { - /* Option: -h, -help */ - - fputs - ( - "\nUsage: " EXENAME - " [-strip]\n\n" - " -strip ignore leading [./] characters.\n\n" - "Converts a directory path into a camelCase string\n\n", - stderr - ); - return 0; - } - - if (!strcmp(argv[1], "-s") || !strcmp(argv[1], "-strip")) - { - /* Option: -s, -strip */ - - while ((c=getchar()) != EOF && (c == '.' || c == '/')) - { - /* nop */ - } - - if (c == EOF) - { - return 0; - } - - putchar(c); - } - } - - - int nextUpper = 0; - while ((c = getchar()) != EOF) - { - if (c == '/') - { - nextUpper = 1; - } - else if (nextUpper) - { - putchar(toupper(c)); - nextUpper = 0; - } - else - { - putchar(c); - } - } - - return 0; -} - - -/*****************************************************************************/