Changes in / [b4ca0a9c:33fc3ae] in mainline
- Location:
- uspace
- Files:
-
- 2 edited
-
app/bdsh/cmds/modules/cat/cat.c (modified) (8 diffs)
-
srv/hid/console/console.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bdsh/cmds/modules/cat/cat.c
rb4ca0a9c r33fc3ae 62 62 static sysarg_t console_rows = 0; 63 63 static bool should_quit = false; 64 static bool dash_represents_stdin = false;65 64 66 65 static console_ctrl_t *console = NULL; … … 74 73 { "more", no_argument, 0, 'm' }, 75 74 { "hex", no_argument, 0, 'x' }, 76 { "stdin", no_argument, 0, 's' },77 75 { 0, 0, 0, 0 } 78 76 }; … … 95 93 " -m, --more Pause after each screen full\n" 96 94 " -x, --hex Print bytes as hex values\n" 97 " -s --stdin Treat `-' in file list as standard input\n"98 95 "Currently, %s is under development, some options don't work.\n", 99 96 cmdname, cmdname); … … 175 172 off64_t file_size = 0, length = 0; 176 173 177 bool reading_stdin = dash_represents_stdin && (str_cmp(fname, "-") == 0); 178 179 if (reading_stdin) { 180 fd = fileno(stdin); 181 /* Allow storing the whole UTF-8 character. */ 182 blen = STR_BOUNDS(1); 183 } else { 184 fd = open(fname, O_RDONLY); 185 } 174 fd = open(fname, O_RDONLY); 186 175 if (fd < 0) { 187 176 printf("Unable to open %s\n", fname); … … 218 207 219 208 do { 220 size_t bytes_to_read; 221 if (reading_stdin) { 222 bytes_to_read = 1; 223 } else { 224 if ((length != CAT_FULL_FILE) 225 && (length - (off64_t)count <= (off64_t)(blen - copied_bytes))) { 226 bytes_to_read = (size_t) (length - count); 227 } else { 228 bytes_to_read = blen - copied_bytes; 229 } 230 } 231 bytes = read(fd, buff + copied_bytes, bytes_to_read); 209 bytes = read(fd, buff + copied_bytes, ( 210 (length != CAT_FULL_FILE && length - (off64_t)count <= (off64_t)(blen - copied_bytes)) ? 211 (size_t)(length - count) : 212 (blen - copied_bytes) ) ); 232 213 bytes += copied_bytes; 233 214 copied_bytes = 0; … … 261 242 reads++; 262 243 } 263 264 if (reading_stdin) {265 fflush(stdout);266 }267 244 } while (bytes > 0 && !should_quit && (count < length || length == CAT_FULL_FILE)); 268 245 … … 307 284 308 285 for (c = 0, optind = 0, opt_ind = 0; c != -1;) { 309 c = getopt_long(argc, argv, "xhvmH:t:b: s", long_options, &opt_ind);286 c = getopt_long(argc, argv, "xhvmH:t:b:", long_options, &opt_ind); 310 287 switch (c) { 311 288 case 'h': … … 341 318 hex = true; 342 319 break; 343 case 's':344 dash_represents_stdin = true;345 break;346 320 } 347 321 } -
uspace/srv/hid/console/console.c
rb4ca0a9c r33fc3ae 76 76 } console_state_t; 77 77 78 #define UTF8_CHAR_BUFFER_SIZE (STR_BOUNDS(1) + 1)79 80 78 typedef struct { 81 79 atomic_t refcnt; /**< Connection reference count */ 82 80 prodcons_t input_pc; /**< Incoming keyboard events */ 83 char char_remains[UTF8_CHAR_BUFFER_SIZE]; /**< Not yet sent bytes of last char event. */84 size_t char_remains_len; /**< Number of not yet sent bytes. */85 81 86 82 fibril_mutex_t mtx; /**< Lock protecting mutable fields */ … … 617 613 618 614 size_t pos = 0; 619 620 /*621 * Read input from keyboard and copy it to the buffer.622 * We need to handle situation when wchar is split by 2 following623 * reads.624 */625 615 while (pos < size) { 626 /* Copy to the buffer remaining characters. */ 627 while ((pos < size) && (cons->char_remains_len > 0)) { 628 buf[pos] = cons->char_remains[0]; 616 link_t *link = prodcons_consume(&cons->input_pc); 617 kbd_event_t *event = list_get_instance(link, kbd_event_t, link); 618 619 if (event->type == KEY_PRESS) { 620 buf[pos] = event->c; 629 621 pos++; 630 /* Unshift the array. */ 631 for (size_t i = 1; i < cons->char_remains_len; i++) { 632 cons->char_remains[i - 1] = cons->char_remains[i]; 633 } 634 cons->char_remains_len--; 635 } 636 /* Still not enough? Then get another key from the queue. */ 637 if (pos < size) { 638 link_t *link = prodcons_consume(&cons->input_pc); 639 kbd_event_t *event = list_get_instance(link, kbd_event_t, link); 640 641 /* Accept key presses of printable chars only. */ 642 if ((event->type == KEY_PRESS) && (event->c != 0)) { 643 wchar_t tmp[2] = { event->c, 0 }; 644 wstr_to_str(cons->char_remains, UTF8_CHAR_BUFFER_SIZE, tmp); 645 cons->char_remains_len = str_size(cons->char_remains); 646 } 647 648 free(event); 649 } 622 } 623 624 free(event); 650 625 } 651 626 … … 955 930 fibril_mutex_initialize(&consoles[i].mtx); 956 931 prodcons_initialize(&consoles[i].input_pc); 957 consoles[i].char_remains_len = 0;958 932 959 933 if (graphics_state == GRAPHICS_FULL) {
Note:
See TracChangeset
for help on using the changeset viewer.
