edc_navigator: compare name elaborately to search the part correctly.

previous string compare is not enough find the string if there are similar ones.

now compare them in detail to correct this.

@fix T3736
This commit is contained in:
Hermet Park 2016-06-02 00:08:04 +09:00
parent 6635a98393
commit 0882acfe93
1 changed files with 74 additions and 52 deletions

View File

@ -6,6 +6,18 @@
#define IDX_MAX 999999 #define IDX_MAX 999999
#define PROGRAM_IDX (IDX_MAX - 1) #define PROGRAM_IDX (IDX_MAX - 1)
#define ESCAPE_GOTO_END() \
p = strstr(++p, "\""); \
if (!p) goto end; \
p++; \
continue
#define ESCAPE_RET_NULL() \
p = strstr(++p, "\""); \
if (!p) return NULL; \
p++; \
continue
typedef struct group_it_s group_it; typedef struct group_it_s group_it;
typedef struct part_it_s part_it; typedef struct part_it_s part_it;
typedef struct state_it_s state_it; typedef struct state_it_s state_it;
@ -278,10 +290,7 @@ find_group_proc_internal(char *utf8, char *utf8_end, const char *group_name)
//Skip " ~ " Section //Skip " ~ " Section
if (*p == '\"') if (*p == '\"')
{ {
p = strstr(++p, "\""); ESCAPE_RET_NULL();
if (!p) return NULL;
p++;
continue;
} }
if (!strncmp("group", p, strlen("group"))) if (!strncmp("group", p, strlen("group")))
@ -289,17 +298,24 @@ find_group_proc_internal(char *utf8, char *utf8_end, const char *group_name)
p = strstr((p + 5), "\""); p = strstr((p + 5), "\"");
if (!p) return NULL; if (!p) return NULL;
p++; p++;
if (!strncmp(group_name, p, strlen(group_name))) int group_name_len = strlen(group_name);
if (!strncmp(group_name, p, group_name_len))
{
//Compare Elaborately
char *next_quote = strstr(p, "\"");
if (group_name_len == (next_quote - p))
{ {
result = p; result = p;
break; break;
} }
else else
{ {
p = strstr(p, "\""); ESCAPE_RET_NULL();
if (!p) return NULL; }
p++; }
continue; else
{
ESCAPE_RET_NULL();
} }
} }
p++; p++;
@ -353,10 +369,7 @@ find_part_proc_internal(char *utf8, char *utf8_end, const char* group_name,
//Skip " ~ " Section //Skip " ~ " Section
if (*p == '\"') if (*p == '\"')
{ {
p = strstr(++p, "\""); ESCAPE_RET_NULL();
if (!p) return NULL;
p++;
continue;
} }
if (!strncmp(part_type, p, strlen(part_type))) if (!strncmp(part_type, p, strlen(part_type)))
@ -364,17 +377,24 @@ find_part_proc_internal(char *utf8, char *utf8_end, const char* group_name,
p = strstr((p + strlen(part_type)), "\""); p = strstr((p + strlen(part_type)), "\"");
if (!p) return NULL; if (!p) return NULL;
p++; p++;
if (!strncmp(part_name, p, strlen(part_name))) int part_name_len = strlen(part_name);
if (!strncmp(part_name, p, part_name_len))
{
//Compare Elaborately
char *next_quote = strstr(p, "\"");
if (part_name_len == (next_quote - p))
{ {
result = p; result = p;
break; break;
} }
else else
{ {
p = strstr(p, "\""); ESCAPE_RET_NULL();
if (!p) return NULL; }
p++; }
continue; else
{
ESCAPE_RET_NULL();
} }
} }
@ -391,10 +411,7 @@ find_part_proc_internal(char *utf8, char *utf8_end, const char* group_name,
} }
else else
{ {
p = strstr(p, "\""); ESCAPE_RET_NULL();
if (!p) return NULL;
p++;
continue;
} }
} }
@ -459,10 +476,7 @@ find_state_proc(const char *group_name, const char *part_name,
//Skip " ~ " Section //Skip " ~ " Section
if (*p == '\"') if (*p == '\"')
{ {
p = strstr(++p, "\""); ESCAPE_GOTO_END();
if (!p) goto end;
p++;
continue;
} }
if (!strncmp("desc", p, strlen("desc"))) if (!strncmp("desc", p, strlen("desc")))
@ -470,17 +484,24 @@ find_state_proc(const char *group_name, const char *part_name,
p = strstr((p + 4), "\""); p = strstr((p + 4), "\"");
if (!p) goto end; if (!p) goto end;
p++; p++;
if (!strncmp(state_name, p, strlen(state_name))) int state_name_len = strlen(state_name);
if (!strncmp(state_name, p, state_name_len))
{
//Compare Elaborately
char *next_quote = strstr(p, "\"");
if (state_name_len == (next_quote - p))
{ {
result = p; result = p;
break; break;
} }
else else
{ {
p = strstr(p, "\""); ESCAPE_GOTO_END();
if (!p) goto end; }
p++; }
continue; else
{
ESCAPE_GOTO_END();
} }
} }
p++; p++;
@ -513,10 +534,7 @@ find_programs_proc_internal(char *utf8, char *utf8_end, const char *group_name)
//Skip " ~ " Section //Skip " ~ " Section
if (*p == '\"') if (*p == '\"')
{ {
p = strstr(++p, "\""); ESCAPE_RET_NULL();
if (!p) return NULL;
p++;
continue;
} }
if (!strncmp("programs", p, strlen("programs"))) if (!strncmp("programs", p, strlen("programs")))
@ -580,10 +598,7 @@ find_program_proc(const char *group_name, const char *program_name)
//Skip " ~ " Section //Skip " ~ " Section
if (*p == '\"') if (*p == '\"')
{ {
p = strstr(++p, "\""); ESCAPE_GOTO_END();
if (!p) goto end;
p++;
continue;
} }
if (!strncmp("program", p, strlen("program"))) if (!strncmp("program", p, strlen("program")))
@ -591,17 +606,24 @@ find_program_proc(const char *group_name, const char *program_name)
p = strstr((p + 6), "\""); p = strstr((p + 6), "\"");
if (!p) goto end; if (!p) goto end;
p++; p++;
if (!strncmp(program_name, p, strlen(program_name))) int program_name_len = strlen(program_name);
if (!strncmp(program_name, p, program_name_len))
{
//Compare Elaborately
char *next_quote = strstr(p, "\"");
if (program_name_len == (next_quote - p))
{ {
result = p; result = p;
break; break;
} }
else else
{ {
p = strstr(p, "\""); ESCAPE_GOTO_END();
if (!p) goto end; }
p++; }
continue; else
{
ESCAPE_GOTO_END();
} }
} }
p++; p++;