0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

global-6.6.5.tar.gzのソースコードを読んでみる (1)

Last updated at Posted at 2020-10-13

GNU GLOBAL source code tagging system - gtagsは、ソースコードを読む際に役立つツールである。

なので、gtagsのソースコードをgtagsしながら読んでみる。。

ここからダウンロードできる。
https://www.gnu.org/software/global/download.html

ファイルを見てみる。。。


$ ls
acinclude.m4  compile       configure.ac  doc                FAQ      gtags             gtags.el   htags-refkit  libglibc   ltmain.sh     missing         reconf.sh
aclocal.m4    config.guess  convert.pl    DONORS             geco.rc  gtags.conf        gtags.pl   htags-server  libltdl    m4            NEWS            script
AUTHORS       config-h.in   COPYING       Doxyfile.in        global   gtags.conf.in     gtags.vim  INSTALL       libparser  mainpage.dox  plugin-factory  THANKS
BUILD_TOOLS   config.sub    COPYING.LIB   elvis-2.2_0.patch  globash  gtags-cscope      head.in    install-sh    libutil    Makefile.am   README          vim74-gtags-cscope.patch
ChangeLog     configure     depcomp       elvis.rc           gozilla  gtags-cscope.vim  htags      libdb         LICENSE    Makefile.in   README.PATCHES

gtagsしてみる。。


$  gtags

mainを探す。


$ global -t main
main    global/global.c 386
main    gozilla/gozilla.c       112
main    gtags-cscope/gtags-cscope.c     142
main    gtags/gtags.c   224
main    htags-refkit/htags_path2url.c   291
main    htags/htags.c   1071
main    libglibc/getopt.c       1152
main    libglibc/getopt1.c      107

global.cの関数を見てみる。。


$ global -f global.c
setcom            247 global.c         setcom(int c)
decide_tag_by_context  267 global.c         decide_tag_by_context(const char *tag, const char *file, int lineno)
NEXT_NUMBER       269 global.c         #define NEXT_NUMBER(p) do {                                                         \
main              386 global.c         main(int argc, char **argv)
completion_tags  1017 global.c         completion_tags(const char *dbpath, const char *root, const char *prefix, int db)
completion       1045 global.c         completion(const char *dbpath, const char *root, const char *prefix, int db)
completion_idutils 1094 global.c         completion_idutils(const char *dbpath, const char *root, const char *prefix)
completion_path  1192 global.c         completion_path(const char *dbpath, const char *prefix)
print_count      1276 global.c         print_count(int number)
idutils          1299 global.c         idutils(const char *pattern, const char *dbpath)
grep             1457 global.c         grep(const char *pattern, char *const *argv, const char *dbpath)
pathlist         1585 global.c         pathlist(const char *pattern, const char *dbpath)
parsefile_data   1684 global.c         struct parsefile_data {
put_syms         1693 global.c         put_syms(int type, const char *tag, int lno, const char *path, const char *line_image, void *arg)
parsefile        1743 global.c         parsefile(char *const *argv, const char *cwd, const char *root, const char *dbpath, int db)
search           1867 global.c         search(const char *pattern, const char *root, const char *cwd, const char *dbpath, int db)
tagsearch        1918 global.c         tagsearch(const char *pattern, const char *cwd, const char *root, const char *dbpath, int db)
encode           1994 global.c         encode(char *to, int size, const char *from)

main関数は、386行目から600行くらい。



   386main(int argc, char **argv)
   387{
   388        const char *av = NULL;
   389        int db;
   390        int optchar;
   391        int option_index = 0;
   392        int status = 0;
   393
   408        if (status == 0) {
   409                cwd = get_cwd();
   410                root = get_root();
   411                dbpath = get_dbpath();
   412        }

コマンドラインのオプション処理


   413        /*                                                                                                                                                                              
   414         * Open configuration file.                                                                                                                                                     
   415         */
   416        openconf(root);
   417        setenv_from_config();
   418        logging_arguments(argc, argv);
   419        while ((optchar = getopt_long(argc, argv, short_options, long_options, &option_index)) != EOF) {
   420                switch (optchar) {
   421                case 0:

$ gtags -v
のオプション設定はおそらくこの辺だらう


   526                case 'v':
   527                        vflag++;
   528                        setverbose();
   529                        break;

parseが始まるのは、985行目くらいだとおもわれる。。


   985        /*                                                                                                                                                                              
   986         * locate paths including the pattern.                                                                                                                                          
   987         */
   988        else if (Pflag) {
   989                chdir(root);
   990                pathlist(av, dbpath);
   991        }
   992        /*                                                                                                                                                                              
   993         * parse source files.                                                                                                                                                          
   994         */   995        else if (fflag) {
   996                chdir(root);
   997                parsefile(argv, cwd, root, dbpath, db);
   998        }
   999        /*                                                                                                                                                                              
  1000         * tag search.                                                                                                                                                                  
  1001         */
  1002        else {
  1003                tagsearch(av, cwd, root, dbpath, db);
  1004        }
  1005        return 0;
  1006}

(`ー´)b

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?