Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
CMake
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Mattias Ellert
CMake
Commits
372d2cbe
Commit
372d2cbe
authored
21 years ago
by
Andy Cedilnik
Browse files
Options
Downloads
Patches
Plain Diff
ENH: Start working on a general file manipulation command
parent
197368d9
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
Source/cmCommands.cxx
+2
-0
2 additions, 0 deletions
Source/cmCommands.cxx
Source/cmFileCommand.cxx
+113
-0
113 additions, 0 deletions
Source/cmFileCommand.cxx
Source/cmFileCommand.h
+88
-0
88 additions, 0 deletions
Source/cmFileCommand.h
with
203 additions
and
0 deletions
Source/cmCommands.cxx
+
2
−
0
View file @
372d2cbe
...
...
@@ -34,6 +34,7 @@
#include
"cmEndForEachCommand.cxx"
#include
"cmEndIfCommand.cxx"
#include
"cmExecProgramCommand.cxx"
#include
"cmFileCommand.cxx"
#include
"cmFindFileCommand.cxx"
#include
"cmFindLibraryCommand.cxx"
#include
"cmFindPackageCommand.cxx"
...
...
@@ -125,6 +126,7 @@ void GetPredefinedCommands(std::list<cmCommand*>& commands)
commands
.
push_back
(
new
cmEndForEachCommand
);
commands
.
push_back
(
new
cmEndIfCommand
);
commands
.
push_back
(
new
cmExecProgramCommand
);
commands
.
push_back
(
new
cmFileCommand
);
commands
.
push_back
(
new
cmFindFileCommand
);
commands
.
push_back
(
new
cmFindLibraryCommand
);
commands
.
push_back
(
new
cmFindPackageCommand
);
...
...
This diff is collapsed.
Click to expand it.
Source/cmFileCommand.cxx
0 → 100644
+
113
−
0
View file @
372d2cbe
/*=========================================================================
Program: CMake - Cross-Platform Makefile Generator
Module: $RCSfile$
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#include
"cmFileCommand.h"
// cmLibraryCommand
bool
cmFileCommand
::
InitialPass
(
std
::
vector
<
std
::
string
>
const
&
args
)
{
if
(
args
.
size
()
<
2
)
{
this
->
SetError
(
"must be called with at least two arguments."
);
return
false
;
}
std
::
string
subCommand
=
args
[
0
];
if
(
subCommand
==
"WRITE"
)
{
return
this
->
HandleWriteCommand
(
args
,
false
);
}
else
if
(
subCommand
==
"APPEND"
)
{
return
this
->
HandleWriteCommand
(
args
,
true
);
}
else
if
(
subCommand
==
"READ"
)
{
return
this
->
HandleReadCommand
(
args
);
}
std
::
string
e
=
"does not recognize sub-command "
+
subCommand
;
this
->
SetError
(
e
.
c_str
());
return
true
;
}
//----------------------------------------------------------------------------
bool
cmFileCommand
::
HandleWriteCommand
(
std
::
vector
<
std
::
string
>
const
&
args
,
bool
append
)
{
std
::
string
message
;
std
::
vector
<
std
::
string
>::
const_iterator
i
=
args
.
begin
();
i
++
;
// Get rid of subcommand
std
::
string
fileName
=
*
i
;
i
++
;
for
(;
i
!=
args
.
end
();
++
i
)
{
message
+=
*
i
;
}
std
::
string
dir
=
cmSystemTools
::
GetFilenamePath
(
fileName
);
cmSystemTools
::
MakeDirectory
(
dir
.
c_str
());
std
::
ofstream
file
(
fileName
.
c_str
(),
append
?
std
::
ios
::
app
:
std
::
ios
::
out
);
if
(
!
file
)
{
std
::
string
error
=
"Internal CMake error when trying to open file: "
;
error
+=
fileName
.
c_str
();
error
+=
" for writting."
;
this
->
SetError
(
error
.
c_str
());
return
false
;
}
file
<<
message
<<
std
::
endl
;
file
.
close
();
return
true
;
}
//----------------------------------------------------------------------------
bool
cmFileCommand
::
HandleReadCommand
(
std
::
vector
<
std
::
string
>
const
&
args
)
{
if
(
args
.
size
()
!=
3
)
{
this
->
SetError
(
"READ must be called with two additional arguments"
);
}
std
::
string
fileName
=
args
[
1
];
std
::
string
variable
=
args
[
2
];
std
::
ifstream
file
(
fileName
.
c_str
(),
std
::
ios
::
in
);
if
(
!
file
)
{
std
::
string
error
=
"Internal CMake error when trying to open file: "
;
error
+=
fileName
.
c_str
();
error
+=
" for reading."
;
this
->
SetError
(
error
.
c_str
());
return
false
;
}
std
::
string
output
;
std
::
string
line
;
bool
has_newline
=
false
;
while
(
cmSystemTools
::
GetLineFromStream
(
file
,
line
,
&
has_newline
)
)
{
output
+=
line
;
if
(
has_newline
)
{
output
+=
"
\n
"
;
}
}
m_Makefile
->
AddDefinition
(
variable
.
c_str
(),
output
.
c_str
());
return
true
;
}
This diff is collapsed.
Click to expand it.
Source/cmFileCommand.h
0 → 100644
+
88
−
0
View file @
372d2cbe
/*=========================================================================
Program: CMake - Cross-Platform Makefile Generator
Module: $RCSfile$
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef cmFileCommand_h
#define cmFileCommand_h
#include
"cmStandardIncludes.h"
#include
"cmCommand.h"
/** \class cmFileCommand
* \brief Command for manipulation of files
*
*/
class
cmFileCommand
:
public
cmCommand
{
public:
/**
* This is a virtual constructor for the command.
*/
virtual
cmCommand
*
Clone
()
{
return
new
cmFileCommand
;
}
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
virtual
bool
InitialPass
(
std
::
vector
<
std
::
string
>
const
&
args
);
/**
* This determines if the command gets propagated down
* to makefiles located in subdirectories.
*/
virtual
bool
IsInherited
()
{
return
true
;}
/**
* The name of the command as specified in CMakeList.txt.
*/
virtual
const
char
*
GetName
()
{
return
"FILE"
;}
/**
* Succinct documentation.
*/
virtual
const
char
*
GetTerseDocumentation
()
{
return
"File manipulation command."
;
}
/**
* More documentation.
*/
virtual
const
char
*
GetFullDocumentation
()
{
return
" FILE(WRITE filename
\"
message to write
\"
... )
\n
"
" FILE(APPEND filename
\"
message to write
\"
... )
\n
"
" FILE(READ filename variable)
\n
"
"WRITE will write a message into a file called 'filename'. It "
"overwrites the file if it already exists, and creates the file "
"if it does not exists.
\n\n
"
"APPEND will write a message into a file same as WRITE, except "
"it will append it to the end of the file
\n\n
"
"READ will read the content of a file and store it into a "
"variable.
\n\n
"
;
}
cmTypeMacro
(
cmFileCommand
,
cmCommand
);
protected
:
bool
HandleWriteCommand
(
std
::
vector
<
std
::
string
>
const
&
args
,
bool
append
);
bool
HandleReadCommand
(
std
::
vector
<
std
::
string
>
const
&
args
);
};
#endif
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment