MCPcopy Create free account
hub / github.com/Bananymous/banan-os / source_script

Method source_script

userspace/programs/Shell/Execute.cpp:392–433  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

390}
391
392BAN::ErrorOr<void> Execute::source_script(BAN::StringView path)
393{
394 BAN::Vector<BAN::String> script_lines;
395
396 {
397 FILE* fp = fopen(path.data(), "r");
398 if (fp == nullptr)
399 return BAN::Error::from_errno(errno);
400
401 BAN::String current;
402 char temp_buffer[128];
403 while (fgets(temp_buffer, sizeof(temp_buffer), fp))
404 {
405 TRY(current.append(temp_buffer));
406 if (current.back() != '\n')
407 continue;
408 current.pop_back();
409
410 if (!current.empty())
411 TRY(script_lines.push_back(BAN::move(current)));
412 current.clear();
413 }
414
415 if (!current.empty())
416 TRY(script_lines.push_back(BAN::move(current)));
417
418 fclose(fp);
419 }
420
421 size_t index = 0;
422 TokenParser parser(
423 [&](BAN::Optional<BAN::StringView>) -> BAN::Optional<BAN::String>
424 {
425 if (index >= script_lines.size())
426 return {};
427 return script_lines[index++];
428 }
429 );
430 if (!parser.main_loop(true))
431 return BAN::Error::from_literal("oop");
432 return {};
433}

Callers 2

initializeMethod · 0.80
mainFunction · 0.80

Calls 12

fopenFunction · 0.85
fgetsFunction · 0.85
fcloseFunction · 0.85
main_loopMethod · 0.80
dataMethod · 0.45
appendMethod · 0.45
backMethod · 0.45
pop_backMethod · 0.45
emptyMethod · 0.45
push_backMethod · 0.45
clearMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected