/* @(#)gen_path.c 2.1 93/05/19 */ /******************************************************************************/ /* function : gen_path.c (recursive) */ /* */ /* subsystem : chgen */ /* */ /* input : path_history, path_head, target */ /* */ /* output : (calls store_into_matrix) */ /* */ /* returns : void */ /* */ /* author : Cheng */ /* */ /* created : July, 1991 */ /* */ /* revisions : 93s523: change strn(cpy/cmp) to use variable hcg_abbr_size */ /* */ /* description : This recursive routine traverses the cp_table, looking for */ /* entries matching the specified target table. With each */ /* one found, check if its already in the path history. If it */ /* is, it must be a cycle. Otherwise, store the entry in the */ /* path matrix (that is being build), and recurse on the */ /* entry. */ /* */ /******************************************************************************/ #include #include #include "chgen_define.h" #include "chgen_externs.h" /**************************************************************** * * * ex : cp_table is as follows : * * AAid:BBid * * BBid:CCid * * CCid:DDid * * CCid:FFid * * gen_path will build the following paths * * AA_BB_CC_DD (for path_length = 3 ) * * AA_BB_CC_FF (for path_length = 3 ) * * . * * . * * . * * AA_BB_CC (for path_length = 2 ) * * AA_CC_DD (for path_length = 2 ) * * . * * . * * . * * * ****************************************************************/ void gen_path ( path_history, path_head, target ) char path_history[]; char path_head[]; char target[]; { static char rcsid[] = ""; char child_abbrev[ABBREV_NAME_LENGTH] , parent_abbrev[ABBREV_NAME_LENGTH] , temp_abbrev[ABBREV_NAME_LENGTH]; struct rr_type *curr_ptr ; int i , j , x , y , cycle ; curr_ptr = cp_table ; while (curr_ptr != NULL) { strncpy_null(child_abbrev,curr_ptr->firstid,hcg_abbr_size); strncpy_null(parent_abbrev,curr_ptr->secondid,hcg_abbr_size); if(strcmp(target,child_abbrev)==0) { i = 0; cycle = 0; while(path_history[i]!='\0') { if(strncmp(path_history+i,parent_abbrev, hcg_abbr_size) == 0) { cycle = 1; break; } i += hcg_abbr_size; } if(!cycle) { strncpy_null(path_history+i,parent_abbrev, hcg_abbr_size); /* get TTchildindex, x and TTparentindex, y */ TXindex = encoding(path_head); x = TINDEX[TXindex].TTindex ; strncpy_null(temp_abbrev, curr_ptr->secondid, hcg_abbr_size); TXindex = encoding(temp_abbrev); y = TINDEX[TXindex].TTindex ; store_into_matrix(x, y, i/hcg_abbr_size, path_history); gen_path(path_history,path_head,parent_abbrev); path_history[i] = '\0' ; } } curr_ptr = curr_ptr->next_ptr ; } return; }