mirror of
https://github.com/adamdunkels/ubasic.git
synced 2026-11-21 03:59:44 +00:00
Enable uBasic to run from the command line
Replace use-basic with run-basic
This commit is contained in:
parent
cc07193c23
commit
1607012cdd
6 changed files with 113 additions and 19 deletions
2
.gitattributes
vendored
Normal file
2
.gitattributes
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
# Auto detect text files and perform LF normalization
|
||||
* text=auto
|
||||
52
.gitignore
vendored
Normal file
52
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
# Prerequisites
|
||||
*.d
|
||||
|
||||
# Object files
|
||||
*.o
|
||||
*.ko
|
||||
*.obj
|
||||
*.elf
|
||||
|
||||
# Linker output
|
||||
*.ilk
|
||||
*.map
|
||||
*.exp
|
||||
|
||||
# Precompiled Headers
|
||||
*.gch
|
||||
*.pch
|
||||
|
||||
# Libraries
|
||||
*.lib
|
||||
*.a
|
||||
*.la
|
||||
*.lo
|
||||
|
||||
# Shared objects (inc. Windows DLLs)
|
||||
*.dll
|
||||
*.so
|
||||
*.so.*
|
||||
*.dylib
|
||||
|
||||
# Executables
|
||||
*.exe
|
||||
*.out
|
||||
*.app
|
||||
*.i*86
|
||||
*.x86_64
|
||||
*.hex
|
||||
|
||||
# Debug files
|
||||
*.dSYM/
|
||||
*.su
|
||||
*.idb
|
||||
*.pdb
|
||||
|
||||
# Kernel Module Compile Results
|
||||
*.mod*
|
||||
*.cmd
|
||||
.tmp_versions/
|
||||
modules.order
|
||||
Module.symvers
|
||||
Mkfile.old
|
||||
dkms.conf
|
||||
1
makefile.bat
Normal file
1
makefile.bat
Normal file
|
|
@ -0,0 +1 @@
|
|||
cl run-ubasic.c ubasic.c tokenizer.c
|
||||
|
|
@ -27,29 +27,54 @@
|
|||
* SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Modified to support simple string variables and functions by David Mitchell
|
||||
* November 2008.
|
||||
* Changes and additions are marked 'string additions' throughout
|
||||
*/
|
||||
|
||||
#include "ubasic.h"
|
||||
|
||||
static const char program[] =
|
||||
"10 gosub 100\n\
|
||||
20 for i = 1 to 10\n\
|
||||
30 print i\n\
|
||||
40 next i\n\
|
||||
50 print \"end\"\n\
|
||||
60 end\n\
|
||||
100 print \"subroutine\"\n\
|
||||
110 return\n";
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
ubasic_init(program);
|
||||
// main routine modified to allow execution of BASIC script files
|
||||
|
||||
int
|
||||
main(int argc, char **argv, char **envp)
|
||||
{
|
||||
char *q;
|
||||
char **p;
|
||||
char *prog;
|
||||
char buffer[15000];
|
||||
int infile;
|
||||
|
||||
if (argc > 1) {
|
||||
p = argv + 1;
|
||||
q = *p;
|
||||
while(*q == ' ') ++q;
|
||||
|
||||
if ((infile = open(q,0)) == -1) {
|
||||
printf("File \"%s\" not found in current directory - terminating\n",q);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if (read(infile,buffer,15000) == -1) {
|
||||
printf("Error reading file \"%s\" - terminating\n",q);
|
||||
printf("Error was \"%d\" \n",errno);
|
||||
return (-1);
|
||||
}
|
||||
prog = buffer;
|
||||
} else {
|
||||
printf("Usage: ubasic fname\n where fname is a file containing basic statements\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
ubasic_init(prog);
|
||||
do {
|
||||
ubasic_run();
|
||||
} while(!ubasic_finished());
|
||||
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
}
|
||||
9
test.bas
Normal file
9
test.bas
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
1 print "start of test"
|
||||
10 gosub 100
|
||||
20 for i = 1 to 10
|
||||
30 print i
|
||||
40 next i
|
||||
50 print "end"
|
||||
60 end
|
||||
100 print "subroutine"
|
||||
110 return
|
||||
11
tokenizer.c
11
tokenizer.c
|
|
@ -43,6 +43,8 @@
|
|||
|
||||
static char const *ptr, *nextptr;
|
||||
|
||||
static char const *prog;
|
||||
|
||||
#define MAX_NUMLEN 6
|
||||
|
||||
struct keyword_token {
|
||||
|
|
@ -119,6 +121,9 @@ get_next_token(void)
|
|||
int i;
|
||||
|
||||
DEBUG_PRINTF("get_next_token(): '%s'\n", ptr);
|
||||
|
||||
// eat all whitespace
|
||||
while(*ptr == ' ' || *ptr == '\t' || *ptr == '\r') ptr++;
|
||||
|
||||
if(*ptr == 0) {
|
||||
return TOKENIZER_ENDOFINPUT;
|
||||
|
|
@ -170,8 +175,7 @@ get_next_token(void)
|
|||
return TOKENIZER_ERROR;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
tokenizer_goto(const char *program)
|
||||
void tokenizer_goto(const char *program)
|
||||
{
|
||||
ptr = program;
|
||||
current_token = get_next_token();
|
||||
|
|
@ -180,7 +184,8 @@ tokenizer_goto(const char *program)
|
|||
void
|
||||
tokenizer_init(const char *program)
|
||||
{
|
||||
tokenizer_goto(program);
|
||||
ptr = program;
|
||||
prog = program;
|
||||
current_token = get_next_token();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue