Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fix wrong xml data for tags in range

  • Loading branch information...
commit 2c6feaaa6afe18f969df24f7acf1954013362130 1 parent d9ec445
Akira TAGOH authored

Showing 1 changed file with 59 additions and 6 deletions. Show diff stats Hide diff stats

  1. +59 6 data/reg2xml.c
65 data/reg2xml.c
@@ -46,7 +46,7 @@ _parse(const char *filename,
46 46 xmlNodePtr root)
47 47 {
48 48 FILE *fp;
49   - char buffer[1024];
  49 + char buffer[1024], *range = NULL, *begin = NULL, *end = NULL;
50 50 lt_bool_t in_entry = FALSE;
51 51 xmlNodePtr ent = NULL;
52 52
@@ -62,9 +62,45 @@ _parse(const char *filename,
62 62 if (lt_strcmp0(buffer, "%%") == 0) {
63 63 if (in_entry) {
64 64 if (ent) {
65   - xmlAddChild(root, ent);
  65 + if (range) {
  66 + xmlNodePtr p;
  67 + const char table[] = "abcdefghijklmnopqrstuvwxyz";
  68 + const char table2[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  69 + const char *t;
  70 + size_t len = strlen(begin);
  71 + int pos;
  72 +
  73 + if (begin[len - 1] >= 'a' && begin[len - 1] <= 'z')
  74 + t = table;
  75 + else
  76 + t = table2;
  77 +
  78 + while (1) {
  79 + p = xmlCopyNode(ent, 1);
  80 + xmlNewChild(p, NULL,
  81 + (const xmlChar *)range,
  82 + (const xmlChar *)begin);
  83 + xmlAddChild(root, p);
  84 + if (lt_strcmp0(begin, end) == 0)
  85 + break;
  86 + pos = len - 1;
  87 + while (pos >= 0) {
  88 + begin[pos] = t[begin[pos] - t[0] + 1];
  89 + if (begin[pos] == 0) {
  90 + begin[pos] = t[0];
  91 + pos--;
  92 + } else {
  93 + break;
  94 + }
  95 + }
  96 + }
  97 + xmlFreeNode(ent);
  98 + } else {
  99 + xmlAddChild(root, ent);
  100 + }
66 101 }
67 102 ent = NULL;
  103 + range = NULL;
68 104 }
69 105 in_entry = TRUE;
70 106 } else {
@@ -85,7 +121,7 @@ _parse(const char *filename,
85 121 buffer);
86 122 in_entry = FALSE;
87 123 } else {
88   - char *token, *tag;
  124 + char *token, *tag, *rtag;
89 125 fpos_t pos;
90 126 size_t len;
91 127
@@ -104,6 +140,7 @@ _parse(const char *filename,
104 140 }
105 141 if (i > 1) {
106 142 memmove(&buffer[len + 1], &buffer[len + i], l - i);
  143 + buffer[len + l - i + 1] = 0;
107 144 }
108 145 goto multiline;
109 146 } else {
@@ -113,9 +150,25 @@ _parse(const char *filename,
113 150 token = strstr(buffer, ": ");
114 151 tag = strndup(buffer, token - buffer);
115 152 token += 2;
116   - xmlNewChild(ent, NULL,
117   - (const xmlChar *)lt_strlower(tag),
118   - (const xmlChar *)token);
  153 + rtag = strstr(token, "..");
  154 + if (rtag && rtag[2] != '.') {
  155 + /* the range in tags */
  156 + begin = strndup(token, rtag - token);
  157 + rtag += 2;
  158 + end = strdup(rtag);
  159 + if (strlen(begin) != strlen(end)) {
  160 + lt_warning("Invalid range: %s..%s", begin, end);
  161 + xmlFreeNode(ent);
  162 + ent = NULL;
  163 + free(tag);
  164 + continue;
  165 + }
  166 + range = lt_strlower(strdup(tag));
  167 + } else {
  168 + xmlNewChild(ent, NULL,
  169 + (const xmlChar *)lt_strlower(tag),
  170 + (const xmlChar *)token);
  171 + }
119 172 free(tag);
120 173 }
121 174 }

0 comments on commit 2c6feaa

Please sign in to comment.
Something went wrong with that request. Please try again.