1
0
mirror of https://github.com/janet-lang/janet synced 2024-12-25 07:50:27 +00:00

Remove readline and add travis

This commit is contained in:
Calvin Rose 2017-06-25 19:47:49 -04:00
parent a7a9ff7629
commit b23fc136dd
3 changed files with 43 additions and 8 deletions

7
.travis.yml Normal file
View File

@ -0,0 +1,7 @@
language: c
script: make test
compiler:
- clang
- gcc

View File

@ -3,7 +3,7 @@
######################################################
##### Set global variables for all gst Makefiles #####
######################################################
CFLAGS=-std=c99 -Wall -Wextra -Wpedantic -I./include -lreadline -g
CFLAGS=-std=c99 -Wall -Wextra -Wpedantic -I./include -g
PREFIX=/usr/local
GST_TARGET=client/gst
GST_CORELIB=core/libgst.a

View File

@ -24,9 +24,35 @@
#include <stdio.h>
#include <gst/gst.h>
/* Use readline support for now */
#include <readline/readline.h>
#include <readline/history.h>
/* Simple read line functionality */
char *getline() {
char *line = malloc(100);
char *linep = line;
size_t lenmax = 100;
size_t len = lenmax;
int c;
if (line == NULL)
return NULL;
for (;;) {
c = fgetc(stdin);
if (c == EOF)
break;
if (--len == 0) {
len = lenmax;
char *linen = realloc(linep, lenmax *= 2);
if (linen == NULL) {
free(linep);
return NULL;
}
line = linen + (line - linep);
linep = linen;
}
if ((*line++ = c) == '\n')
break;
}
*line = '\0';
return linep;
}
/* Compile and run an ast */
int debug_compile_and_run(Gst *vm, GstValue ast, GstValue last) {
@ -98,7 +124,7 @@ int debug_run(Gst *vm, FILE *in) {
/* A simple repl */
int debug_repl(Gst *vm) {
const char *buffer, *reader;
char *buffer, *reader;
GstParser p;
buffer = reader = NULL;
for (;;) {
@ -109,10 +135,12 @@ int debug_repl(Gst *vm) {
if (p.status == GST_PARSER_ERROR || p.status == GST_PARSER_FULL)
break;
if (!reader || *reader == '\0') {
buffer = readline(">> ");
if (*buffer == '\0')
printf("\x1B[32m>>\x1B[0m ");
if (buffer)
free(buffer);
buffer = getline();
if (!buffer || *buffer == '\0')
return 0;
add_history(buffer);
reader = buffer;
}
reader += gst_parse_cstring(&p, reader);