Re: [PATCH 04/18] Offer a function to demote fsck errors to warnings
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Dec 23, 2014, 16:18 UTC
- Message-ID
- <xmqqr3vq49w5.fsf@gitster.dls.corp.google.com>
- In-Reply-To
- <alpine.DEB.1.00.1412231051320.21312@s15462909.onlinehome-server.info>
Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
Show 5 quoted lines
> However, if we had to change the lookup such that it uses an array always, > we would have to introduce a function to initialize the struct, always, in > particular we would have to find a place to call that initialization > function in, say, builtin/fsck.c (actually, in every code path that calls > into the fsck machinery).
You would need to call a function to "initialize" the table if you support customization by reading the configuration files anyway. I am not sure why you think finding such a place is hard. Puzzled.
Also I suspect that you can tell the compiler to initialize the array in place with default values, perhaps like this?
-- >8 -- #include <stdio.h>
/* sorted by the default severity (lowest impact first) */ #define EVENT_LIST(F) \ F(EVENT_A), \ F(EVENT_B), \ F(EVENT_C), \ F(EVENT_D)
#define ID_(event) ID_ ## event
enum event_id {
EVENT_LIST(ID_)
};enum severity_level {
severity_info, severity_warn, severity_error
};/* below this one are INFO */ #define FIRST_WARN_EVENT_ID ID_EVENT_B /* below this one are WARN */ #define FIRST_ERROR_EVENT_ID ID_EVENT_C
#define STRING_(s) #s
#define DESC_(event) \
{ \
ID_ ## event, \
STRING_(event), \
(ID_ ## event < FIRST_WARN_EVENT_ID \
? severity_info \
: ID_ ## event < FIRST_ERROR_EVENT_ID \
? severity_warn \
: severity_error) \
}struct event_config {
enum event_id id;
const char * name;
enum severity_level level;
} event[] = {
EVENT_LIST(DESC_)
};int main(int ac, char **av)
{
int i; for (i = 0; i < sizeof(event) / sizeof(event[0]); i++) {
printf("%d, %s, %d\n",
event[i].id, event[i].name, event[i].level);
}
return 0;
}