91 |
* GLOBAL-4.5.1 - support format version 1, 2 and 3. |
* GLOBAL-4.5.1 - support format version 1, 2 and 3. |
92 |
* if (format version > 3) then print error message. |
* if (format version > 3) then print error message. |
93 |
* format version 1 (default): |
* format version 1 (default): |
94 |
* original format. |
* Standard format |
95 |
* format version 2 (gtags -c): |
* format version 2 (gtags -c): |
96 |
* compact format + pathindex format |
* Compact format + Pathindex option |
97 |
* format version 3 (gtags -cc): |
* format version 3 (gtags -cc): |
98 |
* only pathindex format (undocumented) |
* Compact format without Pathindex option (undocumented) |
99 |
* |
* |
100 |
* About GTAGS and GRTAGS, the default format is still version 1. |
* About GTAGS and GRTAGS, the default format is still version 1. |
101 |
* Since if version number is not found then it assumes version 1, we |
* Since if version number is not found then it assumes version 1, we |
114 |
* 203|main(int argc, char **argv) |
* 203|main(int argc, char **argv) |
115 |
* |{ |
* |{ |
116 |
* |
* |
117 |
* (Standard format) |
* Standard format (e.g. GTAGS by gtags) |
118 |
* |
* |
119 |
* 0 1 2 3 |
* 0 1 2 3 |
120 |
* ------------------------------------------------------------------ |
* ------------------------------------------------------------------ |
121 |
* main 203 ./gtags/gtags.c main(int argc, char **argv) |
* main 203 ./gtags/gtags.c main(int argc, char **argv) |
122 |
* |
* |
123 |
* (Pathindex format) |
* Standard format + Pathindex option (e.g. GTAGS by gtags -cc) |
124 |
* 0 1 2 3 |
* 0 1 2 3 |
125 |
|
* ------------------------------------------------------------------ |
126 |
|
* main 203 22 main(int argc, char **argv) |
127 |
|
* |
128 |
|
* Compact format (e.g. GSYMS by gtags) |
129 |
|
* |
130 |
|
* 0 1 2 |
131 |
* ---------------------------------------------------- |
* ---------------------------------------------------- |
132 |
* main 203 22 main(int argc, char **argv) |
* main ./gtags/gtags.c 203 |
133 |
* |
* |
134 |
* (Compact format) |
* Compact format + Pathindex option (e.g. GTAGS by gtags -c) |
135 |
* |
* |
136 |
* 0 1 2 |
* 0 1 2 |
137 |
* ---------------------------------------------------- |
* ---------------------------------------------------- |
138 |
* main 22 203 |
* main 22 203 |
139 |
|
* |
140 |
|
* [Correspondence of gtags option and format] |
141 |
|
* |
142 |
|
* | gtags option |
143 |
|
* tagfile | (none) | -cc | -c |
144 |
|
* --------+-----------+----------------------+------------------- |
145 |
|
* GTAGS | STANDARD | STANDARD + PATHINDEX | COMPACT + PATHINDEX |
146 |
|
* --------+-----------+----------------------+------------------- |
147 |
|
* GRTAGS | STANDARD | STANDARD + PATHINDEX | COMPACT + PATHINDEX |
148 |
|
* --------+-----------+----------------------+------------------- |
149 |
|
* GSYMS | COMPACT | COMPACT + PATHINDEX | COMPACT + PATHINDEX |
150 |
|
* |
151 |
*/ |
*/ |
152 |
static int support_version = 3; /* acceptable format version */ |
static int support_version = 3; /* acceptable format version */ |
153 |
static const char *tagslist[] = {"GPATH", "GTAGS", "GRTAGS", "GSYMS"}; |
static const char *tagslist[] = {"GPATH", "GTAGS", "GRTAGS", "GSYMS"}; |
640 |
void |
void |
641 |
gtags_delete(GTOP *gtop, IDSET *deleteset) |
gtags_delete(GTOP *gtop, IDSET *deleteset) |
642 |
{ |
{ |
643 |
const char *tagline, *s_fid; |
const char *tagline, *path, *s_fid; |
644 |
SPLIT ptable; |
SPLIT ptable; |
645 |
int fid; |
int fid; |
646 |
|
|
647 |
for (tagline = dbop_first(gtop->dbop, NULL, NULL, 0); tagline; tagline = dbop_next(gtop->dbop)) { |
for (tagline = dbop_first(gtop->dbop, NULL, NULL, 0); tagline; tagline = dbop_next(gtop->dbop)) { |
648 |
/* |
/* |
649 |
* Extract fid from the tag line. |
* Extract path from the tag line. |
650 |
*/ |
*/ |
651 |
split((char *)tagline, 4, &ptable); |
split((char *)tagline, 4, &ptable); |
652 |
if (gtop->format == GTAGS_STANDARD) { |
if (gtop->format & GTAGS_COMPACT) { |
653 |
if (ptable.npart < 4) { |
if (ptable.npart != 3) { |
654 |
recover(&ptable); |
recover(&ptable); |
655 |
die("too small number of parts.\n'%s'", tagline); |
die("too small number of parts in compact format.\n'%s'", tagline); |
656 |
} |
} |
657 |
s_fid = gpath_path2fid(ptable.part[PART_PATH].start); |
path = ptable.part[PART_PATH_COMP].start; |
658 |
if (s_fid == NULL) |
} else { /* Standard format */ |
|
die("GPATH is corrupted."); |
|
|
} |
|
|
else if (gtop->format == GTAGS_PATHINDEX) { |
|
659 |
if (ptable.npart < 4) { |
if (ptable.npart < 4) { |
660 |
recover(&ptable); |
recover(&ptable); |
661 |
die("too small number of parts in pathindex format.\n'%s'", tagline); |
die("too small number of parts in standard format.\n'%s'", tagline); |
|
} |
|
|
s_fid = ptable.part[PART_FID_PIDX].start; |
|
|
} else { /* gtop->format & GTAGS_COMPACT */ |
|
|
if (ptable.npart != 3) { |
|
|
recover(&ptable); |
|
|
die("too small number of parts in compact format.\n'%s'", tagline); |
|
662 |
} |
} |
663 |
s_fid = ptable.part[PART_FID_COMP].start; |
path = ptable.part[PART_PATH].start; |
664 |
|
} |
665 |
|
/* |
666 |
|
* Convert the path into file id. |
667 |
|
*/ |
668 |
|
if (gtop->format & GTAGS_PATHINDEX) |
669 |
|
s_fid = path; /* Nothing to do. */ |
670 |
|
else { |
671 |
|
s_fid = gpath_path2fid(path); |
672 |
|
if (s_fid == NULL) |
673 |
|
die("GPATH is corrupted."); |
674 |
} |
} |
675 |
fid = atoi(s_fid); |
fid = atoi(s_fid); |
676 |
recover(&ptable); |
recover(&ptable); |
754 |
} |
} |
755 |
tagline = dbop_first(gtop->dbop, key, preg, dbflags); |
tagline = dbop_first(gtop->dbop, key, preg, dbflags); |
756 |
if (tagline) { |
if (tagline) { |
757 |
|
/* |
758 |
|
* Standard format (or only key) |
759 |
|
*/ |
760 |
if (gtop->format == GTAGS_STANDARD || gtop->flags & GTOP_KEY) |
if (gtop->format == GTAGS_STANDARD || gtop->flags & GTOP_KEY) |
761 |
return tagline; |
return tagline; |
762 |
|
/* |
763 |
|
* Standard format + Pathindex option. |
764 |
|
*/ |
765 |
else if (gtop->format == GTAGS_PATHINDEX) |
else if (gtop->format == GTAGS_PATHINDEX) |
766 |
return unpack_pathindex(tagline); |
return unpack_pathindex(tagline); |
767 |
else { /* Compact format */ |
/* |
768 |
|
* Compact format |
769 |
|
*/ |
770 |
|
else { |
771 |
gtop->line = (char *)tagline; |
gtop->line = (char *)tagline; |
772 |
gtop->opened = 0; |
gtop->opened = 0; |
773 |
return genrecord(gtop); |
return genrecord(gtop); |
787 |
{ |
{ |
788 |
const char *tagline; |
const char *tagline; |
789 |
/* |
/* |
790 |
* If it is standard format or only key. |
* Standard format (or only key) |
|
* Just return it. |
|
791 |
*/ |
*/ |
792 |
if (gtop->format == GTAGS_STANDARD || gtop->flags & GTOP_KEY) { |
if (gtop->format == GTAGS_STANDARD || gtop->flags & GTOP_KEY) { |
793 |
return dbop_next(gtop->dbop); |
return dbop_next(gtop->dbop); |
794 |
} |
} |
795 |
/* |
/* |
796 |
* Pathindex format. |
* Standard format + Pathindex option. |
797 |
*/ |
*/ |
798 |
else if (gtop->format == GTAGS_PATHINDEX) { |
else if (gtop->format == GTAGS_PATHINDEX) { |
799 |
tagline = dbop_next(gtop->dbop); |
tagline = dbop_next(gtop->dbop); |
800 |
return (tagline == NULL) ? NULL : unpack_pathindex(tagline); |
return (tagline == NULL) ? NULL : unpack_pathindex(tagline); |
801 |
} |
} |
802 |
/* |
/* |
803 |
* gtop->format & GTAGS_COMPACT |
* Compact format |
804 |
*/ |
*/ |
805 |
else { |
else { |
806 |
const char *ctags_x; |
const char *ctags_x; |
843 |
/* |
/* |
844 |
* unpack_pathindex: convert pathindex format into standard format. |
* unpack_pathindex: convert pathindex format into standard format. |
845 |
* |
* |
846 |
* i) tagline tag line (pathindex format) |
* i) tagline tag line (Standard format + pathindex option) |
847 |
*/ |
*/ |
848 |
static const char * |
static const char * |
849 |
unpack_pathindex(const char *tagline) /* virtually const */ |
unpack_pathindex(const char *tagline) /* virtually const */ |
860 |
/* |
/* |
861 |
* extract file id and convert into path name. |
* extract file id and convert into path name. |
862 |
*/ |
*/ |
863 |
path = gpath_fid2path(ptable.part[PART_FID_PIDX].start); |
path = gpath_fid2path(ptable.part[PART_PATH].start); |
864 |
if (path == NULL) |
if (path == NULL) |
865 |
die("GPATH is corrupted.(fid '%s' not found)", ptable.part[PART_FID_PIDX].start); |
die("GPATH is corrupted.(fid '%s' not found)", ptable.part[PART_PATH].start); |
866 |
recover(&ptable); |
recover(&ptable); |
867 |
/* |
/* |
868 |
* copy line with converting fid into path name. |
* copy line with converting fid into path name. |
869 |
*/ |
*/ |
870 |
strbuf_clear(output); |
strbuf_clear(output); |
871 |
strbuf_nputs(output, tagline, ptable.part[PART_FID_PIDX].start - tagline); |
strbuf_nputs(output, tagline, ptable.part[PART_PATH].start - tagline); |
872 |
strbuf_puts(output, path); |
strbuf_puts(output, path); |
873 |
strbuf_puts(output, ptable.part[PART_FID_PIDX].end); |
strbuf_puts(output, ptable.part[PART_PATH].end); |
874 |
|
|
875 |
return strbuf_value(output); |
return strbuf_value(output); |
876 |
} |
} |
890 |
const char *fid, *path; |
const char *fid, *path; |
891 |
|
|
892 |
gtop->opened = 1; |
gtop->opened = 1; |
893 |
|
/* |
894 |
|
* Compact format |
895 |
|
*/ |
896 |
split(gtop->line, 3, &ptable); |
split(gtop->line, 3, &ptable); |
897 |
if (ptable.npart != 3) { |
if (ptable.npart != 3) { |
898 |
recover(&ptable); |
recover(&ptable); |
902 |
strlimcpy(gtop->tag, ptable.part[PART_TAG].start, sizeof(gtop->tag)); |
strlimcpy(gtop->tag, ptable.part[PART_TAG].start, sizeof(gtop->tag)); |
903 |
|
|
904 |
/* Path name */ |
/* Path name */ |
905 |
fid = ptable.part[PART_FID_COMP].start; |
path = ptable.part[PART_PATH_COMP].start; |
906 |
if ((path = gpath_fid2path(fid)) == NULL) |
if (gtop->format & GTAGS_PATHINDEX) { |
907 |
die("GPATH is corrupted.('%s' not found)", fid); |
const char *p; |
908 |
|
|
909 |
|
if ((p = gpath_fid2path(path)) == NULL) |
910 |
|
die("GPATH is corrupted.('%s' not found)", path); |
911 |
|
path = p; |
912 |
|
} |
913 |
strlimcpy(gtop->path, path, sizeof(gtop->path)); |
strlimcpy(gtop->path, path, sizeof(gtop->path)); |
914 |
|
|
915 |
/* line number list */ |
/* line number list */ |