(edit_read_syntax_rules): minor refactoring of keyword first chars collect.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2014-10-01 09:39:22 +04:00
parent 172196d16a
commit 32cfbfaef1

View File

@ -1199,28 +1199,28 @@ edit_read_syntax_rules (WEdit * edit, FILE * f, char **args, int args_size)
if (result == 0) if (result == 0)
{ {
int i; int i;
char *first_chars; GString *first_chars;
if (num_contexts == -1) if (num_contexts == -1)
return line; return line;
first_chars = g_malloc0 (max_alloc_words_per_context + 2); first_chars = g_string_sized_new (max_alloc_words_per_context + 2);
for (i = 0; edit->rules[i] != NULL; i++) for (i = 0; edit->rules[i] != NULL; i++)
{ {
char *p;
int j; int j;
g_string_set_size (first_chars, 0);
c = edit->rules[i]; c = edit->rules[i];
p = first_chars;
*p++ = (char) 1; g_string_append_c (first_chars, (char) 1);
for (j = 1; c->keyword[j] != NULL; j++) for (j = 1; c->keyword[j] != NULL; j++)
*p++ = c->keyword[j]->first; g_string_append_c (first_chars, c->keyword[j]->first);
*p = '\0';
c->keyword_first_chars = g_strdup (first_chars); c->keyword_first_chars = g_strndup (first_chars->str, first_chars->len);
} }
g_free (first_chars); g_string_free (first_chars, TRUE);
} }
return result; return result;