model_server/cmd/src/cmd_look_up.cxx
// returns Widget name - a minimum path which is enough to find the Widget
// input : array of pointers to names - the path for look_up table.
returns Widget name - a minimum path which is enough to find the Widget
input : array of pointers to names - the path for look_up table.
returns Widget name - a minimum path which is enough to find the Widget input : array of pointers to names - the path for look_up table .
char *cmd_lookup(char *names[], int n_names, int *return_flag)
   {
       char *item_name = NULL;
       int len, i, j, k;
       int curr_level;
       Initialize(cmd_lookup);  
       curr_level = -1;
       k = -1;
       for (i = 0; i < n_names; i++){
           len = strlen(names[i]);               
           if (len > CMD_MAX_NAME_LEN)
               Error(ERR_INPUT);
           j = k;
           while( strcmp (CMD_MENU_TABLE[++j].displayed_name, "$END") != 0 ){
                if (curr_level >= CMD_MENU_TABLE[j].level)
                    return NULL;                 
                if (strcmp(names[i], CMD_MENU_TABLE[j].displayed_name) == 0){
                    if ( i == 0 ||                       
                         CMD_MENU_TABLE[j].par_order == 0 ||    
                         CMD_MENU_TABLE[j].level     == curr_level + 1){
                         k = j;                       
                         curr_level = CMD_MENU_TABLE[j].level;
                         break;
                    }
                }
           }
           if ( strcmp (CMD_MENU_TABLE[j].displayed_name, "$END") == 0 )
               return NULL;                 
       }
       item_name    = CMD_MENU_TABLE[k].internal_name;
       *return_flag = CMD_MENU_TABLE[k].flag;
       return item_name;
   }
char * cmd_lookup ( char * names [ ] , int n_names , int * return_flag ) { char * item_name = NULL ; int len , i , j , k ; int curr_level ; Initialize ( cmd_lookup ) ; curr_level = -1 ; k = -1 ; for ( i = 0 ; i < n_names ; i ++ ) { len = strlen ( names [ i ] ) ; if ( len > CMD_MAX_NAME_LEN ) Error ( ERR_INPUT ) ; j = k ; while ( strcmp ( CMD_MENU_TABLE [ ++ j ] . displayed_name , " " ) != 0 ) { if ( curr_level >= CMD_MENU_TABLE [ j ] . level ) return NULL ; if ( strcmp ( names [ i ] , CMD_MENU_TABLE [ j ] . displayed_name ) == 0 ) { if ( i == 0 || CMD_MENU_TABLE [ j ] . par_order == 0 || CMD_MENU_TABLE [ j ] . level == curr_level + 1 ) { k = j ; curr_level = CMD_MENU_TABLE [ j ] . level ; break ; } } } if ( strcmp ( CMD_MENU_TABLE [ j ] . displayed_name , " " ) == 0 ) return NULL ; } item_name = CMD_MENU_TABLE [ k ] . internal_name ; * return_flag = CMD_MENU_TABLE [ k ] . flag ; return item_name ; }
returns Widget name - a minimum path which is enough to find the Widget
input : array of pointers to names - the path for look_up table.
returns Widget name - a minimum path which is enough to find the Widget input : array of pointers to names - the path for look_up table .
// get the i-th name in path //         search for next name in path from current position // name is not found - error ? //                  not enough - can be many same names ( like "File" !); //                  check if the parent is O.K // no parents of the top one // ignore parent check // save found position // name is not found - error ?