1 /*****************************************************************************
2  * HTICK --- FTN Ticker / Request Processor
3  *****************************************************************************
4  * SEEN-BY lines compare routine(s)
5  *
6  * This file is part of HTICK, part of the Husky fidosoft project
7  * http://husky.physcip.uni-stuttgart.de
8  *
9  * HTICK is free software; you can redistribute it and/or modify it
10  * under the terms of the GNU General Public License as published by the
11  * Free Software Foundation; either version 2, or (at your option) any
12  * later version.
13  *
14  * HTICK is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with HTICK; see the file COPYING.  If not, write to the Free
21  * Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
22  *****************************************************************************
23  * $Id$
24  *****************************************************************************/
25 
26 #include <stdlib.h>
27 #include <string.h>
28 #include <fidoconf/fidoconf.h>
29 #include <fidoconf/common.h>
30 #include <areafix/areafix.h>
31 #include <fcommon.h>
32 #include <global.h>
33 #include "seenby.h"
34 
seenbyComp(hs_addr * seenby,int anzseenby,hs_addr Aka)35 int seenbyComp( hs_addr * seenby, int anzseenby, hs_addr Aka )
36 {
37   int i;
38 
39   for( i = 0; i < anzseenby; i++ )
40   {
41     if( addrComp( seenby[i], Aka ) == 0 )
42       return 0;
43   }
44 
45   return !0;
46 }
47 
seenbyAdd(hs_addr ** seenby,UINT * anzseenby,ps_addr Aka)48 int seenbyAdd( hs_addr ** seenby, UINT * anzseenby, ps_addr Aka )
49 {
50   ps_addr tmp = *seenby;
51 
52   if( seenbyComp( *seenby, ( int )( *anzseenby ), *Aka ) )      /* If Aka don't presents in seen-by list */
53   {                             /* then store Aka into list */
54     tmp = srealloc( tmp, ( *anzseenby + 1 ) * sizeof( hs_addr ) );
55     memcpy( &tmp[*anzseenby], Aka, sizeof( hs_addr ) );
56     ( *anzseenby )++;
57     *seenby = tmp;
58     return 1;
59   }
60   else
61     return 0;
62 }
63 
cmp_Addr(const void * a,const void * b)64 static int cmp_Addr( const void *a, const void *b )
65 {
66   const ps_addr r1 = ( ps_addr ) a;
67   const ps_addr r2 = ( ps_addr ) b;
68 
69   if( r1->zone > r2->zone )
70     return 1;
71   else if( r1->zone < r2->zone )
72     return -1;
73   else if( r1->net > r2->net )
74     return 1;
75   else if( r1->net < r2->net )
76     return -1;
77   else if( r1->node > r2->node )
78     return 1;
79   else if( r1->node < r2->node )
80     return -1;
81   else if( r1->point > r2->point )
82     return 1;
83   else if( r1->point < r2->point )
84     return -1;
85   return 0;
86 }
87 
88 
seenbySort(ps_addr seenby,int anzseenby)89 int seenbySort( ps_addr seenby, int anzseenby )
90 {
91   qsort( ( void * )seenby, anzseenby, sizeof( hs_addr ), cmp_Addr );
92   return 1;
93 }
94