From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4533 invoked from network); 8 Oct 2007 02:01:47 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.3 (2007-08-08) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.2.3 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 8 Oct 2007 02:01:47 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 25629 invoked from network); 8 Oct 2007 02:01:41 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 8 Oct 2007 02:01:41 -0000 Received: (qmail 17999 invoked by alias); 8 Oct 2007 02:01:39 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 23911 Received: (qmail 17983 invoked from network); 8 Oct 2007 02:01:38 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 8 Oct 2007 02:01:38 -0000 Received: (qmail 25390 invoked from network); 8 Oct 2007 02:01:38 -0000 Received: from acolyte.scowler.net (216.254.112.45) by a.mx.sunsite.dk with SMTP; 8 Oct 2007 02:01:30 -0000 Received: by acolyte.scowler.net (Postfix, from userid 1000) id EED1F5C3B3; Sun, 7 Oct 2007 22:01:28 -0400 (EDT) Date: Sun, 7 Oct 2007 22:01:28 -0400 From: Clint Adams To: zsh-workers@sunsite.dk Subject: PATCH: curses module Message-ID: <20071008020128.GA3143@scowler.net> Mail-Followup-To: zsh-workers@sunsite.dk MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.16 (2007-06-11) Since there's little value in building this out-of-tree, I've reworked 23821 to build in-tree, renamed a few things, relicensed it, and adapted it to the New Module Way. Unfortunately it depends on wide character support in ncurses unconditionally. Index: configure.ac =================================================================== RCS file: /cvsroot/zsh/zsh/configure.ac,v retrieving revision 1.69 diff -u -r1.69 configure.ac --- configure.ac 2 Oct 2007 10:22:26 -0000 1.69 +++ configure.ac 8 Oct 2007 01:53:38 -0000 @@ -1133,7 +1133,8 @@ putenv getenv setenv unsetenv xw\ brk sbrk \ pathconf sysconf \ - tgetent tigetflag tigetnum tigetstr setupterm \ + tgetent tigetflag tigetnum tigetstr setupterm initscr \ + setcchar \ pcre_compile pcre_study pcre_exec \ nl_langinfo \ erand48 open_memstream \ Index: Src/Modules/curses.c =================================================================== RCS file: Src/Modules/curses.c diff -N Src/Modules/curses.c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ Src/Modules/curses.c 8 Oct 2007 01:53:38 -0000 @@ -0,0 +1,331 @@ +/* + * curses.c - curses windowing module for zsh + * + * This file is part of zsh, the Z shell. + * + * Copyright (c) 2007 Clint Adams + * All rights reserved. + * + * Permission is hereby granted, without written agreement and without + * license or royalty fees, to use, copy, modify, and distribute this + * software and to distribute modified versions of this software for any + * purpose, provided that the above copyright notice and the following + * two paragraphs appear in all copies of this software. + * + * In no event shall Clint Adams or the Zsh Development Group be liable + * to any party for direct, indirect, special, incidental, or consequential + * damages arising out of the use of this software and its documentation, + * even if Clint Adams and the Zsh Development Group have been advised of + * the possibility of such damage. + * + * Clint Adams and the Zsh Development Group specifically disclaim any + * warranties, including, but not limited to, the implied warranties of + * merchantability and fitness for a particular purpose. The software + * provided hereunder is on an "as is" basis, and Clint Adams and the + * Zsh Development Group have no obligation to provide maintenance, + * support, updates, enhancements, or modifications. + * + */ + +#define _XOPEN_SOURCE_EXTENDED 1 + +#include +#include + +#include + +#include "curses.mdh" +#include "curses.pro" + +static char *nam="curses"; + +#define ZCURSES_MAX_WINDOWS 9 + +static WINDOW *zcurses_WIN[ZCURSES_MAX_WINDOWS + 1]; + +/**/ +static int +bin_zcurses_newwin(char *nam, char **args, Options ops, UNUSED(int func)) +{ + int nlines, ncols, begin_y, begin_x; + unsigned winnum; + + nlines = atoi(args[0]); + ncols = atoi(args[1]); + begin_y = atoi(args[2]); + begin_x = atoi(args[3]); + winnum = atoi(args[4]); + + if(winnum > ZCURSES_MAX_WINDOWS) { + zerrnam(nam, "bad window number: %s", args[4], 0); + return 1; + } + + if(zcurses_WIN[winnum]!=NULL) { + zwarnnam(nam, "window number %s already defined", args[4], 0); + return 1; + } + + zcurses_WIN[winnum]=newwin(nlines, ncols, begin_y, begin_x); + + if(zcurses_WIN[winnum]==NULL) + return 1; + + return 0; +} + +/**/ +static int +bin_zcurses_delwin(char *nam, char **args, Options ops, UNUSED(int func)) +{ + unsigned winnum; + + winnum = atoi(args[0]); + + if(winnum > ZCURSES_MAX_WINDOWS) { + zerrnam(nam, "bad window number: %s", args[0], 0); + return 1; + } + + if(zcurses_WIN[winnum]==NULL) { + zwarnnam(nam, "window number %s does not exist", args[0], 0); + return 1; + } + + if(delwin(zcurses_WIN[winnum])!=OK) + return 1; + + zcurses_WIN[winnum]=NULL; + return 0; +} + +/**/ +static int +bin_zcurses_wrefresh(char *nam, char **args, Options ops, UNUSED(int func)) +{ + unsigned winnum; + + winnum = atoi(args[0]); + + if(winnum > ZCURSES_MAX_WINDOWS) { + zerrnam(nam, "bad window number: %s", args[0], 0); + return 1; + } + + if(zcurses_WIN[winnum]==NULL) { + zwarnnam(nam, "window number %s does not exist", args[0], 0); + return 1; + } + + if(wrefresh(zcurses_WIN[winnum])!=OK) + return 1; + + return 0; +} + +/**/ +static int +bin_zcurses_wmove(char *nam, char **args, Options ops, UNUSED(int func)) +{ + int y, x; + unsigned winnum; + + winnum = atoi(args[0]); + y = atoi(args[1]); + x = atoi(args[2]); + + if(winnum > ZCURSES_MAX_WINDOWS) { + zerrnam(nam, "bad window number: %s", args[0], 0); + return 1; + } + + if(zcurses_WIN[winnum]==NULL) { + zwarnnam(nam, "window number %s is not defined", args[0], 0); + return 1; + } + + if(wmove(zcurses_WIN[winnum], y, x)!=OK) + return 1; + + return 0; +} + +/**/ +static int +bin_zcurses_wadd_wch(char *nam, char **args, Options ops, UNUSED(int func)) +{ + unsigned winnum; + wchar_t c; + cchar_t cc; + + winnum = atoi(args[0]); + + if(mbrtowc(&c, args[1], MB_CUR_MAX, NULL) < 1) + return 1; + + if (setcchar(&cc, &c, A_NORMAL, 0, NULL)==ERR) + return 1; + + if(winnum > ZCURSES_MAX_WINDOWS) { + zerrnam(nam, "bad window number: %s", args[0], 0); + return 1; + } + + if(zcurses_WIN[winnum]==NULL) { + zwarnnam(nam, "window number %s is not defined", args[0], 0); + return 1; + } + + if(wadd_wch(zcurses_WIN[winnum], &cc)!=OK) + return 1; + + return 0; +} + +/**/ +static int +bin_zcurses_wadd_wchstr(char *nam, char **args, Options ops, UNUSED(int func)) +{ + unsigned winnum; + wchar_t *ws; + cchar_t *wcc; + size_t sl; + + winnum = atoi(args[0]); + + if(winnum > ZCURSES_MAX_WINDOWS) { + zerrnam(nam, "bad window number: %s", args[0], 0); + return 1; + } + + if(zcurses_WIN[winnum]==NULL) { + zwarnnam(nam, "window number %s is not defined", args[0], 0); + return 1; + } + + sl = strlen(args[1]); + + if(sl == 0) { + return 0; + } + + ws = malloc(sl * sizeof(wchar_t)); + + if(mbstowcs(ws, args[1], sl) < 1) { + free(ws); + return 1; + } + + wcc = malloc(wcslen(ws) * sizeof(cchar_t)); + + if (setcchar(wcc, ws, A_NORMAL, 0, NULL)==ERR) { + return 1; + } + + free(ws); + + if(wadd_wchstr(zcurses_WIN[winnum], wcc)!=OK) { + free(wcc); + return 1; + } + + free(wcc); + return 0; +} + +/**/ +static int +bin_zcurses_wborder(char *nam, char **args, Options ops, UNUSED(int func)) +{ + unsigned winnum; + + winnum = atoi(args[0]); + + if(winnum > ZCURSES_MAX_WINDOWS) { + zerrnam(nam, "bad window number: %s", args[0], 0); + return 1; + } + + if(zcurses_WIN[winnum]==NULL) { + zwarnnam(nam, "window number %s does not exist", args[0], 0); + return 1; + } + + if(wborder(zcurses_WIN[winnum], 0, 0, 0, 0, 0, 0, 0, 0)!=OK) + return 1; + + return 0; +} + + + +/* + * boot_ is executed when the module is loaded. + */ + +static struct builtin bintab[] = { + BUILTIN("zcurses_newwin", 0, bin_zcurses_newwin, 5, 5, 0, NULL, NULL), + BUILTIN("zcurses_delwin", 0, bin_zcurses_delwin, 1, 1, 0, NULL, NULL), + BUILTIN("zcurses_wrefresh", 0, bin_zcurses_wrefresh, 1, 1, 0, NULL, NULL), + BUILTIN("zcurses_wmove", 0, bin_zcurses_wmove, 3, 3, 0, NULL, NULL), + BUILTIN("zcurses_wadd_wch", 0, bin_zcurses_wadd_wch, 2, 2, 0, NULL, NULL), + BUILTIN("zcurses_wadd_wchstr", 0, bin_zcurses_wadd_wchstr, 2, 2, 0, NULL, NULL), + BUILTIN("zcurses_wborder", 0, bin_zcurses_wborder, 1, 1, 0, NULL, NULL), +}; + +static struct features module_features = { + bintab, sizeof(bintab)/sizeof(*bintab), + NULL, 0, + NULL, 0, + NULL, 0, + 0 +}; + +/**/ +int +setup_(UNUSED(Module m)) +{ + return 0; +} + +/**/ +int +features_(Module m, char ***features) +{ + *features = featuresarray(m, &module_features); + return 0; +} + +/**/ +int +enables_(Module m, int **enables) +{ + return handlefeatures(m, &module_features, enables); +} + +/**/ +int +boot_(Module m) +{ + int i; + for(i=1;i<=ZCURSES_MAX_WINDOWS;i++) + zcurses_WIN[i]=NULL; + + zcurses_WIN[0]=initscr(); + + return 0; +} + +/**/ +int +cleanup_(Module m) +{ + return setfeatureenables(m, &module_features, NULL); +} + +/**/ +int +finish_(UNUSED(Module m)) +{ + return 0; +} Index: Src/Modules/curses.mdd =================================================================== RCS file: Src/Modules/curses.mdd diff -N Src/Modules/curses.mdd --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ Src/Modules/curses.mdd 8 Oct 2007 01:53:38 -0000 @@ -0,0 +1,7 @@ +name=zsh/curses +link='if test "x$ac_cv_func_initscr" = xyes -a "x$ac_cv_header_curses_h" = xyes -a "x$ac_cv_func_setcchar" = xyes; then echo dynamic; else echo no; fi' +load=no + +autobins="zcurses_newwin" + +objects="curses.o"