diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2009-03-03 20:01:02 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2009-03-03 20:01:02 +0000 |
commit | 7e32d8837264f3c4f2103da7b0027e3dad040339 (patch) | |
tree | 0983193b780f264a45378129918c3fb7c1d28f2b /bin/ksh | |
parent | 377d2887ff99ee8607be820565642c8b512fde48 (diff) |
Add POSIX character class support ([:alpha:] and friends) to ksh globbing.
OK deraadt@ krw@ jmc@ sobrado@
Diffstat (limited to 'bin/ksh')
-rw-r--r-- | bin/ksh/Makefile | 4 | ||||
-rw-r--r-- | bin/ksh/ksh.1 | 9 | ||||
-rw-r--r-- | bin/ksh/misc.c | 53 | ||||
-rw-r--r-- | bin/ksh/sh.1 | 9 |
4 files changed, 58 insertions, 17 deletions
diff --git a/bin/ksh/Makefile b/bin/ksh/Makefile index 93b9f6a468d..319f077fbb7 100644 --- a/bin/ksh/Makefile +++ b/bin/ksh/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.26 2008/01/12 22:36:34 miod Exp $ +# $OpenBSD: Makefile,v 1.27 2009/03/03 20:01:01 millert Exp $ PROG= ksh SRCS= alloc.c c_ksh.c c_sh.c c_test.c c_ulimit.c edit.c emacs.c eval.c \ @@ -7,7 +7,7 @@ SRCS= alloc.c c_ksh.c c_sh.c c_test.c c_ulimit.c edit.c emacs.c eval.c \ version.c vi.c DEFS= -Wall -CFLAGS+=${DEFS} -I. -I${.CURDIR} +CFLAGS+=${DEFS} -I. -I${.CURDIR} -I${.CURDIR}/../../lib/libc/gen MAN= ksh.1 sh.1 CLEANFILES+= emacs.out diff --git a/bin/ksh/ksh.1 b/bin/ksh/ksh.1 index 5193ae6691f..d7d53ee3cf6 100644 --- a/bin/ksh/ksh.1 +++ b/bin/ksh/ksh.1 @@ -1,8 +1,8 @@ -.\" $OpenBSD: ksh.1,v 1.125 2009/02/07 23:15:28 jmc Exp $ +.\" $OpenBSD: ksh.1,v 1.126 2009/03/03 20:01:01 millert Exp $ .\" .\" Public Domain .\" -.Dd $Mdocdate: February 7 2009 $ +.Dd $Mdocdate: March 3 2009 $ .Dt KSH 1 .Os .Sh NAME @@ -1977,10 +1977,6 @@ If the option is set, any directories that result from file name generation are marked with a trailing .Ql / . -.Pp -The POSIX character classes (i.e.\& -.Pf [: Ns Ar class-name Ns :] -inside a [..] expression) are not yet implemented. .Ss Input/output redirection When a command is executed, its standard input, standard output, and standard error (file descriptors 0, 1, and 2, respectively) are normally inherited from @@ -5546,6 +5542,7 @@ Privileged shell profile. .Xr vi 1 , .Xr shells 5 , .Xr environ 7 , +.Xr re_format 7 , .Xr script 7 .Rs .%A Morris Bolsky diff --git a/bin/ksh/misc.c b/bin/ksh/misc.c index 874a88e89ff..76b0cec98df 100644 --- a/bin/ksh/misc.c +++ b/bin/ksh/misc.c @@ -1,12 +1,13 @@ -/* $OpenBSD: misc.c,v 1.35 2009/01/17 22:06:44 millert Exp $ */ +/* $OpenBSD: misc.c,v 1.36 2009/03/03 20:01:01 millert Exp $ */ /* * Miscellaneous functions */ #include "sh.h" -#include <ctype.h> /* ??? Removing this changes generated code! */ +#include <ctype.h> #include <sys/param.h> /* for MAXPATHLEN */ +#include "charclass.h" short ctypes [UCHAR_MAX+1]; /* type bits for unsigned char */ @@ -703,15 +704,61 @@ do_gmatch(const unsigned char *s, const unsigned char *se, return s == se; } +static int +posix_cclass(const unsigned char *pattern, int test, const unsigned char **ep) +{ + struct cclass *cc; + const unsigned char *colon; + size_t len; + int rval = 0; + + if ((colon = strchr(pattern, ':')) == NULL || colon[1] != MAGIC) { + *ep = pattern - 2; + return -1; + } + *ep = colon + 3; /* skip MAGIC */ + len = (size_t)(colon - pattern); + + for (cc = cclasses; cc->name != NULL; cc++) { + if (!strncmp(pattern, cc->name, len) && cc->name[len] == '\0') { + if (cc->isctype(test)) + rval = 1; + break; + } + } + if (cc->name == NULL) { + rval = -2; /* invalid character class */ + } + return rval; +} + static const unsigned char * cclass(const unsigned char *p, int sub) { - int c, d, not, found = 0; + int c, d, rv, not, found = 0; const unsigned char *orig_p = p; if ((not = (ISMAGIC(*p) && *++p == NOT))) p++; do { + /* check for POSIX character class (e.g. [[:alpha:]]) */ + if ((p[0] == MAGIC && p[1] == '[' && p[2] == ':') || + (p[0] == '[' && p[1] == ':')) { + do { + const char *pp = p + (*p == MAGIC) + 2; + rv = posix_cclass(pp, sub, &p); + switch (rv) { + case 1: + found = 1; + break; + case -2: + return NULL; + } + } while (rv != -1 && p[0] == MAGIC && p[1] == '[' && p[2] == ':'); + if (p[0] == MAGIC && p[1] == ']') + break; + } + c = *p++; if (ISMAGIC(c)) { c = *p++; diff --git a/bin/ksh/sh.1 b/bin/ksh/sh.1 index f8ecab2c751..810c8a02257 100644 --- a/bin/ksh/sh.1 +++ b/bin/ksh/sh.1 @@ -1,8 +1,8 @@ -.\" $OpenBSD: sh.1,v 1.79 2009/02/07 23:15:28 jmc Exp $ +.\" $OpenBSD: sh.1,v 1.80 2009/03/03 20:01:01 millert Exp $ .\" .\" Public Domain .\" -.Dd $Mdocdate: February 7 2009 $ +.Dd $Mdocdate: March 3 2009 $ .Dt SH 1 .Os .Sh NAME @@ -1461,10 +1461,6 @@ If the option is set, any directories that result from file name generation are marked with a trailing .Ql / . -.Pp -The POSIX character classes (i.e.\& -.Pf [: Ns Ar class-name Ns :] -inside a [..] expression) are not yet implemented. .Ss Input/output redirection When a command is executed, its standard input, standard output, and standard error (file descriptors 0, 1, and 2, respectively) are normally inherited from @@ -3738,6 +3734,7 @@ Shell database. .Xr vi 1 , .Xr shells 5 , .Xr environ 7 , +.Xr re_format 7 , .Xr script 7 .Rs .%A Morris Bolsky |