Changeset a35b458 in mainline for uspace/app/bdsh


Ignore:
Timestamp:
2018-03-02T20:10:49Z (6 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f1380b7
Parents:
3061bc1
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2018-02-28 17:38:31)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2018-03-02 20:10:49)
Message:

style: Remove trailing whitespace on _all_ lines, including empty ones, for particular file types.

Command used: tools/srepl '\s\+$' '' -- *.c *.h *.py *.sh *.s *.S *.ag

Currently, whitespace on empty lines is very inconsistent.
There are two basic choices: Either remove the whitespace, or keep empty lines
indented to the level of surrounding code. The former is AFAICT more common,
and also much easier to do automatically.

Alternatively, we could write script for automatic indentation, and use that
instead. However, if such a script exists, it's possible to use the indented
style locally, by having the editor apply relevant conversions on load/save,
without affecting remote repository. IMO, it makes more sense to adopt
the simpler rule.

Location:
uspace/app/bdsh
Files:
17 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/bdsh/cmds/builtin_cmds.c

    r3061bc1 ra35b458  
    107107
    108108        cmd += builtin;
    109        
     109
    110110        iostate_t *old_iostate = get_iostate();
    111111        set_iostate(new_iostate);
    112        
     112
    113113        if (NULL != cmd->entry) {
    114114                rc = ((int)cmd->entry(argv, usr));
     
    116116                rc = CL_ENOENT;
    117117        }
    118        
     118
    119119        set_iostate(old_iostate);
    120120
  • uspace/app/bdsh/cmds/mod_cmds.c

    r3061bc1 ra35b458  
    129129
    130130        mod += module;
    131        
     131
    132132        iostate_t *old_iostate = get_iostate();
    133133        set_iostate(new_iostate);
     
    138138                rc = CL_ENOENT;
    139139        }
    140        
     140
    141141        set_iostate(old_iostate);
    142142
  • uspace/app/bdsh/cmds/modules/cat/cat.c

    r3061bc1 ra35b458  
    110110        console_set_pos(console, 0, console_rows-1);
    111111        console_set_color(console, COLOR_WHITE, COLOR_BLUE, 0);
    112        
     112
    113113        printf("ENTER/SPACE/PAGE DOWN - next page, "
    114114               "ESC/Q - quit, C - continue unpaged");
    115115        fflush(stdout);
    116        
     116
    117117        console_set_style(console, STYLE_NORMAL);
    118118}
     
    122122        cons_event_t ev;
    123123        kbd_event_t *kev;
    124        
     124
    125125        while (true) {
    126126                if (!console_get_event(console, &ev)) {
     
    129129                if (ev.type == CEV_KEY && ev.ev.key.type == KEY_PRESS) {
    130130                        kev = &ev.ev.key;
    131                        
     131
    132132                        if (kev->key == KC_ESCAPE || kev->key == KC_Q) {
    133133                                should_quit = true;
     
    190190
    191191        bool reading_stdin = dash_represents_stdin && (str_cmp(fname, "-") == 0);
    192        
     192
    193193        if (reading_stdin) {
    194194                fd = fileno(stdin);
     
    201201                }
    202202        }
    203        
     203
    204204        if (fd < 0) {
    205205                printf("Unable to open %s\n", fname);
     
    255255                        }
    256256                }
    257                
     257
    258258                rc = vfs_read(fd, &pos, buff + copied_bytes, bytes_to_read,
    259259                    &bytes);
     
    283283                                        paged_char(c);
    284284                                }
    285                                
     285
    286286                        }
    287287                        count += bytes;
    288288                        reads++;
    289289                }
    290                
     290
    291291                if (reading_stdin)
    292292                        fflush(stdout);
     
    317317        sysarg_t rows, cols;
    318318        errno_t rc;
    319        
     319
    320320        /*
    321321         * reset global state
     
    392392        if (buffer < 4)
    393393                buffer = CAT_DEFAULT_BUFLEN;
    394        
     394
    395395        if (more) {
    396396                rc = console_get_size(console, &cols, &rows);
  • uspace/app/bdsh/cmds/modules/cmp/cmp.c

    r3061bc1 ra35b458  
    120120        unsigned int argc;
    121121        int c, opt_ind;
    122        
     122
    123123        argc = cli_count_args(argv);
    124124
  • uspace/app/bdsh/cmds/modules/cp/cp.c

    r3061bc1 ra35b458  
    196196                str_cpy(src_path, src_len + 1, src);
    197197                str_rtrim(src_path, '/');
    198                
     198
    199199                /* Get the last component name from the src path */
    200200                src_fname = get_last_path_component(src_path);
    201                
     201
    202202                /* Initialize dest_path with the dest argument */
    203203                str_cpy(dest_path, PATH_MAX, dest);
     
    206206                        /* e.g. cp file_name /data */
    207207                        /* e.g. cp file_name /data/ */
    208                        
     208
    209209                        /* dest is a directory,
    210210                         * append the src filename to it.
  • uspace/app/bdsh/cmds/modules/kcon/kcon.c

    r3061bc1 ra35b458  
    4343{
    4444        printf("`kcon' switches to the kernel debug console.\n");
    45        
     45
    4646        if (level != HELP_SHORT)
    4747                printf("Usage: %s\n", cmdname);
    48        
     48
    4949        return;
    5050}
     
    5454{
    5555        unsigned int argc = cli_count_args(argv);
    56        
     56
    5757        if (argc != 1) {
    5858                printf("%s - incorrect number of arguments. Try `%s --help'\n",
     
    6060                return CMD_FAILURE;
    6161        }
    62        
     62
    6363        if (console_kcon())
    6464                return CMD_SUCCESS;
  • uspace/app/bdsh/cmds/modules/ls/ls.c

    r3061bc1 ra35b458  
    111111        struct dir_elem_t const *da = a;
    112112        struct dir_elem_t const *db = b;
    113        
     113
    114114        if ((da->s.is_directory && db->s.is_file) ||
    115115            ((da->s.is_directory == db->s.is_directory) &&
     
    141141        struct dir_elem_t *tosort;
    142142        struct dirent *dp;
    143        
     143
    144144        if (!dirp)
    145145                return -1;
     
    150150                return -1;
    151151        }
    152        
     152
    153153        tosort = (struct dir_elem_t *) malloc(alloc_blocks * sizeof(*tosort));
    154154        if (!tosort) {
     
    157157                return -1;
    158158        }
    159        
     159
    160160        while ((dp = readdir(dirp))) {
    161161                if (nbdirs + 1 > alloc_blocks) {
    162162                        alloc_blocks += alloc_blocks;
    163                        
     163
    164164                        tmp = (struct dir_elem_t *) realloc(tosort,
    165165                            alloc_blocks * sizeof(struct dir_elem_t));
     
    170170                        tosort = tmp;
    171171                }
    172                
     172
    173173                /* fill the name field */
    174174                tosort[nbdirs].name = (char *) malloc(str_size(dp->d_name) + 1);
     
    189189                }
    190190        }
    191        
     191
    192192        if (ls.sort)
    193193                qsort(&tosort[0], nbdirs, sizeof(struct dir_elem_t), ls_cmp);
    194        
     194
    195195        for (i = 0; i < nbdirs; i++)
    196196                ls_print(&tosort[i]);
     
    214214                }
    215215        }
    216        
     216
    217217out:
    218218        for(i = 0; i < nbdirs; i++)
     
    239239        DIR *subdirp;
    240240        struct dir_elem_t *dir_list;
    241        
     241
    242242        const char * const trailing_slash = "/";
    243243
     
    294294                }
    295295        }
    296    
     296
    297297        ret = CMD_SUCCESS;
    298298
     
    355355
    356356        argc = cli_count_args(argv);
    357        
     357
    358358        for (c = 0, optreset = 1, optind = 0, opt_ind = 0; c != -1;) {
    359359                c = getopt_long(argc, argv, "hur", long_options, &opt_ind);
  • uspace/app/bdsh/cmds/modules/mkfile/mkfile.c

    r3061bc1 ra35b458  
    171171        if (create_sparse && file_size > 0) {
    172172                const char byte = 0x00;
    173                
     173
    174174                pos = file_size - 1;
    175175                rc = vfs_write(fd, &pos, &byte, sizeof(char), &nwritten);
  • uspace/app/bdsh/cmds/modules/printf/printf.c

    r3061bc1 ra35b458  
    5555        }
    5656
    57        
     57
    5858        return;
    5959}
  • uspace/app/bdsh/cmds/modules/rm/rm.c

    r3061bc1 ra35b458  
    189189
    190190        closedir(dirp);
    191        
     191
    192192        return ret;
    193193}
  • uspace/app/bdsh/cmds/modules/touch/touch.c

    r3061bc1 ra35b458  
    6969                    cmdname);
    7070        }
    71        
     71
    7272        return;
    7373}
     
    8585        int fd = -1;
    8686        char *buff = NULL;
    87        
     87
    8888        DIR *dirp;
    89        
     89
    9090        for (c = 0, optreset = 1, optind = 0, longind = 0; c != -1; ) {
    9191                c = getopt_long(argc, argv, "c", long_options, &longind);
     
    9696                }
    9797        }
    98        
     98
    9999        if (argc - optind < 1) {
    100100                printf("%s: Incorrect number of arguments. Try `help %s extended'\n",
     
    102102                return CMD_FAILURE;
    103103        }
    104        
     104
    105105        for (i = optind; argv[i] != NULL; i++) {
    106106                buff = str_dup(argv[i]);
     
    110110                        continue;
    111111                }
    112                
     112
    113113                dirp = opendir(buff);
    114114                if (dirp) {
     
    119119                        continue;
    120120                }
    121                
     121
    122122                /* Check whether file exists if -c (--no-create) option is given */
    123123                if ((!no_create) ||
     
    128128                        }
    129129                }
    130                
     130
    131131                if (fd < 0) {
    132132                        cli_error(CL_EFAIL, "Could not update or create `%s'", buff);
     
    138138                        fd = -1;
    139139                }
    140                
     140
    141141                free(buff);
    142142        }
    143        
     143
    144144        if (ret)
    145145                return CMD_FAILURE;
  • uspace/app/bdsh/compl.c

    r3061bc1 ra35b458  
    9595        char *dirname = NULL;
    9696        errno_t retval;
    97        
     97
    9898        token_t *tokens = calloc(WORD_MAX, sizeof(token_t));
    9999        if (tokens == NULL) {
     
    101101                goto error;
    102102        }
    103        
     103
    104104        size_t pref_size;
    105105        char *rpath_sep;
     
    108108        ssize_t current_token;
    109109        size_t tokens_length;
    110        
     110
    111111        cs = calloc(1, sizeof(compl_t));
    112112        if (!cs) {
     
    114114                goto error;
    115115        }
    116        
     116
    117117        /* Convert text buffer to string */
    118118        stext = wstr_to_astr(text);
     
    121121                goto error;
    122122        }
    123        
     123
    124124        /* Tokenize the input string */
    125125        retval = tok_init(&tok, stext, tokens, WORD_MAX);
     
    127127                goto error;
    128128        }
    129        
     129
    130130        retval = tok_tokenize(&tok, &tokens_length);
    131131        if (retval != EOK) {
    132132                goto error;
    133133        }
    134        
     134
    135135        /* Find the current token */
    136136        for (current_token = 0; current_token < (ssize_t) tokens_length;
     
    138138                token_t *t = &tokens[current_token];
    139139                size_t end = t->char_start + t->char_length;
    140                
     140
    141141                /*
    142142                 * Check if the caret lies inside the token or immediately
     
    147147                }
    148148        }
    149        
     149
    150150        if (tokens_length == 0)
    151151                current_token = -1;
    152        
     152
    153153        if ((current_token >= 0) && (tokens[current_token].type != TOKTYPE_SPACE))
    154154                *cstart = tokens[current_token].char_start;
    155155        else
    156156                *cstart = pos;
    157        
     157
    158158        /*
    159159         * Extract the prefix being completed
     
    183183        if ((prev_token >= 0) && (tokens[prev_token].type == TOKTYPE_SPACE))
    184184                prev_token--;
    185        
     185
    186186        /*
    187187         * It is a command if it is the first token or if it immediately
     
    236236
    237237        cs->prefix_len = str_length(cs->prefix);
    238        
     238
    239239        tok_fini(&tok);
    240240
     
    244244error:
    245245        /* Error cleanup */
    246        
     246
    247247        tok_fini(&tok);
    248248
     
    258258        if ((cs != NULL) && (cs->prefix != NULL))
    259259                free(cs->prefix);
    260        
     260
    261261        if (dirname != NULL)
    262262                free(dirname);
    263        
     263
    264264        if (prefix != NULL)
    265265                free(prefix);
    266        
     266
    267267        if (stext != NULL)
    268268                free(stext);
    269        
     269
    270270        if (cs != NULL)
    271271                free(cs);
    272        
     272
    273273        if (tokens != NULL)
    274274                free(tokens);
  • uspace/app/bdsh/exec.c

    r3061bc1 ra35b458  
    105105        tmp = str_dup(find_command(cmd));
    106106        free(found);
    107        
     107
    108108        files[0] = io->stdin;
    109109        files[1] = io->stdout;
    110110        files[2] = io->stderr;
    111        
     111
    112112        for (i = 0; i < 3 && files[i] != NULL; i++) {
    113113                vfs_fhandle(files[i], &file_handles[i]);
     
    123123                return 1;
    124124        }
    125        
     125
    126126        rc = task_wait(&twait, &texit, &retval);
    127127        if (rc != EOK) {
  • uspace/app/bdsh/input.c

    r3061bc1 ra35b458  
    7171                return ENOMEM;
    7272        token_t *tokens = tokens_buf;
    73        
     73
    7474        char *cmd[WORD_MAX];
    7575        errno_t rc = EOK;
     
    8989                goto finit;
    9090        }
    91        
     91
    9292        size_t tokens_length;
    9393        rc = tok_tokenize(&tok, &tokens_length);
     
    9595                goto finit;
    9696        }
    97        
     97
    9898        if (tokens_length > 0 && tokens[0].type == TOKTYPE_SPACE) {
    9999                tokens++;
    100100                tokens_length--;
    101101        }
    102        
     102
    103103        if (tokens_length > 0 && tokens[tokens_length-1].type == TOKTYPE_SPACE) {
    104104                tokens_length--;
    105105        }
    106        
     106
    107107        /* Until full support for pipes is implemented, allow for a simple case:
    108108         * [from <file> |] command [| to <file>]
     
    121121                }
    122122        }
    123        
     123
    124124        unsigned int cmd_token_start = 0;
    125125        unsigned int cmd_token_end = tokens_length;
    126        
     126
    127127        processed_pipes = 0;
    128        
     128
    129129        /* Check if the first part (from <file> |) is present */
    130130        if (pipe_count > 0 && (pipe_pos[0] == 3 || pipe_pos[0] == 4) && str_cmp(tokens[0].text, "from") == 0) {
     
    134134                processed_pipes++;
    135135        }
    136        
     136
    137137        /* Check if the second part (| to <file>) is present */
    138138        if ((pipe_count - processed_pipes) > 0 &&
     
    146146                processed_pipes++;
    147147        }
    148        
     148
    149149        if (processed_pipes != pipe_count) {
    150150                print_pipe_usage();
     
    152152                goto finit;
    153153        }
    154        
     154
    155155        /* Convert tokens of the command to string array */
    156156        unsigned int cmd_pos = 0;
     
    161161        }
    162162        cmd[cmd_pos++] = NULL;
    163        
     163
    164164        if (cmd[0] == NULL) {
    165165                print_pipe_usage();
     
    167167                goto finit;
    168168        }
    169        
     169
    170170        iostate_t new_iostate = {
    171171                .stdin = stdin,
     
    173173                .stderr = stderr
    174174        };
    175        
     175
    176176        FILE *from = NULL;
    177177        FILE *to = NULL;
    178        
     178
    179179        if (redir_from) {
    180180                from = fopen(redir_from, "r");
     
    186186                new_iostate.stdin = from;
    187187        }
    188        
    189        
     188
     189
    190190        if (redir_to) {
    191191                to = fopen(redir_to, "w");
     
    203203                rc = EINVAL;
    204204        }
    205        
     205
    206206finit_with_files:
    207207        if (from != NULL) {
     
    211211                fclose(to);
    212212        }
    213        
     213
    214214finit:
    215215        if (NULL != usr->line) {
     
    230230        printf("from filename | command ... | to filename\n");
    231231        printf("command ... | to filename\n");
    232        
     232
    233233}
    234234
     
    236236{
    237237        int id = 0;
    238        
     238
    239239        /* We have rubbish */
    240240        if (NULL == cmd[0]) {
    241241                return CL_ENOENT;
    242242        }
    243        
     243
    244244        /* Is it a builtin command ? */
    245245        if ((id = (is_builtin(cmd[0]))) > -1) {
    246246                return run_builtin(id, cmd, usr, new_iostate);
    247247        }
    248        
     248
    249249        /* Is it a module ? */
    250250        if ((id = (is_module(cmd[0]))) > -1) {
     
    260260        char *str;
    261261        errno_t rc;
    262        
     262
    263263        tinput_set_prompt(tinput, usr->prompt);
    264264
  • uspace/app/bdsh/scli.c

    r3061bc1 ra35b458  
    9999{
    100100        errno_t ret = 0;
    101        
     101
    102102        stdiostate.stdin = stdin;
    103103        stdiostate.stdout = stdout;
  • uspace/app/bdsh/tok.c

    r3061bc1 ra35b458  
    5959        tok->in_char_offset = 0;
    6060        tok->last_in_char_offset = 0;
    61        
     61
    6262        tok->outtok = out_tokens;
    6363        tok->outtok_offset = 0;
    6464        tok->outtok_size = max_tokens;
    65        
     65
    6666        /* Prepare a buffer where all the token strings will be stored */
    6767        size_t len = str_size(input) + max_tokens + 1;
    6868        char *tmp = malloc(len);
    69        
     69
    7070        if (tmp == NULL) {
    7171                return ENOMEM;
    7272        }
    73        
     73
    7474        tok->outbuf = tmp;
    7575        tok->outbuf_offset = 0;
    7676        tok->outbuf_size = len;
    7777        tok->outbuf_last_start = 0;
    78        
     78
    7979        return EOK;
    8080}
     
    9393        errno_t rc;
    9494        wchar_t next_char;
    95        
     95
    9696        /* Read the input line char by char and append tokens */
    9797        while ((next_char = tok_look_char(tok)) != 0) {
     
    113113                        }
    114114                        tok_push_token(tok);
    115                        
     115
    116116                }
    117117                else if (next_char == '|') {
     
    125125                                }
    126126                        }
    127                        
     127
    128128                        tok_start_token(tok, TOKTYPE_PIPE);
    129                        
     129
    130130                        rc = tok_push_char(tok, tok_get_char(tok));
    131131                        if (rc != EOK) {
    132132                                return rc;
    133133                        }
    134                        
     134
    135135                        rc = tok_push_token(tok);
    136136                        if (rc != EOK) {
     
    163163                }
    164164        }
    165        
     165
    166166        /* Push the last token */
    167167        if (tok_pending_chars(tok)) {
     
    171171                }
    172172        }
    173        
     173
    174174        *tokens_length = tok->outtok_offset;
    175        
     175
    176176        return EOK;
    177177}
     
    182182        errno_t rc;
    183183        wchar_t next_char;
    184        
     184
    185185        while ((next_char = tok_look_char(tok)) != 0) {
    186186                if (next_char == '\'') {
     
    193193                                        return rc;
    194194                                }
    195                                
     195
    196196                                /* Swallow the additional one in the input */
    197197                                tok_get_char(tok);
     
    209209                }
    210210        }
    211        
     211
    212212        /* If we are here, the string run to the end without being closed */
    213213        return EINVAL;
     
    249249                return EOVERFLOW;
    250250        }
    251        
     251
    252252        if (tok->outbuf_offset >= tok->outbuf_size) {
    253253                return EOVERFLOW;
    254254        }
    255        
     255
    256256        tok->outbuf[tok->outbuf_offset++] = 0;
    257257        token_t *tokinfo = &tok->outtok[tok->outtok_offset++];
     
    263263        tokinfo->char_length = tok->in_char_offset - tok->last_in_char_offset;
    264264        tok->outbuf_last_start = tok->outbuf_offset;
    265        
     265
    266266        /* We have consumed the first char of the next token already */
    267267        tok->last_in_offset = tok->in_offset;
    268268        tok->last_in_char_offset = tok->in_char_offset;
    269        
     269
    270270        return EOK;
    271271}
  • uspace/app/bdsh/tok.h

    r3061bc1 ra35b458  
    5151        size_t in_char_offset;
    5252        size_t last_in_char_offset;
    53        
     53
    5454        char *outbuf;
    5555        size_t outbuf_offset;
    5656        size_t outbuf_size;
    5757        size_t outbuf_last_start;
    58        
     58
    5959        token_t *outtok;
    6060        token_type_t current_type;
Note: See TracChangeset for help on using the changeset viewer.