~tim/malcc

2589e43e96ae3ae7c3d3b5c6bccd3f1d83f838ad — Tim Morgan 5 years ago 7f9ab03
Fix editline locale for multibyte characters
5 files changed, 10 insertions(+), 47 deletions(-)

M .build.yml
M Makefile
M malcc.c
D readline.c
D readline.h
M .build.yml => .build.yml +1 -1
@@ 10,7 10,7 @@ sources:
tasks:
  - build: |
      cd malcc
      make -e CEXTRAFLAGS='-DNOEDITLINE' all
      make all
  - test: |
      cd malcc
      make test

M Makefile => Makefile +5 -5
@@ 1,7 1,7 @@
OS:=$(shell uname)
CC=gcc
CFLAGS=-Itinycc -Wall -Wextra -Werror -g $(CEXTRAFLAGS)
LDLIBS=-ledit -lgc -lpcre -ldl
CFLAGS=-Itinycc -Wall -Wextra -Werror -g
LDLIBS=-ledit -ltermcap -lgc -lpcre -ldl

ALL_STEPS=step0_repl step1_read_print step2_eval step3_env step4_if_fn_do step5_tco step6_file step7_quote step8_macros step9_try stepA_mal malcc



@@ 20,7 20,7 @@ step7_quote: step7_quote.o core.o env.o hashmap.o printer.o reader.o types.o uti
step8_macros: step8_macros.o core.o env.o hashmap.o printer.o reader.o types.o util.o tinycc/libtcc.a
step9_try: step9_try.o core.o env.o hashmap.o printer.o reader.o types.o util.o tinycc/libtcc.a
stepA_mal: stepA_mal.o core.o env.o hashmap.o printer.o reader.o types.o util.o tinycc/libtcc.a
malcc: malcc.o core.o env.o hashmap.o printer.o reader.o readline.o types.o util.o tinycc/libtcc.a
malcc: malcc.o core.o env.o hashmap.o printer.o reader.o types.o util.o tinycc/libtcc.a

tinycc/libtcc.a:
	cd tinycc && ./configure && make


@@ 115,10 115,10 @@ docker-bash: docker-build
	$(RUN_DOCKER_CMD) bash

docker-test: docker-build
	$(RUN_DOCKER_CMD) make -e CEXTRAFLAGS='-DNOEDITLINE' test
	$(RUN_DOCKER_CMD) make test

docker-test-supplemental: docker-build
	$(RUN_DOCKER_CMD) make -e CEXTRAFLAGS='-DNOEDITLINE' test-supplemental
	$(RUN_DOCKER_CMD) make test-supplemental

docker-watch: docker-build
	$(RUN_DOCKER_CMD) bash -c "ls *.c *.h Makefile | entr -c -s 'make test'"

M malcc.c => malcc.c +4 -1
@@ 1,16 1,17 @@
#include <assert.h>
#include <editline/readline.h>
#include <gc.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <libtcc.h>
#include <locale.h>

#include "core.h"
#include "env.h"
#include "printer.h"
#include "reader.h"
#include "readline.h"
#include "util.h"

char program_template[] =


@@ 1023,6 1024,8 @@ int main(int argc, char *argv[]) {

  rep(builtin_defs, repl_env);

  setlocale(LC_ALL, ""); // use locale set from environment

  if (mal_vector_len(arg_vec) >= 1) {
    rep(mal_sprintf("(load-file %s)", pr_str(mal_vector_ref(arg_vec, 0), 1))->str, repl_env);
  } else {

D readline.c => readline.c +0 -31
@@ 1,31 0,0 @@
#include <stdio.h>
#include <stdlib.h>

#ifdef NOEDITLINE

char* readline(const char *prompt) {
  char* input = malloc(1000);
  printf("%s", prompt);
  return fgets(input, 1000, stdin);
}

int read_history(const char *filename) {
  (void)filename;
  return 1;
}

int add_history(const char *input) {
  (void)input;
  return 1;
}

int write_history(const char *filename) {
  (void)filename;
  return 1;
}

#else

#include <editline/readline.h>

#endif

D readline.h => readline.h +0 -9
@@ 1,9 0,0 @@
#ifndef __MAL_READLINE__
#define __MAL_READLINE__

char* readline(const char *prompt);
int read_history(const char *filename);
int add_history(const char *input);
int write_history(const char *filename);

#endif