> Hi, Hi.
> Here is an updated diff for mg with tinyscheme integration. It's based on > tedu's original diff with various tweaks and changes. For those worried about > mg being too bloated, rest assured, it's still small and lean and a big part > smaller than vi ;-) > It's not fully possible to turn mg into your mail client, but I'd like to commit > this diff and work on it futher in tree (not the mail-client thing, that would > bloat mg and that's far from desired). > > Includes some fixes by lum@ and Sunil Nimmagadda too. > > Diff is also at http://crappydiffs.org/tinyschemg.diff > > OK? Well, this is based on source from tinyscheme, where's the full licence? http://tinyscheme.sourceforge.net/license.txt seems rather strict about that... If the licence seems ok, why not just pull a complete tinyscheme instance, that would then be usable from other applications? (tinyscheme doesn't seem to be in ports). A quick reading makes me wonder about what follows. [...] > Index: Makefile > =================================================================== > RCS file: /cvs/src/usr.bin/mg/Makefile,v > retrieving revision 1.27 > diff -p -u -r1.27 Makefile > --- Makefile 18 Jun 2012 07:13:26 -0000 1.27 > +++ Makefile 28 Jun 2012 06:28:14 -0000 > @@ -13,7 +13,7 @@ DPADD+= ${LIBCURSES} ${LIBUTIL} > # XKEYS -- use termcap function key definitions. > # note: XKEYS and bsmap mode do _not_ get along. > # > -CFLAGS+=-Wall -DFKEYS -DREGEX -DXKEYS > +CFLAGS+=-Wall -DFKEYS -DREGEX -DXKEYS -O0 > > SRCS= autoexec.c basic.c buffer.c cinfo.c dir.c display.c \ > echo.c extend.c file.c fileio.c funmap.c help.c kbd.c keymap.c \ > @@ -26,9 +26,24 @@ SRCS= autoexec.c basic.c buffer.c cinfo. > # > SRCS+= cmode.c cscope.c dired.c grep.c tags.c theo.c > > +# Tinyscheme extension > +SRCS+= scheme.c mgscheme.c > +LDADD+= -lm > +DPADD+= ${LIBM} > + > +# No non-ELF arches support shared objects. > +.include <bsd.own.mk> > +.if ${ELF_TOOLCHAIN} == "yes" > +CFLAGS+=-DUSE_DL > +SRCS += dynload.c > +.endif > + > afterinstall: > ${INSTALL} -d ${DESTDIR}${DOCDIR}/mg > ${INSTALL} -m ${DOCMODE} -c ${.CURDIR}/tutorial \ > ${DESTDIR}${DOCDIR}/mg > + ${INSTALL} -d ${DESTDIR}${SHAREDIR}/mg > + ${INSTALL} -m ${SHAREMODE} -c ${.CURDIR}/init.scm \ > + ${DESTDIR}${SHAREDIR}/mg > > .include <bsd.prog.mk> > Index: def.h > =================================================================== > RCS file: /cvs/src/usr.bin/mg/def.h,v > retrieving revision 1.124 > diff -p -u -r1.124 def.h > --- def.h 14 Jun 2012 17:21:22 -0000 1.124 > +++ def.h 28 Jun 2012 06:28:15 -0000 > @@ -534,6 +534,10 @@ int csprevfile(int, int); > int csprevmatch(int, int); > int cscreatelist(int, int); > > + > +int mgscheme(int, int); > + > + > /* extend.c X */ > int insert(int, int); > int bindtokey(int, int); > Index: dynload.c > =================================================================== > RCS file: dynload.c > diff -N dynload.c > --- /dev/null 1 Jan 1970 00:00:00 -0000 > +++ dynload.c 28 Jun 2012 06:28:16 -0000 > @@ -0,0 +1,112 @@ > +/* $OpenBSD$ */ > + > +/* dynload.c Dynamic Loader for TinyScheme */ > +/* Original Copyright (c) 1999 Alexander Shendi */ > +/* Modifications for NT and dl_* interface, scm_load_ext: D. Souflis */ > +/* Refurbished by Stephen Gildea */ > + > +#define _SCHEME_SOURCE > +#include "dynload.h" > +#include <string.h> > +#include <stdio.h> > +#include <stdlib.h> > + > +#ifndef MAXPATHLEN > +# define MAXPATHLEN 1024 > +#endif What about just pulling <sys/param.h>? > + > +static void make_filename(const char *name, char *filename); > +static void make_init_fn(const char *name, char *init_fn); > + > +typedef void *HMODULE; > +typedef void (*FARPROC)(); > +#define SUN_DL Hmmm. > +#include <dlfcn.h> > + > +#if defined(SUN_DL) Huh? 8) > + > +#include <dlfcn.h> > + > +#define PREFIX "lib" > +#define SUFFIX ".so" > + > +static HMODULE dl_attach(const char *module) { > + HMODULE so=dlopen(module,RTLD_LAZY); > + if(!so) { > + fprintf(stderr, "Error loading scheme extension \"%s\": %s\n", module, dlerror()); > + } > + return so; > +} > + > +static FARPROC dl_proc(HMODULE mo, const char *proc) { > + const char *errmsg; > + FARPROC fp=(FARPROC)dlsym(mo,proc); > + if ((errmsg = dlerror()) == 0) { > + return fp; > + } > + fprintf(stderr, "Error initializing scheme module \"%s\": %s\n", proc, errmsg); > + return 0; > +} > + > +static void dl_detach(HMODULE mo) { > + (void)dlclose(mo); > +} > +#endif > + > +pointer scm_load_ext(scheme *sc, pointer args) > +{ > + pointer first_arg; > + pointer retval; > + char filename[MAXPATHLEN], init_fn[MAXPATHLEN+6]; > + char *name; > + HMODULE dll_handle; > + void (*module_init)(scheme *sc); > + > + if ((args != sc->NIL) && is_string((first_arg = pair_car(args)))) { > + name = string_value(first_arg); > + make_filename(name,filename); > + make_init_fn(name,init_fn); > + dll_handle = dl_attach(filename); > + if (dll_handle == 0) { > + retval = sc -> F; > + } > + else { > + module_init = (void(*)(scheme *))dl_proc(dll_handle, init_fn); > + if (module_init != 0) { > + (*module_init)(sc); > + retval = sc -> T; > + } > + else { > + retval = sc->F; > + } > + } > + } > + else { > + retval = sc -> F; > + } > + > + return(retval); > +} > + > +static void make_filename(const char *name, char *filename) { > + (void)strlcpy(filename,name,sizeof(filename)); > + (void)strlcat(filename,SUFFIX,sizeof(filename)); This looks wrong. > +} > + > +static void make_init_fn(const char *name, char *init_fn) { > + const char *p=strrchr(name,'/'); > + if(p==0) { > + p=name; > + } else { > + p++; > + } > + (void)strlcpy(init_fn,"init_",sizeof(init_fn)); > + (void)strlcat(init_fn,p,sizeof(init_fn)); Same here. > +} > + > + > +/* > +Local variables: > +c-file-style: "k&r" > +End: > +*/ [...] -- Jérémie Courrèges-Anglas GPG fingerprint: 61DB D9A0 00A4 67CF 2A90 8961 6191 8FBF 06A1 1494