Index: libutil/gtagsop.c
===================================================================
RCS file: /sources/global/global/libutil/gtagsop.c,v
retrieving revision 1.99
diff -u -p -r1.99 gtagsop.c
--- libutil/gtagsop.c	1 Dec 2006 14:19:27 -0000	1.99
+++ libutil/gtagsop.c	2 Dec 2006 04:18:42 -0000
@@ -58,7 +58,6 @@
 
 #define HASHBUCKETS	256
 
-static int compare_path(const void *, const void *);
 static int compare_lno(const void *, const void *);
 static void flush_pool(GTOP *);
 static const char *genrecord(GTOP *, const char *);
@@ -235,6 +234,10 @@ gtags_open(const char *dbpath, const cha
 		}
 	} else if (gtop->mode != GTAGS_READ)
 		gtop->sb = strbuf_open(0);
+	/*
+	 * Stuff for path name only.
+	 */
+	strlimcpy(gtop->dbpath, dbpath, sizeof(gtop->dbpath));
 	return gtop;
 }
 /*
@@ -330,15 +333,6 @@ gtags_delete(GTOP *gtop, IDSET *deletese
 	}
 }
 /*
- * compare_path: compare function for sorting path names.
- */
-static int
-compare_path(const void *s1, const void *s2)
-{
-	return strcmp(*(char **)s1, *(char **)s2);
-}
-
-/*
  * gtags_first: return first record
  *
  *	i)	gtop	GTOP structure
@@ -366,13 +360,13 @@ gtags_first(GTOP *gtop, const char *patt
 	const char *tagline;
 
 	/* Settlement for last time if any */
-	if (gtop->pool) {
-		strhash_close(gtop->pool);
-		gtop->pool = NULL;
-	}
-	if (gtop->path_array) {
-		free(gtop->path_array);
-		gtop->path_array = NULL;
+	if (gtop->gfind) {
+		gfind_close(gtop->gfind);
+		gtop->gfind = NULL;
+	}
+	if (gtop->path_set) {
+		idset_close(gtop->path_set);
+		gtop->path_set = NULL;
 	}
 
 	gtop->flags = flags;
@@ -423,64 +417,28 @@ gtags_first(GTOP *gtop, const char *patt
 		preg = NULL;
 	}
 	/*
-	 * If GTOP_PATH is set, at first, we collect all path names in a pool and
-	 * sort them. gtags_first() and gtags_next() returns one of the pool.
+	 * If GTOP_PATH is set, at first, we collect all fids in a idset.
+	 * gtags_first() and gtags_next() returns a path is in the idset.
 	 */
 	if (gtop->flags & GTOP_PATH) {
-		struct sh_entry *entry;
-		char *p;
-		const char *cp;
-		unsigned long i;
+		const char *path, *fid;
 
-		gtop->pool = strhash_open(HASHBUCKETS);
-		/*
-		 * Pool path names.
-		 *
-		 * fid		path name
-		 * +--------------------------
-		 * |100		./aaa/a.c
-		 * |105		./aaa/b.c
-		 *  ...
-		 */
+		gtop->gfind = gfind_open(gtop->dbpath, NULL, GPATH_SOURCE);
+		gtop->path_set = idset_open(gpath_nextkey());
 		for (tagline = dbop_first(gtop->dbop, key, preg, dbflags);
 		     tagline != NULL;
 		     tagline = dbop_next(gtop->dbop))
 		{
-			/* extract file id */
-			p = locatestring(tagline, " ", MATCH_FIRST);
-			if (p == NULL)
-				die("Illegal tag record. '%s'\n", tagline);
-			*p = '\0';
-			entry = strhash_assign(gtop->pool, tagline, 1);
-			/* new entry: get path name and set. */
-			if (entry->value == NULL) {
-				cp = gpath_fid2path(tagline, NULL);
-				if (cp == NULL)
-					die("GPATH is corrupted.(file id '%s' not found)", tagline);
-				entry->value = strhash_strdup(gtop->pool, cp, 0);
-			}
+			idset_add(gtop->path_set, atoi(tagline));
 		}
-		/*
-		 * Sort path names.
-		 *
-		 * fid		path name	path_array (sort)
-		 * +--------------------------	+---+
-		 * |100		./aaa/a.c <-------* |
-		 * |105		./aaa/b.c <-------* |
-		 *  ...				...
-		 */
-		gtop->path_array = (char **)check_malloc(gtop->pool->entries * sizeof(char *));
-		i = 0;
-		for (entry = strhash_first(gtop->pool); entry != NULL; entry = strhash_next(gtop->pool))
-			gtop->path_array[i++] = entry->value;
-		if (i != gtop->pool->entries)
-			die("Something is wrong. 'i = %lu, entries = %lu'" , i, gtop->pool->entries);
-		qsort(gtop->path_array, gtop->pool->entries, sizeof(char *), compare_path);
-		gtop->path_count = gtop->pool->entries;
-		gtop->path_index = 0;
-
-		return (gtop->path_index < gtop->path_count)
-			 ? gtop->path_array[gtop->path_index++] : NULL;
+		while ((path = gfind_read(gtop->gfind)) != NULL) {
+			fid = gpath_path2fid(path, NULL);
+			if (fid == NULL)
+				die("GPATH is corrupted.('%s' not found)", path);
+			if (idset_contains(gtop->path_set, atoi(fid)))
+				break;
+		}
+		return path;
 	} else {
 		tagline = dbop_first(gtop->dbop, key, preg, dbflags);
 		if (tagline == NULL || gtop->flags & GTOP_KEY)
@@ -501,8 +459,16 @@ gtags_next(GTOP *gtop)
 	const char *tagline;
 
 	if (gtop->flags & GTOP_PATH) {
-		return (gtop->path_index < gtop->path_count)
-			 ? gtop->path_array[gtop->path_index++] : NULL;
+		const char *path, *fid;
+
+		while ((path = gfind_read(gtop->gfind)) != NULL) {
+			fid = gpath_path2fid(path, NULL);
+			if (fid == NULL)
+				die("GPATH is corrupted.('%s' not found)", path);
+			if (idset_contains(gtop->path_set, atoi(fid)))
+				break;
+		}
+		return path;
 	} else {
 		if (gtop->format & GTAGS_COMPACT && gtop->lnop != NULL)
 			return genrecord_compact(gtop);
@@ -525,12 +491,14 @@ gtags_close(GTOP *gtop)
 	if (gtop->format & GTAGS_COMPRESS)
 		abbrev_close();
 	if (gtop->pool) {
-		if (gtop->format & GTAGS_COMPACT && gtop->prev_path[0])
+		if (gtop->prev_path[0])
 			flush_pool(gtop);
 		strhash_close(gtop->pool);
 	}
-	if (gtop->path_array)
-		free(gtop->path_array);
+	if (gtop->gfind)
+		gfind_close(gtop->gfind);
+	if (gtop->path_set)
+		idset_close(gtop->path_set);
 	if (gtop->sb)
 		strbuf_close(gtop->sb);
 	if (gtop->ib)
Index: libutil/gtagsop.h
===================================================================
RCS file: /sources/global/global/libutil/gtagsop.h,v
retrieving revision 1.35
diff -u -p -r1.35 gtagsop.h
--- libutil/gtagsop.h	1 Dec 2006 06:38:09 -0000	1.35
+++ libutil/gtagsop.h	2 Dec 2006 04:18:42 -0000
@@ -26,6 +26,7 @@
 
 #include "gparam.h"
 #include "dbop.h"
+#include "gpathop.h"
 #include "idset.h"
 #include "strbuf.h"
 #include "strhash.h"
@@ -71,9 +72,9 @@ typedef struct {
 	/*
 	 * Path name only.
 	 */
-	int path_count;
-	int path_index;
-	char **path_array;
+	char dbpath[MAXPATHLEN+1];
+	GFIND *gfind;
+	IDSET *path_set;
 	/*
 	 * Stuff for compact format
 	 */
@@ -87,8 +88,7 @@ typedef struct {
 	FILE *fp;			/* descriptor of 'path' */
 	const char *lnop;		/* current line number */
 	int lno;			/* integer value of 'lnop' */
-	/* used for compact format and path name only read */
-	STRHASH *pool;
+	STRHASH *pool;			/* record pool for compact format */
 } GTOP;
 
 const char *dbname(int);
