8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-23 21:23:03 +01:00

Postfix for CORE-3990

This commit is contained in:
alexpeshkoff 2013-03-01 13:50:59 +00:00
parent d9145c849a
commit 4cdebb8d50
3 changed files with 56 additions and 8 deletions

View File

@ -226,11 +226,18 @@ void InputDevices::saveCommand(const char* statement, const char* term)
if (m_ifp.indev_fpointer == stdin)
{
FILE* f = m_ofp.indev_fpointer;
fb_assert(f);
fputs(statement, f);
fputs(term, f);
// Add newline to make the file more readable.
fputc('\n', f);
if (f)
{
fputs(statement, f);
fputs(term, f);
// Add newline to make the file more readable.
fputc('\n', f);
}
else
{
Command* command = new Command(statement, term);
commands.add(command);
}
}
}
@ -249,3 +256,27 @@ void InputDevices::gotoEof()
fseek(m_ifp.indev_fpointer, 0, SEEK_END);
}
InputDevices::Command::Command(const char* statement, const char* term)
: m_statement(getPool())
{
m_statement = statement;
m_statement += term;
}
void InputDevices::Command::toFile(FILE* f)
{
fputs(m_statement.c_str(), f);
// Add newline to make the file more readable.
fputc('\n', f);
}
void InputDevices::commandsToFile(FILE* f)
{
for (unsigned n = 0; n < commands.getCount(); ++n)
{
commands[n]->toFile(f);
delete commands[n];
}
commands.clear();
}

View File

@ -35,6 +35,8 @@
// Do not confuse this "Ofp" with the user defined redirection of isql output to a file.
// The logic could be simpler but changing Borland code is tricky here.
#include "../common/classes/array.h"
class InputDevices
{
public:
@ -78,12 +80,24 @@ public:
void saveCommand(const char* statement, const char* term);
bool readingStdin() const;
void gotoEof();
void commandsToFile(FILE* fpointer);
private:
size_t m_count;
indev* m_head;
indev m_ifp;
indev m_ofp;
class Command : public Firebird::GlobalStorage
{
public:
Command(const char* statement, const char* term);
void toFile(FILE* fpointer);
private:
Firebird::string m_statement;
};
Firebird::HalfStaticArray<Command*, 32> commands;
};
@ -100,12 +114,12 @@ inline void InputDevices::indev::close()
inline InputDevices::InputDevices()
: m_count(0), m_head(0), m_ifp(0, ""), m_ofp(0, "")
: m_count(0), m_head(0), m_ifp(0, ""), m_ofp(0, ""), commands(*getDefaultMemoryPool())
{
}
inline InputDevices::InputDevices(Firebird::MemoryPool&)
: m_count(0), m_head(0), m_ifp(0, ""), m_ofp(0, "")
inline InputDevices::InputDevices(Firebird::MemoryPool& p)
: m_count(0), m_head(0), m_ifp(0, ""), m_ofp(0, ""), commands(p)
{
}

View File

@ -4493,7 +4493,10 @@ static processing_state edit(const TEXT* const* cmd)
const char* Tmpfile = filename.c_str();
FILE* f = fopen(Tmpfile, "w+"); // It was w+b
if (f)
{
Ofp.init(f, Tmpfile);
Filelist->commandsToFile(f);
}
else
{
// If we can't open a temp file then bail