| 27 | typedef char WordBuf[2048]; |
| 28 | |
| 29 | static bool GetWord(char* buf, int bufSize, QIStream& in, const char* termin, bool* quot = nullptr) |
| 30 | { |
| 31 | int len = 0; |
| 32 | buf[len] = 0; |
| 33 | int c = in.get(); |
| 34 | // LTrim the word |
| 35 | while (isspace(c)) |
| 36 | { |
| 37 | c = in.get(); |
| 38 | } |
| 39 | if (c == '"') |
| 40 | { |
| 41 | if (quot) |
| 42 | { |
| 43 | *quot = true; |
| 44 | } |
| 45 | c = in.get(); |
| 46 | for (;;) |
| 47 | { |
| 48 | if (c == EOF) |
| 49 | { |
| 50 | // Unterminated string: stop at end of input rather than spinning here, |
| 51 | // since QIStream::get keeps returning EOF without advancing the cursor. |
| 52 | ErrorMessage("Config: End of file encountered inside a string"); |
| 53 | return len > 0; |
| 54 | } |
| 55 | if (c == '"') |
| 56 | { |
| 57 | c = in.get(); |
| 58 | if (c != '"') |
| 59 | { |
| 60 | in.unget(); |
| 61 | return true; // word parsed |
| 62 | } |
| 63 | } |
| 64 | if (c == '\n' || c == '\r') |
| 65 | { |
| 66 | ErrorMessage("Config: End of line encountered after %s", buf); |
| 67 | } |
| 68 | if (len < bufSize - 1) |
| 69 | { |
| 70 | buf[len++] = c, buf[len] = 0; |
| 71 | } |
| 72 | c = in.get(); |
| 73 | } |
| 74 | } |
| 75 | else |
| 76 | { |
| 77 | if (quot) |
| 78 | { |
| 79 | *quot = false; |
| 80 | } |
| 81 | while (!strchr(termin, c) && c != EOF) |
| 82 | { |
| 83 | if (c == '\n' || c == '\r') |
| 84 | { |
| 85 | // word terminated - only white spaces or termin now |
| 86 | for (;;) |
no test coverage detected