Ignore:
Timestamp:
Nov 28, 2012 3:02:01 AM (11 years ago)
Author:
riza
Message:

Re #1098: Modify help screen, change backspace input character, fix static and dynamic choice type argument handling

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/branches/projects/cli/pjlib-util/src/pjlib-util/cli_console.c

    r4299 r4302  
    7878    ST_ARROWMODE 
    7979} cmd_parse_state; 
     80 
     81/** 
     82 * This specify the state of output character parsing. 
     83 */ 
     84typedef enum out_parse_state 
     85{ 
     86    OP_NORMAL, 
     87    OP_TYPE, 
     88    OP_SHORTCUT, 
     89    OP_CHOICE 
     90} out_parse_state; 
    8091 
    8192/** 
     
    366377    console_recv_buf *recv_buf = &fe->input.recv_buf; 
    367378    const pj_cli_hint_info *hint = info->hint; 
    368     pj_bool_t is_process_sc = PJ_FALSE; 
    369     pj_bool_t valid_type = PJ_FALSE; 
     379    out_parse_state parse_state = OP_NORMAL; 
    370380    pj_ssize_t max_length = 0; 
    371     const pj_str_t sc_type = pj_str("SC"); 
     381    static const pj_str_t sc_type = {"sc", 2}; 
     382    static const pj_str_t choice_type = {"choice", 6}; 
    372383    send_data.ptr = &data[0]; 
    373384    send_data.slen = 0; 
     
    391402 
    392403    for (i=0;i<info->hint_cnt;++i) {     
    393         if ((&hint[i].type) && (hint[i].type.slen > 0)) { 
    394             valid_type = PJ_TRUE; 
     404        pj_strcat2(&send_data, "\r\n  "); 
     405         
     406        if ((&hint[i].type) && (hint[i].type.slen > 0)) {            
    395407            if (pj_stricmp(&hint[i].type, &sc_type) == 0) { 
    396                 if (is_process_sc) { 
    397                     pj_strcat2(&send_data, ", "); 
    398                 } else { 
    399                     pj_strcat2(&send_data, "\r\n\t Shorcut: "); 
    400                     is_process_sc = PJ_TRUE; 
     408                parse_state = OP_SHORTCUT; 
     409            } else if (pj_stricmp(&hint[i].type, &choice_type) == 0) { 
     410                parse_state = OP_CHOICE; 
     411            } else { 
     412                parse_state = OP_TYPE; 
     413            } 
     414        } else {                     
     415            parse_state = OP_NORMAL; 
     416        } 
     417     
     418        switch (parse_state) { 
     419        case OP_CHOICE: 
     420            pj_strcat2(&send_data, "["); 
     421            pj_strcat(&send_data, &hint[i].name); 
     422            pj_strcat2(&send_data, "]");         
     423            break; 
     424        case OP_TYPE: 
     425            pj_strcat2(&send_data, "<"); 
     426            pj_strcat(&send_data, &hint[i].type); 
     427            pj_strcat2(&send_data, ">");         
     428            break; 
     429        default: 
     430            pj_strcat(&send_data, &hint[i].name);            
     431            break; 
     432        } 
     433         
     434        if ((&hint[i].desc) && (hint[i].desc.slen > 0)) { 
     435            if (parse_state != OP_TYPE) { 
     436                for (j=0;j<(max_length-hint[i].name.slen);++j) { 
     437                    pj_strcat2(&send_data, " "); 
    401438                } 
    402                 pj_strcat(&send_data, &hint[i].name); 
    403             } else { 
    404                 is_process_sc = PJ_FALSE; 
    405439            } 
    406         } else {             
    407             valid_type = PJ_FALSE; 
    408             is_process_sc = PJ_FALSE; 
    409         } 
    410  
    411         if (!is_process_sc) { 
    412             pj_strcat2(&send_data, "\r\n\t"); 
    413  
    414             if (valid_type) { 
    415                 pj_strcat2(&send_data, "<"); 
    416                 pj_strcat(&send_data, &hint[i].type); 
    417                 pj_strcat2(&send_data, ">");     
    418             } else { 
    419                 pj_strcat(&send_data, &hint[i].name);        
    420             } 
    421          
    422             if ((&hint[i].desc) && (hint[i].desc.slen > 0)) { 
    423                 if (!valid_type) { 
    424                     for (j=0;j<(max_length-hint[i].name.slen);++j) { 
    425                         pj_strcat2(&send_data, " "); 
    426                     } 
    427                 } 
    428                 pj_strcat2(&send_data, "\t"); 
    429                 pj_strcat(&send_data, &hint[i].desc);        
    430             } 
    431         } 
    432     }         
     440            pj_strcat2(&send_data, "  "); 
     441            pj_strcat(&send_data, &hint[i].desc);            
     442        } 
     443    }   
    433444    pj_strcat2(&send_data, "\r\n"); 
    434445    pj_strcat(&send_data, &fe->cfg.prompt_str); 
Note: See TracChangeset for help on using the changeset viewer.