From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19785 invoked from network); 30 Jan 2009 10:03:12 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.3 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.2.5 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 30 Jan 2009 10:03:12 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 53678 invoked from network); 30 Jan 2009 10:03:08 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 30 Jan 2009 10:03:08 -0000 Received: (qmail 8562 invoked by alias); 30 Jan 2009 10:03:03 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 26491 Received: (qmail 8546 invoked from network); 30 Jan 2009 10:03:02 -0000 Received: from bifrost.dotsrc.org (130.225.254.106) by sunsite.dk with SMTP; 30 Jan 2009 10:03:02 -0000 Received: from cluster-g.mailcontrol.com (cluster-g.mailcontrol.com [208.87.233.190]) by bifrost.dotsrc.org (Postfix) with ESMTPS id C432A802720F for ; Fri, 30 Jan 2009 11:02:59 +0100 (CET) Received: from cameurexb01.EUROPE.ROOT.PRI ([193.128.72.68]) by rly12g.srv.mailcontrol.com (MailControl) with ESMTP id n0UA2jlZ007142 for ; Fri, 30 Jan 2009 10:02:46 GMT Received: from news01 ([10.103.143.38]) by cameurexb01.EUROPE.ROOT.PRI with Microsoft SMTPSVC(6.0.3790.3959); Fri, 30 Jan 2009 10:02:45 +0000 Date: Fri, 30 Jan 2009 10:02:45 +0000 From: Peter Stephenson To: "Zsh Hackers' List" Subject: Re: kill-region hook Message-ID: <20090130100245.0042a926@news01> In-Reply-To: <87fxj1psfv.fsf@linux2.maruska.tin.it> References: <87fxj1psfv.fsf@linux2.maruska.tin.it> Organization: CSR X-Mailer: Claws Mail 3.5.0 (GTK+ 2.12.8; i386-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 30 Jan 2009 10:02:45.0304 (UTC) FILETIME=[E5D57380:01C982C1] X-Scanned-By: MailControl A_08_51_00 (www.mailcontrol.com) on 10.71.0.122 X-Virus-Scanned: ClamAV 0.92.1/8922/Fri Jan 30 08:21:43 2009 on bifrost X-Virus-Status: Clean On Fri, 30 Jan 2009 01:07:32 +0100 Michal Maruska wrote: > Then I found zlelineasstring, but I don't understand what metafy is about > (it's called in zlelineasstring to modify the C string somehow). There are two representations of strings: ZLE_STRING_T is in terms of wide characters and is used for editing functions, a "metafied" character string is used elswhere in the shell. The latter is basically an ordinary null-terminated string, but with the special Meta character embedded in it that indicates that the following character is not special and should be xor'd with 32 to get the normal character (hence Meta followed by space represents and embedded null character that does not terminate the string). zlelineasstring() and stringaszleline() convert between the two representations. We only use ordinary ("unmetafied") C strings for interacting with the outside world (a particular example is for filenames passed to system functions). The other thing you need to be aware of is memory allocation: it's not always clear in the shell whether things should be allocated permanently using zalloc() and relatives or on the heap for freeing at the end of the current command execution using zhalloc(). You can work it out by looking at enough code, but possibly not just from the immediate context. So if you're converting a string for permanent storage you'd use the former, if you converting it for temporarily working on it and then converting it back you'd probably use the heap (though you can of course allocate it and free it, which is slower but does mean memory doesn't build up if the operation is repeated). There's some description of this in Src/mem.c. One upshot of that is that zlelineasstring() is probably the right thing to call, but I think you're temporary function argument list for the hook is coming from heap memory (newlinklist() is off the heap, unlike znewlinklist(), and you're not freeing it), so you need the final argument 1 to zlelineasstring(). Your size is now uninitialised, but I don't think you'll need it. Otherwise it looks roughly OK, but I'd have to look a bit more than I have time for at the moment to see if it's in the most logical place to catch operations on the cut buffer and kill ring, and if you're extracting the right bits of the cut buffer. -- Peter Stephenson Software Engineer CSR PLC, Churchill House, Cambridge Business Park, Cowley Road Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070