Changeset 8cc4ddb in mainline for uspace/app/bdsh/compl.c


Ignore:
Timestamp:
2011-08-28T21:16:54Z (13 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
0f0f8bc
Parents:
1a5b252 (diff), 36e2b55 (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

    r1a5b252 r8cc4ddb  
    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         unsigned 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 < tokens_length; current_token++) {
     135        for (current_token = 0; current_token < (ssize_t) tokens_length;
     136            current_token++) {
    130137                token_t *t = &tokens[current_token];
    131138                size_t end = t->char_start + t->char_length;
    132                 /* Check if the caret lies inside the token or immediately
     139               
     140                /*
     141                 * Check if the caret lies inside the token or immediately
    133142                 * after it
    134143                 */
     
    138147        }
    139148       
    140         if (tokens[current_token].type != TOKTYPE_SPACE) {
     149        if (tokens_length == 0)
     150                current_token = -1;
     151       
     152        if ((current_token >= 0) && (tokens[current_token].type != TOKTYPE_SPACE))
    141153                *cstart = tokens[current_token].char_start;
    142         }
    143         else {
     154        else
    144155                *cstart = pos;
    145         }
    146        
    147         /* Extract the prefix being completed
     156       
     157        /*
     158         * Extract the prefix being completed
    148159         * XXX: handle strings, etc.
    149160         */
     
    154165                goto error;
    155166        }
    156 
    157         str_ncpy(prefix, pref_size + 1, stext +
    158             tokens[current_token].byte_start, pref_size);
     167        prefix[pref_size] = 0;
     168
     169        if (current_token >= 0) {
     170                str_ncpy(prefix, pref_size + 1, stext +
     171                    tokens[current_token].byte_start, pref_size);
     172        }
    159173
    160174        /*
     
    165179
    166180        /* Skip any whitespace before current token */
    167         int prev_token = current_token - 1;
    168         if (prev_token != -1 && 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))
    169183                prev_token--;
    170         }
    171 
     184       
    172185        /*
    173186         * It is a command if it is the first token or if it immediately
    174187         * follows a pipe token.
    175188         */
    176         if (prev_token == -1 || tokens[prev_token].type == TOKTYPE_SPACE)
     189        if ((prev_token < 0) || (tokens[prev_token].type == TOKTYPE_SPACE))
    177190                cs->is_command = true;
    178191        else
     
    249262        if (cs != NULL)
    250263                free(cs);
     264        if (tokens != NULL)
     265                free(tokens);
    251266
    252267        return retval;
Note: See TracChangeset for help on using the changeset viewer.