From 9f6cba5c0370aee2f9803abbc35ab7e67f57ee84 Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Tue, 1 Nov 2016 06:58:18 +0100 Subject: globbing supports character classes now and ^EN string building construct to escape glob patterns * globbing is fnmatch(3) compatible, now on every supported platform. * which means that escaping of glob patterns is possible now. ^ENq has been introduced to ease this task. * This finally allows you to pass unmodified filenames to EB. Previously it was impossible to open file names containing glob wildcards. * this was achieved by moving from GPattern to GRegex as the underlying implementation. * The glob pattern is converted to a regular expression before being compiled to a GRegex. This turned out to be trickier than anticipated (~140 lines of code) and has a runtime penalty of course (complexity is O(2*n) over the pattern length). It is IMHO still better than the alternatives, like importing external code from libiberty, which is potentially non-cross-platform. * Using GRegex also opens the potential of supporting brace "expansions" later in the form of glob pattern constructs (they won't actually expand but match alternatives). * is_glob_pattern() has been simplified and moved to Globber::is_pattern(). It makes sense to reuse the Globber class namespace instead of using plain functions for functions working on glob patterns. * The documentation has a new subsection on glob patterns now. * Testsuite extended with glob pattern test cases --- doc/sciteco.7.template | 58 ++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 54 insertions(+), 4 deletions(-) (limited to 'doc') diff --git a/doc/sciteco.7.template b/doc/sciteco.7.template index 6ed89db..9bf0cc0 100644 --- a/doc/sciteco.7.template +++ b/doc/sciteco.7.template @@ -1466,7 +1466,7 @@ Expands to the string contents of the Q-Register specified by \fIq\fP. .TP .BI ^E@ q -Expands to the quoted string contents of the Q-Register +Expands to the shell-quoted string contents of the Q-Register specified by \fIq\fP. The quoting will be such that an UNIX98 \(lq/bin/sh\(rq will interpret the quoted string like the original contents of @@ -1475,6 +1475,14 @@ This is useful when generating UNIX shell code or when passing registers with unknown contents as parameters to external commands using the \fBEC\fP command. .TP +.BI ^EN q +Expands to the string contents of the Q-Register specified +by \fIq\fP but with glob pattern wildcards escaped. +This is useful for commands accepting glob patterns to +pass file names which will not be interpreted further +(e.g. if the file name may contain \(lq*\(rq or other +special characters). +.TP .BI ^E c All remaining \fB^E\fP combinations are passed down unmodified. @@ -1624,15 +1632,57 @@ user's\fP home directory using the value of the \(lq$HOME\(rq environment register. Thus the \(lq~\fIusername\fP\(rq syntax is \fBnot\fP supported. .LP -Last but not least, some commands accept glob patterns -in their file name arguments to refer to multiple files at once -(see \fBEN\fP command). There is special immediate editing command support for file and directory path arguments (e.g. tab-completions and specialized rub-out/rub-in commands). These are documented in the section .BR "COMMANDLINE EDITING" . . +.SS Glob Patterns +. +Some commands accept glob patterns +in their file name arguments to perform pattern matching +on arbitrary strings or to work with multiple existing files +(see \fBEN\fP and \fBEB\fP commands). +\*(ST glob patterns mimic the POSIX +.BR fnmatch (3) +syntax, but work uniformly across all platforms. +The following wildcard constructs are supported: +.TP +.B * +Matches an arbitary number of characters or no character +at all. +.TP +.B ? +Matches a single arbitrary character. +.TP +.BI [ set ] +Matches one character in the given character \fIset\fP. +For instance \(lq[ch]\(rq matches both \(lqc\(rq and \(lqh\(rq. +A hyphen may be used to specify character ranges as in +\(lq[0-9]\(rq to match all decimal digits. +Within a character class, the \(lq*\(rq and \(lq?\(rq wildcards +have no special meanings and represent their corresponding +characters. +To include a hypen in the \fIset\fP, write it first or last. +To include a closing bracket in the \fIset\fP, write it first, +as in \(lq[]ch]\(rq. +.TP +.BI [^ set ] +.TQ +.BI [! set ] +Matches one character which is \fBnot\fP in the given character +\fIset\fP. +Otherwise behaves exactly like \fB[\fIset\fB]\fR. +.LP +All other characters match themselves. +Brackets can be used to escape wildcard characters. +For instance, \(lq[*]\(rq may be used to match a literal asterisk. +To facilitate passing filenames verbatim to commands +accepting glob patterns, there is the \fB^EN\fIq\fR string +building construct which automatically escapes glob pattern +wildcards. +. . .SH FLOW CONTROL . -- cgit v1.2.3