From eac37c6a45837f7ea717c9fed8cb21e2d5665618 Mon Sep 17 00:00:00 2001 From: Aleksey Veresov Date: Fri, 31 Jan 2020 17:36:15 +0300 Subject: [xift] Working. --- src/attribute.cpp | 46 ++++++++++++++++++++++------------------------ src/attribute.hpp | 47 ++++++++++++++++++++++------------------------- src/attribute.o | Bin 4456 -> 0 bytes src/exporter.o | Bin 2488 -> 0 bytes src/file.o | Bin 2992 -> 0 bytes src/str.o | Bin 3328 -> 0 bytes src/tag.cpp | 22 +++++++++++----------- src/tag.hpp | 41 +++++++++++++++++++---------------------- src/tag.o | Bin 6832 -> 0 bytes src/utils.o | Bin 1856 -> 0 bytes src/xift.cpp | 48 ++++++++++++++++++++++++------------------------ src/xift.hpp | 2 +- 12 files changed, 99 insertions(+), 107 deletions(-) delete mode 100644 src/attribute.o delete mode 100644 src/exporter.o delete mode 100644 src/file.o delete mode 100644 src/str.o delete mode 100644 src/tag.o delete mode 100644 src/utils.o (limited to 'src') diff --git a/src/attribute.cpp b/src/attribute.cpp index 4458713..d6f928a 100644 --- a/src/attribute.cpp +++ b/src/attribute.cpp @@ -5,6 +5,23 @@ #include +XiftAttribute::XiftAttribute(): + name(0), nlen(0), nsize(0), value(0), vlen(0), vsize(0) +{} + +XiftAttribute::~XiftAttribute() +{ + if (name) free(name); + if (value) free(value); +} + + +bool XiftAttribute::MatchesForm(const XiftAttribute &form) const +{ + return !strcmp(name, form.name); +} + + XiftAttributes::XiftAttributes(): stack(0) {} @@ -18,7 +35,7 @@ XiftAttributes::~XiftAttributes() } -XiftAttributes::Attr &XiftAttributes::Attribute(const char *name) +XiftAttribute &XiftAttributes::Attribute(const char *name) { Stack *current = stack; while (current) { @@ -27,7 +44,7 @@ XiftAttributes::Attr &XiftAttributes::Attribute(const char *name) } current = current->next; } - Attr &res = New(); + XiftAttribute &res = New(); res.nlen = strlen(name); res.name = xift_str_create_copy(name, name + res.nlen); res.nsize = res.nlen + 1; @@ -49,24 +66,7 @@ void XiftAttributes::Remove(const char *name) } -XiftAttributes::Attr::Attr(): - name(0), nlen(0), nsize(0), value(0), vlen(0), vsize(0) -{} - -XiftAttributes::Attr::~Attr() -{ - if (name) free(name); - if (value) free(value); -} - - -bool XiftAttributes::Attr::MatchesForm(const XiftAttributes::Attr &form) const -{ - return !strcmp(name, form.name); -} - - -XiftAttributes::Attr *XiftAttributes::Top() +XiftAttribute *XiftAttributes::Top() { if (stack) { return &stack->item; @@ -84,7 +84,7 @@ void XiftAttributes::Pop() } } -XiftAttributes::Attr &XiftAttributes::New() +XiftAttribute &XiftAttributes::New() { Stack *old = stack; stack = new Stack; @@ -92,9 +92,7 @@ XiftAttributes::Attr &XiftAttributes::New() return stack->item; } -bool XiftAttributes::ContainsMatchedForm( - const XiftAttributes::Attr &attribute -) const +bool XiftAttributes::ContainsMatchedForm(const XiftAttribute &attribute) const { Stack *current = stack; while (current) { diff --git a/src/attribute.hpp b/src/attribute.hpp index d54d5a3..d3323a4 100644 --- a/src/attribute.hpp +++ b/src/attribute.hpp @@ -2,44 +2,41 @@ #define XIFT_INCLUDED_ATTRIBUTE -class XiftAttributes { -public: - class Attr { - friend class XiftAttributes; - - Attr(); - ~Attr(); +struct XiftAttribute { + XiftAttribute(); + ~XiftAttribute(); - bool MatchesForm(const Attr &form) const; + bool MatchesForm(const XiftAttribute &form) const; - char *name; - int nlen; - int nsize; - char *value; - int vlen; - int vsize; + char *name; + int nlen; + int nsize; + char *value; + int vlen; + int vsize; - char value_quota; - }; + char value_quota; +}; +class XiftAttributes { +public: XiftAttributes(); ~XiftAttributes(); - Attr &Attribute(const char *name); - void Remove(const char *name); + XiftAttribute &Attribute(const char *name); + void Remove(const char *name); -protected: - Attr *Top(); - void Pop(); - Attr &New(); + XiftAttribute *Top(); + void Pop(); + XiftAttribute &New(); - bool ContainsMatchedForm(const Attr &attribute) const; + bool ContainsMatchedForm(const XiftAttribute &attribute) const; bool MatchesForm(const XiftAttributes &form) const; private: struct Stack { - Stack *next; - Attr item; + Stack *next; + XiftAttribute item; } *stack; }; diff --git a/src/attribute.o b/src/attribute.o deleted file mode 100644 index 88d99c2..0000000 Binary files a/src/attribute.o and /dev/null differ diff --git a/src/exporter.o b/src/exporter.o deleted file mode 100644 index 18565b9..0000000 Binary files a/src/exporter.o and /dev/null differ diff --git a/src/file.o b/src/file.o deleted file mode 100644 index 857e72e..0000000 Binary files a/src/file.o and /dev/null differ diff --git a/src/str.o b/src/str.o deleted file mode 100644 index 0ebee34..0000000 Binary files a/src/str.o and /dev/null differ diff --git a/src/tag.cpp b/src/tag.cpp index 2f4bbcb..308a7d2 100644 --- a/src/tag.cpp +++ b/src/tag.cpp @@ -5,16 +5,16 @@ #include -XiftTags::Item::Item(): name(0), len(0), size(0) +XiftTag::XiftTag(): name(0), len(0), size(0) {} -XiftTags::Item::~Item() +XiftTag::~XiftTag() { if (name) free(name); } -bool XiftTags::Item::MatchesForm(const XiftTags::Item &form) const +bool XiftTag::MatchesForm(const XiftTag &form) const { return !strcmp(name, form.name) && XiftAttributes::MatchesForm(form); } @@ -34,7 +34,7 @@ XiftTags::~XiftTags() } -XiftTags::Item &XiftTags::Tag(const char *name) +XiftTag &XiftTags::Tag(const char *name) { Stack *current = stack; while (current) { @@ -43,7 +43,7 @@ XiftTags::Item &XiftTags::Tag(const char *name) } current = current->next; } - Item &res = New(); + XiftTag &res = New(); res.len = strlen(name); res.name = xift_str_create_copy(name, name + res.len); res.size = res.len + 1; @@ -66,7 +66,7 @@ void XiftTags::Remove(const char *name) } -XiftTags::Item *XiftTags::Top() +XiftTag *XiftTags::Top() { if (stack) { return stack->item; @@ -85,9 +85,9 @@ void XiftTags::Pop() } } -XiftTags::Item *XiftTags::PopToBeDeleted() +XiftTag *XiftTags::PopToBeDeleted() { - XiftTags::Item *res = 0; + XiftTag *res = 0; if (stack) { Stack *old = stack; res = stack->item; @@ -97,17 +97,17 @@ XiftTags::Item *XiftTags::PopToBeDeleted() return res; } -XiftTags::Item &XiftTags::New() +XiftTag &XiftTags::New() { Stack *old = stack; stack = new Stack; - stack->item = new XiftTags::Item; + stack->item = new XiftTag; stack->next = old; return *stack->item; } -bool XiftTags::ContainsMatchedForm(const XiftTags::Item & tag) const +bool XiftTags::ContainsMatchedForm(const XiftTag & tag) const { Stack *current = stack; while (current) { diff --git a/src/tag.hpp b/src/tag.hpp index 469c4fd..75e5f59 100644 --- a/src/tag.hpp +++ b/src/tag.hpp @@ -4,39 +4,36 @@ #include "attribute.hpp" -class XiftTags { -public: - class Item: public XiftAttributes { - friend class XiftTags; - - Item(); - ~Item(); +struct XiftTag: public XiftAttributes { + XiftTag(); + ~XiftTag(); - bool MatchesForm(const Item & form) const; + bool MatchesForm(const XiftTag & form) const; - char *name; - int len; - int size; - }; + char *name; + int len; + int size; +}; +class XiftTags { +public: XiftTags(); ~XiftTags(); - Item &Tag(const char *name); - void Remove(const char *name); + XiftTag &Tag(const char *name); + void Remove(const char *name); -protected: - Item *Top(); - void Pop(); - Item *PopToBeDeleted(); - Item &New(); + XiftTag *Top(); + void Pop(); + XiftTag *PopToBeDeleted(); + XiftTag &New(); - bool ContainsMatchedForm(const Item &tag) const; + bool ContainsMatchedForm(const XiftTag &tag) const; private: struct Stack { - Stack *next; - Item *item; + Stack *next; + XiftTag *item; } *stack; }; diff --git a/src/tag.o b/src/tag.o deleted file mode 100644 index 00a8cac..0000000 Binary files a/src/tag.o and /dev/null differ diff --git a/src/utils.o b/src/utils.o deleted file mode 100644 index 7531793..0000000 Binary files a/src/utils.o and /dev/null differ diff --git a/src/xift.cpp b/src/xift.cpp index 8b703cb..2ee127b 100644 --- a/src/xift.cpp +++ b/src/xift.cpp @@ -4,15 +4,15 @@ #include -const char *XiftErrorMessage(XiftError error) +const char *xift_error_message(XiftError error) { switch (error) { - case xift_ok: return ""; case xift_wrong_char: return "Wrong character in tag."; case xift_attr_sep: return "Attribute separator missed."; case xift_something_after_close: return "Met something after tag close."; case xift_close_selfclose: return "Tag is closing and self-closing."; case xift_unwanted_close: return "Closing not opened tag."; + default: return ""; } } @@ -101,7 +101,7 @@ void Xift::ReadText(char c) void Xift::OpenTag(char c) { - Item &t = opened.New(); + XiftTag &t = opened.New(); if (c == '/') { is_closing = true; state = reading_name; @@ -117,7 +117,7 @@ void Xift::OpenTag(char c) void Xift::ReadName(char c) { if (AllowedInToken(c)) { - Item &t = *opened.Top(); + XiftTag &t = *opened.Top(); xift_str_add(t.name, t.len, t.size, c); } else if (IsWhitespace(c)) { state = waiting_attr; @@ -133,7 +133,7 @@ void Xift::ReadName(char c) void Xift::WaitAttr(char c) { if (AllowedInTokenStart(c)) { - Item::Attr &a = opened.Top()->New(); + XiftAttribute &a = opened.Top()->New(); xift_str_add(a.name, a.nlen, a.nsize, c); state = reading_attr_name; } else if (c == '/') { @@ -151,13 +151,13 @@ void Xift::WaitAttr(char c) void Xift::ReadAttrName(char c) { if (AllowedInToken(c)) { - Item::Attr &a = *opened.Top()->Top(); + XiftAttribute &a = *opened.Top()->Top(); xift_str_add(a.name, a.nlen, a.nsize, c); } else if (c == '=') { state = waiting_attr_value; } else if (c == '>') { - Item::Attr &a = *opened.Top()->Top(); - a.value = xift_str_create_copy(a.name, a.name + a.len); + XiftAttribute &a = *opened.Top()->Top(); + a.value = xift_str_create_copy(a.name, a.name + a.nlen); a.vlen = a.nlen; a.vsize = a.vlen + 1; a.value_quota = '\''; @@ -176,20 +176,20 @@ void Xift::WaitAttrSep(char c) if (c == '=') { state = waiting_attr_value; } else if (c == '>') { - Item::Attr &a = *opened.Top()->Top(); - a.value = xift_str_create_copy(a.name, a.name + a.len); + XiftAttribute &a = *opened.Top()->Top(); + a.value = xift_str_create_copy(a.name, a.name + a.nlen); a.vlen = a.nlen; a.vsize = a.vlen + 1; a.value_quota = '\''; CompleteCurrent(); state = reading_text; } else if (AllowedInTokenStart(c)) { - Item::Attr &a = *opened.Top()->Top(); - a.value = xift_str_create_copy(a.name, a.name + a.len); + XiftAttribute &a = *opened.Top()->Top(); + a.value = xift_str_create_copy(a.name, a.name + a.nlen); a.vlen = a.nlen; a.vsize = a.vlen + 1; a.value_quota = '\''; - Item::Attr &n = opened.Top()->New(); + XiftAttribute &n = opened.Top()->New(); xift_str_add(n.name, n.nlen, n.nsize, c); state = reading_attr_name; } else if (!IsWhitespace(c)) { @@ -205,7 +205,7 @@ void Xift::WaitAttrValue(char c) value_quota = c; state = reading_attr_value; } else if (AllowedInTokenStart(c)) { - Item::Attr &a = *opened.Top()->Top(); + XiftAttribute &a = *opened.Top()->Top(); a.value_quota = '\''; xift_str_add(a.value, a.vlen, a.vsize, c); value_quota = 0; @@ -222,7 +222,7 @@ void Xift::ReadAttrValue(char c) if (c == value_quota) { state = waiting_attr; } else { - Item::Attr &a = *opened.Top()->Top(); + XiftAttribute &a = *opened.Top()->Top(); xift_str_add(a.value, a.vlen, a.vsize, c); } } else { @@ -231,7 +231,7 @@ void Xift::ReadAttrValue(char c) state = reading_text; } if (AllowedInToken(c)) { - Item::Attr &a = *opened.Top()->Top(); + XiftAttribute &a = *opened.Top()->Top(); xift_str_add(a.value, a.vlen, a.vsize, c); } else if (IsWhitespace(c)) { state = waiting_attr; @@ -249,7 +249,7 @@ void Xift::CloseTag(char c) state = reading_text; } else if (!IsWhitespace(c)) { state = state_error; - error = something_after_close; + error = xift_something_after_close; } } @@ -297,7 +297,7 @@ void Xift::CloseTop() opened.Pop(); } -void Xift::CloseName(const ScriptVariable &name) +void Xift::CloseName(const char *name) { exporter.Put("name); exporter.Put('='); @@ -325,11 +325,11 @@ void Xift::SelfcloseCurrent() void Xift::PutCurrent() { - Item &t = *opened.Top(); + XiftTag &t = *opened.Top(); exporter.Put('<'); exporter.Put(t.name); - Item::Attr *a; - while (a = t.Top()) { + XiftAttribute *a; + for (a = t.Top(); a; a = t.Top()) { exporter.Put(' '); exporter.Put(a->name); exporter.Put('='); diff --git a/src/xift.hpp b/src/xift.hpp index a37f1c2..674f737 100644 --- a/src/xift.hpp +++ b/src/xift.hpp @@ -15,7 +15,7 @@ enum XiftError { xift_unwanted_close }; -const char *XiftErrorMessage(XiftError error); +const char *xift_error_message(XiftError error); class Xift: public XiftTags { -- cgit v1.2.3