Changeset 966f753 in mainline


Ignore:
Timestamp:
2018-11-30T20:33:12Z (5 years ago)
Author:
Matthieu Riolo <matthieu.riolo@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
a8c09f91
Parents:
a02aa5c
Message:

imlementing nohups for cmd alias

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/bdsh/input.c

    ra02aa5c r966f753  
    4545#include <tinput.h>
    4646#include <adt/odict.h>
     47#include <adt/list.h>
    4748
    4849#include "config.h"
     
    6465static void print_pipe_usage(void);
    6566
     67typedef struct {
     68        link_t alias_hup_link;
     69        alias_t *alias;
     70} alias_hup_t;
     71
     72static bool find_alias_hup(alias_t *alias, list_t *alias_hups)
     73{
     74        list_foreach(*alias_hups, alias_hup_link, alias_hup_t, link) {
     75                if (alias == link->alias) {
     76                        return true;
     77                }
     78        }
     79
     80        return false;
     81}
     82
    6683/*
    6784 * Tokenizes input from console, sees if the first word is a built-in, if so
     
    6986 * the handler
    7087 */
    71 errno_t process_input(cliuser_t *usr)
     88static errno_t process_input_nohup(cliuser_t *usr, list_t *alias_hups)
    7289{
    7390        token_t *tokens_buf = calloc(WORD_MAX, sizeof(token_t));
     
    177194        if (alias_link != NULL) {
    178195                alias_t *data = odict_get_instance(alias_link, alias_t, odict);
    179                 char *oldLine = usr->line;
    180 
    181                 const size_t input_length = str_size(usr->line) - str_size(cmd[0]) + str_size(data->value) + 1;
    182                 usr->line = (char *)malloc(input_length * sizeof(char));
    183                 usr->line[0] = '\0';
    184 
    185                 unsigned int cmd_replace_index = cmd_token_start;
    186                 for (i = 0; i < tokens_length; i++) {
    187                         if (i == cmd_replace_index) {
    188                                 //if there is a pipe symbol than cmd_token_start will point at the SPACE after the pipe symbol
    189                                 if (tokens[i].type == TOKTYPE_SPACE) {
    190                                         cmd_replace_index++;
     196                //check if the alias already has been resolved once
     197                if (!find_alias_hup(data, alias_hups)) {
     198                        alias_hup_t *hup = (alias_hup_t *)calloc(1, sizeof(hup));
     199                        hup->alias = data;
     200                        list_append(&hup->alias_hup_link, alias_hups);
     201
     202                        char *oldLine = usr->line;
     203                        const size_t input_length = str_size(usr->line) - str_size(cmd[0]) + str_size(data->value) + 1;
     204                        usr->line = (char *)malloc(input_length * sizeof(char));
     205                        usr->line[0] = '\0';
     206
     207                        unsigned int cmd_replace_index = cmd_token_start;
     208                        for (i = 0; i < tokens_length; i++) {
     209                                if (i == cmd_replace_index) {
     210                                        //if there is a pipe symbol than cmd_token_start will point at the SPACE after the pipe symbol
     211                                        if (tokens[i].type == TOKTYPE_SPACE) {
     212                                                cmd_replace_index++;
     213                                                str_append(usr->line, input_length, tokens[i].text);
     214                                                continue;
     215                                        }
     216
     217                                        str_append(usr->line, input_length, data->value);
     218                                } else {
    191219                                        str_append(usr->line, input_length, tokens[i].text);
    192                                         continue;
    193220                                }
    194 
    195                                 str_append(usr->line, input_length, data->value);
    196                         } else {
    197                                 str_append(usr->line, input_length, tokens[i].text);
    198221                        }
    199                 }
    200 
    201                 //reprocess input after string replace
    202                 rc = process_input(usr);
    203                 usr->line = oldLine;
    204                 goto finit;
     222
     223                        //reprocess input after string replace
     224                        rc = process_input_nohup(usr, alias_hups);
     225                        usr->line = oldLine;
     226                        goto finit;
     227                }
    205228        }
    206229
     
    259282}
    260283
     284errno_t process_input(cliuser_t *usr)
     285{
     286        list_t alias_hups;
     287        list_initialize(&alias_hups);
     288
     289        errno_t rc = process_input_nohup(usr, &alias_hups);
     290
     291        list_foreach_safe(alias_hups, cur_link, next_link) {
     292                alias_hup_t *cur_item = list_get_instance(cur_link, alias_hup_t, alias_hup_link);
     293                free(cur_item);
     294        }
     295
     296        return rc;
     297}
     298
    261299void print_pipe_usage(void)
    262300{
Note: See TracChangeset for help on using the changeset viewer.