'프로그램 사용/ctags & cscope'에 해당되는 글 5건

  1. 2011.10.28 ctags 제약사항
  2. 2009.11.04 kscope 에서 특정 확장자 추가하기
  3. 2009.08.20 kscope 프로젝트 생성하기
  4. 2009.06.14 ctags format - CTAGS 출력 포맷/양식
  5. 2009.01.07 ctags
막상 ctags를 돌려보니 main()은 보이는데
그아래의 변수들이 보이지 않는 현상 발생 -_-
이게 무슨 신혼첫날밤에 발기부전 걸리는 소리야! 라는 생각에
검색을 해보니 공식적인 내용은 발견하지 못했지만 아래의 내용들 발견..

ctagas는 원래 로컬 변수들은 못다루는듯 -_-
확인겸 openCV 소스를 받아서 전체를 돌리고 vi에서 해보니
main(int argc, char** argv) 의 argv를 소스내에서 찾으니 엉뚱한 곳으로 날아간다.

I know CTags does not handle local vars, However, the code I said I will be happy to contribute uses also a lexer + written with flex language to analyze a current scope (small scope, the main parsing is done via CTags)

즉, ctags만으로는 지역변수나 전역변수가 사용된 곳, 함수가 사용된 곳은 찾기 힘들다. 이때는 cscope를 사용하면 된다.
[링크 : http://blog.naver.com/parkys1982/30014739315

12. How can I locate all references to a specific function or variable?

There are several packages already available which provide this capability. As of this writing, they are:
GLOBAL source code tag system
GNU id-utils
cscope
cflow
 
[링크 : http://ctags.sourceforge.net/faq.html#12

'프로그램 사용 > ctags & cscope' 카테고리의 다른 글

kscope 에서 특정 확장자 추가하기  (0) 2009.11.04
kscope 프로젝트 생성하기  (0) 2009.08.20
ctags format - CTAGS 출력 포맷/양식  (0) 2009.06.14
ctags  (0) 2009.01.07
Posted by 구차니

kscope 기본적으로 *.c와 *.h에 대한 검색을 사용합니다.


Project Properties를 보면 Filetype에 기본값으로는 *.c와 *.h만 있는데
개발시에 Makefile 등의 다른 파일도 추가해야 한다면
우측의 Available Types의 Editbox에 원하는 확장자를 입력하고 "<< Add"를 누르면 This Project에 추가가 됩니다.


추가 후 Add/Remove files 의 Filter에 추가된 확장자를 확인하실 수 있습니다.

'프로그램 사용 > ctags & cscope' 카테고리의 다른 글

ctags 제약사항  (0) 2011.10.28
kscope 프로젝트 생성하기  (0) 2009.08.20
ctags format - CTAGS 출력 포맷/양식  (0) 2009.06.14
ctags  (0) 2009.01.07
Posted by 구차니
kscope는 KDE용 cscope의 GUI 프로그램이다.
솔찍히 대충써봐서인지 자세히는 모르겠지만
결과적으로 source insight를 대체하기에는 너무나 부족한 감이 든다.
물론 추적기능이라던가, 여러가지 있지만, 자동추적 기능이 없기 때문에 공백이 크게 느껴지는 것 같다.

아래는 kscope의 Project 메뉴이다.


Create Project를 하면 아래와 같은 dialog 창이 뜬다.

위에는 프로젝트의 이름( = 프로젝트 디렉토리의 이름)을 넣고
아래에는 프로젝트 디렉토리가 저장될 경로를 넣는다.
colinux portable ubuntu / ubuntu 9.04 에서 해봤는데,
/home이 아닌 곳에서는 아래와 같은 에러가 나므로, 되도록이면 $HOME(사용자 디렉토리) 에 생성하도록 한다.


프로젝트를 생성후, 소스 트리에서 소스파일들을 추가해준다.
Add/Remove files에 들어가면 아래와 같은 Dialog창으 뜨게 되고,
Add 에서 Directory 등을 이용해 파일을 추가한다. (이 부분은 source insight와 거의 유사하다)


만약에 *.c *.h 외에 다른 확장자가 필요하다면,
초기 프로젝트 생성시에 File Types에서 추가를 해주거나
Project 메뉴의 Project Properties에서 추가를 해주면 된다.


'프로그램 사용 > ctags & cscope' 카테고리의 다른 글

ctags 제약사항  (0) 2011.10.28
kscope 에서 특정 확장자 추가하기  (0) 2009.11.04
ctags format - CTAGS 출력 포맷/양식  (0) 2009.06.14
ctags  (0) 2009.01.07
Posted by 구차니
6. Proposal
-----------

Use a comment after the {tagaddress} field.  The format would be:

    {tagname}<Tab>{tagfile}<Tab>{tagaddress}[;"<Tab>{tagfield}..]

   {tagname}    Any identifier, not containing white space..
   <Tab>    Exactly one TAB character (although many versions of Vi can handle any amount of white space).
   {tagfile}    The name of the file where {tagname} is defined, relative to the current directory
                   (or location of the tags file?).
   {tagaddress}    Any Ex command.  When executed, it behaves like 'magic' was not set.
                         It may be restricted to a line number or a search pattern (Posix).

Optionally:
   ;"        semicolon + doublequote: Ends the tagaddress in way that looks like the start of a comment to Vi.
   {tagfield}    See below.

A tagfield has a name, a colon, and a value: "name:value".
- The name consist only out of alphabetical characters.  Upper and lower case are allowed.
   Lower case is recommended.  Case matters ("kind:" and "Kind: are different tagfields).
- The value may be empty.
  It cannot contain a <Tab>.
  When a value contains a "\t", this stands for a <Tab>.
  When a value contains a "\r", this stands for a <CR>.
  When a value contains a "\n", this stands for a <NL>.
  When a value contains a "\\", this stands for a single '\' character.
  Other use of the backslash character is reserved for future expansion.
  Warning: When a tagfield value holds an MS-DOS file name, the backslashes must be doubled!

Proposed tagfield names:

FIELD-NAME    DESCRIPTION

arity        Number of arguments for a function tag.
class        Name of the class for which this tag is a member or method.
enum        Name of the enumeration in which this tag is an enumerator.
file        Static (local) tag, with a scope of the specified file.  When the value is empty, {tagfile} is used.
function    Function in which this tag is defined.  Useful for local variables (and functions).
               When functions nest (e.g., in Pascal), the function names are concatenated, separated with
                '/', so it looks like a path.
kind        Kind of tag.  The value depends on the language.  For C and
        C++ these kinds are recommended:
        c    class name
        d    define (from #define XXX)
        e    enumerator
        f    function or method name
        F    File name
        g    enumeration name
        m    member (of structure or class data)
        p    function prototype
        s    structure name
        t    typedef
        u    union name
        v    variable
        When this field is omitted, the kind of tag is undefined.
struct        Name of the struct in which this tag is a member.
union        Name of the union in which this tag is a member.

Note that these are mostly for C and C++.  When tags programs are written for
other languages, this list should be extended to include the used field names.
This will help users to be independent of the tags program used.

Examples:

    asdf    sub.cc    /^asdf()$/;"    new_field:some\svalue    file:
    foo_t    sub.h    /^typedef foo_t$/;"    kind:t
    func3    sub.p    /^func3()$/;"    function:/func1/func2    file:
    getflag    sub.c    /^getflag(arg)$/;"    kind:f    file:
    inc    sub.cc    /^inc()$/;"    file: class:PipeBuf


The name of the "kind:" field can be omitted.  This is to reduce the size of
the tags file by about 15%.  A program reading the tags file can recognize the
"kind:" field by the missing ':'.  Examples:

    foo_t    sub.h    /^typedef foo_t$/;"    t
    getflag    sub.c    /^getflag(arg)$/;"    f    file:


Additional remarks:
- When a tagfield appears twice in a tag line, only the last one is used.

Note about line separators:

Vi traditionally runs on Unix systems, where the line separator is a single
linefeed character <NL>.  On MS-DOS and compatible systems <CR><NL> is the
standard line separator.  To increase portability, this line separator is also
supported.

On the Macintosh a single <CR> is used for line separator.  Supporting this on
Unix systems causes problems, because most fgets() implementation don't see
the <CR> as a line separator.  Therefore the support for a <CR> as line
separator is limited to the Macintosh.

Summary:
line separator    generated on        accepted on
<LF>        Unix            Unix, MS-DOS, Macintosh
<CR>        Macintosh        Macintosh
<CR><LF>    MS-DOS            Unix, MS-DOS, Macintosh

The characters <CR> and <LF> cannot be used inside a tag line.  This is not
mentioned elsewhere (because it's obvious).

Note about white space:

Vi allowed any white space to separate the tagname from the tagfile, and the
filename from the tagaddress.  This would need to be allowed for backwards
compatibility.  However, all known programs that generate tags use a single
<Tab> to separate fields.

There is a problem for using file names with embedded white space in the
tagfile field.  To work around this, the same special characters could be used
as in the new fields, for example "\s".  But, unfortunately, in MS-DOS the
backslash character is used to separate file names.  The file name
"c:\vim\sap" contains "\s", but this is not a <Space>.  The number of
backslashes could be doubled, but that will add a lot of characters, and make
parsing the tags file slower and clumsy.

To avoid these problems, we will only allow a <Tab> to separate fields, and
not support a file name or tagname that contains a <Tab> character.  This
means that we are not 100% Vi compatible.  However, there is no known tags
program that uses something else than a <Tab> to separate the fields.  Only
when a user typed the tags file himself, or made his own program to generate a
tags file, we could run into problems.  To solve this, the tags file should be
filtered, to replace the arbitrary white space with a single <Tab>.  This Vi
command can be used:

    :%s/^\([^ ^I]*\)[ ^I]*\([^ ^I]*\)[ ^I]*/\1^I\2^I/

(replace ^I with a real <Tab>).

TAG FILE INFORMATION:

Psuedo-tag lines can be used to encode information into the tag file regarding
details about its content (e.g. have the tags been sorted?, are the optional
tagfields present?), and regarding the program used to generate the tag file.
This information can be used both to optimize use of the tag file (e.g.
enable/disable binary searching) and provide general information (what version
of the generator was used).

The names of the tags used in these lines may be suitably chosen to ensure
that when sorted, they will always be located near the first lines of the tag
file.  The use of "!_TAG_" is recommended.  Note that a rare tag like "!"
can sort to before these lines.  The program reading the tags file should be
smart enough to skip over these tags.

The lines described below have been chosen to convey a select set of
information.

Tag lines providing information about the content of the tag file:

!_TAG_FILE_FORMAT    {version-number}    /optional comment/
!_TAG_FILE_SORTED    {0|1}            /0=unsorted, 1=sorted/

The {version-number} used in the tag file format line reserves the value of
"1" for tag files complying with the original UNIX vi/ctags format, and
reserves the value "2" for tag files complying with this proposal. This value
may be used to determine if the extended features described in this proposal
are present.

Tag lines providing information about the program used to generate the tag
file, and provided solely for documentation purposes:

!_TAG_PROGRAM_AUTHOR    {author-name}    /{email-address}/
!_TAG_PROGRAM_NAME    {program-name}    /optional comment/
!_TAG_PROGRAM_URL    {URL}    /optional comment/
!_TAG_PROGRAM_VERSION    {version-id}    /optional comment/

[링크 : http://ctags.sourceforge.net/FORMAT]



별다른 옵션을 주지 않고
 ctags [filename]
으로 실행하면 tags 라는 파일이 생성됨

$more test.c
#include <stdio.h>
#define VERSION 1.00

typedef struct _point_
{
    int x;
    int y;
} POINT;

void main()
{
    int a;
    char str[] = "Hello world";
    POINT pt;
   
    printf("%s\n",str);
}

$ more tags
!_TAG_FILE_FORMAT    2    /extended format; --format=1 will not append ;" to lines/
!_TAG_FILE_SORTED    1    /0=unsorted, 1=sorted, 2=foldcase/
!_TAG_PROGRAM_AUTHOR    Darren Hiebert    /dhiebert@users.sourceforge.net/
!_TAG_PROGRAM_NAME    Exuberant Ctags    //
!_TAG_PROGRAM_URL    http://ctags.sourceforge.net    /official site/
!_TAG_PROGRAM_VERSION    5.4    //
POINT    test.c    /^} POINT;$/;"    t    file:
VERSION    test.c    2;"    d    file:
_point_    test.c    /^typedef struct _point_$/;"    s    file:
main    test.c    /^void main()$/;"    f
x    test.c    /^    int x;$/;"    m    struct:_point_    file:
y    test.c    /^   
int y;$/;"    m    struct:_point_    file:

{tagname}<Tab>{tagfile}<Tab>{tagaddress}[;"<Tab>{tagfield}..] 가 기본 포맷인데
POINT    test.c    /^} POINT;$/;"    t    file: 를 보면

tagname - POINT
tagfile - test.c
tagaddress - /^} POINT;$/
tagfield - t
tagfield - file:

라는 의미를 지니게 된다. 아래의 POINT 구조체의 x, y 변수는 m(member)로 표기된다.

'프로그램 사용 > ctags & cscope' 카테고리의 다른 글

ctags 제약사항  (0) 2011.10.28
kscope 에서 특정 확장자 추가하기  (0) 2009.11.04
kscope 프로젝트 생성하기  (0) 2009.08.20
ctags  (0) 2009.01.07
Posted by 구차니
ctags는 말 그대로 c 언어 파일의 keyword, identifier를 출력해 주는 툴이다.

 ctags -R
을 실행하면 tags라는 파일이 생성이 된다.

source code [test.c]

command [ctags test.c]
file [tags]
!_TAG_FILE_FORMAT    2    /extended format; --format=1 will not append ;" to lines/
!_TAG_FILE_SORTED    1    /0=unsorted, 1=sorted, 2=foldcase/
!_TAG_PROGRAM_AUTHOR    Darren Hiebert    /dhiebert@users.sourceforge.net/
!_TAG_PROGRAM_NAME    Exuberant Ctags    //
!_TAG_PROGRAM_URL    http://ctags.sourceforge.net    /official site/
!_TAG_PROGRAM_VERSION    5.4    //
CHARLEY    test.c    /^    CHARLEY,$/;"    e    file:
FALSE    test.c    /^    FALSE$/;"    e    file:
LINDA    test.c    /^    LINDA$/;"    e    file:
TOM    test.c    /^    TOM,$/;"    e    file:
TRUE    test.c    /^    TRUE,$/;"    e    file:
WIN32_VERSION    test.c    3;"    d    file:
boolean    test.c    /^} boolean;$/;"    t    file:
main    test.c    /^int main(int argc,char argv**)$/;"    f
test_int    test.c    /^int test_int;$/;"    v
test_int_static    test.c    /^static int test_int_static;$/;"    v    file:

command [ctags -n -u test.c]
file [tags]
!_TAG_FILE_FORMAT    2    /extended format; --format=1 will not append ;" to lines/
!_TAG_FILE_SORTED    0    /0=unsorted, 1=sorted, 2=foldcase/
!_TAG_PROGRAM_AUTHOR    Darren Hiebert    /dhiebert@users.sourceforge.net/
!_TAG_PROGRAM_NAME    Exuberant Ctags    //
!_TAG_PROGRAM_URL    http://ctags.sourceforge.net    /official site/
!_TAG_PROGRAM_VERSION    5.4    //
WIN32_VERSION    test.c    3;"    d    file:
test_int_static    test.c    5;"    v    file:
test_int    test.c    6;"    v
TRUE    test.c    10;"    e    file:
FALSE    test.c    11;"    e    file:
boolean    test.c    12;"    t    file:
TOM    test.c    16;"    e    file:
CHARLEY    test.c    17;"    e    file:
LINDA    test.c    18;"    e    file:
main    test.c    21;"    f

Wikipedia의 ctags file format 에 관련된 내용

ctags의 옵션(도움말)

---
2011.10.28 추가

ctags 지원 언어
 
Posted by 구차니