| 20 | using namespace std; |
| 21 | |
| 22 | void 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 | |
| 57 | int main(int argc, char const *argv[]) { |
| 58 | // SM shell doesn't implement an event loop and therefore doesn't support |