MCPcopy Create free account
hub / github.com/OpenApoc/OpenApoc / parseFile

Method parseFile

framework/fs/physfs_archiver_cue.cpp:155–221  ·  view source on GitHub ↗

Parse command while being in a FILE context

Source from the content-addressed store, hash-verified

153 }
154 // Parse command while being in a FILE context
155 bool parseFile(std::string command, std::string arg)
156 {
157 // Waiting for the "TRACK" command
158 UString cmd(command);
159 if (to_upper(cmd) != "TRACK")
160 {
161 // According to
162 // https://www.gnu.org/software/ccd2cue/manual/html_node/FILE-_0028CUE-Command_0029.html#FILE-_0028CUE-Command_0029
163 // only TRACK is allowed after FILE
164 LogError("Encountered unexpected command: \"%s\" (only TRACK is allowed)", cmd);
165 parserState = PARSER_ERROR;
166 fileType = CueFileType::FT_UNDEFINED;
167 return false;
168 }
169
170 // Read track number
171 size_t first_char = 0;
172 while ((first_char < arg.size()) && isspace(arg[first_char]))
173 {
174 first_char++;
175 }
176 size_t last_char = first_char;
177 while ((last_char < arg.size()) && isdigit(arg[last_char]))
178 {
179 last_char++;
180 }
181 int trackNumber = std::stoi(arg.substr(first_char, last_char - first_char + 1));
182
183 if (trackNumber > 1)
184 {
185 LogWarning("First track is not numbered 1 (actual number is %d)", trackNumber);
186 }
187
188 // Read track mode
189 first_char = last_char + 1;
190 last_char = arg.size() - 1;
191 while ((first_char <= last_char) && isspace(arg[first_char]))
192 {
193 first_char++;
194 }
195 while ((last_char >= first_char) && isspace(arg[last_char]))
196 {
197 last_char--;
198 }
199 UString modeStr(std::string(arg, first_char, last_char - first_char + 1));
200 trackMode = CueTrackMode::MODE_UNDEFINED;
201 modeStr = to_upper(modeStr);
202 if (modeStr == "MODE1/2048")
203 trackMode = CueTrackMode::MODE1_2048;
204 else if (modeStr == "MODE1/2352")
205 trackMode = CueTrackMode::MODE1_2352;
206 else if (modeStr == "MODE2/2048")
207 trackMode = CueTrackMode::MODE2_2048;
208 else if (modeStr == "MODE2/2324")
209 trackMode = CueTrackMode::MODE2_2324;
210 else if (modeStr == "MODE2/2336")
211 trackMode = CueTrackMode::MODE2_2336;
212 else if (modeStr == "MODE2/2352")

Callers

nothing calls this directly

Calls 2

to_upperFunction · 0.85
sizeMethod · 0.45

Tested by

no test coverage detected