Search code examples
ctags

Can't add reg expression for a #define in ctags


I can't figure out how to make ctags detect the __mrs_s definition. It doesn't add the search pattern so I can't find it in vi.

$cat /tmp/qq.h
int test(int i)
{
printf("Hello!");
return 0;
}

#define __mrs_s(v, r)                       \
    DEFINE_MRS_S                        \
"   mrs_s " v ", " __stringify(r) "\n"          \
    UNDEFINE_MRS_S

$ctags --regex-C++='/^#define \([a-zA-Z_0-9]+\)([a-zA-Z,\ ]+)[\t ]+/\1/d/'  -o - /tmp/qq.h
__mrs_s /tmp/qq.h   7;" d
test    /tmp/qq.h   /^int test(int i)$/;"   f

Solution

  • Use --excmd=pattern option like:

    [root@localhost ~]# cat /tmp/qq.h 
    int test(int i)
    {
    printf("Hello!");
    return 0;
    }
    
    #define __mrs_s(v, r)                       \
        DEFINE_MRS_S                        \
    "   mrs_s " v ", " __stringify(r) "\n"          \
        UNDEFINE_MRS_S
    
    
    [root@localhost ~]# ctags --excmd=pattern -o - /tmp/qq.h 
    __mrs_s /tmp/qq.h   /^#define __mrs_s(/;"   d
    test    /tmp/qq.h   /^int test(int i)$/;"   f