Ignore:
File:
1 edited

Legend:

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

    r07b7c48 rcc9f314  
    6262static sysarg_t console_rows = 0;
    6363static bool should_quit = false;
    64 static bool dash_represents_stdin = false;
    6564
    6665static console_ctrl_t *console = NULL;
     
    7473        { "more", no_argument, 0, 'm' },
    7574        { "hex", no_argument, 0, 'x' },
    76         { "stdin", no_argument, 0, 's' },
    7775        { 0, 0, 0, 0 }
    7876};
     
    9593                "  -m, --more       Pause after each screen full\n"
    9694                "  -x, --hex        Print bytes as hex values\n"
    97                 "  -s  --stdin      Treat `-' in file list as standard input\n"
    9895                "Currently, %s is under development, some options don't work.\n",
    9996                cmdname, cmdname);
     
    117114static void waitkey()
    118115{
    119         cons_event_t ev;
    120         kbd_event_t *kev;
     116        kbd_event_t ev;
    121117       
    122118        while (true) {
    123                 if (!console_get_event(console, &ev)) {
     119                if (!console_get_kbd_event(console, &ev)) {
    124120                        return;
    125121                }
    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) {
     122                if (ev.type == KEY_PRESS) {
     123                        if (ev.key == KC_ESCAPE || ev.key == KC_Q) {
    130124                                should_quit = true;
    131125                                return;
    132126                        }
    133                         if (kev->key == KC_C) {
     127                        if (ev.key == KC_C) {
    134128                                paging_enabled = false;
    135129                                return;
    136130                        }
    137                         if (kev->key == KC_ENTER || kev->key == KC_SPACE ||
    138                             kev->key == KC_PAGE_DOWN) {
     131                        if (ev.key == KC_ENTER || ev.key == KC_SPACE ||
     132                            ev.key == KC_PAGE_DOWN) {
    139133                                return;
    140134                        }
     
    178172        off64_t file_size = 0, length = 0;
    179173
    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        
     174        fd = open(fname, O_RDONLY);
    189175        if (fd < 0) {
    190176                printf("Unable to open %s\n", fname);
     
    221207
    222208        do {
    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);
     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) ) );
    236213                bytes += copied_bytes;
    237214                copied_bytes = 0;
     
    265242                        reads++;
    266243                }
    267                
    268                 if (reading_stdin)
    269                         fflush(stdout);
    270244        } while (bytes > 0 && !should_quit && (count < length || length == CAT_FULL_FILE));
    271245
     
    310284
    311285        for (c = 0, optind = 0, opt_ind = 0; c != -1;) {
    312                 c = getopt_long(argc, argv, "xhvmH:t:b:s", long_options, &opt_ind);
     286                c = getopt_long(argc, argv, "xhvmH:t:b:", long_options, &opt_ind);
    313287                switch (c) {
    314288                case 'h':
     
    344318                        hex = true;
    345319                        break;
    346                 case 's':
    347                         dash_represents_stdin = true;
    348                         break;
    349320                }
    350321        }
Note: See TracChangeset for help on using the changeset viewer.