Changeset 00aece0 in mainline for uspace/app/bdsh/compl.c


Ignore:
Timestamp:
2012-02-18T16:47:38Z (13 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
4449c6c
Parents:
bd5f3b7 (diff), f943dd3 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/bdsh/compl.c

    rbd5f3b7 r00aece0  
    9090{
    9191        compl_t *cs = NULL;
    92         size_t pref_size;
    9392        char *stext = NULL;
    9493        char *prefix = NULL;
    9594        char *dirname = NULL;
     95        int retval;
     96       
     97        token_t *tokens = calloc(WORD_MAX, sizeof(token_t));
     98        if (tokens == NULL) {
     99                retval = ENOMEM;
     100                goto error;
     101        }
     102       
     103        size_t pref_size;
    96104        char *rpath_sep;
    97105        static const char *dirlist_arg[] = { ".", NULL };
    98         int retval;
    99106        tokenizer_t tok;
    100         token_t tokens[WORD_MAX];
    101         int current_token;
     107        ssize_t current_token;
    102108        size_t tokens_length;
    103 
     109       
    104110        cs = calloc(1, sizeof(compl_t));
    105111        if (!cs) {
     
    107113                goto error;
    108114        }
    109 
     115       
    110116        /* Convert text buffer to string */
    111117        stext = wstr_to_astr(text);
     
    127133       
    128134        /* Find the current token */
    129         for (current_token = 0; current_token < (int) tokens_length;
     135        for (current_token = 0; current_token < (ssize_t) tokens_length;
    130136            current_token++) {
    131137                token_t *t = &tokens[current_token];
    132138                size_t end = t->char_start + t->char_length;
    133                 /* Check if the caret lies inside the token or immediately
     139               
     140                /*
     141                 * Check if the caret lies inside the token or immediately
    134142                 * after it
    135143                 */
     
    138146                }
    139147        }
    140         if (tokens_length == 0) current_token = -1;
    141        
    142         if (current_token >= 0 && tokens[current_token].type != TOKTYPE_SPACE) {
     148       
     149        if (tokens_length == 0)
     150                current_token = -1;
     151       
     152        if ((current_token >= 0) && (tokens[current_token].type != TOKTYPE_SPACE))
    143153                *cstart = tokens[current_token].char_start;
    144         }
    145         else {
     154        else
    146155                *cstart = pos;
    147         }
    148        
    149         /* Extract the prefix being completed
     156       
     157        /*
     158         * Extract the prefix being completed
    150159         * XXX: handle strings, etc.
    151160         */
     
    170179
    171180        /* Skip any whitespace before current token */
    172         int prev_token = current_token - 1;
    173         if (prev_token >= 0 && tokens[prev_token].type == TOKTYPE_SPACE) {
     181        ssize_t prev_token = current_token - 1;
     182        if ((prev_token >= 0) && (tokens[prev_token].type == TOKTYPE_SPACE))
    174183                prev_token--;
    175         }
    176 
     184       
    177185        /*
    178186         * It is a command if it is the first token or if it immediately
    179187         * follows a pipe token.
    180188         */
    181         if (prev_token < 0 || tokens[prev_token].type == TOKTYPE_SPACE)
     189        if ((prev_token < 0) || (tokens[prev_token].type == TOKTYPE_SPACE))
    182190                cs->is_command = true;
    183191        else
     
    254262        if (cs != NULL)
    255263                free(cs);
     264        if (tokens != NULL)
     265                free(tokens);
    256266
    257267        return retval;
Note: See TracChangeset for help on using the changeset viewer.