2 * ##/%% variable matching code ripped out of ash shell for code sharing
4 * This code is derived from software contributed to Berkeley by
7 * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
9 * Copyright (c) 1989, 1991, 1993, 1994
10 * The Regents of the University of California. All rights reserved.
12 * Copyright (c) 1997-2005 Herbert Xu <herbert@gondor.apana.org.au>
13 * was re-ported from NetBSD and debianized.
27 #define pmatch(a, b) !fnmatch((a), (b), 0)
29 char *scanleft(char *string, char *pattern, bool match_at_left)
44 match = pmatch(pattern, s);
56 char *scanright(char *string, char *pattern, bool match_at_left)
59 char *loc = string + strlen(string);
61 while (loc >= string) {
71 match = pmatch(pattern, s);
84 int main(int argc, char *argv[])
96 "Usage: match <test> [test...]\n\n"
97 "Where a <test> is the form: <string><op><match>\n"
98 "This is to test the shell ${var#val} expression type.\n\n"
99 "e.g. `match 'abc#a*'` -> bc"
104 for (i = 1; i < argc; ++i) {
108 printf("'%s': ", argv[i]);
110 string = strdup(argv[i]);
111 off = strcspn(string, "#%");
113 printf("invalid format\n");
118 scan = pick_scan(op[0], op[1], &match_at_left);
121 op[1] = '\0', ++pattern;
124 loc = scan(string, pattern, match_at_left);
127 printf("'%s'\n", loc);
130 printf("'%s'\n", string);