/* @(#)rr_insert.c 2.1 93/05/18 */ /******************************************************************************/ /* function : rr_insert.c */ /* */ /* subsystem : chgen */ /* */ /* input : obj_ptr (rr obj ptr to insert) , table_head (table root) */ /* */ /* output : table_head (may change if elt is now first) */ /* */ /* returns : table_head */ /* */ /* author : Steve Smith / Craig Smith */ /* */ /* created : July, 1991 */ /* */ /* revisions : */ /* */ /* description : This routine will insert the specified node (pointed to by */ /* obj_ptr) into the rr_type list rooted by table_head. The */ /* insert is performed in 'firstid' order. */ /* The result of the routine is the new table_head. */ /* */ /******************************************************************************/ #include #include #include "chgen_define.h" #include "chgen_externs.h" #include "prototypes.h" /* changed the return type of this function for OSF maldred 22-Nov-95 */ struct rr_type * rr_insert ( obj_ptr , table_head ) struct rr_type *obj_ptr , *table_head ; { static char rcsid[] = "$Id: rr_insert.c,v 1.3.4.1 1999/05/04 17:00:20 jkarner Exp $"; struct rr_type *previous_ptr , *current_ptr ; current_ptr = table_head ; if ( table_head == NULL ) table_head = obj_ptr ; else { previous_ptr = current_ptr ; while ( ( current_ptr != NULL ) && ( strcmp ( current_ptr->firstid , obj_ptr->firstid ) < 0 ) ) /* traversing the link list sorted in ascending order by the 1st field of a rr_type object and searching for the right position to insert */ { previous_ptr = current_ptr ; current_ptr = current_ptr->next_ptr ; } if ( current_ptr == table_head ) /* new entry to be inserted in front of the link list */ { obj_ptr->next_ptr = current_ptr ; table_head = obj_ptr ; } else { previous_ptr->next_ptr = obj_ptr ; obj_ptr->next_ptr = current_ptr ; } } return table_head ; }