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

Postfix for CORE-3990

This commit is contained in:
alexpeshkoff 2013-03-01 13:50:37 +00:00
parent cfbe804aa4
commit 62f06e6c77
3 changed files with 56 additions and 8 deletions

View File

@ -247,11 +247,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);
}
}
}
@ -270,3 +277,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

@ -27,6 +27,8 @@
#include "../common/classes/fb_string.h"
#include "../common/os/path_utils.h"
#include "../common/classes/array.h"
#include <stdio.h>
// This is basically a stack of input files caused by the INPUT command,
@ -83,12 +85,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;
};
@ -105,12 +119,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

@ -4465,7 +4465,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, Tmpfile);
Filelist->commandsToFile(f);
}
else
{
// If we can't open a temp file then bail