MCPcopy Create free account
hub / github.com/SoarGroup/Soar / DoSource

Method DoSource

Core/CLI/src/cli_source.cpp:88–249  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

86}
87
88bool CommandLineInterface::DoSource(std::string path, SourceBitset* pOptions)
89{
90 if (m_SourceFileStack.size() >= 100)
91 {
92 return SetError("Source depth (100) exceeded, possible recursive source.");
93 }
94
95 normalize_separators(path);
96
97 // Separate the path out of the filename if any
98 std::string filename;
99 std::string folder;
100 std::string::size_type lastSeparator = path.rfind('/');
101 if (lastSeparator == std::string::npos)
102 {
103 filename.assign(path);
104 }
105 else
106 {
107 ++lastSeparator;
108 if (lastSeparator < path.length())
109 {
110 folder = path.substr(0, lastSeparator);
111 filename.assign(path.substr(lastSeparator, path.length() - lastSeparator));
112 }
113 }
114
115 if (!folder.empty()) if (!DoPushD(folder))
116 {
117 return false;
118 }
119
120 FILE* pFile = fopen(filename.c_str() , "rb");
121 if (!pFile)
122 {
123 if (!folder.empty())
124 {
125 DoPopD();
126 }
127 return SetError("Failed to open file for reading: " + path);
128 }
129
130 // obtain file size:
131 fseek(pFile, 0, SEEK_END);
132 long lSize = ftell(pFile);
133 rewind(pFile);
134
135 // allocate memory to contain the whole file:
136 char* buffer = reinterpret_cast<char*>(malloc(sizeof(char) * (lSize + 1)));
137 if (!buffer)
138 {
139 if (!folder.empty())
140 {
141 DoPopD();
142 }
143 path.insert(0, "Memory allocation failed: ");
144 fclose(pFile);
145 return SetError("Failed to open file for reading: " + path);

Callers 1

ParseMethod · 0.45

Calls 13

SetErrorFunction · 0.85
lengthMethod · 0.80
RegisterWithKernelMethod · 0.80
pushMethod · 0.80
popMethod · 0.80
endMethod · 0.80
UnregisterWithKernelMethod · 0.80
normalize_separatorsFunction · 0.50
sizeMethod · 0.45
insertMethod · 0.45
clearMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected