]> git.lizzy.rs Git - libscout.git/blob - scout.c
b9a2170db3dfc2b9942fa461266d97bf7f338857
[libscout.git] / scout.c
1 #include <stdlib.h>
2 #include "scout.h"
3
4 typedef struct scnode scnode;
5 typedef struct scway scway;
6 typedef struct scwaypoint scwaypoint;
7
8 scway *scaddway(scnode *from, const scnode *to, int len)
9 {
10         scway *way = malloc(sizeof(scway));
11         way->lto = to;
12         way->alt = NULL;
13         way->len = len;
14         scway *apar, *par = NULL;
15         for (apar = from->way; apar != NULL; par = apar, apar = apar->alt);
16         if (par)
17                 par->alt = way;
18         else
19                 from->way = way;
20         return way;
21 }
22
23 scwaypoint *__scallocwayp(const scnode *node, scway *way)
24 {
25         scwaypoint *wayp = malloc(sizeof(scwaypoint));
26         wayp->nod = node;
27         wayp->way = way;
28         wayp->nxt = NULL;
29         wayp->len = 0;
30 }
31
32 scwaypoint *__scstackfindgetend(scwaypoint *stack, scway *way)
33 {
34         scwaypoint *asptr, *sptr;
35         for (asptr = stack; asptr != NULL; sptr = asptr, asptr = asptr->nxt)
36                 if (asptr->nod == way->lto)
37                         return NULL;
38         return sptr;
39 }
40
41 void __scstackfree(scwaypoint *stack)
42 {
43         for (scwaypoint *sptr = stack; sptr != NULL; sptr = sptr->nxt)
44                 free(sptr);
45 }
46
47 int __scstackgetlen(scwaypoint *stack)
48 {
49         for (scwaypoitn)
50 }
51
52 scwaypoint *scout(const scnode *from, const scnode *to, scwaypoint *stack)
53 {
54         scwaypoint *wayp = NULL;
55         if (from == to)
56                 return __scallocwayp(from, NULL);
57         for (scway *way = from->way; way != NULL; way = way->alt) {
58                 scwaypoint *stackend;
59                 if ((stackend = __scstackfindgetend(stack, way)) == NULL)
60                         continue;
61                 
62                 if (wayp && wayp->len <= (tway->len = __scstackgetlen(tway)))
63                         __scstackfree(wayp);
64                 wayp = twayp;
65         }
66         return wayp;
67 }