Exemple #1
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));
}
Exemple #2
0
static int
search_cmd_action(int cmd_id, int *pmatch_act_id, char *sub_name, char *action, int is_print)
{
    int cmd_act_no = 0, pmatch_act_nr = 0;

    *pmatch_act_id = GCMD_DESC_NO_MATCH;

    /*search for full matched */
    for (cmd_act_no = 0; GCMD_SUB_DESC_VALID(cmd_id, cmd_act_no); cmd_act_no++)
    {

        if (strcasecmp(sub_name, GCMD_SUB_NAME(cmd_id, cmd_act_no)))
            continue;

        if (!GCMD_SUB_ACT(cmd_id, cmd_act_no))
            continue;

        if (!strcasecmp(action, GCMD_SUB_ACT(cmd_id, cmd_act_no)))
        {
            /*full matched */
            if (*pmatch_act_id == GCMD_DESC_NO_MATCH)
            {
                printc(is_print, "%-10s\n", GCMD_SUB_USAGE(cmd_id, cmd_act_no));
            }

            *pmatch_act_id = cmd_act_no;
            break;
        }
        else if (!strncasecmp(action, GCMD_SUB_ACT(cmd_id, cmd_act_no), strlen(action)))
        {
            /*partly matched */
            if (*pmatch_act_id == GCMD_DESC_NO_MATCH ||( GCMD_SUB_ACT(cmd_id, cmd_act_no-1) &&
                    strcasecmp(GCMD_SUB_ACT(cmd_id, cmd_act_no), GCMD_SUB_ACT(cmd_id, cmd_act_no-1))))
            {
                printc(is_print, "%-10s\t%s\n", GCMD_SUB_ACT(cmd_id, cmd_act_no), GCMD_SUB_MEMO(cmd_id, cmd_act_no));
                pmatch_act_nr++;
                *pmatch_act_id = cmd_act_no;
            }
        }
    }

    return pmatch_act_nr;
}
Exemple #3
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();
}