Ejemplo n.º 1
0
void cref(char *name, FILE *fp, Table_T identifiers) {
	char buf[512];
	Text_T filename = { 0, "" };
	int linenum;

	if (name)
		filename = Text_put(name);
	for (linenum = 1; fgets(buf, sizeof buf, fp) != NULL; linenum++) {
		Text_T id, line = Text_put(buf);
		while ((id = getword(&line, first, rest)).len > 0) {
			Ring_T ring;
			Table_T files;
			files = Table_get(identifiers, &id);
			if (files == NULL) {
				files = Table_new(0, textcmp, texthash);
				Table_put(identifiers, copy(id), files);
			}
			ring = Table_get(files, &filename);
			if (ring == NULL) {
				ring = Ring_new();
				Table_put(files, copy(filename), ring);
				Ring_addlo(ring, Integer_new(linenum));
			} else if (Integer_get(Ring_get(ring, 0)) != linenum)
				Ring_addlo(ring, Integer_new(linenum));
		}
	}
}
Ejemplo n.º 2
0
void *Ring_add(T ring, int pos, void *x) {
	assert(ring);
	assert(pos >= -ring->length && pos<=ring->length+1);
	if (pos == 1 || pos == -ring->length)
		return Ring_addlo(ring, x);
	else if (pos == 0 || pos == ring->length + 1)
		return Ring_addhi(ring, x);
	else {
		struct node *p, *q;
		int i = pos < 0 ? pos + ring->length : pos - 1;
		{
			int n;
			q = ring->head;
			if (i <= ring->length/2)
				for (n = i; n-- > 0; )
					q = q->rlink;
			else
				for (n = ring->length - i; n-- > 0; )
					q = q->llink;
		}
		NEW(p);
		{
			p->llink = q->llink;
			q->llink->rlink = p;
			p->rlink = q;
			q->llink = p;
		}
		ring->length++;
		return p->value = x;
	}
}