Re: [PATCH 03/18] Provide a function to parse fsck message IDs
Hi Junio, On Wed, 10 Dec 2014, Junio C Hamano wrote: Johannes Schindelin johannes.schinde...@gmx.de writes: This function will be used in the next commits to allow the user to ask fsck to handle specific problems differently, e.g. demoting certain errors to warnings. It has to handle partial strings because we would like to be able to parse, say, '--strict=missing-email=warn' command lines. To make the parsing robust, we generate strings from the enum keys, and we will match both lower-case, dash-separated values as well as camelCased ones (e.g. both missing-email and missingEmail will match the MISSING_EMAIL key). Signed-off-by: Johannes Schindelin johannes.schinde...@gmx.de --- fsck.c | 32 1 file changed, 32 insertions(+) diff --git a/fsck.c b/fsck.c index 3cea034..05b146c 100644 --- a/fsck.c +++ b/fsck.c @@ -63,6 +63,38 @@ enum fsck_msg_id { FSCK_MSG_MAX }; +#define STR(x) #x +#define MSG_ID_STR(x) STR(x), +static const char *msg_id_str[FSCK_MSG_MAX + 1] = { + FOREACH_MSG_ID(MSG_ID_STR) + NULL +}; I wondered what the ugly macro was in the previous step, but as a way to keep these two lists in sync it makes sense. I added a comment to the commit message. Ciao, Dscho -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 03/18] Provide a function to parse fsck message IDs
Johannes Schindelin johannes.schinde...@gmx.de writes: This function will be used in the next commits to allow the user to ask fsck to handle specific problems differently, e.g. demoting certain errors to warnings. It has to handle partial strings because we would like to be able to parse, say, '--strict=missing-email=warn' command lines. To make the parsing robust, we generate strings from the enum keys, and we will match both lower-case, dash-separated values as well as camelCased ones (e.g. both missing-email and missingEmail will match the MISSING_EMAIL key). Signed-off-by: Johannes Schindelin johannes.schinde...@gmx.de --- fsck.c | 32 1 file changed, 32 insertions(+) diff --git a/fsck.c b/fsck.c index 3cea034..05b146c 100644 --- a/fsck.c +++ b/fsck.c @@ -63,6 +63,38 @@ enum fsck_msg_id { FSCK_MSG_MAX }; +#define STR(x) #x +#define MSG_ID_STR(x) STR(x), +static const char *msg_id_str[FSCK_MSG_MAX + 1] = { + FOREACH_MSG_ID(MSG_ID_STR) + NULL +}; I wondered what the ugly macro was in the previous step, but as a way to keep these two lists in sync it makes sense. -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 03/18] Provide a function to parse fsck message IDs
This function will be used in the next commits to allow the user to ask fsck to handle specific problems differently, e.g. demoting certain errors to warnings. It has to handle partial strings because we would like to be able to parse, say, '--strict=missing-email=warn' command lines. To make the parsing robust, we generate strings from the enum keys, and we will match both lower-case, dash-separated values as well as camelCased ones (e.g. both missing-email and missingEmail will match the MISSING_EMAIL key). Signed-off-by: Johannes Schindelin johannes.schinde...@gmx.de --- fsck.c | 32 1 file changed, 32 insertions(+) diff --git a/fsck.c b/fsck.c index 3cea034..05b146c 100644 --- a/fsck.c +++ b/fsck.c @@ -63,6 +63,38 @@ enum fsck_msg_id { FSCK_MSG_MAX }; +#define STR(x) #x +#define MSG_ID_STR(x) STR(x), +static const char *msg_id_str[FSCK_MSG_MAX + 1] = { + FOREACH_MSG_ID(MSG_ID_STR) + NULL +}; + +static int parse_msg_id(const char *text, int len) +{ + int i, j; + + for (i = 0; i FSCK_MSG_MAX; i++) { + const char *key = msg_id_str[i]; + /* msg_id_str is upper-case, with underscores */ + for (j = 0; j len; j++) { + char c = *(key++); + if (c == '_') { + if (isalpha(text[j])) + c = *(key++); + else if (text[j] != '_') + c = '-'; + } + if (toupper(text[j]) != c) + break; + } + if (j == len !*key) + return i; + } + + die(Unhandled type: %.*s, len, text); +} + int fsck_msg_type(enum fsck_msg_id msg_id, struct fsck_options *options) { return msg_id FIRST_WARNING ? FSCK_ERROR : FSCK_WARN; -- 2.0.0.rc3.9669.g840d1f9 -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html