Ignore:
Timestamp:
2011-05-01T19:34:26Z (13 years ago)
Author:
Martin Sucha <sucha14@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
0e26444
Parents:
1ff896e (diff), 042fbe0 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/bdsh/cmds/modules/cat/cat.c

    r1ff896e r694ca93f  
    3939#include <io/color.h>
    4040#include <io/style.h>
     41#include <io/keycode.h>
    4142#include <errno.h>
    4243#include <vfs/vfs.h>
     
    6263static sysarg_t console_cols = 0;
    6364static sysarg_t console_rows = 0;
     65static bool should_quit = false;
    6466
    6567static struct option const long_options[] = {
     
    102104        console_set_pos(fphone(stdout), 0, console_rows-1);
    103105        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");
    105108        fflush(stdout);
    106109        console_set_style(fphone(stdout), STYLE_NORMAL);
     
    116119                }
    117120                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                        }
    119133                }
    120134        }
     
    150164{
    151165        int fd, bytes = 0, count = 0, reads = 0;
    152         off64_t total = 0;
    153166        char *buff = NULL;
    154167        int i;
     
    160173                return 1;
    161174        }
    162 
    163         total = lseek(fd, 0, SEEK_END);
    164         lseek(fd, 0, SEEK_SET);
    165175
    166176        if (NULL == (buff = (char *) malloc(blen + 1))) {
     
    177187                        buff[bytes] = '\0';
    178188                        offset = 0;
    179                         for (i = 0; i < bytes; i++) {
     189                        for (i = 0; i < bytes && !should_quit; i++) {
    180190                                if (hex) {
    181191                                        paged_char(hexchars[((uint8_t)buff[i])/16]);
     
    185195                                        wchar_t c = str_decode(buff, &offset, bytes);
    186196                                        if (c == 0) {
    187                                                 // reached end of string
     197                                                /* Reached end of string */
    188198                                                break;
    189199                                        }
     
    194204                        reads++;
    195205                }
    196         } while (bytes > 0);
     206        } while (bytes > 0 && !should_quit);
    197207
    198208        close(fd);
     
    218228        int rc;
    219229       
    220         // reset global state
    221         // TODO: move to structure?
     230        /*
     231         * reset global state
     232         * TODO: move to structure?
     233         */
    222234        paging_enabled = false;
    223235        chars_remaining = 0;
     
    225237        console_cols = 0;
    226238        console_rows = 0;
     239        should_quit = false;
    227240
    228241        argc = cli_count_args(argv);
     
    278291        }
    279292
    280         for (i = optind; argv[i] != NULL; i++)
     293        for (i = optind; argv[i] != NULL && !should_quit; i++)
    281294                ret += cat_file(argv[i], buffer, hex);
    282295
Note: See TracChangeset for help on using the changeset viewer.