apps/interpreters/minibasic: Move 1K I/O buffer off the stack and into a static.

This commit is contained in:
Gregory Nutt 2016-08-11 11:50:25 -06:00
parent fb3fa286d5
commit 1c613745ed
2 changed files with 28 additions and 13 deletions

View File

@ -45,4 +45,10 @@ config INTERPRETER_MINIBASIC_STACKSIZE
---help--- ---help---
Size of the stack allocated for the Basic interpreter main task Size of the stack allocated for the Basic interpreter main task
config INTERPRETER_MINIBASIC_IOBUFSIZE
int "I/O buffer size"
default 1024
---help---
Size of the statically allocated I/O buffer.
endif endif

View File

@ -53,6 +53,13 @@
/**************************************************************************** /****************************************************************************
* Pre-processor Definitions * Pre-processor Definitions
****************************************************************************/ ****************************************************************************/
/* Configuration */
#ifndef CONFIG_INTERPRETER_MINIBASIC_IOBUFSIZE
# define CONFIG_INTERPRETER_MINIBASIC_IOBUFSIZE 1024
#endif
#define IOBUFSIZE CONFIG_INTERPRETER_MINIBASIC_IOBUFSIZE
/* Tokens defined */ /* Tokens defined */
@ -224,6 +231,7 @@ static FILE *g_fperr; /* Error stream */
static FAR const char *g_string; /* String we are parsing */ static FAR const char *g_string; /* String we are parsing */
static int g_token; /* Current token (lookahead) */ static int g_token; /* Current token (lookahead) */
static int g_errorflag; /* Set when error in input encountered */ static int g_errorflag; /* Set when error in input encountered */
static char g_iobuffer[IOBUFSIZE]; /* I/O buffer */
/**************************************************************************** /****************************************************************************
* Private Function Prototypes * Private Function Prototypes
@ -1142,7 +1150,6 @@ static int donext(void)
static void doinput(void) static void doinput(void)
{ {
struct mb_lvalue_s lv; struct mb_lvalue_s lv;
char buff[1024];
FAR char *end; FAR char *end;
match(INPUT); match(INPUT);
@ -1151,6 +1158,7 @@ static void doinput(void)
switch (lv.type) switch (lv.type)
{ {
case FLTID: case FLTID:
{
while (fscanf(g_fpin, "%lf", lv.dval) != 1) while (fscanf(g_fpin, "%lf", lv.dval) != 1)
{ {
fgetc(g_fpin); fgetc(g_fpin);
@ -1160,6 +1168,7 @@ static void doinput(void)
return; return;
} }
} }
}
break; break;
case STRID: case STRID:
@ -1170,13 +1179,13 @@ static void doinput(void)
*lv.sval = 0; *lv.sval = 0;
} }
if (fgets(buff, sizeof(buff), g_fpin) == 0) if (fgets(g_iobuffer, IOBUFSIZE, g_fpin) == 0)
{ {
seterror(ERR_EOF); seterror(ERR_EOF);
return; return;
} }
end = strchr(buff, '\n'); end = strchr(g_iobuffer, '\n');
if (!end) if (!end)
{ {
seterror(ERR_INPUTTOOLONG); seterror(ERR_INPUTTOOLONG);
@ -1184,7 +1193,7 @@ static void doinput(void)
} }
*end = 0; *end = 0;
*lv.sval = mystrdup(buff); *lv.sval = mystrdup(g_iobuffer);
if (!*lv.sval) if (!*lv.sval)
{ {
seterror(ERR_OUTOFMEMORY); seterror(ERR_OUTOFMEMORY);