/[radius]/radius/lib/avl.c
ViewVC logotype

Diff of /radius/lib/avl.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.5 by gray, Mon Aug 5 08:01:05 2002 UTC revision 1.6 by gray, Wed Apr 30 08:38:29 2003 UTC
# Line 1  Line 1 
1  /* This file is part of GNU RADIUS.  /* This file is part of GNU Radius.
2     Copyright (C) 2000, Sergey Poznyakoff     Copyright (C) 2000,2001,2002,2003 Sergey Poznyakoff
3      
4     This program is free software; you can redistribute it and/or modify     GNU Radius is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.     (at your option) any later version.
8      
9     This program is distributed in the hope that it will be useful,     GNU Radius is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.     GNU General Public License for more details.
13      
14     You should have received a copy of the GNU General Public License     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software Foundation,     along with GNU Radius; if not, write to the Free Software Foundation,
16     Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */     Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
17    
 #ifndef lint  
 static char rcsid[] =  
 "$Id$";  
 #endif  
   
18  #ifdef HAVE_CONFIG_H  #ifdef HAVE_CONFIG_H
19  # include <config.h>  # include <config.h>
20  #endif  #endif
# Line 52  avp_alloc() Line 47  avp_alloc()
47  }  }
48    
49  void  void
50  avp_free(p)      avp_free(VALUE_PAIR *p)
         VALUE_PAIR *p;  
51  {  {
52          if (!p)          if (!p)
53                  return;                  return;
# Line 66  avp_free(p) Line 60  avp_free(p)
60    
61  /* Create a copy of a pair */  /* Create a copy of a pair */
62  VALUE_PAIR *  VALUE_PAIR *
63  avp_dup(vp)  avp_dup(VALUE_PAIR *vp)
         VALUE_PAIR *vp;  
64  {  {
65          VALUE_PAIR *ret = avp_alloc();          VALUE_PAIR *ret = avp_alloc();
66    
# Line 80  avp_dup(vp) Line 73  avp_dup(vp)
73    
74  /* Create a pair with given attribute, length and value; */  /* Create a pair with given attribute, length and value; */
75  VALUE_PAIR *  VALUE_PAIR *
76  avp_create(attr, length, strval, lval)  avp_create(int attr, int length, char *strval, int lval)
         int attr;  
         int length;  
         char *strval;  
         int lval;  
77  {  {
78          VALUE_PAIR *pair;          VALUE_PAIR *pair;
79          DICT_ATTR  *dict;          DICT_ATTR  *dict;
# Line 111  avp_create(attr, length, strval, lval) Line 100  avp_create(attr, length, strval, lval)
100    
101  /* Add a pair to the end of a VALUE_PAIR list. */  /* Add a pair to the end of a VALUE_PAIR list. */
102  VALUE_PAIR *  VALUE_PAIR *
103  avp_move(first, new)  avp_move(VALUE_PAIR **first, VALUE_PAIR *new)
         VALUE_PAIR **first;  
         VALUE_PAIR *new;  
104  {  {
105          VALUE_PAIR *pair, *prev = NULL;          VALUE_PAIR *pair, *prev = NULL;
106    
# Line 162  avp_move(first, new) Line 149  avp_move(first, new)
149  }  }
150    
151  int  int
152  avp_cmp(a, b)  avp_cmp(VALUE_PAIR *a, VALUE_PAIR *b)
         VALUE_PAIR *a, *b;  
153  {  {
154          int rc = 1;          int rc = 1;
155                    
# Line 192  avp_cmp(a, b) Line 178  avp_cmp(a, b)
178  /* Release the memory used by a list of attribute-value pairs.  /* Release the memory used by a list of attribute-value pairs.
179   */   */
180  void  void
181  avl_free(pair)  avl_free(VALUE_PAIR *pair)
         VALUE_PAIR *pair;  
182  {  {
183          VALUE_PAIR *next;          VALUE_PAIR *next;
184    
# Line 208  avl_free(pair) Line 193  avl_free(pair)
193  /* Find the pair with the matching attribute  /* Find the pair with the matching attribute
194   */   */
195  VALUE_PAIR *  VALUE_PAIR *
196  avl_find(first, attr)  avl_find(VALUE_PAIR *first, int attr)
         VALUE_PAIR *first;  
         int attr;  
197  {  {
198          while (first && first->attribute != attr)          while (first && first->attribute != attr)
199                  first = first->next;                  first = first->next;
# Line 219  avl_find(first, attr) Line 202  avl_find(first, attr)
202    
203  /* Find nth occurrence of a pair with the matching attribute. */  /* Find nth occurrence of a pair with the matching attribute. */
204  VALUE_PAIR *  VALUE_PAIR *
205  avl_find_n(first, attr, n)  avl_find_n(VALUE_PAIR *first, int attr, int n)
         VALUE_PAIR *first;  
         int attr;  
         int n;  
206  {  {
207          for ( ; first; first = first->next) {          for ( ; first; first = first->next) {
208                  if (first->attribute == attr && n-- == 0)                  if (first->attribute == attr && n-- == 0)
# Line 234  avl_find_n(first, attr, n) Line 214  avl_find_n(first, attr, n)
214  /* Delete the pairs with the matching attribute  /* Delete the pairs with the matching attribute
215   */   */
216  void  void
217  avl_delete(first, attr)  avl_delete(VALUE_PAIR **first, int attr)
         VALUE_PAIR **first;  
         int attr;  
218  {  {
219          VALUE_PAIR *pair, *next, *last = NULL;          VALUE_PAIR *pair, *next, *last = NULL;
220    
# Line 255  avl_delete(first, attr) Line 233  avl_delete(first, attr)
233    
234  /* Delete Nth pair with the matching attribute */  /* Delete Nth pair with the matching attribute */
235  void  void
236  avl_delete_n(first, attr, n)  avl_delete_n(VALUE_PAIR **first, int attr, int n)
         VALUE_PAIR **first;  
         int attr;  
         int n;  
237  {  {
238          VALUE_PAIR *pair, *next, *last = NULL;          VALUE_PAIR *pair, *next, *last = NULL;
239    
# Line 279  avl_delete_n(first, attr, n) Line 254  avl_delete_n(first, attr, n)
254    
255  /* Move all attributes of a given type from one list to another */  /* Move all attributes of a given type from one list to another */
256  void  void
257  avl_move_pairs(to, from, fun, closure)  avl_move_pairs(VALUE_PAIR **to, VALUE_PAIR **from, int (*fun)(),
258          VALUE_PAIR **to;                 void *closure)
         VALUE_PAIR **from;  
         int (*fun)();  
         void *closure;  
259  {  {
260          VALUE_PAIR *to_tail, *i, *next;          VALUE_PAIR *to_tail, *i, *next;
261          VALUE_PAIR *iprev = NULL;          VALUE_PAIR *iprev = NULL;
# Line 326  avl_move_pairs(to, from, fun, closure) Line 298  avl_move_pairs(to, from, fun, closure)
298          }          }
299  }  }
300    
301  int  static int
302  cmp_attr(valp, pair)  cmp_attr(int *valp, VALUE_PAIR *pair)
         int *valp;  
         VALUE_PAIR *pair;  
303  {  {
304          return *valp == pair->attribute;          return *valp == pair->attribute;
305  }  }
306    
307  /* Move all attributes of a given type from one list to another */  /* Move all attributes of a given type from one list to another */
308  void  void
309  avl_move_attr(to, from, attr)  avl_move_attr(VALUE_PAIR **to, VALUE_PAIR **from, int attr)
         VALUE_PAIR **to;  
         VALUE_PAIR **from;  
         int attr;  
310  {  {
311          avl_move_pairs(to, from, cmp_attr, &attr);          avl_move_pairs(to, from, cmp_attr, &attr);
312  }  }
# Line 347  avl_move_attr(to, from, attr) Line 314  avl_move_attr(to, from, attr)
314  /* Move attributes from one list to the other honoring their additivity  /* Move attributes from one list to the other honoring their additivity
315   */   */
316  void  void
317  avl_merge(dst_ptr, src_ptr)  avl_merge(VALUE_PAIR **dst_ptr, VALUE_PAIR **src_ptr)
         VALUE_PAIR **dst_ptr;  
         VALUE_PAIR **src_ptr;  
318  {  {
319          VALUE_PAIR *src, *next, *src_head, *src_tail;          VALUE_PAIR *src, *next, *src_head, *src_tail;
320    
# Line 378  avl_merge(dst_ptr, src_ptr) Line 343  avl_merge(dst_ptr, src_ptr)
343    
344  /* Append the list `new' to the end of the list `*first' */  /* Append the list `new' to the end of the list `*first' */
345  void  void
346  avl_add_list(first, new)  avl_add_list(VALUE_PAIR **first, VALUE_PAIR *new)
         VALUE_PAIR **first;  
         VALUE_PAIR *new;  
347  {  {
348          VALUE_PAIR *pair;          VALUE_PAIR *pair;
349                    
# Line 395  avl_add_list(first, new) Line 358  avl_add_list(first, new)
358    
359  /* Add a single pair to the list */  /* Add a single pair to the list */
360  void  void
361  avl_add_pair(first, new)  avl_add_pair(VALUE_PAIR **first, VALUE_PAIR *new)
         VALUE_PAIR **first;  
         VALUE_PAIR *new;  
362  {  {
363          if (!new)          if (!new)
364                  return;                  return;
# Line 408  avl_add_pair(first, new) Line 369  avl_add_pair(first, new)
369    
370  /* Create a copy of a pair list. */  /* Create a copy of a pair list. */
371  VALUE_PAIR *  VALUE_PAIR *
372  avl_dup(from)  avl_dup(VALUE_PAIR *from)
         VALUE_PAIR *from;  
373  {  {
374          VALUE_PAIR *first = NULL;          VALUE_PAIR *first = NULL;
375          VALUE_PAIR *last = NULL;          VALUE_PAIR *last = NULL;
# Line 433  avl_dup(from) Line 393  avl_dup(from)
393    
394  /* write a pairlist to the file */  /* write a pairlist to the file */
395  void  void
396  avl_fprint(fp, avl)  avl_fprint(FILE *fp, VALUE_PAIR *avl)
         FILE *fp;  
         VALUE_PAIR *avl;  
397  {  {
398          char *save;          char *save;
399          for (;avl; avl = avl->next) {          for (;avl; avl = avl->next) {
# Line 445  avl_fprint(fp, avl) Line 403  avl_fprint(fp, avl)
403  }  }
404    
405  int  int
406  avl_cmp(a, b, prop)  avl_cmp(VALUE_PAIR *a, VALUE_PAIR *b, int prop)
         VALUE_PAIR *a, *b;  
         int prop;  
407  {  {
408          int cmp_count = 0;          int cmp_count = 0;
409                    

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.6

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26