From 25965a249435a3fda795422cc61caf161580d441 Mon Sep 17 00:00:00 2001 From: Jakob Kaivo Date: Fri, 2 Aug 2019 21:39:28 -0400 Subject: check against yesexpr instead of hardcoding "yes" and "y" --- rm.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'rm.c') diff --git a/rm.c b/rm.c index 20d0225..e54793d 100644 --- a/rm.c +++ b/rm.c @@ -27,9 +27,11 @@ #include #include #include +#include +#include +#include #include #include -#include #include #include @@ -43,6 +45,9 @@ static int retval = 0; static int rm_prompt(const char *p) { + static regex_t yesre = { 0 }; + static int compiled = 0; + if (mode == FORCE) { return 1; } @@ -51,13 +56,17 @@ static int rm_prompt(const char *p) return 1; } - fprintf(stderr, "remove %s? ", p); + fprintf(stderr, "rm: %s? ", p); char buf[MAX_CANON]; fgets(buf, sizeof(buf), stdin); - /* TODO: use yesexpr */ - if (!strcasecmp("yes\n", buf) || !(strcasecmp("y\n", buf))) { + if (!compiled) { + char *yesexpr = nl_langinfo(YESEXPR); + regcomp(&yesre, yesexpr, REG_EXTENDED | REG_ICASE | REG_NOSUB); + } + + if (regexec(&yesre, buf, 0, NULL, 0) == 0) { return 1; } @@ -93,6 +102,8 @@ int rm(const char *p, const struct stat *st, int typeflag, struct FTW *f) int main(int argc, char **argv) { + setlocale(LC_ALL, ""); + int c; while ((c = getopt(argc, argv, "fiRr")) != -1) { switch (c) { -- cgit v1.2.1