userdiff.c: add builtin fortran regex patterns
This adds fortran xfuncname and wordRegex patterns to the list of builtin patterns. The intention is for the patterns to be appropriate for all versions of fortran including 77, 90, 95. The patterns can be enabled by adding the diff=fortran attribute to the .gitattributes file for the desired file glob. This also adds a new macro named IPATTERN which is just like the PATTERNS macro except it sets the REG_ICASE flag so that case will be ignored. The test code in t4018 and the docs were updated as appropriate. Signed-off-by: Brandon Casey <casey@nrlssc.navy.mil> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Brandon Casey committed
Sep 10, 2010 at 11:18 UTC
909a5494f869371565ed9326e984adeabf42611d
3 files changed
+20
-1
Documentation/gitattributes.txt
+2
@@ -477,6 +477,8 @@ patterns are available:
477
478
- `csharp` suitable for source code in the C# language.
479
480
+- `fortran` suitable for source code in the Fortran language.
481
+
482
- `html` suitable for HTML/XHTML documents.
483
484
- `java` suitable for source code in the Java language.
t/t4018-diff-funcname.sh
+1
-1
@@ -32,7 +32,7 @@ EOF
32
33
sed 's/beer\\/beer,\\/' < Beer.java > Beer-correct.java
34
35
-builtin_patterns="bibtex cpp csharp html java objc pascal php python ruby tex"
35
+builtin_patterns="bibtex cpp csharp fortran html java objc pascal php python ruby tex"
36
for p in $builtin_patterns
37
do
38
test_expect_success "builtin $p pattern compiles" '
userdiff.c
+17
@@ -9,7 +9,23 @@ static int drivers_alloc;
9
10
#define PATTERNS(name, pattern, word_regex) \
11
{ name, NULL, -1, { pattern, REG_EXTENDED }, word_regex }
12
+#define IPATTERN(name, pattern, word_regex) \
13
+ { name, NULL, -1, { pattern, REG_EXTENDED | REG_ICASE }, word_regex }
14
static struct userdiff_driver builtin_drivers[] = {
15
+IPATTERN("fortran",
16
+ "!^([C*]|[ \t]*!)\n"
17
+ "!^[ \t]*MODULE[ \t]+PROCEDURE[ \t]\n"
18
+ "^[ \t]*((END[ \t]+)?(PROGRAM|MODULE|BLOCK[ \t]+DATA"
19
+ "|([^'\" \t]+[ \t]+)*(SUBROUTINE|FUNCTION))[ \t]+[A-Z].*)$",
20
+ /* -- */
21
+ "[a-zA-Z][a-zA-Z0-9_]*"
22
+ "|\\.([Ee][Qq]|[Nn][Ee]|[Gg][TtEe]|[Ll][TtEe]|[Tt][Rr][Uu][Ee]|[Ff][Aa][Ll][Ss][Ee]|[Aa][Nn][Dd]|[Oo][Rr]|[Nn]?[Ee][Qq][Vv]|[Nn][Oo][Tt])\\."
23
+ /* numbers and format statements like 2E14.4, or ES12.6, 9X.
24
+ * Don't worry about format statements without leading digits since
25
+ * they would have been matched above as a variable anyway. */
26
+ "|[-+]?[0-9.]+([AaIiDdEeFfLlTtXx][Ss]?[-+]?[0-9.]*)?(_[a-zA-Z0-9][a-zA-Z0-9_]*)?"
27
+ "|//|\\*\\*|::|[/<>=]="
28
+ "|[^[:space:]]|[\x80-\xff]+"),
29
PATTERNS("html", "^[ \t]*(<[Hh][1-6][ \t].*>.*)$",
30
"[^<>= \t]+|[^[:space:]]|[\x80-\xff]+"),
31
PATTERNS("java",
@@ -101,6 +117,7 @@ PATTERNS("csharp",
117
{ "default", NULL, -1, { NULL, 0 } },
118
};
119
#undef PATTERNS
120
+#undef IPATTERN
121
122
static struct userdiff_driver driver_true = {
123
"diff=true",