Changes in uspace/app/bdsh/cmds/modules/cat/cat.c [a33706e:0845589] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bdsh/cmds/modules/cat/cat.c
ra33706e r0845589 63 63 static bool should_quit = false; 64 64 static bool dash_represents_stdin = false; 65 static unsigned int lineno = 0; 66 static bool number = false; 67 static bool last_char_was_newline = false; 65 68 66 69 static console_ctrl_t *console = NULL; … … 75 78 { "hex", no_argument, 0, 'x' }, 76 79 { "stdin", no_argument, 0, 's' }, 80 { "number", no_argument, 0, 'n' }, 77 81 { 0, 0, 0, 0 } 78 82 }; … … 95 99 " -m, --more Pause after each screen full\n" 96 100 " -x, --hex Print bytes as hex values\n" 97 " -s --stdin Treat `-' in file list as standard input\n" 101 " -s, --stdin Treat `-' in file list as standard input\n" 102 " -n, --number Number all output lines\n" 98 103 "Currently, %s is under development, some options don't work.\n", 99 104 cmdname, cmdname); … … 117 122 static void waitkey() 118 123 { 119 kbd_event_t ev; 124 cons_event_t ev; 125 kbd_event_t *kev; 120 126 121 127 while (true) { 122 if (!console_get_ kbd_event(console, &ev)) {128 if (!console_get_event(console, &ev)) { 123 129 return; 124 130 } 125 if (ev.type == KEY_PRESS) { 126 if (ev.key == KC_ESCAPE || ev.key == KC_Q) { 131 if (ev.type == CEV_KEY && ev.ev.key.type == KEY_PRESS) { 132 kev = &ev.ev.key; 133 134 if (kev->key == KC_ESCAPE || kev->key == KC_Q) { 127 135 should_quit = true; 128 136 return; 129 137 } 130 if ( ev.key == KC_C) {138 if (kev->key == KC_C) { 131 139 paging_enabled = false; 132 140 return; 133 141 } 134 if ( ev.key == KC_ENTER || ev.key == KC_SPACE ||135 ev.key == KC_PAGE_DOWN) {142 if (kev->key == KC_ENTER || kev->key == KC_SPACE || 143 kev->key == KC_PAGE_DOWN) { 136 144 return; 137 145 } … … 150 158 static void paged_char(wchar_t c) 151 159 { 160 if (last_char_was_newline && number) { 161 lineno++; 162 printf("%6u ", lineno); 163 } 152 164 putchar(c); 165 last_char_was_newline = c == '\n'; 153 166 if (paging_enabled) { 154 167 chars_remaining--; … … 176 189 177 190 bool reading_stdin = dash_represents_stdin && (str_cmp(fname, "-") == 0); 178 191 179 192 if (reading_stdin) { 180 193 fd = fileno(stdin); 181 194 /* Allow storing the whole UTF-8 character. */ 182 195 blen = STR_BOUNDS(1); 183 } else {196 } else 184 197 fd = open(fname, O_RDONLY); 185 }198 186 199 if (fd < 0) { 187 200 printf("Unable to open %s\n", fname); … … 222 235 bytes_to_read = 1; 223 236 } else { 224 if ((length != CAT_FULL_FILE) 225 &&(length - (off64_t)count <= (off64_t)(blen - copied_bytes))) {237 if ((length != CAT_FULL_FILE) && 238 (length - (off64_t)count <= (off64_t)(blen - copied_bytes))) { 226 239 bytes_to_read = (size_t) (length - count); 227 240 } else { … … 229 242 } 230 243 } 244 231 245 bytes = read(fd, buff + copied_bytes, bytes_to_read); 232 246 bytes += copied_bytes; … … 261 275 reads++; 262 276 } 263 264 if (reading_stdin) {277 278 if (reading_stdin) 265 279 fflush(stdout); 266 }267 280 } while (bytes > 0 && !should_quit && (count < length || length == CAT_FULL_FILE)); 268 281 … … 303 316 should_quit = false; 304 317 console = console_init(stdin, stdout); 318 number = false; 319 lineno = 0; 320 /* This enables printing of the first number. */ 321 last_char_was_newline = true; 322 305 323 306 324 argc = cli_count_args(argv); 307 325 308 326 for (c = 0, optind = 0, opt_ind = 0; c != -1;) { 309 c = getopt_long(argc, argv, "xhvmH:t:b:s ", long_options, &opt_ind);327 c = getopt_long(argc, argv, "xhvmH:t:b:s:n", long_options, &opt_ind); 310 328 switch (c) { 311 329 case 'h': … … 344 362 dash_represents_stdin = true; 345 363 break; 364 case 'n': 365 number = true; 366 break; 346 367 } 347 368 }
Note:
See TracChangeset
for help on using the changeset viewer.