Example #1
0
static int
search_cmd_type(char *name, int *pmatch_id, int is_print)
{
    int cmd_no = 0, pmatch_nr = 0;

    *pmatch_id = GCMD_DESC_NO_MATCH;
    
    /*search type in glb_num_types print matched */
    for (cmd_no = 0; GCMD_DESC_VALID(cmd_no); cmd_no++) {
        
        if (!GCMD_NAME(cmd_no))
            continue;
        
        if (!strcasecmp(name, GCMD_NAME(cmd_no))) {
            /*full matched */
            *pmatch_id = cmd_no;
            break;
        } else if (!strncasecmp(name, GCMD_NAME(cmd_no), strlen(name))) {
            /*partly matched */
            printc(is_print, "%-10s%s\n", GCMD_NAME(cmd_no), GCMD_MEMO(cmd_no));
            pmatch_nr++;
            *pmatch_id = cmd_no;
        }
    }

    return pmatch_nr;
}
Example #2
0
static void
print_cmd_all (void) 
{
    int cmd_no = 0;
    for (cmd_no = 0; GCMD_DESC_VALID(cmd_no); cmd_no++) {
        if (!GCMD_NAME(cmd_no))
            continue;
                
        printf("%-10s%s\n", GCMD_NAME(cmd_no), GCMD_MEMO(cmd_no));
    }
}
Example #3
0
void
cmd_print_usage (int cmd_index, int cmd_index_sub)
{
    if(GCMD_NAME(cmd_index))
        dprintf("usage: %s", GCMD_NAME(cmd_index));

    if (GCMD_SUB_NAME(cmd_index, cmd_index_sub))
        dprintf(" %s", GCMD_SUB_NAME(cmd_index, cmd_index_sub));

    if(GCMD_SUB_ACT(cmd_index, cmd_index_sub) && GCMD_SUB_USAGE(cmd_index, cmd_index_sub))
        dprintf(" %s %s\n\n", GCMD_SUB_ACT(cmd_index, cmd_index_sub),
                GCMD_SUB_USAGE(cmd_index, cmd_index_sub));
}
Example #4
0
/*command string lookup*/
a_uint32_t
cmd_lookup(char **cmd_str, int *cmd_index, int *cmd_index_sub)
{
    a_uint32_t no, sub_no;
    a_uint32_t cmd_deepth = 0;

    *cmd_index = GCMD_DESC_NO_MATCH;
    *cmd_index_sub = GCMD_DESC_NO_MATCH;

    if (cmd_str[0] == NULL)
        return cmd_deepth;

    for (no = 0; GCMD_DESC_VALID(no); no++)
    {
        if (strcasecmp(cmd_str[0], GCMD_NAME(no)))
            continue;

        for (sub_no = 0; GCMD_SUB_DESC_VALID(no, sub_no); sub_no++)
        {
            if (cmd_str[1] != NULL && cmd_str[2] != NULL)
            {

                if (GCMD_SUB_NAME(no, sub_no) && GCMD_SUB_ACT(no, sub_no)
                        && !strcasecmp(cmd_str[1], GCMD_SUB_NAME(no, sub_no))
                        && !strcasecmp(cmd_str[2], GCMD_SUB_ACT(no, sub_no)))
                {
                    *cmd_index = no;
                    *cmd_index_sub = sub_no;
                    cmd_deepth = 3;
                    return cmd_deepth;
                }

                else if (!GCMD_SUB_NAME(no, sub_no) && GCMD_SUB_ACT(no, sub_no)
                         && !strcasecmp(cmd_str[1], GCMD_SUB_ACT(no, sub_no)))
                {
                    *cmd_index = no;
                    *cmd_index_sub = sub_no;
                    cmd_deepth = 2;
                    return cmd_deepth;
                }
            }
            else if (cmd_str[1] != NULL && cmd_str[2] == NULL)
            {

                if (!GCMD_SUB_NAME(no, sub_no) && GCMD_SUB_ACT(no, sub_no)
                        && !strcasecmp(cmd_str[1], GCMD_SUB_ACT(no, sub_no)))
                {
                    *cmd_index = no;
                    *cmd_index_sub = sub_no;
                    cmd_deepth = 2;
                    return cmd_deepth;
                }
            }
        }
    }

    return cmd_deepth;
}
Example #5
0
static void
handle_tab(void)
{

    int cmd_nr = 0;
    char matchBuf[MATCH_BUF_MAX];
    char *tmp_str[3];

    memset(matchBuf, 0, MATCH_BUF_MAX);
    strncpy(matchBuf, cmd_strp, cmd_cursor);

    printf("\n");

    /* split command string into temp array */
    tmp_str[cmd_nr] = (void *) strtok(matchBuf, " ");
    
    if(!tmp_str[cmd_nr])  {
        print_cmd_all();
        if (cmd_promptp)
            printf("\n%s%s", cmd_promptp, cmd_strp);
        _cursor_recover();
        return;
    }
    
    while (tmp_str[cmd_nr]) {
        if (++cmd_nr == 3)
            break;
        tmp_str[cmd_nr] = (void *) strtok(NULL, " ");
    }

    int is_print = 1, is_completed = 0;
    int pmatch_nr = 0, pmatch_id = GCMD_DESC_NO_MATCH;

    pmatch_nr = search_cmd_type(tmp_str[0], &pmatch_id, is_print); 

    if (cmd_nr == 1) {
        if (ONE_PART_MATCHED(pmatch_nr, pmatch_id)) {
            _cmd_complete(tmp_str[0], GCMD_NAME(pmatch_id));
            is_completed = 1;
        } 

        if(NONE_MATCHED(pmatch_nr, pmatch_id)) {
            print_cmd_all();
            
        } else if(FULL_MATCHED(pmatch_nr, pmatch_id)) {
            print_sub_all(pmatch_id);
        }
        
    } else if (cmd_nr > 1) {
        if (FULL_MATCHED(pmatch_nr, pmatch_id)) {
            
            int pmatch_sub_nr = 0, pmatch_sub_id = GCMD_DESC_NO_MATCH;
            
            if(cmd_nr == 3) is_print = 0;
            pmatch_sub_nr = search_cmd_sub(pmatch_id, &pmatch_sub_id, tmp_str[1], is_print);

            if(cmd_nr == 2) {
                if (ONE_PART_MATCHED(pmatch_sub_nr, pmatch_sub_id)) {
                    _cmd_complete(tmp_str[1], GCMD_SUB_NAME(pmatch_id, pmatch_sub_id));
                    is_completed = 1;
                }
                
            } else if (cmd_nr == 3){
                int pmatch_act_nr = 0, pmatch_act_id = GCMD_DESC_NO_MATCH;
                pmatch_act_nr = search_cmd_action(pmatch_id, &pmatch_act_id, tmp_str[1], tmp_str[2], is_print); 
                
                if (ONE_PART_MATCHED(pmatch_act_nr, pmatch_act_id)) {
                    _cmd_complete(tmp_str[2], GCMD_SUB_ACT(pmatch_id, pmatch_act_id));
                    is_completed = 1;
                    
                } else if (FULL_MATCHED(pmatch_act_nr, pmatch_act_id)) {
                    is_print = 1;
                    printc(is_print, "%-10s\n", GCMD_SUB_USAGE(pmatch_id, pmatch_act_id));
                }
            }
        }
    } 

    if (is_completed == 0) {
        /*re-echo */
        if (cmd_promptp)
            printf("\n%s%s", cmd_promptp, cmd_strp);
        _cursor_recover();
    }
    //_cursor_recover();
}