Changeset bd5f3b7 in mainline for uspace/app/bdsh
- Timestamp:
- 2011-08-21T13:07:35Z (15 years ago)
- 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. - Location:
- uspace/app/bdsh
- Files:
-
- 2 added
- 12 edited
-
Makefile (modified) (2 diffs)
-
cmds/modules/bdd/bdd.c (modified) (8 diffs)
-
cmds/modules/cp/cp.c (modified) (2 diffs)
-
cmds/modules/help/help.c (modified) (3 diffs)
-
cmds/modules/ls/ls.c (modified) (1 diff)
-
compl.c (added)
-
compl.h (added)
-
config.h (modified) (1 diff)
-
exec.c (modified) (7 diffs)
-
exec.h (modified) (1 diff)
-
input.c (modified) (10 diffs)
-
scli.h (modified) (1 diff)
-
tok.c (modified) (14 diffs)
-
tok.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bdsh/Makefile
r86a34d3e rbd5f3b7 29 29 30 30 USPACE_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 31 LIBS = $(LIBBLOCK_PREFIX)/libblock.a $(LIBCLUI_PREFIX)/libclui.a \ 32 $(LIBFMTUTIL_PREFIX)/libfmtutil.a 33 EXTRA_CFLAGS = -I$(LIBBLOCK_PREFIX) -I$(LIBCLUI_PREFIX) -I$(LIBFMTUTIL_PREFIX)\ 34 -I. -Icmds/ -Icmds/builtins -Icmds/modules 34 35 BINARY = bdsh 35 36 … … 54 55 cmds/mod_cmds.c \ 55 56 cmds/builtin_cmds.c \ 57 compl.c \ 56 58 errors.c \ 57 59 input.c \ -
uspace/app/bdsh/cmds/modules/bdd/bdd.c
r86a34d3e rbd5f3b7 39 39 40 40 #include <libblock.h> 41 #include < devmap.h>41 #include <loc.h> 42 42 #include <errno.h> 43 43 #include <assert.h> … … 69 69 unsigned int argc; 70 70 unsigned int i, j; 71 devmap_handle_t handle;71 service_id_t service_id; 72 72 aoff64_t offset; 73 73 uint8_t *blk; … … 96 96 size = 256; 97 97 98 rc = devmap_device_get_handle(argv[1], &handle, 0);98 rc = loc_service_get_id(argv[1], &service_id, 0); 99 99 if (rc != EOK) { 100 100 printf("%s: Error resolving device `%s'.\n", cmdname, argv[1]); … … 102 102 } 103 103 104 rc = block_init(EXCHANGE_SERIALIZE, handle, 2048);104 rc = block_init(EXCHANGE_SERIALIZE, service_id, 2048); 105 105 if (rc != EOK) { 106 106 printf("%s: Error initializing libblock.\n", cmdname); … … 108 108 } 109 109 110 rc = block_get_bsize( handle, &block_size);110 rc = block_get_bsize(service_id, &block_size); 111 111 if (rc != EOK) { 112 112 printf("%s: Error determining device block size.\n", cmdname); … … 117 117 if (blk == NULL) { 118 118 printf("%s: Error allocating memory.\n", cmdname); 119 block_fini( handle);119 block_fini(service_id); 120 120 return CMD_FAILURE; 121 121 } … … 124 124 125 125 while (size > 0) { 126 rc = block_read_direct( handle, ba, 1, blk);126 rc = block_read_direct(service_id, ba, 1, blk); 127 127 if (rc != EOK) { 128 128 printf("%s: Error reading block %" PRIuOFF64 "\n", cmdname, ba); 129 129 free(blk); 130 block_fini( handle);130 block_fini(service_id); 131 131 return CMD_FAILURE; 132 132 } … … 170 170 171 171 free(blk); 172 block_fini( handle);172 block_fini(service_id); 173 173 174 174 return CMD_SUCCESS; -
uspace/app/bdsh/cmds/modules/cp/cp.c
r86a34d3e rbd5f3b7 71 71 size_t blen, int vb) 72 72 { 73 int fd1, fd2, bytes = 0;74 off64_t total = 0;73 int fd1, fd2, bytes; 74 off64_t total; 75 75 int64_t copied = 0; 76 76 char *buff = NULL; … … 104 104 } 105 105 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) 112 108 break; 113 109 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 have119 * 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 shell130 */131 if (res != 0) {132 printf("\n%zd more bytes than actually exist were copied\n", res);133 goto err;134 }135 110 } 136 111 137 112 if (bytes < 0) { 138 err:139 113 printf("\nError copying %s, (%d)\n", src, bytes); 140 114 copied = bytes; -
uspace/app/bdsh/cmds/modules/help/help.c
r86a34d3e rbd5f3b7 1 1 /* 2 2 * Copyright (c) 2008 Tim Post 3 * Copyright (c) 2011 Martin Sucha 3 4 * All rights reserved. 4 5 * … … 30 31 #include <stdlib.h> 31 32 #include <str.h> 33 #include <fmtutil.h> 32 34 33 35 #include "config.h" … … 128 130 static void help_survival(void) 129 131 { 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 " 133 136 "the primary user interface to HelenOS. Bdsh allows you to enter " 134 137 "commands and supports history (Up, Down arrow keys), " 135 138 "line editing (Left Arrow, Right Arrow, Home, End, Backspace), " 136 139 "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 " 140 143 "'help commands' [Enter] to see the list of Bdsh builtin commands. " 141 144 "Other commands are external executables located in the /app and " 142 145 "/srv directories. Type 'ls /app' [Enter] and 'ls /srv' [Enter] " 143 146 "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. " 150 153 "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); 152 156 } 153 157 -
uspace/app/bdsh/cmds/modules/ls/ls.c
r86a34d3e rbd5f3b7 169 169 170 170 /* 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); 172 172 if (!tosort[nbdirs].name) { 173 173 cli_error(CL_ENOMEM, "ls: failed to scan %s", d); 174 174 goto out; 175 175 } 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); 178 178 len = snprintf(buff, PATH_MAX - 1, "%s/%s", d, tosort[nbdirs].name); 179 179 buff[len] = '\0'; -
uspace/app/bdsh/config.h
r86a34d3e rbd5f3b7 40 40 #endif 41 41 42 /* Work around for getenv() */43 #define PATH "/srv:/app"44 #define PATH_DELIM ":"45 46 42 /* Used in many places */ 47 43 #define SMALL_BUFLEN 256 -
uspace/app/bdsh/exec.c
r86a34d3e rbd5f3b7 40 40 #include <str_error.h> 41 41 #include <errno.h> 42 #include <vfs/vfs.h> 42 43 43 44 #include "config.h" … … 51 52 static char *find_command(char *); 52 53 static int try_access(const char *); 54 55 const char *search_dir[] = { "/app", "/srv", NULL }; 53 56 54 57 /* work-around for access() */ … … 69 72 static char *find_command(char *cmd) 70 73 { 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; 75 75 76 76 found = (char *)malloc(PATH_MAX); … … 81 81 } 82 82 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 97 83 /* 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++) { 99 85 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); 101 87 if (-1 != try_access(found)) { 102 free(path_tok);103 88 return (char *) found; 104 89 } … … 106 91 107 92 /* We didn't find it, just give it back as-is. */ 108 free(path_tok);109 93 return (char *) cmd; 110 94 } … … 116 100 char *tmp; 117 101 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]; 120 104 FILE *files[3]; 121 105 … … 128 112 129 113 for (i = 0; i < 3 && files[i] != NULL; i++) { 130 if (f node(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]; 132 116 } 133 117 else { 134 file_ nodes_p[i] = NULL;118 file_handles_p[i] = NULL; 135 119 } 136 120 } 137 file_ nodes_p[i] = NULL;121 file_handles_p[i] = NULL; 138 122 139 rc = task_spawnvf(&tid, tmp, (const char **) argv, file_ nodes_p);123 rc = task_spawnvf(&tid, tmp, (const char **) argv, file_handles_p); 140 124 free(tmp); 141 125 -
uspace/app/bdsh/exec.h
r86a34d3e rbd5f3b7 33 33 #include "scli.h" 34 34 35 extern const char *search_dir[]; 36 35 37 extern unsigned int try_exec(char *, char **, iostate_t *); 36 38 -
uspace/app/bdsh/input.c
r86a34d3e rbd5f3b7 1 1 /* 2 2 * Copyright (c) 2008 Tim Post 3 * Copyright (c) 2011 Jiri Svoboda 4 * Copyright (c) 2011 Martin Sucha 3 5 * All rights reserved. 4 6 * … … 43 45 44 46 #include "config.h" 47 #include "compl.h" 45 48 #include "util.h" 46 49 #include "scli.h" … … 65 68 { 66 69 char *cmd[WORD_MAX]; 70 token_t *tokens = calloc(WORD_MAX, sizeof(token_t)); 71 if (tokens == NULL) 72 return ENOMEM; 67 73 int rc = 0; 68 74 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]; 72 77 char *redir_from = NULL; 73 78 char *redir_to = NULL; 74 79 75 if (NULL == usr->line) 80 if (NULL == usr->line) { 81 free(tokens); 76 82 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); 79 86 if (rc != EOK) { 80 87 goto finit; 81 88 } 82 89 83 rc = tok_tokenize(&tok); 90 size_t tokens_length; 91 rc = tok_tokenize(&tok, &tokens_length); 84 92 if (rc != EOK) { 85 93 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--; 86 103 } 87 104 … … 91 108 * First find the pipes and check that there are no more 92 109 */ 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) { 96 112 if (pipe_count >= 2) { 97 113 print_pipe_usage(); … … 104 120 } 105 121 106 actual_cmd = cmd; 122 unsigned int cmd_token_start = 0; 123 unsigned int cmd_token_end = tokens_length; 124 107 125 processed_pipes = 0; 108 126 109 127 /* 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) { 111 129 /* 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; 114 132 processed_pipes++; 115 133 } … … 117 135 /* Check if the second part (| to <file>) is present */ 118 136 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) { 121 141 /* 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]; 125 144 processed_pipes++; 126 145 } … … 132 151 } 133 152 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) { 135 163 print_pipe_usage(); 136 164 rc = ENOTSUP; … … 184 212 } 185 213 tok_fini(&tok); 214 free(tokens); 186 215 187 216 return rc; … … 226 255 int rc; 227 256 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); 233 258 234 259 rc = tinput_read(tinput, &str); … … 263 288 } 264 289 290 tinput_set_compl_ops(tinput, &compl_ops); 291 265 292 return 0; 266 293 } -
uspace/app/bdsh/scli.h
r86a34d3e rbd5f3b7 32 32 #include "config.h" 33 33 #include <stdint.h> 34 #include <stdio.h> 34 35 35 36 typedef struct { -
uspace/app/bdsh/tok.c
r86a34d3e rbd5f3b7 42 42 static bool tok_pending_chars(tokenizer_t *); 43 43 static int tok_finish_string(tokenizer_t *); 44 static void tok_start_token(tokenizer_t *, token_type_t); 44 45 45 46 /** Initialize the token parser … … 50 51 * @param max_tokens number of elements of the out_tokens array 51 52 */ 52 int tok_init(tokenizer_t *tok, char *input, char **out_tokens,53 int tok_init(tokenizer_t *tok, char *input, token_t *out_tokens, 53 54 size_t max_tokens) 54 55 { 55 56 tok->in = input; 56 57 tok->in_offset = 0; 58 tok->last_in_offset = 0; 59 tok->in_char_offset = 0; 60 tok->last_in_char_offset = 0; 57 61 58 62 tok->outtok = out_tokens; 59 63 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; 63 65 64 66 /* Prepare a buffer where all the token strings will be stored */ … … 87 89 88 90 /** Tokenize the input string into the tokens */ 89 int tok_tokenize(tokenizer_t *tok )91 int tok_tokenize(tokenizer_t *tok, size_t *tokens_length) 90 92 { 91 93 int rc; 92 wchar_t cur_char;94 wchar_t next_char; 93 95 94 96 /* 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. 99 100 * There may not be any pending char for a token in case 100 101 * there are several spaces in the input. … … 106 107 } 107 108 } 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 112 120 */ 113 121 if (tok_pending_chars(tok)) { … … 118 126 } 119 127 120 rc = tok_push_char(tok, '|'); 128 tok_start_token(tok, TOKTYPE_PIPE); 129 130 rc = tok_push_char(tok, tok_get_char(tok)); 121 131 if (rc != EOK) { 122 132 return rc; … … 128 138 } 129 139 } 130 else if ( cur_char == '\'') {140 else if (next_char == '\'') { 131 141 /* A string starts with a quote (') and ends again with a quote. 132 142 * A literal quote is written as '' 133 143 */ 144 tok_start_token(tok, TOKTYPE_TEXT); 145 /* Eat the quote */ 146 tok_get_char(tok); 134 147 rc = tok_finish_string(tok); 135 148 if (rc != EOK) { … … 138 151 } 139 152 else { 153 if (!tok_pending_chars(tok)) { 154 tok_start_token(tok, TOKTYPE_TEXT); 155 } 140 156 /* If we are handling any other character, just append it to 141 157 * the current token. 142 158 */ 143 rc = tok_push_char(tok, cur_char);159 rc = tok_push_char(tok, tok_get_char(tok)); 144 160 if (rc != EOK) { 145 161 return rc; … … 156 172 } 157 173 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; 161 175 162 176 return EOK; … … 167 181 { 168 182 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); 173 189 if (tok_look_char(tok) == '\'') { 174 190 /* Encode a single literal quote */ … … 187 203 } 188 204 else { 189 rc = tok_push_char(tok, cur_char);205 rc = tok_push_char(tok, tok_get_char(tok)); 190 206 if (rc != EOK) { 191 207 return rc; … … 201 217 wchar_t tok_get_char(tokenizer_t *tok) 202 218 { 219 tok->in_char_offset++; 203 220 return str_decode(tok->in, &tok->in_offset, STR_NO_LIMIT); 204 221 } … … 208 225 { 209 226 size_t old_offset = tok->in_offset; 227 size_t old_char_offset = tok->in_char_offset; 210 228 wchar_t ret = tok_get_char(tok); 211 229 tok->in_offset = old_offset; 230 tok->in_char_offset = old_char_offset; 212 231 return ret; 213 232 } … … 219 238 } 220 239 240 void tok_start_token(tokenizer_t *tok, token_type_t type) 241 { 242 tok->current_type = type; 243 } 244 221 245 /** Push the current token to the output array */ 222 246 int tok_push_token(tokenizer_t *tok) … … 231 255 232 256 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; 234 264 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; 235 269 236 270 return EOK; -
uspace/app/bdsh/tok.h
r86a34d3e rbd5f3b7 30 30 #define TOK_H 31 31 32 typedef enum { 33 TOKTYPE_TEXT, 34 TOKTYPE_PIPE, 35 TOKTYPE_SPACE 36 } token_type_t; 37 38 typedef 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 32 47 typedef struct { 33 48 char *in; 34 49 size_t in_offset; 50 size_t last_in_offset; 51 size_t in_char_offset; 52 size_t last_in_char_offset; 35 53 36 54 char *outbuf; … … 39 57 size_t outbuf_last_start; 40 58 41 char **outtok; 59 token_t *outtok; 60 token_type_t current_type; 42 61 size_t outtok_offset; 43 62 size_t outtok_size; 44 63 } tokenizer_t; 45 64 46 extern int tok_init(tokenizer_t *, char *, char **, size_t);65 extern int tok_init(tokenizer_t *, char *, token_t *, size_t); 47 66 extern void tok_fini(tokenizer_t *); 48 extern int tok_tokenize(tokenizer_t * );67 extern int tok_tokenize(tokenizer_t *, size_t *); 49 68 50 69 #endif
Note:
See TracChangeset
for help on using the changeset viewer.
