Changes in uspace/app/bdsh/cmds/modules/cat/cat.c [cc9f314:07b7c48] 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
rcc9f314 r07b7c48 62 62 static sysarg_t console_rows = 0; 63 63 static bool should_quit = false; 64 static bool dash_represents_stdin = false; 64 65 65 66 static console_ctrl_t *console = NULL; … … 73 74 { "more", no_argument, 0, 'm' }, 74 75 { "hex", no_argument, 0, 'x' }, 76 { "stdin", no_argument, 0, 's' }, 75 77 { 0, 0, 0, 0 } 76 78 }; … … 93 95 " -m, --more Pause after each screen full\n" 94 96 " -x, --hex Print bytes as hex values\n" 97 " -s --stdin Treat `-' in file list as standard input\n" 95 98 "Currently, %s is under development, some options don't work.\n", 96 99 cmdname, cmdname); … … 114 117 static void waitkey() 115 118 { 116 kbd_event_t ev; 119 cons_event_t ev; 120 kbd_event_t *kev; 117 121 118 122 while (true) { 119 if (!console_get_ kbd_event(console, &ev)) {123 if (!console_get_event(console, &ev)) { 120 124 return; 121 125 } 122 if (ev.type == KEY_PRESS) { 123 if (ev.key == KC_ESCAPE || ev.key == KC_Q) { 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) { 124 130 should_quit = true; 125 131 return; 126 132 } 127 if ( ev.key == KC_C) {133 if (kev->key == KC_C) { 128 134 paging_enabled = false; 129 135 return; 130 136 } 131 if ( ev.key == KC_ENTER || ev.key == KC_SPACE ||132 ev.key == KC_PAGE_DOWN) {137 if (kev->key == KC_ENTER || kev->key == KC_SPACE || 138 kev->key == KC_PAGE_DOWN) { 133 139 return; 134 140 } … … 172 178 off64_t file_size = 0, length = 0; 173 179 174 fd = open(fname, O_RDONLY); 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 175 189 if (fd < 0) { 176 190 printf("Unable to open %s\n", fname); … … 207 221 208 222 do { 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) ) ); 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); 213 236 bytes += copied_bytes; 214 237 copied_bytes = 0; … … 242 265 reads++; 243 266 } 267 268 if (reading_stdin) 269 fflush(stdout); 244 270 } while (bytes > 0 && !should_quit && (count < length || length == CAT_FULL_FILE)); 245 271 … … 284 310 285 311 for (c = 0, optind = 0, opt_ind = 0; c != -1;) { 286 c = getopt_long(argc, argv, "xhvmH:t:b: ", long_options, &opt_ind);312 c = getopt_long(argc, argv, "xhvmH:t:b:s", long_options, &opt_ind); 287 313 switch (c) { 288 314 case 'h': … … 318 344 hex = true; 319 345 break; 346 case 's': 347 dash_represents_stdin = true; 348 break; 320 349 } 321 350 }
Note:
See TracChangeset
for help on using the changeset viewer.
