我正在尝试使用带有VIM的ctags,而且我是两者的新手。为了测试ctags有用的程度,我决定通过一个非常简单的测试,即解析/ usr / include中的头文件,以便我可以自动完成一些非常基本的函数。
当我运行命令
时 ctags --c++-kinds=+p --fields=+iaS -f ~/.tags/tags /usr/include/*.h
然后输出打印
BUFSIZ /usr/include/stdio.h 108;" d EOF /usr/include/stdio.h 115;" d FILE /usr/include/stdio.h /^typedef struct _IO_FILE FILE;$/;" t typeref:struct:_IO_FILE FSETLOCKING_BYCALLER /usr/include/stdio_ext.h /^ FSETLOCKING_BYCALLER$/;" e enum:__anon122 FSETLOCKING_BYCALLER /usr/include/stdio_ext.h 39;" d FSETLOCKING_INTERNAL /usr/include/stdio_ext.h /^ FSETLOCKING_INTERNAL,$/;" e enum:__anon122 FSETLOCKING_INTERNAL /usr/include/stdio_ext.h 36;" d FSETLOCKING_QUERY /usr/include/stdio_ext.h /^ FSETLOCKING_QUERY = 0,$/;" e enum:__anon122 FSETLOCKING_QUERY /usr/include/stdio_ext.h 32;" d P_tmpdir /usr/include/stdio.h 128;" d SEEK_CUR /usr/include/stdio.h 122;" d SEEK_END /usr/include/stdio.h 123;" d SEEK_SET /usr/include/stdio.h 121;" d _IOFBF /usr/include/stdio.h 101;" d _IOLBF /usr/include/stdio.h 102;" d _IONBF /usr/include/stdio.h 103;" d _IO_STDIO /usr/include/libio.h 165;" d _IO_STDIO_H /usr/include/libio.h 30;" d _OLD_STDIO_MAGIC /usr/include/libio.h 121;" d _STDIO_EXT_H /usr/include/stdio_ext.h 24;" d _STDIO_H /usr/include/stdio.h 27;" d _STDIO_USES_IOSTREAM /usr/include/stdio.h 73;" d _VA_LIST_DEFINED /usr/include/stdio.h 81;" d __FILE /usr/include/stdio.h /^typedef struct _IO_FILE __FILE;$/;" t typeref:struct:_IO_FILE __FILE_defined /usr/include/stdio.h 57;" d ____FILE_defined /usr/include/stdio.h 67;" d __need_FILE /usr/include/stdio.h 37;" d __need_FILE /usr/include/stdio.h 59;" d __need_NULL /usr/include/stdio.h 33;" d __need___FILE /usr/include/stdio.h 38;" d __need___FILE /usr/include/stdio.h 69;" d __need_getopt /usr/include/stdio.h 902;" d __need_size_t /usr/include/stdio.h 32;" d __wur /usr/include/stdio.h /^ _IO_cookie_io_functions_t __io_funcs) __THROW __wur;$/;" v __wur /usr/include/stdio.h /^ __THROW __attribute__ ((__format__ (__printf__, 2, 0))) __wur;$/;" v __wur /usr/include/stdio.h /^ __THROW __attribute__ ((__format__ (__printf__, 2, 3))) __wur;$/;" v __wur /usr/include/stdio.h /^ __THROW __attribute_malloc__ __wur;$/;" v __wur /usr/include/stdio.h /^ __THROW __wur;$/;" v __wur /usr/include/stdio.h /^extern FILE *fdopen (int __fd, __const char *__modes) __THROW __wur;$/;" v __wur /usr/include/stdio.h /^extern FILE *open_memstream (char **__bufloc, size_t *__sizeloc) __THROW __wur;$/;" v __wur /usr/include/stdio.h /^extern char *tmpnam (char *__s) __THROW __wur;$/;" v __wur /usr/include/stdio.h /^extern char *tmpnam_r (char *__s) __THROW __wur;$/;" v __wur /usr/include/stdio.h /^extern int feof (FILE *__stream) __THROW __wur;$/;" v __wur /usr/include/stdio.h /^extern int feof_unlocked (FILE *__stream) __THROW __wur;$/;" v __wur /usr/include/stdio.h /^extern int ferror (FILE *__stream) __THROW __wur;$/;" v __wur /usr/include/stdio.h /^extern int ferror_unlocked (FILE *__stream) __THROW __wur;$/;" v __wur /usr/include/stdio.h /^extern int fileno (FILE *__stream) __THROW __wur;$/;" v __wur /usr/include/stdio.h /^extern int fileno_unlocked (FILE *__stream) __THROW __wur;$/;" v __wur /usr/include/stdio.h /^extern int ftrylockfile (FILE *__stream) __THROW __wur;$/;" v _flushlbf /usr/include/stdio_ext.h /^extern void _flushlbf (void);$/;" p signature:(void) cuserid /usr/include/stdio.h /^extern char *cuserid (char *__s);$/;" p signature:(char *__s) dprintf /usr/include/stdio.h /^extern int dprintf (int __fd, __const char *__restrict __fmt, ...)$/;" p signature:(int __fd, __const char *__restrict __fmt, ...) fclose /usr/include/stdio.h /^extern int fclose (FILE *__stream);$/;" p signature:(FILE *__stream) fcloseall /usr/include/stdio.h /^extern int fcloseall (void);$/;" p signature:(void) fflush /usr/include/stdio.h /^extern int fflush (FILE *__stream);$/;" p signature:(FILE *__stream) fflush_unlocked /usr/include/stdio.h /^extern int fflush_unlocked (FILE *__stream);$/;" p signature:(FILE *__stream) fgetc /usr/include/stdio.h /^extern int fgetc (FILE *__stream);$/;" p signature:(FILE *__stream) fgetc_unlocked /usr/include/stdio.h /^extern int fgetc_unlocked (FILE *__stream);$/;" p signature:(FILE *__stream) fgetpos /usr/include/stdio.h /^extern int fgetpos (FILE *__restrict __stream, fpos_t *__restrict __pos);$/;" p signature:(FILE *__restrict __stream, fpos_t *__restrict __pos) fgetpos64 /usr/include/stdio.h /^extern int fgetpos64 (FILE *__restrict __stream, fpos64_t *__restrict __pos);$/;" p signature:(FILE *__restrict __stream, fpos64_t *__restrict __pos) fpos64_t /usr/include/stdio.h /^typedef _G_fpos64_t fpos64_t;$/;" t fpos_t /usr/include/stdio.h /^typedef _G_fpos_t fpos_t;$/;" t fprintf /usr/include/stdio.h /^extern int fprintf (FILE *__restrict __stream,$/;" p signature:(FILE *__restrict __stream, __const char *__restrict __format, ...) fputc /usr/include/stdio.h /^extern int fputc (int __c, FILE *__stream);$/;" p signature:(int __c, FILE *__stream) fputc_unlocked /usr/include/stdio.h /^extern int fputc_unlocked (int __c, FILE *__stream);$/;" p signature:(int __c, FILE *__stream) fputs /usr/include/stdio.h /^extern int fputs (__const char *__restrict __s, FILE *__restrict __stream);$/;" p signature:(__const char *__restrict __s, FILE *__restrict __stream) fputs_unlocked /usr/include/stdio.h /^extern int fputs_unlocked (__const char *__restrict __s,$/;" p signature:(__const char *__restrict __s, FILE *__restrict __stream) fscanf /usr/include/stdio.h 441;" d fseek /usr/include/stdio.h /^extern int fseek (FILE *__stream, long int __off, int __whence);$/;" p signature:(FILE *__stream, long int __off, int __whence) fseeko /usr/include/stdio.h /^extern int fseeko (FILE *__stream, __off_t __off, int __whence);$/;" p signature:(FILE *__stream, __off_t __off, int __whence) fseeko64 /usr/include/stdio.h /^extern int fseeko64 (FILE *__stream, __off64_t __off, int __whence);$/;" p signature:(FILE *__stream, __off64_t __off, int __whence) fsetpos /usr/include/stdio.h /^extern int fsetpos (FILE *__stream, __const fpos_t *__pos);$/;" p signature:(FILE *__stream, __const fpos_t *__pos) fsetpos64 /usr/include/stdio.h /^extern int fsetpos64 (FILE *__stream, __const fpos64_t *__pos);$/;" p signature:(FILE *__stream, __const fpos64_t *__pos) getc /usr/include/stdio.h /^extern int getc (FILE *__stream);$/;" p signature:(FILE *__stream) getc /usr/include/stdio.h 527;" d getc_unlocked /usr/include/stdio.h /^extern int getc_unlocked (FILE *__stream);$/;" p signature:(FILE *__stream) getchar /usr/include/stdio.h /^extern int getchar (void);$/;" p signature:(void) getchar_unlocked /usr/include/stdio.h /^extern int getchar_unlocked (void);$/;" p signature:(void) getw /usr/include/stdio.h /^extern int getw (FILE *__stream);$/;" p signature:(FILE *__stream) jpeg_stdio_dest /usr/include/jpeglib.h /^EXTERN(void) jpeg_stdio_dest JPP((j_compress_ptr cinfo, FILE * outfile));$/;" p signature:(j_compress_ptr cinfo, FILE * outfile) jpeg_stdio_dest /usr/include/jpeglib.h 841;" d jpeg_stdio_src /usr/include/jpeglib.h /^EXTERN(void) jpeg_stdio_src JPP((j_decompress_ptr cinfo, FILE * infile));$/;" p signature:(j_decompress_ptr cinfo, FILE * infile) jpeg_stdio_src /usr/include/jpeglib.h 842;" d pclose /usr/include/stdio.h /^extern int pclose (FILE *__stream);$/;" p signature:(FILE *__stream) perror /usr/include/stdio.h /^extern void perror (__const char *__s);$/;" p signature:(__const char *__s) printf /usr/include/stdio.h /^extern int printf (__const char *__restrict __format, ...);$/;" p signature:(__const char *__restrict __format, ...) putc /usr/include/stdio.h /^extern int putc (int __c, FILE *__stream);$/;" p signature:(int __c, FILE *__stream) putc /usr/include/stdio.h 569;" d putc_unlocked /usr/include/stdio.h /^extern int putc_unlocked (int __c, FILE *__stream);$/;" p signature:(int __c, FILE *__stream) putchar /usr/include/stdio.h /^extern int putchar (int __c);$/;" p signature:(int __c) putchar_unlocked /usr/include/stdio.h /^extern int putchar_unlocked (int __c);$/;" p signature:(int __c) puts /usr/include/stdio.h /^extern int puts (__const char *__s);$/;" p signature:(__const char *__s) putw /usr/include/stdio.h /^extern int putw (int __w, FILE *__stream);$/;" p signature:(int __w, FILE *__stream) rewind /usr/include/stdio.h /^extern void rewind (FILE *__stream);$/;" p signature:(FILE *__stream) scanf /usr/include/stdio.h 442;" d sscanf /usr/include/stdio.h 443;" d stderr /usr/include/stdio.h 152;" d stdin /usr/include/stdio.h 150;" d stdout /usr/include/stdio.h 151;" d ungetc /usr/include/stdio.h /^extern int ungetc (int __c, FILE *__stream);$/;" p signature:(int __c, FILE *__stream) va_list /usr/include/stdio.h /^typedef _G_va_list va_list;$/;" t vdprintf /usr/include/stdio.h /^extern int vdprintf (int __fd, __const char *__restrict __fmt,$/;" p signature:(int __fd, __const char *__restrict __fmt, _G_va_list __arg) vfprintf /usr/include/stdio.h /^extern int vfprintf (FILE *__restrict __s, __const char *__restrict __format,$/;" p signature:(FILE *__restrict __s, __const char *__restrict __format, _G_va_list __arg) vfscanf /usr/include/stdio.h 500;" d vprintf /usr/include/stdio.h /^extern int vprintf (__const char *__restrict __format, _G_va_list __arg);$/;" p signature:(__const char *__restrict __format, _G_va_list __arg) vscanf /usr/include/stdio.h 501;" d vsscanf /usr/include/stdio.h 502;" d很明显,ctags错过了一些非常明显的函数,比如fopen,但它包含了像fclose这样的函数。当我使用ctags解析时,是否有一些我缺少的选项?
答案 0 :(得分:5)
只是一些提示,以便您可以获得更具体的标签文件:
# First make sure apt-file is install and then do:
$ sudo apt-file update
# set up tags for libc, the standard C library
$ apt-file list libc6-dev | grep -o '/usr/include/.*\.h'> ~/.vim/tags/libc6-filelist
$ ctags --sort=foldcase --c++-kinds=+p --fields=+iaS --extra=+q -I./libc6-ignore -f ~/.vim/tags/libc6 -L ~/.vim/tags/libc6-filelist
文件libc6-ignore的内容是:
__attribute__
__attribute_deprecated__
__attribute_format_arg__
__attribute_format_strfmon__
__attribute_malloc__
__attribute_noinline__
__attribute_pure__
__attribute_used__
__attribute_warn_unused_result__
__wur
__THROW
__nonnull+
我假设您正在使用vim和OmniCppComplete插件吗?
答案 1 :(得分:4)
在您的ctags命令中添加-I__wur
,您将获得您所追求的结果。
__wur
是__attribute__ ((__warn_unused_result__))
有关更详尽的解释,请参阅:
http://sourceforge.net/mailarchive/message.php?msg_name=48A7FF60.9080609%40sina.com
答案 2 :(得分:2)
更多提示,HTH。
<强> 1 即可。在Ubuntu机器下,可以运行dpkg -L libc6-dev |grep -o '/usr/include/.*h' > ~/.vim/tags/libc6-dev_files
来获取GNU C库中的头文件。
<强> 2 即可。使用以下命令生成更具体的ctags文件。
如果需要,#mkdir
。
cd ~/.vim/tags
#使用grep
获取更多令牌。
grep -oe '__attribute\w*__' libc6-dev_tags |sort -u > libc6-dev_ignore-tokens
echo __THROW >> libc6-dev_ignore-tokens
echo __wur >> libc6-dev_ignore-tokens
#生成ctags文件。有关详细信息,请参阅ctags手册页。
ctags --c++-kinds=+px --fields=+iaS --extra=+q -I @./libc6-dev_ignore-tokens -L libc6-dev_files -f libc6-dev_tags
第3 即可。将此标记文件添加到您的初始标记路径,即将set tags+=~/.vim/tags/libc6-dev_tags
放在.vimrc文件中的某个位置。
答案 3 :(得分:0)
同样的问题。已使用-I选项解决。查看此站点以获取信息: http://ctags.sourceforge.net/ctags.html#OPTIONS
注意几个“陷阱”。首先,当使用包含忽略列表的文件指定-I时,需要立即跟随@或a。或者一个驱动器号(如果在窗口中)。我花了几个小时使用-I~ /没有成功。同样的事情-I / home / username /就像魅力一样。
其次,确保使用多行解析(--fields = + S)。这已经被指示为OP在此线程中使用的选项,但是想再次指出它。
感谢其他人提供的精彩提示!