From: Michael D. Lowis Date: Sat, 7 Oct 2017 00:31:53 +0000 (-0400) Subject: Added function to load file to string X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=fc20737dcd8ffd48bf9603e9d6dc497303f5a87a;p=archive%2Ftide-ocaml.git Added function to load file to string --- diff --git a/Makefile b/Makefile index eeb53a8..68289b8 100644 --- a/Makefile +++ b/Makefile @@ -28,9 +28,11 @@ LIBOBJS = \ lib/tide.$(OBJEXT) \ lib/x11.$(OBJEXT) \ lib/cfg.$(OBJEXT) \ - lib/x11_prims.o \ lib/rope.$(OBJEXT) \ lib/buf.$(OBJEXT) \ + lib/misc.$(OBJEXT) \ + lib/x11_prims.o \ + lib/misc_prims.o \ lib/utf8.o .PHONY: all clean diff --git a/edit.ml b/edit.ml index d2136ae..848d7e2 100644 --- a/edit.ml +++ b/edit.ml @@ -8,13 +8,12 @@ let font = font_load "Monospace:size=10" type drawpos = { x: int; y: int } let draw_bkg color width height pos = - let clr = Cfg.Color.palette.(color) in - draw_rect { x = pos.x; y = pos.y; w = width; h = height; c = clr } + draw_rect { x = pos.x; y = pos.y; w = width; h = height; c = color } (* curried helpers *) -let draw_dark_bkg = draw_bkg 0 -let draw_light_bkg = draw_bkg 1 -let draw_gray_bkg = draw_bkg 3 +let draw_dark_bkg = draw_bkg Cfg.Color.palette.(0) +let draw_light_bkg = draw_bkg Cfg.Color.palette.(1) +let draw_gray_bkg = draw_bkg Cfg.Color.palette.(3) let draw_text text pos = draw_string font Cfg.Color.palette.(5) text (pos.x + 2, pos.y + 2); @@ -69,7 +68,7 @@ let onupdate width height = let pos = draw_status pos width "UNSI> *scratch*" in let pos = draw_tags pos width (height / font.height / 4) "Sample tags data" in let pos = draw_scroll pos height in - let _ = draw_edit pos width height in + let _ = draw_edit pos width height in flip () let onshutdown () = diff --git a/lib/misc.ml b/lib/misc.ml new file mode 100644 index 0000000..18d6320 --- /dev/null +++ b/lib/misc.ml @@ -0,0 +1,2 @@ +external load_file : string -> string + = "load_file" diff --git a/lib/misc_prims.c b/lib/misc_prims.c new file mode 100644 index 0000000..2bc6268 --- /dev/null +++ b/lib/misc_prims.c @@ -0,0 +1,34 @@ +#include "internals.h" +#include +#include +#include +#include + +CAMLprim value load_file(value path) { + CAMLparam1(path); + CAMLlocal1(str); + int fd, nread; + struct stat sb; + if (((fd = open(String_val(path), O_RDONLY, 0)) < 0) || + (fstat(fd, &sb) < 0) || + (sb.st_size == 0)) { + caml_failwith("could not open file"); + } else { + str = caml_alloc_string(sb.st_size); + while ((nread = read(fd, String_val(str), sb.st_size)) > 0); + if (nread < 0) + caml_failwith("read() failed"); + } + close(fd); + CAMLreturn(str); +} + +CAMLprim value env_set(value name, value val) { + CAMLparam2(name,val); + CAMLreturn(Val_unit); +} + +CAMLprim value env_get(value name) { + CAMLparam1(name); + CAMLreturn(Val_unit); +}