Changeset 0296ee1 in mainline


Ignore:
Timestamp:
2018-12-08T14:50:11Z (5 years ago)
Author:
Matthieu Riolo <matthieu.riolo@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
41453d93
Parents:
a27e370
git-author:
Matthieu Riolo <matthieu.riolo@…> (2018-12-08 14:22:17)
git-committer:
Matthieu Riolo <matthieu.riolo@…> (2018-12-08 14:50:11)
Message:

making formatted output right justified

  • default is now always formatted, unformatted must be explicit stated
  • the formatted is now right justified
File:
1 edited

Legend:

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

    ra27e370 r0296ee1  
    5959        { "unsort", no_argument, 0, 'u' },
    6060        { "recursive", no_argument, 0, 'r' },
    61         { "well-formatted", no_argument, 0, 'w' },
     61        { "exact-size", no_argument, 0, 'e' },
    6262        { "single-column", no_argument, 0, '1' },
    6363        { 0, 0, 0, 0 }
     
    7979        ls->sort = 1;
    8080
    81         ls->well_formatted = false;
     81        ls->well_formatted = true;
    8282        ls->single_column = false;
    8383        ls->printer = ls_print;
     
    9898static void ls_print(struct dir_elem_t *de)
    9999{
     100        int width = 13;
    100101
    101102        if (de->s.is_file) {
     
    108109                        char *rptr;
    109110                        if (cap_format(&cap, &rptr) == EOK) {
    110                                 printf("%-40s\t%s\n", de->name, rptr);
     111                                char bytes[9], suffix[3];
     112                                sscanf(rptr, "%s %s", bytes, suffix);
    111113                                free(rptr);
     114
     115                                printf("%-40s\t%*s %2s\n", de->name, width - 3, bytes, suffix);
     116                               
    112117                                //if there is a failure with cap_format we simply print out an unformatted size
    113118                                return;
     
    116121                }
    117122
    118                 printf("%-40s\t%llu\n", de->name, (long long) de->s.size);
     123                printf("%-40s\t%*llu\n", de->name, width, (long long) de->s.size);
    119124        } else if (de->s.is_directory)
    120                 printf("%-40s\t<dir>\n", de->name);
     125                printf("%-40s\t%*s\n", de->name, width, "<dir>");
    121126        else
    122127                printf("%-40s\n", de->name);
     
    387392                    "  -u, --unsort          Do not sort directory entries\n"
    388393                    "  -r, --recursive       List subdirectories recursively\n"
    389                     "  -w, --well-formatted  File sizes will be formatted\n"
     394                    "  -e, --exact-size      File sizes will be unformatted (raw bytes count)\n"
    390395                    "  -1, --single-column   Only the names will be returned\n",
    391396                    cmdname);
     
    417422
    418423        while (c != -1) {
    419                 c = getopt_long(argc, argv, "hurw1", long_options, &opt_ind);
     424                c = getopt_long(argc, argv, "hure1", long_options, &opt_ind);
    420425                switch (c) {
    421426                case 'h':
     
    428433                        ls.recursive = 1;
    429434                        break;
    430                 case 'w':
    431                         ls.well_formatted = true;
     435                case 'e':
     436                        ls.well_formatted = false;
    432437                        break;
    433438                case '1':
Note: See TracChangeset for help on using the changeset viewer.