Merge branch 'tr/userdiff-c-returns-pointer'
authorJunio C Hamano <gitster@pobox.com>
Wed, 14 Dec 2011 06:57:19 +0000 (22:57 -0800)
committerJunio C Hamano <gitster@pobox.com>
Wed, 14 Dec 2011 06:57:19 +0000 (22:57 -0800)
* tr/userdiff-c-returns-pointer:
userdiff: allow * between cpp funcname words

1  2 
userdiff.c
diff --combined userdiff.c
index 7c983c14ff2f4bc2aac6e632ccf982ea9589c6e3,16b5119b17636670cf05560d388c284eee963572..76109da4bcb7abc26ed20508692051a40e8addd7
@@@ -8,27 -8,10 +8,27 @@@ static int ndrivers
  static int drivers_alloc;
  
  #define PATTERNS(name, pattern, word_regex)                   \
 -      { name, NULL, -1, { pattern, REG_EXTENDED }, word_regex }
 +      { name, NULL, -1, { pattern, REG_EXTENDED },            \
 +        word_regex "|[^[:space:]]|[\xc0-\xff][\x80-\xbf]+" }
 +#define IPATTERN(name, pattern, word_regex)                   \
 +      { name, NULL, -1, { pattern, REG_EXTENDED | REG_ICASE }, \
 +        word_regex "|[^[:space:]]|[\xc0-\xff][\x80-\xbf]+" }
  static struct userdiff_driver builtin_drivers[] = {
 +IPATTERN("fortran",
 +       "!^([C*]|[ \t]*!)\n"
 +       "!^[ \t]*MODULE[ \t]+PROCEDURE[ \t]\n"
 +       "^[ \t]*((END[ \t]+)?(PROGRAM|MODULE|BLOCK[ \t]+DATA"
 +              "|([^'\" \t]+[ \t]+)*(SUBROUTINE|FUNCTION))[ \t]+[A-Z].*)$",
 +       /* -- */
 +       "[a-zA-Z][a-zA-Z0-9_]*"
 +       "|\\.([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])\\."
 +       /* numbers and format statements like 2E14.4, or ES12.6, 9X.
 +        * Don't worry about format statements without leading digits since
 +        * they would have been matched above as a variable anyway. */
 +       "|[-+]?[0-9.]+([AaIiDdEeFfLlTtXx][Ss]?[-+]?[0-9.]*)?(_[a-zA-Z0-9][a-zA-Z0-9_]*)?"
 +       "|//|\\*\\*|::|[/<>=]="),
  PATTERNS("html", "^[ \t]*(<[Hh][1-6][ \t].*>.*)$",
 -       "[^<>= \t]+|[^[:space:]]|[\x80-\xff]+"),
 +       "[^<>= \t]+"),
  PATTERNS("java",
         "!^[ \t]*(catch|do|for|if|instanceof|new|return|switch|throw|while)\n"
         "^[ \t]*(([A-Za-z_][A-Za-z_0-9]*[ \t]+)+[A-Za-z_][A-Za-z_0-9]*[ \t]*\\([^;]*)$",
         "[a-zA-Z_][a-zA-Z0-9_]*"
         "|[-+0-9.e]+[fFlL]?|0[xXbB]?[0-9a-fA-F]+[lL]?"
         "|[-+*/<>%&^|=!]="
 -       "|--|\\+\\+|<<=?|>>>?=?|&&|\\|\\|"
 -       "|[^[:space:]]|[\x80-\xff]+"),
 +       "|--|\\+\\+|<<=?|>>>?=?|&&|\\|\\|"),
 +PATTERNS("matlab",
 +       "^[[:space:]]*((classdef|function)[[:space:]].*)$|^%%[[:space:]].*$",
 +       "[a-zA-Z_][a-zA-Z0-9_]*|[-+0-9.e]+|[=~<>]=|\\.[*/\\^']|\\|\\||&&"),
  PATTERNS("objc",
         /* Negate C statements that can look like functions */
         "!^[ \t]*(do|for|if|else|return|switch|while)\n"
         /* -- */
         "[a-zA-Z_][a-zA-Z0-9_]*"
         "|[-+0-9.e]+[fFlL]?|0[xXbB]?[0-9a-fA-F]+[lL]?"
 -       "|[-+*/<>%&^|=!]=|--|\\+\\+|<<=?|>>=?|&&|\\|\\||::|->"
 -       "|[^[:space:]]|[\x80-\xff]+"),
 +       "|[-+*/<>%&^|=!]=|--|\\+\\+|<<=?|>>=?|&&|\\|\\||::|->"),
  PATTERNS("pascal",
 -       "^((procedure|function|constructor|destructor|interface|"
 +       "^(((class[ \t]+)?(procedure|function)|constructor|destructor|interface|"
                "implementation|initialization|finalization)[ \t]*.*)$"
         "\n"
         "^(.*=[ \t]*(class|record).*)$",
         /* -- */
         "[a-zA-Z_][a-zA-Z0-9_]*"
         "|[-+0-9.e]+|0[xXbB]?[0-9a-fA-F]+"
 -       "|<>|<=|>=|:=|\\.\\."
 -       "|[^[:space:]]|[\x80-\xff]+"),
 +       "|<>|<=|>=|:=|\\.\\."),
 +PATTERNS("perl",
 +       "^package .*\n"
 +       "^sub [[:alnum:]_':]+[ \t]*"
 +              "(\\([^)]*\\)[ \t]*)?" /* prototype */
 +              /*
 +               * Attributes.  A regex can't count nested parentheses,
 +               * so just slurp up whatever we see, taking care not
 +               * to accept lines like "sub foo; # defined elsewhere".
 +               *
 +               * An attribute could contain a semicolon, but at that
 +               * point it seems reasonable enough to give up.
 +               */
 +              "(:[^;#]*)?"
 +              "(\\{[ \t]*)?" /* brace can come here or on the next line */
 +              "(#.*)?$\n" /* comment */
 +       "^(BEGIN|END|INIT|CHECK|UNITCHECK|AUTOLOAD|DESTROY)[ \t]*"
 +              "(\\{[ \t]*)?" /* brace can come here or on the next line */
 +              "(#.*)?$\n"
 +       "^=head[0-9] .*",      /* POD */
 +       /* -- */
 +       "[[:alpha:]_'][[:alnum:]_']*"
 +       "|0[xb]?[0-9a-fA-F_]*"
 +       /* taking care not to interpret 3..5 as (3.)(.5) */
 +       "|[0-9a-fA-F_]+(\\.[0-9a-fA-F_]+)?([eE][-+]?[0-9_]+)?"
 +       "|=>|-[rwxoRWXOezsfdlpSugkbctTBMAC>]|~~|::"
 +       "|&&=|\\|\\|=|//=|\\*\\*="
 +       "|&&|\\|\\||//|\\+\\+|--|\\*\\*|\\.\\.\\.?"
 +       "|[-+*/%.^&<>=!|]="
 +       "|=~|!~"
 +       "|<<|<>|<=>|>>"),
  PATTERNS("php",
         "^[\t ]*(((public|protected|private|static)[\t ]+)*function.*)$\n"
         "^[\t ]*(class.*)$",
         /* -- */
         "[a-zA-Z_][a-zA-Z0-9_]*"
         "|[-+0-9.e]+|0[xXbB]?[0-9a-fA-F]+"
 -       "|[-+*/<>%&^|=!.]=|--|\\+\\+|<<=?|>>=?|===|&&|\\|\\||::|->"
 -       "|[^[:space:]]|[\x80-\xff]+"),
 +       "|[-+*/<>%&^|=!.]=|--|\\+\\+|<<=?|>>=?|===|&&|\\|\\||::|->"),
  PATTERNS("python", "^[ \t]*((class|def)[ \t].*)$",
         /* -- */
         "[a-zA-Z_][a-zA-Z0-9_]*"
         "|[-+0-9.e]+[jJlL]?|0[xX]?[0-9a-fA-F]+[lL]?"
 -       "|[-+*/<>%&^|=!]=|//=?|<<=?|>>=?|\\*\\*=?"
 -       "|[^[:space:]|[\x80-\xff]+"),
 +       "|[-+*/<>%&^|=!]=|//=?|<<=?|>>=?|\\*\\*=?"),
         /* -- */
  PATTERNS("ruby", "^[ \t]*((class|module|def)[ \t].*)$",
         /* -- */
         "(@|@@|\\$)?[a-zA-Z_][a-zA-Z0-9_]*"
         "|[-+0-9.e]+|0[xXbB]?[0-9a-fA-F]+|\\?(\\\\C-)?(\\\\M-)?."
 -       "|//=?|[-+*/<>%&^|=!]=|<<=?|>>=?|===|\\.{1,3}|::|[!=]~"
 -       "|[^[:space:]|[\x80-\xff]+"),
 +       "|//=?|[-+*/<>%&^|=!]=|<<=?|>>=?|===|\\.{1,3}|::|[!=]~"),
  PATTERNS("bibtex", "(@[a-zA-Z]{1,}[ \t]*\\{{0,1}[ \t]*[^ \t\"@',\\#}{~%]*).*$",
         "[={}\"]|[^={}\" \t]+"),
  PATTERNS("tex", "^(\\\\((sub)*section|chapter|part)\\*{0,1}\\{.*)$",
 -       "\\\\[a-zA-Z@]+|\\\\.|[a-zA-Z0-9\x80-\xff]+|[^[:space:]]"),
 +       "\\\\[a-zA-Z@]+|\\\\.|[a-zA-Z0-9\x80-\xff]+"),
  PATTERNS("cpp",
         /* Jump targets or access declarations */
         "!^[ \t]*[A-Za-z_][A-Za-z_0-9]*:.*$\n"
         /* C/++ functions/methods at top level */
-        "^([A-Za-z_][A-Za-z_0-9]*([ \t]+[A-Za-z_][A-Za-z_0-9]*([ \t]*::[ \t]*[^[:space:]]+)?){1,}[ \t]*\\([^;]*)$\n"
+        "^([A-Za-z_][A-Za-z_0-9]*([ \t*]+[A-Za-z_][A-Za-z_0-9]*([ \t]*::[ \t]*[^[:space:]]+)?){1,}[ \t]*\\([^;]*)$\n"
         /* compound type at top level */
         "^((struct|class|enum)[^;]*)$",
         /* -- */
         "[a-zA-Z_][a-zA-Z0-9_]*"
         "|[-+0-9.e]+[fFlL]?|0[xXbB]?[0-9a-fA-F]+[lL]?"
 -       "|[-+*/<>%&^|=!]=|--|\\+\\+|<<=?|>>=?|&&|\\|\\||::|->"
 -       "|[^[:space:]]|[\x80-\xff]+"),
 +       "|[-+*/<>%&^|=!]=|--|\\+\\+|<<=?|>>=?|&&|\\|\\||::|->"),
  PATTERNS("csharp",
         /* Keywords */
         "!^[ \t]*(do|while|for|if|else|instanceof|new|return|switch|case|throw|catch|using)\n"
         /* -- */
         "[a-zA-Z_][a-zA-Z0-9_]*"
         "|[-+0-9.e]+[fFlL]?|0[xXbB]?[0-9a-fA-F]+[lL]?"
 -       "|[-+*/<>%&^|=!]=|--|\\+\\+|<<=?|>>=?|&&|\\|\\||::|->"
 -       "|[^[:space:]]|[\x80-\xff]+"),
 +       "|[-+*/<>%&^|=!]=|--|\\+\\+|<<=?|>>=?|&&|\\|\\||::|->"),
  { "default", NULL, -1, { NULL, 0 } },
  };
  #undef PATTERNS
 +#undef IPATTERN
  
  static struct userdiff_driver driver_true = {
        "diff=true",
@@@ -273,7 -230,7 +273,7 @@@ struct userdiff_driver *userdiff_find_b
  
        if (!path)
                return NULL;
 -      if (git_checkattr(path, 1, &check))
 +      if (git_check_attr(path, 1, &check))
                return NULL;
  
        if (ATTR_TRUE(check.value))
                return NULL;
        return userdiff_find_by_name(check.value);
  }
 +
 +struct userdiff_driver *userdiff_get_textconv(struct userdiff_driver *driver)
 +{
 +      if (!driver->textconv)
 +              return NULL;
 +
 +      if (driver->textconv_want_cache && !driver->textconv_cache) {
 +              struct notes_cache *c = xmalloc(sizeof(*c));
 +              struct strbuf name = STRBUF_INIT;
 +
 +              strbuf_addf(&name, "textconv/%s", driver->name);
 +              notes_cache_init(c, name.buf, driver->textconv);
 +              driver->textconv_cache = c;
 +      }
 +
 +      return driver;
 +}