mirror of
https://github.com/FirebirdSQL/firebird.git
synced 2025-01-24 02:03:03 +01:00
More encapsulation, bring some order, fix some B.O. cases, etc.
This commit is contained in:
parent
0ba8a36d7d
commit
7333e03c17
@ -302,7 +302,7 @@ const char* ConfObject::getConcatenatedValues(const char* attributeName)
|
||||
if (!attribute)
|
||||
return value;
|
||||
|
||||
for (const Element *att = attribute->attributes; att; att = att->sibling)
|
||||
for (const Element *att = attribute->getAttributes(); att; att = att->sibling)
|
||||
{
|
||||
if (!value.IsEmpty())
|
||||
value += " ";
|
||||
|
@ -276,7 +276,7 @@ JString ConfigFile::expand(JString rawString)
|
||||
return temp;
|
||||
}
|
||||
|
||||
const char* ConfigFile::translate(const char *value, Element *object)
|
||||
const char* ConfigFile::translate(const char* value, const Element* object)
|
||||
{
|
||||
if (strcasecmp (value, "root") == 0)
|
||||
return getRootDirectory();
|
||||
@ -302,8 +302,10 @@ const char* ConfigFile::translate(const char *value, Element *object)
|
||||
const char *p = NULL;
|
||||
|
||||
for (const char *q = fileName; *q; ++q)
|
||||
{
|
||||
if (IS_SEPARATOR(*q))
|
||||
p = q;
|
||||
}
|
||||
|
||||
if (p)
|
||||
currentDirectory = JString(fileName, p - fileName);
|
||||
|
@ -63,12 +63,12 @@ public:
|
||||
const char* getInstallDirectory();
|
||||
virtual JString expand(JString rawString);
|
||||
|
||||
const char* translate(const char *value, Element *object);
|
||||
void init(int configFlags);
|
||||
const char* translate(const char* value, const Element* object);
|
||||
void wildCardInclude(const char* fileName);
|
||||
const Element* getObjects() const { return objects; }
|
||||
|
||||
private:
|
||||
void init(int configFlags);
|
||||
Element* objects;
|
||||
JString rootDirectory;
|
||||
JString installDirectory;
|
||||
|
@ -120,26 +120,53 @@ void Element::addChild(Element *child)
|
||||
{
|
||||
child->parent = this;
|
||||
child->sibling = NULL;
|
||||
Element **ptr;
|
||||
|
||||
for (ptr = &children; *ptr; ptr = &(*ptr)->sibling)
|
||||
;
|
||||
Element** ptr = &children;
|
||||
while (*ptr)
|
||||
ptr = &(*ptr)->sibling;
|
||||
|
||||
*ptr = child;
|
||||
}
|
||||
|
||||
Element* Element::addChild(JString childName)
|
||||
{
|
||||
Element *element = new Element (childName);
|
||||
addChild (element);
|
||||
|
||||
return element;
|
||||
}
|
||||
|
||||
void Element::addAttribute(Element *child)
|
||||
{
|
||||
child->parent = this;
|
||||
child->sibling = NULL;
|
||||
Element **ptr;
|
||||
|
||||
for (ptr = &attributes; *ptr; ptr = &(*ptr)->sibling)
|
||||
;
|
||||
Element** ptr = &attributes;
|
||||
while (*ptr)
|
||||
ptr = &(*ptr)->sibling;
|
||||
|
||||
*ptr = child;
|
||||
}
|
||||
|
||||
void Element::addAttribute(JString attributeName)
|
||||
{
|
||||
addAttribute (new Element (attributeName));
|
||||
}
|
||||
|
||||
Element* Element::addAttribute(JString attributeName, JString attributeValue)
|
||||
{
|
||||
Element *attribute = new Element (attributeName, attributeValue);
|
||||
addAttribute (attribute);
|
||||
|
||||
return attribute;
|
||||
}
|
||||
|
||||
Element* Element::addAttribute(JString attributeName, int attributeValue)
|
||||
{
|
||||
char buffer [32];
|
||||
sprintf (buffer, "%d", attributeValue);
|
||||
|
||||
return addAttribute (attributeName, buffer);
|
||||
}
|
||||
|
||||
void Element::print(int level) const
|
||||
{
|
||||
printf ("%*s%s", level * 3, "", (const char*) name);
|
||||
@ -203,8 +230,10 @@ Element* Element::findAttribute(int seq)
|
||||
int n = 0;
|
||||
|
||||
for (Element *attribute = attributes; attribute; attribute = attribute->sibling)
|
||||
{
|
||||
if (n++ == seq)
|
||||
return attribute;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@ -284,22 +313,6 @@ void Element::indent(int level, Stream *stream) const
|
||||
stream->putCharacter (' ');
|
||||
}
|
||||
|
||||
Element* Element::addAttribute(JString attributeName, JString attributeValue)
|
||||
{
|
||||
Element *attribute = new Element (attributeName, attributeValue);
|
||||
addAttribute (attribute);
|
||||
|
||||
return attribute;
|
||||
}
|
||||
|
||||
Element* Element::addChild(JString childName)
|
||||
{
|
||||
Element *element = new Element (childName);
|
||||
addChild (element);
|
||||
|
||||
return element;
|
||||
}
|
||||
|
||||
Element* Element::findChildIgnoreCase(const char *childName)
|
||||
{
|
||||
for (Element *child = children; child; child = child->sibling)
|
||||
@ -380,19 +393,6 @@ void Element::gen(int level, Stream *stream) const
|
||||
stream->putSegment (">\n");
|
||||
}
|
||||
|
||||
void Element::addAttribute(JString attributeName)
|
||||
{
|
||||
addAttribute (new Element (attributeName));
|
||||
}
|
||||
|
||||
Element* Element::addAttribute(JString attributeName, int attributeValue)
|
||||
{
|
||||
char buffer [32];
|
||||
sprintf (buffer, "%d", attributeValue);
|
||||
|
||||
return addAttribute (attributeName, buffer);
|
||||
}
|
||||
|
||||
Element* Element::findChild(const char *childName, const char *attribute, const char *attributeValue)
|
||||
{
|
||||
for (Element *child = children; child; child = child->sibling)
|
||||
|
@ -45,18 +45,25 @@ class InputStream;
|
||||
class Element
|
||||
{
|
||||
public:
|
||||
Element* findChild (const char *name, const char *attribute, const char *value);
|
||||
Element* addAttribute (JString name, int value);
|
||||
explicit Element(JString elementName);
|
||||
Element (JString elementName, JString elementValue);
|
||||
virtual ~Element();
|
||||
|
||||
void addChild (Element *child);
|
||||
Element* addChild (JString name);
|
||||
|
||||
void addAttribute (Element *child);
|
||||
void addAttribute (JString name);
|
||||
Element* addAttribute (JString name, JString value);
|
||||
Element* addAttribute (JString name, int value);
|
||||
|
||||
Element* findChild (const char *name, const char *attribute, const char *value);
|
||||
void gen (int level, Stream *stream) const;
|
||||
void setSource (int line, InputStream *stream);
|
||||
void init(JString elementName);
|
||||
const char* getAttributeValue (const char *name, const char *defaultValue);
|
||||
const char* getAttributeValue (const char *name);
|
||||
const char* getAttributeName (int position) const;
|
||||
Element* findChildIgnoreCase (const char *name);
|
||||
Element* addChild (JString name);
|
||||
Element* addAttribute (JString name, JString value);
|
||||
void indent (int level, Stream *stream) const;
|
||||
void genXML (int level, Stream *stream) const;
|
||||
Element* findAttribute (const char *name);
|
||||
@ -66,26 +73,26 @@ public:
|
||||
Element* findChild (const char *name);
|
||||
const Element* findChild (const char *name) const;
|
||||
void print (int level) const;
|
||||
void addAttribute (Element *child);
|
||||
void addChild (Element *child);
|
||||
Element (JString elementName, JString elementValue);
|
||||
explicit Element(JString elementName);
|
||||
virtual ~Element();
|
||||
const Element* getAttributes() const { return attributes; }
|
||||
|
||||
JString name;
|
||||
JString value;
|
||||
JString innerText;
|
||||
JString outerText;
|
||||
|
||||
Element *sibling;
|
||||
Element *parent;
|
||||
Element *children;
|
||||
Element *attributes;
|
||||
|
||||
int lineNumber;
|
||||
int numberLines;
|
||||
InputStream *inputStream;
|
||||
static int analyseText(const char* text);
|
||||
void putQuotedText(const char* text, Stream* stream) const;
|
||||
static int analyzeData(int length, const UCHAR* data);
|
||||
private:
|
||||
void init(JString elementName);
|
||||
JString innerText;
|
||||
//JString outerText;
|
||||
Element *parent; // assigned but never used.
|
||||
Element *attributes;
|
||||
};
|
||||
|
||||
END_NAMESPACE
|
||||
|
@ -103,7 +103,7 @@ const char* InputFile::getSegment()
|
||||
return buffer;
|
||||
}
|
||||
|
||||
const char* InputFile::getFileName()
|
||||
const char* InputFile::getFileName() const
|
||||
{
|
||||
return fileName;
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ public:
|
||||
void rewrite();
|
||||
void postChange (int lineNumber, int skip, JString insertion);
|
||||
virtual InputFile* getInputFile();
|
||||
virtual const char* getFileName();
|
||||
virtual const char* getFileName() const;
|
||||
virtual const char* getSegment();
|
||||
virtual void close();
|
||||
|
||||
|
@ -102,7 +102,7 @@ void InputStream::release()
|
||||
delete this;
|
||||
}
|
||||
|
||||
const char* InputStream::getFileName()
|
||||
const char* InputStream::getFileName() const
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ public:
|
||||
virtual ~InputStream();
|
||||
|
||||
virtual InputFile* getInputFile();
|
||||
virtual const char* getFileName();
|
||||
virtual const char* getFileName() const;
|
||||
void init();
|
||||
void release();
|
||||
virtual void addRef();
|
||||
|
@ -110,7 +110,7 @@ void Lex::skipWhite()
|
||||
ptr += 2;
|
||||
++inputStream->lineNumber;
|
||||
}
|
||||
else if (charTable (*ptr) & WHITE)
|
||||
else if (charTable(*ptr) & WHITE)
|
||||
{
|
||||
if (*ptr++ == '\n')
|
||||
{
|
||||
@ -157,55 +157,67 @@ void Lex::getToken()
|
||||
|
||||
tokenOffset = inputStream->getOffset (ptr);
|
||||
char *p = token;
|
||||
char *endToken = token + sizeof (token);
|
||||
char c = *p++ = *ptr++;
|
||||
const char* const endToken = token + sizeof(token) - 1; // take into account the '\0'
|
||||
const char c = *p++ = *ptr++;
|
||||
|
||||
if (charTable (c) & PUNCT)
|
||||
if (charTable(c) & PUNCT)
|
||||
tokenType = PUNCT;
|
||||
else if (c == '\'' || c == '"')
|
||||
{
|
||||
{
|
||||
p = token;
|
||||
for (;;)
|
||||
{
|
||||
{
|
||||
if (ptr >= end)
|
||||
{
|
||||
{
|
||||
if (!getSegment())
|
||||
throw AdminException ("end of file in quoted string");
|
||||
}
|
||||
}
|
||||
else if (*ptr == c)
|
||||
break;
|
||||
else
|
||||
{
|
||||
{
|
||||
if (p >= endToken)
|
||||
throw AdminException ("token overflow in quoted string");
|
||||
*p++ = *ptr++;
|
||||
}
|
||||
}
|
||||
}
|
||||
++ptr;
|
||||
tokenType = (c == '"') ? QUOTED_STRING : SINGLE_QUOTED_STRING;
|
||||
}
|
||||
else if (charTable (c) & DIGIT)
|
||||
{
|
||||
}
|
||||
else if (charTable(c) & DIGIT)
|
||||
{
|
||||
tokenType = NUMBER;
|
||||
while (ptr < end && (charTable (*ptr) & DIGIT))
|
||||
while (ptr < end && (charTable(*ptr) & DIGIT))
|
||||
{
|
||||
if (p >= endToken)
|
||||
throw AdminException ("token overflow in number");
|
||||
*p++ = *ptr++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
{
|
||||
tokenType = NAME;
|
||||
if (flags & LEX_upcase)
|
||||
{
|
||||
{
|
||||
p [-1] = UPCASE(c);
|
||||
while (ptr < end && !(charTable (*ptr) & (WHITE | PUNCT)))
|
||||
{
|
||||
c = *ptr++;
|
||||
*p++ = UPCASE(c);
|
||||
}
|
||||
while (ptr < end && !(charTable(*ptr) & (WHITE | PUNCT)))
|
||||
{
|
||||
if (p >= endToken)
|
||||
throw AdminException ("token overflow in name (uppercase)");
|
||||
const char c2 = *ptr++;
|
||||
*p++ = UPCASE(c2);
|
||||
}
|
||||
else
|
||||
while (ptr < end && !(charTable (*ptr) & (WHITE | PUNCT)))
|
||||
*p++ = *ptr++;
|
||||
}
|
||||
else
|
||||
{
|
||||
while (ptr < end && !(charTable(*ptr) & (WHITE | PUNCT)))
|
||||
{
|
||||
if (p >= endToken)
|
||||
throw AdminException ("token overflow in name");
|
||||
*p++ = *ptr++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*p = 0;
|
||||
}
|
||||
@ -213,7 +225,7 @@ void Lex::getToken()
|
||||
void Lex::setCharacters(int type, const char *characters)
|
||||
{
|
||||
for (const char *p = characters; *p; ++p)
|
||||
charTable (*p) |= type;
|
||||
charTable(*p) |= type;
|
||||
}
|
||||
|
||||
/***
|
||||
@ -260,7 +272,7 @@ JString Lex::reparseFilename()
|
||||
while (*p)
|
||||
++p;
|
||||
|
||||
while (ptr < end && *ptr != '>' && !(charTable (*ptr) & WHITE))
|
||||
while (ptr < end && *ptr != '>' && !(charTable(*ptr) & WHITE))
|
||||
*p++ = *ptr++;
|
||||
|
||||
*p = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user