File: hole.c

package info (click to toggle)
fped 0.1%2B201210-1.2
  • links: PTS
  • area: main
  • in suites: bookworm, bullseye
  • size: 968 kB
  • sloc: ansic: 12,651; yacc: 1,112; sh: 974; lex: 204; makefile: 140; awk: 75
file content (86 lines) | stat: -rw-r--r-- 2,056 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
 * hole.c - Classify holes and connect them with pads
 *
 * Written 2010 by Werner Almesberger
 * Copyright 2010 by Werner Almesberger
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 */


#include "error.h"
#include "inst.h"
#include "overlap.h"
#include "hole.h"


static int check_through_hole(struct inst *pad, struct inst *hole)
{
	if (!overlap(pad, hole, ao_none))
		return 1;
	if (!inside(hole, pad)) {
		fail("hole (line %d) not completely inside "
		    "pad \"%s\" (line %d)", hole->obj->lineno,
		    pad->u.pad.name, pad->obj->lineno);
		instantiation_error = pad->obj;
		return 0;
	}
	if (hole->u.hole.pad) {
		/*
		 * A hole can only be on several pads if the pads themselves
		 * overlap. We'll catch this error in refine_copper.
		 */
		return 1;
	}
	if (pad->u.pad.hole) {
		fail("pad \"%s\" (line %d) has multiple holes (lines %d, %d)",
		    pad->u.pad.name, pad->obj->lineno,
		    hole->obj->lineno, pad->u.pad.hole->obj->lineno);
		instantiation_error = pad->obj;
		return 0;
	}
	pad->u.pad.hole = hole;
	hole->u.hole.pad = pad;
	return 1;
}


static int connect_holes(const struct pkg *pkg)
{
	struct inst *pad, *hole;

	for (pad = pkg->insts[ip_pad_copper]; pad; pad = pad->next)
		for (hole = pkg->insts[ip_hole]; hole; hole = hole->next)
			if (!check_through_hole(pad, hole))
				return 0;
	return 1;
}


static void clear_links(const struct pkg *pkg)
{
	struct inst *pad, *hole;

	for (pad = pkg->insts[ip_pad_copper]; pad; pad = pad->next)
		pad->u.pad.hole = NULL;
	for (pad = pkg->insts[ip_pad_special]; pad; pad = pad->next)
		pad->u.pad.hole = NULL;
	for (hole = pkg->insts[ip_hole]; hole; hole = hole->next)
		hole->u.hole.pad = NULL;
}


int link_holes(void)
{
	const struct pkg *pkg;

	for (pkg = pkgs; pkg; pkg = pkg->next) {
		clear_links(pkg);
		if (!connect_holes(pkg))
			return 0;
	}
        return 1;
}