MCPcopy Create free account
hub / github.com/Kitware/CMake / HandleReadCommand

Function HandleReadCommand

Source/cmFileCommand.cxx:160–259  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

158}
159
160bool HandleReadCommand(std::vector<std::string> const& args,
161 cmExecutionStatus& status)
162{
163 if (args.size() < 3) {
164 status.SetError("READ must be called with at least two additional "
165 "arguments");
166 return false;
167 }
168
169 std::string const& fileNameArg = args[1];
170 std::string const& variable = args[2];
171
172 struct Arguments
173 {
174 std::string Offset;
175 std::string Limit;
176 bool Hex = false;
177 };
178
179 static auto const parser = cmArgumentParser<Arguments>{}
180 .Bind("OFFSET"_s, &Arguments::Offset)
181 .Bind("LIMIT"_s, &Arguments::Limit)
182 .Bind("HEX"_s, &Arguments::Hex);
183
184 Arguments const arguments = parser.Parse(cmMakeRange(args).advance(3),
185 /*unparsedArguments=*/nullptr);
186
187 std::string fileName = fileNameArg;
188 if (!cmsys::SystemTools::FileIsFullPath(fileName)) {
189 fileName = cmStrCat(status.GetMakefile().GetCurrentSourceDirectory(), '/',
190 fileNameArg);
191 }
192
193// Open the specified file.
194#if defined(_WIN32) || defined(__CYGWIN__)
195 cmsys::ifstream file(fileName.c_str(),
196 arguments.Hex ? (std::ios::binary | std::ios::in)
197 : std::ios::in);
198#else
199 cmsys::ifstream file(fileName.c_str());
200#endif
201
202 if (!file) {
203 std::string error =
204 cmStrCat("failed to open for reading (",
205 cmSystemTools::GetLastSystemError(), "):\n ", fileName);
206 status.SetError(error);
207 return false;
208 }
209
210 // is there a limit?
211 std::string::size_type sizeLimit = std::string::npos;
212 if (!arguments.Limit.empty()) {
213 unsigned long long limit;
214 if (cmStrToULongLong(arguments.Limit, &limit)) {
215 sizeLimit = static_cast<std::string::size_type>(limit);
216 }
217 }

Callers

nothing calls this directly

Calls 15

cmMakeRangeFunction · 0.85
cmStrToULongLongFunction · 0.85
cmStrToLongLongFunction · 0.85
c_strMethod · 0.80
cmStrCatFunction · 0.70
snprintfFunction · 0.50
sizeMethod · 0.45
SetErrorMethod · 0.45
BindMethod · 0.45
ParseMethod · 0.45
advanceMethod · 0.45
GetMakefileMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…