Changes in uspace/app/bdsh/cmds/modules/cat/cat.c [07b7c48:cc9f314] in mainline
- File:
-
- 1 edited
-
uspace/app/bdsh/cmds/modules/cat/cat.c (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bdsh/cmds/modules/cat/cat.c
r07b7c48 rcc9f314 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); … … 117 114 static void waitkey() 118 115 { 119 cons_event_t ev; 120 kbd_event_t *kev; 116 kbd_event_t ev; 121 117 122 118 while (true) { 123 if (!console_get_ event(console, &ev)) {119 if (!console_get_kbd_event(console, &ev)) { 124 120 return; 125 121 } 126 if (ev.type == CEV_KEY && ev.ev.key.type == KEY_PRESS) { 127 kev = &ev.ev.key; 128 129 if (kev->key == KC_ESCAPE || kev->key == KC_Q) { 122 if (ev.type == KEY_PRESS) { 123 if (ev.key == KC_ESCAPE || ev.key == KC_Q) { 130 124 should_quit = true; 131 125 return; 132 126 } 133 if ( kev->key == KC_C) {127 if (ev.key == KC_C) { 134 128 paging_enabled = false; 135 129 return; 136 130 } 137 if ( kev->key == KC_ENTER || kev->key == KC_SPACE ||138 kev->key == KC_PAGE_DOWN) {131 if (ev.key == KC_ENTER || ev.key == KC_SPACE || 132 ev.key == KC_PAGE_DOWN) { 139 133 return; 140 134 } … … 178 172 off64_t file_size = 0, length = 0; 179 173 180 bool reading_stdin = dash_represents_stdin && (str_cmp(fname, "-") == 0); 181 182 if (reading_stdin) { 183 fd = fileno(stdin); 184 /* Allow storing the whole UTF-8 character. */ 185 blen = STR_BOUNDS(1); 186 } else 187 fd = open(fname, O_RDONLY); 188 174 fd = open(fname, O_RDONLY); 189 175 if (fd < 0) { 190 176 printf("Unable to open %s\n", fname); … … 221 207 222 208 do { 223 size_t bytes_to_read; 224 if (reading_stdin) { 225 bytes_to_read = 1; 226 } else { 227 if ((length != CAT_FULL_FILE) && 228 (length - (off64_t)count <= (off64_t)(blen - copied_bytes))) { 229 bytes_to_read = (size_t) (length - count); 230 } else { 231 bytes_to_read = blen - copied_bytes; 232 } 233 } 234 235 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) ) ); 236 213 bytes += copied_bytes; 237 214 copied_bytes = 0; … … 265 242 reads++; 266 243 } 267 268 if (reading_stdin)269 fflush(stdout);270 244 } while (bytes > 0 && !should_quit && (count < length || length == CAT_FULL_FILE)); 271 245 … … 310 284 311 285 for (c = 0, optind = 0, opt_ind = 0; c != -1;) { 312 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); 313 287 switch (c) { 314 288 case 'h': … … 344 318 hex = true; 345 319 break; 346 case 's':347 dash_represents_stdin = true;348 break;349 320 } 350 321 }
Note:
See TracChangeset
for help on using the changeset viewer.
