Changeset bd5f3b7 in mainline for uspace/app/bdsh


Ignore:
Timestamp:
2011-08-21T13:07:35Z (15 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/fix-logger-deadlock, topic/msim-upgrade, topic/simplify-dev-export
Children:
00aece0, f1a9e87
Parents:
86a34d3e (diff), a6480d5 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes.

Location:
uspace/app/bdsh
Files:
2 added
12 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/bdsh/Makefile

    r86a34d3e rbd5f3b7  
    2929
    3030USPACE_PREFIX = ../..
    31 LIBS = $(LIBBLOCK_PREFIX)/libblock.a $(LIBCLUI_PREFIX)/libclui.a
    32 EXTRA_CFLAGS = -I$(LIBBLOCK_PREFIX) -I$(LIBCLUI_PREFIX) -I. -Icmds/ \
    33         -Icmds/builtins -Icmds/modules
     31LIBS = $(LIBBLOCK_PREFIX)/libblock.a $(LIBCLUI_PREFIX)/libclui.a \
     32        $(LIBFMTUTIL_PREFIX)/libfmtutil.a
     33EXTRA_CFLAGS = -I$(LIBBLOCK_PREFIX) -I$(LIBCLUI_PREFIX) -I$(LIBFMTUTIL_PREFIX)\
     34        -I. -Icmds/ -Icmds/builtins -Icmds/modules
    3435BINARY = bdsh
    3536
     
    5455        cmds/mod_cmds.c \
    5556        cmds/builtin_cmds.c \
     57        compl.c \
    5658        errors.c \
    5759        input.c \
  • uspace/app/bdsh/cmds/modules/bdd/bdd.c

    r86a34d3e rbd5f3b7  
    3939
    4040#include <libblock.h>
    41 #include <devmap.h>
     41#include <loc.h>
    4242#include <errno.h>
    4343#include <assert.h>
     
    6969        unsigned int argc;
    7070        unsigned int i, j;
    71         devmap_handle_t handle;
     71        service_id_t service_id;
    7272        aoff64_t offset;
    7373        uint8_t *blk;
     
    9696                size = 256;
    9797
    98         rc = devmap_device_get_handle(argv[1], &handle, 0);
     98        rc = loc_service_get_id(argv[1], &service_id, 0);
    9999        if (rc != EOK) {
    100100                printf("%s: Error resolving device `%s'.\n", cmdname, argv[1]);
     
    102102        }
    103103
    104         rc = block_init(EXCHANGE_SERIALIZE, handle, 2048);
     104        rc = block_init(EXCHANGE_SERIALIZE, service_id, 2048);
    105105        if (rc != EOK)  {
    106106                printf("%s: Error initializing libblock.\n", cmdname);
     
    108108        }
    109109
    110         rc = block_get_bsize(handle, &block_size);
     110        rc = block_get_bsize(service_id, &block_size);
    111111        if (rc != EOK) {
    112112                printf("%s: Error determining device block size.\n", cmdname);
     
    117117        if (blk == NULL) {
    118118                printf("%s: Error allocating memory.\n", cmdname);
    119                 block_fini(handle);
     119                block_fini(service_id);
    120120                return CMD_FAILURE;
    121121        }
     
    124124
    125125        while (size > 0) {
    126                 rc = block_read_direct(handle, ba, 1, blk);
     126                rc = block_read_direct(service_id, ba, 1, blk);
    127127                if (rc != EOK) {
    128128                        printf("%s: Error reading block %" PRIuOFF64 "\n", cmdname, ba);
    129129                        free(blk);
    130                         block_fini(handle);
     130                        block_fini(service_id);
    131131                        return CMD_FAILURE;
    132132                }
     
    170170
    171171        free(blk);
    172         block_fini(handle);
     172        block_fini(service_id);
    173173
    174174        return CMD_SUCCESS;
  • uspace/app/bdsh/cmds/modules/cp/cp.c

    r86a34d3e rbd5f3b7  
    7171        size_t blen, int vb)
    7272{
    73         int fd1, fd2, bytes = 0;
    74         off64_t total = 0;
     73        int fd1, fd2, bytes;
     74        off64_t total;
    7575        int64_t copied = 0;
    7676        char *buff = NULL;
     
    104104        }
    105105
    106         for (;;) {
    107                 ssize_t res;
    108                 size_t written = 0;
    109 
    110                 bytes = read(fd1, buff, blen);
    111                 if (bytes <= 0)
     106        while ((bytes = read_all(fd1, buff, blen)) > 0) {
     107                if ((bytes = write_all(fd2, buff, bytes)) < 0)
    112108                        break;
    113109                copied += bytes;
    114                 res = bytes;
    115                 do {
    116                         /*
    117                          * Theoretically, it may not be enough to call write()
    118                          * only once. Also the previous read() may have
    119                          * returned less data than requested.
    120                          */
    121                         bytes = write(fd2, buff + written, res);
    122                         if (bytes < 0)
    123                                 goto err;
    124                         written += bytes;
    125                         res -= bytes;
    126                 } while (res > 0);
    127 
    128                 /* TODO: re-insert assert() once this is stand alone,
    129                  * removed as abort() exits the entire shell
    130                  */
    131                 if (res != 0) {
    132                         printf("\n%zd more bytes than actually exist were copied\n", res);
    133                         goto err;
    134                 }
    135110        }
    136111
    137112        if (bytes < 0) {
    138 err:
    139113                printf("\nError copying %s, (%d)\n", src, bytes);
    140114                copied = bytes;
  • uspace/app/bdsh/cmds/modules/help/help.c

    r86a34d3e rbd5f3b7  
    11/*
    22 * Copyright (c) 2008 Tim Post
     3 * Copyright (c) 2011 Martin Sucha
    34 * All rights reserved.
    45 *
     
    3031#include <stdlib.h>
    3132#include <str.h>
     33#include <fmtutil.h>
    3234
    3335#include "config.h"
     
    128130static void help_survival(void)
    129131{
    130         printf("Don't panic!\n\n");
    131 
    132         printf("This is Bdsh, the Brain dead shell, currently "
     132        print_wrapped_console(
     133            "Don't panic!\n\n"
     134
     135            "This is Bdsh, the Brain dead shell, currently "
    133136            "the primary user interface to HelenOS. Bdsh allows you to enter "
    134137            "commands and supports history (Up, Down arrow keys), "
    135138            "line editing (Left Arrow, Right Arrow, Home, End, Backspace), "
    136139            "selection (Shift + movement keys), copy and paste (Ctrl-C, "
    137             "Ctrl-V), similar to common desktop environments.\n\n");
    138 
    139         printf("The most basic filesystem commands are Bdsh builtins. Type "
     140            "Ctrl-V), similar to common desktop environments.\n\n"
     141
     142            "The most basic filesystem commands are Bdsh builtins. Type "
    140143            "'help commands' [Enter] to see the list of Bdsh builtin commands. "
    141144            "Other commands are external executables located in the /app and "
    142145            "/srv directories. Type 'ls /app' [Enter] and 'ls /srv' [Enter] "
    143146            "to see their list. You can execute an external command simply "
    144             "by entering its name (e.g. type 'tetris' [Enter]).\n\n");
    145 
    146         printf("HelenOS has virtual consoles (VCs). You can switch between "
    147             "these using the F1-F11 keys.\n\n");
    148 
    149         printf("This is but a small glimpse of what you can do with HelenOS. "
     147            "by entering its name (e.g. type 'tetris' [Enter]).\n\n"
     148
     149            "HelenOS has virtual consoles (VCs). You can switch between "
     150            "these using the F1-F11 keys.\n\n"
     151
     152            "This is but a small glimpse of what you can do with HelenOS. "
    150153            "To learn more please point your browser to the HelenOS User's "
    151             "Guide: http://trac.helenos.org/trac.fcgi/wiki/UsersGuide\n\n");
     154            "Guide: http://trac.helenos.org/trac.fcgi/wiki/UsersGuide\n\n",
     155            ALIGN_LEFT);
    152156}
    153157
  • uspace/app/bdsh/cmds/modules/ls/ls.c

    r86a34d3e rbd5f3b7  
    169169               
    170170                /* fill the name field */
    171                 tosort[nbdirs].name = (char *) malloc(str_length(dp->d_name) + 1);
     171                tosort[nbdirs].name = (char *) malloc(str_size(dp->d_name) + 1);
    172172                if (!tosort[nbdirs].name) {
    173173                        cli_error(CL_ENOMEM, "ls: failed to scan %s", d);
    174174                        goto out;
    175175                }
    176                
    177                 str_cpy(tosort[nbdirs].name, str_length(dp->d_name) + 1, dp->d_name);
     176
     177                str_cpy(tosort[nbdirs].name, str_size(dp->d_name) + 1, dp->d_name);
    178178                len = snprintf(buff, PATH_MAX - 1, "%s/%s", d, tosort[nbdirs].name);
    179179                buff[len] = '\0';
  • uspace/app/bdsh/config.h

    r86a34d3e rbd5f3b7  
    4040#endif
    4141
    42 /* Work around for getenv() */
    43 #define PATH "/srv:/app"
    44 #define PATH_DELIM ":"
    45 
    4642/* Used in many places */
    4743#define SMALL_BUFLEN 256
  • uspace/app/bdsh/exec.c

    r86a34d3e rbd5f3b7  
    4040#include <str_error.h>
    4141#include <errno.h>
     42#include <vfs/vfs.h>
    4243
    4344#include "config.h"
     
    5152static char *find_command(char *);
    5253static int try_access(const char *);
     54
     55const char *search_dir[] = { "/app", "/srv", NULL };
    5356
    5457/* work-around for access() */
     
    6972static char *find_command(char *cmd)
    7073{
    71         char *path_tok;
    72         char *path[PATH_MAX];
    73         int n = 0, i = 0;
    74         size_t x = str_size(cmd) + 2;
     74        size_t i;
    7575
    7676        found = (char *)malloc(PATH_MAX);
     
    8181        }
    8282
    83         path_tok = str_dup(PATH);
    84 
    85         /* Extract the PATH env to a path[] array */
    86         path[n] = strtok(path_tok, PATH_DELIM);
    87         while (NULL != path[n]) {
    88                 if ((str_size(path[n]) + x ) > PATH_MAX) {
    89                         cli_error(CL_ENOTSUP,
    90                                 "Segment %d of path is too large, search ends at segment %d",
    91                                 n, n-1);
    92                         break;
    93                 }
    94                 path[++n] = strtok(NULL, PATH_DELIM);
    95         }
    96 
    9783        /* We now have n places to look for the command */
    98         for (i=0; path[i]; i++) {
     84        for (i = 0; search_dir[i] != NULL; i++) {
    9985                memset(found, 0, sizeof(found));
    100                 snprintf(found, PATH_MAX, "%s/%s", path[i], cmd);
     86                snprintf(found, PATH_MAX, "%s/%s", search_dir[i], cmd);
    10187                if (-1 != try_access(found)) {
    102                         free(path_tok);
    10388                        return (char *) found;
    10489                }
     
    10691
    10792        /* We didn't find it, just give it back as-is. */
    108         free(path_tok);
    10993        return (char *) cmd;
    11094}
     
    116100        char *tmp;
    117101        int rc, retval, i;
    118         fdi_node_t file_nodes[3];
    119         fdi_node_t *file_nodes_p[4];
     102        int file_handles[3];
     103        int *file_handles_p[4];
    120104        FILE *files[3];
    121105
     
    128112       
    129113        for (i = 0; i < 3 && files[i] != NULL; i++) {
    130                 if (fnode(files[i], &file_nodes[i]) == EOK) {
    131                         file_nodes_p[i] = &file_nodes[i];
     114                if (fhandle(files[i], &file_handles[i]) == EOK) {
     115                        file_handles_p[i] = &file_handles[i];
    132116                }
    133117                else {
    134                         file_nodes_p[i] = NULL;
     118                        file_handles_p[i] = NULL;
    135119                }
    136120        }
    137         file_nodes_p[i] = NULL;
     121        file_handles_p[i] = NULL;
    138122
    139         rc = task_spawnvf(&tid, tmp, (const char **) argv, file_nodes_p);
     123        rc = task_spawnvf(&tid, tmp, (const char **) argv, file_handles_p);
    140124        free(tmp);
    141125
  • uspace/app/bdsh/exec.h

    r86a34d3e rbd5f3b7  
    3333#include "scli.h"
    3434
     35extern const char *search_dir[];
     36
    3537extern unsigned int try_exec(char *, char **, iostate_t *);
    3638
  • uspace/app/bdsh/input.c

    r86a34d3e rbd5f3b7  
    11/*
    22 * Copyright (c) 2008 Tim Post
     3 * Copyright (c) 2011 Jiri Svoboda
     4 * Copyright (c) 2011 Martin Sucha
    35 * All rights reserved.
    46 *
     
    4345
    4446#include "config.h"
     47#include "compl.h"
    4548#include "util.h"
    4649#include "scli.h"
     
    6568{
    6669        char *cmd[WORD_MAX];
     70        token_t *tokens = calloc(WORD_MAX, sizeof(token_t));
     71        if (tokens == NULL)
     72                return ENOMEM;
    6773        int rc = 0;
    6874        tokenizer_t tok;
    69         int i, pipe_count, processed_pipes;
    70         int pipe_pos[2];
    71         char **actual_cmd;
     75        unsigned int i, pipe_count, processed_pipes;
     76        unsigned int pipe_pos[2];
    7277        char *redir_from = NULL;
    7378        char *redir_to = NULL;
    7479
    75         if (NULL == usr->line)
     80        if (NULL == usr->line) {
     81                free(tokens);
    7682                return CL_EFAIL;
    77 
    78         rc = tok_init(&tok, usr->line, cmd, WORD_MAX);
     83        }
     84
     85        rc = tok_init(&tok, usr->line, tokens, WORD_MAX);
    7986        if (rc != EOK) {
    8087                goto finit;
    8188        }
    8289       
    83         rc = tok_tokenize(&tok);
     90        size_t tokens_length;
     91        rc = tok_tokenize(&tok, &tokens_length);
    8492        if (rc != EOK) {
    8593                goto finit;
     94        }
     95       
     96        if (tokens_length > 0 && tokens[0].type == TOKTYPE_SPACE) {
     97                tokens++;
     98                tokens_length--;
     99        }
     100       
     101        if (tokens_length > 0 && tokens[tokens_length-1].type == TOKTYPE_SPACE) {
     102                tokens_length--;
    86103        }
    87104       
     
    91108         * First find the pipes and check that there are no more
    92109         */
    93         int cmd_length = 0;
    94         for (i = 0, pipe_count = 0; cmd[i] != NULL; i++, cmd_length++) {
    95                 if (cmd[i][0] == '|') {
     110        for (i = 0, pipe_count = 0; i < tokens_length; i++) {
     111                if (tokens[i].type == TOKTYPE_PIPE) {
    96112                        if (pipe_count >= 2) {
    97113                                print_pipe_usage();
     
    104120        }
    105121       
    106         actual_cmd = cmd;
     122        unsigned int cmd_token_start = 0;
     123        unsigned int cmd_token_end = tokens_length;
     124       
    107125        processed_pipes = 0;
    108126       
    109127        /* Check if the first part (from <file> |) is present */
    110         if (pipe_count > 0 && pipe_pos[0] == 2 && str_cmp(cmd[0], "from") == 0) {
     128        if (pipe_count > 0 && (pipe_pos[0] == 3 || pipe_pos[0] == 4) && str_cmp(tokens[0].text, "from") == 0) {
    111129                /* Ignore the first three tokens (from, file, pipe) and set from */
    112                 redir_from = cmd[1];
    113                 actual_cmd = cmd + 3;
     130                redir_from = tokens[2].text;
     131                cmd_token_start = pipe_pos[0]+1;
    114132                processed_pipes++;
    115133        }
     
    117135        /* Check if the second part (| to <file>) is present */
    118136        if ((pipe_count - processed_pipes) > 0 &&
    119             pipe_pos[processed_pipes] == cmd_length - 3 &&
    120             str_cmp(cmd[cmd_length-2], "to") == 0) {
     137            (pipe_pos[processed_pipes] == tokens_length - 4 ||
     138            (pipe_pos[processed_pipes] == tokens_length - 5 &&
     139            tokens[tokens_length-4].type == TOKTYPE_SPACE )) &&
     140            str_cmp(tokens[tokens_length-3].text, "to") == 0) {
    121141                /* Ignore the last three tokens (pipe, to, file) and set to */
    122                 redir_to = cmd[cmd_length-1];
    123                 cmd[cmd_length-3] = NULL;
    124                 cmd_length -= 3;
     142                redir_to = tokens[tokens_length-1].text;
     143                cmd_token_end = pipe_pos[processed_pipes];
    125144                processed_pipes++;
    126145        }
     
    132151        }
    133152       
    134         if (actual_cmd[0] == NULL) {
     153        /* Convert tokens of the command to string array */
     154        unsigned int cmd_pos = 0;
     155        for (i = cmd_token_start; i < cmd_token_end; i++) {
     156                if (tokens[i].type != TOKTYPE_SPACE) {
     157                        cmd[cmd_pos++] = tokens[i].text;
     158                }
     159        }
     160        cmd[cmd_pos++] = NULL;
     161       
     162        if (cmd[0] == NULL) {
    135163                print_pipe_usage();
    136164                rc = ENOTSUP;
     
    184212        }
    185213        tok_fini(&tok);
     214        free(tokens);
    186215
    187216        return rc;
     
    226255        int rc;
    227256       
    228         console_flush(tinput->console);
    229         console_set_style(tinput->console, STYLE_EMPHASIS);
    230         printf("%s", usr->prompt);
    231         console_flush(tinput->console);
    232         console_set_style(tinput->console, STYLE_NORMAL);
     257        tinput_set_prompt(tinput, usr->prompt);
    233258
    234259        rc = tinput_read(tinput, &str);
     
    263288        }
    264289
     290        tinput_set_compl_ops(tinput, &compl_ops);
     291
    265292        return 0;
    266293}
  • uspace/app/bdsh/scli.h

    r86a34d3e rbd5f3b7  
    3232#include "config.h"
    3333#include <stdint.h>
     34#include <stdio.h>
    3435
    3536typedef struct {
  • uspace/app/bdsh/tok.c

    r86a34d3e rbd5f3b7  
    4242static bool tok_pending_chars(tokenizer_t *);
    4343static int tok_finish_string(tokenizer_t *);
     44static void tok_start_token(tokenizer_t *, token_type_t);
    4445
    4546/** Initialize the token parser
     
    5051 * @param max_tokens number of elements of the out_tokens array
    5152 */
    52 int tok_init(tokenizer_t *tok, char *input, char **out_tokens,
     53int tok_init(tokenizer_t *tok, char *input, token_t *out_tokens,
    5354    size_t max_tokens)
    5455{       
    5556        tok->in = input;
    5657        tok->in_offset = 0;
     58        tok->last_in_offset = 0;
     59        tok->in_char_offset = 0;
     60        tok->last_in_char_offset = 0;
    5761       
    5862        tok->outtok = out_tokens;
    5963        tok->outtok_offset = 0;
    60         /* Leave one slot for a null terminator */
    61         assert(max_tokens > 0);
    62         tok->outtok_size = max_tokens - 1;
     64        tok->outtok_size = max_tokens;
    6365       
    6466        /* Prepare a buffer where all the token strings will be stored */
     
    8789
    8890/** Tokenize the input string into the tokens */
    89 int tok_tokenize(tokenizer_t *tok)
     91int tok_tokenize(tokenizer_t *tok, size_t *tokens_length)
    9092{
    9193        int rc;
    92         wchar_t cur_char;
     94        wchar_t next_char;
    9395       
    9496        /* Read the input line char by char and append tokens */
    95         while ((cur_char = tok_get_char(tok)) != 0) {
    96                 if (cur_char == ' ') {
    97                         /* Spaces delimit tokens, but are not processed in any way
    98                          * Push the token if there is any.
     97        while ((next_char = tok_look_char(tok)) != 0) {
     98                if (next_char == ' ') {
     99                        /* Push the token if there is any.
    99100                         * There may not be any pending char for a token in case
    100101                         * there are several spaces in the input.
     
    106107                                }
    107108                        }
    108                 }
    109                 else if (cur_char == '|') {
    110                         /* Pipes are tokens that are delimiters and should be output
    111                          * as a separate token
     109                        tok_start_token(tok, TOKTYPE_SPACE);
     110                        /* Eat all the spaces */
     111                        while (tok_look_char(tok) == ' ') {
     112                                tok_push_char(tok, tok_get_char(tok));
     113                        }
     114                        tok_push_token(tok);
     115                       
     116                }
     117                else if (next_char == '|') {
     118                        /* Pipes are tokens that are delimiters and should be
     119                         * output as a separate token
    112120                         */
    113121                        if (tok_pending_chars(tok)) {
     
    118126                        }
    119127                       
    120                         rc = tok_push_char(tok, '|');
     128                        tok_start_token(tok, TOKTYPE_PIPE);
     129                       
     130                        rc = tok_push_char(tok, tok_get_char(tok));
    121131                        if (rc != EOK) {
    122132                                return rc;
     
    128138                        }
    129139                }
    130                 else if (cur_char == '\'') {
     140                else if (next_char == '\'') {
    131141                        /* A string starts with a quote (') and ends again with a quote.
    132142                         * A literal quote is written as ''
    133143                         */
     144                        tok_start_token(tok, TOKTYPE_TEXT);
     145                        /* Eat the quote */
     146                        tok_get_char(tok);
    134147                        rc = tok_finish_string(tok);
    135148                        if (rc != EOK) {
     
    138151                }
    139152                else {
     153                        if (!tok_pending_chars(tok)) {
     154                                tok_start_token(tok, TOKTYPE_TEXT);
     155                        }
    140156                        /* If we are handling any other character, just append it to
    141157                         * the current token.
    142158                         */
    143                         rc = tok_push_char(tok, cur_char);
     159                        rc = tok_push_char(tok, tok_get_char(tok));
    144160                        if (rc != EOK) {
    145161                                return rc;
     
    156172        }
    157173       
    158         /* We always have a space for the terminator, as we
    159          * reserved it in tok_init */
    160         tok->outtok[tok->outtok_offset] = 0;
     174        *tokens_length = tok->outtok_offset;
    161175       
    162176        return EOK;
     
    167181{
    168182        int rc;
    169         wchar_t cur_char;
    170        
    171         while ((cur_char = tok_get_char(tok)) != 0) {
    172                 if (cur_char == '\'') {
     183        wchar_t next_char;
     184       
     185        while ((next_char = tok_look_char(tok)) != 0) {
     186                if (next_char == '\'') {
     187                        /* Eat the quote */
     188                        tok_get_char(tok);
    173189                        if (tok_look_char(tok) == '\'') {
    174190                                /* Encode a single literal quote */
     
    187203                }
    188204                else {
    189                         rc = tok_push_char(tok, cur_char);
     205                        rc = tok_push_char(tok, tok_get_char(tok));
    190206                        if (rc != EOK) {
    191207                                return rc;
     
    201217wchar_t tok_get_char(tokenizer_t *tok)
    202218{
     219        tok->in_char_offset++;
    203220        return str_decode(tok->in, &tok->in_offset, STR_NO_LIMIT);
    204221}
     
    208225{
    209226        size_t old_offset = tok->in_offset;
     227        size_t old_char_offset = tok->in_char_offset;
    210228        wchar_t ret = tok_get_char(tok);
    211229        tok->in_offset = old_offset;
     230        tok->in_char_offset = old_char_offset;
    212231        return ret;
    213232}
     
    219238}
    220239
     240void tok_start_token(tokenizer_t *tok, token_type_t type)
     241{
     242        tok->current_type = type;
     243}
     244
    221245/** Push the current token to the output array */
    222246int tok_push_token(tokenizer_t *tok)
     
    231255       
    232256        tok->outbuf[tok->outbuf_offset++] = 0;
    233         tok->outtok[tok->outtok_offset++] = tok->outbuf + tok->outbuf_last_start;
     257        token_t *tokinfo = &tok->outtok[tok->outtok_offset++];
     258        tokinfo->type = tok->current_type;
     259        tokinfo->text = tok->outbuf + tok->outbuf_last_start;
     260        tokinfo->byte_start = tok->last_in_offset;
     261        tokinfo->byte_length = tok->in_offset - tok->last_in_offset;
     262        tokinfo->char_start = tok->last_in_char_offset;
     263        tokinfo->char_length = tok->in_char_offset - tok->last_in_char_offset;
    234264        tok->outbuf_last_start = tok->outbuf_offset;
     265       
     266        /* We have consumed the first char of the next token already */
     267        tok->last_in_offset = tok->in_offset;
     268        tok->last_in_char_offset = tok->in_char_offset;
    235269       
    236270        return EOK;
  • uspace/app/bdsh/tok.h

    r86a34d3e rbd5f3b7  
    3030#define TOK_H
    3131
     32typedef enum {
     33        TOKTYPE_TEXT,
     34        TOKTYPE_PIPE,
     35        TOKTYPE_SPACE
     36} token_type_t;
     37
     38typedef struct {
     39        char *text;
     40        size_t byte_start;
     41        size_t char_start;
     42        size_t byte_length;
     43        size_t char_length;
     44        token_type_t type;
     45} token_t;
     46
    3247typedef struct {
    3348        char *in;
    3449        size_t in_offset;
     50        size_t last_in_offset;
     51        size_t in_char_offset;
     52        size_t last_in_char_offset;
    3553       
    3654        char *outbuf;
     
    3957        size_t outbuf_last_start;
    4058       
    41         char **outtok;
     59        token_t *outtok;
     60        token_type_t current_type;
    4261        size_t outtok_offset;
    4362        size_t outtok_size;
    4463} tokenizer_t;
    4564
    46 extern int tok_init(tokenizer_t *, char *, char **, size_t);
     65extern int tok_init(tokenizer_t *, char *, token_t *, size_t);
    4766extern void tok_fini(tokenizer_t *);
    48 extern int tok_tokenize(tokenizer_t *);
     67extern int tok_tokenize(tokenizer_t *, size_t *);
    4968
    5069#endif
Note: See TracChangeset for help on using the changeset viewer.