Ignore:
Timestamp:
Feb 4, 2014 10:13:56 AM (10 years ago)
Author:
bennylp
Message:

Misc (re #1630): Fixing warnings about variable set but not used with recent gcc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjlib-util/src/pjlib-util/cli_console.c

    r4537 r4728  
    4646    pj_thread_t        *input_thread; 
    4747    pj_bool_t           thread_quit; 
    48     pj_sem_t           *thread_sem;    
    49     pj_cli_console_cfg  cfg;     
     48    pj_sem_t           *thread_sem; 
     49    pj_cli_console_cfg  cfg; 
    5050 
    5151    struct async_input_t 
    52     {         
     52    { 
    5353        char       *buf; 
    54         unsigned    maxlen;      
     54        unsigned    maxlen; 
    5555        pj_sem_t   *sem; 
    5656    } input; 
     
    127127    if (!pool) 
    128128        return PJ_ENOMEM; 
    129          
     129 
    130130    sess = PJ_POOL_ZALLOC_T(pool, pj_cli_sess); 
    131131    fe = PJ_POOL_ZALLOC_T(pool, struct cli_console_fe); 
     
    136136    } 
    137137    sess->fe = &fe->base; 
    138     sess->log_level = param->log_level;     
     138    sess->log_level = param->log_level; 
    139139    sess->op = PJ_POOL_ZALLOC_T(pool, struct pj_cli_sess_op); 
    140140    fe->base.op = PJ_POOL_ZALLOC_T(pool, struct pj_cli_front_end_op); 
     
    155155 
    156156    pj_cli_register_front_end(cli, &fe->base); 
    157     if (param->prompt_str.slen == 0) {   
     157    if (param->prompt_str.slen == 0) { 
    158158        pj_str_t prompt_sign = pj_str(">>> "); 
    159159        fe->cfg.prompt_str.ptr = pj_pool_alloc(fe->pool, prompt_sign.slen+1); 
    160         pj_strcpy(&fe->cfg.prompt_str, &prompt_sign);    
     160        pj_strcpy(&fe->cfg.prompt_str, &prompt_sign); 
    161161    } else { 
    162         fe->cfg.prompt_str.ptr = pj_pool_alloc(fe->pool,  
     162        fe->cfg.prompt_str.ptr = pj_pool_alloc(fe->pool, 
    163163                                               param->prompt_str.slen+1); 
    164164        pj_strcpy(&fe->cfg.prompt_str, &param->prompt_str); 
    165     }     
    166     fe->cfg.prompt_str.ptr[fe->cfg.prompt_str.slen] = 0;  
     165    } 
     166    fe->cfg.prompt_str.ptr[fe->cfg.prompt_str.slen] = 0; 
    167167 
    168168    if (param->quit_command.slen) 
     
    184184    send_data.ptr = data_str; 
    185185    send_data.slen = 0; 
    186      
     186 
    187187    pj_strcat(&send_data, &fe->cfg.prompt_str); 
    188188    send_data.ptr[send_data.slen] = 0; 
     
    191191} 
    192192 
    193 static void send_err_arg(pj_cli_sess *sess,  
    194                          const pj_cli_exec_info *info,  
     193static void send_err_arg(pj_cli_sess *sess, 
     194                         const pj_cli_exec_info *info, 
    195195                         const pj_str_t *msg, 
    196196                         pj_bool_t with_return) 
     
    219219 
    220220    send_data.ptr[send_data.slen] = 0; 
    221     printf("%s", send_data.ptr);     
    222 } 
    223  
    224 static void send_inv_arg(pj_cli_sess *sess,  
     221    printf("%s", send_data.ptr); 
     222} 
     223 
     224static void send_inv_arg(pj_cli_sess *sess, 
    225225                         const pj_cli_exec_info *info, 
    226226                         pj_bool_t with_return) 
     
    230230} 
    231231 
    232 static void send_too_many_arg(pj_cli_sess *sess,  
     232static void send_too_many_arg(pj_cli_sess *sess, 
    233233                              const pj_cli_exec_info *info, 
    234234                              pj_bool_t with_return) 
     
    238238} 
    239239 
    240 static void send_hint_arg(pj_str_t *send_data,  
     240static void send_hint_arg(pj_str_t *send_data, 
    241241                          const pj_str_t *desc, 
    242242                          pj_ssize_t cmd_len, 
     
    257257} 
    258258 
    259 static void send_ambi_arg(pj_cli_sess *sess,  
     259static void send_ambi_arg(pj_cli_sess *sess, 
    260260                          const pj_cli_exec_info *info, 
    261261                          pj_bool_t with_return) 
     
    270270    pj_ssize_t max_length = 0; 
    271271    pj_ssize_t cmd_length = 0; 
    272     const pj_str_t *cmd_desc = 0; 
    273272    static const pj_str_t sc_type = {"sc", 2}; 
    274273    static const pj_str_t choice_type = {"choice", 6}; 
    275274    send_data.ptr = data; 
    276275    send_data.slen = 0; 
    277      
     276 
    278277    if (with_return) 
    279278        pj_strcat2(&send_data, "\r\n"); 
     
    284283        pj_strcat2(&send_data, " "); 
    285284    } 
    286     pj_strcat2(&send_data, "^");         
     285    pj_strcat2(&send_data, "^"); 
    287286    /* Get the max length of the command name */ 
    288287    for (i=0;i<info->hint_cnt;++i) { 
    289         if ((&hint[i].type) && (hint[i].type.slen > 0)) {            
    290             if (pj_stricmp(&hint[i].type, &sc_type) == 0) {              
     288        if ((&hint[i].type) && (hint[i].type.slen > 0)) { 
     289            if (pj_stricmp(&hint[i].type, &sc_type) == 0) { 
    291290                if ((i > 0) && (!pj_stricmp(&hint[i-1].desc, &hint[i].desc))) { 
    292291                    cmd_length += (hint[i].name.slen + 3); 
    293292                } else { 
    294293                    cmd_length = hint[i].name.slen; 
    295                 }                
     294                } 
    296295            } else { 
    297296                cmd_length = hint[i].name.slen; 
    298297            } 
    299         } else {                     
     298        } else { 
    300299            cmd_length = hint[i].name.slen; 
    301300        } 
     
    308307    cmd_length = 0; 
    309308    for (i=0;i<info->hint_cnt;++i) { 
    310         if ((&hint[i].type) && (hint[i].type.slen > 0)) {            
     309        if ((&hint[i].type) && (hint[i].type.slen > 0)) { 
    311310            if (pj_stricmp(&hint[i].type, &sc_type) == 0) { 
    312311                parse_state = OP_SHORTCUT; 
     
    316315                parse_state = OP_TYPE; 
    317316            } 
    318         } else {                     
     317        } else { 
    319318            parse_state = OP_NORMAL; 
    320319        } 
     
    324323            cmd_length = hint[i].name.slen; 
    325324        } 
    326      
     325 
    327326        switch (parse_state) { 
    328327        case OP_CHOICE: 
    329328            pj_strcat2(&send_data, "["); 
    330329            pj_strcat(&send_data, &hint[i].name); 
    331             pj_strcat2(&send_data, "]");         
     330            pj_strcat2(&send_data, "]"); 
    332331            break; 
    333332        case OP_TYPE: 
    334333            pj_strcat2(&send_data, "<"); 
    335334            pj_strcat(&send_data, &hint[i].type); 
    336             pj_strcat2(&send_data, ">");         
     335            pj_strcat2(&send_data, ">"); 
    337336            break; 
    338337        case OP_SHORTCUT: 
    339338            /* Format : "Command | sc |  description" */ 
    340             {            
     339            { 
    341340                cmd_length += hint[i].name.slen; 
    342341                if ((i > 0) && (!pj_stricmp(&hint[i-1].desc, &hint[i].desc))) { 
    343342                    pj_strcat2(&send_data, " | "); 
    344                     cmd_length += 3;                 
     343                    cmd_length += 3; 
    345344                } else { 
    346345                    pj_strcat2(&send_data, "\r\n  "); 
    347346                } 
    348                 pj_strcat(&send_data, &hint[i].name);    
     347                pj_strcat(&send_data, &hint[i].name); 
    349348            } 
    350349            break; 
    351350        default: 
    352351            pj_strcat(&send_data, &hint[i].name); 
    353             cmd_desc = &hint[i].desc; 
    354352            break; 
    355353        } 
    356          
    357         if ((parse_state == OP_TYPE) || (parse_state == OP_CHOICE) ||  
     354 
     355        if ((parse_state == OP_TYPE) || (parse_state == OP_CHOICE) || 
    358356            ((i+1) >= info->hint_cnt) || 
    359             (pj_strncmp(&hint[i].desc, &hint[i+1].desc, hint[i].desc.slen)))  
     357            (pj_strncmp(&hint[i].desc, &hint[i+1].desc, hint[i].desc.slen))) 
    360358        { 
    361359            /* Add description info */ 
     
    364362            cmd_length = 0; 
    365363        } 
    366     }   
     364    } 
    367365    pj_strcat2(&send_data, "\r\n"); 
    368366    pj_strcat(&send_data, &fe->cfg.prompt_str); 
    369367    send_data.ptr[send_data.slen] = 0; 
    370     printf("%s", send_data.ptr);     
     368    printf("%s", send_data.ptr); 
    371369} 
    372370 
     
    375373    pj_status_t status; 
    376374    pj_bool_t retval = PJ_TRUE; 
    377      
     375 
    378376    pj_pool_t *pool; 
    379377    pj_cli_cmd_val *cmd_val; 
     
    388386 
    389387    cmd_val = PJ_POOL_ZALLOC_T(pool, pj_cli_cmd_val); 
    390      
    391     status = pj_cli_sess_parse(sess, recv_buf, cmd_val,  
     388 
     389    status = pj_cli_sess_parse(sess, recv_buf, cmd_val, 
    392390                               pool, &info); 
    393391 
    394392    switch (status) { 
    395393    case PJ_CLI_EINVARG: 
    396         send_inv_arg(sess, &info, PJ_TRUE);              
     394        send_inv_arg(sess, &info, PJ_TRUE); 
    397395        break; 
    398396    case PJ_CLI_ETOOMANYARGS: 
     
    403401        send_ambi_arg(sess, &info, PJ_TRUE); 
    404402        break; 
    405     case PJ_SUCCESS:     
    406         if (info.hint_cnt > 0) {         
    407             /* Compelete command */          
    408             send_ambi_arg(sess, &info, PJ_TRUE);                         
     403    case PJ_SUCCESS: 
     404        if (info.hint_cnt > 0) { 
     405            /* Compelete command */ 
     406            send_ambi_arg(sess, &info, PJ_TRUE); 
    409407        } else { 
    410408            retval = PJ_FALSE; 
    411         }        
    412         break; 
    413     } 
    414  
    415     pj_pool_release(pool);       
    416     return retval;  
     409        } 
     410        break; 
     411    } 
     412 
     413    pj_pool_release(pool); 
     414    return retval; 
    417415} 
    418416 
     
    421419    pj_status_t status; 
    422420    pj_bool_t retval = PJ_TRUE; 
    423      
    424     pj_pool_t *pool;     
     421 
     422    pj_pool_t *pool; 
    425423    pj_cli_exec_info info; 
    426424    pj_cli_t *cli = sess->fe->cli; 
    427425    struct cli_console_fe *fe = (struct cli_console_fe *)sess->fe; 
    428426    char *recv_buf = fe->input.buf; 
    429          
     427 
    430428    printf("\r\n"); 
    431429 
    432430    pool = pj_pool_create(pj_cli_get_param(cli)->pf, "handle_exec", 
    433431                          PJ_CLI_CONSOLE_POOL_SIZE, PJ_CLI_CONSOLE_POOL_INC, 
    434                           NULL);     
    435      
    436     status = pj_cli_sess_exec(sess, recv_buf,  
     432                          NULL); 
     433 
     434    status = pj_cli_sess_exec(sess, recv_buf, 
    437435                              pool, &info); 
    438436 
    439437    switch (status) { 
    440438    case PJ_CLI_EINVARG: 
    441         send_inv_arg(sess, &info, PJ_FALSE);     
     439        send_inv_arg(sess, &info, PJ_FALSE); 
    442440        break; 
    443441    case PJ_CLI_ETOOMANYARGS: 
     
    452450        break; 
    453451    case PJ_SUCCESS: 
    454         send_prompt_str(sess);   
    455         break; 
    456     }     
    457  
    458     pj_pool_release(pool);       
    459     return retval;  
     452        send_prompt_str(sess); 
     453        break; 
     454    } 
     455 
     456    pj_pool_release(pool); 
     457    return retval; 
    460458} 
    461459 
    462460static int readline_thread(void * p) 
    463 {     
     461{ 
    464462    struct cli_console_fe * fe = (struct cli_console_fe *)p; 
    465463 
     
    473471 
    474472        if (fgets(recv_buf, fe->input.maxlen, stdin) == NULL) { 
    475             /*  
     473            /* 
    476474             * Be friendly to users who redirect commands into 
    477475             * program, when file ends, resume with kbd. 
     
    488486                puts("Cannot switch back to console from file redirection"); 
    489487                if (fe->cfg.quit_command.slen) { 
    490                     pj_memcpy(recv_buf, fe->cfg.quit_command.ptr,  
     488                    pj_memcpy(recv_buf, fe->cfg.quit_command.ptr, 
    491489                              fe->input.maxlen); 
    492490                } 
    493                 recv_buf[fe->cfg.quit_command.slen] = '\0';              
     491                recv_buf[fe->cfg.quit_command.slen] = '\0'; 
    494492            } else { 
    495493                puts("Switched back to console from file redirection"); 
     
    506504            break; 
    507505        } 
    508         input_len = pj_ansi_strlen(fe->input.buf);       
     506        input_len = pj_ansi_strlen(fe->input.buf); 
    509507        if ((input_len > 1) && (fe->input.buf[input_len-2] == '?')) { 
    510508            fe->input.buf[input_len-1] = 0; 
     
    516514        } 
    517515 
    518         pj_sem_post(fe->input.sem);         
     516        pj_sem_post(fe->input.sem); 
    519517        pj_sem_wait(fe->thread_sem); 
    520     }     
     518    } 
    521519 
    522520    return 0; 
    523521} 
    524522 
    525 PJ_DEF(pj_status_t) pj_cli_console_process(pj_cli_sess *sess,  
     523PJ_DEF(pj_status_t) pj_cli_console_process(pj_cli_sess *sess, 
    526524                                           char *buf, 
    527525                                           unsigned maxlen) 
Note: See TracChangeset for help on using the changeset viewer.