2 * ##/%% variable matching code ripped out of ash shell for code sharing
4 * Copyright (c) 1989, 1991, 1993, 1994
5 * The Regents of the University of California. All rights reserved.
7 * Copyright (c) 1997-2005 Herbert Xu <herbert@gondor.apana.org.au>
8 * was re-ported from NetBSD and debianized.
10 * This code is derived from software contributed to Berkeley by
13 * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
15 * Original BSD copyright notice is retained at the end of this file.
29 #define pmatch(a, b) !fnmatch((a), (b), 0)
31 char *scanleft(char *string, char *pattern, bool zero)
46 match = pmatch(pattern, s);
58 char *scanright(char *string, char *pattern, bool zero)
61 char *loc = string + strlen(string);
63 while (loc >= string) {
73 match = pmatch(pattern, s);
86 int main(int argc, char *argv[])
98 "Usage: match <test> [test...]\n\n"
99 "Where a <test> is the form: <string><op><match>\n"
100 "This is to test the shell ${var#val} expression type.\n\n"
101 "e.g. `match 'abc#a*'` -> bc"
106 for (i = 1; i < argc; ++i) {
110 printf("'%s': ", argv[i]);
112 string = strdup(argv[i]);
113 off = strcspn(string, "#%");
115 printf("invalid format\n");
120 scan = pick_scan(op[0], op[1], &zero);
123 op[1] = '\0', ++pattern;
126 loc = scan(string, pattern, zero);
129 printf("'%s'\n", loc);
132 printf("'%s'\n", string);