diff --git a/Makefile b/Makefile index 87f5e00..c43c028 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ endif CC = gcc TARGET = jzboot -SOURCES = debug.c devmgr.c ingenic.c main.c shell_lex.c usbdev.c shell.c config.c spl_cmdset.c usbboot_cmdset.c +SOURCES = debug.c devmgr.c ingenic.c main.c shell_lex.c usbdev.c shell.c shell_builtins.c config.c spl_cmdset.c usbboot_cmdset.c CFLAGS = --std=gnu99 -Wall -Werror -O2 $(shell pkg-config libusb-1.0 --cflags) LIBS += $(shell pkg-config libusb-1.0 --libs) diff --git a/main.c b/main.c index 663ab08..e94aa93 100644 --- a/main.c +++ b/main.c @@ -146,7 +146,9 @@ int main(int argc, char *argv[]) { goto exit_usb; } - if(shell_init(ingenic) == -1) { + shell_context_t *shell = shell_init(ingenic); + + if(shell == NULL) { perror("shell_init"); ret = 1; @@ -155,7 +157,7 @@ int main(int argc, char *argv[]) { } if(config) - if(shell_source(config) == -1) { + if(shell_source(shell, config) == -1) { perror("shell_source"); ret = 1; @@ -164,23 +166,23 @@ int main(int argc, char *argv[]) { } if(cmd != NULL) { - if(shell_execute(cmd) == -1) { + if(shell_execute(shell, cmd) == -1) { perror("shell_execute"); ret = 1; } } else if(script != NULL) { - if(shell_source(script) == -1) { + if(shell_source(shell, script) == -1) { perror("shell_source"); ret = 1; } } else - shell_interactive(); + shell_interactive(shell); exit_shell: - shell_fini(); + shell_fini(shell); exit_ingenic: ingenic_close(ingenic); diff --git a/shell.c b/shell.c index 913e6e3..32e1d64 100644 --- a/shell.c +++ b/shell.c @@ -27,42 +27,9 @@ #include #include -#include "shell.h" +#include "shell_internal.h" #include "debug.h" #include "ingenic.h" -#include "config.h" - -static void *device = NULL; -static char linebuf[512]; -char *strval = NULL, *line = NULL; - -int yylex(); -void yyrestart(FILE *new_file); - -static int builtin_help(int argc, char *argv[]); -static int builtin_exit(int argc, char *argv[]); -static int builtin_source(int argc, char *argv[]); -static int builtin_echo(int argc, char *argv[]); -static int builtin_sleep(int argc, char *argv[]); -static int builtin_redetect(int argc, char *argv[]); -static int builtin_rebuildcfg(int argc, char *argv[]); -static int builtin_set(int argc, char *argv[]); -static int builtin_safe(int argc, char *argv[]); - -static const shell_command_t commands[] = { - { "help", "- Display this message", builtin_help }, - { "exit", "- Batch: stop current script, interactive: end session", builtin_exit }, - { "source", " - run specified script", builtin_source }, - { "echo", " - output specified string", builtin_echo }, - { "sleep", " - sleep a specified amount of time", builtin_sleep }, - { "set", "[VARIABLE] [VALUE] - print or set configuraton variables", builtin_set }, - { "safe", " [ARG]... - run command ignoring errors", builtin_safe }, - - { "redetect", " - Redetect CPU", builtin_redetect }, - { "rebuildcfg", " - Rebuild firmware configuration data", builtin_rebuildcfg }, - - { NULL, NULL, NULL } -}; static void shell_update_cmdset(void *arg); @@ -70,64 +37,106 @@ static const ingenic_callbacks_t shell_callbacks = { shell_update_cmdset, }; -static const shell_command_t *set_cmds = NULL; -static int shell_exit = 0; +static const struct { + int set; + const char *name; + const shell_command_t *commands; +} cmdsets[] = { + { CMDSET_SPL, "SPL", spl_cmdset }, + { CMDSET_USBBOOT, "USBBoot", usbboot_cmdset }, + { 0, NULL, NULL } +}; -int shell_init(void *ingenic) { +shell_context_t *shell_init(void *ingenic) { #ifdef WITH_READLINE rl_initialize(); #endif debug(LEVEL_DEBUG, "Initializing shell\n"); - device = ingenic; + shell_context_t *ctx = malloc(sizeof(shell_context_t)); + memset(ctx, 0, sizeof(shell_context_t)); + ctx->device = ingenic; - ingenic_set_callbacks(ingenic, &shell_callbacks, NULL); + ingenic_set_callbacks(ingenic, &shell_callbacks, ctx); - shell_update_cmdset(NULL); + shell_update_cmdset(ctx); + + return ctx; +} + +int shell_enumerate_commands(shell_context_t *ctx, int (*callback)(shell_context_t *ctx, const shell_command_t *cmd, void *arg), void *arg) { + for(int i = 0; builtin_cmdset[i].cmd != NULL; i++) { + int ret = callback(ctx, builtin_cmdset + i, arg); + + if(ret != 0) + return ret; + } + + if(ctx->set_cmds) + for(int i = 0; ctx->set_cmds[i].cmd != NULL; i++) { + int ret = callback(ctx, ctx->set_cmds + i, arg); + + if(ret != 0) + return ret; + } return 0; } -#define STATE_WANTSTR 0 -#define STATE_WANTSPACE 1 +static int shell_run_function(shell_context_t *ctx, const shell_command_t *cmd, void *arg) { + shell_run_data_t *data = arg; -int shell_run(int argc, char *argv[]) { - for(int i = 0; commands[i].cmd != NULL; i++) - if(strcmp(commands[i].cmd, argv[0]) == 0) - return commands[i].handler(argc, argv); + if(strcmp(cmd->cmd, data->argv[0]) == 0) { + int ret = cmd->handler(ctx, data->argc, data->argv); - if(set_cmds) { - for(int i = 0; set_cmds[i].cmd != NULL; i++) - if(strcmp(set_cmds[i].cmd, argv[0]) == 0) - return set_cmds[i].handler(argc, argv); - } - - debug(LEVEL_ERROR, "Bad command '%s'\n", argv[0]); - - errno = EINVAL; - return -1; + if(ret == 0) + return 1; + else + return ret; + } else + return 0; } -int shell_execute(const char *cmd) { - line = strdup(cmd); - char *ptr = line; +int shell_run(shell_context_t *ctx, int argc, char *argv[]) { + shell_run_data_t data = { argc, argv }; + + int ret = shell_enumerate_commands(ctx, shell_run_function, &data); + + if(ret != 0) { + debug(LEVEL_ERROR, "Bad command '%s'\n", argv[0]); + + errno = EINVAL; + return -1; + + } else if(ret == 1) { + return 0; + } else + return ret; +} + +int shell_execute(shell_context_t *ctx, const char *cmd) { + yyscan_t scanner; + if(yylex_init_extra(ctx, &scanner) == -1) + return -1; + + ctx->line = strdup(cmd); + char *ptr = ctx->line; int token; int state = STATE_WANTSTR; int argc = 0; char **argv = NULL; - - yyrestart(NULL); + int fret = -1; do { int noway = 0; - token = yylex(); + token = yylex(&scanner); if((token == TOK_SEPARATOR || token == TOK_COMMENT || token == 0)) { if(argc > 0) { - int ret = shell_run(argc, argv); + int ret = shell_run(ctx, argc, argv); for(int i = 0; i < argc; i++) { free(argv[i]); @@ -139,9 +148,9 @@ int shell_execute(const char *cmd) { argc = 0; if(ret == -1) { - free(ptr); + fret = -1; - return -1; + break; } } @@ -156,7 +165,7 @@ int shell_execute(const char *cmd) { argv = realloc(argv, sizeof(char *) * argc); - argv[oargc] = strval; + argv[oargc] = ctx->strval; state = STATE_WANTSPACE; } else { @@ -167,7 +176,7 @@ int shell_execute(const char *cmd) { case STATE_WANTSPACE: if(token == TOK_STRING) { - free(strval); + free(ctx->strval); noway = 1; } else if(token == TOK_SPACE) { @@ -183,9 +192,10 @@ int shell_execute(const char *cmd) { free(argv[i]); free(argv); - free(ptr); - return -1; + fret = -1; + + break; } } @@ -193,28 +203,30 @@ int shell_execute(const char *cmd) { free(ptr); - return 0; + yylex_destroy(&scanner); + + return fret; } -int shell_pull(char *buf, int maxlen) { - size_t len = strlen(line); +int shell_pull(shell_context_t *ctx, char *buf, int maxlen) { + size_t len = strlen(ctx->line); if(len < maxlen) maxlen = len; - memcpy(buf, line, maxlen); + memcpy(buf, ctx->line, maxlen); - line += maxlen; + ctx->line += maxlen; return maxlen; } -void shell_fini() { - device = NULL; +void shell_fini(shell_context_t *ctx) { + free(ctx); } -int shell_source(const char *filename) { - shell_exit = 0; +int shell_source(shell_context_t *ctx, const char *filename) { + ctx->shell_exit = 0; FILE *file = fopen(filename, "r"); @@ -224,8 +236,8 @@ int shell_source(const char *filename) { char *line; - while((line = fgets(linebuf, sizeof(linebuf), file)) && !shell_exit) { - if(shell_execute(line) == -1) { + while((line = fgets(ctx->linebuf, sizeof(ctx->linebuf), file)) && !ctx->shell_exit) { + if(shell_execute(ctx, line) == -1) { fclose(file); return -1; @@ -237,38 +249,37 @@ int shell_source(const char *filename) { return 0; } -void shell_interactive() { - shell_exit = 0; +void shell_interactive(shell_context_t *ctx) { + ctx->shell_exit = 0; #ifndef WITH_READLINE char *line; - while(!shell_exit) { + while(!ctx->shell_exit) { fputs("jzboot> ", stdout); fflush(stdout); - line = fgets(linebuf, sizeof(linebuf), stdin); + line = fgets(ctx->linebuf, sizeof(ctx->linebuf), stdin); if(line == NULL) break; - shell_execute(line); + shell_execute(ctx, line); } #else rl_set_signals(); - while(!shell_exit) { + while(!ctx->shell_exit) { char *line = readline("jzboot> "); if(line == NULL) { - printf("line null, EOP\n"); break; } add_history(line); - shell_execute(line); + shell_execute(ctx, line); free(line); } @@ -277,153 +288,18 @@ void shell_interactive() { #endif } -static int builtin_help(int argc, char *argv[]) { - for(int i = 0; commands[i].cmd != NULL; i++) { - printf("%s %s\n", commands[i].cmd, commands[i].description); - } - - if(set_cmds) { - for(int i = 0; set_cmds[i].cmd != NULL; i++) - printf("%s %s\n", set_cmds[i].cmd, set_cmds[i].description); - } - - return 0; -} - -static int builtin_exit(int argc, char *argv[]) { - shell_exit = 1; - - return 0; -} - -static int builtin_source(int argc, char *argv[]) { - if(argc != 2) { - printf("Usage: %s \n", argv[0]); - - return -1; - } - - int ret = shell_source(argv[1]); - - if(ret == -1) { - fprintf(stderr, "Error while sourcing file %s: %s\n", argv[1], strerror(errno)); - } - - shell_exit = 0; - - return ret; -} - -static int builtin_echo(int argc, char *argv[]) { - if(argc < 2) { - printf("Usage: %s \n", argv[0]); - - return -1; - } - - for(int i = 1; i < argc; i++) { - fputs(argv[i], stdout); - - putchar((i < argc - 1) ? ' ' : '\n'); - } - - return 0; -} - -static int builtin_sleep(int argc, char *argv[]) { - if(argc != 2) { - printf("Usage: %s \n", argv[0]); - - return -1; - } - - uint32_t ms = atoi(argv[1]); - - usleep(ms * 1000); - - return 0; -} - -static int builtin_redetect(int argc, char *argv[]) { - if(argc != 1) { - printf("Usage: %s\n", argv[0]); - - return -1; - } - - if(ingenic_redetect(device) == -1) { - perror("ingenic_redetect"); - - return -1; - } else - return 0; -} - - -static int builtin_set(int argc, char *argv[]) { - if(argc == 1 && cfg_environ) { - for(int i = 0; cfg_environ[i] != NULL; i++) - printf("%s\n", cfg_environ[i]); - - } else if(argc == 2) { - cfg_unsetenv(argv[1]); - - } else if(argc == 3) { - cfg_setenv(argv[1], argv[2]); - - } else { - printf("Usage: %s [VARIABLE] [VALUE]\n", argv[0]); - - return -1; - } - - return 0; -} - - -static int builtin_rebuildcfg(int argc, char *argv[]) { - if(argc != 1) { - printf("Usage: %s\n", argv[0]); - - return -1; - } - - return ingenic_rebuild(device); -} - -static int builtin_safe(int argc, char *argv[]) { - if(argc < 2) { - printf("Usage: %s [ARG]...\n", argv[0]); - - return -1; - } - - if(shell_run(argc - 1, argv + 1) == -1) - perror("shell_run"); - - return 0; -} - -static const struct { - int set; - const char *name; - const shell_command_t *commands; -} cmdsets[] = { - { CMDSET_SPL, "SPL", spl_cmdset }, - { CMDSET_USBBOOT, "USBBoot", usbboot_cmdset }, - { 0, NULL, NULL } -}; - static void shell_update_cmdset(void *arg) { - set_cmds = NULL; + shell_context_t *ctx = arg; - int set = ingenic_cmdset(device); + ctx->set_cmds = NULL; + + int set = ingenic_cmdset(ctx->device); for(int i = 0; cmdsets[i].name != NULL; i++) { if(cmdsets[i].set == set) { - printf("Shell: using command set '%s', run 'help' for command list. CPU: %04X\n", cmdsets[i].name, ingenic_type(device)); + printf("Shell: using command set '%s', run 'help' for command list. CPU: %04X\n", cmdsets[i].name, ingenic_type(ctx->device)); - set_cmds = cmdsets[i].commands; + ctx->set_cmds = cmdsets[i].commands; return; } @@ -432,6 +308,11 @@ static void shell_update_cmdset(void *arg) { debug(LEVEL_ERROR, "Shell: unknown cmdset %d\n", set); } -void *shell_device() { - return device; +void *shell_device(shell_context_t *ctx) { + return ctx->device; } + +void shell_exit(shell_context_t *ctx, int val) { + ctx->shell_exit = val; +} + diff --git a/shell.h b/shell.h index 0f11518..8a77369 100644 --- a/shell.h +++ b/shell.h @@ -19,32 +19,30 @@ #ifndef __SHELL__H__ #define __SHELL__H__ -typedef struct { +#ifndef SHELL_INTERNALS +typedef void shell_context_t; +#endif + +typedef struct shell_command { const char *cmd; const char *description; - int (*handler)(int argc, char *argv[]); + int (*handler)(shell_context_t *ctx, int argc, char *argv[]); } shell_command_t; -int shell_init(void *ingenic); -void shell_fini(); +shell_context_t *shell_init(void *ingenic); +void shell_fini(shell_context_t *context); -void shell_interactive(); -int shell_source(const char *filename); -int shell_execute(const char *input); +void shell_interactive(shell_context_t *ctx); +int shell_source(shell_context_t *ctx, const char *filename); +int shell_execute(shell_context_t *ctx, const char *input); +void *shell_device(shell_context_t *ctx); +int shell_run(shell_context_t *ctx, int argc, char *argv[]); -void *shell_device(); - -// lexer interface -extern char *strval; - -#define TOK_SEPARATOR 1 -#define TOK_STRING 2 -#define TOK_SPACE 3 -#define TOK_COMMENT 4 - -int shell_pull(char *buf, int maxlen); +void shell_exit(shell_context_t *ctx, int val); +int shell_enumerate_commands(shell_context_t *ctx, int (*callback)(shell_context_t *ctx, const shell_command_t *cmd, void *arg), void *arg); extern const shell_command_t spl_cmdset[]; extern const shell_command_t usbboot_cmdset[]; +extern const shell_command_t builtin_cmdset[]; #endif diff --git a/shell_builtins.c b/shell_builtins.c new file mode 100644 index 0000000..675da32 --- /dev/null +++ b/shell_builtins.c @@ -0,0 +1,181 @@ +/* + * JzBoot: an USB bootloader for JZ series of Ingenic(R) microprocessors. + * Copyright (C) 2010 Sergey Gridassov , + * Peter Zotov + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include +#include +#include +#include + +#include "shell.h" +#include "config.h" +#include "ingenic.h" + +static int builtin_help(shell_context_t *ctx, int argc, char *argv[]); +static int builtin_exit(shell_context_t *ctx, int argc, char *argv[]); +static int builtin_source(shell_context_t *ctx, int argc, char *argv[]); +static int builtin_echo(shell_context_t *ctx, int argc, char *argv[]); +static int builtin_sleep(shell_context_t *ctx, int argc, char *argv[]); +static int builtin_redetect(shell_context_t *ctx, int argc, char *argv[]); +static int builtin_rebuildcfg(shell_context_t *ctx, int argc, char *argv[]); +static int builtin_set(shell_context_t *ctx, int argc, char *argv[]); +static int builtin_safe(shell_context_t *ctx, int argc, char *argv[]); + +const shell_command_t builtin_cmdset[] = { + { "help", "- Display this message", builtin_help }, + { "exit", "- Batch: stop current script, interactive: end session", builtin_exit }, + { "source", " - run specified script", builtin_source }, + { "echo", " - output specified string", builtin_echo }, + { "sleep", " - sleep a specified amount of time", builtin_sleep }, + { "set", "[VARIABLE] [VALUE] - print or set configuraton variables", builtin_set }, + { "safe", " [ARG]... - run command ignoring errors", builtin_safe }, + + { "redetect", " - Redetect CPU", builtin_redetect }, + { "rebuildcfg", " - Rebuild firmware configuration data", builtin_rebuildcfg }, + + { NULL, NULL, NULL } +}; + +static int builtin_help(shell_context_t *ctx, int argc, char *argv[]) { +/* for(int i = 0; commands[i].cmd != NULL; i++) { + printf("%s %s\n", commands[i].cmd, commands[i].description); + } + + if(set_cmds) { + for(int i = 0; set_cmds[i].cmd != NULL; i++) + printf("%s %s\n", set_cmds[i].cmd, set_cmds[i].description); + }*/ + + return 0; +} + +static int builtin_exit(shell_context_t *ctx, int argc, char *argv[]) { + shell_exit(ctx, 1); + + return 0; +} + +static int builtin_source(shell_context_t *ctx, int argc, char *argv[]) { + if(argc != 2) { + printf("Usage: %s \n", argv[0]); + + return -1; + } + + int ret = shell_source(ctx, argv[1]); + + if(ret == -1) { + fprintf(stderr, "Error while sourcing file %s: %s\n", argv[1], strerror(errno)); + } + + shell_exit(ctx, 0); + + return ret; +} + +static int builtin_echo(shell_context_t *ctx, int argc, char *argv[]) { + if(argc < 2) { + printf("Usage: %s \n", argv[0]); + + return -1; + } + + for(int i = 1; i < argc; i++) { + fputs(argv[i], stdout); + + putchar((i < argc - 1) ? ' ' : '\n'); + } + + return 0; +} + +static int builtin_sleep(shell_context_t *ctx, int argc, char *argv[]) { + if(argc != 2) { + printf("Usage: %s \n", argv[0]); + + return -1; + } + + uint32_t ms = atoi(argv[1]); + + usleep(ms * 1000); + + return 0; +} + +static int builtin_redetect(shell_context_t *ctx, int argc, char *argv[]) { + if(argc != 1) { + printf("Usage: %s\n", argv[0]); + + return -1; + } + + if(ingenic_redetect(shell_device(ctx)) == -1) { + perror("ingenic_redetect"); + + return -1; + } else + return 0; +} + + +static int builtin_set(shell_context_t *ctx, int argc, char *argv[]) { + if(argc == 1 && cfg_environ) { + for(int i = 0; cfg_environ[i] != NULL; i++) + printf("%s\n", cfg_environ[i]); + + } else if(argc == 2) { + cfg_unsetenv(argv[1]); + + } else if(argc == 3) { + cfg_setenv(argv[1], argv[2]); + + } else { + printf("Usage: %s [VARIABLE] [VALUE]\n", argv[0]); + + return -1; + } + + return 0; +} + + +static int builtin_rebuildcfg(shell_context_t *ctx, int argc, char *argv[]) { + if(argc != 1) { + printf("Usage: %s\n", argv[0]); + + return -1; + } + + return ingenic_rebuild(shell_device(ctx)); +} + +static int builtin_safe(shell_context_t *ctx, int argc, char *argv[]) { + if(argc < 2) { + printf("Usage: %s [ARG]...\n", argv[0]); + + return -1; + } + + if(shell_run(ctx, argc - 1, argv + 1) == -1) + perror("shell_run"); + + return 0; +} + diff --git a/shell_internal.h b/shell_internal.h new file mode 100644 index 0000000..e416c20 --- /dev/null +++ b/shell_internal.h @@ -0,0 +1,62 @@ +/* + * JzBoot: an USB bootloader for JZ series of Ingenic(R) microprocessors. + * Copyright (C) 2010 Sergey Gridassov + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef __SHELL_INTERNAL__H__ +#define __SHELL_INTERNAL__H__ + +#define SHELL_INTERNALS +#define STATE_WANTSTR 0 +#define STATE_WANTSPACE 1 + +#define TOK_SEPARATOR 1 +#define TOK_STRING 2 +#define TOK_SPACE 3 +#define TOK_COMMENT 4 + +typedef struct { + void *device; + char linebuf[512]; + char *strval; + char *line; + const struct shell_command *set_cmds; + int shell_exit; +} shell_context_t; + + +typedef struct { + int argc; + char **argv; +} shell_run_data_t; + +int shell_pull(shell_context_t *ctx, char *buf, int maxlen); + +#ifndef FLEX_SCANNER +typedef void *yyscan_t; +int yylex_init(yyscan_t *ptr_yy_globals); +int yylex_init_extra(shell_context_t *user_defined, yyscan_t *ptr_yy_globals); +int yylex(yyscan_t yyscanner) ; +int yylex_destroy (yyscan_t yyscanner) ; +#else +#define YY_EXTRA_TYPE shell_context_t * +#define YY_INPUT(buf, result, max_size) result = shell_pull(yyextra, buf, max_size); +#endif + +#include "shell.h" + +#endif + diff --git a/shell_lex.c b/shell_lex.c index eea7de3..c32427d 100644 --- a/shell_lex.c +++ b/shell_lex.c @@ -119,24 +119,41 @@ typedef unsigned int flex_uint32_t; */ #define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c) +/* An opaque pointer. */ +#ifndef YY_TYPEDEF_YY_SCANNER_T +#define YY_TYPEDEF_YY_SCANNER_T +typedef void* yyscan_t; +#endif + +/* For convenience, these vars (plus the bison vars far below) + are macros in the reentrant scanner. */ +#define yyin yyg->yyin_r +#define yyout yyg->yyout_r +#define yyextra yyg->yyextra_r +#define yyleng yyg->yyleng_r +#define yytext yyg->yytext_r +#define yylineno (YY_CURRENT_BUFFER_LVALUE->yy_bs_lineno) +#define yycolumn (YY_CURRENT_BUFFER_LVALUE->yy_bs_column) +#define yy_flex_debug yyg->yy_flex_debug_r + /* Enter a start condition. This macro really ought to take a parameter, * but we do it the disgusting crufty way forced on us by the ()-less * definition of BEGIN. */ -#define BEGIN (yy_start) = 1 + 2 * +#define BEGIN yyg->yy_start = 1 + 2 * /* Translate the current start state into a value that can be later handed * to BEGIN to return to the state. The YYSTATE alias is for lex * compatibility. */ -#define YY_START (((yy_start) - 1) / 2) +#define YY_START ((yyg->yy_start - 1) / 2) #define YYSTATE YY_START /* Action number for EOF rule of a given start state. */ #define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) /* Special action meaning "start processing a new file". */ -#define YY_NEW_FILE yyrestart(yyin ) +#define YY_NEW_FILE yyrestart(yyin ,yyscanner ) #define YY_END_OF_BUFFER_CHAR 0 @@ -162,10 +179,6 @@ typedef unsigned int flex_uint32_t; typedef struct yy_buffer_state *YY_BUFFER_STATE; #endif -extern int yyleng; - -extern FILE *yyin, *yyout; - #define EOB_ACT_CONTINUE_SCAN 0 #define EOB_ACT_END_OF_FILE 1 #define EOB_ACT_LAST_MATCH 2 @@ -179,14 +192,14 @@ extern FILE *yyin, *yyout; /* Undo effects of setting up yytext. */ \ int yyless_macro_arg = (n); \ YY_LESS_LINENO(yyless_macro_arg);\ - *yy_cp = (yy_hold_char); \ + *yy_cp = yyg->yy_hold_char; \ YY_RESTORE_YY_MORE_OFFSET \ - (yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \ + yyg->yy_c_buf_p = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \ YY_DO_BEFORE_ACTION; /* set up yytext again */ \ } \ while ( 0 ) -#define unput(c) yyunput( c, (yytext_ptr) ) +#define unput(c) yyunput( c, yyg->yytext_ptr , yyscanner ) #ifndef YY_TYPEDEF_YY_SIZE_T #define YY_TYPEDEF_YY_SIZE_T @@ -258,71 +271,51 @@ struct yy_buffer_state }; #endif /* !YY_STRUCT_YY_BUFFER_STATE */ -/* Stack of input buffers. */ -static size_t yy_buffer_stack_top = 0; /**< index of top of stack. */ -static size_t yy_buffer_stack_max = 0; /**< capacity of stack. */ -static YY_BUFFER_STATE * yy_buffer_stack = 0; /**< Stack as an array. */ - /* We provide macros for accessing buffer states in case in the * future we want to put the buffer states in a more general * "scanner state". * * Returns the top of the stack, or NULL. */ -#define YY_CURRENT_BUFFER ( (yy_buffer_stack) \ - ? (yy_buffer_stack)[(yy_buffer_stack_top)] \ +#define YY_CURRENT_BUFFER ( yyg->yy_buffer_stack \ + ? yyg->yy_buffer_stack[yyg->yy_buffer_stack_top] \ : NULL) /* Same as previous macro, but useful when we know that the buffer stack is not * NULL or when we need an lvalue. For internal use only. */ -#define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)] +#define YY_CURRENT_BUFFER_LVALUE yyg->yy_buffer_stack[yyg->yy_buffer_stack_top] -/* yy_hold_char holds the character lost when yytext is formed. */ -static char yy_hold_char; -static int yy_n_chars; /* number of characters read into yy_ch_buf */ -int yyleng; +void yyrestart (FILE *input_file ,yyscan_t yyscanner ); +void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ,yyscan_t yyscanner ); +YY_BUFFER_STATE yy_create_buffer (FILE *file,int size ,yyscan_t yyscanner ); +void yy_delete_buffer (YY_BUFFER_STATE b ,yyscan_t yyscanner ); +void yy_flush_buffer (YY_BUFFER_STATE b ,yyscan_t yyscanner ); +void yypush_buffer_state (YY_BUFFER_STATE new_buffer ,yyscan_t yyscanner ); +void yypop_buffer_state (yyscan_t yyscanner ); -/* Points to current character in buffer. */ -static char *yy_c_buf_p = (char *) 0; -static int yy_init = 0; /* whether we need to initialize */ -static int yy_start = 0; /* start state number */ +static void yyensure_buffer_stack (yyscan_t yyscanner ); +static void yy_load_buffer_state (yyscan_t yyscanner ); +static void yy_init_buffer (YY_BUFFER_STATE b,FILE *file ,yyscan_t yyscanner ); -/* Flag which is used to allow yywrap()'s to do buffer switches - * instead of setting up a fresh yyin. A bit of a hack ... - */ -static int yy_did_buffer_switch_on_eof; +#define YY_FLUSH_BUFFER yy_flush_buffer(YY_CURRENT_BUFFER ,yyscanner) -void yyrestart (FILE *input_file ); -void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ); -YY_BUFFER_STATE yy_create_buffer (FILE *file,int size ); -void yy_delete_buffer (YY_BUFFER_STATE b ); -void yy_flush_buffer (YY_BUFFER_STATE b ); -void yypush_buffer_state (YY_BUFFER_STATE new_buffer ); -void yypop_buffer_state (void ); +YY_BUFFER_STATE yy_scan_buffer (char *base,yy_size_t size ,yyscan_t yyscanner ); +YY_BUFFER_STATE yy_scan_string (yyconst char *yy_str ,yyscan_t yyscanner ); +YY_BUFFER_STATE yy_scan_bytes (yyconst char *bytes,int len ,yyscan_t yyscanner ); -static void yyensure_buffer_stack (void ); -static void yy_load_buffer_state (void ); -static void yy_init_buffer (YY_BUFFER_STATE b,FILE *file ); - -#define YY_FLUSH_BUFFER yy_flush_buffer(YY_CURRENT_BUFFER ) - -YY_BUFFER_STATE yy_scan_buffer (char *base,yy_size_t size ); -YY_BUFFER_STATE yy_scan_string (yyconst char *yy_str ); -YY_BUFFER_STATE yy_scan_bytes (yyconst char *bytes,int len ); - -void *yyalloc (yy_size_t ); -void *yyrealloc (void *,yy_size_t ); -void yyfree (void * ); +void *yyalloc (yy_size_t ,yyscan_t yyscanner ); +void *yyrealloc (void *,yy_size_t ,yyscan_t yyscanner ); +void yyfree (void * ,yyscan_t yyscanner ); #define yy_new_buffer yy_create_buffer #define yy_set_interactive(is_interactive) \ { \ if ( ! YY_CURRENT_BUFFER ){ \ - yyensure_buffer_stack (); \ + yyensure_buffer_stack (yyscanner); \ YY_CURRENT_BUFFER_LVALUE = \ - yy_create_buffer(yyin,YY_BUF_SIZE ); \ + yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner); \ } \ YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \ } @@ -330,9 +323,9 @@ void yyfree (void * ); #define yy_set_bol(at_bol) \ { \ if ( ! YY_CURRENT_BUFFER ){\ - yyensure_buffer_stack (); \ + yyensure_buffer_stack (yyscanner); \ YY_CURRENT_BUFFER_LVALUE = \ - yy_create_buffer(yyin,YY_BUF_SIZE ); \ + yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner); \ } \ YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \ } @@ -344,31 +337,24 @@ void yyfree (void * ); typedef unsigned char YY_CHAR; -FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0; - typedef int yy_state_type; -extern int yylineno; +#define yytext_ptr yytext_r -int yylineno = 1; - -extern char *yytext; -#define yytext_ptr yytext - -static yy_state_type yy_get_previous_state (void ); -static yy_state_type yy_try_NUL_trans (yy_state_type current_state ); -static int yy_get_next_buffer (void ); -static void yy_fatal_error (yyconst char msg[] ); +static yy_state_type yy_get_previous_state (yyscan_t yyscanner ); +static yy_state_type yy_try_NUL_trans (yy_state_type current_state ,yyscan_t yyscanner); +static int yy_get_next_buffer (yyscan_t yyscanner ); +static void yy_fatal_error (yyconst char msg[] ,yyscan_t yyscanner ); /* Done after the current pattern has been matched and before the * corresponding action - sets up yytext. */ #define YY_DO_BEFORE_ACTION \ - (yytext_ptr) = yy_bp; \ + yyg->yytext_ptr = yy_bp; \ yyleng = (size_t) (yy_cp - yy_bp); \ - (yy_hold_char) = *yy_cp; \ + yyg->yy_hold_char = *yy_cp; \ *yy_cp = '\0'; \ - (yy_c_buf_p) = yy_cp; + yyg->yy_c_buf_p = yy_cp; #define YY_NUM_RULES 10 #define YY_END_OF_BUFFER 11 @@ -452,12 +438,6 @@ static yyconst flex_int16_t yy_chk[36] = 18, 18, 18, 18, 18 } ; -static yy_state_type yy_last_accepting_state; -static char *yy_last_accepting_cpos; - -extern int yy_flex_debug; -int yy_flex_debug = 0; - /* The intent behind this definition is that it'll catch * any uses of REJECT which flex missed. */ @@ -465,7 +445,6 @@ int yy_flex_debug = 0; #define yymore() yymore_used_but_not_detected #define YY_MORE_ADJ 0 #define YY_RESTORE_YY_MORE_OFFSET -char *yytext; #line 1 "shell_lex.l" /* * JzBoot: an USB bootloader for JZ series of Ingenic(R) microprocessors. @@ -485,12 +464,10 @@ char *yytext; * along with this program. If not, see . */ #line 20 "shell_lex.l" -#include "shell.h" +#include "shell_internal.h" #include #include -#define YY_INPUT(buf, result, max_size) result = shell_pull(buf, max_size); - static char *str_append(char *str, const char *src) { if(str) { size_t newlen = strlen(str) + strlen(src) + 1; @@ -508,7 +485,7 @@ static char *str_append(char *str, const char *src) { } #define YY_NO_INPUT 1 -#line 512 "shell_lex.c" +#line 489 "shell_lex.c" #define INITIAL 0 #define STR 1 @@ -525,36 +502,74 @@ static char *str_append(char *str, const char *src) { #define YY_EXTRA_TYPE void * #endif -static int yy_init_globals (void ); +/* Holds the entire state of the reentrant scanner. */ +struct yyguts_t + { + + /* User-defined. Not touched by flex. */ + YY_EXTRA_TYPE yyextra_r; + + /* The rest are the same as the globals declared in the non-reentrant scanner. */ + FILE *yyin_r, *yyout_r; + size_t yy_buffer_stack_top; /**< index of top of stack. */ + size_t yy_buffer_stack_max; /**< capacity of stack. */ + YY_BUFFER_STATE * yy_buffer_stack; /**< Stack as an array. */ + char yy_hold_char; + int yy_n_chars; + int yyleng_r; + char *yy_c_buf_p; + int yy_init; + int yy_start; + int yy_did_buffer_switch_on_eof; + int yy_start_stack_ptr; + int yy_start_stack_depth; + int *yy_start_stack; + yy_state_type yy_last_accepting_state; + char* yy_last_accepting_cpos; + + int yylineno_r; + int yy_flex_debug_r; + + char *yytext_r; + int yy_more_flag; + int yy_more_len; + + }; /* end struct yyguts_t */ + +static int yy_init_globals (yyscan_t yyscanner ); + +int yylex_init (yyscan_t* scanner); + +int yylex_init_extra (YY_EXTRA_TYPE user_defined,yyscan_t* scanner); /* Accessor methods to globals. These are made visible to non-reentrant scanners for convenience. */ -int yylex_destroy (void ); +int yylex_destroy (yyscan_t yyscanner ); -int yyget_debug (void ); +int yyget_debug (yyscan_t yyscanner ); -void yyset_debug (int debug_flag ); +void yyset_debug (int debug_flag ,yyscan_t yyscanner ); -YY_EXTRA_TYPE yyget_extra (void ); +YY_EXTRA_TYPE yyget_extra (yyscan_t yyscanner ); -void yyset_extra (YY_EXTRA_TYPE user_defined ); +void yyset_extra (YY_EXTRA_TYPE user_defined ,yyscan_t yyscanner ); -FILE *yyget_in (void ); +FILE *yyget_in (yyscan_t yyscanner ); -void yyset_in (FILE * in_str ); +void yyset_in (FILE * in_str ,yyscan_t yyscanner ); -FILE *yyget_out (void ); +FILE *yyget_out (yyscan_t yyscanner ); -void yyset_out (FILE * out_str ); +void yyset_out (FILE * out_str ,yyscan_t yyscanner ); -int yyget_leng (void ); +int yyget_leng (yyscan_t yyscanner ); -char *yyget_text (void ); +char *yyget_text (yyscan_t yyscanner ); -int yyget_lineno (void ); +int yyget_lineno (yyscan_t yyscanner ); -void yyset_lineno (int line_number ); +void yyset_lineno (int line_number ,yyscan_t yyscanner ); /* Macros after this point can all be overridden by user definitions in * section 1. @@ -562,26 +577,26 @@ void yyset_lineno (int line_number ); #ifndef YY_SKIP_YYWRAP #ifdef __cplusplus -extern "C" int yywrap (void ); +extern "C" int yywrap (yyscan_t yyscanner ); #else -extern int yywrap (void ); +extern int yywrap (yyscan_t yyscanner ); #endif #endif #ifndef yytext_ptr -static void yy_flex_strncpy (char *,yyconst char *,int ); +static void yy_flex_strncpy (char *,yyconst char *,int ,yyscan_t yyscanner); #endif #ifdef YY_NEED_STRLEN -static int yy_flex_strlen (yyconst char * ); +static int yy_flex_strlen (yyconst char * ,yyscan_t yyscanner); #endif #ifndef YY_NO_INPUT #ifdef __cplusplus -static int yyinput (void ); +static int yyinput (yyscan_t yyscanner ); #else -static int input (void ); +static int input (yyscan_t yyscanner ); #endif #endif @@ -655,7 +670,7 @@ static int input (void ); /* Report a fatal error. */ #ifndef YY_FATAL_ERROR -#define YY_FATAL_ERROR(msg) yy_fatal_error( msg ) +#define YY_FATAL_ERROR(msg) yy_fatal_error( msg , yyscanner) #endif /* end tables serialization structures and prototypes */ @@ -666,9 +681,9 @@ static int input (void ); #ifndef YY_DECL #define YY_DECL_IS_OURS 1 -extern int yylex (void); +extern int yylex (yyscan_t yyscanner); -#define YY_DECL int yylex (void) +#define YY_DECL int yylex (yyscan_t yyscanner) #endif /* !YY_DECL */ /* Code executed at the beginning of each rule, after yytext and yyleng @@ -693,21 +708,22 @@ YY_DECL register yy_state_type yy_current_state; register char *yy_cp, *yy_bp; register int yy_act; - -#line 45 "shell_lex.l" + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; -#line 700 "shell_lex.c" +#line 43 "shell_lex.l" - if ( !(yy_init) ) +#line 716 "shell_lex.c" + + if ( !yyg->yy_init ) { - (yy_init) = 1; + yyg->yy_init = 1; #ifdef YY_USER_INIT YY_USER_INIT; #endif - if ( ! (yy_start) ) - (yy_start) = 1; /* first start state */ + if ( ! yyg->yy_start ) + yyg->yy_start = 1; /* first start state */ if ( ! yyin ) yyin = stdin; @@ -716,35 +732,35 @@ YY_DECL yyout = stdout; if ( ! YY_CURRENT_BUFFER ) { - yyensure_buffer_stack (); + yyensure_buffer_stack (yyscanner); YY_CURRENT_BUFFER_LVALUE = - yy_create_buffer(yyin,YY_BUF_SIZE ); + yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner); } - yy_load_buffer_state( ); + yy_load_buffer_state(yyscanner ); } while ( 1 ) /* loops until end-of-file is reached */ { - yy_cp = (yy_c_buf_p); + yy_cp = yyg->yy_c_buf_p; /* Support of yytext. */ - *yy_cp = (yy_hold_char); + *yy_cp = yyg->yy_hold_char; /* yy_bp points to the position in yy_ch_buf of the start of * the current run. */ yy_bp = yy_cp; - yy_current_state = (yy_start); + yy_current_state = yyg->yy_start; yy_match: do { register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)]; if ( yy_accept[yy_current_state] ) { - (yy_last_accepting_state) = yy_current_state; - (yy_last_accepting_cpos) = yy_cp; + yyg->yy_last_accepting_state = yy_current_state; + yyg->yy_last_accepting_cpos = yy_cp; } while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { @@ -756,8 +772,8 @@ yy_match: ++yy_cp; } while ( yy_current_state != 18 ); - yy_cp = (yy_last_accepting_cpos); - yy_current_state = (yy_last_accepting_state); + yy_cp = yyg->yy_last_accepting_cpos; + yy_current_state = yyg->yy_last_accepting_state; yy_find_action: yy_act = yy_accept[yy_current_state]; @@ -770,64 +786,64 @@ do_action: /* This label is used only to access EOF actions. */ { /* beginning of action switch */ case 0: /* must back up */ /* undo the effects of YY_DO_BEFORE_ACTION */ - *yy_cp = (yy_hold_char); - yy_cp = (yy_last_accepting_cpos); - yy_current_state = (yy_last_accepting_state); + *yy_cp = yyg->yy_hold_char; + yy_cp = yyg->yy_last_accepting_cpos; + yy_current_state = yyg->yy_last_accepting_state; goto yy_find_action; case 1: YY_RULE_SETUP -#line 46 "shell_lex.l" -{ strval = NULL; BEGIN(STR); } +#line 44 "shell_lex.l" +{ yyextra->strval = NULL; BEGIN(STR); } YY_BREAK case 2: YY_RULE_SETUP -#line 47 "shell_lex.l" +#line 45 "shell_lex.l" return TOK_SEPARATOR; YY_BREAK case 3: /* rule 3 can match eol */ YY_RULE_SETUP -#line 48 "shell_lex.l" +#line 46 "shell_lex.l" return TOK_SPACE; YY_BREAK case 4: YY_RULE_SETUP -#line 49 "shell_lex.l" +#line 47 "shell_lex.l" return TOK_COMMENT; YY_BREAK case 5: YY_RULE_SETUP -#line 50 "shell_lex.l" -{ strval = strdup(yytext); return TOK_STRING; } +#line 48 "shell_lex.l" +{ yyextra->strval = strdup(yytext); return TOK_STRING; } YY_BREAK case 6: /* rule 6 can match eol */ YY_RULE_SETUP -#line 51 "shell_lex.l" -strval = str_append(strval, yytext); +#line 49 "shell_lex.l" +yyextra->strval = str_append(yyextra->strval, yytext); YY_BREAK case 7: YY_RULE_SETUP -#line 52 "shell_lex.l" -strval = str_append(strval, "\""); +#line 50 "shell_lex.l" +yyextra->strval = str_append(yyextra->strval, "\""); YY_BREAK case 8: YY_RULE_SETUP -#line 53 "shell_lex.l" -strval = str_append(strval, "\\"); +#line 51 "shell_lex.l" +yyextra->strval = str_append(yyextra->strval, "\\"); YY_BREAK case 9: YY_RULE_SETUP -#line 54 "shell_lex.l" +#line 52 "shell_lex.l" { BEGIN(INITIAL); return TOK_STRING; } YY_BREAK case 10: YY_RULE_SETUP -#line 55 "shell_lex.l" +#line 53 "shell_lex.l" ECHO; YY_BREAK -#line 831 "shell_lex.c" +#line 847 "shell_lex.c" case YY_STATE_EOF(INITIAL): case YY_STATE_EOF(STR): yyterminate(); @@ -835,10 +851,10 @@ case YY_STATE_EOF(STR): case YY_END_OF_BUFFER: { /* Amount of text matched not including the EOB char. */ - int yy_amount_of_matched_text = (int) (yy_cp - (yytext_ptr)) - 1; + int yy_amount_of_matched_text = (int) (yy_cp - yyg->yytext_ptr) - 1; /* Undo the effects of YY_DO_BEFORE_ACTION. */ - *yy_cp = (yy_hold_char); + *yy_cp = yyg->yy_hold_char; YY_RESTORE_YY_MORE_OFFSET if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW ) @@ -852,7 +868,7 @@ case YY_STATE_EOF(STR): * this is the first action (other than possibly a * back-up) that will match for the new input source. */ - (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; + yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin; YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL; } @@ -864,13 +880,13 @@ case YY_STATE_EOF(STR): * end-of-buffer state). Contrast this with the test * in input(). */ - if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) + if ( yyg->yy_c_buf_p <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] ) { /* This was really a NUL. */ yy_state_type yy_next_state; - (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text; + yyg->yy_c_buf_p = yyg->yytext_ptr + yy_amount_of_matched_text; - yy_current_state = yy_get_previous_state( ); + yy_current_state = yy_get_previous_state( yyscanner ); /* Okay, we're now positioned to make the NUL * transition. We couldn't have @@ -881,33 +897,33 @@ case YY_STATE_EOF(STR): * will run more slowly). */ - yy_next_state = yy_try_NUL_trans( yy_current_state ); + yy_next_state = yy_try_NUL_trans( yy_current_state , yyscanner); - yy_bp = (yytext_ptr) + YY_MORE_ADJ; + yy_bp = yyg->yytext_ptr + YY_MORE_ADJ; if ( yy_next_state ) { /* Consume the NUL. */ - yy_cp = ++(yy_c_buf_p); + yy_cp = ++yyg->yy_c_buf_p; yy_current_state = yy_next_state; goto yy_match; } else { - yy_cp = (yy_last_accepting_cpos); - yy_current_state = (yy_last_accepting_state); + yy_cp = yyg->yy_last_accepting_cpos; + yy_current_state = yyg->yy_last_accepting_state; goto yy_find_action; } } - else switch ( yy_get_next_buffer( ) ) + else switch ( yy_get_next_buffer( yyscanner ) ) { case EOB_ACT_END_OF_FILE: { - (yy_did_buffer_switch_on_eof) = 0; + yyg->yy_did_buffer_switch_on_eof = 0; - if ( yywrap( ) ) + if ( yywrap(yyscanner ) ) { /* Note: because we've taken care in * yy_get_next_buffer() to have set up @@ -918,7 +934,7 @@ case YY_STATE_EOF(STR): * YY_NULL, it'll still work - another * YY_NULL will get returned. */ - (yy_c_buf_p) = (yytext_ptr) + YY_MORE_ADJ; + yyg->yy_c_buf_p = yyg->yytext_ptr + YY_MORE_ADJ; yy_act = YY_STATE_EOF(YY_START); goto do_action; @@ -926,30 +942,30 @@ case YY_STATE_EOF(STR): else { - if ( ! (yy_did_buffer_switch_on_eof) ) + if ( ! yyg->yy_did_buffer_switch_on_eof ) YY_NEW_FILE; } break; } case EOB_ACT_CONTINUE_SCAN: - (yy_c_buf_p) = - (yytext_ptr) + yy_amount_of_matched_text; + yyg->yy_c_buf_p = + yyg->yytext_ptr + yy_amount_of_matched_text; - yy_current_state = yy_get_previous_state( ); + yy_current_state = yy_get_previous_state( yyscanner ); - yy_cp = (yy_c_buf_p); - yy_bp = (yytext_ptr) + YY_MORE_ADJ; + yy_cp = yyg->yy_c_buf_p; + yy_bp = yyg->yytext_ptr + YY_MORE_ADJ; goto yy_match; case EOB_ACT_LAST_MATCH: - (yy_c_buf_p) = - &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)]; + yyg->yy_c_buf_p = + &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars]; - yy_current_state = yy_get_previous_state( ); + yy_current_state = yy_get_previous_state( yyscanner ); - yy_cp = (yy_c_buf_p); - yy_bp = (yytext_ptr) + YY_MORE_ADJ; + yy_cp = yyg->yy_c_buf_p; + yy_bp = yyg->yytext_ptr + YY_MORE_ADJ; goto yy_find_action; } break; @@ -969,20 +985,21 @@ case YY_STATE_EOF(STR): * EOB_ACT_CONTINUE_SCAN - continue scanning from current position * EOB_ACT_END_OF_FILE - end of file */ -static int yy_get_next_buffer (void) +static int yy_get_next_buffer (yyscan_t yyscanner) { - register char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; - register char *source = (yytext_ptr); + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + register char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; + register char *source = yyg->yytext_ptr; register int number_to_move, i; int ret_val; - if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] ) + if ( yyg->yy_c_buf_p > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] ) YY_FATAL_ERROR( "fatal flex scanner internal error--end of buffer missed" ); if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 ) { /* Don't try to fill the buffer, so this is an EOF. */ - if ( (yy_c_buf_p) - (yytext_ptr) - YY_MORE_ADJ == 1 ) + if ( yyg->yy_c_buf_p - yyg->yytext_ptr - YY_MORE_ADJ == 1 ) { /* We matched a single character, the EOB, so * treat this as a final EOF. @@ -1002,7 +1019,7 @@ static int yy_get_next_buffer (void) /* Try to read more data. */ /* First move last chars to start of buffer. */ - number_to_move = (int) ((yy_c_buf_p) - (yytext_ptr)) - 1; + number_to_move = (int) (yyg->yy_c_buf_p - yyg->yytext_ptr) - 1; for ( i = 0; i < number_to_move; ++i ) *(dest++) = *(source++); @@ -1011,7 +1028,7 @@ static int yy_get_next_buffer (void) /* don't do the read, it's not guaranteed to return an EOF, * just force an EOF */ - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0; + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars = 0; else { @@ -1025,7 +1042,7 @@ static int yy_get_next_buffer (void) YY_BUFFER_STATE b = YY_CURRENT_BUFFER; int yy_c_buf_p_offset = - (int) ((yy_c_buf_p) - b->yy_ch_buf); + (int) (yyg->yy_c_buf_p - b->yy_ch_buf); if ( b->yy_is_our_buffer ) { @@ -1038,7 +1055,7 @@ static int yy_get_next_buffer (void) b->yy_ch_buf = (char *) /* Include room in for 2 EOB chars. */ - yyrealloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 ); + yyrealloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 ,yyscanner ); } else /* Can't grow it, we don't own it. */ @@ -1048,7 +1065,7 @@ static int yy_get_next_buffer (void) YY_FATAL_ERROR( "fatal error - scanner input buffer overflow" ); - (yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset]; + yyg->yy_c_buf_p = &b->yy_ch_buf[yy_c_buf_p_offset]; num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; @@ -1060,17 +1077,17 @@ static int yy_get_next_buffer (void) /* Read in more data. */ YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]), - (yy_n_chars), (size_t) num_to_read ); + yyg->yy_n_chars, (size_t) num_to_read ); - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars; } - if ( (yy_n_chars) == 0 ) + if ( yyg->yy_n_chars == 0 ) { if ( number_to_move == YY_MORE_ADJ ) { ret_val = EOB_ACT_END_OF_FILE; - yyrestart(yyin ); + yyrestart(yyin ,yyscanner); } else @@ -1084,39 +1101,40 @@ static int yy_get_next_buffer (void) else ret_val = EOB_ACT_CONTINUE_SCAN; - if ((yy_size_t) ((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { + if ((yy_size_t) (yyg->yy_n_chars + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { /* Extend the array by 50%, plus the number we really need. */ - yy_size_t new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1); - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size ); + yy_size_t new_size = yyg->yy_n_chars + number_to_move + (yyg->yy_n_chars >> 1); + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size ,yyscanner ); if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" ); } - (yy_n_chars) += number_to_move; - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR; - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR; + yyg->yy_n_chars += number_to_move; + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] = YY_END_OF_BUFFER_CHAR; + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR; - (yytext_ptr) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0]; + yyg->yytext_ptr = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0]; return ret_val; } /* yy_get_previous_state - get the state just before the EOB char was reached */ - static yy_state_type yy_get_previous_state (void) + static yy_state_type yy_get_previous_state (yyscan_t yyscanner) { register yy_state_type yy_current_state; register char *yy_cp; - - yy_current_state = (yy_start); + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp ) + yy_current_state = yyg->yy_start; + + for ( yy_cp = yyg->yytext_ptr + YY_MORE_ADJ; yy_cp < yyg->yy_c_buf_p; ++yy_cp ) { register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); if ( yy_accept[yy_current_state] ) { - (yy_last_accepting_state) = yy_current_state; - (yy_last_accepting_cpos) = yy_cp; + yyg->yy_last_accepting_state = yy_current_state; + yyg->yy_last_accepting_cpos = yy_cp; } while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { @@ -1135,16 +1153,17 @@ static int yy_get_next_buffer (void) * synopsis * next_state = yy_try_NUL_trans( current_state ); */ - static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state ) + static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state , yyscan_t yyscanner) { register int yy_is_jam; - register char *yy_cp = (yy_c_buf_p); + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; /* This var may be unused depending upon options. */ + register char *yy_cp = yyg->yy_c_buf_p; register YY_CHAR yy_c = 1; if ( yy_accept[yy_current_state] ) { - (yy_last_accepting_state) = yy_current_state; - (yy_last_accepting_cpos) = yy_cp; + yyg->yy_last_accepting_state = yy_current_state; + yyg->yy_last_accepting_cpos = yy_cp; } while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { @@ -1160,32 +1179,33 @@ static int yy_get_next_buffer (void) #ifndef YY_NO_INPUT #ifdef __cplusplus - static int yyinput (void) + static int yyinput (yyscan_t yyscanner) #else - static int input (void) + static int input (yyscan_t yyscanner) #endif { int c; - - *(yy_c_buf_p) = (yy_hold_char); + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - if ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR ) + *yyg->yy_c_buf_p = yyg->yy_hold_char; + + if ( *yyg->yy_c_buf_p == YY_END_OF_BUFFER_CHAR ) { /* yy_c_buf_p now points to the character we want to return. * If this occurs *before* the EOB characters, then it's a * valid NUL; if not, then we've hit the end of the buffer. */ - if ( (yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) + if ( yyg->yy_c_buf_p < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] ) /* This was really a NUL. */ - *(yy_c_buf_p) = '\0'; + *yyg->yy_c_buf_p = '\0'; else { /* need more input */ - int offset = (yy_c_buf_p) - (yytext_ptr); - ++(yy_c_buf_p); + int offset = yyg->yy_c_buf_p - yyg->yytext_ptr; + ++yyg->yy_c_buf_p; - switch ( yy_get_next_buffer( ) ) + switch ( yy_get_next_buffer( yyscanner ) ) { case EOB_ACT_LAST_MATCH: /* This happens because yy_g_n_b() @@ -1199,34 +1219,34 @@ static int yy_get_next_buffer (void) */ /* Reset buffer status. */ - yyrestart(yyin ); + yyrestart(yyin ,yyscanner); /*FALLTHROUGH*/ case EOB_ACT_END_OF_FILE: { - if ( yywrap( ) ) + if ( yywrap(yyscanner ) ) return EOF; - if ( ! (yy_did_buffer_switch_on_eof) ) + if ( ! yyg->yy_did_buffer_switch_on_eof ) YY_NEW_FILE; #ifdef __cplusplus - return yyinput(); + return yyinput(yyscanner); #else - return input(); + return input(yyscanner); #endif } case EOB_ACT_CONTINUE_SCAN: - (yy_c_buf_p) = (yytext_ptr) + offset; + yyg->yy_c_buf_p = yyg->yytext_ptr + offset; break; } } } - c = *(unsigned char *) (yy_c_buf_p); /* cast for 8-bit char's */ - *(yy_c_buf_p) = '\0'; /* preserve yytext */ - (yy_hold_char) = *++(yy_c_buf_p); + c = *(unsigned char *) yyg->yy_c_buf_p; /* cast for 8-bit char's */ + *yyg->yy_c_buf_p = '\0'; /* preserve yytext */ + yyg->yy_hold_char = *++yyg->yy_c_buf_p; return c; } @@ -1234,76 +1254,79 @@ static int yy_get_next_buffer (void) /** Immediately switch to a different input stream. * @param input_file A readable stream. - * + * @param yyscanner The scanner object. * @note This function does not reset the start condition to @c INITIAL . */ - void yyrestart (FILE * input_file ) + void yyrestart (FILE * input_file , yyscan_t yyscanner) { - + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + if ( ! YY_CURRENT_BUFFER ){ - yyensure_buffer_stack (); + yyensure_buffer_stack (yyscanner); YY_CURRENT_BUFFER_LVALUE = - yy_create_buffer(yyin,YY_BUF_SIZE ); + yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner); } - yy_init_buffer(YY_CURRENT_BUFFER,input_file ); - yy_load_buffer_state( ); + yy_init_buffer(YY_CURRENT_BUFFER,input_file ,yyscanner); + yy_load_buffer_state(yyscanner ); } /** Switch to a different input buffer. * @param new_buffer The new input buffer. - * + * @param yyscanner The scanner object. */ - void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ) + void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner) { - + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + /* TODO. We should be able to replace this entire function body * with * yypop_buffer_state(); * yypush_buffer_state(new_buffer); */ - yyensure_buffer_stack (); + yyensure_buffer_stack (yyscanner); if ( YY_CURRENT_BUFFER == new_buffer ) return; if ( YY_CURRENT_BUFFER ) { /* Flush out information for old buffer. */ - *(yy_c_buf_p) = (yy_hold_char); - YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + *yyg->yy_c_buf_p = yyg->yy_hold_char; + YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p; + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars; } YY_CURRENT_BUFFER_LVALUE = new_buffer; - yy_load_buffer_state( ); + yy_load_buffer_state(yyscanner ); /* We don't actually know whether we did this switch during * EOF (yywrap()) processing, but the only time this flag * is looked at is after yywrap() is called, so it's safe * to go ahead and always set it. */ - (yy_did_buffer_switch_on_eof) = 1; + yyg->yy_did_buffer_switch_on_eof = 1; } -static void yy_load_buffer_state (void) +static void yy_load_buffer_state (yyscan_t yyscanner) { - (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; - (yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos; + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; + yyg->yytext_ptr = yyg->yy_c_buf_p = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos; yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file; - (yy_hold_char) = *(yy_c_buf_p); + yyg->yy_hold_char = *yyg->yy_c_buf_p; } /** Allocate and initialize an input buffer state. * @param file A readable stream. * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE. - * + * @param yyscanner The scanner object. * @return the allocated buffer state. */ - YY_BUFFER_STATE yy_create_buffer (FILE * file, int size ) + YY_BUFFER_STATE yy_create_buffer (FILE * file, int size , yyscan_t yyscanner) { YY_BUFFER_STATE b; - b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) ); + b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) ,yyscanner ); if ( ! b ) YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); @@ -1312,24 +1335,25 @@ static void yy_load_buffer_state (void) /* yy_ch_buf has to be 2 characters longer than the size given because * we need to put in 2 end-of-buffer characters. */ - b->yy_ch_buf = (char *) yyalloc(b->yy_buf_size + 2 ); + b->yy_ch_buf = (char *) yyalloc(b->yy_buf_size + 2 ,yyscanner ); if ( ! b->yy_ch_buf ) YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); b->yy_is_our_buffer = 1; - yy_init_buffer(b,file ); + yy_init_buffer(b,file ,yyscanner); return b; } /** Destroy the buffer. * @param b a buffer created with yy_create_buffer() - * + * @param yyscanner The scanner object. */ - void yy_delete_buffer (YY_BUFFER_STATE b ) + void yy_delete_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner) { - + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + if ( ! b ) return; @@ -1337,9 +1361,9 @@ static void yy_load_buffer_state (void) YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0; if ( b->yy_is_our_buffer ) - yyfree((void *) b->yy_ch_buf ); + yyfree((void *) b->yy_ch_buf ,yyscanner ); - yyfree((void *) b ); + yyfree((void *) b ,yyscanner ); } #ifndef __cplusplus @@ -1350,12 +1374,13 @@ extern int isatty (int ); * This function is sometimes called more than once on the same buffer, * such as during a yyrestart() or at EOF. */ - static void yy_init_buffer (YY_BUFFER_STATE b, FILE * file ) + static void yy_init_buffer (YY_BUFFER_STATE b, FILE * file , yyscan_t yyscanner) { int oerrno = errno; - - yy_flush_buffer(b ); + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + + yy_flush_buffer(b ,yyscanner); b->yy_input_file = file; b->yy_fill_buffer = 1; @@ -1376,11 +1401,12 @@ extern int isatty (int ); /** Discard all buffered characters. On the next scan, YY_INPUT will be called. * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER. - * + * @param yyscanner The scanner object. */ - void yy_flush_buffer (YY_BUFFER_STATE b ) + void yy_flush_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner) { - if ( ! b ) + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + if ( ! b ) return; b->yy_n_chars = 0; @@ -1398,114 +1424,117 @@ extern int isatty (int ); b->yy_buffer_status = YY_BUFFER_NEW; if ( b == YY_CURRENT_BUFFER ) - yy_load_buffer_state( ); + yy_load_buffer_state(yyscanner ); } /** Pushes the new state onto the stack. The new state becomes * the current state. This function will allocate the stack * if necessary. * @param new_buffer The new state. - * + * @param yyscanner The scanner object. */ -void yypush_buffer_state (YY_BUFFER_STATE new_buffer ) +void yypush_buffer_state (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner) { - if (new_buffer == NULL) + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + if (new_buffer == NULL) return; - yyensure_buffer_stack(); + yyensure_buffer_stack(yyscanner); /* This block is copied from yy_switch_to_buffer. */ if ( YY_CURRENT_BUFFER ) { /* Flush out information for old buffer. */ - *(yy_c_buf_p) = (yy_hold_char); - YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + *yyg->yy_c_buf_p = yyg->yy_hold_char; + YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p; + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars; } /* Only push if top exists. Otherwise, replace top. */ if (YY_CURRENT_BUFFER) - (yy_buffer_stack_top)++; + yyg->yy_buffer_stack_top++; YY_CURRENT_BUFFER_LVALUE = new_buffer; /* copied from yy_switch_to_buffer. */ - yy_load_buffer_state( ); - (yy_did_buffer_switch_on_eof) = 1; + yy_load_buffer_state(yyscanner ); + yyg->yy_did_buffer_switch_on_eof = 1; } /** Removes and deletes the top of the stack, if present. * The next element becomes the new top. - * + * @param yyscanner The scanner object. */ -void yypop_buffer_state (void) +void yypop_buffer_state (yyscan_t yyscanner) { - if (!YY_CURRENT_BUFFER) + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + if (!YY_CURRENT_BUFFER) return; - yy_delete_buffer(YY_CURRENT_BUFFER ); + yy_delete_buffer(YY_CURRENT_BUFFER ,yyscanner); YY_CURRENT_BUFFER_LVALUE = NULL; - if ((yy_buffer_stack_top) > 0) - --(yy_buffer_stack_top); + if (yyg->yy_buffer_stack_top > 0) + --yyg->yy_buffer_stack_top; if (YY_CURRENT_BUFFER) { - yy_load_buffer_state( ); - (yy_did_buffer_switch_on_eof) = 1; + yy_load_buffer_state(yyscanner ); + yyg->yy_did_buffer_switch_on_eof = 1; } } /* Allocates the stack if it does not exist. * Guarantees space for at least one push. */ -static void yyensure_buffer_stack (void) +static void yyensure_buffer_stack (yyscan_t yyscanner) { int num_to_alloc; - - if (!(yy_buffer_stack)) { + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + + if (!yyg->yy_buffer_stack) { /* First allocation is just for 2 elements, since we don't know if this * scanner will even need a stack. We use 2 instead of 1 to avoid an * immediate realloc on the next call. */ num_to_alloc = 1; - (yy_buffer_stack) = (struct yy_buffer_state**)yyalloc + yyg->yy_buffer_stack = (struct yy_buffer_state**)yyalloc (num_to_alloc * sizeof(struct yy_buffer_state*) - ); - if ( ! (yy_buffer_stack) ) + , yyscanner); + if ( ! yyg->yy_buffer_stack ) YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); - memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*)); + memset(yyg->yy_buffer_stack, 0, num_to_alloc * sizeof(struct yy_buffer_state*)); - (yy_buffer_stack_max) = num_to_alloc; - (yy_buffer_stack_top) = 0; + yyg->yy_buffer_stack_max = num_to_alloc; + yyg->yy_buffer_stack_top = 0; return; } - if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){ + if (yyg->yy_buffer_stack_top >= (yyg->yy_buffer_stack_max) - 1){ /* Increase the buffer to prepare for a possible push. */ int grow_size = 8 /* arbitrary grow size */; - num_to_alloc = (yy_buffer_stack_max) + grow_size; - (yy_buffer_stack) = (struct yy_buffer_state**)yyrealloc - ((yy_buffer_stack), + num_to_alloc = yyg->yy_buffer_stack_max + grow_size; + yyg->yy_buffer_stack = (struct yy_buffer_state**)yyrealloc + (yyg->yy_buffer_stack, num_to_alloc * sizeof(struct yy_buffer_state*) - ); - if ( ! (yy_buffer_stack) ) + , yyscanner); + if ( ! yyg->yy_buffer_stack ) YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); /* zero only the new slots.*/ - memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*)); - (yy_buffer_stack_max) = num_to_alloc; + memset(yyg->yy_buffer_stack + yyg->yy_buffer_stack_max, 0, grow_size * sizeof(struct yy_buffer_state*)); + yyg->yy_buffer_stack_max = num_to_alloc; } } /** Setup the input buffer state to scan directly from a user-specified character buffer. * @param base the character buffer * @param size the size in bytes of the character buffer - * + * @param yyscanner The scanner object. * @return the newly allocated buffer state object. */ -YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size ) +YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size , yyscan_t yyscanner) { YY_BUFFER_STATE b; @@ -1515,7 +1544,7 @@ YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size ) /* They forgot to leave room for the EOB's. */ return 0; - b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) ); + b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) ,yyscanner ); if ( ! b ) YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" ); @@ -1529,7 +1558,7 @@ YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size ) b->yy_fill_buffer = 0; b->yy_buffer_status = YY_BUFFER_NEW; - yy_switch_to_buffer(b ); + yy_switch_to_buffer(b ,yyscanner ); return b; } @@ -1537,25 +1566,25 @@ YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size ) /** Setup the input buffer state to scan a string. The next call to yylex() will * scan from a @e copy of @a str. * @param yystr a NUL-terminated string to scan - * + * @param yyscanner The scanner object. * @return the newly allocated buffer state object. * @note If you want to scan bytes that may contain NUL values, then use * yy_scan_bytes() instead. */ -YY_BUFFER_STATE yy_scan_string (yyconst char * yystr ) +YY_BUFFER_STATE yy_scan_string (yyconst char * yystr , yyscan_t yyscanner) { - return yy_scan_bytes(yystr,strlen(yystr) ); + return yy_scan_bytes(yystr,strlen(yystr) ,yyscanner); } /** Setup the input buffer state to scan the given bytes. The next call to yylex() will * scan from a @e copy of @a bytes. * @param yybytes the byte buffer to scan * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes. - * + * @param yyscanner The scanner object. * @return the newly allocated buffer state object. */ -YY_BUFFER_STATE yy_scan_bytes (yyconst char * yybytes, int _yybytes_len ) +YY_BUFFER_STATE yy_scan_bytes (yyconst char * yybytes, int _yybytes_len , yyscan_t yyscanner) { YY_BUFFER_STATE b; char *buf; @@ -1564,7 +1593,7 @@ YY_BUFFER_STATE yy_scan_bytes (yyconst char * yybytes, int _yybytes_len ) /* Get memory for full buffer, including space for trailing EOB's. */ n = _yybytes_len + 2; - buf = (char *) yyalloc(n ); + buf = (char *) yyalloc(n ,yyscanner ); if ( ! buf ) YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" ); @@ -1573,7 +1602,7 @@ YY_BUFFER_STATE yy_scan_bytes (yyconst char * yybytes, int _yybytes_len ) buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR; - b = yy_scan_buffer(buf,n ); + b = yy_scan_buffer(buf,n ,yyscanner); if ( ! b ) YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" ); @@ -1589,7 +1618,7 @@ YY_BUFFER_STATE yy_scan_bytes (yyconst char * yybytes, int _yybytes_len ) #define YY_EXIT_FAILURE 2 #endif -static void yy_fatal_error (yyconst char* msg ) +static void yy_fatal_error (yyconst char* msg , yyscan_t yyscanner) { (void) fprintf( stderr, "%s\n", msg ); exit( YY_EXIT_FAILURE ); @@ -1604,106 +1633,241 @@ static void yy_fatal_error (yyconst char* msg ) /* Undo effects of setting up yytext. */ \ int yyless_macro_arg = (n); \ YY_LESS_LINENO(yyless_macro_arg);\ - yytext[yyleng] = (yy_hold_char); \ - (yy_c_buf_p) = yytext + yyless_macro_arg; \ - (yy_hold_char) = *(yy_c_buf_p); \ - *(yy_c_buf_p) = '\0'; \ + yytext[yyleng] = yyg->yy_hold_char; \ + yyg->yy_c_buf_p = yytext + yyless_macro_arg; \ + yyg->yy_hold_char = *yyg->yy_c_buf_p; \ + *yyg->yy_c_buf_p = '\0'; \ yyleng = yyless_macro_arg; \ } \ while ( 0 ) /* Accessor methods (get/set functions) to struct members. */ -/** Get the current line number. - * +/** Get the user-defined data for this scanner. + * @param yyscanner The scanner object. */ -int yyget_lineno (void) +YY_EXTRA_TYPE yyget_extra (yyscan_t yyscanner) { - + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + return yyextra; +} + +/** Get the current line number. + * @param yyscanner The scanner object. + */ +int yyget_lineno (yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + + if (! YY_CURRENT_BUFFER) + return 0; + return yylineno; } -/** Get the input stream. - * +/** Get the current column number. + * @param yyscanner The scanner object. */ -FILE *yyget_in (void) +int yyget_column (yyscan_t yyscanner) { - return yyin; + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + + if (! YY_CURRENT_BUFFER) + return 0; + + return yycolumn; +} + +/** Get the input stream. + * @param yyscanner The scanner object. + */ +FILE *yyget_in (yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + return yyin; } /** Get the output stream. - * + * @param yyscanner The scanner object. */ -FILE *yyget_out (void) +FILE *yyget_out (yyscan_t yyscanner) { - return yyout; + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + return yyout; } /** Get the length of the current token. - * + * @param yyscanner The scanner object. */ -int yyget_leng (void) +int yyget_leng (yyscan_t yyscanner) { - return yyleng; + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + return yyleng; } /** Get the current token. - * + * @param yyscanner The scanner object. */ -char *yyget_text (void) +char *yyget_text (yyscan_t yyscanner) { - return yytext; + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + return yytext; +} + +/** Set the user-defined data. This data is never touched by the scanner. + * @param user_defined The data to be associated with this scanner. + * @param yyscanner The scanner object. + */ +void yyset_extra (YY_EXTRA_TYPE user_defined , yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + yyextra = user_defined ; } /** Set the current line number. * @param line_number - * + * @param yyscanner The scanner object. */ -void yyset_lineno (int line_number ) +void yyset_lineno (int line_number , yyscan_t yyscanner) { + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + + /* lineno is only valid if an input buffer exists. */ + if (! YY_CURRENT_BUFFER ) + yy_fatal_error( "yyset_lineno called with no buffer" , yyscanner); yylineno = line_number; } +/** Set the current column. + * @param line_number + * @param yyscanner The scanner object. + */ +void yyset_column (int column_no , yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + + /* column is only valid if an input buffer exists. */ + if (! YY_CURRENT_BUFFER ) + yy_fatal_error( "yyset_column called with no buffer" , yyscanner); + + yycolumn = column_no; +} + /** Set the input stream. This does not discard the current * input buffer. * @param in_str A readable stream. - * + * @param yyscanner The scanner object. * @see yy_switch_to_buffer */ -void yyset_in (FILE * in_str ) +void yyset_in (FILE * in_str , yyscan_t yyscanner) { - yyin = in_str ; + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + yyin = in_str ; } -void yyset_out (FILE * out_str ) +void yyset_out (FILE * out_str , yyscan_t yyscanner) { - yyout = out_str ; + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + yyout = out_str ; } -int yyget_debug (void) +int yyget_debug (yyscan_t yyscanner) { - return yy_flex_debug; + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + return yy_flex_debug; } -void yyset_debug (int bdebug ) +void yyset_debug (int bdebug , yyscan_t yyscanner) { - yy_flex_debug = bdebug ; + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + yy_flex_debug = bdebug ; } -static int yy_init_globals (void) +/* Accessor methods for yylval and yylloc */ + +/* User-visible API */ + +/* yylex_init is special because it creates the scanner itself, so it is + * the ONLY reentrant function that doesn't take the scanner as the last argument. + * That's why we explicitly handle the declaration, instead of using our macros. + */ + +int yylex_init(yyscan_t* ptr_yy_globals) + { - /* Initialization is the same as for the non-reentrant scanner. + if (ptr_yy_globals == NULL){ + errno = EINVAL; + return 1; + } + + *ptr_yy_globals = (yyscan_t) yyalloc ( sizeof( struct yyguts_t ), NULL ); + + if (*ptr_yy_globals == NULL){ + errno = ENOMEM; + return 1; + } + + /* By setting to 0xAA, we expose bugs in yy_init_globals. Leave at 0x00 for releases. */ + memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t)); + + return yy_init_globals ( *ptr_yy_globals ); +} + +/* yylex_init_extra has the same functionality as yylex_init, but follows the + * convention of taking the scanner as the last argument. Note however, that + * this is a *pointer* to a scanner, as it will be allocated by this call (and + * is the reason, too, why this function also must handle its own declaration). + * The user defined value in the first argument will be available to yyalloc in + * the yyextra field. + */ + +int yylex_init_extra(YY_EXTRA_TYPE yy_user_defined,yyscan_t* ptr_yy_globals ) + +{ + struct yyguts_t dummy_yyguts; + + yyset_extra (yy_user_defined, &dummy_yyguts); + + if (ptr_yy_globals == NULL){ + errno = EINVAL; + return 1; + } + + *ptr_yy_globals = (yyscan_t) yyalloc ( sizeof( struct yyguts_t ), &dummy_yyguts ); + + if (*ptr_yy_globals == NULL){ + errno = ENOMEM; + return 1; + } + + /* By setting to 0xAA, we expose bugs in + yy_init_globals. Leave at 0x00 for releases. */ + memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t)); + + yyset_extra (yy_user_defined, *ptr_yy_globals); + + return yy_init_globals ( *ptr_yy_globals ); +} + +static int yy_init_globals (yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + /* Initialization is the same as for the non-reentrant scanner. * This function is called from yylex_destroy(), so don't allocate here. */ - (yy_buffer_stack) = 0; - (yy_buffer_stack_top) = 0; - (yy_buffer_stack_max) = 0; - (yy_c_buf_p) = (char *) 0; - (yy_init) = 0; - (yy_start) = 0; + yyg->yy_buffer_stack = 0; + yyg->yy_buffer_stack_top = 0; + yyg->yy_buffer_stack_max = 0; + yyg->yy_c_buf_p = (char *) 0; + yyg->yy_init = 0; + yyg->yy_start = 0; + + yyg->yy_start_stack_ptr = 0; + yyg->yy_start_stack_depth = 0; + yyg->yy_start_stack = NULL; /* Defined in main.c */ #ifdef YY_STDINIT @@ -1721,24 +1885,32 @@ static int yy_init_globals (void) } /* yylex_destroy is for both reentrant and non-reentrant scanners. */ -int yylex_destroy (void) +int yylex_destroy (yyscan_t yyscanner) { - + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + /* Pop the buffer stack, destroying each element. */ while(YY_CURRENT_BUFFER){ - yy_delete_buffer(YY_CURRENT_BUFFER ); + yy_delete_buffer(YY_CURRENT_BUFFER ,yyscanner ); YY_CURRENT_BUFFER_LVALUE = NULL; - yypop_buffer_state(); + yypop_buffer_state(yyscanner); } /* Destroy the stack itself. */ - yyfree((yy_buffer_stack) ); - (yy_buffer_stack) = NULL; + yyfree(yyg->yy_buffer_stack ,yyscanner); + yyg->yy_buffer_stack = NULL; + + /* Destroy the start condition stack. */ + yyfree(yyg->yy_start_stack ,yyscanner ); + yyg->yy_start_stack = NULL; /* Reset the globals. This is important in a non-reentrant scanner so the next time * yylex() is called, initialization will occur. */ - yy_init_globals( ); + yy_init_globals( yyscanner); + /* Destroy the main struct (reentrant only). */ + yyfree ( yyscanner , yyscanner ); + yyscanner = NULL; return 0; } @@ -1747,7 +1919,7 @@ int yylex_destroy (void) */ #ifndef yytext_ptr -static void yy_flex_strncpy (char* s1, yyconst char * s2, int n ) +static void yy_flex_strncpy (char* s1, yyconst char * s2, int n , yyscan_t yyscanner) { register int i; for ( i = 0; i < n; ++i ) @@ -1756,7 +1928,7 @@ static void yy_flex_strncpy (char* s1, yyconst char * s2, int n ) #endif #ifdef YY_NEED_STRLEN -static int yy_flex_strlen (yyconst char * s ) +static int yy_flex_strlen (yyconst char * s , yyscan_t yyscanner) { register int n; for ( n = 0; s[n]; ++n ) @@ -1766,12 +1938,12 @@ static int yy_flex_strlen (yyconst char * s ) } #endif -void *yyalloc (yy_size_t size ) +void *yyalloc (yy_size_t size , yyscan_t yyscanner) { return (void *) malloc( size ); } -void *yyrealloc (void * ptr, yy_size_t size ) +void *yyrealloc (void * ptr, yy_size_t size , yyscan_t yyscanner) { /* The cast to (char *) in the following accommodates both * implementations that use char* generic pointers, and those @@ -1783,11 +1955,11 @@ void *yyrealloc (void * ptr, yy_size_t size ) return (void *) realloc( (char *) ptr, size ); } -void yyfree (void * ptr ) +void yyfree (void * ptr , yyscan_t yyscanner) { free( (char *) ptr ); /* see yyrealloc() for (char *) cast */ } #define YYTABLES_NAME "yytables" -#line 55 "shell_lex.l" +#line 53 "shell_lex.l" diff --git a/shell_lex.l b/shell_lex.l index 240b1ef..65f8987 100644 --- a/shell_lex.l +++ b/shell_lex.l @@ -17,12 +17,10 @@ */ %{ -#include "shell.h" +#include "shell_internal.h" #include #include -#define YY_INPUT(buf, result, max_size) result = shell_pull(buf, max_size); - static char *str_append(char *str, const char *src) { if(str) { size_t newlen = strlen(str) + strlen(src) + 1; @@ -39,16 +37,16 @@ static char *str_append(char *str, const char *src) { return strdup(src); } %} -%option noyywrap nounput noinput batch +%option noyywrap nounput noinput batch reentrant %x STR %% -["] { strval = NULL; BEGIN(STR); } +["] { yyextra->strval = NULL; BEGIN(STR); } ; return TOK_SEPARATOR; [[:space:]]+ return TOK_SPACE; [#] return TOK_COMMENT; -[^[:space:];"#]+ { strval = strdup(yytext); return TOK_STRING; } -[^\\"]+ strval = str_append(strval, yytext); -\\["] strval = str_append(strval, "\""); -\\ strval = str_append(strval, "\\"); +[^[:space:];"#]+ { yyextra->strval = strdup(yytext); return TOK_STRING; } +[^\\"]+ yyextra->strval = str_append(yyextra->strval, yytext); +\\["] yyextra->strval = str_append(yyextra->strval, "\""); +\\ yyextra->strval = str_append(yyextra->strval, "\\"); ["] { BEGIN(INITIAL); return TOK_STRING; } diff --git a/spl_cmdset.c b/spl_cmdset.c index 86503e5..f226efa 100644 --- a/spl_cmdset.c +++ b/spl_cmdset.c @@ -26,9 +26,9 @@ #include "config.h" #include "ingenic.h" -static int spl_memtest(int argc, char *argv[]); -static int spl_gpio(int argc, char *argv[]); -static int spl_boot(int argc, char *argv[]); +static int spl_memtest(shell_context_t *ctx, int argc, char *argv[]); +static int spl_gpio(shell_context_t *ctx, int argc, char *argv[]); +static int spl_boot(shell_context_t *ctx, int argc, char *argv[]); const shell_command_t spl_cmdset[] = { { "memtest", "[BASE ] - SDRAM test", spl_memtest }, @@ -37,14 +37,14 @@ const shell_command_t spl_cmdset[] = { { NULL, NULL, NULL } }; -static int spl_stage1_op(uint32_t op, uint32_t pin, uint32_t base, uint32_t size) { +static int spl_stage1_op(shell_context_t *ctx, uint32_t op, uint32_t pin, uint32_t base, uint32_t size) { if(cfg_getenv("STAGE1_FILE") == NULL) { printf("Variable STAGE1_FILE is not set\n"); return -1; } - int ret = ingenic_stage1_debugop(shell_device(), cfg_getenv("STAGE1_FILE"), op, pin, base, size); + int ret = ingenic_stage1_debugop(shell_device(ctx), cfg_getenv("STAGE1_FILE"), op, pin, base, size); if(ret == -1) perror("ingenic_stage1_debugop"); @@ -52,7 +52,7 @@ static int spl_stage1_op(uint32_t op, uint32_t pin, uint32_t base, uint32_t size return ret; } -static int spl_memtest(int argc, char *argv[]) { +static int spl_memtest(shell_context_t *ctx, int argc, char *argv[]) { if(argc != 1 && argc != 3) { printf("Usage: %s [BASE ]\n", argv[0]); @@ -66,7 +66,7 @@ static int spl_memtest(int argc, char *argv[]) { size = strtoul(argv[2], NULL, 0); } else { start = SDRAM_BASE; - size = ingenic_sdram_size(shell_device()); + size = ingenic_sdram_size(shell_device(ctx)); } if(cfg_getenv("STAGE1_FILE") == NULL) { @@ -77,7 +77,7 @@ static int spl_memtest(int argc, char *argv[]) { uint32_t fail; - int ret = ingenic_memtest(shell_device(), cfg_getenv("STAGE1_FILE"), start, size, &fail); + int ret = ingenic_memtest(shell_device(ctx), cfg_getenv("STAGE1_FILE"), start, size, &fail); if(ret == -1) { if(errno == EFAULT) { @@ -93,7 +93,7 @@ static int spl_memtest(int argc, char *argv[]) { return ret; } -static int spl_gpio(int argc, char *argv[]) { +static int spl_gpio(shell_context_t *ctx, int argc, char *argv[]) { if(argc != 3 || (strcmp(argv[2], "0") && strcmp(argv[2], "1"))) { printf("Usage: %s \n", argv[0]); printf(" STATE := 0 | 1\n"); @@ -101,15 +101,15 @@ static int spl_gpio(int argc, char *argv[]) { return -1; } - return spl_stage1_op(!strcmp(argv[2], "1") ? STAGE1_DEBUG_GPIO_SET : STAGE1_DEBUG_GPIO_CLEAR, atoi(argv[1]), 0, 0); + return spl_stage1_op(ctx, !strcmp(argv[2], "1") ? STAGE1_DEBUG_GPIO_SET : STAGE1_DEBUG_GPIO_CLEAR, atoi(argv[1]), 0, 0); } -static int spl_boot(int argc, char *argv[]) { +static int spl_boot(shell_context_t *ctx, int argc, char *argv[]) { if(argc != 1) { printf("Usage: %s\n", argv[0]); } - int ret = spl_stage1_op(STAGE1_DEBUG_BOOT, 0, 0, 0); + int ret = spl_stage1_op(ctx, STAGE1_DEBUG_BOOT, 0, 0, 0); if(ret == -1) return -1; @@ -120,7 +120,7 @@ static int spl_boot(int argc, char *argv[]) { return -1; } - ret = ingenic_loadstage(shell_device(), INGENIC_STAGE2, cfg_getenv("STAGE2_FILE")); + ret = ingenic_loadstage(shell_device(ctx), INGENIC_STAGE2, cfg_getenv("STAGE2_FILE")); if(ret == -1) { perror("ingenic_loadstage"); @@ -128,7 +128,7 @@ static int spl_boot(int argc, char *argv[]) { return -1; } - ret = ingenic_configure_stage2(shell_device()); + ret = ingenic_configure_stage2(shell_device(ctx)); if(ret == -1) perror("ingenic_configure_stage2"); diff --git a/usbboot_cmdset.c b/usbboot_cmdset.c index e177246..dd723bb 100644 --- a/usbboot_cmdset.c +++ b/usbboot_cmdset.c @@ -25,14 +25,14 @@ #include "ingenic.h" #include "config.h" -static int usbboot_boot(int argc, char *argv[]); -static int usbboot_load(int argc, char *argv[]); -static int usbboot_go(int argc, char *argv[]); -static int usbboot_nquery(int argc, char *argv[]); -static int usbboot_ndump(int argc, char *argv[]); -static int usbboot_nerase(int argc, char *argv[]); -static int usbboot_nprogram(int argc, char *argv[]); -static int usbboot_nload(int argc, char *argv[]); +static int usbboot_boot(shell_context_t *ctx, int argc, char *argv[]); +static int usbboot_load(shell_context_t *ctx, int argc, char *argv[]); +static int usbboot_go(shell_context_t *ctx, int argc, char *argv[]); +static int usbboot_nquery(shell_context_t *ctx, int argc, char *argv[]); +static int usbboot_ndump(shell_context_t *ctx, int argc, char *argv[]); +static int usbboot_nerase(shell_context_t *ctx, int argc, char *argv[]); +static int usbboot_nprogram(shell_context_t *ctx, int argc, char *argv[]); +static int usbboot_nload(shell_context_t *ctx, int argc, char *argv[]); const shell_command_t usbboot_cmdset[] = { @@ -51,8 +51,8 @@ const shell_command_t usbboot_cmdset[] = { { NULL, NULL, NULL } }; -static int usbboot_boot(int argc, char *argv[]) { - int ret = ingenic_configure_stage2(shell_device()); +static int usbboot_boot(shell_context_t *ctx, int argc, char *argv[]) { + int ret = ingenic_configure_stage2(shell_device(ctx)); if(ret == -1) perror("ingenic_configure_stage2"); @@ -60,14 +60,14 @@ static int usbboot_boot(int argc, char *argv[]) { return ret; } -static int usbboot_load(int argc, char *argv[]) { +static int usbboot_load(shell_context_t *ctx, int argc, char *argv[]) { if(argc != 3) { printf("Usage: %s \n", argv[0]); return -1; } - int ret = ingenic_load_sdram_file(shell_device(), strtoul(argv[2], NULL, 0), argv[1]); + int ret = ingenic_load_sdram_file(shell_device(ctx), strtoul(argv[2], NULL, 0), argv[1]); if(ret == -1) perror("ingenic_load_sdram_file"); @@ -75,14 +75,14 @@ static int usbboot_load(int argc, char *argv[]) { return ret; } -static int usbboot_go(int argc, char *argv[]) { +static int usbboot_go(shell_context_t *ctx, int argc, char *argv[]) { if(argc != 2) { printf("Usage: %s
\n", argv[0]); return -1; } - int ret = ingenic_go(shell_device(), strtoul(argv[1], NULL, 0)); + int ret = ingenic_go(shell_device(ctx), strtoul(argv[1], NULL, 0)); if(ret == -1) perror("ingenic_go"); @@ -90,7 +90,7 @@ static int usbboot_go(int argc, char *argv[]) { return ret; } -static int usbboot_nquery(int argc, char *argv[]) { +static int usbboot_nquery(shell_context_t *ctx, int argc, char *argv[]) { if(argc != 2) { printf("Usage: %s \n", argv[0]); @@ -99,7 +99,7 @@ static int usbboot_nquery(int argc, char *argv[]) { nand_info_t info; - int ret = ingenic_query_nand(shell_device(), atoi(argv[1]), &info); + int ret = ingenic_query_nand(shell_device(ctx), atoi(argv[1]), &info); if(ret == -1) { perror("ingenic_query_nand"); @@ -119,7 +119,7 @@ static int usbboot_nquery(int argc, char *argv[]) { return 0; } -static int usbboot_ndump(int argc, char *argv[]) { +static int usbboot_ndump(shell_context_t *ctx, int argc, char *argv[]) { if(argc != 5) { printf("Usage: %s \n", argv[0]); @@ -131,7 +131,7 @@ static int usbboot_ndump(int argc, char *argv[]) { if(cfg_getenv("NAND_RAW")) type |= NAND_RAW; - int ret = ingenic_dump_nand(shell_device(), atoi(argv[1]), atoi(argv[2]), atoi(argv[3]), type, argv[4]); + int ret = ingenic_dump_nand(shell_device(ctx), atoi(argv[1]), atoi(argv[2]), atoi(argv[3]), type, argv[4]); if(ret == -1) perror("ingenic_dump_nand"); @@ -139,14 +139,14 @@ static int usbboot_ndump(int argc, char *argv[]) { return ret; } -static int usbboot_nerase(int argc, char *argv[]) { +static int usbboot_nerase(shell_context_t *ctx, int argc, char *argv[]) { if(argc != 4) { printf("Usage: %s \n", argv[0]); return -1; } - int ret = ingenic_erase_nand(shell_device(), atoi(argv[1]), atoi(argv[2]), atoi(argv[3])); + int ret = ingenic_erase_nand(shell_device(ctx), atoi(argv[1]), atoi(argv[2]), atoi(argv[3])); if(ret == -1) perror("ingenic_erase_nand"); @@ -155,7 +155,7 @@ static int usbboot_nerase(int argc, char *argv[]) { } -static int usbboot_nprogram(int argc, char *argv[]) { +static int usbboot_nprogram(shell_context_t *ctx, int argc, char *argv[]) { if(argc != 4) { printf("Usage: %s \n", argv[0]); @@ -172,7 +172,7 @@ static int usbboot_nprogram(int argc, char *argv[]) { } else type = NO_OOB; - int ret = ingenic_program_nand(shell_device(), atoi(argv[1]), atoi(argv[2]), type, argv[3]); + int ret = ingenic_program_nand(shell_device(ctx), atoi(argv[1]), atoi(argv[2]), type, argv[3]); if(ret == -1) perror("ingenic_program_nand"); @@ -180,14 +180,14 @@ static int usbboot_nprogram(int argc, char *argv[]) { return ret; } -static int usbboot_nload(int argc, char *argv[]) { +static int usbboot_nload(shell_context_t *ctx, int argc, char *argv[]) { if(argc != 5) { printf("Usage: %s \n", argv[0]); return -1; } - int ret = ingenic_load_nand(shell_device(), atoi(argv[1]), atoi(argv[2]), atoi(argv[3]), strtoul(argv[4], NULL, 0)); + int ret = ingenic_load_nand(shell_device(ctx), atoi(argv[1]), atoi(argv[2]), atoi(argv[3]), strtoul(argv[4], NULL, 0)); if(ret == -1) perror("ingenic_load_nand");