• R/O
  • SSH
  • HTTPS

yash: Commit


Commit MetaInfo

Revision3922 (tree)
Time2018-11-25 14:25:44
Authormagicant

Log Message

Extract match_pattern function

Change Summary

Incremental Difference

--- yash/branches/double_bracket/exec.c (revision 3921)
+++ yash/branches/double_bracket/exec.c (revision 3922)
@@ -516,14 +516,8 @@
516516 if (pattern == NULL)
517517 goto fail;
518518
519- xfnmatch_T *xfnm = xfnm_compile(
520- pattern, XFNM_HEADONLY | XFNM_TAILONLY);
519+ bool match = match_pattern(word, pattern);
521520 free(pattern);
522- if (xfnm == NULL)
523- continue;
524-
525- bool match = (xfnm_wmatch(xfnm, word).start != (size_t) -1);
526- xfnm_free(xfnm);
527521 if (match) {
528522 if (ci->ci_commands != NULL) {
529523 exec_and_or_lists(ci->ci_commands, finally_exit);
--- yash/branches/double_bracket/xfnmatch.c (revision 3921)
+++ yash/branches/double_bracket/xfnmatch.c (revision 3922)
@@ -1,6 +1,6 @@
11 /* Yash: yet another shell */
22 /* xfnmatch.c: regex matching wrapper as a replacement for fnmatch */
3-/* (C) 2007-2012 magicant */
3+/* (C) 2007-2018 magicant */
44
55 /* This program is free software: you can redistribute it and/or modify
66 * it under the terms of the GNU General Public License as published by
@@ -732,6 +732,16 @@
732732 }
733733 }
734734
735+/* Tests if pattern matching expression `pattern' matches string `s'. */
736+bool match_pattern(const wchar_t *s, const wchar_t *pattern)
737+{
738+ xfnmatch_T *xfnm = xfnm_compile(pattern, XFNM_HEADONLY | XFNM_TAILONLY);
739+ if (xfnm == NULL)
740+ return false;
741+ bool match = (xfnm_wmatch(xfnm, s).start != (size_t) -1);
742+ xfnm_free(xfnm);
743+ return match;
744+}
735745
736746 #if YASH_ENABLE_TEST
737747
--- yash/branches/double_bracket/xfnmatch.h (revision 3921)
+++ yash/branches/double_bracket/xfnmatch.h (revision 3922)
@@ -1,6 +1,6 @@
11 /* Yash: yet another shell */
22 /* xfnmatch.h: regex matching wrapper as a replacement for fnmatch */
3-/* (C) 2007-2012 magicant */
3+/* (C) 2007-2018 magicant */
44
55 /* This program is free software: you can redistribute it and/or modify
66 * it under the terms of the GNU General Public License as published by
@@ -55,6 +55,8 @@
5555 __attribute__((malloc,warn_unused_result,nonnull));
5656 extern void xfnm_free(xfnmatch_T *xfnm);
5757
58+extern _Bool match_pattern(const wchar_t *s, const wchar_t *pattern)
59+ __attribute__((nonnull));
5860 #if YASH_ENABLE_TEST
5961 extern _Bool match_regex(const wchar_t *s, const wchar_t *regex)
6062 __attribute__((nonnull));
Show on old repository browser