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_telnet.c

    r4299 r4302  
    198198 
    199199/** 
     200 * This specify the state of output character parsing. 
     201 */ 
     202typedef enum out_parse_state 
     203{ 
     204    OP_NORMAL, 
     205    OP_TYPE, 
     206    OP_SHORTCUT, 
     207    OP_CHOICE 
     208} out_parse_state; 
     209 
     210/** 
    200211 * This structure contains the command line shown to the user.   
    201212 */ 
     
    755766    struct cli_telnet_fe *fe = (struct cli_telnet_fe *)sess->base.fe; 
    756767    const pj_cli_hint_info *hint = info->hint; 
    757     pj_bool_t is_process_sc = PJ_FALSE; 
    758     pj_bool_t valid_type = PJ_FALSE; 
     768    out_parse_state parse_state = OP_NORMAL; 
    759769    pj_ssize_t max_length = 0; 
    760     const pj_str_t sc_type = pj_str("SC");     
     770    static const pj_str_t sc_type = {"sc", 2}; 
     771    static const pj_str_t choice_type = {"choice", 6}; 
    761772    send_data.ptr = &data[0]; 
    762773    send_data.slen = 0; 
     
    779790 
    780791    for (i=0;i<info->hint_cnt;++i) {     
    781         if ((&hint[i].type) && (hint[i].type.slen > 0)) { 
    782             valid_type = PJ_TRUE; 
     792        pj_strcat2(&send_data, "\r\n  "); 
     793         
     794        if ((&hint[i].type) && (hint[i].type.slen > 0)) {            
    783795            if (pj_stricmp(&hint[i].type, &sc_type) == 0) { 
    784                 if (is_process_sc) { 
    785                     pj_strcat2(&send_data, ", "); 
    786                 } else { 
    787                     pj_strcat2(&send_data, "\r\n\t Shorcut: "); 
    788                     is_process_sc = PJ_TRUE; 
     796                parse_state = OP_SHORTCUT; 
     797            } else if (pj_stricmp(&hint[i].type, &choice_type) == 0) { 
     798                parse_state = OP_CHOICE; 
     799            } else { 
     800                parse_state = OP_TYPE; 
     801            } 
     802        } else {                     
     803            parse_state = OP_NORMAL; 
     804        } 
     805     
     806        switch (parse_state) { 
     807        case OP_CHOICE: 
     808            pj_strcat2(&send_data, "["); 
     809            pj_strcat(&send_data, &hint[i].name); 
     810            pj_strcat2(&send_data, "]");         
     811            break; 
     812        case OP_TYPE: 
     813            pj_strcat2(&send_data, "<"); 
     814            pj_strcat(&send_data, &hint[i].name); 
     815            pj_strcat2(&send_data, ">");         
     816            break; 
     817        default: 
     818            pj_strcat(&send_data, &hint[i].name);            
     819            break; 
     820        } 
     821         
     822        if ((&hint[i].desc) && (hint[i].desc.slen > 0)) { 
     823            if (parse_state != OP_TYPE) { 
     824                for (j=0;j<(max_length-hint[i].name.slen);++j) { 
     825                    pj_strcat2(&send_data, " "); 
    789826                } 
    790                 pj_strcat(&send_data, &hint[i].name); 
    791             } else { 
    792                 is_process_sc = PJ_FALSE; 
    793827            } 
    794         } else {             
    795             valid_type = PJ_FALSE; 
    796             is_process_sc = PJ_FALSE; 
     828            pj_strcat2(&send_data, "  "); 
     829            pj_strcat(&send_data, &hint[i].desc);            
    797830        } 
    798  
    799         if (!is_process_sc) { 
    800             pj_strcat2(&send_data, "\r\n\t"); 
    801  
    802             if (valid_type) { 
    803                 pj_strcat2(&send_data, "<"); 
    804                 pj_strcat(&send_data, &hint[i].type); 
    805                 pj_strcat2(&send_data, ">");     
    806             } else { 
    807                 pj_strcat(&send_data, &hint[i].name);        
    808             } 
    809          
    810             if ((&hint[i].desc) && (hint[i].desc.slen > 0)) { 
    811                 if (!valid_type) { 
    812                     for (j=0;j<(max_length-hint[i].name.slen);++j) { 
    813                         pj_strcat2(&send_data, " "); 
    814                     } 
    815                 } 
    816                 pj_strcat2(&send_data, "\t"); 
    817                 pj_strcat(&send_data, &hint[i].desc);        
    818             } 
    819         } 
    820     }    
     831    }   
    821832    pj_strcat2(&send_data, "\r\n");        
    822833    pj_strcat(&send_data, &fe->cfg.prompt_str); 
     
    12911302            if (*cdata == IAC) { 
    12921303                sess->parse_state = ST_IAC; 
    1293             } else if (*cdata == '\b') { 
     1304            } else if (*cdata == 127) { 
    12941305                is_valid = handle_backspace(sess, cdata); 
    12951306            } else if (*cdata == 27) {               
Note: See TracChangeset for help on using the changeset viewer.