Changes in uspace/app/bdsh/cmds/modules/cat/cat.c [f2d665b4:28a3e74] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bdsh/cmds/modules/cat/cat.c
rf2d665b4 r28a3e74 39 39 #include <io/color.h> 40 40 #include <io/style.h> 41 #include <io/keycode.h> 41 42 #include <errno.h> 42 43 #include <vfs/vfs.h> … … 62 63 static sysarg_t console_cols = 0; 63 64 static sysarg_t console_rows = 0; 65 static bool should_quit = false; 64 66 65 67 static struct option const long_options[] = { … … 102 104 console_set_pos(fphone(stdout), 0, console_rows-1); 103 105 console_set_color(fphone(stdout), COLOR_BLUE, COLOR_WHITE, 0); 104 printf("Press any key to continue"); 106 printf("ENTER/SPACE/PAGE DOWN - next page, " 107 "ESC/Q - quit, C - continue unpaged"); 105 108 fflush(stdout); 106 109 console_set_style(fphone(stdout), STYLE_NORMAL); … … 116 119 } 117 120 if (ev.type == KEY_PRESS) { 118 return; 121 if (ev.key == KC_ESCAPE || ev.key == KC_Q) { 122 should_quit = true; 123 return; 124 } 125 if (ev.key == KC_C) { 126 paging_enabled = false; 127 return; 128 } 129 if (ev.key == KC_ENTER || ev.key == KC_SPACE || 130 ev.key == KC_PAGE_DOWN) { 131 return; 132 } 119 133 } 120 134 } … … 150 164 { 151 165 int fd, bytes = 0, count = 0, reads = 0; 152 off64_t total = 0;153 166 char *buff = NULL; 154 167 int i; … … 160 173 return 1; 161 174 } 162 163 total = lseek(fd, 0, SEEK_END);164 lseek(fd, 0, SEEK_SET);165 175 166 176 if (NULL == (buff = (char *) malloc(blen + 1))) { … … 177 187 buff[bytes] = '\0'; 178 188 offset = 0; 179 for (i = 0; i < bytes ; i++) {189 for (i = 0; i < bytes && !should_quit; i++) { 180 190 if (hex) { 181 191 paged_char(hexchars[((uint8_t)buff[i])/16]); … … 185 195 wchar_t c = str_decode(buff, &offset, bytes); 186 196 if (c == 0) { 187 / / reached end of string197 /* Reached end of string */ 188 198 break; 189 199 } … … 194 204 reads++; 195 205 } 196 } while (bytes > 0 );206 } while (bytes > 0 && !should_quit); 197 207 198 208 close(fd); … … 218 228 int rc; 219 229 220 // reset global state 221 // TODO: move to structure? 230 /* 231 * reset global state 232 * TODO: move to structure? 233 */ 222 234 paging_enabled = false; 223 235 chars_remaining = 0; … … 225 237 console_cols = 0; 226 238 console_rows = 0; 239 should_quit = false; 227 240 228 241 argc = cli_count_args(argv); … … 278 291 } 279 292 280 for (i = optind; argv[i] != NULL ; i++)293 for (i = optind; argv[i] != NULL && !should_quit; i++) 281 294 ret += cat_file(argv[i], buffer, hex); 282 295
Note:
See TracChangeset
for help on using the changeset viewer.