2009-10-27 12 views
6

Estoy tratando de usar ctags con VIM, y soy un novato en ambos. Para probar el grado en que los ctags podrían ser útiles, decidí pasar por una prueba muy simple, concretamente analizar los encabezados en/usr/include para poder completar automáticamente algunas funciones muy básicas.ctags no analiza correctamente stdio.h

Cuando ejecuto el comando

ctags --c++-kinds=+p --fields=+iaS -f ~/.tags/tags /usr/include/*.h 

entonces las impresiones de salida

 
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 

tan claramente CTags perdido algunas funciones muy obvias como fopen, sin embargo, que incluía funciones como fclose. ¿Hay alguna opción que me falta cuando estoy analizando ctags?

Respuesta

5

sólo algunos consejos para que pueda obtener un archivo de etiquetas más específicas:

# 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 

El el contenido del archivo libc6-ignore es:

__attribute__ 
__attribute_deprecated__ 
__attribute_format_arg__ 
__attribute_format_strfmon__ 
__attribute_malloc__ 
__attribute_noinline__ 
__attribute_pure__ 
__attribute_used__ 
__attribute_warn_unused_result__ 
__wur 
__THROW 
__nonnull+ 

Supongo que está utilizando esto con vim y el complemento OmniCppComplete?

2

Solo más consejos, HTH.

. En Ubuntu máquina, uno puede ejecutar dpkg -L libc6-dev |grep -o '/usr/include/.*h' > ~/.vim/tags/libc6-dev_files para obtener encabezados en GNU C Library.

. Use los comandos a continuación para generar un archivo ctags más específico.

# mkdir si es necesario.

cd ~/.vim/tags 

# Obtener más fichas ignorarse usando 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 

# Generar archivo ctags. Consulte la página del manual de ctags para más detalles.

ctags --c++-kinds=+px --fields=+iaS --extra=+q -I @./libc6-dev_ignore-tokens -L libc6-dev_files -f libc6-dev_tags 

. Agregue este archivo de etiquetas a su ruta de etiquetas inicial, es decir, ponga set tags+=~/.vim/tags/libc6-dev_tags en algún lugar de su archivo .vimrc.

0

Mismo problema. Resuelto con la opción -I. Marque este sitio para obtener información: http://ctags.sourceforge.net/ctags.html#OPTIONS

Tenga en cuenta un par de "gotcha's". Primero, cuando se especifica -I con un archivo que contiene la lista de ignorar, se debe seguir inmediatamente con un @ o a. o una letra de unidad (si está en Windows). Pasé horas usando -I ~/sin éxito. Lo mismo con -I/home/username/funcionó como un amuleto.

En segundo lugar, asegúrese de utilizar el análisis multilínea (--fields = + S). Esto ya está indicado como una opción utilizada por el OP en este hilo, pero quería señalarlo nuevamente.

¡Gracias a todos por los consejos geniales!

Cuestiones relacionadas