MCPcopy Create free account
hub / github.com/emscripten-core/emscripten / main_loop

Function main_loop

test/module/test_stdin.cpp:22–55  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

20using namespace std;
21
22void main_loop() {
23 static bool first_line = true;
24 string str;
25
26 errno = 0;
27 while (errno != EAGAIN) {
28 if (first_line) {
29 char c;
30 if (std::cin.get(c)) {
31 std::cout.put(c);
32 if (c == '\n') {
33 first_line = false;
34 }
35 }
36 } else {
37 if (getline(std::cin, str)) {
38 std::cout << str << "\n";
39 }
40 }
41
42 if (std::cin.fail() && !std::cin.eof()) {
43 if (errno != EAGAIN) {
44 cerr << "error " << strerror(errno) << "\n";
45 exit(EXIT_FAILURE);
46 }
47 std::cin.clear();
48 }
49
50 if (std::cin.eof()) {
51 std::cout << "eof\n";
52 exit(EXIT_SUCCESS);
53 }
54 }
55}
56
57int main(int argc, char const *argv[]) {
58 // SM shell doesn't implement an event loop and therefore doesn't support

Callers 1

mainFunction · 0.70

Calls 7

getlineFunction · 0.85
strerrorFunction · 0.85
failMethod · 0.80
getMethod · 0.65
exitFunction · 0.50
putMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected