aboutsummaryrefslogtreecommitdiffstats
path: root/glob.txi
blob: c2a27bb1dd5b6aca75cb82d4471709cea05ae95e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
@code{(require 'filename)} or @code{(require 'glob)}
@ftindex filename
@ftindex glob


@defun filename:match?? pattern
@defunx filename:match-ci?? pattern

Returns a predicate which returns a non-false value if its string argument
matches (the string) @var{pattern}, false otherwise.  Filename matching
is like
@cindex glob
@dfn{glob} expansion described the bash manpage, except that names
@cindex glob
beginning with @samp{.} are matched and @samp{/} characters are not
treated specially.

These functions interpret the following characters specially in
@var{pattern} strings:
@table @samp
@item *
Matches any string, including the null string.
@item ?
Matches any single character.
@item [@dots{}]
Matches any one of the enclosed characters.  A pair of characters
separated by a minus sign (-) denotes a range; any character lexically
between those two characters, inclusive, is matched.  If the first
character following the @samp{[} is a @samp{!} or a @samp{^} then any
character not enclosed is matched.  A @samp{-} or @samp{]} may be
matched by including it as the first or last character in the set.
@end table
@end defun


@defun filename:substitute?? pattern template
@defunx filename:substitute-ci?? pattern template

Returns a function transforming a single string argument according to
glob patterns @var{pattern} and @var{template}.  @var{pattern} and
@var{template} must have the same number of wildcard specifications,
which need not be identical.  @var{pattern} and @var{template} may have
a different number of literal sections. If an argument to the function
matches @var{pattern} in the sense of @code{filename:match??} then it
returns a copy of @var{template} in which each wildcard specification is
replaced by the part of the argument matched by the corresponding
wildcard specification in @var{pattern}.  A @code{*} wildcard matches
the longest leftmost string possible.  If the argument does not match
@var{pattern} then false is returned.

@var{template} may be a function accepting the same number of string
arguments as there are wildcard specifications in @var{pattern}.  In
the case of a match the result of applying @var{template} to a list
of the substrings matched by wildcard specifications will be returned,
otherwise @var{template} will not be called and @code{#f} will be returned.
@end defun

@example
((filename:substitute?? "scm_[0-9]*.html" "scm5c4_??.htm")
 "scm_10.html")
@result{} "scm5c4_10.htm"
((filename:substitute?? "??" "beg?mid?end") "AZ")
@result{} "begAmidZend"
((filename:substitute?? "*na*" "?NA?") "banana")
@result{} "banaNA"
((filename:substitute?? "?*?" (lambda (s1 s2 s3) (string-append s3 s1)))
 "ABZ")
@result{} "ZA"
@end example


@defun replace-suffix str old new

@var{str} can be a string or a list of strings.  Returns a new string
(or strings) similar to @code{str} but with the suffix string @var{old}
removed and the suffix string @var{new} appended.  If the end of
@var{str} does not match @var{old}, an error is signaled.
@end defun

@example
(replace-suffix "/usr/local/lib/slib/batch.scm" ".scm" ".c")
@result{} "/usr/local/lib/slib/batch.c"
@end example


@defun call-with-tmpnam proc k


@defunx call-with-tmpnam proc
Calls @var{proc} with @var{k} arguments, strings returned by successive calls to
@code{tmpnam}.
If @var{proc} returns, then any files named by the arguments to @var{proc} are
deleted automatically and the value(s) yielded by the @var{proc} is(are)
returned.  @var{k} may be ommited, in which case it defaults to @code{1}.


@defunx call-with-tmpnam proc suffix1 @dots{}
Calls @var{proc} with strings returned by successive calls to @code{tmpnam},
each with the corresponding @var{suffix} string appended.
If @var{proc} returns, then any files named by the arguments to @var{proc} are
deleted automatically and the value(s) yielded by the @var{proc} is(are)
returned.
@end defun