1 |
/* |
/* |
2 |
* Copyright (c) 1996, 1997, 1998, 1999 Shigio Yamaguchi |
* Copyright (c) 1996, 1997, 1998, 1999 Shigio Yamaguchi |
3 |
* Copyright (c) 1999, 2000, 2001, 2002, 2003 Tama Communications Corporation |
* Copyright (c) 1999, 2000, 2001, 2002, 2003, 2004 |
4 |
|
* Tama Communications Corporation |
5 |
* |
* |
6 |
* This file is part of GNU GLOBAL. |
* This file is part of GNU GLOBAL. |
7 |
* |
* |
35 |
#include "anchor.h" |
#include "anchor.h" |
36 |
#include "htags.h" |
#include "htags.h" |
37 |
|
|
|
static int alloced; |
|
|
static int used; |
|
38 |
static struct anchor *table; |
static struct anchor *table; |
39 |
|
static VARRAY *vb; |
40 |
|
|
41 |
static struct anchor *start; |
static struct anchor *start; |
42 |
static struct anchor *curp; |
static struct anchor *curp; |
75 |
FIRST = LAST = 0; |
FIRST = LAST = 0; |
76 |
end = CURRENT = NULL; |
end = CURRENT = NULL; |
77 |
|
|
78 |
used = 0; |
if (vb == NULL) |
79 |
|
vb = varray_open(sizeof(struct anchor), 1000); |
80 |
|
else |
81 |
|
varray_reset(vb); |
82 |
|
|
83 |
for (db = GTAGS; db < GTAGLIM; db++) { |
for (db = GTAGS; db < GTAGLIM; db++) { |
84 |
char *_; |
char *_; |
85 |
|
|
132 |
type = 'R'; |
type = 'R'; |
133 |
else |
else |
134 |
type = 'Y'; |
type = 'Y'; |
|
/* |
|
|
* Allocate table if needed. |
|
|
* |
|
|
* Old implementations of realloc() may crash when a null pointer is passed. |
|
|
* Therefore, we cannot use realloc(NULL, sizeof(struct anchor) * alloced). |
|
|
*/ |
|
|
if (alloced == 0) { |
|
|
alloced = 1000; |
|
|
table = (struct anchor *)malloc(sizeof(struct anchor) * alloced); |
|
|
used = 0; |
|
|
} else if (used >= alloced) { |
|
|
alloced += 1000; |
|
|
table = (struct anchor *)realloc(table, sizeof(struct anchor) * alloced); |
|
|
} |
|
|
if (table == NULL) |
|
|
die("Short of memory."); |
|
135 |
/* allocate an entry */ |
/* allocate an entry */ |
136 |
a = &table[used++]; |
a = varray_append(vb); |
137 |
a->lineno = atoi(lineno); |
a->lineno = atoi(lineno); |
138 |
a->type = type; |
a->type = type; |
139 |
a->done = 0; |
a->done = 0; |
144 |
die("command '%s' failed.", command); |
die("command '%s' failed.", command); |
145 |
} |
} |
146 |
strbuf_close(sb); |
strbuf_close(sb); |
147 |
/* |
if (vb->length == 0) { |
148 |
* Sort by lineno. |
table = NULL; |
149 |
*/ |
} else { |
150 |
qsort(table, used, sizeof(struct anchor), cmp); |
int used = vb->length; |
151 |
/* |
/* |
152 |
* Setup some lineno. |
* Sort by lineno. |
153 |
*/ |
*/ |
154 |
for (i = 0; i < used; i++) |
table = varray_assign(vb, 0, 0); |
155 |
if (table[i].type == 'D') |
qsort(table, used, sizeof(struct anchor), cmp); |
156 |
break; |
/* |
157 |
if (i < used) |
* Setup some lineno. |
158 |
FIRST = table[i].lineno; |
*/ |
159 |
for (i = used - 1; i >= 0; i--) |
for (i = 0; i < used; i++) |
160 |
if (table[i].type == 'D') |
if (table[i].type == 'D') |
161 |
break; |
break; |
162 |
if (i >= 0) |
if (i < used) |
163 |
LAST = table[i].lineno; |
FIRST = table[i].lineno; |
164 |
|
for (i = used - 1; i >= 0; i--) |
165 |
|
if (table[i].type == 'D') |
166 |
|
break; |
167 |
|
if (i >= 0) |
168 |
|
LAST = table[i].lineno; |
169 |
|
} |
170 |
/* |
/* |
171 |
* Setup loop range. |
* Setup loop range. |
172 |
*/ |
*/ |
173 |
start = table; |
start = table; |
174 |
curp = NULL; |
curp = NULL; |
175 |
end = &table[used]; |
end = &table[vb->length]; |
176 |
/* anchor_dump(stderr, 0);*/ |
/* anchor_dump(stderr, 0);*/ |
177 |
} |
} |
178 |
/* |
/* |
183 |
{ |
{ |
184 |
struct anchor *a; |
struct anchor *a; |
185 |
|
|
186 |
for (a = start; a < end; a++) { |
for (a = start; a && a < end; a++) { |
187 |
if (a->reserve) { |
if (a->reserve) { |
188 |
free(a->reserve); |
free(a->reserve); |
189 |
a->reserve = NULL; |
a->reserve = NULL; |
190 |
} |
} |
191 |
} |
} |
192 |
|
/* We don't free varray */ |
193 |
|
/* varray_close(vb); */ |
194 |
FIRST = LAST = 0; |
FIRST = LAST = 0; |
195 |
start = curp = end = NULL; |
start = curp = end = NULL; |
|
used = 0; |
|
196 |
} |
} |
197 |
/* |
/* |
198 |
* anchor_first: return the first anchor |
* anchor_first: return the first anchor |