From: Peter Stephenson <pws@csr.com>
To: zsh workers <zsh-workers@sunsite.dk>
Subject: Re: [wip patch] new zsh/attr module
Date: Tue, 3 Mar 2009 16:35:26 +0000 [thread overview]
Message-ID: <20090303163526.533995be@news01> (raw)
In-Reply-To: <alpine.LNX.2.00.0903031455360.10365@localhost>
On Tue, 3 Mar 2009 15:43:29 +0100 (CET)
Mikael Magnusson <mikachu@gmail.com> 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 <pws@csr.com> Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070
next prev parent reply other threads:[~2009-03-03 16:35 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-02-26 21:55 Mikael Magnusson
2009-02-26 22:36 ` Mikael Magnusson
2009-02-27 0:48 ` Mikael Magnusson
2009-03-03 12:12 ` Peter Stephenson
2009-03-03 14:43 ` Mikael Magnusson
2009-03-03 16:35 ` Peter Stephenson [this message]
2009-03-03 16:51 ` Mikael Magnusson
2009-03-03 16:55 ` Peter Stephenson
2009-03-03 17:00 ` Mikael Magnusson
2009-11-03 18:52 ` Mikael Magnusson
2009-11-03 18:55 ` [PATCH 1/4] attr: add -h option to operate on symlinks without dereferencing Mikael Magnusson
2009-11-04 10:48 ` Peter Stephenson
2009-11-04 11:01 ` Mikael Magnusson
2009-11-04 11:36 ` Peter Stephenson
2010-09-12 11:12 ` Mikael Magnusson
2009-11-03 18:56 ` [PATCH 2/4] attr: Make zlistattr return an array, zdelattr take several attrs Mikael Magnusson
2009-11-05 6:51 ` [PATCH 2/4] attr: Make zlistattr return an array, zdelattr takeseveral attrs Jun T.
2009-11-05 9:48 ` Mikael Magnusson
2009-11-03 18:57 ` [PATCH 3/4] attr: dynamically allocate memory for attributes Mikael Magnusson
2009-11-03 18:57 ` [PATCH 4/4] attr: Use descriptive variables for argv and allow setting values with embedded nuls Mikael Magnusson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20090303163526.533995be@news01 \
--to=pws@csr.com \
--cc=zsh-workers@sunsite.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).