-
Notifications
You must be signed in to change notification settings - Fork 4
/
selpnt.c
81 lines (73 loc) · 1.8 KB
/
selpnt.c
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
#include "db.h"
SELPNT *selpnt_new(double *x,double *y, DB_DEFLIST *pdef)
{
SELPNT *tmp;
tmp = (SELPNT *) malloc(sizeof(SELPNT));
tmp->p = pdef;
tmp->xsel = x;
tmp->ysel = y;
tmp->xselorig = (x==NULL)?0.0:(*x);
tmp->yselorig = (y==NULL)?0.0:(*y);
tmp->next = NULL;
tmp->prev = tmp; /* prev pointer points at last */
return(tmp);
}
void selpnt_clear(SELPNT **selhead) {
SELPNT *tmp1;
SELPNT *tmp2;
tmp1 = *selhead;
while (tmp1 != NULL) {
tmp2 = tmp1->next;
free(tmp1);
tmp1 = tmp2;
}
*selhead = NULL;
}
void selpnt_print(SELPNT **selhead) {
SELPNT *tmp1;
int i=0;
tmp1 = *selhead;
printf("------------------\n");
while (tmp1 != NULL) {
printf("%d: %g %g %g %g\n", i++,
(tmp1->xsel == NULL)?0.0:(*(tmp1->xsel)),
(tmp1->ysel == NULL)?0.0:(*(tmp1->ysel)),
(tmp1->xselorig), (tmp1->yselorig));
tmp1 = tmp1->next;
}
}
void selpnt_save(SELPNT **selhead, double *x, double *y, DB_DEFLIST *pdef) {
SELPNT *tmp;
if (*selhead == NULL) {
*selhead = selpnt_new(x,y,pdef);
} else {
tmp = (*selhead)->prev;
tmp->next = selpnt_new(x,y,pdef);
tmp->next->prev = tmp;
(*selhead)->prev = tmp->next;
}
}
/*
int main() {
SELPNT *selhead = NULL;
double px = 2.0;
double py = 4.2;
selpnt_save(&selhead, &px, &py, NULL);
py = 9.2;
selpnt_save(&selhead, NULL, &py, NULL);
selpnt_save(&selhead, NULL, NULL, NULL);
px = 6.0;
selpnt_save(&selhead, &px, &py, NULL);
selpnt_print(&selhead);
selpnt_clear(&selhead);
selpnt_print(&selhead);
py = 9.2;
selpnt_save(&selhead, NULL, &py, NULL);
selpnt_save(&selhead, NULL, NULL, NULL);
px = 6.0;
selpnt_save(&selhead, &px, &py, NULL);
selpnt_print(&selhead);
selpnt_clear(&selhead);
return(0);
}
*/