Changeset a20a451 in mainline


Ignore:
Timestamp:
2018-11-30T09:40:48Z (5 years ago)
Author:
Matthieu Riolo <matthieu.riolo@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
87ba3ceb
Parents:
c483fca
Message:

adding options for single column output and human readable sizes

Location:
uspace/app/bdsh/cmds/modules/ls
Files:
2 edited

Legend:

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

    rc483fca ra20a451  
    4242#include <vfs/vfs.h>
    4343#include <str.h>
     44#include <cap.h>
    4445
    4546#include "ls.h"
     
    5859        { "unsort", no_argument, 0, 'u' },
    5960        { "recursive", no_argument, 0, 'r' },
     61        { "well-formatted", no_argument, 0, 'w' },
     62        { "single-column", no_argument, 0, '1' },
    6063        { 0, 0, 0, 0 }
    6164};
     
    7477        ls->sort = 1;
    7578
     79        ls->well_formatted = false;
     80        ls->single_column = false;
     81
    7682        return 1;
    7783}
     
    9096static void ls_print(struct dir_elem_t *de)
    9197{
    92         if (de->s.is_file)
     98        if (!ls.single_column && de->s.is_file) {
     99                if (ls.well_formatted) {
     100                        cap_spec_t cap;
     101
     102                        cap_from_blocks(1, de->s.size, &cap);
     103                        cap_simplify(&cap);
     104
     105                        char *rptr;
     106                        if (cap_format(&cap, &rptr) == EOK) {
     107                                printf("%-40s\t%s\n", de->name, rptr);
     108                                free(rptr);
     109                                //if there is a failure with cap_format we simply print out an unformatted size
     110                                return;
     111                        }
     112
     113                }
     114
    93115                printf("%-40s\t%llu\n", de->name, (long long) de->s.size);
    94         else if (de->s.is_directory)
     116        } else if (!ls.single_column && de->s.is_directory)
    95117                printf("%-40s\t<dir>\n", de->name);
    96118        else
     
    364386
    365387        while (c != -1) {
    366                 c = getopt_long(argc, argv, "hur", long_options, &opt_ind);
     388                c = getopt_long(argc, argv, "hurw1", long_options, &opt_ind);
    367389                switch (c) {
    368390                case 'h':
     
    374396                case 'r':
    375397                        ls.recursive = 1;
     398                        break;
     399                case 'w':
     400                        ls.well_formatted = true;
     401                        break;
     402                case '1':
     403                        ls.single_column = true;
    376404                        break;
    377405                }
  • uspace/app/bdsh/cmds/modules/ls/ls.h

    rc483fca ra20a451  
    1414        unsigned int sort;
    1515
     16        bool single_column;
     17        bool well_formatted;
    1618} ls_job_t;
    1719
Note: See TracChangeset for help on using the changeset viewer.