From 2fc82c79d333fb7d8a287e52cc9a804bb1247d8f Mon Sep 17 00:00:00 2001 From: Jaehyun Cho Date: Fri, 22 Jul 2016 11:53:31 +0900 Subject: [PATCH] Revert "Support to use macro as a group name." This reverts commit 335575eb84a87e38ee1ef4ff16673d5336ab6fdf Although using macro as a group name is not a common usage, but it takes a lot of efforts to maintain and implement new features based on this. --- src/lib/edc_parser.c | 501 +++---------------------------------- src/lib/enventor_private.h | 4 - 2 files changed, 32 insertions(+), 473 deletions(-) diff --git a/src/lib/edc_parser.c b/src/lib/edc_parser.c index ef91473..0dceda2 100644 --- a/src/lib/edc_parser.c +++ b/src/lib/edc_parser.c @@ -10,20 +10,6 @@ const char ATTR_PREPEND_NONE[] = ""; const char ATTR_APPEND_SEMICOLON[] = ";"; const char ATTR_APPEND_TRANSITION_TIME[] = " 1.0;"; -typedef enum { - PREPROC_DIRECTIVE_NONE, - PREPROC_DIRECTIVE_DEFINE, - PREPROC_DIRECTIVE_UNDEF -} Preproc_Directive; - -typedef struct defined_macro_s -{ - char *name; - char *definition; - int begin_line; - int end_line; //0 means that this macro is valid until the end of file. -} defined_macro; - typedef struct parser_attr_s { Eina_Stringshare *keyword; @@ -74,7 +60,6 @@ struct parser_s cur_context_td *cntd; type_init_td *titd; bracket_td *btd; - Eina_List *macro_list; Eina_Bool macro_update : 1; }; @@ -84,223 +69,6 @@ struct parser_s /* Internal method implementation */ /*****************************************************************************/ -/* Remove double quotation marks indicating a string to extract a pure string. - * Return translated macro. - */ -static char * -double_quotation_marks_remove(const char *str) -{ - char *new_str = NULL; - int i; - int j; - int len; - int new_len; - int cnt; - - if (!str) return NULL; - - len = strlen(str); - cnt = 0; - for (i = 0; i < len; i++) - { - if (str[i] == '"') - { - cnt++; - - if ((i > 0) && (str[i - 1] == '\\')) cnt--; - } - } - - new_len = len - cnt; - //Allocate one more char for last null character - new_str = (char *) calloc((new_len + 1) * sizeof(char), 1); - j = 0; - for (i = 0; i < len; i++) - { - if (str[i] != '"') - { - new_str[j] = str[i]; - j++; - } - else - { - if ((i > 0) && (str[i - 1] == '\\')) - { - new_str[j] = str[i]; - j++; - } - } - } - - return new_str; -} - -/* Convert input into output based on macro definitions of macro list. - * Return translated macro. - */ -static char * -macro_translate(Eina_List *macro_list, const char *macro, int macro_line) -{ - defined_macro *macro_node = NULL; - Eina_List *l = NULL; - char *cur_trans_macro = NULL; - char *trans_macro = NULL; - - if (!macro) return NULL; - - trans_macro = strdup(macro); - - EINA_LIST_REVERSE_FOREACH(macro_list, l, macro_node) - { - int cur_len; - int new_len; - int macro_name_len; - int macro_def_len; - long replace_begin_index; - char *sub_macro = NULL; - - sub_macro = strstr(trans_macro, macro_node->name); - if (!sub_macro) continue; - - if (macro_line < macro_node->begin_line) continue; - - if ((macro_node->end_line != 0) && - (macro_line > macro_node->end_line)) continue; - - replace_begin_index = sub_macro - trans_macro; - - cur_len = strlen(trans_macro); - macro_name_len = strlen(macro_node->name); - if (macro_node->definition) - macro_def_len = strlen(macro_node->definition); - else - macro_def_len = 0; - new_len = cur_len + (macro_def_len - macro_name_len); - - cur_trans_macro = strdup(trans_macro); - free(trans_macro); - - trans_macro = (char *) calloc(new_len * sizeof(char), 1); - strncpy(trans_macro, cur_trans_macro, replace_begin_index); - strncpy(&trans_macro[replace_begin_index], macro_node->definition, - macro_def_len); - strncpy(&trans_macro[replace_begin_index + macro_def_len], - &cur_trans_macro[replace_begin_index + macro_name_len], - new_len - (replace_begin_index + macro_def_len)); - - free(cur_trans_macro); - } - - cur_trans_macro = strdup(trans_macro); - free(trans_macro); - - trans_macro = double_quotation_marks_remove(cur_trans_macro); - free(cur_trans_macro); - - return trans_macro; -} - -/* Parse macro into name and definition. - * Return EINA_TRUE if parsing is successful. - * Return EINA_FALSE if parsing is failed. - */ -static Eina_Bool -define_parse(const char *macro, char **name, char **definition) -{ - int i; - int macro_len; - int name_len; - int def_len; - int name_end_index; - int def_begin_index; - char *macro_name; - char *macro_def; - - if (!macro) return EINA_FALSE; - - macro_len = strlen(macro); - name_end_index = -1; - def_begin_index = -1; - - for (i = 0; i < macro_len; i++) - { - if (isspace(macro[i])) - { - if (name_end_index == -1) - name_end_index = i - 1; - } - else - { - if (name_end_index != -1) - { - def_begin_index = i; - break; - } - } - } - - if (i == macro_len) - { - name_end_index = i - 1; - def_begin_index = macro_len; - } - - if (name) - { - name_len = name_end_index + 1; - - if (name_len == 0) - *name = NULL; - else - { - macro_name = strndup(macro, name_len); - *name = macro_name; - } - } - - if (definition) - { - def_len = macro_len - def_begin_index; - if (def_len == 0) - *definition = NULL; - else - { - macro_def = strndup(¯o[def_begin_index], def_len); - *definition = macro_def; - } - } - - return EINA_TRUE; -} - -static void -macro_node_free(defined_macro *macro) -{ - if (!macro) return; - - if (macro->name) - { - free(macro->name); - macro->name = NULL; - } - if (macro->definition) - { - free(macro->definition); - macro->definition = NULL; - } -} - -static void -macro_list_free(Eina_List *macro_list) -{ - defined_macro *macro = NULL; - - EINA_LIST_FREE(macro_list, macro) - { - macro_node_free(macro); - } -} - static void cur_context_thread_blocking(void *data, Ecore_Thread *thread EINA_UNUSED) { @@ -343,17 +111,10 @@ cur_context_thread_blocking(void *data, Ecore_Thread *thread EINA_UNUSED) int value_len = 0; double value_convert = 0.0; - int cur_line = 1; - Eina_List *macro_list = NULL; - if (!collections) bracket = 1; if (td->pd->macro_update) - { - parser_macro_list_set(td->pd, (const char *) utf8); - parser_macro_update(td->pd, EINA_FALSE); - } - macro_list = parser_macro_list_get(td->pd); + parser_macro_update(td->pd, EINA_FALSE); td->part_name = NULL; td->group_name = NULL; @@ -361,8 +122,6 @@ cur_context_thread_blocking(void *data, Ecore_Thread *thread EINA_UNUSED) while (p && p <= end) { - if (*p == '\n') cur_line++; - //Skip "" range if (!strncmp(p, QUOT_UTF8, QUOT_UTF8_LEN)) { @@ -551,34 +310,16 @@ cur_context_thread_blocking(void *data, Ecore_Thread *thread EINA_UNUSED) if (!strncmp(p, GROUP, GROUP_LEN)) { p += GROUP_LEN; - - char *name_end = strstr(p, SEMICOL_UTF8); - if (!name_end) goto end; - - char *space_pos = NULL; - char *temp_pos = strchr(p, ' '); - while (temp_pos && (temp_pos < name_end)) - { - space_pos = temp_pos; - if (!(++temp_pos)) break; - temp_pos = strchr(temp_pos, ' '); - } - - char *tab_pos = NULL; - temp_pos = strchr(p, '\t'); - while (temp_pos && (temp_pos < name_end)) - { - tab_pos = temp_pos; - temp_pos = strchr(p, '\t'); - } - - char *name_begin = space_pos > tab_pos ? space_pos : tab_pos; + char *name_begin = strstr(p, QUOT_UTF8); if (!name_begin) goto end; - name_begin++; + name_begin += QUOT_UTF8_LEN; + p = name_begin; + char *name_end = strstr(p, QUOT_UTF8); + if (!name_end) goto end; group_name = name_begin; group_name_len = name_end - name_begin; - p = name_end + SEMICOL_UTF8_LEN; + p = name_end + QUOT_UTF8_LEN; bracket++; continue; } @@ -590,18 +331,7 @@ cur_context_thread_blocking(void *data, Ecore_Thread *thread EINA_UNUSED) if (desc_name) desc_name = eina_stringshare_add_length(desc_name, desc_name_len); if (group_name) - { - group_name = eina_stringshare_add_length(group_name, group_name_len); - - char *trans_group_name = NULL; - trans_group_name = macro_translate(macro_list, group_name, cur_line); - if (trans_group_name) - { - eina_stringshare_del(group_name); - group_name = eina_stringshare_add(trans_group_name); - free(trans_group_name); - } - } + group_name = eina_stringshare_add_length(group_name, group_name_len); td->part_name = part_name; td->group_name = group_name; @@ -1866,151 +1596,29 @@ parser_line_cnt_get(parser_data *pd EINA_UNUSED, const char *src) return cnt; } -void -parser_macro_list_set(parser_data *pd, const char *text) -{ - const char str_define[] = "#define"; - const char str_undef[] = "#undef"; - int len; - int i; - int cur_line; - Eina_List *macro_list = NULL; - Preproc_Directive found_directive = PREPROC_DIRECTIVE_NONE; - - if (!text) return; - - len = strlen(text); - cur_line = 1; - for (i = 0; i < len; i++) - { - if (isspace(text[i])) - { - if (text[i] == '\n') cur_line++; - - continue; - } - - if (found_directive == PREPROC_DIRECTIVE_DEFINE) - { - defined_macro *macro_node; - char *macro = NULL; - char *macro_name = NULL; - char *macro_def = NULL; - char *trans_macro = NULL; - const char *new_line_pos = strchr(&text[i], '\n'); - long macro_len = new_line_pos - &text[i]; - - if (macro_len > 0) - { - macro = strndup(&text[i], (int) macro_len); - - define_parse(macro, ¯o_name, ¯o_def); - - trans_macro = macro_translate(macro_list, macro_def, - cur_line); - - macro_node = calloc(sizeof(defined_macro), 1); - macro_node->name = strdup(macro_name); - macro_node->definition = trans_macro; - macro_node->begin_line = cur_line; - macro_node->end_line = 0; - - macro_list = eina_list_append(macro_list, macro_node); - - i += strlen(macro) - 1; - free(macro); - } - found_directive = PREPROC_DIRECTIVE_NONE; - } - else if (found_directive == PREPROC_DIRECTIVE_UNDEF) - { - Eina_List *l = NULL; - defined_macro *macro_node; - char *macro_name = NULL; - const char *new_line_pos = strchr(&text[i], '\n'); - long macro_name_len = new_line_pos - &text[i]; - - if (macro_name_len > 0) - { - macro_name = strndup(&text[i], (int) macro_name_len); - - EINA_LIST_FOREACH(macro_list, l, macro_node) - { - if (!strcmp(macro_name, macro_node->name) && - (macro_node->end_line == -1)) - { - macro_node->end_line = cur_line; - break; - } - } - i += strlen(macro_name) - 1; - free(macro_name); - } - found_directive = PREPROC_DIRECTIVE_NONE; - } - else - { - if (text[i] == '#') - { - if (!strncmp(&text[i], str_define, strlen(str_define))) - { - found_directive = PREPROC_DIRECTIVE_DEFINE; - i += strlen(str_define) - 1; - } - else if (!strncmp(&text[i], str_undef, strlen(str_undef))) - { - found_directive = PREPROC_DIRECTIVE_UNDEF; - i += strlen(str_undef) - 1; - } - } - } - } - - if (pd->macro_list) macro_list_free(pd->macro_list); - - pd->macro_list = macro_list; -} - -Eina_List * -parser_macro_list_get(parser_data *pd) -{ - return pd->macro_list; -} - Eina_Stringshare * -parser_first_group_name_get(parser_data *pd, Evas_Object *entry) +parser_first_group_name_get(parser_data *pd EINA_UNUSED, Evas_Object *entry) { - const char *markup = elm_entry_entry_get(entry); - char *utf8 = elm_entry_markup_to_utf8(markup); - int utf8_len = strlen(utf8); - char *p = utf8; + Evas_Object *tb = elm_entry_textblock_get(entry); + char *text = (char *) evas_object_textblock_text_markup_get(tb); + if (!text) return NULL; - const char *quot = QUOT_UTF8; - const char *semicol = SEMICOL_UTF8; + const int text_len = strlen(text); + char *p = text; + + const char *quot = QUOT; + const int quot_len = QUOT_LEN; const char *group = "group"; - const int quot_len = QUOT_UTF8_LEN; const int group_len = 5; //strlen("group"); - const char *group_name = NULL; - - int cur_line = 1; - parser_macro_list_set(pd, (const char *) utf8); - Eina_List *macro_list = parser_macro_list_get(pd); - - while (p < (utf8 + utf8_len)) + while (p < (text + text_len)) { - if (*p == '\n') cur_line++; - //Skip "" range if (!strncmp(p, quot, quot_len)) { p += quot_len; p = strstr(p, quot); - if (!p) - { - group_name = NULL; - goto end;; - } + if (!p) goto end; p += quot_len; continue; } @@ -2027,9 +1635,9 @@ parser_first_group_name_get(parser_data *pd, Evas_Object *entry) //Skip comments: // if ((*p == '/') && (*(++p) == '/')) { - p = strstr(p, "\n"); + p = strstr(p, EOL); if (!p) goto end; - p++; + p += EOL_LEN; continue; } @@ -2048,7 +1656,7 @@ parser_first_group_name_get(parser_data *pd, Evas_Object *entry) //escape "\", "ie, #define .... \" p += 7; //strlen(#define) - while (p < (utf8 + utf8_len)) + while (p < (text + text_len)) { char *slash = strstr(p, "\\"); if (!slash) break; @@ -2058,7 +1666,7 @@ parser_first_group_name_get(parser_data *pd, Evas_Object *entry) if (eol < slash) break; - p = eol + 1; + p = eol + EOL_LEN; } } @@ -2066,62 +1674,20 @@ parser_first_group_name_get(parser_data *pd, Evas_Object *entry) if (!strncmp(p, group, group_len)) { p += group_len; + char *name_begin = strstr(p, quot); + if (!name_begin) goto end; + name_begin += quot_len; + p = name_begin; + char *name_end = strstr(p, quot); + if (!name_end) goto end; - char *name_end = strstr(p, semicol); - if (!name_end) - { - group_name = NULL; - goto end;; - } - - char *space_pos = NULL; - char *temp_pos = strchr(p, ' '); - while (temp_pos && (temp_pos < name_end)) - { - space_pos = temp_pos; - temp_pos++; - temp_pos = strchr(temp_pos, ' '); - } - - char *tab_pos = NULL; - temp_pos = strchr(p, '\t'); - while (temp_pos && (temp_pos < name_end)) - { - tab_pos = temp_pos; - temp_pos++; - temp_pos = strchr(p, '\t'); - } - - char *name_begin = space_pos > tab_pos ? space_pos : tab_pos; - if (!name_begin) - { - group_name = NULL; - goto end;; - } - name_begin++; - - group_name = eina_stringshare_add_length(name_begin, - name_end - name_begin); - break; + return eina_stringshare_add_length(name_begin, + (name_end - name_begin)); } p++; } - - if (group_name) - { - char *trans_group_name = NULL; - trans_group_name = macro_translate(macro_list, group_name, cur_line); - if (trans_group_name) - { - eina_stringshare_del(group_name); - group_name = eina_stringshare_add(trans_group_name); - free(trans_group_name); - } - } - end: - free(utf8); - return group_name; + return NULL; } Eina_List * @@ -2201,9 +1767,6 @@ parser_term(parser_data *pd) eina_inarray_free(pd->attrs); - macro_list_free(pd->macro_list); - pd->macro_list = NULL; - free(pd); } diff --git a/src/lib/enventor_private.h b/src/lib/enventor_private.h index f308910..5ae98f7 100644 --- a/src/lib/enventor_private.h +++ b/src/lib/enventor_private.h @@ -7,8 +7,6 @@ #define QUOT_LEN 6 #define QUOT_UTF8 "\"" #define QUOT_UTF8_LEN 1 -#define SEMICOL_UTF8 ";" -#define SEMICOL_UTF8_LEN 1 #define LESS "<" #define GREATER ">" #define AMP "&" @@ -121,8 +119,6 @@ Eina_Bool parser_images_pos_get(const Evas_Object *entry, int *ret); Eina_Bool parser_is_image_name(const Evas_Object *entry, const char *str); Eina_Bool parser_styles_pos_get(const Evas_Object *entry, int *ret); Eina_Bool parser_state_info_get(Evas_Object *entry, state_info *info); -void parser_macro_list_set(parser_data *pd, const char *text); -Eina_List *parser_macro_list_get(parser_data *pd); void parser_macro_update(parser_data *pd, Eina_Bool macro_update); typedef void (*Bracket_Update_Cb)(void *data, int left, int right); void parser_bracket_find(parser_data *pd, Evas_Object *entry, Bracket_Update_Cb func, void *data);