source: branches/port5/ptpan/PTP_findEx.cxx

Last change on this file was 5908, checked in by westram, 16 years ago
  • source files with identical names are really a pain when using valgrind
File size: 3.7 KB
Line 
1#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4// #include <malloc.h>
5
6#include <PT_server.h>
7#include <PT_server_prototypes.h>
8#include "ptpan.h"
9//#include "probe_tree.hxx"
10#include "pt_prototypes.h"
11
12//  ------------------------------------------------------
13//      extern "C" int PT_find_exProb(PT_exProb *pep)
14//  ------------------------------------------------------
15
16/* called by AISC */
17
18/* /// "PT_find_exProb()" */
19extern "C" int PT_find_exProb(PT_exProb *pep)
20{
21  struct PTPanGlobal *pg = PTPanGlobalPtr;
22  struct PTPanPartition *pp;
23  struct TreeNode *tn;
24  struct TreeNode *parenttn;
25  BOOL done;
26  BOOL first;
27  ULONG cnt;
28  UWORD seqcode;
29  STRPTR outptr;
30  ULONG len;
31
32  printf("EXTERN: PT_find_exProb\n");
33
34  /* free old result */
35  freeset(pep->result, NULL);
36
37  /* do we need to start from scratch? */
38  if(pep->restart)
39  {
40    /* reset everything */
41    if((tn = (struct TreeNode *) pep->next_probe.data))
42    {
43      /* free old tree nodes */
44      do
45      {
46        parenttn = tn->tn_Parent;
47        free(tn);
48      } while((tn = parenttn));
49    }
50    /* get first partition */
51    pp = (struct PTPanPartition *) pg->pg_Partitions.lh_Head;
52    if(!(pp->pp_CacheNode = CacheLoadData(pg->pg_PartitionCache, pp->pp_CacheNode, pp)))
53    {
54      printf("That's it, I'm outta here!\n");
55      return(-1); /* something went wrong while loading */
56    }
57    /* get root node */
58    tn = ReadPackedNode(pp, 0);
59    pep->restart = 0;
60  } else {
61    tn = (struct TreeNode *) pep->next_probe.data;
62  }
63  if(!tn)
64  {
65    pep->result = strdup(""); /* empty string */
66    return(0);
67  }
68  pp = tn->tn_PTPanPartition;
69  outptr = (STRPTR) malloc(pep->numget * (pep->plength + 1) + 1);
70  pep->result = outptr;
71
72  /* collect all the strings that are on our way */
73  done = FALSE;
74  first = TRUE;
75  seqcode = 0;
76  len = (pep->plength < pp->pp_TreePruneLength) ? pep->plength : pp->pp_TreePruneLength;
77  for(cnt = 0; cnt < (ULONG) pep->numget; cnt++)
78  {
79    //printf("Cnt: %ld\n", cnt);
80    /* go down! */
81    while(tn->tn_TreeOffset < len)
82    {
83      while(seqcode < pg->pg_AlphaSize)
84      {
85        //printf("Seqcode %d %ld\n", seqcode, tn->tn_Children[seqcode]);
86        if(tn->tn_Children[seqcode])
87        {
88          /* there is a child, go down */
89          tn = GoDownNodeChild(tn, seqcode);
90          //printf("Down %d %08lx\n", seqcode, tn);
91          seqcode = 0;
92          break;
93        }
94        seqcode++;
95      }
96
97      while(seqcode == pg->pg_AlphaSize) /* we didn't find any children */
98      {
99        /* go up again */
100        //printf("Up\n");
101        parenttn = tn->tn_Parent;
102        seqcode = tn->tn_ParentSeq + 1;
103        freeset(tn, parenttn);
104        if(!tn)
105        {
106        /* we're done with this partition */
107          pep->next_probe.data = NULL;
108          if(pp->pp_Node.ln_Succ->ln_Succ)
109         {
110           /* load next partition */
111            pp = (struct PTPanPartition *) pp->pp_Node.ln_Succ;
112            if(!(pp->pp_CacheNode = CacheLoadData(pg->pg_PartitionCache, pp->pp_CacheNode, pp)))
113            {
114              printf("That's it, I'm outta here!\n");
115              return(-1); /* something went wrong while loading */
116            }
117            /* get root node */
118            tn = ReadPackedNode(pp, 0);
119         } else {
120           done = TRUE;
121           break; /* we're done! */
122        }
123      }
124      }
125      if(done)
126      {
127       break;
128      }
129    }
130
131    if(done)
132    {
133      break;
134    }
135
136    if(!first)
137    {
138      *outptr++ = ';';
139    } else {
140      first = FALSE;
141    }
142    GetTreePath(tn, outptr, pep->plength);
143    outptr += pep->plength;
144
145    parenttn = tn->tn_Parent;
146    seqcode = tn->tn_ParentSeq + 1;
147    freeset(tn, parenttn);
148  }
149  *outptr = 0;
150  pep->next_probe.data = (STRPTR) tn;
151  return(0);
152}
153/* \\\ */
Note: See TracBrowser for help on using the repository browser.