diff.c: make built-in hunk header pattern a separate table
This would hopefully make it easier to maintain. Initially we would have "java" and "tex" defined, as they are the only ones we already have. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Jul 8, 2007 at 00:25 UTC
d3a93dc96786847f9d148da42ecadee5f027c9a7
1 file changed
+16
-6
diff.c
+16
-6
@@ -1216,9 +1216,22 @@ static const char *funcname_pattern(const char *ident)
1216
return NULL;
1217
}
1218
1219
+static struct builtin_funcname_pattern {
1220
+ const char *name;
1221
+ const char *pattern;
1222
+} builtin_funcname_pattern[] = {
1223
+ { "java", "!^[ ]*\\(catch\\|do\\|for\\|if\\|instanceof\\|"
1224
+ "new\\|return\\|switch\\|throw\\|while\\)\n"
1225
+ "^[ ]*\\(\\([ ]*"
1226
+ "[A-Za-z_][A-Za-z_0-9]*\\)\\{2,\\}"
1227
+ "[ ]*([^;]*$\\)" },
1228
+ { "tex", "^\\(\\\\\\(sub\\)*section{.*\\)$" },
1229
+};
1230
+
1231
static const char *diff_funcname_pattern(struct diff_filespec *one)
1232
{
1233
const char *ident, *pattern;
1234
+ int i;
1235
1236
diff_filespec_check_attr(one);
1237
ident = one->funcname_pattern_ident;
@@ -1240,12 +1253,9 @@ static const char *diff_funcname_pattern(struct diff_filespec *one)
1253
* And define built-in fallback patterns here. Note that
1254
* these can be overriden by the user's config settings.
1255
*/
1243
- if (!strcmp(ident, "java"))
1244
- return "!^[ ]*\\(catch\\|do\\|for\\|if\\|instanceof\\|"
1245
- "new\\|return\\|switch\\|throw\\|while\\)\n"
1246
- "^[ ]*\\(\\([ ]*"
1247
- "[A-Za-z_][A-Za-z_0-9]*\\)\\{2,\\}"
1248
- "[ ]*([^;]*$\\)";
1256
+ for (i = 0; i < ARRAY_SIZE(builtin_funcname_pattern); i++)
1257
+ if (!strcmp(ident, builtin_funcname_pattern[i].name))
1258
+ return builtin_funcname_pattern[i].pattern;
1259
1260
return NULL;
1261
}