apps/interpreters/minibasic: Add a port of Mini Basic, version 1.0, written by Malcom McLean and released under the Creative Commons Attirbution license.
This commit is contained in:
parent
93f7809258
commit
a1c0580034
11
COPYING
11
COPYING
@ -80,6 +80,17 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|||||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||||
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
Mini Basic
|
||||||
|
^^^^^^^^^^
|
||||||
|
|
||||||
|
The Mini Basic implementation at apps/interpreters derives from version 1.0
|
||||||
|
by Malcolm McLean, Leeds University, and was released under the Creative
|
||||||
|
Commons Attibution license. I am not legal expert, but this license
|
||||||
|
appears to be compatible with the NuttX BSD license see:
|
||||||
|
https://creativecommons.org/licenses/ . I, however, cannot take
|
||||||
|
responsibility for any actions that you might take based on my
|
||||||
|
understanding. Please use your own legal judgement.
|
||||||
|
|
||||||
THTTPD
|
THTTPD
|
||||||
^^^^^^
|
^^^^^^
|
||||||
|
|
||||||
|
72
include/interpreters/minibasic.h
Normal file
72
include/interpreters/minibasic.h
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* apps/interpreters/minibasic/basic.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 2016 Gregory Nutt. All rights reserved.
|
||||||
|
*
|
||||||
|
* This file was taken from Mini Basic, versino 1.0 developed by Malcolm
|
||||||
|
* McLean, Leeds University. Mini Basic version 1.0 was released the the
|
||||||
|
* Creative Commons Attribution license which, from my reading, appears to
|
||||||
|
* be compatible with the NuttX BSD-style license:
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in
|
||||||
|
* the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||||
|
* used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||||
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||||
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef __APPS_INCLUDE_INTERPRETERS_MINIBASIC_H
|
||||||
|
#define __APPS_INCLUDE_INTERPRETERS_MINIBASIC_H
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Included Files
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Function Prototypes
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: basic
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Interpret a BASIC script
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* script - the script to run
|
||||||
|
* in - input stream
|
||||||
|
* out - output stream
|
||||||
|
* err - error stream
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* Returns: 0 on success, 1 on error condition.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int basic(FAR const char *script, FILE *in, FILE *out, FILE *err);
|
||||||
|
|
||||||
|
#endif
|
52
interpreters/minibasic/Kconfig
Normal file
52
interpreters/minibasic/Kconfig
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
#
|
||||||
|
# For a description of the syntax of this configuration file,
|
||||||
|
# see the file kconfig-language.txt in the NuttX tools repository.
|
||||||
|
#
|
||||||
|
|
||||||
|
config INTERPRETERS_MINIBASIC
|
||||||
|
bool "Mini Basic Interpreter support"
|
||||||
|
default n
|
||||||
|
select LIBC_FLOATINGPOINT
|
||||||
|
---help---
|
||||||
|
This is a Basic interpreter written by Malcolm McLean
|
||||||
|
|
||||||
|
NOTE: This interpreter requires a usable math.h header file. By
|
||||||
|
default, the math library (and hence, math.h) are not provided by
|
||||||
|
NuttX. Therefore, when the Basic code includes math.h it will
|
||||||
|
either fail to find the math.h header file or, worse, will take an
|
||||||
|
incompatible version of math.h from your toolchain. The toolchain's
|
||||||
|
version of math.h will be incompatible because it will have been
|
||||||
|
implemented to work with a different version of the C library.
|
||||||
|
|
||||||
|
Normally, developers will use an optimized math library for their
|
||||||
|
processor architecture and do the following:
|
||||||
|
|
||||||
|
- Save a customized copy of math.h from your tool chain in
|
||||||
|
nuttx/arch/<arch>/include
|
||||||
|
- Set CONFIG_ARCH_MATH_H=y in your .config file to select this
|
||||||
|
architecture-specific math.h header file.
|
||||||
|
|
||||||
|
An option is to use the built-in, generic, unoptimized NuttX math
|
||||||
|
library that is selected by simply by:
|
||||||
|
|
||||||
|
- Set CONFIG_LIBM=y in your .config file
|
||||||
|
|
||||||
|
if INTERPRETERS_MINIBASIC
|
||||||
|
|
||||||
|
config INTERPRETER_MINIBASIC_VERSION
|
||||||
|
string "Version number"
|
||||||
|
default "1.0"
|
||||||
|
|
||||||
|
config INTERPRETER_MINIBASIC_PRIORITY
|
||||||
|
int "Basic interpreter priority"
|
||||||
|
default 100
|
||||||
|
---help---
|
||||||
|
Task priority of the Basic interpreter main task
|
||||||
|
|
||||||
|
config INTERPRETER_MINIBASIC_STACKSIZE
|
||||||
|
int "Basic interpreter stack size"
|
||||||
|
default 4096
|
||||||
|
---help---
|
||||||
|
Size of the stack allocated for the Basic interpreter main task
|
||||||
|
|
||||||
|
endif
|
38
interpreters/minibasic/Make.defs
Normal file
38
interpreters/minibasic/Make.defs
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
############################################################################
|
||||||
|
# interpreters/minibasic/Make.defs
|
||||||
|
#
|
||||||
|
# Copyright (C) 2016 Gregory Nutt. All rights reserved.
|
||||||
|
# Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
|
#
|
||||||
|
# Redistribution and use in source and binary forms, with or without
|
||||||
|
# modification, are permitted provided that the following conditions
|
||||||
|
# are met:
|
||||||
|
#
|
||||||
|
# 1. Redistributions of source code must retain the above copyright
|
||||||
|
# notice, this list of conditions and the following disclaimer.
|
||||||
|
# 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
# notice, this list of conditions and the following disclaimer in
|
||||||
|
# the documentation and/or other materials provided with the
|
||||||
|
# distribution.
|
||||||
|
# 3. Neither the name NuttX nor the names of its contributors may be
|
||||||
|
# used to endorse or promote products derived from this software
|
||||||
|
# without specific prior written permission.
|
||||||
|
#
|
||||||
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||||
|
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||||
|
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
# POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
#
|
||||||
|
############################################################################
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_INTERPRETERS_MINIBASIC),y)
|
||||||
|
CONFIGURED_APPS += interpreters/minibasic
|
||||||
|
endif
|
116
interpreters/minibasic/Makefile
Normal file
116
interpreters/minibasic/Makefile
Normal file
@ -0,0 +1,116 @@
|
|||||||
|
############################################################################
|
||||||
|
# interpreters/minibasic/Makefile
|
||||||
|
#
|
||||||
|
# Copyright (C) 2016 Gregory Nutt. All rights reserved.
|
||||||
|
# Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
|
#
|
||||||
|
# Redistribution and use in source and binary forms, with or without
|
||||||
|
# modification, are permitted provided that the following conditions
|
||||||
|
# are met:
|
||||||
|
#
|
||||||
|
# 1. Redistributions of source code must retain the above copyright
|
||||||
|
# notice, this list of conditions and the following disclaimer.
|
||||||
|
# 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
# notice, this list of conditions and the following disclaimer in
|
||||||
|
# the documentation and/or other materials provided with the
|
||||||
|
# distribution.
|
||||||
|
# 3. Neither the name NuttX nor the names of its contributors may be
|
||||||
|
# used to endorse or promote products derived from this software
|
||||||
|
# without specific prior written permission.
|
||||||
|
#
|
||||||
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||||
|
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||||
|
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
# POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
#
|
||||||
|
############################################################################
|
||||||
|
|
||||||
|
-include $(TOPDIR)/.config
|
||||||
|
-include $(TOPDIR)/Make.defs
|
||||||
|
include $(APPDIR)/Make.defs
|
||||||
|
|
||||||
|
# Mini Basic Library
|
||||||
|
|
||||||
|
ASRCS =
|
||||||
|
CSRCS = basic.c script.c
|
||||||
|
|
||||||
|
DEPPATH = --dep-path .
|
||||||
|
VPATH = .
|
||||||
|
|
||||||
|
AOBJS = $(ASRCS:.S=$(OBJEXT))
|
||||||
|
COBJS = $(CSRCS:.c=$(OBJEXT))
|
||||||
|
|
||||||
|
SRCS = $(ASRCS) $(CSRCS)
|
||||||
|
OBJS = $(AOBJS) $(COBJS)
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_WINDOWS_NATIVE),y)
|
||||||
|
BIN = ..\..\libapps$(LIBEXT)
|
||||||
|
else
|
||||||
|
ifeq ($(WINTOOL),y)
|
||||||
|
BIN = ..\\..\\libapps$(LIBEXT)
|
||||||
|
else
|
||||||
|
BIN = ../../libapps$(LIBEXT)
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
# Mini Basic built-in application info
|
||||||
|
|
||||||
|
CONFIG_INTERPRETER_MINIBASIC_PRIORITY ?= 100
|
||||||
|
CONFIG_INTERPRETER_MINIBASIC_STACKSIZE ?= 4096
|
||||||
|
|
||||||
|
APPNAME = basic
|
||||||
|
PRIORITY = $(CONFIG_INTERPRETER_MINIBASIC_PRIORITY)
|
||||||
|
STACKSIZE = $(CONFIG_INTERPRETER_MINIBASIC_STACKSIZE)
|
||||||
|
|
||||||
|
# Build targets
|
||||||
|
|
||||||
|
all: .built
|
||||||
|
.PHONY: context .depend depend clean distclean
|
||||||
|
|
||||||
|
$(AOBJS): %$(OBJEXT): %.S
|
||||||
|
$(call ASSEMBLE, $<, $@)
|
||||||
|
|
||||||
|
$(COBJS): %$(OBJEXT): %.c
|
||||||
|
$(call COMPILE, $<, $@)
|
||||||
|
|
||||||
|
.built: $(OBJS)
|
||||||
|
$(call ARCHIVE, $(BIN), $(OBJS))
|
||||||
|
$(Q) touch .built
|
||||||
|
|
||||||
|
install:
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
|
||||||
|
$(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat: $(DEPCONFIG) Makefile
|
||||||
|
$(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main)
|
||||||
|
|
||||||
|
context: $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat
|
||||||
|
else
|
||||||
|
context:
|
||||||
|
endif
|
||||||
|
|
||||||
|
.depend: Makefile $(SRCS)
|
||||||
|
$(Q) $(MKDEP) $(DEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
|
||||||
|
$(Q) touch $@
|
||||||
|
|
||||||
|
depend: .depend
|
||||||
|
|
||||||
|
clean:
|
||||||
|
$(call DELFILE, .built)
|
||||||
|
$(call CLEAN)
|
||||||
|
|
||||||
|
distclean: clean
|
||||||
|
$(call DELFILE, Make.dep)
|
||||||
|
$(call DELFILE, .depend)
|
||||||
|
|
||||||
|
-include Make.dep
|
||||||
|
.PHONY: preconfig
|
||||||
|
|
||||||
|
preconfig:
|
4074
interpreters/minibasic/basic.c
Normal file
4074
interpreters/minibasic/basic.c
Normal file
File diff suppressed because it is too large
Load Diff
176
interpreters/minibasic/script.c
Normal file
176
interpreters/minibasic/script.c
Normal file
@ -0,0 +1,176 @@
|
|||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* apps/interpreters/minibasic/sript.c
|
||||||
|
* Driver file for MiniBasic.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2016 Gregory Nutt. All rights reserved.
|
||||||
|
*
|
||||||
|
* This file was taken from Mini Basic, versino 1.0 developed by Malcolm
|
||||||
|
* McLean, Leeds University. Mini Basic version 1.0 was released the the
|
||||||
|
* Creative Commons Attribution license which, from my reading, appears to
|
||||||
|
* be compatible with the NuttX BSD-style license:
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in
|
||||||
|
* the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||||
|
* used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||||
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||||
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Included Files
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <nuttx/config.h>
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "interpreters/minibasic.h"
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Data
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/* Here is a simple script to play with */
|
||||||
|
|
||||||
|
static FAR char *script =
|
||||||
|
"10 REM Test Script\n"
|
||||||
|
"20 REM Tests the Interpreter\n"
|
||||||
|
"30 REM By Malcolm Mclean\n"
|
||||||
|
"35 PRINT \"HERE\" \n"
|
||||||
|
"40 PRINT INSTR(\"FRED\", \"ED\", 4)\n"
|
||||||
|
"50 PRINT VALLEN(\"12a\"), VALLEN(\"xyz\")\n"
|
||||||
|
"60 LET x = SQRT(3.0) * SQRT(3.0)\n"
|
||||||
|
"65 LET x = INT(x + 0.5)\n" "70 PRINT MID$(\"1234567890\", x, -1)\n";
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: leftstring
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Function to slurp in an ASCII file
|
||||||
|
* Params: path - path to file
|
||||||
|
* Returns: malloced string containing whole file
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static FAR char *loadfile(FAR char *path)
|
||||||
|
{
|
||||||
|
FILE *fp;
|
||||||
|
int ch;
|
||||||
|
long i = 0;
|
||||||
|
long size = 0;
|
||||||
|
FAR char *answer;
|
||||||
|
|
||||||
|
fp = fopen(path, "r");
|
||||||
|
if (!fp)
|
||||||
|
{
|
||||||
|
printf("Can't open %s\n", path);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
fseek(fp, 0, SEEK_END);
|
||||||
|
size = ftell(fp);
|
||||||
|
fseek(fp, 0, SEEK_SET);
|
||||||
|
|
||||||
|
answer = malloc(size + 100);
|
||||||
|
if (!answer)
|
||||||
|
{
|
||||||
|
printf("Out of memory\n");
|
||||||
|
fclose(fp);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
while ((ch = fgetc(fp)) != EOF)
|
||||||
|
{
|
||||||
|
answer[i++] = ch;
|
||||||
|
}
|
||||||
|
|
||||||
|
answer[i++] = 0;
|
||||||
|
|
||||||
|
fclose(fp);
|
||||||
|
return answer;
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: leftstring
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
*
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static void usage(void)
|
||||||
|
{
|
||||||
|
printf("MiniBasic: a BASIC interpreter\n");
|
||||||
|
printf("usage:\n");
|
||||||
|
printf("Basic <script>\n");
|
||||||
|
printf("See documentation for BASIC syntax.\n");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: main/basic_main
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Call with the name of the Minibasic script file
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifdef CONFIG_BUILD_KERNEL
|
||||||
|
int main(int argc, FAR char *argv[])
|
||||||
|
#else
|
||||||
|
int basic_main(int argc, char *argv[])
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
FAR char *scr;
|
||||||
|
|
||||||
|
if (argc == 1)
|
||||||
|
{
|
||||||
|
/* Comment out usage call to run test script */
|
||||||
|
|
||||||
|
usage();
|
||||||
|
basic(script, stdin, stdout, stderr);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
scr = loadfile(argv[1]);
|
||||||
|
if (scr)
|
||||||
|
{
|
||||||
|
basic(scr, stdin, stdout, stderr);
|
||||||
|
free(scr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user