fsck: factor out msg_id_info[] lazy initialization code
This array will be used by some other function than parse_msg_id() in the following commit. Factor out this prep code so it could be called from that one. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>maint
parent
fa151dc54d
commit
a46baac61e
40
fsck.c
40
fsck.c
|
@ -84,26 +84,34 @@ static struct {
|
||||||
};
|
};
|
||||||
#undef MSG_ID
|
#undef MSG_ID
|
||||||
|
|
||||||
|
static void prepare_msg_ids(void)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if (msg_id_info[0].downcased)
|
||||||
|
return;
|
||||||
|
|
||||||
|
/* convert id_string to lower case, without underscores. */
|
||||||
|
for (i = 0; i < FSCK_MSG_MAX; i++) {
|
||||||
|
const char *p = msg_id_info[i].id_string;
|
||||||
|
int len = strlen(p);
|
||||||
|
char *q = xmalloc(len);
|
||||||
|
|
||||||
|
msg_id_info[i].downcased = q;
|
||||||
|
while (*p)
|
||||||
|
if (*p == '_')
|
||||||
|
p++;
|
||||||
|
else
|
||||||
|
*(q)++ = tolower(*(p)++);
|
||||||
|
*q = '\0';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static int parse_msg_id(const char *text)
|
static int parse_msg_id(const char *text)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (!msg_id_info[0].downcased) {
|
prepare_msg_ids();
|
||||||
/* convert id_string to lower case, without underscores. */
|
|
||||||
for (i = 0; i < FSCK_MSG_MAX; i++) {
|
|
||||||
const char *p = msg_id_info[i].id_string;
|
|
||||||
int len = strlen(p);
|
|
||||||
char *q = xmalloc(len);
|
|
||||||
|
|
||||||
msg_id_info[i].downcased = q;
|
|
||||||
while (*p)
|
|
||||||
if (*p == '_')
|
|
||||||
p++;
|
|
||||||
else
|
|
||||||
*(q)++ = tolower(*(p)++);
|
|
||||||
*q = '\0';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < FSCK_MSG_MAX; i++)
|
for (i = 0; i < FSCK_MSG_MAX; i++)
|
||||||
if (!strcmp(text, msg_id_info[i].downcased))
|
if (!strcmp(text, msg_id_info[i].downcased))
|
||||||
|
|
Loading…
Reference in New Issue