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

Fix the most obvioius problems:

- style (few fixes only)
- constness
- total lack of encapsulation (all data members exposed in the interface).
This commit is contained in:
robocop 2008-04-20 10:40:58 +00:00
parent 67e68fd8ed
commit 60802a9d77
33 changed files with 190 additions and 134 deletions

View File

@ -54,16 +54,16 @@ AdminException::AdminException(const char *txt, ...)
if (ret < 0) if (ret < 0)
{ {
int l = sizeof (temp) * 2; const int l = sizeof (temp) * 2;
char *buffer = new char [l]; char* const buffer = new char [l];
vsnprintf (buffer, l, txt, args); vsnprintf (buffer, l, txt, args);
text = buffer; text = buffer;
delete [] buffer; delete [] buffer;
} }
else if (static_cast<unsigned>(ret) >= sizeof (temp)) else if (static_cast<unsigned>(ret) >= sizeof (temp))
{ {
int l = ret + 1; const int l = ret + 1;
char *buffer = new char [l]; char* const buffer = new char [l];
vsnprintf (buffer, l, txt, args); vsnprintf (buffer, l, txt, args);
text = buffer; text = buffer;
delete [] buffer; delete [] buffer;
@ -79,7 +79,7 @@ AdminException::~AdminException()
} }
const char* AdminException::getText() const char* AdminException::getText() const
{ {
return text; return text;
} }

View File

@ -41,10 +41,11 @@ class AdminException
{ {
public: public:
void setLocation (JString fileName, int lineNumber); void setLocation (JString fileName, int lineNumber);
const char* getText(); const char* getText() const;
AdminException(const char *txt, ...); AdminException(const char *txt, ...);
virtual ~AdminException(); virtual ~AdminException();
private:
JString text; JString text;
JString fileName; JString fileName;
}; };

View File

@ -59,7 +59,7 @@ void Args::parse(const Switches *switches, int argc, char **argv)
{ {
for (char **arg = argv, **end = arg + argc; arg < end;) for (char **arg = argv, **end = arg + argc; arg < end;)
{ {
char *p = *arg++; const char *p = *arg++;
const Switches *parameter = NULL; const Switches *parameter = NULL;
bool hit = false; bool hit = false;
for (const Switches *sw = switches; sw->string; ++sw) for (const Switches *sw = switches; sw->string; ++sw)
@ -114,6 +114,7 @@ void Args::printHelp(const char *helpText, const Switches *switches)
const Switches *sw; const Switches *sw;
for (sw = switches; sw->string; ++sw) for (sw = switches; sw->string; ++sw)
{
if (sw->description) if (sw->description)
{ {
int l = (int) strlen (sw->string); int l = (int) strlen (sw->string);
@ -126,6 +127,7 @@ void Args::printHelp(const char *helpText, const Switches *switches)
argLength = l; argLength = l;
} }
} }
}
if (helpText) if (helpText)
printf (helpText); printf (helpText);
@ -133,11 +135,13 @@ void Args::printHelp(const char *helpText, const Switches *switches)
printf ("Options are:\n"); printf ("Options are:\n");
for (sw = switches; sw->string; ++sw) for (sw = switches; sw->string; ++sw)
{
if (sw->description) if (sw->description)
{ {
const char *arg = (sw->argName) ? sw->argName : ""; const char *arg = (sw->argName) ? sw->argName : "";
printf (" %-*s %-*s %s\n", switchLength, sw->string, argLength, arg, sw->description); printf (" %-*s %-*s %s\n", switchLength, sw->string, argLength, arg, sw->description);
} }
}
} }
bool Args::readPasswords(const char *msg, char *pw1, int length) bool Args::readPasswords(const char *msg, char *pw1, int length)

View File

@ -39,7 +39,7 @@ struct Switches
{ {
const char *string; const char *string;
bool *boolean; bool *boolean;
char **argument; const char* *argument;
const char *argName; const char *argName;
const char *description; const char *description;
}; };

View File

@ -60,7 +60,7 @@ ArgsException::~ArgsException()
} }
const char* ArgsException::getText() const char* ArgsException::getText() const
{ {
return text; return text;
} }

View File

@ -39,10 +39,11 @@
class ArgsException class ArgsException
{ {
public: public:
const char* getText(); const char* getText() const;
ArgsException(const char * txt, ...); ArgsException(const char * txt, ...);
virtual ~ArgsException(); virtual ~ArgsException();
private:
JString text; JString text;
}; };

View File

@ -40,21 +40,18 @@ ConfObj::ConfObj(ConfObject *confObject)
object->addRef(); object->addRef();
} }
ConfObj::ConfObj(ConfObj& source)
{
if (object = source.object)
object->addRef();
}
ConfObj::~ConfObj() ConfObj::~ConfObj()
{ {
if (object) if (object)
object->release(); object->release();
} }
ConfObj::ConfObj(const ConfObj& source)
{
if (object)
object->release();
if (object = source.object)
object->addRef();
}
bool ConfObj::hasObject() const bool ConfObj::hasObject() const
{ {
return object != NULL; return object != NULL;

View File

@ -34,7 +34,9 @@ class ConfObject;
class ConfObj class ConfObj
{ {
public: public:
ConfObj();
explicit ConfObj(ConfObject *confObject); explicit ConfObj(ConfObject *confObject);
ConfObj(ConfObj& source);
~ConfObj(); ~ConfObj();
operator ConfObject*() { return object; } operator ConfObject*() { return object; }
@ -42,10 +44,10 @@ public:
const ConfObject* operator -> () const { return object; } const ConfObject* operator -> () const { return object; }
ConfObject* operator = (ConfObject *source); ConfObject* operator = (ConfObject *source);
ConfObject *object;
ConfObj(const ConfObj& source);
ConfObj();
bool hasObject() const; bool hasObject() const;
private:
ConfObject *object;
}; };
END_NAMESPACE END_NAMESPACE

View File

@ -74,7 +74,7 @@ ConfObject::~ConfObject()
chain->release(); chain->release();
} }
bool ConfObject::matches(Element *element, const char* type, const char* string) bool ConfObject::matches(Element* element, const char* type, const char* string)
{ {
if (element->name != type) if (element->name != type)
return false; return false;
@ -123,6 +123,7 @@ bool ConfObject::match(int position, const char* pattern, const char* string)
const char *s = string; const char *s = string;
for (const char *p = pattern; (c = *p++); ++s) for (const char *p = pattern; (c = *p++); ++s)
{
if (c == '*') if (c == '*')
{ {
if (!*p) if (!*p)
@ -131,16 +132,20 @@ bool ConfObject::match(int position, const char* pattern, const char* string)
return true; return true;
} }
for (; *s; ++s) for (; *s; ++s)
{
if (match (position + 1, pattern + 1, s)) if (match (position + 1, pattern + 1, s))
{ {
putString (position, string, (int) (s - string)); putString (position, string, (int) (s - string));
return true; return true;
} }
}
return false; return false;
} }
else if (!*s)
if (!*s)
return false; return false;
else if (c != '%' && c != *s)
if (c != '%' && c != *s)
{ {
#ifdef _WIN32 #ifdef _WIN32
if (UPPER (c) == UPPER (*s)) if (UPPER (c) == UPPER (*s))
@ -150,6 +155,7 @@ bool ConfObject::match(int position, const char* pattern, const char* string)
#endif #endif
return false; return false;
} }
}
if (c || *s) if (c || *s)
return false; return false;

View File

@ -41,12 +41,14 @@ class ConfigFile;
class ConfObject : public RefObject class ConfObject : public RefObject
{ {
public: public:
ConfObject(ConfigFile *confFile); explicit ConfObject(ConfigFile *confFile);
virtual ~ConfObject();
virtual const char* getValue(const char* option, const char *defaultValue); virtual const char* getValue(const char* option, const char *defaultValue);
virtual int getValue(const char* option, int defaultValue); virtual int getValue(const char* option, int defaultValue);
virtual bool getValue(const char* option, bool defaultValue); virtual bool getValue(const char* option, bool defaultValue);
virtual const char* getValue(int instanceNumber, const char* attributeName); virtual const char* getValue(int instanceNumber, const char* attributeName);
virtual bool matches(Element *element, const char* type, const char* string); virtual bool matches(Element* element, const char* type, const char* string);
virtual void setChain(ConfObject* object); virtual void setChain(ConfObject* object);
virtual const char* getName(); virtual const char* getName();
virtual const char* getConcatenatedValues(const char* attributeName); virtual const char* getConcatenatedValues(const char* attributeName);
@ -61,8 +63,6 @@ protected:
virtual Element* findAttribute(const char* attributeName); virtual Element* findAttribute(const char* attributeName);
virtual const char* getValue(const Element* attribute); virtual const char* getValue(const Element* attribute);
virtual ~ConfObject();
public: public:
Element *object; Element *object;

View File

@ -96,20 +96,22 @@ void ConfigFile::init(int configFlags)
memset (hashTable, 0, sizeof (hashTable)); memset (hashTable, 0, sizeof (hashTable));
} }
ConfigFile::~ConfigFile(void) ConfigFile::~ConfigFile()
{ {
if (objects) if (objects)
delete objects; delete objects;
for (int n = 0; n < HASH_SIZE; ++n) for (int n = 0; n < HASH_SIZE; ++n)
{
for (Element *element; element = hashTable [n];) for (Element *element; element = hashTable [n];)
{ {
hashTable [n] = element->sibling; hashTable [n] = element->sibling;
delete element; delete element;
} }
}
} }
InputFile* ConfigFile::openConfigFile(void) InputFile* ConfigFile::openConfigFile()
{ {
fb_assert(false); fb_assert(false);
// Vulcan specific code removed // Vulcan specific code removed
@ -137,7 +139,7 @@ void ConfigFile::parse(void)
else else
{ {
Element *element = parseAttribute(); Element *element = parseAttribute();
int slot = element->name.hash (HASH_SIZE); const int slot = element->name.hash (HASH_SIZE);
element->sibling = hashTable [slot]; element->sibling = hashTable [slot];
hashTable [slot] = element; hashTable [slot] = element;
} }
@ -202,8 +204,10 @@ ConfObject* ConfigFile::findObject(const char* objectType, const char* objectNam
ConfObject *object = new ConfObject (this); ConfObject *object = new ConfObject (this);
for (Element *child = objects->children; child; child = child->sibling) for (Element *child = objects->children; child; child = child->sibling)
{
if (object->matches (child, objectType, objectName)) if (object->matches (child, objectType, objectName))
return object; return object;
}
object->release(); object->release();

View File

@ -45,6 +45,7 @@ class ConfigFile : public Lex, public RefObject
{ {
public: public:
explicit ConfigFile(int configFlags); explicit ConfigFile(int configFlags);
ConfigFile(const char* configFile, int configFlags);
//protected: //protected:
virtual ~ConfigFile(); virtual ~ConfigFile();
@ -64,12 +65,11 @@ public:
const char* translate(const char *value, Element *object); const char* translate(const char *value, Element *object);
void init(int configFlags); void init(int configFlags);
ConfigFile(const char* configFile, int configFlags);
void wildCardInclude(const char* fileName); void wildCardInclude(const char* fileName);
const Element* getObjects() const { return objects; }
Element* objects;
private: private:
Element* objects;
JString rootDirectory; JString rootDirectory;
JString installDirectory; JString installDirectory;
JString currentDirectory; JString currentDirectory;

View File

@ -31,12 +31,12 @@
static ConfigFile *configFile; static ConfigFile *configFile;
Configuration::Configuration(void) Configuration::Configuration()
{ {
configFile = NULL; configFile = NULL;
} }
Configuration::~Configuration(void) Configuration::~Configuration()
{ {
if (configFile) if (configFile)
configFile->release(); configFile->release();
@ -50,7 +50,7 @@ ConfObject* Configuration::findObject(const char* objectType, const char* object
return configFile->findObject (objectType, objectName); return configFile->findObject (objectType, objectName);
} }
const char* Configuration::getRootDirectory(void) const char* Configuration::getRootDirectory()
{ {
if (!configFile) if (!configFile)
loadConfigFile(); loadConfigFile();
@ -58,7 +58,7 @@ const char* Configuration::getRootDirectory(void)
return configFile->getRootDirectory(); return configFile->getRootDirectory();
} }
void Configuration::loadConfigFile(void) void Configuration::loadConfigFile()
{ {
if (!configFile) if (!configFile)
configFile = new ConfigFile (0); configFile = new ConfigFile (0);

View File

@ -35,12 +35,12 @@ class ConfObject;
class Configuration class Configuration
{ {
public: public:
Configuration(void); Configuration();
virtual ~Configuration(void); virtual ~Configuration();
static ConfObject* findObject(const char* objectType, const char* objectName); static ConfObject* findObject(const char* objectType, const char* objectName);
static const char* getRootDirectory(void); static const char* getRootDirectory();
static void loadConfigFile(void); static void loadConfigFile();
static void setConfigFilePath(const char* filename); static void setConfigFilePath(const char* filename);
static ConfObject* getObject(const char* objectType); static ConfObject* getObject(const char* objectType);
static ConfObject* getObject(const char* objectType, const char* objectName); static ConfObject* getObject(const char* objectType, const char* objectName);

View File

@ -17,10 +17,12 @@ FileName::FileName(JString name)
absolute = IS_SLASH (start [0]); absolute = IS_SLASH (start [0]);
for (const char *p = start; *p; ++p) for (const char *p = start; *p; ++p)
{
if (!dot && IS_SLASH (*p)) if (!dot && IS_SLASH (*p))
slash = p; slash = p;
else if (*p == '.') else if (*p == '.')
dot = p; dot = p;
}
if (slash) if (slash)
@ -38,6 +40,6 @@ FileName::FileName(JString name)
root = rootName; root = rootName;
} }
FileName::~FileName(void) FileName::~FileName()
{ {
} }

View File

@ -7,13 +7,16 @@ class FileName
{ {
public: public:
FileName(JString name); FileName(JString name);
~FileName(void); ~FileName();
JString pathName; JString pathName;
JString directory; JString directory;
JString root; JString root;
JString extension; JString extension;
bool isAbsolute() const { return absolute; }
private:
bool absolute; bool absolute;
}; };
#endif #endif

View File

@ -64,7 +64,7 @@ InputFile::InputFile(const char *name)
throw AdminException ("can't open file \"%s\"", name); throw AdminException ("can't open file \"%s\"", name);
} }
InputFile::InputFile(void) InputFile::InputFile()
{ {
changes = NULL; changes = NULL;
} }
@ -137,10 +137,10 @@ void InputFile::rewrite()
FILE *input = fopen (fileName, "r"); FILE *input = fopen (fileName, "r");
if (!input) if (!input)
throw AdminException ("can't open \"%s\" for input", (const char*) fileName); throw AdminException ("can't open \"%s\" for input", fileName.getString());
char tempName [MAX_FILE_NAME]; char tempName [MAX_FILE_NAME];
sprintf (tempName, "%s.tmp", (const char*) fileName); sprintf (tempName, "%.*s.tmp", sizeof(tempName) - 5, fileName.getString());
FILE *output = fopen (tempName,"w"); FILE *output = fopen (tempName,"w");
if (!output) if (!output)
@ -152,8 +152,10 @@ void InputFile::rewrite()
for (FileChange *change = changes; change; change = change->next) for (FileChange *change = changes; change; change = change->next)
{ {
for (; line < change->lineNumber; ++line) for (; line < change->lineNumber; ++line)
{
if (fgets (temp, sizeof (temp), input)) if (fgets (temp, sizeof (temp), input))
fputs (temp, output); fputs (temp, output);
}
//fputs ("#insertion starts here\n", output); //fputs ("#insertion starts here\n", output);
fputs (change->insertion, output); fputs (change->insertion, output);
//fputs ("#insertion end here\n", output); //fputs ("#insertion end here\n", output);
@ -170,11 +172,13 @@ void InputFile::rewrite()
char filename1 [MAX_FILE_NAME]; char filename1 [MAX_FILE_NAME];
char filename2 [MAX_FILE_NAME]; char filename2 [MAX_FILE_NAME];
fb_assert(BACKUP_FILES < 10); // assumption to avoid B.O.
for (int n = BACKUP_FILES; n >= 0; --n) for (int n = BACKUP_FILES; n >= 0; --n)
{ {
sprintf (filename1, "%s.%d", (const char*) fileName, n); sprintf (filename1, "%.*s.%d", sizeof(filename1) - 3, (const char*) fileName, n);
if (n) if (n)
sprintf (filename2, "%s.%d", (const char*) fileName, n - 1); sprintf (filename2, "%.*s.%d", sizeof(filename2) - 3, (const char*) fileName, n - 1);
else else
strcpy (filename2, fileName); strcpy (filename2, fileName);
if (n == BACKUP_FILES) if (n == BACKUP_FILES)
@ -190,15 +194,19 @@ bool InputFile::pathEqual(const char *path1, const char *path2)
{ {
#ifdef _WIN32 #ifdef _WIN32
for (; *path1 && *path2; ++path1, ++path2) for (; *path1 && *path2; ++path1, ++path2)
{
if (*path1 != *path2 && if (*path1 != *path2 &&
UPPER (*path1) != UPPER (*path2) && UPPER (*path1) != UPPER (*path2) &&
!((*path1 == '/' || *path1 == '\\') && !((*path1 == '/' || *path1 == '\\') &&
(*path2 == '/' || *path2 == '\\'))) (*path2 == '/' || *path2 == '\\')))
return false; return false;
}
#else #else
for (; *path1 && *path2; ++path1, ++path2) for (; *path1 && *path2; ++path1, ++path2)
{
if (*path1 != *path2) if (*path1 != *path2)
return false; return false;
}
#endif #endif
return *path1 == 0 && *path2 == 0; return *path1 == 0 && *path2 == 0;

View File

@ -42,16 +42,13 @@
START_NAMESPACE START_NAMESPACE
struct FileChange {
FileChange *next;
int lineNumber;
int linesSkipped;
JString insertion;
};
class InputFile : public InputStream class InputFile : public InputStream
{ {
public: public:
explicit InputFile(const char* fileName);
InputFile();
virtual ~InputFile();
static bool pathEqual(const char *path1, const char *path2); static bool pathEqual(const char *path1, const char *path2);
void rewrite(); void rewrite();
void postChange (int lineNumber, int skip, JString insertion); void postChange (int lineNumber, int skip, JString insertion);
@ -59,15 +56,21 @@ public:
virtual const char* getFileName(); virtual const char* getFileName();
virtual const char* getSegment(); virtual const char* getSegment();
virtual void close(); virtual void close();
InputFile(const char *fileName);
virtual ~InputFile();
JString fileName; bool openInputFile(const char* fileName);
private:
struct FileChange
{
FileChange *next;
int lineNumber;
int linesSkipped;
JString insertion;
};
void *file; void *file;
char buffer [1024]; char buffer [1024];
FileChange *changes; JString fileName;
InputFile(void); FileChange* changes;
bool openInputFile(const char* fileName);
}; };
END_NAMESPACE END_NAMESPACE

View File

@ -42,25 +42,29 @@ class InputFile;
class InputStream class InputStream
{ {
public: public:
explicit InputStream (const char* stuff);
InputStream();
virtual ~InputStream();
virtual InputFile* getInputFile(); virtual InputFile* getInputFile();
virtual const char* getFileName(); virtual const char* getFileName();
void init(); void init();
void release(); void release();
virtual void addRef(); virtual void addRef();
InputStream (const char *stuff);
virtual void close(); virtual void close();
virtual const char* getEnd(); virtual const char* getEnd();
virtual int getOffset (const char *ptr); virtual int getOffset (const char *ptr);
virtual const char* getSegment(); virtual const char* getSegment();
InputStream();
virtual ~InputStream();
int segmentLength;
int segmentOffset;
int lineNumber; int lineNumber;
const char *segment; const char *segment;
const char *ptr; const char *ptr;
InputStream *prior; InputStream *prior;
protected:
int segmentLength; // used by InputFile
private:
int segmentOffset;
int useCount; int useCount;
}; };

View File

@ -81,9 +81,12 @@ void Lex::skipWhite()
for (;;) for (;;)
{ {
while (ptr >= end) while (ptr >= end)
{
if (!getSegment()) if (!getSegment())
return; return;
}
while (ptr < end) while (ptr < end)
{
if (lineComment && lineComment [0] == *ptr && match (lineComment, ptr)) if (lineComment && lineComment [0] == *ptr && match (lineComment, ptr))
{ {
while (ptr < end && *ptr++ != '\n') while (ptr < end && *ptr++ != '\n')
@ -118,7 +121,7 @@ void Lex::skipWhite()
else else
return; return;
} }
}
} }
// Just another custom memcmp-like routine. // Just another custom memcmp-like routine.

View File

@ -68,6 +68,9 @@ class Stream;
class Lex class Lex
{ {
public: public:
Lex(const char *punctuation, int debugFlags);
virtual ~Lex();
void captureStuff(); void captureStuff();
char& charTable(int ch); char& charTable(int ch);
bool getSegment(); bool getSegment();
@ -84,16 +87,13 @@ public:
void getToken(); void getToken();
static bool match (const char *pattern, const char *string); static bool match (const char *pattern, const char *string);
void skipWhite(); void skipWhite();
Lex(const char *punctuation, int debugFlags); protected:
virtual ~Lex();
int flags; int flags;
int tokenType; int tokenType;
int priorLineNumber; int priorLineNumber;
bool eol; bool eol;
InputStream *inputStream; InputStream *inputStream;
InputStream *priorInputStream; InputStream *priorInputStream;
private: private:
InputStream *tokenInputStream; InputStream *tokenInputStream;
Stream stuff; Stream stuff;

View File

@ -127,8 +127,10 @@ bool ScanDir::match(const char *pattern, const char *name)
if (!pattern [1]) if (!pattern [1])
return true; return true;
for (const char *p = name; *p; ++p) for (const char *p = name; *p; ++p)
{
if (match (pattern + 1, p)) if (match (pattern + 1, p))
return true; return true;
}
return false; return false;
} }

View File

@ -50,19 +50,21 @@
class ScanDir class ScanDir
{ {
public: public:
ScanDir(const char *dir, const char *pattern);
virtual ~ScanDir();
bool isDots(); bool isDots();
const char* getFilePath(); const char* getFilePath();
bool isDirectory(); bool isDirectory();
static bool match (const char *pattern, const char *name); static bool match (const char *pattern, const char *name);
const char* getFileName(); const char* getFileName();
bool next(); bool next();
ScanDir(const char *dir, const char *pattern);
virtual ~ScanDir();
JString directory; JString directory;
JString pattern; JString pattern;
JString fileName; JString fileName;
JString filePath; JString filePath;
private:
#ifdef _WIN32 #ifdef _WIN32
WIN32_FIND_DATA data; WIN32_FIND_DATA data;
HANDLE handle; HANDLE handle;

View File

@ -37,6 +37,10 @@
#include "Stream.h" #include "Stream.h"
#include "StreamSegment.h" #include "StreamSegment.h"
// CVC: The logic in this module seems to overwrite constant params passed into the
// address field of the Segment structure. This includes literal strings (see Element.cpp).
#ifndef MAX #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) #define MIN(a,b) ((a < b) ? a : b)
@ -112,7 +116,7 @@ void Stream::putSegment(int length, const char *ptr, bool copy)
int l = currentLength - current->length; int l = currentLength - current->length;
if (l > 0) if (l > 0)
{ {
int l2 = MIN (l, length); const int l2 = MIN (l, length);
memcpy (current->address + current->length, address, l2); memcpy (current->address + current->length, address, l2);
current->length += l2; current->length += l2;
length -= l2; length -= l2;
@ -505,7 +509,7 @@ void Stream::putSegment(Stream * stream)
if (stream->totalLength == 0) if (stream->totalLength == 0)
return; return;
StreamSegment seg = stream; StreamSegment seg(stream);
if (current) if (current)
for (int len = currentLength - current->length; len && seg.available;) for (int len = currentLength - current->length; len && seg.available;)
@ -545,7 +549,7 @@ char* Stream::alloc(int length)
if (!current || length > currentLength - current->length) if (!current || length > currentLength - current->length)
allocSegment (length); allocSegment (length);
char *p = current->tail + current->length; char* const p = current->tail + current->length;
current->length += length; current->length += length;
return p; return p;
@ -592,8 +596,8 @@ int Stream::compare(const Stream *stream) const
{ {
for (int offset = 0;;) for (int offset = 0;;)
{ {
int length1 = getSegmentLength(offset); const int length1 = getSegmentLength(offset);
int length2 = stream->getSegmentLength(offset); const int length2 = stream->getSegmentLength(offset);
if (length1 == 0) if (length1 == 0)
{ {
if (length2) if (length2)

View File

@ -53,6 +53,9 @@ struct Segment
class Stream class Stream
{ {
public: public:
explicit Stream (int minSegmentSize = FIXED_SEGMENT_SIZE);
virtual ~Stream();
int compare (const Stream *stream) const; int compare (const Stream *stream) const;
void truncate (int length); void truncate (int length);
void format (const char *pattern, ...); void format (const char *pattern, ...);
@ -78,18 +81,15 @@ public:
Segment* allocSegment (int tail); Segment* allocSegment (int tail);
void setMinSegment (int length); void setMinSegment (int length);
explicit Stream (int minSegmentSize = FIXED_SEGMENT_SIZE);
virtual ~Stream();
int totalLength; int totalLength;
//int useCount;
Segment *segments; // used by StreamSegment::setStream
private:
int minSegment; int minSegment;
int currentLength; int currentLength;
int decompressedLength; int decompressedLength;
int useCount;
bool copyFlag; bool copyFlag;
Segment first; Segment first;
Segment *segments;
Segment *current; Segment *current;
}; };

View File

@ -77,7 +77,7 @@ void StreamSegment::advance(int size)
{ {
for (int len = size; len;) for (int len = size; len;)
{ {
int l = MIN (available, len); const int l = MIN (available, len);
available -= l; available -= l;
remaining -= l; remaining -= l;
len -= size; len -= size;
@ -100,7 +100,7 @@ char* StreamSegment::copy(void *target, int length)
for (int len = length; len;) for (int len = length; len;)
{ {
int l = MIN (len, available); const int l = MIN (len, available);
memcpy (targ, data, l); memcpy (targ, data, l);
targ += l; targ += l;
len -= l; len -= l;

View File

@ -44,13 +44,16 @@ struct Segment;
class StreamSegment class StreamSegment
{ {
public: public:
explicit StreamSegment(Stream *stream);
virtual ~StreamSegment();
char* copy (void *target, int length); char* copy (void *target, int length);
void advance (int size); void advance (int size);
void advance(); void advance();
void setStream (Stream *stream); void setStream (Stream *stream);
StreamSegment(Stream *stream);
virtual ~StreamSegment();
private:
friend class Stream; // for "available" and "remaining"
int available; int available;
int remaining; int remaining;
char *data; char *data;

View File

@ -417,7 +417,7 @@ bool IntlManager::initialize()
if (s.hasData()) if (s.hasData())
builtinConfig = s; builtinConfig = s;
for (const Element* el = configFile.objects->children; el; el = el->sibling) for (const Element* el = configFile.getObjects()->children; el; el = el->sibling)
{ {
if (el->name == "charset") if (el->name == "charset")
{ {

View File

@ -45,7 +45,7 @@
static char THIS_FILE[]=__FILE__; static char THIS_FILE[]=__FILE__;
#endif #endif
JString::JString () JString::JString ()
{ {
/************************************** /**************************************
@ -61,7 +61,7 @@ JString::JString ()
string = NULL; string = NULL;
} }
JString::JString (const char *stuff) JString::JString (const char *stuff)
{ {
/************************************** /**************************************
@ -79,6 +79,12 @@ JString::JString (const char *stuff)
setString (stuff); setString (stuff);
} }
JString::JString(const char * source, int len)
{
string = NULL;
setString (source, len);
}
JString::JString (const JString& source) JString::JString (const JString& source)
{ {
/************************************** /**************************************
@ -145,7 +151,7 @@ void JString::append (const char* stuff)
if (--((int*) temp)[0] == 0) if (--((int*) temp)[0] == 0)
delete [] temp; delete [] temp;
} }
void JString::setString (const char* stuff) void JString::setString (const char* stuff)
{ {
/************************************** /**************************************
@ -457,7 +463,8 @@ JString& JString::operator =(const WCHAR * wString)
void JString::setString(const char * source, int len) void JString::setString(const char * source, int len)
{ {
char *old = string; fb_assert(len >= 0);
char* const old = string;
allocSpace (len); allocSpace (len);
memcpy (string, source, len); memcpy (string, source, len);
string[len] = 0; string[len] = 0;
@ -483,7 +490,7 @@ int JString::findSubstring(const char * string, const char * sub)
JString JString::upcase(const char * source) JString JString::upcase(const char * source)
{ {
JString string; JString string;
int len = (int) strlen (source); const int len = (int) strlen (source);
string.alloc (len); string.alloc (len);
for (int n = 0; n < len; ++n) for (int n = 0; n < len; ++n)
@ -512,8 +519,10 @@ bool JString::equalsNoCase(const char * string2) const
const char *p; const char *p;
for (p = string; *p && *string2; ++p, ++string2) for (p = string; *p && *string2; ++p, ++string2)
{
if (UPPER (*p) != UPPER (*string2)) if (UPPER (*p) != UPPER (*string2))
return false; return false;
}
return *p == *string2; return *p == *string2;
} }
@ -523,20 +532,13 @@ int JString::length() const
if (!string) if (!string)
return 0; return 0;
const char *p; const char* p = string;
while (*p)
for (p = string; *p; ++p) ++p;
;
return (int) (p - string); return (int) (p - string);
} }
JString::JString(const char * source, int len)
{
string = NULL;
setString (source, len);
}
char* JString::getBuffer(int len) char* JString::getBuffer(int len)
{ {
alloc (len); alloc (len);

View File

@ -34,10 +34,10 @@ START_NAMESPACE
class JString class JString
{ {
public: public:
JString (const char *source, int length);
JString(); JString();
JString (const char *string); JString (const char *stuff);
JString(const JString& stringSrc); JString (const char *source, int length);
JString(const JString& source);
~JString(); ~JString();
//JString& operator = (const WCHAR *wString); //JString& operator = (const WCHAR *wString);

View File

@ -53,15 +53,15 @@
#define IS_LETTER(c) ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) #define IS_LETTER(c) ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
//#define UPPER(c) ((c >= 'a' && c <= 'z') ? c - 'a' + 'A' : c) //#define UPPER(c) ((c >= 'a' && c <= 'z') ? c - 'a' + 'A' : c)
PathName::PathName(void) PathName::PathName()
{ {
} }
PathName::~PathName(void) PathName::~PathName()
{ {
} }
const char* PathName::getWorkingDirectory(void) const char* PathName::getWorkingDirectory()
{ {
static char workingDirectory [MAXPATHLEN]; static char workingDirectory [MAXPATHLEN];
@ -85,11 +85,11 @@ const char* PathName::getWorkingDirectory(void)
int PathName::findWorkingDirectory(int dpbLength, const UCHAR* dpb, int bufferLength, char* buffer) int PathName::findWorkingDirectory(int dpbLength, const UCHAR* dpb, int bufferLength, char* buffer)
{ {
const UCHAR *p = dpb, *end = dpb + dpbLength; const UCHAR *p = dpb, *end = dpb + dpbLength;
int length;
if (dpbLength <= 0 || *p++ != isc_dpb_version1) if (dpbLength <= 0 || *p++ != isc_dpb_version1)
return 0; return 0;
int length = 0;
for (; p < end; p += length) for (; p < end; p += length)
{ {
const UCHAR verb = *p++; const UCHAR verb = *p++;
@ -98,7 +98,7 @@ int PathName::findWorkingDirectory(int dpbLength, const UCHAR* dpb, int bufferLe
if (verb == isc_dpb_working_directory) if (verb == isc_dpb_working_directory)
{ {
int l = MIN (bufferLength - 1, length); const int l = MIN (bufferLength - 1, length);
memcpy (buffer, p, l); memcpy (buffer, p, l);
buffer [l] = 0; buffer [l] = 0;
return length; return length;
@ -128,8 +128,10 @@ JString PathName::expandFilename(const char* fileName, const char* workingDirect
#ifdef _WIN32 #ifdef _WIN32
for (char *p = buffer; *p; ++p) for (char *p = buffer; *p; ++p)
{
if (*p == '/') if (*p == '/')
*p = SEPARATOR; *p = SEPARATOR;
}
#endif #endif
return JString (buffer, length); return JString (buffer, length);
@ -249,8 +251,10 @@ JString PathName::expandFilename(const char* fileName)
bool PathName::hasDirectory(const char* fileName) bool PathName::hasDirectory(const char* fileName)
{ {
for (const char *p = fileName; *p; ++p) for (const char *p = fileName; *p; ++p)
{
if (IS_SEPARATOR (*p)) if (IS_SEPARATOR (*p))
return true; return true;
}
return false; return false;
} }

View File

@ -36,9 +36,10 @@
class PathName class PathName
{ {
public: public:
PathName(void); PathName();
virtual ~PathName(void); virtual ~PathName();
static const char* getWorkingDirectory(void);
static const char* getWorkingDirectory();
static int findWorkingDirectory(int dpbLength, const UCHAR* dpb, int bufferLength, char* buffer); static int findWorkingDirectory(int dpbLength, const UCHAR* dpb, int bufferLength, char* buffer);
static JString expandFilename(const char* fileName, int dpbLength, const UCHAR* dpb); static JString expandFilename(const char* fileName, int dpbLength, const UCHAR* dpb);
static JString expandFilename(const char* fileName, const char* workingDirectory); static JString expandFilename(const char* fileName, const char* workingDirectory);

View File

@ -38,10 +38,10 @@
class RefObject class RefObject
{ {
public: public:
virtual void release();
virtual void addRef();
RefObject(); RefObject();
virtual ~RefObject(); virtual ~RefObject();
virtual void addRef();
virtual void release();
private: private:
int useCount; int useCount;
}; };