ExecutionLexer::Token ExecutionLexer::PullPsql() { int start = pos; Take(); // consume the starting backslash do { int c = Take(); if (c < 0 || c == '\n') { return Token(Token::PSQL, start, pos - start); } else if (c == '\\') { if (Peek() == '\\') { // skip over terminating double-backslash Take(); return Token(Token::PSQL, start, pos - start - 2); } else { // preserve starting backslash of next command BackUp(); return Token(Token::PSQL, start, pos - start); } } else if (c == '\'') { PassSingleQuotedString(false); } } while (true); }
void ExecutionLexer::PassWhitespace() { do { int c = Take(); if (c < 0) return; if (!isspace((char) c)) { BackUp(); return; } } while (true); }
bool GzipInputStream::Skip(int count) { const void* data; int size; bool ok = Next(&data, &size); while (ok && (size < count)) { count -= size; ok = Next(&data, &size); } if (size > count) { BackUp(size - count); } return ok; }
void Permute(Stack *out, Stack *in, Stack *spur) { Stack *temp_out; Stack *temp_spur; Stack *temp_in; /* the backups. */ if (StackEmpty(out)) { while (!StackEmpty(spur)) SendTrain(in, spur); TraverseStack(in, PrintEntry); /* A mode is detected, */ total++; /* then print out the results.*/ ClearStack(in); /* release the memory. */ #ifdef __TRAVERSE__ printf("\n"); #endif } else { if (1 - frame_depth % 2) { /* To decide how to send trains. */ SendTrain(spur, out); /* If 'frame_depth' is odd, */ } else { /* 'out' to 'spur'. If 'frame_depth */ SendTrain(in, spur); /* is even, 'spur' to 'in'. */ } temp_out = BackUp(out); temp_spur = BackUp(spur); temp_in = BackUp(in); frame_depth++; /* To enter into a new recursion. */ Permute(temp_out, temp_in, temp_spur); frame_depth--; /* Now back to the higher level of recursion. */ if (!StackEmpty(out) && !StackEmpty(spur)) Permute(out, in, spur); } }
ExecutionLexer::Token ExecutionLexer::PullSql() { int start = pos; do { int c = Take(); if (c < 0) { return Token(Token::SQL, start, pos - start); } // note that dollar-quoting takes priority over *everything* (except end of input of course) if (c == '$') PassDollarQuote(); else if (quoteStack.empty()) { if (c == '\'') PassSingleQuotedString(false); // FIXME handle E'...' flag for escape syntax else if (c == '\"') PassDoubleQuotedString(); else if (c == ';') { // inclusive end character int end = ++pos; PassWhitespace(); return Token(Token::SQL, start, end - start); } else if (c == '-') { if (Peek() == '-') { PassSingleLineComment(); } } else if (c == '/') { if (Peek() == '*') { PassBlockComment(); } } else if (c == '\\') { // exclusive end character BackUp(); return Token(Token::SQL, start, pos - start); } } } while (true); }
bool CFileBackUp::BackUp(const string& src, const string& dst) { return BackUp(S2WS(src), S2WS(dst)); }