1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-10-27 04:40:59 +01:00

Mikael Magnusson: 26670: add zsh/attr module

This commit is contained in:
Peter Stephenson 2009-03-03 15:04:15 +00:00
parent 29233548ae
commit d58e5061ad
10 changed files with 270 additions and 4 deletions

View file

@ -1,5 +1,11 @@
2009-03-03 Peter Stephenson <pws@csr.com> 2009-03-03 Peter Stephenson <pws@csr.com>
* Mikael Magnusson: 26670: configure.ac,
Completion/Command/Zsh/.distfiles, Completion/Zsh/Command/_zattr,
Doc/Makefile.in, Doc/Zsh/.distfiles, Doc/Zsh/mod_attr.yo,
Src/Modules/.distfiles, Src/Modules/attr.c, Src/Modules/attr.mdd:
add module to handle Linux extended file attributes.
* Jun T.: 26667: Doc/Zsh/prompt.yo: separate out parentheses. * Jun T.: 26667: Doc/Zsh/prompt.yo: separate out parentheses.
2009-03-02 Barton E. Schaefer <schaefer@zsh.org> 2009-03-02 Barton E. Schaefer <schaefer@zsh.org>
@ -11298,5 +11304,5 @@
***************************************************** *****************************************************
* This is used by the shell to define $ZSH_PATCHLEVEL * This is used by the shell to define $ZSH_PATCHLEVEL
* $Revision: 1.4591 $ * $Revision: 1.4592 $
***************************************************** *****************************************************

View file

@ -37,6 +37,7 @@ _unsetopt
_vared _vared
_wait _wait
_which _which
_zattr
_zcompile _zcompile
_zed _zed
_zftp _zftp

View file

@ -0,0 +1,34 @@
#compdef zgetattr zsetattr zdelattr zlistattr
local state line expl ret=1 REPLY
local -a args privs
case $service in
zgetattr)
_arguments \
'1:file:_files' \
'2:attribute:->attrs' \
'3:parameter'
;;
zsetattr)
_arguments \
'1:file:_files' \
'2:attribute:->attrs' \
'3:value'
;;
zdelattr)
_arguments \
'1:file:_files' \
'2:attribute:->attrs'
;;
zlistattr)
_arguments \
'1:file:_files' \
'2:parameter'
;;
esac
if [[ $state = attrs ]]; then
zlistattr $line[1] REPLY
_wanted attrs expl 'attribute' compadd ${(0)REPLY}
fi

View file

@ -55,7 +55,7 @@ zshall.1
YODLDOC = $(MAN) texi YODLDOC = $(MAN) texi
MODDOCSRC = \ MODDOCSRC = \
Zsh/mod_cap.yo Zsh/mod_clone.yo \ Zsh/mod_attr.yo Zsh/mod_cap.yo Zsh/mod_clone.yo \
Zsh/mod_compctl.yo Zsh/mod_complete.yo Zsh/mod_complist.yo \ Zsh/mod_compctl.yo Zsh/mod_complete.yo Zsh/mod_complist.yo \
Zsh/mod_computil.yo Zsh/mod_curses.yo \ Zsh/mod_computil.yo Zsh/mod_curses.yo \
Zsh/mod_datetime.yo Zsh/mod_deltochar.yo \ Zsh/mod_datetime.yo Zsh/mod_deltochar.yo \

View file

@ -5,7 +5,8 @@ DISTFILES_SRC='
contrib.yo exec.yo expn.yo filelist.yo contrib.yo exec.yo expn.yo filelist.yo
files.yo func.yo grammar.yo index.yo files.yo func.yo grammar.yo index.yo
intro.yo invoke.yo jobs.yo manmodmenu.yo intro.yo invoke.yo jobs.yo manmodmenu.yo
manual.yo metafaq.yo mod_cap.yo mod_clone.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_compctl.yo mod_complete.yo mod_complist.yo mod_computil.yo
mod_curses.yo mod_datetime.yo mod_deltochar.yo mod_example.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_files.yo mod_langinfo.yo modlist.yo mod_mapfile.yo

34
Doc/Zsh/mod_attr.yo Normal file
View file

@ -0,0 +1,34 @@
COMMENT(!MOD!zsh/attr
Builtins for manipulating extended attributes (xattr).
!MOD!)
The tt(zsh/attr) module is used for manipulating extended attributes.
The builtins in this module are:
startitem()
findex(zgetattr)
cindex(extended attributes, xattr, getting from files)
item(tt(zgetattr) var(filename) var(attribute) [ var(parameter) ])(
Get the extended attribute var(attribute) from the specified
var(filename). If the optional argument var(parameter) is given, the
attribute is set on that parameter instead of being printed to stdout.
)
findex(zsetattr)
cindex(extended attributes, xattr, setting on files)
item(tt(zsetattr) var(filename) var(attribute) var(value))(
Set the extended attribute var(attribute) on the specified
var(filename) to var(value).
)
findex(zdelattr)
cindex(extended attributes, xattr, removing, deleting)
item(tt(zdelattr) var(filename) var(attribute))(
Remove the extended attribute var(attribute) from the specified
var(filename).
)
findex(zlistattr)
cindex(extended attributes, xattr, listing)
item(tt(zlistattr) var(filename) [ var(parameter) ])(
List the extended attributes currently set on the specified
var(filename). If the optional argument var(parameter) is given, the
list of attributes is set on that parameter instead of being printed to stdout.
)
enditem()

View file

@ -2,6 +2,8 @@ DISTFILES_SRC='
.cvsignore .cvsignore
.distfiles .distfiles
.exrc .exrc
attr.mdd
attr.c
cap.mdd cap.mdd
cap.c cap.c
clone.mdd clone.mdd

174
Src/Modules/attr.c Normal file
View file

@ -0,0 +1,174 @@
/*
* attr.c - extended attributes (xattr) manipulation
*
* This file is part of zsh, the Z shell.
*
* Copyright (c) 2009 Mikael Magnusson
* 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 Mikael Magnusson 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 Andrew Main and the Zsh Development Group have been advised of
* the possibility of such damage.
*
* Mikael Magnusson 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 Mikael Magnusson and the
* Zsh Development Group have no obligation to provide maintenance,
* support, updates, enhancements, or modifications.
*
*/
#include "attr.mdh"
#include "attr.pro"
#include <sys/types.h>
#include <sys/xattr.h>
static int
bin_getattr(char *nam, char **argv, UNUSED(Options ops), UNUSED(int func))
{
int ret = 0;
int len;
char value[256];
unmetafy(*argv, NULL);
unmetafy(*(argv+1), NULL);
if (listxattr(*argv, NULL, 0) > 0) {
if (0 < (len = getxattr(*argv, *(argv+1), value, 255))) {
if (len < 256) {
value[len] = '\0';
if (*(argv+2))
setsparam(*(argv+2), metafy(value, len, META_DUP));
else
printf("%s\n", value);
}
} else {
zwarnnam(nam, "%s: %e", metafy(*argv, -1, META_NOALLOC), errno);
ret = 1;
}
}
return ret;
}
static int
bin_setattr(char *nam, char **argv, UNUSED(Options ops), UNUSED(int func))
{
int ret = 0;
unmetafy(*argv, NULL);
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);
ret = 1;
}
return ret;
}
static int
bin_delattr(char *nam, char **argv, UNUSED(Options ops), UNUSED(int func))
{
int ret = 0;
unmetafy(*argv, NULL);
unmetafy(*(argv+1), NULL);
if (removexattr(*argv, *(argv+1))) {
zwarnnam(nam, "%s: %e", metafy(*argv, -1, 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;
char value[256];
unmetafy(*argv, NULL);
if (0 < (len = listxattr(*argv, value, 256))) {
if (len < 256) {
char *p = value;
if (*(argv+1))
setsparam(*(argv+1), metafy(value, len, META_DUP));
else while (p < &value[len]) {
printf("%s\n", p);
p += strlen(p) + 1;
}
}
} else {
zwarnnam(nam, "%s: %e", metafy(*argv, -1, META_NOALLOC), errno);
ret = 1;
}
return ret;
}
/* module paraphernalia */
static struct builtin bintab[] = {
BUILTIN("zgetattr", 0, bin_getattr, 2, 3, 0, NULL, NULL),
BUILTIN("zsetattr", 0, bin_setattr, 3, 3, 0, NULL, NULL),
BUILTIN("zdelattr", 0, bin_delattr, 2, 2, 0, NULL, NULL),
BUILTIN("zlistattr", 0, bin_listattr, 1, 2, 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_(UNUSED(Module m))
{
return 0;
}
/**/
int
cleanup_(Module m)
{
return setfeatureenables(m, &module_features, NULL);
}
/**/
int
finish_(UNUSED(Module m))
{
return 0;
}

12
Src/Modules/attr.mdd Normal file
View file

@ -0,0 +1,12 @@
name=zsh/attr
link='if test "x$ac_cv_func_getxattr" = xyes && test "x$ac_cv_header_sys_xattr_h" = xyes; then
echo dynamic
else
echo no
fi
'
load=no
autofeatures="b:zgetattr b:zsetattr b:zdelattr"
objects="attr.o"

View file

@ -858,6 +858,8 @@ if test x$gdbm != xno; then
AC_CHECK_LIB(gdbm, gdbm_open) AC_CHECK_LIB(gdbm, gdbm_open)
fi fi
AC_CHECK_HEADERS(sys/xattr.h)
dnl -------------- dnl --------------
dnl CHECK TYPEDEFS dnl CHECK TYPEDEFS
dnl -------------- dnl --------------
@ -1155,7 +1157,7 @@ AC_CHECK_FUNCS(strftime strptime mktime timelocal \
grantpt unlockpt ptsname \ grantpt unlockpt ptsname \
htons ntohs \ htons ntohs \
regcomp regexec regerror regfree \ regcomp regexec regerror regfree \
gdbm_open) gdbm_open getxattr)
AC_FUNC_STRCOLL AC_FUNC_STRCOLL
if test x$enable_cap = xyes; then if test x$enable_cap = xyes; then