From 60802a9d77a9855e87ef5593afc31b65cc41a3e7 Mon Sep 17 00:00:00 2001 From: robocop Date: Sun, 20 Apr 2008 10:40:58 +0000 Subject: [PATCH] Fix the most obvioius problems: - style (few fixes only) - constness - total lack of encapsulation (all data members exposed in the interface). --- src/config/AdminException.cpp | 10 +++++----- src/config/AdminException.h | 3 ++- src/config/Args.cpp | 6 +++++- src/config/Args.h | 2 +- src/config/ArgsException.cpp | 2 +- src/config/ArgsException.h | 3 ++- src/config/ConfObj.cpp | 15 ++++++--------- src/config/ConfObj.h | 10 ++++++---- src/config/ConfObject.cpp | 28 +++++++++++++++++----------- src/config/ConfObject.h | 8 ++++---- src/config/ConfigFile.cpp | 14 +++++++++----- src/config/ConfigFile.h | 6 +++--- src/config/Configuration.cpp | 8 ++++---- src/config/Configuration.h | 8 ++++---- src/config/FileName.cpp | 4 +++- src/config/FileName.h | 5 ++++- src/config/InputFile.cpp | 18 +++++++++++++----- src/config/InputFile.h | 31 +++++++++++++++++-------------- src/config/InputStream.h | 14 +++++++++----- src/config/Lex.cpp | 7 +++++-- src/config/Lex.h | 8 ++++---- src/config/ScanDir.cpp | 2 ++ src/config/ScanDir.h | 6 ++++-- src/config/Stream.cpp | 14 +++++++++----- src/config/Stream.h | 12 ++++++------ src/config/StreamSegment.cpp | 4 ++-- src/config/StreamSegment.h | 7 +++++-- src/jrd/IntlManager.cpp | 2 +- src/vulcan/JString.cpp | 32 +++++++++++++++++--------------- src/vulcan/JString.h | 8 ++++---- src/vulcan/PathName.cpp | 16 ++++++++++------ src/vulcan/PathName.h | 7 ++++--- src/vulcan/RefObject.h | 4 ++-- 33 files changed, 190 insertions(+), 134 deletions(-) diff --git a/src/config/AdminException.cpp b/src/config/AdminException.cpp index dc53989a1b..81da50bd86 100644 --- a/src/config/AdminException.cpp +++ b/src/config/AdminException.cpp @@ -54,16 +54,16 @@ AdminException::AdminException(const char *txt, ...) if (ret < 0) { - int l = sizeof (temp) * 2; - char *buffer = new char [l]; + const int l = sizeof (temp) * 2; + char* const buffer = new char [l]; vsnprintf (buffer, l, txt, args); text = buffer; delete [] buffer; } else if (static_cast(ret) >= sizeof (temp)) { - int l = ret + 1; - char *buffer = new char [l]; + const int l = ret + 1; + char* const buffer = new char [l]; vsnprintf (buffer, l, txt, args); text = buffer; delete [] buffer; @@ -79,7 +79,7 @@ AdminException::~AdminException() } -const char* AdminException::getText() +const char* AdminException::getText() const { return text; } diff --git a/src/config/AdminException.h b/src/config/AdminException.h index 646f686c00..01a21aba1f 100644 --- a/src/config/AdminException.h +++ b/src/config/AdminException.h @@ -41,10 +41,11 @@ class AdminException { public: void setLocation (JString fileName, int lineNumber); - const char* getText(); + const char* getText() const; AdminException(const char *txt, ...); virtual ~AdminException(); +private: JString text; JString fileName; }; diff --git a/src/config/Args.cpp b/src/config/Args.cpp index 613536e9ac..6dccee0f7c 100644 --- a/src/config/Args.cpp +++ b/src/config/Args.cpp @@ -59,7 +59,7 @@ void Args::parse(const Switches *switches, int argc, char **argv) { for (char **arg = argv, **end = arg + argc; arg < end;) { - char *p = *arg++; + const char *p = *arg++; const Switches *parameter = NULL; bool hit = false; for (const Switches *sw = switches; sw->string; ++sw) @@ -114,6 +114,7 @@ void Args::printHelp(const char *helpText, const Switches *switches) const Switches *sw; for (sw = switches; sw->string; ++sw) + { if (sw->description) { int l = (int) strlen (sw->string); @@ -126,6 +127,7 @@ void Args::printHelp(const char *helpText, const Switches *switches) argLength = l; } } + } if (helpText) printf (helpText); @@ -133,11 +135,13 @@ void Args::printHelp(const char *helpText, const Switches *switches) printf ("Options are:\n"); 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) diff --git a/src/config/Args.h b/src/config/Args.h index 6e5376a59e..6537ec9ca5 100644 --- a/src/config/Args.h +++ b/src/config/Args.h @@ -39,7 +39,7 @@ struct Switches { const char *string; bool *boolean; - char **argument; + const char* *argument; const char *argName; const char *description; }; diff --git a/src/config/ArgsException.cpp b/src/config/ArgsException.cpp index 3f1913f84e..bb83831670 100644 --- a/src/config/ArgsException.cpp +++ b/src/config/ArgsException.cpp @@ -60,7 +60,7 @@ ArgsException::~ArgsException() } -const char* ArgsException::getText() +const char* ArgsException::getText() const { return text; } diff --git a/src/config/ArgsException.h b/src/config/ArgsException.h index 4e9a6fdff7..ec647326bb 100644 --- a/src/config/ArgsException.h +++ b/src/config/ArgsException.h @@ -39,10 +39,11 @@ class ArgsException { public: - const char* getText(); + const char* getText() const; ArgsException(const char * txt, ...); virtual ~ArgsException(); +private: JString text; }; diff --git a/src/config/ConfObj.cpp b/src/config/ConfObj.cpp index 86e09a7f12..280cd7255f 100644 --- a/src/config/ConfObj.cpp +++ b/src/config/ConfObj.cpp @@ -40,21 +40,18 @@ ConfObj::ConfObj(ConfObject *confObject) object->addRef(); } +ConfObj::ConfObj(ConfObj& source) +{ + if (object = source.object) + object->addRef(); +} + ConfObj::~ConfObj() { if (object) object->release(); } -ConfObj::ConfObj(const ConfObj& source) -{ - if (object) - object->release(); - - if (object = source.object) - object->addRef(); -} - bool ConfObj::hasObject() const { return object != NULL; diff --git a/src/config/ConfObj.h b/src/config/ConfObj.h index ed8c94ffdf..fa3e7a3e6e 100644 --- a/src/config/ConfObj.h +++ b/src/config/ConfObj.h @@ -34,18 +34,20 @@ class ConfObject; class ConfObj { public: + ConfObj(); 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 *object; - ConfObj(const ConfObj& source); - ConfObj(); + bool hasObject() const; + +private: + ConfObject *object; }; END_NAMESPACE diff --git a/src/config/ConfObject.cpp b/src/config/ConfObject.cpp index 134088bb84..06ccd46c1b 100644 --- a/src/config/ConfObject.cpp +++ b/src/config/ConfObject.cpp @@ -74,7 +74,7 @@ ConfObject::~ConfObject() 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) return false; @@ -123,25 +123,30 @@ bool ConfObject::match(int position, const char* pattern, const char* string) const char *s = string; for (const char *p = pattern; (c = *p++); ++s) + { if (c == '*') - { + { if (!*p) - { + { putString (position, string, (int) strlen (string)); return true; - } + } for (; *s; ++s) + { if (match (position + 1, pattern + 1, s)) - { + { putString (position, string, (int) (s - string)); return true; - } - return false; + } } - else if (!*s) return false; - else if (c != '%' && c != *s) - { + } + + if (!*s) + return false; + + if (c != '%' && c != *s) + { #ifdef _WIN32 if (UPPER (c) == UPPER (*s)) continue; @@ -149,7 +154,8 @@ bool ConfObject::match(int position, const char* pattern, const char* string) continue; #endif return false; - } + } + } if (c || *s) return false; diff --git a/src/config/ConfObject.h b/src/config/ConfObject.h index f579fb83ef..249bb94894 100644 --- a/src/config/ConfObject.h +++ b/src/config/ConfObject.h @@ -41,12 +41,14 @@ class ConfigFile; class ConfObject : public RefObject { public: - ConfObject(ConfigFile *confFile); + explicit ConfObject(ConfigFile *confFile); + virtual ~ConfObject(); + virtual const char* getValue(const char* option, const char *defaultValue); virtual int getValue(const char* option, int defaultValue); virtual bool getValue(const char* option, bool defaultValue); 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 const char* getName(); virtual const char* getConcatenatedValues(const char* attributeName); @@ -61,8 +63,6 @@ protected: virtual Element* findAttribute(const char* attributeName); virtual const char* getValue(const Element* attribute); - virtual ~ConfObject(); - public: Element *object; diff --git a/src/config/ConfigFile.cpp b/src/config/ConfigFile.cpp index 32c28a8bed..e0496484c2 100644 --- a/src/config/ConfigFile.cpp +++ b/src/config/ConfigFile.cpp @@ -96,20 +96,22 @@ void ConfigFile::init(int configFlags) memset (hashTable, 0, sizeof (hashTable)); } -ConfigFile::~ConfigFile(void) +ConfigFile::~ConfigFile() { if (objects) delete objects; for (int n = 0; n < HASH_SIZE; ++n) + { for (Element *element; element = hashTable [n];) - { + { hashTable [n] = element->sibling; delete element; - } + } + } } -InputFile* ConfigFile::openConfigFile(void) +InputFile* ConfigFile::openConfigFile() { fb_assert(false); // Vulcan specific code removed @@ -137,7 +139,7 @@ void ConfigFile::parse(void) else { Element *element = parseAttribute(); - int slot = element->name.hash (HASH_SIZE); + const int slot = element->name.hash (HASH_SIZE); element->sibling = hashTable [slot]; hashTable [slot] = element; } @@ -202,8 +204,10 @@ ConfObject* ConfigFile::findObject(const char* objectType, const char* objectNam ConfObject *object = new ConfObject (this); for (Element *child = objects->children; child; child = child->sibling) + { if (object->matches (child, objectType, objectName)) return object; + } object->release(); diff --git a/src/config/ConfigFile.h b/src/config/ConfigFile.h index 3ba4cee3c1..2644952863 100644 --- a/src/config/ConfigFile.h +++ b/src/config/ConfigFile.h @@ -45,6 +45,7 @@ class ConfigFile : public Lex, public RefObject { public: explicit ConfigFile(int configFlags); + ConfigFile(const char* configFile, int configFlags); //protected: virtual ~ConfigFile(); @@ -64,12 +65,11 @@ public: const char* translate(const char *value, Element *object); void init(int configFlags); - ConfigFile(const char* configFile, int configFlags); void wildCardInclude(const char* fileName); - - Element* objects; + const Element* getObjects() const { return objects; } private: + Element* objects; JString rootDirectory; JString installDirectory; JString currentDirectory; diff --git a/src/config/Configuration.cpp b/src/config/Configuration.cpp index 8da7c5ae26..88f9423329 100644 --- a/src/config/Configuration.cpp +++ b/src/config/Configuration.cpp @@ -31,12 +31,12 @@ static ConfigFile *configFile; -Configuration::Configuration(void) +Configuration::Configuration() { configFile = NULL; } -Configuration::~Configuration(void) +Configuration::~Configuration() { if (configFile) configFile->release(); @@ -50,7 +50,7 @@ ConfObject* Configuration::findObject(const char* objectType, const char* object return configFile->findObject (objectType, objectName); } -const char* Configuration::getRootDirectory(void) +const char* Configuration::getRootDirectory() { if (!configFile) loadConfigFile(); @@ -58,7 +58,7 @@ const char* Configuration::getRootDirectory(void) return configFile->getRootDirectory(); } -void Configuration::loadConfigFile(void) +void Configuration::loadConfigFile() { if (!configFile) configFile = new ConfigFile (0); diff --git a/src/config/Configuration.h b/src/config/Configuration.h index 2282c1ec21..dd9e05b091 100644 --- a/src/config/Configuration.h +++ b/src/config/Configuration.h @@ -35,12 +35,12 @@ class ConfObject; class Configuration { public: - Configuration(void); - virtual ~Configuration(void); + Configuration(); + virtual ~Configuration(); static ConfObject* findObject(const char* objectType, const char* objectName); - static const char* getRootDirectory(void); - static void loadConfigFile(void); + static const char* getRootDirectory(); + static void loadConfigFile(); static void setConfigFilePath(const char* filename); static ConfObject* getObject(const char* objectType); static ConfObject* getObject(const char* objectType, const char* objectName); diff --git a/src/config/FileName.cpp b/src/config/FileName.cpp index 5c26d24adc..c0cea3ae8b 100644 --- a/src/config/FileName.cpp +++ b/src/config/FileName.cpp @@ -17,10 +17,12 @@ FileName::FileName(JString name) absolute = IS_SLASH (start [0]); for (const char *p = start; *p; ++p) + { if (!dot && IS_SLASH (*p)) slash = p; else if (*p == '.') dot = p; + } if (slash) @@ -38,6 +40,6 @@ FileName::FileName(JString name) root = rootName; } -FileName::~FileName(void) +FileName::~FileName() { } diff --git a/src/config/FileName.h b/src/config/FileName.h index fb537b4172..c5da07642d 100644 --- a/src/config/FileName.h +++ b/src/config/FileName.h @@ -7,13 +7,16 @@ class FileName { public: FileName(JString name); - ~FileName(void); + ~FileName(); JString pathName; JString directory; JString root; JString extension; + bool isAbsolute() const { return absolute; } +private: bool absolute; }; #endif + diff --git a/src/config/InputFile.cpp b/src/config/InputFile.cpp index 1bc83d2f0c..8b8babdd9f 100644 --- a/src/config/InputFile.cpp +++ b/src/config/InputFile.cpp @@ -64,7 +64,7 @@ InputFile::InputFile(const char *name) throw AdminException ("can't open file \"%s\"", name); } -InputFile::InputFile(void) +InputFile::InputFile() { changes = NULL; } @@ -137,10 +137,10 @@ void InputFile::rewrite() FILE *input = fopen (fileName, "r"); 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]; - sprintf (tempName, "%s.tmp", (const char*) fileName); + sprintf (tempName, "%.*s.tmp", sizeof(tempName) - 5, fileName.getString()); FILE *output = fopen (tempName,"w"); if (!output) @@ -152,8 +152,10 @@ void InputFile::rewrite() for (FileChange *change = changes; change; change = change->next) { for (; line < change->lineNumber; ++line) + { if (fgets (temp, sizeof (temp), input)) fputs (temp, output); + } //fputs ("#insertion starts here\n", output); fputs (change->insertion, output); //fputs ("#insertion end here\n", output); @@ -170,11 +172,13 @@ void InputFile::rewrite() char filename1 [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) { - sprintf (filename1, "%s.%d", (const char*) fileName, n); + sprintf (filename1, "%.*s.%d", sizeof(filename1) - 3, (const char*) fileName, 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 strcpy (filename2, fileName); if (n == BACKUP_FILES) @@ -190,15 +194,19 @@ bool InputFile::pathEqual(const char *path1, const char *path2) { #ifdef _WIN32 for (; *path1 && *path2; ++path1, ++path2) + { if (*path1 != *path2 && UPPER (*path1) != UPPER (*path2) && !((*path1 == '/' || *path1 == '\\') && (*path2 == '/' || *path2 == '\\'))) return false; + } #else for (; *path1 && *path2; ++path1, ++path2) + { if (*path1 != *path2) return false; + } #endif return *path1 == 0 && *path2 == 0; diff --git a/src/config/InputFile.h b/src/config/InputFile.h index f1b8e38a35..ef4b6f8bdf 100644 --- a/src/config/InputFile.h +++ b/src/config/InputFile.h @@ -42,16 +42,13 @@ START_NAMESPACE -struct FileChange { - FileChange *next; - int lineNumber; - int linesSkipped; - JString insertion; -}; - -class InputFile : public InputStream +class InputFile : public InputStream { public: + explicit InputFile(const char* fileName); + InputFile(); + virtual ~InputFile(); + static bool pathEqual(const char *path1, const char *path2); void rewrite(); void postChange (int lineNumber, int skip, JString insertion); @@ -59,15 +56,21 @@ public: virtual const char* getFileName(); virtual const char* getSegment(); 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; char buffer [1024]; - FileChange *changes; - InputFile(void); - bool openInputFile(const char* fileName); + JString fileName; + FileChange* changes; }; END_NAMESPACE diff --git a/src/config/InputStream.h b/src/config/InputStream.h index cf9eae6295..519d6348db 100644 --- a/src/config/InputStream.h +++ b/src/config/InputStream.h @@ -42,25 +42,29 @@ class InputFile; class InputStream { public: + explicit InputStream (const char* stuff); + InputStream(); + virtual ~InputStream(); + virtual InputFile* getInputFile(); virtual const char* getFileName(); void init(); void release(); virtual void addRef(); - InputStream (const char *stuff); + virtual void close(); virtual const char* getEnd(); virtual int getOffset (const char *ptr); virtual const char* getSegment(); - InputStream(); - virtual ~InputStream(); - int segmentLength; - int segmentOffset; int lineNumber; const char *segment; const char *ptr; InputStream *prior; +protected: + int segmentLength; // used by InputFile +private: + int segmentOffset; int useCount; }; diff --git a/src/config/Lex.cpp b/src/config/Lex.cpp index dcc103a69d..ee30839122 100644 --- a/src/config/Lex.cpp +++ b/src/config/Lex.cpp @@ -79,11 +79,14 @@ Lex::~Lex() void Lex::skipWhite() { for (;;) - { + { while (ptr >= end) + { if (!getSegment()) return; + } while (ptr < end) + { if (lineComment && lineComment [0] == *ptr && match (lineComment, ptr)) { while (ptr < end && *ptr++ != '\n') @@ -118,7 +121,7 @@ void Lex::skipWhite() else return; } - + } } // Just another custom memcmp-like routine. diff --git a/src/config/Lex.h b/src/config/Lex.h index 6a3d140637..dbcf53dc66 100644 --- a/src/config/Lex.h +++ b/src/config/Lex.h @@ -68,6 +68,9 @@ class Stream; class Lex { public: + Lex(const char *punctuation, int debugFlags); + virtual ~Lex(); + void captureStuff(); char& charTable(int ch); bool getSegment(); @@ -84,16 +87,13 @@ public: void getToken(); static bool match (const char *pattern, const char *string); void skipWhite(); - Lex(const char *punctuation, int debugFlags); - virtual ~Lex(); - +protected: int flags; int tokenType; int priorLineNumber; bool eol; InputStream *inputStream; InputStream *priorInputStream; - private: InputStream *tokenInputStream; Stream stuff; diff --git a/src/config/ScanDir.cpp b/src/config/ScanDir.cpp index db8d8cdd04..4e48f0fd0c 100644 --- a/src/config/ScanDir.cpp +++ b/src/config/ScanDir.cpp @@ -127,8 +127,10 @@ bool ScanDir::match(const char *pattern, const char *name) if (!pattern [1]) return true; for (const char *p = name; *p; ++p) + { if (match (pattern + 1, p)) return true; + } return false; } diff --git a/src/config/ScanDir.h b/src/config/ScanDir.h index 57dfe5bfc0..cd72ae7c9f 100644 --- a/src/config/ScanDir.h +++ b/src/config/ScanDir.h @@ -50,19 +50,21 @@ class ScanDir { public: + ScanDir(const char *dir, const char *pattern); + virtual ~ScanDir(); + bool isDots(); const char* getFilePath(); bool isDirectory(); static bool match (const char *pattern, const char *name); const char* getFileName(); bool next(); - ScanDir(const char *dir, const char *pattern); - virtual ~ScanDir(); JString directory; JString pattern; JString fileName; JString filePath; +private: #ifdef _WIN32 WIN32_FIND_DATA data; HANDLE handle; diff --git a/src/config/Stream.cpp b/src/config/Stream.cpp index 73f3d7b063..33d6c41c18 100644 --- a/src/config/Stream.cpp +++ b/src/config/Stream.cpp @@ -37,6 +37,10 @@ #include "Stream.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 #define MAX(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; if (l > 0) { - int l2 = MIN (l, length); + const int l2 = MIN (l, length); memcpy (current->address + current->length, address, l2); current->length += l2; length -= l2; @@ -505,7 +509,7 @@ void Stream::putSegment(Stream * stream) if (stream->totalLength == 0) return; - StreamSegment seg = stream; + StreamSegment seg(stream); if (current) for (int len = currentLength - current->length; len && seg.available;) @@ -545,7 +549,7 @@ char* Stream::alloc(int length) if (!current || length > currentLength - current->length) allocSegment (length); - char *p = current->tail + current->length; + char* const p = current->tail + current->length; current->length += length; return p; @@ -592,8 +596,8 @@ int Stream::compare(const Stream *stream) const { for (int offset = 0;;) { - int length1 = getSegmentLength(offset); - int length2 = stream->getSegmentLength(offset); + const int length1 = getSegmentLength(offset); + const int length2 = stream->getSegmentLength(offset); if (length1 == 0) { if (length2) diff --git a/src/config/Stream.h b/src/config/Stream.h index 07b28f73cc..f0b04cf1e5 100644 --- a/src/config/Stream.h +++ b/src/config/Stream.h @@ -53,6 +53,9 @@ struct Segment class Stream { public: + explicit Stream (int minSegmentSize = FIXED_SEGMENT_SIZE); + virtual ~Stream(); + int compare (const Stream *stream) const; void truncate (int length); void format (const char *pattern, ...); @@ -78,18 +81,15 @@ public: Segment* allocSegment (int tail); void setMinSegment (int length); - - explicit Stream (int minSegmentSize = FIXED_SEGMENT_SIZE); - virtual ~Stream(); - int totalLength; + //int useCount; + Segment *segments; // used by StreamSegment::setStream +private: int minSegment; int currentLength; int decompressedLength; - int useCount; bool copyFlag; Segment first; - Segment *segments; Segment *current; }; diff --git a/src/config/StreamSegment.cpp b/src/config/StreamSegment.cpp index aade36a517..3446831e6c 100644 --- a/src/config/StreamSegment.cpp +++ b/src/config/StreamSegment.cpp @@ -77,7 +77,7 @@ void StreamSegment::advance(int size) { for (int len = size; len;) { - int l = MIN (available, len); + const int l = MIN (available, len); available -= l; remaining -= l; len -= size; @@ -100,7 +100,7 @@ char* StreamSegment::copy(void *target, int length) for (int len = length; len;) { - int l = MIN (len, available); + const int l = MIN (len, available); memcpy (targ, data, l); targ += l; len -= l; diff --git a/src/config/StreamSegment.h b/src/config/StreamSegment.h index cb75c3766e..fda5fb8923 100644 --- a/src/config/StreamSegment.h +++ b/src/config/StreamSegment.h @@ -44,13 +44,16 @@ struct Segment; class StreamSegment { public: + explicit StreamSegment(Stream *stream); + virtual ~StreamSegment(); + char* copy (void *target, int length); void advance (int size); void advance(); void setStream (Stream *stream); - StreamSegment(Stream *stream); - virtual ~StreamSegment(); +private: + friend class Stream; // for "available" and "remaining" int available; int remaining; char *data; diff --git a/src/jrd/IntlManager.cpp b/src/jrd/IntlManager.cpp index 0c1df61d8e..5dbfaabf99 100644 --- a/src/jrd/IntlManager.cpp +++ b/src/jrd/IntlManager.cpp @@ -417,7 +417,7 @@ bool IntlManager::initialize() if (s.hasData()) 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") { diff --git a/src/vulcan/JString.cpp b/src/vulcan/JString.cpp index 833192735c..e4aadf6015 100644 --- a/src/vulcan/JString.cpp +++ b/src/vulcan/JString.cpp @@ -45,7 +45,7 @@ static char THIS_FILE[]=__FILE__; #endif - + JString::JString () { /************************************** @@ -61,7 +61,7 @@ JString::JString () string = NULL; } - + JString::JString (const char *stuff) { /************************************** @@ -79,6 +79,12 @@ JString::JString (const char *stuff) setString (stuff); } +JString::JString(const char * source, int len) +{ + string = NULL; + setString (source, len); +} + JString::JString (const JString& source) { /************************************** @@ -145,7 +151,7 @@ void JString::append (const char* stuff) if (--((int*) temp)[0] == 0) delete [] temp; } - + void JString::setString (const char* stuff) { /************************************** @@ -457,7 +463,8 @@ JString& JString::operator =(const WCHAR * wString) void JString::setString(const char * source, int len) { - char *old = string; + fb_assert(len >= 0); + char* const old = string; allocSpace (len); memcpy (string, source, len); string[len] = 0; @@ -483,7 +490,7 @@ int JString::findSubstring(const char * string, const char * sub) JString JString::upcase(const char * source) { JString string; - int len = (int) strlen (source); + const int len = (int) strlen (source); string.alloc (len); for (int n = 0; n < len; ++n) @@ -512,8 +519,10 @@ bool JString::equalsNoCase(const char * string2) const const char *p; for (p = string; *p && *string2; ++p, ++string2) + { if (UPPER (*p) != UPPER (*string2)) return false; + } return *p == *string2; } @@ -523,20 +532,13 @@ int JString::length() const if (!string) return 0; - const char *p; - - for (p = string; *p; ++p) - ; + const char* p = string; + while (*p) + ++p; return (int) (p - string); } -JString::JString(const char * source, int len) -{ - string = NULL; - setString (source, len); -} - char* JString::getBuffer(int len) { alloc (len); diff --git a/src/vulcan/JString.h b/src/vulcan/JString.h index 73e3ea6510..8cac6898cb 100644 --- a/src/vulcan/JString.h +++ b/src/vulcan/JString.h @@ -34,10 +34,10 @@ START_NAMESPACE class JString { public: - JString (const char *source, int length); JString(); - JString (const char *string); - JString(const JString& stringSrc); + JString (const char *stuff); + JString (const char *source, int length); + JString(const JString& source); ~JString(); //JString& operator = (const WCHAR *wString); @@ -59,7 +59,7 @@ public: void setString (const char*); void setString (const char *source, int length); void Format (const char*, ...); - + inline const char *getString() const { return (string) ? string : ""; diff --git a/src/vulcan/PathName.cpp b/src/vulcan/PathName.cpp index e2bd316964..cd042ec145 100644 --- a/src/vulcan/PathName.cpp +++ b/src/vulcan/PathName.cpp @@ -53,15 +53,15 @@ #define IS_LETTER(c) ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) //#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]; @@ -85,11 +85,11 @@ const char* PathName::getWorkingDirectory(void) int PathName::findWorkingDirectory(int dpbLength, const UCHAR* dpb, int bufferLength, char* buffer) { const UCHAR *p = dpb, *end = dpb + dpbLength; - int length; - + if (dpbLength <= 0 || *p++ != isc_dpb_version1) return 0; + int length = 0; for (; p < end; p += length) { const UCHAR verb = *p++; @@ -98,7 +98,7 @@ int PathName::findWorkingDirectory(int dpbLength, const UCHAR* dpb, int bufferLe if (verb == isc_dpb_working_directory) { - int l = MIN (bufferLength - 1, length); + const int l = MIN (bufferLength - 1, length); memcpy (buffer, p, l); buffer [l] = 0; return length; @@ -128,8 +128,10 @@ JString PathName::expandFilename(const char* fileName, const char* workingDirect #ifdef _WIN32 for (char *p = buffer; *p; ++p) + { if (*p == '/') *p = SEPARATOR; + } #endif return JString (buffer, length); @@ -249,8 +251,10 @@ JString PathName::expandFilename(const char* fileName) bool PathName::hasDirectory(const char* fileName) { for (const char *p = fileName; *p; ++p) + { if (IS_SEPARATOR (*p)) return true; + } return false; } diff --git a/src/vulcan/PathName.h b/src/vulcan/PathName.h index 86089c8285..db5cce1e4d 100644 --- a/src/vulcan/PathName.h +++ b/src/vulcan/PathName.h @@ -36,9 +36,10 @@ class PathName { public: - PathName(void); - virtual ~PathName(void); - static const char* getWorkingDirectory(void); + PathName(); + virtual ~PathName(); + + static const char* getWorkingDirectory(); 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, const char* workingDirectory); diff --git a/src/vulcan/RefObject.h b/src/vulcan/RefObject.h index bb02d67c89..c37a8b3d4f 100644 --- a/src/vulcan/RefObject.h +++ b/src/vulcan/RefObject.h @@ -38,10 +38,10 @@ class RefObject { public: - virtual void release(); - virtual void addRef(); RefObject(); virtual ~RefObject(); + virtual void addRef(); + virtual void release(); private: int useCount; };