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