From 0991b04f695deac9b9349613e007d4a2aa70f8f7 Mon Sep 17 00:00:00 2001 From: Rick Bird Date: Fri, 25 Mar 2011 14:12:24 -0400 Subject: [PATCH] PennMUSH Incorporation. 182p2 * regraballi() couldn't use its output seperator argument. Reported by Jules. [SW] --- src/conf.c | 2 +- src/function.c | 2 +- src/funstr.c | 118 +++++++++++++++++++++++++++++-------------------- 3 files changed, 73 insertions(+), 49 deletions(-) diff --git a/src/conf.c b/src/conf.c index d6d2e06..ae209b2 100644 --- a/src/conf.c +++ b/src/conf.c @@ -1357,7 +1357,7 @@ config_file_startup(const char *conf, int restrictions) if (!cp->overridden) { do_rawlog(LT_ERR, T - ("CONFIG: local directive '%s' missing from cnf file. using default value."), + ("CONFIG: local directive '%s' missing from cnf file. Using default value."), cp->name); } } diff --git a/src/function.c b/src/function.c index 7058860..6a3a4da 100644 --- a/src/function.c +++ b/src/function.c @@ -583,7 +583,7 @@ FUNTAB flist[] = { {"REGMATCHI", fun_regmatch, 2, 3, FN_REG}, {"REGRAB", fun_regrab, 2, 4, FN_REG}, {"REGRABALL", fun_regrab, 2, 4, FN_REG}, - {"REGRABALLI", fun_regrab, 2, 3, FN_REG}, + {"REGRABALLI", fun_regrab, 2, 4, FN_REG}, {"REGRABI", fun_regrab, 2, 3, FN_REG}, {"REGREP", fun_regrep, 3, 3, FN_REG}, {"REGREPI", fun_regrep, 3, 3, FN_REG}, diff --git a/src/funstr.c b/src/funstr.c index afe91a9..5fe9cfe 100644 --- a/src/funstr.c +++ b/src/funstr.c @@ -665,70 +665,94 @@ FUNCTION(fun_tr) char charmap[256]; char instr[BUFFER_LEN], outstr[BUFFER_LEN]; - char rawstr[BUFFER_LEN]; char *ip, *op; size_t i, len; + unsigned char cur, dest; char *c; ansi_string *as; - /* No ansi allowed in find or replace lists */ - c = remove_markup(args[1], &len); - memcpy(rawstr, c, len); - - /* do length checks first */ - + /* Initialize */ for (i = 0; i < 256; i++) { charmap[i] = (char) i; } +#define goodchr(x) (isprint(x) || (x == '\n')) + /* Convert ranges in input string, and check that + * we don't receive a nonprinting char such as + * beep() */ ip = instr; - op = outstr; - - for (i = 0; i < len; i++) { - safe_chr(rawstr[i], instr, &ip); - /* Handle a range of characters */ - if (i != len - 1 && rawstr[i + 1] == '-' && i != len - 2) { - int dir, sentinel, cur; - - if (rawstr[i] < rawstr[i + 2]) - dir = 1; - else - dir = -1; - - sentinel = rawstr[i + 2] + dir; - cur = rawstr[i] + dir; - - while (cur != sentinel) { - safe_chr((char) cur, instr, &ip); - cur += dir; + c = remove_markup(args[1], NULL); + while (*c) { + cur = (unsigned char) *c; + if (!goodchr(cur)) { + safe_str(T("#-1 TR CANNOT ACCEPT NONPRINTING CHARS"), buff, bp); + return; + } + /* Tack it onto the string */ + /* Do we have a range? */ + if (*(c + 1) && *(c + 1) == '-' && *(c + 2)) { + dest = (unsigned char) *(c + 2); + if (!goodchr(dest)) { + safe_str(T("#-1 TR CANNOT ACCEPT NONPRINTING CHARS"), buff, bp); + return; + } + if (dest > cur) { + for (; cur <= dest; cur++) { + if (goodchr(cur)) + safe_chr(cur, instr, &ip); + } + } else { + for (; cur >= dest; cur--) { + if (goodchr(cur)) + safe_chr(cur, instr, &ip); + } } - i += 2; + c += 3; + } else { + safe_chr(cur, instr, &ip); + c++; } } + *ip = '\0'; - c = remove_markup(args[2], &len); - memcpy(rawstr, c, len); - for (i = 0; i < len; i++) { - safe_chr(rawstr[i], outstr, &op); - /* Handle a range of characters */ - if (i != len - 1 && rawstr[i + 1] == '-' && i != len - 2) { - int dir, sentinel, cur; - - if (rawstr[i] < rawstr[i + 2]) - dir = 1; - else - dir = -1; - - sentinel = rawstr[i + 2] + dir; - cur = rawstr[i] + dir; - - while (cur != sentinel) { - safe_chr((char) cur, outstr, &op); - cur += dir; + /* Convert ranges in output string, and check that + * we don't receive a nonprinting char such as + * beep() */ + op = outstr; + c = remove_markup(args[2], NULL); + while (*c) { + cur = (unsigned char) *c; + if (!goodchr(cur)) { + safe_str(T("#-1 TR CANNOT ACCEPT NONPRINTING CHARS"), buff, bp); + return; + } + /* Tack it onto the string */ + /* Do we have a range? */ + if (*(c + 1) && *(c + 1) == '-' && *(c + 2)) { + dest = (unsigned char) *(c + 2); + if (!goodchr(dest)) { + safe_str(T("#-1 TR CANNOT ACCEPT NONPRINTING CHARS"), buff, bp); + return; + } + if (dest > cur) { + for (; cur <= dest; cur++) { + if (goodchr(cur)) + safe_chr(cur, outstr, &op); + } + } else { + for (; cur >= dest; cur--) { + if (goodchr(cur)) + safe_chr(cur, outstr, &op); + } } - i += 2; + c += 3; + } else { + safe_chr(cur, outstr, &op); + c++; } } + *op = '\0'; +#undef goodchr if ((ip - instr) != (op - outstr)) { safe_str(T("#-1 STRING LENGTHS MUST BE EQUAL"), buff, bp); -- 2.30.2