Commit 5028d12
Remove xml parser
Changed files (10)
modifiedREADME.mdmodifiedconfiguremodifieddodo.pydeletedlibbirdxml/Attribute.valadeletedlibbirdxml/Attributes.valadeletedlibbirdxml/Tag.valadeletedlibbirdxml/Xml.valadeletedlibbirdxml/XmlData.valadeletedlibbirdxml/XmlString.valamodifiedscripts/build.py
Diff
@@ -17,6 +17,7 @@ packages with a -dev or -devel affix: valac font-roboto+ libxmlbird libgee-dev libglib2.0-dev libgtk-3-dev @@ -72,7 +72,8 @@ def configure (gtk, libbgee, posixvala): 'webkitgtk-3.0', 'libsoup-2.4', 'libnotify',- 'sqlite3'+ 'sqlite3',+ 'xmlbird' ] else: libs = [@@ -80,7 +81,8 @@ def configure (gtk, libbgee, posixvala): 'gio-2.0', 'glib-2.0', 'sqlite3',- 'fontconfig'+ 'fontconfig',+ 'xmlbird' ] for lib in libs:@@ -32,7 +32,6 @@ DOIT_CONFIG = { 'default_tasks': [ 'build', 'libbirdgems', - 'libbirdxml', 'libbirdfont', 'birdfont', 'birdfont_autotrace',@@ -53,18 +52,8 @@ LIBS = [ 'gdk-pixbuf-2.0', 'webkitgtk-3.0', config.GEE,- 'libnotify'- ]--if not config.POSIXVALA:- LIBBIRD_XML_LIBS = [- 'glib-2.0',- 'posix'- ]-else:- LIBBIRD_XML_LIBS = [- 'posix',- 'posixtypes'+ 'libnotify',+ 'xmlbird' ] LIBBIRD_LIBS = [@@ -105,24 +94,6 @@ valac_options = [ if "bsd" in sys.platform:- LIBBIRDXML_SO_VERSION='${LIBbirdxml_VERSION}'-else:- LIBBIRDXML_SO_VERSION=version.LIBBIRDXML_SO_VERSION--libbirdxml = Vala(src='libbirdxml', build='build', library='birdxml', so_version=LIBBIRDXML_SO_VERSION, pkg_libs=LIBBIRD_XML_LIBS)-def task_libbirdxml():-- if config.POSIXVALA == True:- yield libbirdxml.gen_c(valac_options + ['--profile posix'])- else:- yield libbirdxml.gen_c(valac_options)-- yield libbirdxml.gen_o(['-fPIC'])- yield libbirdxml.gen_so()- yield libbirdxml.gen_ln()- --if "bsd" in sys.platform: LIBBIRDGEMS_SO_VERSION='${LIBbirdgems_VERSION}' else: LIBBIRDGEMS_SO_VERSION=version.LIBBIRDGEMS_SO_VERSION@@ -139,7 +110,7 @@ if "bsd" in sys.platform: else: SO_VERSION=version.SO_VERSION -libbird = Vala(src='libbirdfont', build='build', library='birdfont', so_version=SO_VERSION, pkg_libs=LIBS, vala_deps=[libbirdgems, libbirdxml])+libbird = Vala(src='libbirdfont', build='build', library='birdfont', so_version=SO_VERSION, pkg_libs=LIBS, vala_deps=[libbirdgems]) def task_libbirdfont(): yield libbird.gen_c(valac_options) yield libbird.gen_o(['-fPIC -I./build/', """-D 'GETTEXT_PACKAGE="birdfont"'"""])@@ -148,25 +119,25 @@ def task_libbirdfont(): def task_birdfont():- bird = Vala(src='birdfont', build='build', pkg_libs=LIBS, vala_deps=[libbird, libbirdxml, libbirdgems])+ bird = Vala(src='birdfont', build='build', pkg_libs=LIBS, vala_deps=[libbird, libbirdgems]) yield bird.gen_c(valac_options) yield bird.gen_bin(["""-D 'GETTEXT_PACKAGE="birdfont"' """]) def task_birdfont_autotrace():- exp = Vala(src='birdfont-autotrace', build='build', pkg_libs=LIBS, vala_deps=[libbird, libbirdxml, libbirdgems])+ exp = Vala(src='birdfont-autotrace', build='build', pkg_libs=LIBS, vala_deps=[libbird, libbirdgems]) yield exp.gen_c(valac_options) yield exp.gen_bin(["""-D 'GETTEXT_PACKAGE="birdfont"' """]) def task_birdfont_export():- exp = Vala(src='birdfont-export', build='build', pkg_libs=LIBS, vala_deps=[libbird, libbirdxml, libbirdgems])+ exp = Vala(src='birdfont-export', build='build', pkg_libs=LIBS, vala_deps=[libbird, libbirdgems]) yield exp.gen_c(valac_options) yield exp.gen_bin(["""-D 'GETTEXT_PACKAGE="birdfont"' """]) def task_birdfont_import():- exp = Vala(src='birdfont-import', build='build', pkg_libs=LIBS, vala_deps=[libbird, libbirdxml, libbirdgems])+ exp = Vala(src='birdfont-import', build='build', pkg_libs=LIBS, vala_deps=[libbird, libbirdgems]) yield exp.gen_c(valac_options) yield exp.gen_bin(["""-D 'GETTEXT_PACKAGE="birdfont"' """]) deleted file mode 100644@@ -1,61 +0,0 @@-/*- Copyright (C) 2014 Johan Mattsson-- This library is free software; you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as - published by the Free Software Foundation; either version 3 of the - License, or (at your option) any later version.-- This library is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details.-*/-namespace B {--/** - * Representation of one XML attribute.- */-public class Attribute : GLib.Object {- - public XmlString ns;- public XmlString name;- public XmlString content;-- public int refcount = 1;- - internal Attribute (XmlString ns, XmlString name, XmlString content) {- this.ns = ns;- this.name = name;- this.content = content;- }-- internal Attribute.empty () {- this.ns = new XmlString ("", 0);- this.name = new XmlString ("", 0);- this.content = new XmlString ("", 0);- }- - /** - * @return namespace part for this attribute.- */- public string get_namespace () {- return ns.to_string ();- }- - /**- * @return the name of this attribute. - */- public string get_name () {- return name.to_string ();- }-- /** - * @return the value of this attribute.- */- public string get_content () {- return content.to_string ();- }-}--}deleted file mode 100644@@ -1,64 +0,0 @@-/*- Copyright (C) 2014 Johan Mattsson-- This library is free software; you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as - published by the Free Software Foundation; either version 3 of the - License, or (at your option) any later version.-- This library is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details.-*/-namespace B {--/** - * Iterator for XML attributes. - */-public class Attributes : GLib.Object {- - public Tag tag;- public int refcount = 1;- - internal Attributes (Tag t) {- tag = t;- }- - public Iterator iterator () {- return new Iterator (tag);- }-- public class Iterator : GLib.Object {- public Tag tag;- public Attribute? next_attribute;- public int iterator_refcount = 1;- - internal Iterator (Tag t) {- tag = t;- next_attribute = null;- tag.reparse_attributes ();- }-- public bool next () {- if (tag.has_more_attributes ()) {- next_attribute = tag.get_next_attribute ();- } else {- next_attribute = null;- }- - return next_attribute != null;- }-- public new Attribute get () {- if (next_attribute == null) {- XmlParser.warning ("No attribute is parsed yet.");- return new Attribute.empty ();- }- - return (!) next_attribute;- }- }-}--}deleted file mode 100644@@ -1,502 +0,0 @@-/*- Copyright (C) 2014 Johan Mattsson-- This library is free software; you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as - published by the Free Software Foundation; either version 3 of the - License, or (at your option) any later version.-- This library is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details.-*/--namespace B {--/**- * Representation of one XML tag.- */-public class Tag : GLib.Object {- internal XmlData entire_file;- - public int tag_index; - public int attribute_index;- - public bool has_tags;- public bool has_attributes;- - public XmlString name;- public XmlString data;- public XmlString attributes;- - public Tag? next_tag = null;- public Attribute? next_attribute = null;- - public bool error = false;- public int log_level = WARNINGS;- - public int refcount = 1;- - internal Tag (XmlString name, XmlString attributes, XmlString content,- int log_level, XmlData entire_file) {- - this.entire_file = entire_file;- this.log_level = log_level;- this.name = name;- this.data = content;- this.attributes = attributes;- - reparse ();- reparse_attributes ();- }- - internal Tag.empty () {- entire_file = new XmlData ("", 0);- data = new XmlString ("", 0);- attributes = new XmlString ("", 0);- name = new XmlString ("", 0);- }- - /** - * Get tag attributes for this tag. - * @return a container with all the attributes- */- public Attributes get_attributes () {- return new Attributes (this);- }-- /** - * Iterate over all tags inside of this tag.- */- public Iterator iterator () {- return new Iterator(this);- }-- /** - * Reset the parser and start from the beginning XML tag.- */- public void reparse () {- tag_index = 0;- next_tag = obtain_next_tag ();- }-- internal void reparse_attributes () {- attribute_index = 0;- next_attribute = obtain_next_attribute ();- }- - /** - * Obtain the name of the tag.- * @return the name of this tag. - */ - public string get_name () {- return name.to_string ();- }-- /** - * Obtain tag content.- * @return data between the start and end tags.- */- public string get_content () {- return data.to_string ();- }-- /** - * @return true if there is one more tags left- */- internal bool has_more_tags () {- return has_tags;- }- - /** @return the next tag. **/- internal Tag get_next_tag () {- Tag r = next_tag == null ? new Tag.empty () : (!) next_tag;- next_tag = obtain_next_tag ();- return r;- }-- /** @return true is there is one or more attributes to obtain with get_next_attribute */- internal bool has_more_attributes () {- return has_attributes;- }- - /** @return next attribute. */- internal Attribute get_next_attribute () {- Attribute r = next_attribute == null ? new Attribute.empty () : (!) next_attribute;- next_attribute = obtain_next_attribute ();- return r;- }- - internal bool has_failed () {- return error;- }- - Tag obtain_next_tag () {- int end_tag_index;- Tag tag;- - tag = find_next_tag (tag_index, out end_tag_index);-- if (end_tag_index != -1) {- tag_index = end_tag_index;- has_tags = true;- return tag;- }- - has_tags = false;- return new Tag.empty ();- }- - Tag find_next_tag (int start, out int end_tag_index) {- int index;- unichar c;- int separator;- int end;- int closing_tag;- XmlString? d;-- XmlString name;- XmlString attributes;- XmlString content;-- end_tag_index = -1;- - if (start < 0) {- warn ("Negative index.");- return new Tag.empty ();- }- - index = start;-- d = data;- if (d == null) {- warn ("No data in xml string.");- return new Tag.empty ();- }- - while (data.get_next_ascii_char (ref index, out c)) {- - if (c == '<') {- separator = find_next_separator (index);-- if (separator < 0) {- error = true;- warn ("Expecting a separator.");- return new Tag.empty ();- }- - name = data.substring (index, separator - index);- - if (name.has_prefix ("!")) {- continue;- }- - end = data.index_of (">", start);- attributes = data.substring (separator, end - separator);- - if (attributes.has_suffix ("/")) {- content = new XmlString ("", 0);- end_tag_index = data.index_of (">", index);- data.get_next_ascii_char (ref end_tag_index, out c);- } else {- if (!data.get_next_ascii_char (ref end, out c)) {; // skip >- warn ("Unexpected end of data.");- error = true;- break;- }- - if (c != '>') {- warn ("Expecting '>'");- error = true;- break;- }- - closing_tag = find_closing_tag (name, end);- - if (closing_tag == -1) {- warn ("No closing tag.");- error = true;- break;- }- - content = data.substring (end, closing_tag - end);- end_tag_index = data.index_of (">", closing_tag);- data.get_next_ascii_char (ref end_tag_index, out c);- }- - return new Tag (name, attributes, content, log_level, entire_file); - }- }- - return new Tag.empty ();- }- - int find_next_separator (int start) {- int index = start;- int previous_index = start;- unichar c;- - while (true) {- - previous_index = index;- if (!data.get_next_ascii_char (ref index, out c)) {- break;- }- - if (c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == '>' || c == '/') {- return previous_index;- }- }- - return -1;- }- - int find_closing_tag (XmlString name, int start) {- int index = start;- int slash_index = start;- int previous_index;- unichar c, slash;- int start_count = 1;- int next_tag;- - if (name.length == 0) {- error = true;- warn ("No name for tag.");- return -1;- }- - index = entire_file.get_index (data) + start;- while (true) {- while (!entire_file.substring (index).has_prefix ("</")) {- index = entire_file.find_next_tag_token (index + 1);- - if (index == -1) {- warning (@"No end tag for $(name)");- return -1;- }- }-- previous_index = index - entire_file.get_index (data);- - if (!entire_file.get_next_ascii_char (ref index, out c)) {- warn ("Unexpected end of file");- break;- }- - if (c == '<') {- slash_index = index;- entire_file.get_next_ascii_char (ref slash_index, out slash);-- if (slash == '/' && is_tag (entire_file, name, slash_index)) {- if (start_count == 1) {- return previous_index;- } else {- start_count--;- if (start_count == 0) {- return previous_index;- }- }- } else if (is_tag (entire_file, name, slash_index)) {- start_count++;- }- }- }- - error = true;- warn (@"No closing tag for $(name.to_string ())");- - return -1;- }- - bool is_tag (XmlString tag, XmlString name, int start) {- int index = 0;- int data_index = start;- unichar c;- unichar c_data;- - while (name.get_next_ascii_char (ref index, out c)) {- if (tag.get_next_ascii_char (ref data_index, out c_data)) {- if (c_data != c) {- return false;- }- }- }- - if (tag.get_next_ascii_char (ref data_index, out c_data)) {- return c_data == '>' || c_data == ' ' || c_data == '\t' - || c_data == '\n' || c_data == '\r' || c_data == '/';- }- - return false;- }-- internal Attribute obtain_next_attribute () {- int previous_index;- int index = attribute_index;- int name_start;- XmlString attribute_name; - XmlString ns;- XmlString content;- int ns_separator;- int content_start;- int content_stop;- unichar quote;- unichar c;- - // skip space and other separators- while (true) {- previous_index = index;- - if (!attributes.get_next_ascii_char (ref index, out c)) {- has_attributes = false;- return new Attribute.empty ();- }- - if (!(c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == '/')) {- break;- }- }- - name_start = previous_index;-- // read attribute name- while (true) {- previous_index = index;- if (!attributes.get_next_ascii_char (ref index, out c)) {- error = true;- warn (@"Unexpected end of attributes in tag $(this.name)");- has_attributes = false;- return new Attribute.empty ();- }- - if (c == ' ' || c == '\t' || c == '=' || c == '\n' || c == '\r') {- break;- }- }- - attribute_name = attributes.substring (name_start, previous_index - name_start);- index = name_start + attribute_name.length;- ns = new XmlString ("", 0);- ns_separator = attribute_name.index_of (":");- if (ns_separator != -1) {- ns = attribute_name.substring (0, ns_separator);- attribute_name = attribute_name.substring (ns_separator + 1);- }- - // equal sign and space around it- while (attributes.get_next_ascii_char (ref index, out c)) {- if (!(c == ' ' || c == '\t' || c == '\n' || c == '\r')) {- if (c == '=') {- break;- } else {- has_attributes = false;- error = true;- warn (@"Expecting equal sign for attribute $(attribute_name).");- warn (@"Around: $(attributes.substring (index, 10)).");- warn (@"Row: $(get_row (((size_t) attributes.data) + index))");- - return new Attribute.empty ();- }- }- }- - while (attributes.get_next_ascii_char (ref index, out c)) {- if (!(c == ' ' || c == '\t' || c == '\n' || c == '\r')) {- if (c == '"' || c == '\'') {- break;- } else {- has_attributes = false;- error = true;- warn (@"Expecting quote for attribute $(attribute_name).");- return new Attribute.empty ();- }- }- }- - quote = c;- content_start = index;- - while (true) {- if (!attributes.get_next_ascii_char (ref index, out c)) {- has_attributes = false;- error = true;- warn (@"Expecting end quote for attribute $(attribute_name).");- return new Attribute.empty ();- }- - if (c == quote) {- break;- }- }- - content_stop = index - 1;- content = attributes.substring (content_start, content_stop - content_start);- - has_attributes = true;- - attribute_index = content_stop + 1;- return new Attribute (ns, attribute_name, content);- }-- public class Iterator : GLib.Object {- public Tag tag;- public Tag? next_tag = null;- public int iterator_efcount = 1;- - internal Iterator (Tag t) {- tag = t;- tag.reparse ();- }-- public bool next () {- if (tag.error) { - return false;- }- - if (tag.has_more_tags ()) {- next_tag = tag.get_next_tag ();- } else {- next_tag = null;- }- - return next_tag != null;- }-- public new Tag get () {- if (next_tag == null) {- XmlParser.warning ("No tag is parsed yet.");- return new Tag.empty ();- }- return (!) next_tag;- }- }- - internal int get_row (size_t pos) {- int index = 0;- unichar c;- int row = 1;- size_t e;- - e = (size_t) entire_file.data;- while (entire_file.get_next_ascii_char (ref index, out c)) {- if (c == '\n') {- row++;- }- - if (e + index >= pos) {- break;- }- }- - return row;- }- - internal void warn (string message) {- if (log_level == WARNINGS) {- XmlParser.warning (message);- }- }-}--}deleted file mode 100644@@ -1,220 +0,0 @@-/*- Copyright (C) 2014 Johan Mattsson-- This library is free software; you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as - published by the Free Software Foundation; either version 3 of the - License, or (at your option) any later version.-- This library is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details.-*/--/** - * Tools originally written for the BirdFont project.- */-namespace B {--/** Log levels */-internal const int NONE = 0;-internal const int WARNINGS = 1;--/** - * XML parser- * - * A tiny XML parser written in Vala.- * - * Example:- * {{{- * - * // Print all tags and attributes in an XML document. - * // Expected output:- * // tag1- * // tag2- * // attribute1- * public static int main (string[] arg) {- * Tag root;- * XmlParser parser;- * - * parser = new XmlParser ("""<tag1><tag2 attribute1=""/></tag1>"""); - * - * if (parser.validate ()) {- * root = parser.get_root_tag ();- * print_tags (root);- * }- * }- * - * - * void print_tags (Tag tag) {- * print (tag.get_name ());- * print ("\n");- * print_attributes (tag);- * - * foreach (Tag t in tag) {- * print_tags (t);- * }- * }- * - * void print_attributes (Tag tag) {- * Attributes attributes = tag.get_attributes ();- * foreach (Attribute attribute in attributes) {- * print (attribute.get_name ());- * print ("\n");- * }- * }- * - * }}}- * - */-public class XmlParser : GLib.Object {- Tag root;- XmlData data;- string input;- bool error;- - /** - * Create a new xml parser. - * @param data valid xml data- */- public XmlParser (string data) {- this.input = data;- this.data = new XmlData (data, data.length); - reparse (NONE);- }- - /** - * Determine if the document can be parsed.- * @return true if the xml document is valid xml.- */- public bool validate () {- if (this.data.error) {- error = true;- return false;- } - - reparse (NONE);-- if (error) {- return false;- }- - validate_tags (root);- - reparse (NONE);- return !error;- }- - void validate_tags (Tag tag) {- Attributes attributes = tag.get_attributes ();- - foreach (Attribute a in attributes) {- if (tag.has_failed () || a.name.length == 0) {- error = true;- return;- }- }- - foreach (Tag t in tag) {- if (tag.has_failed ()) {- error = true;- return;- }- - validate_tags (t);- } - }- - /** - * Obtain the root tag.- * @return the root tag. - */- public Tag get_root_tag () {- reparse (WARNINGS);- return root;- }- - /** - * Reset the parser and start from the beginning of the XML document. - */- internal void reparse (int log_level) {- int root_index;- Tag container;- XmlString content;- XmlString empty;- - error = false;- empty = new XmlString ("", 0);- - root_index = find_root_tag ();- if (root_index == -1) {- if (log_level == WARNINGS) {- XmlParser.warning ("No root tag found.");- }- error = true;- root = new Tag.empty ();- } else {- content = data.substring (root_index);- container = new Tag (empty, empty, content, log_level, data);- root = container.get_next_tag ();- }- }- - int find_root_tag () {- int index = 0;- int prev_index = 0;- int modifier = 0;- unichar c;- - while (true) {- prev_index = index;- if (!data.get_next_ascii_char (ref index, out c)) {- break;- }- - if (c == '<') {- modifier = index;- data.get_next_ascii_char (ref modifier, out c);- if (c != '?' && c != '[' && c != '!') {- return prev_index;- } - }- }- - return -1;- }-- /** Print a warning message. */- public static void warning (string message) {- print ("XML error: "); - print (message);- print ("\n");- }-- /** Replace escaped character with plain text characters. - * & will be replaced with & etc.- */- public static string decode (string s) {- string t;- t = s.replace (""", "\"");- t = t.replace ("'", "'");- t = t.replace ("<", "<");- t = t.replace (">", ">");- t = t.replace ("&", "&");- return t;- }-- public static string encode (string s) {- string t;- t = s.replace ("\"", """);- t = t.replace ("'", "'");- t = t.replace ("<", "<");- t = t.replace (">", ">");- t = t.replace ("&", "&");- return t;- }--}--}deleted file mode 100644@@ -1,152 +0,0 @@-/*- Copyright (C) 2015 Johan Mattsson-- This library is free software; you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as - published by the Free Software Foundation; either version 3 of the - License, or (at your option) any later version.-- This library is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details.-*/--namespace B {--public class XmlData : XmlString {- int* start_tags;- int tags_capacity;- int tags_size;- - internal bool error = false;- - public XmlData (char* data, int length) {- base (data, length);-- start_tags = null;- tags_capacity = 0;- tags_size = 0;- - index_start_tags ();- }- - ~XmlData () {- if (start_tags != null) {- delete start_tags;- start_tags = null;- }- }- - public int get_index (XmlString start) {- int offset = (int) ((size_t) start.data - (size_t) data);- return offset;- }- - public int find_next_tag_token (int index) {- int new_index;- - if (index >= length) {- return -1;- }- - for (int i = 0; i < tags_size; i++) {- new_index = start_tags[i];- if (new_index >= index) {- - if (new_index == 0 && i > 0) { //FIXME:DELETE- return -1;- }- - return new_index;- }- }- - return -1;- }-- void index_start_tags () {- const char first_bit = 1 << 7;- int i = 0;- char* d = data;- - while (d[i] != '\0') {- if ((int) (d[i] & first_bit) == 0) {- if (d[i] == '<') {- add_tag (i);- }- }- i++;- }- }- - void add_tag (int index) {- if (unlikely (tags_size == tags_capacity)) {- if (!increase_capacity ()) {- return;- }- }- - start_tags[tags_size] = index;- tags_size++;- }-- bool increase_capacity () {- int* tags;- - tags_capacity += 512;- tags = (int*) try_malloc (tags_capacity * sizeof (int));- - if (tags == null) {- tags_capacity = 0;- - if (start_tags != null) {- delete start_tags;- start_tags = null;- tags_size = 0;- error = true;- }- - warning ("Can not allocate xml data buffer.");- return false;- }- - if (tags_size > 0) {- Posix.memcpy (tags, start_tags, tags_size * sizeof (int));- }- - if (start_tags != null) {- delete start_tags;- }- - start_tags = tags;- - return true;- }- - public void print_all () {- XmlString s;- int i = -1;- string e;- - print("All tags:\n");- - for (int j = 0; j < tags_size; j++) {- i = find_next_tag_token (i + 1);- - if (i > -1) {- s = substring (i);- s = s.substring (0, s.index_of (">"));- s = s.substring (0, s.index_of (" "));- } else {- e = "error";- s = new XmlString (e, e.length); - }- - int o = start_tags[j];- print (s.to_string () + " : " + ((string) (data + o)).ndup (4) + @" $o $j i: $i\n");- }- }-}--}deleted file mode 100644@@ -1,143 +0,0 @@-/*- Copyright (C) 2014 2015 Johan Mattsson-- This library is free software; you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as - published by the Free Software Foundation; either version 3 of the - License, or (at your option) any later version.-- This library is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details.-*/--namespace B {--/** - * Representation of a string in the XmlParser. This class adds reference counting and- * copies a pointer to string instead of the data. It is faster if the string is - * huge.- */-public class XmlString : GLib.Object { - public int length;- public char* data;- public int refcount = 1;-- internal XmlString (char* data, int length) {- this.data = data;- this.length = length;- }-- internal int index_of (string needle, int offset = 0) {- int len = length;- int needle_len = needle.length;- char* needle_data = (char*) needle;- char* haystack = data + offset;- - if (needle_len == 0 || offset > length) {- return -1;- }- - for (int i = 0; i < len; i++) {- if (haystack[i] == '\0') {- return -1;- }- - for (int j = 0; j <= needle_len && i + j < len; j++) {- if (j == needle_len) {- return offset + i;- }- - if (needle_data[j] != haystack[i + j]) {- break;- }- }- }- - return -1;- }-- internal bool has_prefix (string prefix) {- unowned string s = (string) data;- bool p = s.has_prefix (prefix);-- if (!p) {- return false;- }- - return length > prefix.length;- }-- internal bool has_suffix (string suffix) {- int suffix_length = suffix.length;-- if (length < suffix_length) {- return false;- }- - return Posix.strncmp ((string) (data + length - suffix_length), suffix, suffix_length) == 0;- } -- internal bool get_next_char (ref int index, out unichar c) {- unowned string s;- unowned string? n = (string) data;- - if (index >= length) {- c = '\0';- return false;- }- - s = (!) n;- - return s.get_next_char (ref index, out c);- }- - internal bool get_next_ascii_char (ref int index, out unichar c) {- const char first_bit = 1 << 7;- int i = index;- char* d = data;-- if (index >= length) {- c = '\0';- return false;- }- - if (likely ((int) (d[i] & first_bit) == 0)) {- c = d[i];- index++;- return c != '\0';- }- - while ((int) (d[i] & first_bit) != 0) {- i++;- }- - index = i;- return get_next_char (ref index, out c);- }-- internal XmlString substring (int offset, int len = -1) {- Posix.assert (offset >= 0);- Posix.assert (offset < length);- - if (len == -1) {- return new XmlString (data + offset, length - offset);- }- - Posix.assert (len + offset < length); - return new XmlString (data + offset, len);- } - - public string to_string () {- unowned string s = (string) data;- - if (length == 0) {- return "".dup ();- } - - return s.ndup (length);- }-}--}@@ -47,7 +47,7 @@ def libbirdfont(prefix, cc, cflags, ldflags, valac, valaflags, library, nonNull --pkg """ + config.GEE + """ \ --pkg gio-2.0 \ --pkg cairo \- --pkg libbirdxml \+ --pkg xmlbird \ --pkg libbirdgems \ --pkg sqlite3 \ """)@@ -67,7 +67,7 @@ def libbirdfont(prefix, cc, cflags, ldflags, valac, valaflags, library, nonNull $(pkg-config --cflags gio-2.0) \ $(pkg-config --cflags cairo) \ $(pkg-config --cflags glib-2.0) \- -I ./build/libbirdxml \+ $(pkg-config --cflags xmlbird) \ -I ./build/libbirdgems""") run("mv ./*.o build/libbirdfont/ ") @@ -86,7 +86,8 @@ def libbirdfont(prefix, cc, cflags, ldflags, valac, valaflags, library, nonNull $(pkg-config --libs gio-2.0) \ $(pkg-config --libs cairo) \ $(pkg-config --libs glib-2.0) \- -L./build -L./build/bin -l birdxml -l birdgems\+ $(pkg-config --libs xmlbird) \+ -L./build -L./build/bin -l birdgems\ -o """ + library) run("mv " + library + " build/bin/") @@ -112,64 +113,6 @@ def libbirdfont(prefix, cc, cflags, ldflags, valac, valaflags, library, nonNull run("gzip build/birdfont-import.1") -def libbirdxml(prefix, cc, cflags, ldflags, valac, valaflags, library, nonNull = True):- #libbirdfont- run("mkdir -p build/libbirdxml")- run("mkdir -p build/bin")-- experimentalNonNull = ""- if nonNull:- experimentalNonNull = "--enable-experimental-non-null"-- run(valac + """\- -C \- """ + valaflags + """ \- --pkg posix \- --vapidir=./ \- --basedir build/libbirdxml/ \- """ + experimentalNonNull + """ \- --enable-experimental \- --library libbirdxml \- -H build/libbirdxml/birdxml.h \- libbirdxml/*.vala \- """)- - if cc == "":- print ("Skipping compilation");- else:- run(cc + " " + cflags + """ \- -c build/libbirdxml/*.c \- -fPIC \- $(pkg-config --cflags glib-2.0) \- $(pkg-config --cflags gobject-2.0) \- """)- - run("mv ./*.o build/libbirdxml/ ")-- if library.endswith (".dylib"):- sonameparam = "" # gcc on mac os does not have the soname parameter- else:- sonameparam = "-Wl,-soname," + library- - run(cc + " " + ldflags + """ \- -shared \- """ + sonameparam + """ \- build/libbirdxml/*.o \- $(pkg-config --libs glib-2.0) \- $(pkg-config --libs gobject-2.0) \- -o """ + library)- run("mv " + library + " build/bin/")- - if os.path.exists("build/bin/libbirdxml.so"):- run ("cd build/bin && unlink libbirdxml.so")-- # create link to the versioned library- if library.find ('.so') > -1:- run ("""cd build/bin && ln -sf """ + library + " libbirdxml.so")- elif library.find ('.dylib') > -1:- run ("""cd build/bin && ln -sf """ + library + " libbirdxml.dylib")- - def libbirdgems(prefix, cc, cflags, ldflags, valac, valaflags, library, nonNull = True): print ('Compiling libbirdgems') run("mkdir -p build/libbirdgems")@@ -273,7 +216,8 @@ def birdfont_export(prefix, cc, cflags, ldflags, valac, valaflags, nonNull = Tru $(pkg-config --libs gio-2.0) \ $(pkg-config --libs cairo) \ $(pkg-config --libs glib-2.0) \- -L./build -L./build/bin -l birdxml -l birdgems\+ $(pkg-config --libs xmlbird) \+ -L./build -L./build/bin -l birdgems\ -o ./build/bin/birdfont-export""") run("rm -f build/birdfont.1.gz")@@ -333,7 +277,8 @@ def birdfont_import(prefix, cc, cflags, ldflags, valac, valaflags, nonNull = Tru $(pkg-config --libs gio-2.0) \ $(pkg-config --libs cairo) \ $(pkg-config --libs glib-2.0) \- -L./build -L./build/bin -l birdxml -l birdgems\+ $(pkg-config --libs xmlbird) \+ -L./build -L./build/bin -l birdgems\ -o ./build/bin/birdfont-import""") def birdfont_autotrace(prefix, cc, cflags, ldflags, valac, valaflags, nonNull = True):@@ -379,8 +324,9 @@ def birdfont_autotrace(prefix, cc, cflags, ldflags, valac, valaflags, nonNull = $(pkg-config --libs gio-2.0) \ $(pkg-config --libs cairo) \ $(pkg-config --libs glib-2.0) \+ $(pkg-config --libs xmlbird) \ $(pkg-config --libs gdk-pixbuf-2.0) \- -L./build -L./build/bin -l birdxml -l birdgems\+ -L./build -L./build/bin -l birdgems\ -o ./build/bin/birdfont-autotrace""") @@ -433,7 +379,8 @@ def birdfont_gtk(prefix, cc, cflags, ldflags, valac, valaflags, nonNull = True): $(pkg-config --libs gdk-pixbuf-2.0) \ $(pkg-config --libs webkitgtk-3.0) \ $(pkg-config --libs gtk+-2.0) \+ $(pkg-config --libs xmlbird) \ $(pkg-config --libs libnotify) \- -L./build -L./build/bin -l birdxml -l birdgems\+ -L./build -L./build/bin -l birdgems\ -o ./build/bin/birdfont""")