MCPcopy Create free account
hub / github.com/CruiserOne/Astrolog / FProcessSwitchFile

Function FProcessSwitchFile

io.cpp:234–291  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

232// handle, run through each line as a series of command switches.
233
234flag FProcessSwitchFile(CONST char *szFile, FILE *file)
235{
236 char rgchLine[cchSzLine], *argv[MAXSWITCHES], *szLine = rgchLine, *szNew, ch;
237 int argc, cchLine = cchSzLine, i;
238 flag fHaveFile, fRet = fFalse;
239
240 // Open a file if don't already have one.
241 fHaveFile = (file != NULL);
242 if (!fHaveFile) {
243 file = FileOpen(szFile, 0, NULL);
244 if (file == NULL)
245 goto LDone;
246 }
247 is.fileIn = file;
248
249 // All files have to begin with the -@ switch file type identifier.
250 ch = getc(file); ungetc(ch, file);
251 if (ch != '@') {
252 sprintf(szLine,
253 "The command file '%s' is not in any valid format (character %d).",
254 szFile, (int)ch);
255 PrintWarning(szLine);
256 goto LDone;
257 }
258
259 // Read the file one line at a time.
260 loop {
261 while (!feof(file) && (ch = getbyte()) < ' ')
262 ;
263 if (feof(file))
264 break;
265 for (szLine[0] = ch, i = 1; !feof(file); i++) {
266 if (i >= cchLine-1) {
267 // Double the size of the buffer if the line overfills it.
268 szNew = (char *)RgReallocate(szLine, cchLine, sizeof(char), cchLine*2,
269 "line");
270 if (szNew == NULL)
271 goto LDone;
272 if (szLine != rgchLine)
273 DeallocateP(szLine);
274 szLine = szNew;
275 cchLine *= 2;
276 }
277 ch = getbyte();
278 if (!((uchar)ch >= ' ' || ch == chTab))
279 break;
280 szLine[i] = ch;
281 }
282 if (ch != '\n')
283 ch = getbyte();
284 // Windows Notepad files sometimes have character 255 at end of file.
285 if (i > 0 && (uchar)szLine[i-1] == 255)
286 i--;
287 szLine[i] = chNull;
288 argc = NParseCommandLine(szLine, argv);
289 if (!FProcessSwitches(argc, argv))
290 goto LDone;
291 }

Callers 5

mainFunction · 0.85
FInputDataFunction · 0.85
WinMainFunction · 0.85
FEnsureAtlasFunction · 0.85
FEnsureTimezoneChangesFunction · 0.85

Calls 6

FileOpenFunction · 0.85
PrintWarningFunction · 0.85
RgReallocateFunction · 0.85
DeallocatePFunction · 0.85
NParseCommandLineFunction · 0.85
FProcessSwitchesFunction · 0.85

Tested by

no test coverage detected