From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21407 invoked from network); 3 Mar 2009 16:35:47 -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.4 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; 3 Mar 2009 16:35:47 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 41399 invoked from network); 3 Mar 2009 16:35:42 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 3 Mar 2009 16:35:42 -0000 Received: (qmail 16435 invoked by alias); 3 Mar 2009 16:35:37 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 26671 Received: (qmail 16420 invoked from network); 3 Mar 2009 16:35:37 -0000 Received: from bifrost.dotsrc.org (130.225.254.106) by sunsite.dk with SMTP; 3 Mar 2009 16:35:37 -0000 Received: from cluster-g.mailcontrol.com (cluster-g.mailcontrol.com [208.87.233.190]) by bifrost.dotsrc.org (Postfix) with ESMTPS id A70B78058F82 for ; Tue, 3 Mar 2009 17:35:31 +0100 (CET) Received: from cameurexb01.EUROPE.ROOT.PRI ([193.128.72.68]) by rly22g.srv.mailcontrol.com (MailControl) with ESMTP id n23GZRjB030682 for ; Tue, 3 Mar 2009 16:35:28 GMT Received: from news01 ([10.103.143.38]) by cameurexb01.EUROPE.ROOT.PRI with Microsoft SMTPSVC(6.0.3790.3959); Tue, 3 Mar 2009 16:35:27 +0000 Date: Tue, 3 Mar 2009 16:35:26 +0000 From: Peter Stephenson To: zsh workers Subject: Re: [wip patch] new zsh/attr module Message-ID: <20090303163526.533995be@news01> In-Reply-To: References: <20090303121253.61f5e2ec@news01> 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: 03 Mar 2009 16:35:27.0013 (UTC) FILETIME=[0EECED50:01C99C1E] X-Scanned-By: MailControl A_08_51_00 (www.mailcontrol.com) on 10.71.0.132 X-Virus-Scanned: ClamAV 0.92.1/9065/Tue Mar 3 11:43:41 2009 on bifrost X-Virus-Status: Clean On Tue, 3 Mar 2009 15:43:29 +0100 (CET) Mikael Magnusson wrote: > I've written some basic entries for the builtins, it doesn't seem to show > up properly in man zshmodules though, in the summary list at the top it > doesn't appear, but it does appear below with the details. It might be just a dependency problem; it all seems to be there in my case. > It's trivial if you know how the standard builtin handling code works, > less so otherwise :). I will look into it later. I think I want a -h > option for not dereferencing symlinks. You need a string containing "h" where the builtin is declared and to test OPT_ISSET(ops,'h') in the function for the builtin. > I didn't quite figure out how to best set an array parameter, so for now I > still only handle one file, and the zlistattr function sets the whole > string with nulls in the parameter, so you have to use ${(0)REPLY} to > split it. I looked a little at bin_read since i know read can set an array > parameter, but it is probably not very well suited as an easy to > understand example since it does so many other things too. The use of setaparam() in stat.c is probably a good example, it's doing something very similar, and there are some hash examples down there, too. Remember all the bits come from permanently allocated memory. > I think I got this right now, but I haven't tested the case where the > stuff isn't found. It looks OK. I'll see if I can find a Solaris machine left over to try it on when I've committed the patch at the bottom. > It looks like I have to re-metafy the string when using zwarnnam, I pass > in the parameter that says the buffer is large enough, since it did > contain the metafied version of the string some milliseconds earlier. That > should work, right? It's better to pass in the right length in case of embedded NULs---there shouldn't be any since the filesystem calls wouldn't handle them, but it's more consistent. That's an easy change. Something strange happened with some of the whitespace in the patch so I applied various bits by hand. There are various minor tweaks below: expand the filename in completion in case it's got a ~ in it; reformat the .distfiles (I've been gradually doing this to all of them since one file per line is much easier to maintain); handle lengths when metafying; don't report errors unless system calls returned a negative value; remove an unused variable. =================================================================== RCS file: /cvsroot/zsh/zsh/Completion/Zsh/Command/_zattr,v retrieving revision 1.1 diff -u -r1.1 _zattr --- Completion/Zsh/Command/_zattr 3 Mar 2009 15:04:27 -0000 1.1 +++ Completion/Zsh/Command/_zattr 3 Mar 2009 16:24:48 -0000 @@ -29,6 +29,6 @@ esac if [[ $state = attrs ]]; then - zlistattr $line[1] REPLY + zlistattr $~line[1] REPLY _wanted attrs expl 'attribute' compadd ${(0)REPLY} fi Index: Doc/Zsh/.distfiles =================================================================== RCS file: /cvsroot/zsh/zsh/Doc/Zsh/.distfiles,v retrieving revision 1.19 diff -u -r1.19 .distfiles --- Doc/Zsh/.distfiles 3 Mar 2009 15:04:28 -0000 1.19 +++ Doc/Zsh/.distfiles 3 Mar 2009 16:24:48 -0000 @@ -1,21 +1,72 @@ DISTFILES_SRC=' - .cvsignore .distfiles - arith.yo builtins.yo calsys.yo compat.yo - compctl.yo compsys.yo compwid.yo cond.yo - contrib.yo exec.yo expn.yo filelist.yo - files.yo func.yo grammar.yo index.yo - intro.yo invoke.yo jobs.yo manmodmenu.yo - manual.yo metafaq.yo mod_attr.yo mod_cap.yo - mod_clone.yo - mod_compctl.yo mod_complete.yo mod_complist.yo mod_computil.yo - mod_curses.yo mod_datetime.yo mod_deltochar.yo mod_example.yo - mod_files.yo mod_langinfo.yo modlist.yo mod_mapfile.yo - mod_mathfunc.yo modmenu.yo mod_newuser.yo mod_parameter.yo - mod_pcre.yo mod_regex.yo mod_sched.yo mod_socket.yo - mod_stat.yo mod_system.yo mod_tcp.yo mod_termcap.yo - mod_terminfo.yo modules.yo mod_zftp.yo mod_zleparameter.yo - mod_zle.yo mod_zprof.yo mod_zpty.yo mod_zselect.yo - mod_zutil.yo options.yo params.yo prompt.yo - redirect.yo restricted.yo roadmap.yo seealso.yo - tcpsys.yo zftpsys.yo zle.yo +.cvsignore +.distfiles +arith.yo +builtins.yo +calsys.yo +compat.yo +compctl.yo +compsys.yo +compwid.yo +cond.yo +contrib.yo +exec.yo +expn.yo +filelist.yo +files.yo +func.yo +grammar.yo +index.yo +intro.yo +invoke.yo +jobs.yo +manmodmenu.yo +manual.yo +metafaq.yo +mod_attr.yo +mod_cap.yo +mod_clone.yo +mod_compctl.yo +mod_complete.yo +mod_complist.yo +mod_computil.yo +mod_curses.yo +mod_datetime.yo +mod_deltochar.yo +mod_example.yo +mod_files.yo +mod_langinfo.yo +modlist.yo +mod_mapfile.yo +mod_mathfunc.yo +modmenu.yo +mod_newuser.yo +mod_parameter.yo +mod_pcre.yo +mod_regex.yo +mod_sched.yo +mod_socket.yo +mod_stat.yo +mod_system.yo +mod_tcp.yo +mod_termcap.yo +mod_terminfo.yo +modules.yo +mod_zftp.yo +mod_zleparameter.yo +mod_zle.yo +mod_zprof.yo +mod_zpty.yo +mod_zselect.yo +mod_zutil.yo +options.yo +params.yo +prompt.yo +redirect.yo +restricted.yo +roadmap.yo +seealso.yo +tcpsys.yo +zftpsys.yo +zle.yo ' Index: Src/Modules/attr.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/Modules/attr.c,v retrieving revision 1.1 diff -u -r1.1 attr.c --- Src/Modules/attr.c 3 Mar 2009 15:04:28 -0000 1.1 +++ Src/Modules/attr.c 3 Mar 2009 16:24:48 -0000 @@ -37,10 +37,10 @@ bin_getattr(char *nam, char **argv, UNUSED(Options ops), UNUSED(int func)) { int ret = 0; - int len; + int len, slen; char value[256]; - unmetafy(*argv, NULL); + unmetafy(*argv, &slen); unmetafy(*(argv+1), NULL); if (listxattr(*argv, NULL, 0) > 0) { if (0 < (len = getxattr(*argv, *(argv+1), value, 255))) { @@ -51,8 +51,8 @@ else printf("%s\n", value); } - } else { - zwarnnam(nam, "%s: %e", metafy(*argv, -1, META_NOALLOC), errno); + } else if (len < 0) { + zwarnnam(nam, "%s: %e", metafy(*argv, slen, META_NOALLOC), errno); ret = 1; } } @@ -62,13 +62,13 @@ static int bin_setattr(char *nam, char **argv, UNUSED(Options ops), UNUSED(int func)) { - int ret = 0; - - unmetafy(*argv, NULL); + int ret = 0, slen; + + unmetafy(*argv, &slen); unmetafy(*(argv+1), NULL); unmetafy(*(argv+2), NULL); if (setxattr(*argv, *(argv+1), *(argv+2), strlen(*(argv+2)), 0)) { - zwarnnam(nam, "%s: %e", metafy(*argv, -1, META_NOALLOC), errno); + zwarnnam(nam, "%s: %e", metafy(*argv, slen, META_NOALLOC), errno); ret = 1; } return ret; @@ -77,25 +77,25 @@ static int bin_delattr(char *nam, char **argv, UNUSED(Options ops), UNUSED(int func)) { - int ret = 0; - - unmetafy(*argv, NULL); + int ret = 0, slen; + + unmetafy(*argv, &slen); unmetafy(*(argv+1), NULL); if (removexattr(*argv, *(argv+1))) { - zwarnnam(nam, "%s: %e", metafy(*argv, -1, META_NOALLOC), errno); + zwarnnam(nam, "%s: %e", metafy(*argv, slen, META_NOALLOC), errno); ret = 1; } return ret; } - + static int bin_listattr(char *nam, char **argv, UNUSED(Options ops), UNUSED(int func)) { int ret = 0; - int len, i = 1; + int len, slen; char value[256]; - unmetafy(*argv, NULL); + unmetafy(*argv, &slen); if (0 < (len = listxattr(*argv, value, 256))) { if (len < 256) { char *p = value; @@ -106,8 +106,8 @@ p += strlen(p) + 1; } } - } else { - zwarnnam(nam, "%s: %e", metafy(*argv, -1, META_NOALLOC), errno); + } else if (len < 0) { + zwarnnam(nam, "%s: %e", metafy(*argv, slen, META_NOALLOC), errno); ret = 1; } return ret; -- Peter Stephenson Software Engineer CSR PLC, Churchill House, Cambridge Business Park, Cowley Road Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070