Test-fileNameClean.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Application
25  fileNameCleanTest
26 
27 Description
28 
29 
30 \*---------------------------------------------------------------------------*/
31 
32 #include "argList.H"
33 #include "fileName.H"
34 #include "SubList.H"
35 #include "IOobject.H"
36 #include "IOstreams.H"
37 #include "OSspecific.H"
38 
39 
40 using namespace Foam;
41 
42 void printCleaning(fileName& pathName)
43 {
44  Info<< "fileName = " << pathName << nl
45  << " path() = " << pathName.path() << nl
46  << " name() = " << pathName.name() << nl
47  << " joined = " << pathName.path()/pathName.name() << nl << nl;
48 
49  pathName.clean();
50 
51  Info<< "cleaned = " << pathName << nl
52  << " path() = " << pathName.path() << nl
53  << " name() = " << pathName.name() << nl
54  << " joined = " << pathName.path()/pathName.name() << nl << nl;
55 
57 }
58 
59 
60 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
61 // Main program:
62 
63 int main(int argc, char *argv[])
64 {
67  argList::validArgs.insert("fileName .. fileNameN");
68  argList::addOption("istream", "fileName", "test Istream values");
69 
70  argList args(argc, argv, false, true);
71 
72  if (args.size() <= 1 && args.options().empty())
73  {
74  args.printUsage();
75  }
76 
77  fileName pathName;
78  if (args.optionReadIfPresent("case", pathName))
79  {
80  Info<< nl
81  << "-case" << nl
82  << "path = " << args.path() << nl
83  << "root = " << args.rootPath() << nl
84  << "case = " << args.caseName() << nl
85  << "FOAM_CASE=" << getEnv("FOAM_CASE") << nl
86  << "FOAM_CASENAME=" << getEnv("FOAM_CASENAME") << nl
87  << endl;
88 
89  printCleaning(pathName);
90  }
91 
92  for (label argI=1; argI < args.size(); ++argI)
93  {
94  pathName = args[argI];
95  printCleaning(pathName);
96  }
97 
98  if (args.optionFound("istream"))
99  {
100  args.optionLookup("istream")() >> pathName;
101 
102  Info<< nl
103  << "-case" << nl
104  << "path = " << args.path() << nl
105  << "root = " << args.rootPath() << nl
106  << "case = " << args.caseName() << nl
107  << "FOAM_CASE=" << getEnv("FOAM_CASE") << nl
108  << "FOAM_CASENAME=" << getEnv("FOAM_CASENAME") << nl
109  << endl;
110 
111  printCleaning(pathName);
112  }
113 
114  Info<< "\nEnd\n" << endl;
115  return 0;
116 }
117 
118 
119 // ************************************************************************* //
Foam::argList::validArgs
static SLList< string > validArgs
A list of valid (mandatory) arguments.
Definition: argList.H:143
Foam::argList::noBanner
static void noBanner()
Disable emitting the banner information.
Definition: argList.C:155
OSspecific.H
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
IOstreams.H
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
SubList.H
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::argList::addOption
static void addOption(const word &opt, const string &param="", const string &usage="")
Add to an option to validOptions with usage information.
Definition: argList.C:108
Foam::argList::size
label size() const
Return the number of arguments.
Definition: argListI.H:84
Foam::fileName::path
fileName path() const
Return directory path name (part before last /)
Definition: fileName.C:293
Foam::argList
Extract command arguments and options from the supplied argc and argv parameters.
Definition: argList.H:97
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::argList::rootPath
const fileName & rootPath() const
Return root path.
Definition: argListI.H:36
Foam::fileName::name
word name() const
Return file name (part beyond last /)
Definition: fileName.C:212
Foam::argList::options
const Foam::HashTable< string > & options() const
Return options.
Definition: argListI.H:90
Foam::getEnv
string getEnv(const word &)
Return environment variable of given name.
Definition: POSIX.C:101
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
main
int main(int argc, char *argv[])
Definition: Test-fileNameClean.C:60
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::Info
messageStream Info
argList.H
fileName.H
Foam::argList::printUsage
void printUsage() const
Print usage.
Definition: argList.C:1045
Foam::argList::path
fileName path() const
Return the path to the caseName.
Definition: argListI.H:60
IOobject.H
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::IOobject::writeDivider
static Stream & writeDivider(Stream &os)
Write the standard file section divider.
Definition: IOobjectI.H:108
Foam::argList::optionFound
bool optionFound(const word &opt) const
Return true if the named option is found.
Definition: argListI.H:108
Foam::argList::caseName
const fileName & caseName() const
Return case name (parallel run) or global case (serial run)
Definition: argListI.H:42
Foam::fileName::clean
bool clean()
Cleanup file name.
Definition: fileName.C:97
Foam::argList::noParallel
static void noParallel()
Remove the parallel options.
Definition: argList.C:161
args
Foam::argList args(argc, argv)
Foam::argList::optionReadIfPresent
bool optionReadIfPresent(const word &opt, T &) const
Read a value from the named option if present.
Definition: argListI.H:198
printCleaning
void printCleaning(fileName &pathName)
Definition: Test-fileNameClean.C:39
Foam::argList::optionLookup
IStringStream optionLookup(const word &opt) const
Return an IStringStream from the named option.
Definition: argListI.H:114