From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22671 invoked from network); 8 Oct 2007 23:20:05 -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 23:20:05 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 56108 invoked from network); 8 Oct 2007 23:19:59 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 8 Oct 2007 23:19:59 -0000 Received: (qmail 6802 invoked by alias); 8 Oct 2007 23:19:56 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 23923 Received: (qmail 6788 invoked from network); 8 Oct 2007 23:19:56 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 8 Oct 2007 23:19:56 -0000 Received: (qmail 55863 invoked from network); 8 Oct 2007 23:19:56 -0000 Received: from acolyte.scowler.net (216.254.112.45) by a.mx.sunsite.dk with SMTP; 8 Oct 2007 23:19:50 -0000 Received: by acolyte.scowler.net (Postfix, from userid 1000) id 2DFC65C3B3; Mon, 8 Oct 2007 19:19:45 -0400 (EDT) Date: Mon, 8 Oct 2007 19:19:46 -0400 From: Clint Adams To: zsh-workers@sunsite.dk Subject: Re: PATCH: zcurses builtin Message-ID: <20071008231946.GA10129@scowler.net> Mail-Followup-To: zsh-workers@sunsite.dk References: <20071008140554.GA24853@scowler.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20071008140554.GA24853@scowler.net> User-Agent: Mutt/1.5.16 (2007-06-11) On Mon, Oct 08, 2007 at 10:05:54AM -0400, Clint Adams wrote: > I haven't done the rest yet mostly due to indecision about option > letters. Here's the rest. It assumes that the user is passing the current number of arguments. zcurses -s is still not functioning properly. Example script, evolved: --8<-- zmodload curses zcurses -a 10 10 10 10 5 zcurses -b 5 zcurses -m 5 1 1 zcurses -c 5 B zcurses -c 5 l zcurses -c 5 a zcurses -c 5 h zcurses -r 5 sleep 5 --8<-- Index: Src/Modules/curses.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/Modules/curses.c,v retrieving revision 1.2 diff -u -r1.2 curses.c --- Src/Modules/curses.c 8 Oct 2007 14:11:29 -0000 1.2 +++ Src/Modules/curses.c 8 Oct 2007 22:59:42 -0000 @@ -55,12 +55,12 @@ zcurses_strerror(int err) { static const char *errs[] = { - NULL, + "unknown error", "window number out of range", "window already defined", NULL }; - return errs[err]; + return errs[(err < 1 || err > 2) ? 0 : err]; } /**/ @@ -81,12 +81,12 @@ return -1; } - if(zcurses_WIN[target]!=NULL && (criteria & ZCURSES_UNUSED)) { + if (zcurses_WIN[target]!=NULL && (criteria & ZCURSES_UNUSED)) { zc_errno = ZCURSES_EDEFINED; return -1; } - if(zcurses_WIN[target]==NULL && (criteria & ZCURSES_USED)) { + if (zcurses_WIN[target]==NULL && (criteria & ZCURSES_USED)) { zc_errno = ZCURSES_EUNDEFINED; return -1; } @@ -98,30 +98,30 @@ static int bin_zcurses(char *nam, char **args, Options ops, UNUSED(int func)) { - int targetwin; + unsigned targetwin; if (OPT_ISSET(ops,'a')) { 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 = zcurses_validate_window(args[4], ZCURSES_UNUSED); + targetwin = zcurses_validate_window(args[4], ZCURSES_UNUSED); - if (winnum == -1) { + if (targetwin == -1) { zerrnam(nam, "%s: %s", zcurses_strerror(zc_errno), args[4], 0); return 1; } - zcurses_WIN[winnum]=newwin(nlines, ncols, begin_y, begin_x); + zcurses_WIN[targetwin]=newwin(nlines, ncols, begin_y, begin_x); - if(zcurses_WIN[winnum]==NULL) + if (zcurses_WIN[targetwin]==NULL) return 1; return 0; } + if (OPT_ISSET(ops,'d')) { targetwin = zcurses_validate_window(OPT_ARG(ops,'d'), ZCURSES_USED); if (targetwin == -1) { @@ -129,7 +129,7 @@ return 1; } - if(delwin(zcurses_WIN[targetwin])!=OK) + if (delwin(zcurses_WIN[targetwin])!=OK) return 1; zcurses_WIN[targetwin]=NULL; @@ -145,136 +145,102 @@ return (wrefresh(zcurses_WIN[targetwin])!=OK) ? 1 : 0; } + if (OPT_ISSET(ops,'m')) { 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); + targetwin = zcurses_validate_window(args[0], ZCURSES_USED); + if (targetwin == -1) { + zwarnnam(nam, "%s: %s", zcurses_strerror(zc_errno), args[0], 0); return 1; } - if(zcurses_WIN[winnum]==NULL) { - zwarnnam(nam, "window number %s is not defined", args[0], 0); - return 1; - } + y = atoi(args[1]); + x = atoi(args[2]); - if(wmove(zcurses_WIN[winnum], y, x)!=OK) + if (wmove(zcurses_WIN[targetwin], y, x)!=OK) return 1; return 0; } - 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; + if (OPT_ISSET(ops,'c')) { + wchar_t c; + cchar_t cc; - winnum = atoi(args[0]); + targetwin = zcurses_validate_window(args[0], ZCURSES_USED); + if (targetwin == -1) { + zwarnnam(nam, "%s: %s", zcurses_strerror(zc_errno), args[0], 0); + return 1; + } - if(mbrtowc(&c, args[1], MB_CUR_MAX, NULL) < 1) - return 1; + if (mbrtowc(&c, args[1], MB_CUR_MAX, NULL) < 1) + return 1; - if (setcchar(&cc, &c, A_NORMAL, 0, NULL)==ERR) - 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 (wadd_wch(zcurses_WIN[targetwin], &cc)!=OK) + return 1; - if(zcurses_WIN[winnum]==NULL) { - zwarnnam(nam, "window number %s is not defined", args[0], 0); - return 1; + return 0; } - if(wadd_wch(zcurses_WIN[winnum], &cc)!=OK) - return 1; + if (OPT_ISSET(ops,'s')) { + wchar_t *ws; + cchar_t *wcc; + size_t sl; - 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; + targetwin = zcurses_validate_window(args[0], ZCURSES_USED); + if (targetwin == -1) { + zwarnnam(nam, "%s: %s", zcurses_strerror(zc_errno), args[0], 0); + return 1; + } - winnum = atoi(args[0]); + sl = strlen(args[1]); - if(winnum > ZCURSES_MAX_WINDOWS) { - zerrnam(nam, "bad window number: %s", args[0], 0); - return 1; - } + if (sl == 0) { + return 0; + } - if(zcurses_WIN[winnum]==NULL) { - zwarnnam(nam, "window number %s is not defined", args[0], 0); - return 1; - } + ws = malloc(sl * sizeof(wchar_t)); - sl = strlen(args[1]); + if (mbstowcs(ws, args[1], sl) < 1) { + free(ws); + return 1; + } - if(sl == 0) { - return 0; - } + wcc = malloc(wcslen(ws) * sizeof(cchar_t)); - ws = malloc(sl * sizeof(wchar_t)); + if (setcchar(wcc, ws, A_NORMAL, 0, NULL)==ERR) { + return 1; + } - 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[targetwin], wcc)!=OK) { + free(wcc); + return 1; + } - if(wadd_wchstr(zcurses_WIN[winnum], wcc)!=OK) { free(wcc); - return 1; + return 0; } - free(wcc); - return 0; -} - -/**/ -static int -bin_zcurses_wborder(char *nam, char **args, Options ops, UNUSED(int func)) -{ - unsigned winnum; + if (OPT_ISSET(ops,'b')) { - winnum = atoi(args[0]); + targetwin = zcurses_validate_window(OPT_ARG(ops,'b'), ZCURSES_USED); + if (targetwin == -1) { + zwarnnam(nam, "%s: %s", zcurses_strerror(zc_errno), OPT_ARG(ops,'b'), 0); + return 1; + } - if(winnum > ZCURSES_MAX_WINDOWS) { - zerrnam(nam, "bad window number: %s", args[0], 0); - return 1; - } + if (wborder(zcurses_WIN[targetwin], 0, 0, 0, 0, 0, 0, 0, 0)!=OK) + return 1; - if(zcurses_WIN[winnum]==NULL) { - zwarnnam(nam, "window number %s does not exist", args[0], 0); - return 1; + return 0; } - if(wborder(zcurses_WIN[winnum], 0, 0, 0, 0, 0, 0, 0, 0)!=OK) - return 1; - return 0; } @@ -283,10 +249,7 @@ */ static struct builtin bintab[] = { - BUILTIN("zcurses", 0, bin_zcurses, 0, 5, 0, "ad:mr:", 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), + BUILTIN("zcurses", 0, bin_zcurses, 0, 5, 0, "ab:cd:mr:rs", NULL), }; static struct features module_features = {