MCPcopy Create free account
hub / github.com/EmbeddedRPC/erpc / openFile

Method openFile

erpcgen/src/ErpcLexer.cpp:209–260  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

207}
208
209CurrentFileInfo *ErpcLexer::openFile(const string &fileName)
210{
211 // search file in path
212 string foundFile, currentFolderPath;
213 if (!PathSearcher::getGlobalSearcher().search(fileName, PathSearcher::target_type_t::kFindFile, true, foundFile))
214 {
215 throw runtime_error(format_string("could not find input file %s in defined directories", fileName.c_str()));
216 }
217
218 if (fileName.rfind(PATH_SEP_CHAR) != string::npos)
219 {
220 int fileSepPos = foundFile.rfind(PATH_SEP_CHAR);
221 currentFolderPath = foundFile.substr(0, fileSepPos);
222 PathSearcher::getGlobalSearcher().setTempPath(currentFolderPath);
223 }
224 else
225 {
226 if (m_currentFileInfo != NULL)
227 {
228 currentFolderPath = m_currentFileInfo->m_currentFolderPath;
229 }
230 else
231 {
232 currentFolderPath = "";
233 }
234 }
235 // open file
236 ifstream *inputFile = new ifstream(foundFile.c_str(), ios_base::in | ios_base::binary);
237 if (inputFile)
238 {
239 if (!inputFile->is_open())
240 {
241 delete inputFile;
242 throw runtime_error(format_string("could not open input file %s", foundFile.c_str()));
243 }
244 }
245 else
246 {
247 throw runtime_error(format_string("could not create ifstream object from file %s", foundFile.c_str()));
248 }
249
250 /* Counting CRC16 for Generator. */
251 string str((istreambuf_iterator<char>(*inputFile)), istreambuf_iterator<char>());
252 erpc::Crc16 crc16 = erpc::Crc16(ERPC_VERSION_NUMBER);
253 m_idlCrc16 += crc16.computeCRC16(reinterpret_cast<const uint8_t *>(str.c_str()), str.size());
254
255 /* Reset state to beginning of file. */
256 inputFile->clear();
257 inputFile->seekg(0, ios::beg);
258
259 return new CurrentFileInfo(inputFile, foundFile, currentFolderPath);
260}

Callers

nothing calls this directly

Calls 7

format_stringFunction · 0.85
searchMethod · 0.80
setTempPathMethod · 0.80
Crc16Class · 0.50
computeCRC16Method · 0.45
sizeMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected