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

1.- Style.

2.- Cleanup.
3.- Put enumerations and plain structures in their due classes, checked constness, commented or deleted unused crap (watch stupid macros in header files that pollute all the files where such headers are included), etc.

There's a lot of pending work to do. Still trying to convert to decent C++ this barbarian code probably written by Genghis Khan or Attila the Hun.
This commit is contained in:
robocop 2008-04-29 12:01:24 +00:00
parent e9737dd290
commit 39e02e49fb
23 changed files with 455 additions and 421 deletions

View File

@ -39,7 +39,7 @@
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
AdminException::AdminException(const char *txt, ...) :
AdminException::AdminException(const char* txt, ...) :
text(getPool()), fileName(getPool())
{
va_list args;

View File

@ -1,19 +1,19 @@
/*
*
* The contents of this file are subject to the Initial
* Developer's Public License Version 1.0 (the "License");
* you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
* http://www.ibphoenix.com/idpl.html.
*
* Software distributed under the License is distributed on
* an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for the specific
* The contents of this file are subject to the Initial
* Developer's Public License Version 1.0 (the "License");
* you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
* http://www.ibphoenix.com/idpl.html.
*
* Software distributed under the License is distributed on
* an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for the specific
* language governing rights and limitations under the License.
*
* The contents of this file or any work derived from this file
* may not be distributed under any other license whatsoever
* without the express prior written permission of the original
* may not be distributed under any other license whatsoever
* without the express prior written permission of the original
* author.
*
*
@ -40,10 +40,10 @@
class AdminException : public Firebird::GlobalStorage
{
public:
AdminException(const char* txt, ...);
virtual ~AdminException();
void setLocation (const Firebird::PathName& fileName, int lineNumber);
const char* getText() const;
AdminException(const char *txt, ...);
virtual ~AdminException();
private:
Firebird::string text;

View File

@ -1,19 +1,19 @@
/*
*
* The contents of this file are subject to the Initial
* Developer's Public License Version 1.0 (the "License");
* you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
* http://www.ibphoenix.com/idpl.html.
*
* Software distributed under the License is distributed on
* an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for the specific
* The contents of this file are subject to the Initial
* Developer's Public License Version 1.0 (the "License");
* you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
* http://www.ibphoenix.com/idpl.html.
*
* Software distributed under the License is distributed on
* an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for the specific
* language governing rights and limitations under the License.
*
* The contents of this file or any work derived from this file
* may not be distributed under any other license whatsoever
* without the express prior written permission of the original
* may not be distributed under any other license whatsoever
* without the express prior written permission of the original
* author.
*
*
@ -41,6 +41,46 @@
#include "Args.h"
#include "ArgsException.h"
class ConsoleNoEcho
{
public:
ConsoleNoEcho();
~ConsoleNoEcho();
private:
#ifdef _WIN32
HANDLE m_stdin;
DWORD m_orgSettings;
#else
termios m_orgSettings;
#endif
};
ConsoleNoEcho::ConsoleNoEcho()
{
#ifdef _WIN32
m_stdin = GetStdHandle(STD_INPUT_HANDLE);
GetConsoleMode(m_stdin, &m_orgSettings);
const DWORD newSettings = m_orgSettings & ~(ENABLE_ECHO_INPUT);
SetConsoleMode(m_stdin, newSettings);
#else
tcgetattr(0, &m_orgSettings);
termios newSettings = m_orgSettings;
newSettings.c_lflag &= (~ECHO);
tcsetattr(0, TCSANOW, &newSettings);
#endif
}
ConsoleNoEcho::~ConsoleNoEcho()
{
#ifdef _WIN32
SetConsoleMode(m_stdin, m_orgSettings);
#else
tcsetattr(0, TCSANOW, &m_orgSettings);
#endif
}
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
@ -55,59 +95,60 @@ Args::~Args()
}
void Args::parse(const Switches *switches, int argc, char **argv)
void Args::parse(const Switches* switches, int argc, const char* const* argv)
{
for (char **arg = argv, **end = arg + argc; arg < end;)
{
const char *p = *arg++;
const Switches *parameter = NULL;
const char* const* const end = argv + argc;
while (argv < end)
{
const char* p = *argv++;
const Switches* parameter = NULL;
bool hit = false;
for (const Switches *sw = switches; sw->string; ++sw)
{
for (const Switches* sw = switches; sw->string; ++sw)
{
if (strcmp (sw->string, p) == 0)
{
{
if (sw->boolean)
*sw->boolean = true;
if (sw->argument)
{
if (arg >= end)
{
if (argv >= end)
throw ArgsException ("an argument is required for \"%s\"", sw->string);
*sw->argument = *arg++;
}
*sw->argument = *argv++;
}
hit = true;
break;
}
}
if (!sw->string [0])
parameter = sw;
}
}
if (!hit)
{
{
if (parameter)
{
{
if (parameter->boolean)
*parameter->boolean = true;
if (parameter->argument)
*parameter->argument = p;
}
}
else
throw ArgsException ("invalid option \"%s\"", p);
}
}
}
}
void Args::init(const Switches *switches)
void Args::init(const Switches* switches)
{
for (const Switches *sw = switches; sw->string; ++sw)
{
{
if (sw->boolean)
*sw->boolean = false;
if (sw->argument)
*sw->argument = NULL;
}
}
}
void Args::printHelp(const char *helpText, const Switches *switches)
void Args::printHelp(const char* helpText, const Switches* switches)
{
int switchLength = 0;
int argLength = 0;
@ -116,17 +157,17 @@ void Args::printHelp(const char *helpText, const Switches *switches)
for (sw = switches; sw->string; ++sw)
{
if (sw->description)
{
{
int l = (int) strlen (sw->string);
if (l > switchLength)
switchLength = l;
if (sw->argName)
{
{
l = (int) strlen (sw->argName);
if (l > argLength)
argLength = l;
}
}
}
}
if (helpText)
@ -137,33 +178,22 @@ void Args::printHelp(const char *helpText, const Switches *switches)
for (sw = switches; sw->string; ++sw)
{
if (sw->description)
{
{
const char *arg = (sw->argName) ? sw->argName : "";
printf (" %-*s %-*s %s\n", switchLength, sw->string, argLength, arg, sw->description);
}
}
}
}
bool Args::readPasswords(const char *msg, char *pw1, int length)
{
#ifdef _WIN32
DWORD orgSettings, newSettings;
HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE);
int ret = GetConsoleMode(hStdin, &orgSettings);
newSettings = orgSettings & ~(ENABLE_ECHO_INPUT);
ret = SetConsoleMode(hStdin, newSettings);
#else
termios orgSettings, newSettings;
tcgetattr(0, &orgSettings);
newSettings = orgSettings;
newSettings.c_lflag &= (~ECHO);
tcsetattr(0, TCSANOW, &newSettings);
#endif
ConsoleNoEcho instance;
char pw2 [100];
bool hit = false;
for (;;)
{
{
if (msg)
printf (msg);
printf ("New password: ");
@ -172,28 +202,25 @@ bool Args::readPasswords(const char *msg, char *pw1, int length)
char *p = strchr (pw1, '\n');
if (p)
*p = 0;
// blanks not detected here, need something like trim()
if (!pw1 [0])
{
{
printf ("\nPassword may not be null. Please re-enter.\n");
continue;
}
}
printf ("\nRepeat new password: ");
if (!fgets (pw2, sizeof (pw2), stdin))
break;
if (p = strchr (pw2, '\n'))
*p = 0;
if (strcmp (pw1, pw2) == 0)
{
{
hit = true;
break;
}
printf ("\nPasswords do not match. Please re-enter.\n");
}
#ifdef _WIN32
ret = SetConsoleMode(hStdin, orgSettings);
#else
tcsetattr(0, TCSANOW, &orgSettings);
#endif
printf ("\nPasswords do not match. Please re-enter.\n");
}
printf ("\n");
return hit;
@ -201,23 +228,12 @@ bool Args::readPasswords(const char *msg, char *pw1, int length)
bool Args::readPassword(const char *msg, char *pw1, int length)
{
#ifdef _WIN32
DWORD orgSettings, newSettings;
HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE);
int ret = GetConsoleMode(hStdin, &orgSettings);
newSettings = orgSettings & ~(ENABLE_ECHO_INPUT);
ret = SetConsoleMode(hStdin, newSettings);
#else
termios orgSettings, newSettings;
tcgetattr(0, &orgSettings);
newSettings = orgSettings;
newSettings.c_lflag &= (~ECHO);
tcsetattr(0, TCSANOW, &newSettings);
#endif
ConsoleNoEcho instance;
bool hit = false;
for (;;)
{
{
if (msg)
printf (msg);
if (!fgets (pw1, length, stdin))
@ -225,20 +241,15 @@ bool Args::readPassword(const char *msg, char *pw1, int length)
char *p = strchr (pw1, '\n');
if (p)
*p = 0;
// blanks not detected here, need something like trim()
if (pw1 [0])
{
{
hit = true;
break;
}
printf ("\nPassword may not be null. Please re-enter.\n");
continue;
}
printf ("\nPassword may not be null. Please re-enter.\n");
}
#ifdef _WIN32
ret = SetConsoleMode(hStdin, orgSettings);
#else
tcsetattr(0, TCSANOW, &orgSettings);
#endif
printf ("\n");
return hit;

View File

@ -1,19 +1,19 @@
/*
*
* The contents of this file are subject to the Initial
* Developer's Public License Version 1.0 (the "License");
* you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
* http://www.ibphoenix.com/idpl.html.
*
* Software distributed under the License is distributed on
* an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for the specific
* The contents of this file are subject to the Initial
* Developer's Public License Version 1.0 (the "License");
* you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
* http://www.ibphoenix.com/idpl.html.
*
* Software distributed under the License is distributed on
* an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for the specific
* language governing rights and limitations under the License.
*
* The contents of this file or any work derived from this file
* may not be distributed under any other license whatsoever
* without the express prior written permission of the original
* may not be distributed under any other license whatsoever
* without the express prior written permission of the original
* author.
*
*
@ -36,30 +36,31 @@
#include "../common/classes/alloc.h"
struct Switches
{
const char *string;
bool *boolean;
const char* *argument;
const char *argName;
const char *description;
};
#define WORD_ARG(value,name) "", NULL, &value, name, NULL,
#define ARG_ARG(sw,value,help) sw, NULL, &value, NULL, help,
#define SW_ARG(sw,value,help) sw, &value,NULL, NULL, help,
//#define WORD_ARG(value,name) "", NULL, &value, name, NULL,
//#define ARG_ARG(sw,value,help) sw, NULL, &value, NULL, help,
//#define SW_ARG(sw,value,help) sw, &value,NULL, NULL, help,
class Args : public Firebird::GlobalStorage
{
public:
static bool readPassword (const char *msg, char *pw1, int length);
static bool readPasswords(const char *msg, char *pw1, int length);
static void printHelp (const char *helpText, const Switches *switches);
static void init (const Switches *switches);
static void parse (const Switches *switches, int argc, char **argv);
struct Switches
{
const char* string;
bool* boolean;
const char** argument;
const char* argName;
const char* description;
};
Args();
virtual ~Args();
static bool readPassword (const char* msg, char* pw1, int length);
static bool readPasswords(const char* msg, char* pw1, int length);
static void printHelp (const char* helpText, const Switches* switches);
static void init (const Switches* switches);
static void parse (const Switches* switches, int argc, const char* const* argv);
};
#endif // !defined(AFX_ARGS_H__7C584339_5A11_4040_889B_417B607C858B__INCLUDED_)

View File

@ -38,7 +38,7 @@
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
ArgsException::ArgsException(const char * txt, ...) :
ArgsException::ArgsException(const char* txt, ...) :
text(getPool())
{
va_list args;

View File

@ -1,19 +1,19 @@
/*
*
* The contents of this file are subject to the Initial
* Developer's Public License Version 1.0 (the "License");
* you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
* http://www.ibphoenix.com/idpl.html.
*
* Software distributed under the License is distributed on
* an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for the specific
* The contents of this file are subject to the Initial
* Developer's Public License Version 1.0 (the "License");
* you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
* http://www.ibphoenix.com/idpl.html.
*
* Software distributed under the License is distributed on
* an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for the specific
* language governing rights and limitations under the License.
*
* The contents of this file or any work derived from this file
* may not be distributed under any other license whatsoever
* without the express prior written permission of the original
* may not be distributed under any other license whatsoever
* without the express prior written permission of the original
* author.
*
*
@ -39,9 +39,9 @@
class ArgsException : public Firebird::GlobalStorage
{
public:
const char* getText() const;
ArgsException(const char * txt, ...);
ArgsException(const char* txt, ...);
virtual ~ArgsException();
const char* getText() const;
private:
Firebird::string text;

View File

@ -1,19 +1,19 @@
/*
*
* The contents of this file are subject to the Initial
* Developer's Public License Version 1.0 (the "License");
* you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
* http://www.ibphoenix.com/idpl.html.
*
* Software distributed under the License is distributed on
* an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for the specific
* The contents of this file are subject to the Initial
* Developer's Public License Version 1.0 (the "License");
* you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
* http://www.ibphoenix.com/idpl.html.
*
* Software distributed under the License is distributed on
* an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for the specific
* language governing rights and limitations under the License.
*
* The contents of this file or any work derived from this file
* may not be distributed under any other license whatsoever
* without the express prior written permission of the original
* may not be distributed under any other license whatsoever
* without the express prior written permission of the original
* author.
*
*
@ -34,7 +34,7 @@ ConfObj::ConfObj()
object = NULL;
}
ConfObj::ConfObj(ConfObject *confObject)
ConfObj::ConfObj(ConfObject* confObject)
{
if (object = confObject)
object->addRef();
@ -57,14 +57,16 @@ bool ConfObj::hasObject() const
return object != NULL;
}
ConfObject* ConfObj::operator = (ConfObject *source)
ConfObject* ConfObj::operator = (ConfObject* source)
{
if (object)
object->release();
object = source;
object->addRef();
if (object)
object->addRef();
return object;
}

View File

@ -37,14 +37,14 @@ class ConfObj : public Firebird::GlobalStorage
{
public:
ConfObj();
explicit ConfObj(ConfObject *confObject);
explicit ConfObj(ConfObject* confObject);
ConfObj(ConfObj& source);
~ConfObj();
operator ConfObject*() { return object; }
ConfObject* operator -> () { return object; }
const ConfObject* operator -> () const { return object; }
ConfObject* operator = (ConfObject *source);
ConfObject* operator = (ConfObject* source);
bool hasObject() const;

View File

@ -1,19 +1,19 @@
/*
*
* The contents of this file are subject to the Initial
* Developer's Public License Version 1.0 (the "License");
* you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
* http://www.ibphoenix.com/idpl.html.
*
* Software distributed under the License is distributed on
* an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for the specific
* The contents of this file are subject to the Initial
* Developer's Public License Version 1.0 (the "License");
* you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
* http://www.ibphoenix.com/idpl.html.
*
* Software distributed under the License is distributed on
* an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for the specific
* language governing rights and limitations under the License.
*
* The contents of this file or any work derived from this file
* may not be distributed under any other license whatsoever
* without the express prior written permission of the original
* may not be distributed under any other license whatsoever
* without the express prior written permission of the original
* author.
*
*
@ -46,25 +46,25 @@
#ifndef strcasecmp
#define strcasecmp stricmp
#define strncasecmp strnicmp
//#define strncasecmp strnicmp
#endif
#define KEY "SOFTWARE\\Firebird Project\\Firebird Server\\Instances"
#define SUB_KEY NULL
#define PATH_KEY "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\Firebird"
//#define KEY "SOFTWARE\\Firebird Project\\Firebird Server\\Instances"
//#define SUB_KEY NULL
//#define PATH_KEY "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\Firebird"
#else
#define IS_SEPARATOR(c) (c == '/')
#endif
ConfigFile::ConfigFile(int configFlags) :
ConfigFile::ConfigFile(const LEX_flags configFlags) :
Lex ("/<>=", configFlags),
rootDirectory(getPool()), installDirectory(getPool()), currentDirectory(getPool())
{
init (configFlags);
InputFile *inputFile = openConfigFile();
if (!inputFile)
return;
@ -73,25 +73,25 @@ ConfigFile::ConfigFile(int configFlags) :
}
ConfigFile::ConfigFile(const char* configFile, int configFlags) :
Lex ("/<>=", configFlags),
ConfigFile::ConfigFile(const char* configFile, const LEX_flags configFlags) :
Lex ("/<>=", configFlags),
rootDirectory(getPool()), installDirectory(getPool()), currentDirectory(getPool())
{
init (configFlags);
InputFile *inputFile = new InputFile;
Firebird::PathName expandedFile (expand (configFile));
if (!inputFile->openInputFile(expandedFile.c_str()))
{
{
delete inputFile;
throw AdminException ("can't open configuration file \"%s\"", configFile);
}
}
pushStream (inputFile);
parse();
}
void ConfigFile::init(int configFlags)
void ConfigFile::init(const LEX_flags configFlags)
{
flags = configFlags;
setLineComment ("#");
@ -122,78 +122,78 @@ InputFile* ConfigFile::openConfigFile()
return NULL;
}
void ConfigFile::parse(void)
void ConfigFile::parse()
{
objects = new Element ("ConfObjects");
getToken();
while (tokenType != END_OF_STREAM)
{
{
while (match ("include"))
{
{
Firebird::PathName fileName = expand (reparseFilename());
if (fileName.find('*') != Firebird::PathName::npos)
wildCardInclude(fileName.c_str());
else
pushStream (new InputFile (fileName.c_str()));
getToken();
}
}
if (match ("<"))
objects->addChild (parseObject());
else
{
{
Element *element = parseAttribute();
const int slot = element->name.hash (HASH_SIZE);
element->sibling = hashTable [slot];
hashTable [slot] = element;
}
}
}
}
Element* ConfigFile::parseObject(void)
Element* ConfigFile::parseObject()
{
Firebird::string name = getName();
const Firebird::string name = getName();
Element *element = new Element (name);
element->setSource (priorLineNumber, priorInputStream);
while (!match (">"))
{
{
element->addAttribute (new Element (reparseFilename().ToString()));
getToken();
}
}
for (;;)
{
{
if (match ("<"))
{
{
if (match ("/"))
{
{
if (!match (element->name.c_str()))
syntaxError ("closing element");
if (!match (">"))
syntaxError ("\">\"");
element->numberLines = priorLineNumber - element->lineNumber + 1;
return element;
}
element->addChild (parseObject());
}
element->addChild (parseObject());
}
else
element->addChild (parseAttribute());
}
}
}
Element* ConfigFile::parseAttribute(void)
Element* ConfigFile::parseAttribute()
{
Element *element = new Element (getName());
element->setSource (priorLineNumber, priorInputStream);
match ("=");
while (!eol)
{
{
element->addAttribute (new Element (reparseFilename().ToString()));
getToken();
}
}
element->numberLines = priorLineNumber - element->lineNumber + 1;
@ -206,19 +206,19 @@ ConfObject* ConfigFile::findObject(const char* objectType, const char* objectNam
return NULL;
ConfObject *object = new ConfObject (this);
for (Element *child = objects->children; child; child = child->sibling)
{
if (object->matches (child, objectType, objectName))
return object;
}
object->release();
return NULL;
}
const char* ConfigFile::getRootDirectory(void)
const char* ConfigFile::getRootDirectory()
{
return Config::getRootDirectory();
}
@ -235,7 +235,7 @@ Element* ConfigFile::findGlobalAttribute(const char *attributeName)
if (element->name == attributeName)
return element;
}
return NULL;
}
@ -251,7 +251,7 @@ Firebird::PathName ConfigFile::expand(const Firebird::PathName& rawString)
char* p = temp;
const char* const temp_end = temp + sizeof(temp) - 1;
bool change = false;
for (const char *s = rawString.c_str(); *s;)
{
char c = *s++;
@ -295,40 +295,40 @@ Firebird::PathName ConfigFile::expand(const Firebird::PathName& rawString)
else
throw AdminException(errstr, sizeof(temp) - 1);
}
if (!change)
return rawString;
*p = 0;
return temp;
return temp;
}
const char* ConfigFile::translate(const char* value, const Element* object)
{
if (strcasecmp (value, "root") == 0)
return getRootDirectory();
if (strcasecmp (value, "install") == 0)
return getInstallDirectory();
if (strcasecmp (value, "this") == 0)
{
{
const char *source = NULL;
if (object && object->inputStream)
source = object->inputStream->getFileName();
if (!source && inputStream)
source = inputStream->getFileName();
if (!source)
throw AdminException("no context for $(this)");
Firebird::PathName currentFile = expand (source);
const Firebird::PathName currentFile = expand (source);
const char *fileName = currentFile.c_str();
const char *p = NULL;
for (const char *q = fileName; *q; ++q)
{
if (IS_SEPARATOR(*q))
@ -339,9 +339,9 @@ const char* ConfigFile::translate(const char* value, const Element* object)
currentDirectory = Firebird::PathName(fileName, p - fileName);
else
currentDirectory = ".";
return currentDirectory.c_str();
}
}
return NULL;
}
@ -350,19 +350,19 @@ const char* ConfigFile::translate(const char* value, const Element* object)
void ConfigFile::wildCardInclude(const char* fileName)
{
char directory [256];
if (strlen(fileName) >= sizeof(directory))
throw AdminException("Too long filename in wildCardInclude()");
strcpy (directory, fileName);
const char *wildcard = fileName;
char *p = strrchr (directory, '/');
if (p)
{
{
*p = 0;
wildcard = p + 1;
}
}
else
directory [0] = 0;

View File

@ -31,10 +31,9 @@
#include "RefObject.h"
#include "../common/classes/fb_string.h"
static const int HASH_SIZE = 101;
static const int CONFIG_trace = 1;
static const int CONFIG_list = 2;
static const int CONFIG_verbose = 4;
//static const int CONFIG_trace = 1;
//static const int CONFIG_list = 2;
//static const int CONFIG_verbose = 4;
START_NAMESPACE
class InputFile;
@ -44,8 +43,8 @@ class ConfObject;
class ConfigFile : public Lex, public RefObject
{
public:
explicit ConfigFile(int configFlags);
ConfigFile(const char* configFile, int configFlags);
explicit ConfigFile(const LEX_flags configFlags);
ConfigFile(const char* configFile, const LEX_flags configFlags);
//protected:
virtual ~ConfigFile();
@ -68,7 +67,8 @@ public:
const Element* getObjects() const { return objects; }
private:
void init(int configFlags);
enum { HASH_SIZE = 101 };
void init(const LEX_flags configFlags);
Element* objects;
Firebird::PathName rootDirectory;
Firebird::PathName installDirectory;

View File

@ -29,17 +29,24 @@
#include "Configuration.h"
#include "ConfigFile.h"
static ConfigFile *configFile;
// This var could be a static member of the class.
static ConfigFile* configFile;
// Non MT-safe code follows, maybe it was intended?
Configuration::Configuration()
{
fb_assert(!configFile); // only one instance of Configuration at a given time.
configFile = NULL;
}
Configuration::~Configuration()
{
if (configFile)
{
configFile->release();
configFile = NULL;
}
}
ConfObject* Configuration::findObject(const char* objectType, const char* objectName)
@ -61,13 +68,13 @@ const char* Configuration::getRootDirectory()
void Configuration::loadConfigFile()
{
if (!configFile)
configFile = new ConfigFile (0);
configFile = new ConfigFile (ConfigFile::LEX_none);
}
void Configuration::setConfigFilePath(const char* filename)
{
if (!configFile)
configFile = new ConfigFile (filename, 0);
configFile = new ConfigFile (filename, ConfigFile::LEX_none);
}
ConfObject* Configuration::getObject(const char* objectType)
@ -80,7 +87,7 @@ ConfObject* Configuration::getObject(const char* objectType)
ConfObject* Configuration::getObject(const char* objectType, const char* objectName)
{
ConfObject *object = findObject (objectType, objectName);
ConfObject* object = findObject (objectType, objectName);
if (!object)
object = getObject (objectType);

View File

@ -1,26 +1,26 @@
/*
*
* The contents of this file are subject to the Initial
* Developer's Public License Version 1.0 (the "License");
* you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
* http://www.ibphoenix.com/idpl.html.
*
* Software distributed under the License is distributed on
* an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for the specific
* The contents of this file are subject to the Initial
* Developer's Public License Version 1.0 (the "License");
* you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
* http://www.ibphoenix.com/idpl.html.
*
* Software distributed under the License is distributed on
* an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for the specific
* language governing rights and limitations under the License.
*
* The contents of this file or any work derived from this file
* may not be distributed under any other license whatsoever
* without the express prior written permission of the original
* may not be distributed under any other license whatsoever
* without the express prior written permission of the original
* author.
*
*
* The Original Code was created by James A. Starkey for IBPhoenix.
*
* Copyright (c) 1997 - 2000, 2001, 2003 James A. Starkey
* Copyright (c) 1997 - 2000, 2001, 2003 Netfrastructure, Inc.
* Copyright (c) 1997 - 2000, 2001, 2003 Netfrastructure, Inc.
* All Rights Reserved.
*/
@ -39,7 +39,7 @@ class Configuration : public Firebird::GlobalStorage
public:
Configuration();
virtual ~Configuration();
static ConfObject* findObject(const char* objectType, const char* objectName);
static const char* getRootDirectory();
static void loadConfigFile();

View File

@ -1,19 +1,19 @@
/*
*
* The contents of this file are subject to the Initial
* Developer's Public License Version 1.0 (the "License");
* you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
* http://www.ibphoenix.com/idpl.html.
*
* Software distributed under the License is distributed on
* an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for the specific
* The contents of this file are subject to the Initial
* Developer's Public License Version 1.0 (the "License");
* you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
* http://www.ibphoenix.com/idpl.html.
*
* Software distributed under the License is distributed on
* an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for the specific
* language governing rights and limitations under the License.
*
* The contents of this file or any work derived from this file
* may not be distributed under any other license whatsoever
* without the express prior written permission of the original
* may not be distributed under any other license whatsoever
* without the express prior written permission of the original
* author.
*
*
@ -40,7 +40,7 @@
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
static char THIS_FILE[] = __FILE__;
#endif
static const int quoted = 1;
@ -61,7 +61,7 @@ int init()
setCharTable('<', quoted);
setCharTable('>', quoted);
setCharTable('&', quoted);
for (int n = 0; n < 10; ++n)
charTable[n] = illegal;
@ -102,16 +102,16 @@ Element::~Element()
Element *child;
while (child = children)
{
{
children = child->sibling;
delete child;
}
}
while (child = attributes)
{
{
attributes = child->sibling;
delete child;
}
}
if (inputStream)
inputStream->release();
@ -175,11 +175,11 @@ void Element::print(int level) const
const Element *element;
for (element = attributes; element; element = element->sibling)
{
{
printf (" %s", element->name.c_str());
if (element->value != "")
printf ("=%s", (const char*) element->value.c_str());
}
}
printf ("\n");
++level;
@ -190,8 +190,10 @@ void Element::print(int level) const
Element* Element::findChild(const char *childName)
{
for (Element *child = children; child; child = child->sibling)
{
if (child->name == childName)
return child;
}
return NULL;
}
@ -210,8 +212,10 @@ const Element* Element::findChild(const char *childName) const
Element* Element::findAttribute(const char *childName)
{
for (Element *child = attributes; child; child = child->sibling)
{
if (child->name == childName)
return child;
}
return NULL;
}
@ -260,40 +264,42 @@ void Element::genXML(int level, Stream *stream) const
stream->putSegment (name.c_str());
for (const Element *attribute = attributes; attribute; attribute = attribute->sibling)
{
{
stream->putCharacter (' ');
stream->putSegment (attribute->name.c_str());
stream->putSegment ("=\"");
for (const char *p = attribute->value.c_str(); *p; ++p)
{
switch (*p)
{
{
case '"': stream->putSegment ("&quot;"); break;
case '\'': stream->putSegment ("&apos;"); break;
case '&': stream->putSegment ("&amp;"); break;
case '<': stream->putSegment ("&lt;"); break;
case '>': stream->putSegment ("&gt;"); break;
default: stream->putCharacter (*p); break;
}
}
}
//stream->putSegment (attribute->value);
stream->putCharacter ('"');
}
}
if (innerText.hasData())
{
{
stream->putCharacter('>');
putQuotedText(innerText.c_str(), stream);
}
}
else if (!children)
{
if (name.c_str()[0] == '?')
{
if (name.at(0) == '?')
stream->putSegment ("?>\n");
else
stream->putSegment ("/>\n");
return;
}
}
else
stream->putSegment (">\n");
++level;
for (const Element *child = children; child; child = child->sibling)
@ -301,7 +307,7 @@ void Element::genXML(int level, Stream *stream) const
if (innerText.isEmpty())
indent (level - 1, stream);
stream->putSegment ("</");
stream->putSegment (name.c_str());
stream->putSegment (">\n");
@ -318,8 +324,10 @@ void Element::indent(int level, Stream *stream) const
Element* Element::findChildIgnoreCase(const char *childName)
{
for (Element *child = children; child; child = child->sibling)
{
if (child->name.equalsNoCase (childName))
return child;
}
return NULL;
}
@ -368,21 +376,21 @@ void Element::gen(int level, Stream *stream) const
const Element *element;
for (element = attributes; element; element = element->sibling)
{
{
stream->putCharacter (' ');
stream->putSegment (element->name.c_str());
if (element->value != "")
{
{
stream->putCharacter ('=');
stream->putSegment (element->value.c_str());
}
}
}
if (!children)
{
{
stream->putCharacter ('\n');
return;
}
}
stream->putSegment (">\n");
++level;
@ -398,12 +406,14 @@ void Element::gen(int level, Stream *stream) const
Element* Element::findChild(const char *childName, const char *attribute, const char *attributeValue)
{
for (Element *child = children; child; child = child->sibling)
{
if (child->name == childName)
{
{
const char *p = child->getAttributeValue (attribute, NULL);
if (p && strcmp (p, attributeValue) == 0)
return child;
}
}
}
return NULL;
}
@ -411,20 +421,20 @@ Element* Element::findChild(const char *childName, const char *attribute, const
int Element::analyseText(const char* text)
{
int count = 0;
for (const char *p = text; *p; p++)
{
{
const int n = charTable[(UCHAR) *p];
if (n)
{
{
if (n & illegal)
return -1;
++count;
}
}
}
return count;
}
@ -432,47 +442,55 @@ void Element::putQuotedText(const char* text, Stream* stream) const
{
const char *start = text;
const char *p;
for (p = text; *p; p++)
{
if (charTable[(UCHAR) *p])
{
const char* escape = NULL;
switch (*p)
{
const char *escape = NULL;
if (*p == '>')
case '>':
escape = "&gt;";
else if (*p == '<')
break;
case '<':
escape = "&lt;";
else if (*p == '&')
break;
case '&':
escape = "&amp;";
else
break;
default:
continue;
}
if (p > start)
stream->putSegment(p - start, start, true);
stream->putSegment(escape);
start = p + 1;
}
}
}
if (p > start)
stream->putSegment(p - start, start, true);
stream->putSegment(p - start, start, true);
}
int Element::analyzeData(int length, const UCHAR* bytes)
{
int count = 0;
for (const UCHAR *p = bytes; *p; p++)
{
{
const int n = charTable[*p];
if (n)
{
{
if (n & illegal)
return -1;
++count;
}
}
}
return count;
}

View File

@ -11,13 +11,13 @@ FileName::FileName(const Firebird::PathName& name) :
pathName(getPool()), directory(getPool()), root(getPool()), extension(getPool())
{
pathName = name;
const char *start = pathName.c_str();
const char *slash = NULL;
const char *dot = NULL;
const char *rootName = start;
const char* const start = pathName.c_str();
const char* slash = NULL;
const char* dot = NULL;
const char* rootName = start;
absolute = IS_SLASH (start [0]);
for (const char *p = start; *p; ++p)
for (const char* p = start; *p; ++p)
{
if (!dot && IS_SLASH (*p))
slash = p;
@ -25,18 +25,17 @@ FileName::FileName(const Firebird::PathName& name) :
dot = p;
}
if (slash)
{
{
directory.assign (start, (int) (slash - rootName));
rootName = slash + 1;
}
}
if (dot)
{
{
extension = dot + 1;
root.assign (rootName, (int) (dot - rootName));
}
}
else
root = rootName;
}

View File

@ -6,7 +6,7 @@
class FileName : public Firebird::GlobalStorage
{
public:
FileName(const Firebird::PathName& name);
explicit FileName(const Firebird::PathName& name);
~FileName();
Firebird::PathName pathName;

View File

@ -1,19 +1,19 @@
/*
*
* The contents of this file are subject to the Initial
* Developer's Public License Version 1.0 (the "License");
* you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
* http://www.ibphoenix.com/idpl.html.
*
* Software distributed under the License is distributed on
* an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for the specific
* The contents of this file are subject to the Initial
* Developer's Public License Version 1.0 (the "License");
* you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
* http://www.ibphoenix.com/idpl.html.
*
* Software distributed under the License is distributed on
* an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for the specific
* language governing rights and limitations under the License.
*
* The contents of this file or any work derived from this file
* may not be distributed under any other license whatsoever
* without the express prior written permission of the original
* may not be distributed under any other license whatsoever
* without the express prior written permission of the original
* author.
*
*
@ -42,14 +42,14 @@
#include "AdminException.h"
#define ISLOWER(c) (c >= 'a' && c <= 'z')
#define ISUPPER(c) (c >= 'A' && c <= 'Z')
#define ISDIGIT(c) (c >= '0' && c <= '9')
//#define ISUPPER(c) (c >= 'A' && c <= 'Z')
//#define ISDIGIT(c) (c >= '0' && c <= '9')
#ifndef UPPER
#define UPPER(c) ((ISLOWER (c)) ? c - 'a' + 'A' : c)
#endif
#define BACKUP_FILES 5
const int BACKUP_FILES = 5;
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
@ -59,7 +59,7 @@ InputFile::InputFile(const char *name) : fileName(getPool())
{
changes = NULL;
file = NULL;
if (!openInputFile (name))
throw AdminException ("can't open file \"%s\"", name);
}
@ -75,19 +75,19 @@ InputFile::~InputFile()
close();
for (FileChange *change; change = changes;)
{
{
changes = change->next;
delete change;
}
}
}
void InputFile::close()
{
if (file)
{
{
fclose ((FILE*) file);
file = NULL;
}
}
}
const char* InputFile::getSegment()
@ -120,17 +120,17 @@ void InputFile::postChange(int line, int skip, const Firebird::string& insertion
change->lineNumber = line;
change->linesSkipped = skip;
change->insertion = insertion;
for (FileChange **p = &changes;; p = &(*p)->next)
{
{
FileChange *next = *p;
if (!next || next->lineNumber > change->lineNumber)
{
{
change->next = *p;
*p = change;
break;
}
}
}
}
void InputFile::rewrite()
@ -151,7 +151,7 @@ void InputFile::rewrite()
int line = 0;
for (FileChange *change = changes; change; change = change->next)
{
{
for (; line < change->lineNumber; ++line)
{
if (fgets (temp, sizeof (temp), input))
@ -163,7 +163,7 @@ void InputFile::rewrite()
for (int n = 0; n < change->linesSkipped; ++n)
fgets (temp, sizeof (temp), input);
line += change->linesSkipped;
}
}
while (fgets (temp, sizeof (temp), input))
fputs (temp, output);
@ -173,9 +173,9 @@ void InputFile::rewrite()
Firebird::PathName filename1, filename2;
fb_assert(BACKUP_FILES < 10); // assumption to avoid too long filenames
for (int n = BACKUP_FILES; n >= 0; --n)
{
{
filename1.printf("%.*s.%d", MAXPATHLEN - 3, fileName.c_str(), n);
if (n)
filename2.printf("%.*s.%d", MAXPATHLEN - 3, fileName.c_str(), n - 1);
@ -184,7 +184,7 @@ void InputFile::rewrite()
if (n == BACKUP_FILES)
unlink (filename1.c_str());
rename (filename2.c_str(), filename1.c_str());
}
}
if (rename (tempName.c_str(), fileName.c_str()))
perror ("rename");
@ -219,10 +219,10 @@ bool InputFile::openInputFile(const char* name)
// It's good idea to keep file names limited to meet OS requirements
if (!name || strlen(name) >= MAXPATHLEN)
return false;
if (!(file = fopen (name, "r")))
return false;
fileName = name;
segment = buffer;
changes = NULL;

View File

@ -38,8 +38,6 @@
#include "InputStream.h"
#include "../common/classes/fb_string.h"
#define AT_FILE_END 100000
START_NAMESPACE
class InputFile : public InputStream

View File

@ -44,7 +44,7 @@ InputStream::InputStream()
segmentLength = 0;
}
InputStream::InputStream(const char *stuff)
InputStream::InputStream(const char* stuff)
{
init();
segment = stuff;
@ -75,7 +75,7 @@ const char* InputStream::getSegment()
return segment;
}
int InputStream::getOffset(const char *pointer)
int InputStream::getOffset(const char* pointer)
{
return (int) (segmentOffset + pointer - segment);
}

View File

@ -56,18 +56,18 @@ public:
virtual void close();
virtual const char* getEnd();
virtual int getOffset (const char *ptr);
virtual int getOffset (const char* ptr);
virtual const char* getSegment();
int lineNumber;
const char *segment;
const char *ptr;
InputStream *prior;
int lineNumber;
const char* segment;
const char* ptr;
InputStream* prior;
protected:
int segmentLength; // used by InputFile
int segmentLength; // used by InputFile
private:
int segmentOffset;
int useCount;
int segmentOffset;
int useCount;
};
END_NAMESPACE

View File

@ -1,19 +1,19 @@
/*
*
* The contents of this file are subject to the Initial
* Developer's Public License Version 1.0 (the "License");
* you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
* http://www.ibphoenix.com/idpl.html.
*
* Software distributed under the License is distributed on
* an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for the specific
* The contents of this file are subject to the Initial
* Developer's Public License Version 1.0 (the "License");
* you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
* http://www.ibphoenix.com/idpl.html.
*
* Software distributed under the License is distributed on
* an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for the specific
* language governing rights and limitations under the License.
*
* The contents of this file or any work derived from this file
* may not be distributed under any other license whatsoever
* without the express prior written permission of the original
* may not be distributed under any other license whatsoever
* without the express prior written permission of the original
* author.
*
*
@ -78,10 +78,10 @@ bool ScanDir::next()
{
#ifdef _WIN32
if (handle == NULL)
{
{
handle = FindFirstFile ((directory + "\\" + pattern).c_str(), &data);
return handle != INVALID_HANDLE_VALUE;
}
}
return FindNextFile (handle, &data) != 0;
#else
@ -89,10 +89,10 @@ bool ScanDir::next()
return false;
while (data = readdir (dir))
{
{
if (match (pattern.c_str(), data->d_name))
return true;
}
}
return false;
#endif
@ -124,7 +124,7 @@ const char* ScanDir::getFilePath()
bool ScanDir::match(const char *pattern, const char *name)
{
if (*pattern == '*')
{
{
if (!pattern [1])
return true;
for (const char *p = name; *p; ++p)
@ -133,7 +133,7 @@ bool ScanDir::match(const char *pattern, const char *name)
return true;
}
return false;
}
}
if (*pattern != *name)
return false;

View File

@ -1,19 +1,19 @@
/*
*
* The contents of this file are subject to the Initial
* Developer's Public License Version 1.0 (the "License");
* you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
* http://www.ibphoenix.com/idpl.html.
*
* Software distributed under the License is distributed on
* an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for the specific
* The contents of this file are subject to the Initial
* Developer's Public License Version 1.0 (the "License");
* you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
* http://www.ibphoenix.com/idpl.html.
*
* Software distributed under the License is distributed on
* an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for the specific
* language governing rights and limitations under the License.
*
* The contents of this file or any work derived from this file
* may not be distributed under any other license whatsoever
* without the express prior written permission of the original
* may not be distributed under any other license whatsoever
* without the express prior written permission of the original
* author.
*
*
@ -41,7 +41,7 @@
#include <windows.h>
#endif
#else
#include <sys/types.h>
#include <sys/types.h>
#include <dirent.h>
#endif
@ -52,7 +52,7 @@ class ScanDir : public Firebird::GlobalStorage
public:
ScanDir(const char *dir, const char *pattern);
virtual ~ScanDir();
bool isDots();
const char* getFilePath();
bool isDirectory();

View File

@ -1,19 +1,19 @@
/*
*
* The contents of this file are subject to the Initial
* Developer's Public License Version 1.0 (the "License");
* you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
* http://www.ibphoenix.com/idpl.html.
*
* Software distributed under the License is distributed on
* an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for the specific
* The contents of this file are subject to the Initial
* Developer's Public License Version 1.0 (the "License");
* you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
* http://www.ibphoenix.com/idpl.html.
*
* Software distributed under the License is distributed on
* an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for the specific
* language governing rights and limitations under the License.
*
* The contents of this file or any work derived from this file
* may not be distributed under any other license whatsoever
* without the express prior written permission of the original
* may not be distributed under any other license whatsoever
* without the express prior written permission of the original
* author.
*
*
@ -34,7 +34,7 @@
#include "Stream.h"
#ifndef MAX
#define MAX(a,b) ((a > b) ? a : b)
//#define MAX(a,b) ((a > b) ? a : b)
#define MIN(a,b) ((a < b) ? a : b)
#endif
@ -57,15 +57,15 @@ void StreamSegment::setStream(Stream *stream)
remaining = stream->totalLength;
if (segment = stream->segments)
{
{
data = segment->address;
available = segment->length;
}
}
else
{
{
data = NULL;
available = 0;
}
}
}
void StreamSegment::advance()
@ -76,7 +76,7 @@ void StreamSegment::advance()
void StreamSegment::advance(int size)
{
for (int len = size; len;)
{
{
const int l = MIN (available, len);
available -= l;
remaining -= l;
@ -86,26 +86,26 @@ void StreamSegment::advance(int size)
if (available)
data += l;
else
{
{
segment = segment->next;
data = segment->address;
available = segment->length;
}
}
}
}
char* StreamSegment::copy(void *target, int length)
{
char *targ = (char*) target;
char* targ = static_cast<char*>(target);
for (int len = length; len;)
{
{
const int l = MIN (len, available);
memcpy (targ, data, l);
targ += l;
len -= l;
advance (l);
}
}
return targ;
}

View File

@ -36,12 +36,10 @@
#endif // _MSC_VER > 1000
#include "../common/classes/alloc.h"
#include "Stream.h"
START_NAMESPACE
class Stream;
struct Segment;
class StreamSegment : public Firebird::GlobalStorage
{
@ -58,8 +56,8 @@ private:
friend class Stream; // for "available" and "remaining"
int available;
int remaining;
char *data;
Segment *segment;
char* data;
Stream::Segment* segment;
};
END_NAMESPACE