Changeset f1b37d6 in mainline


Ignore:
Timestamp:
2009-12-05T17:13:33Z (14 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
cedd33b
Parents:
2a5af223
Message:

Make paste more efficient.

File:
1 edited

Legend:

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

    r2a5af223 rf1b37d6  
    3939#include <vfs/vfs.h>
    4040#include <clipboard.h>
     41#include <macros.h>
    4142#include <errno.h>
    4243#include <assert.h>
     
    8687
    8788static char *tinput_read(tinput_t *ti);
     89static void tinput_insert_string(tinput_t *ti, const char *str);
    8890static void tinput_sel_get_bounds(tinput_t *ti, int *sa, int *sb);
    8991static bool tinput_sel_active(tinput_t *ti);
     
    245247}
    246248
     249static void tinput_insert_string(tinput_t *ti, const char *str)
     250{
     251        int i;
     252        int new_width, new_height;
     253        int ilen;
     254        wchar_t c;
     255        size_t off;
     256
     257        ilen = min(str_length(str), INPUT_MAX - ti->nc);
     258        if (ilen == 0)
     259                return;
     260
     261        new_width = ti->col0 + ti->nc + ilen;
     262        new_height = (new_width / ti->con_cols) + 1;
     263        if (new_height >= ti->con_rows)
     264                return; /* Disallow text longer than 1 page for now. */
     265
     266        for (i = ti->nc - 1; i >= ti->pos; --i)
     267                ti->buffer[i + ilen] = ti->buffer[i];
     268
     269        off = 0; i = 0;
     270        while (i < ilen) {
     271                c = str_decode(str, &off, STR_NO_LIMIT);
     272                if (c == '\0')
     273                        break;
     274
     275                /* Filter out non-printable chars. */
     276                if (c < 32)
     277                        c = 32;
     278
     279                ti->buffer[i++] = c;
     280        }
     281
     282        ti->pos += ilen;
     283        ti->nc += ilen;
     284        ti->buffer[ti->nc] = '\0';
     285        ti->sel_start = ti->pos;
     286
     287        tinput_display_tail(ti, ti->pos - ilen, 0);
     288        tinput_update_origin(ti);
     289        tinput_position_caret(ti);
     290}
     291
    247292static void tinput_backspace(tinput_t *ti)
    248293{
     
    484529{
    485530        char *str;
    486         size_t off;
    487         wchar_t c;
    488531        int rc;
    489532
     
    492535                return; /* TODO: Give the user some warning. */
    493536
    494         off = 0;
    495 
    496         while (true) {
    497                 c = str_decode(str, &off, STR_NO_LIMIT);
    498                 if (c == '\0')
    499                         break;
    500 
    501                 tinput_insert_char(ti, c);
    502         }
    503 
     537        tinput_insert_string(ti, str);
    504538        free(str);
    505539}
Note: See TracChangeset for help on using the changeset viewer.