diff --git a/Regex/Common.h b/Regex/Common.h index efb2eeff..55dbe44e 100644 --- a/Regex/Common.h +++ b/Regex/Common.h @@ -18,7 +18,7 @@ unsigned int U_CHAR_AT(Ptr p) noexcept { template T *OPERAND(T *p) noexcept { static_assert(sizeof(T) == 1, "Invalid Pointer Type"); - return p + NODE_SIZE; + return p + NODE_SIZE; } template diff --git a/Regex/Compile.cpp b/Regex/Compile.cpp index 8fc70c12..ac8ce1c0 100644 --- a/Regex/Compile.cpp +++ b/Regex/Compile.cpp @@ -15,6 +15,7 @@ #include #include #include +#include namespace { @@ -180,7 +181,7 @@ template uint8_t *emit_node(T op_code) noexcept { if (pContext.FirstPass) { - pContext.Reg_Size += NODE_SIZE; + pContext.Reg_Size += NODE_SIZE; return reinterpret_cast(1); } @@ -246,18 +247,18 @@ uint8_t *emit_special(Ch op_code, uint32_t test_val, size_t index) noexcept { switch (op_code) { case POS_BEHIND_OPEN: case NEG_BEHIND_OPEN: - pContext.Reg_Size += LENGTH_SIZE; // Length of the look-behind match - pContext.Reg_Size += NODE_SIZE; // Make room for the node + pContext.Reg_Size += LENGTH_SIZE; // Length of the look-behind match + pContext.Reg_Size += NODE_SIZE; // Make room for the node break; case TEST_COUNT: - pContext.Reg_Size += NEXT_PTR_SIZE; // Make room for a test value. + pContext.Reg_Size += NEXT_PTR_SIZE; // Make room for a test value. NEDIT_FALLTHROUGH(); case INC_COUNT: - pContext.Reg_Size += INDEX_SIZE; // Make room for an index value. + pContext.Reg_Size += INDEX_SIZE; // Make room for an index value. NEDIT_FALLTHROUGH(); default: - pContext.Reg_Size += NODE_SIZE; // Make room for the node. + pContext.Reg_Size += NODE_SIZE; // Make room for the node. } return reinterpret_cast(1); @@ -319,14 +320,14 @@ uint8_t *insert(uint8_t op, const uint8_t *insert_pos, uint32_t min, uint32_t ma if (pContext.FirstPass) { - size_t insert_size = NODE_SIZE; + size_t insert_size = NODE_SIZE; if (op == BRACE || op == LAZY_BRACE) { // Make room for the min and max values. - insert_size += (2 * NEXT_PTR_SIZE); + insert_size += (2 * NEXT_PTR_SIZE); } else if (op == INIT_COUNT) { // Make room for an index value. - insert_size += INDEX_SIZE; + insert_size += INDEX_SIZE; } pContext.Reg_Size += insert_size; @@ -1227,8 +1228,8 @@ uint8_t *piece(int *flag_param, len_range &range_param) { *flag_param = (min_max[0] > 0) ? (WORST | HAS_WIDTH) : WORST; if (range_local.lower >= 0) { if (min_max[1] != REG_INFINITY) { - range_param.lower = range_local.lower * min_max[0]; - range_param.upper = range_local.upper * min_max[1]; + range_param.lower = gsl::narrow(range_local.lower * min_max[0]); + range_param.upper = gsl::narrow(range_local.upper * min_max[1]); } else { range_param.lower = -1; // Not a fixed-size length range_param.upper = -1; @@ -1282,15 +1283,15 @@ uint8_t *piece(int *flag_param, len_range &range_param) { next = emit_node(NOTHING); // 2,3 - offset_tail(ret_val, NODE_SIZE, next); // 2 + offset_tail(ret_val, NODE_SIZE, next); // 2 tail(ret_val, next); // 3 insert(BRANCH, ret_val, 0UL, 0UL, 0); // 4,5 - tail(ret_val, ret_val + (2 * NODE_SIZE)); // 4 - offset_tail(ret_val, 3 * NODE_SIZE, ret_val); // 5 + tail(ret_val, ret_val + (2 * NODE_SIZE)); // 4 + offset_tail(ret_val, 3 * NODE_SIZE, ret_val); // 5 if (op_code == '+') { insert(NOTHING, ret_val, 0UL, 0UL, 0); // 6 - tail(ret_val, ret_val + (4 * NODE_SIZE)); // 6 + tail(ret_val, ret_val + (4 * NODE_SIZE)); // 6 } } else if (op_code == '*') { /* Node structure for (x)* construct. @@ -1302,8 +1303,8 @@ uint8_t *piece(int *flag_param, len_range &range_param) { */ insert(BRANCH, ret_val, 0UL, 0UL, 0); // 1,3 - offset_tail(ret_val, NODE_SIZE, emit_node(BACK)); // 2 - offset_tail(ret_val, NODE_SIZE, ret_val); // 1 + offset_tail(ret_val, NODE_SIZE, emit_node(BACK)); // 2 + offset_tail(ret_val, NODE_SIZE, ret_val); // 1 tail(ret_val, emit_node(BRANCH)); // 3 tail(ret_val, emit_node(NOTHING)); // 4 } else if (op_code == '+') { @@ -1336,11 +1337,11 @@ uint8_t *piece(int *flag_param, len_range &range_param) { next = emit_node(NOTHING); // 1,2,3 - offset_tail(ret_val, 2 * NODE_SIZE, next); // 1 - offset_tail(ret_val, NODE_SIZE, next); // 2 + offset_tail(ret_val, 2 * NODE_SIZE, next); // 1 + offset_tail(ret_val, NODE_SIZE, next); // 2 tail(ret_val, next); // 3 insert(BRANCH, ret_val, 0UL, 0UL, 0); // 4 - tail(ret_val, (ret_val + (2 * NODE_SIZE))); // 4 + tail(ret_val, (ret_val + (2 * NODE_SIZE))); // 4 } else if (op_code == '?') { /* Node structure for (x)? construct. @@ -1356,7 +1357,7 @@ uint8_t *piece(int *flag_param, len_range &range_param) { next = emit_node(NOTHING); // 2,3 tail(ret_val, next); // 2 - offset_tail(ret_val, NODE_SIZE, next); // 3 + offset_tail(ret_val, NODE_SIZE, next); // 3 } else if (op_code == '{' && min_max[0] == min_max[1]) { /* Node structure for (x){m}, (x){m}?, (x){m,m}, or (x){m,m}? constructs. * Note that minimal and maximal matching mean the same thing when we @@ -1400,13 +1401,13 @@ uint8_t *piece(int *flag_param, len_range &range_param) { insert(NOTHING, ret_val, 0UL, 0UL, pContext.Num_Braces); // 5 insert(BRANCH, ret_val, 0UL, 0UL, pContext.Num_Braces); // 3,4,8 tail(emit_node(BACK), ret_val); // 3 - tail(ret_val, ret_val + (2 * NODE_SIZE)); // 4 + tail(ret_val, ret_val + (2 * NODE_SIZE)); // 4 next = emit_node(NOTHING); // 5,6,7 - offset_tail(ret_val, NODE_SIZE, next); // 5 - offset_tail(ret_val, 2 * NODE_SIZE, next); // 6 - offset_tail(ret_val, 3 * NODE_SIZE, next); // 7 + offset_tail(ret_val, NODE_SIZE, next); // 5 + offset_tail(ret_val, 2 * NODE_SIZE, next); // 6 + offset_tail(ret_val, 3 * NODE_SIZE, next); // 7 next = insert(INIT_COUNT, ret_val, 0UL, 0UL, pContext.Num_Braces); // 8 @@ -1436,13 +1437,13 @@ uint8_t *piece(int *flag_param, len_range &range_param) { next = emit_node(NOTHING); // 5,6 - offset_tail(ret_val, NODE_SIZE, next); // 5 + offset_tail(ret_val, NODE_SIZE, next); // 5 tail(ret_val, next); // 6 insert(BRANCH, ret_val, 0UL, 0UL, 0); // 7,8 - tail(ret_val, ret_val + (2 * NODE_SIZE)); // 7 - offset_tail(ret_val, 3 * NODE_SIZE, ret_val); // 8 + tail(ret_val, ret_val + (2 * NODE_SIZE)); // 7 + offset_tail(ret_val, 3 * NODE_SIZE, ret_val); // 8 insert(INIT_COUNT, ret_val, 0UL, 0UL, pContext.Num_Braces); // 9 - tail(ret_val, ret_val + INDEX_SIZE + (4 * NODE_SIZE)); // 9 + tail(ret_val, ret_val + INDEX_SIZE + (4 * NODE_SIZE)); // 9 } else { /* Node structure for (x){m,n}? construct. @@ -1473,13 +1474,13 @@ uint8_t *piece(int *flag_param, len_range &range_param) { next = emit_node(NOTHING); // 5,6,7 - offset_tail(ret_val, NODE_SIZE, next); // 5 - offset_tail(ret_val, 2 * NODE_SIZE, next); // 6 - offset_tail(ret_val, 3 * NODE_SIZE, next); // 7 - tail(ret_val, ret_val + (2 * NODE_SIZE)); // 8 - offset_tail(next, -NODE_SIZE, ret_val); // 9 + offset_tail(ret_val, NODE_SIZE, next); // 5 + offset_tail(ret_val, 2 * NODE_SIZE, next); // 6 + offset_tail(ret_val, 3 * NODE_SIZE, next); // 7 + tail(ret_val, ret_val + (2 * NODE_SIZE)); // 8 + offset_tail(next, -NODE_SIZE, ret_val); // 9 insert(INIT_COUNT, ret_val, 0UL, 0UL, pContext.Num_Braces); // 10 - tail(ret_val, ret_val + INDEX_SIZE + (4 * NODE_SIZE)); // 10 + tail(ret_val, ret_val + INDEX_SIZE + (4 * NODE_SIZE)); // 10 } pContext.Num_Braces++; @@ -1507,7 +1508,7 @@ uint8_t *piece(int *flag_param, len_range &range_param) { tail(ret_val, next); // 4 tail(next, emit_node(NOTHING)); // 5,6 - offset_tail(ret_val, NODE_SIZE, next); // 6 + offset_tail(ret_val, NODE_SIZE, next); // 6 next = insert(INIT_COUNT, ret_val, 0UL, 0UL, pContext.Num_Braces); // 7 @@ -1535,13 +1536,13 @@ uint8_t *piece(int *flag_param, len_range &range_param) { next = emit_node(BACK); // 4 tail(next, ret_val); // 4 - offset_tail(ret_val, NODE_SIZE, next); // 5 + offset_tail(ret_val, NODE_SIZE, next); // 5 tail(ret_val, emit_node(BRANCH)); // 6 tail(ret_val, emit_node(NOTHING)); // 7 insert(INIT_COUNT, ret_val, 0UL, 0UL, pContext.Num_Braces); // 8 - tail(ret_val, ret_val + INDEX_SIZE + (2 * NODE_SIZE)); // 8 + tail(ret_val, ret_val + INDEX_SIZE + (2 * NODE_SIZE)); // 8 } else { /* Node structure for (x){m,n} construct. @@ -1570,15 +1571,15 @@ uint8_t *piece(int *flag_param, len_range &range_param) { next = emit_node(BRANCH); // 5,8 tail(ret_val, next); // 5 - offset_tail(next, -NODE_SIZE, ret_val); // 6 + offset_tail(next, -NODE_SIZE, ret_val); // 6 next = emit_node(NOTHING); // 7,8 - offset_tail(ret_val, NODE_SIZE, next); // 7 + offset_tail(ret_val, NODE_SIZE, next); // 7 - offset_tail(next, -NODE_SIZE, next); // 8 + offset_tail(next, -NODE_SIZE, next); // 8 insert(INIT_COUNT, ret_val, 0UL, 0UL, pContext.Num_Braces); // 9 - tail(ret_val, ret_val + INDEX_SIZE + (2 * NODE_SIZE)); // 9 + tail(ret_val, ret_val + INDEX_SIZE + (2 * NODE_SIZE)); // 9 } pContext.Num_Braces++; @@ -1703,7 +1704,7 @@ uint8_t *chunk(int paren, int *flag_param, len_range &range_param) { look_only = true; // We'll overwrite the zero length later on, so we save the ptr ret_val = emit_special(paren, 0, 0); - emit_look_behind_bounds = ret_val + NODE_SIZE; + emit_look_behind_bounds = ret_val + NODE_SIZE; } else if (paren == INSENSITIVE) { pContext.Is_Case_Insensitive = true; } else if (paren == SENSITIVE) { @@ -1777,7 +1778,7 @@ uint8_t *chunk(int paren, int *flag_param, len_range &range_param) { // Hook the tails of the branch alternatives to the closing node. for (uint8_t *this_branch = ret_val; this_branch != nullptr; this_branch = next_ptr(this_branch)) { - branch_tail(this_branch, NODE_SIZE, ender); + branch_tail(this_branch, NODE_SIZE, ender); } // Check for proper termination. @@ -1788,7 +1789,7 @@ uint8_t *chunk(int paren, int *flag_param, len_range &range_param) { if (*pContext.Reg_Parse == ')') { Raise("missing left parenthesis '('"); } else { - Raise("junk on end"); // "Can't happen" - NOTREACHED + Raise("junk on end"); // "Can't happen" - NOT REACHED } } @@ -1923,9 +1924,9 @@ Regex::Regex(view::string_view exp, int defaultFlags) { * Match_Newline: Newlines are NOT matched by default * in character classes */ - pContext.Is_Case_Insensitive = ((defaultFlags & REDFLT_CASE_INSENSITIVE) != 0); + pContext.Is_Case_Insensitive = ((defaultFlags & RE_DEFAULT_CASE_INSENSITIVE) != 0); #if 0 // Currently not used. Uncomment if needed. - pContext.Match_Newline = ((defaultFlags & REDFLT_MATCH_NEWLINE) != 0); + pContext.Match_Newline = ((defaultFlags & RE_DEFAULT_MATCH_NEWLINE) != 0); #else pContext.Match_Newline = false; #endif @@ -1987,8 +1988,8 @@ Regex::Regex(view::string_view exp, int defaultFlags) { /* Allow x+ or x+? at the start of the regex to be optimized. */ - if (GET_OP_CODE(scan + NODE_SIZE) == EXACTLY) { - re->match_start = static_cast(*OPERAND(scan + NODE_SIZE)); + if (GET_OP_CODE(scan + NODE_SIZE) == EXACTLY) { + re->match_start = static_cast(*OPERAND(scan + NODE_SIZE)); } } else if (GET_OP_CODE(scan) == BOL) { re->anchor++; diff --git a/Regex/Constants.h b/Regex/Constants.h index e964a0d8..651508fc 100644 --- a/Regex/Constants.h +++ b/Regex/Constants.h @@ -2,6 +2,7 @@ #ifndef CONSTANTS_H_ #define CONSTANTS_H_ +#include #include /* The first byte of the Regex internal 'program' is a magic number to help @@ -22,11 +23,20 @@ constexpr auto MaxSubExpr = 50u; */ constexpr int RecursionLimit = 10000; -constexpr int OP_CODE_SIZE = 1; -constexpr int NEXT_PTR_SIZE = 2; -constexpr int INDEX_SIZE = 1; -constexpr int LENGTH_SIZE = 4; -constexpr int NODE_SIZE = NEXT_PTR_SIZE + OP_CODE_SIZE; +template +constexpr T OP_CODE_SIZE = 1; + +template +constexpr T NEXT_PTR_SIZE = 2; + +template +constexpr T INDEX_SIZE = 1; + +template +constexpr T LENGTH_SIZE = 4; + +template +constexpr T NODE_SIZE = NEXT_PTR_SIZE + OP_CODE_SIZE; constexpr auto REG_INFINITY = 0UL; diff --git a/Regex/Decompile.cpp b/Regex/Decompile.cpp index c9215b36..ca6195fc 100644 --- a/Regex/Decompile.cpp +++ b/Regex/Decompile.cpp @@ -4,12 +4,12 @@ namespace { -constexpr int16_t make_int16(uint8_t hi, uint16_t lo) { - return (static_cast(hi << 8)) | lo; +constexpr uint16_t make_uint16(uint8_t hi, uint8_t lo) { + return (static_cast(hi) << 8) | lo; } -constexpr uint16_t make_uint16(uint8_t hi, uint16_t lo) { - return (static_cast(hi << 8)) | lo; +constexpr int16_t make_int16(uint8_t hi, uint8_t lo) { + return static_cast(make_uint16(hi, lo)); } } @@ -337,11 +337,11 @@ std::vector decompileRegex(const Regex &re) { uint8_t offset_hi = *it++; uint8_t offset_lo = *it++; - int16_t min_hi = *it++; - int16_t min_lo = *it++; + uint8_t min_hi = *it++; + uint8_t min_lo = *it++; - int16_t max_hi = *it++; - int16_t max_lo = *it++; + uint8_t max_hi = *it++; + uint8_t max_lo = *it++; results.emplace_back(Instruction3{static_cast(opcode), make_int16(offset_hi, offset_lo), make_uint16(min_hi, min_lo), make_uint16(max_hi, max_lo)}); break; @@ -352,11 +352,11 @@ std::vector decompileRegex(const Regex &re) { uint8_t offset_hi = *it++; uint8_t offset_lo = *it++; - int16_t min_hi = *it++; - int16_t min_lo = *it++; + uint8_t min_hi = *it++; + uint8_t min_lo = *it++; - int16_t max_hi = *it++; - int16_t max_lo = *it++; + uint8_t max_hi = *it++; + uint8_t max_lo = *it++; results.emplace_back(Instruction3{static_cast(opcode), make_int16(offset_hi, offset_lo), make_uint16(min_hi, min_lo), make_uint16(max_hi, max_lo)}); break; diff --git a/Regex/Execute.cpp b/Regex/Execute.cpp index d902fbac..6fa0ec1d 100644 --- a/Regex/Execute.cpp +++ b/Regex/Execute.cpp @@ -73,7 +73,7 @@ FORCE_INLINE bool end_of_string(const char *ptr) noexcept { * @return */ FORCE_INLINE uint16_t get_lower(const uint8_t *p) noexcept { - return static_cast(((p[NODE_SIZE + 0] & 0xff) << 8) + ((p[NODE_SIZE + 1]) & 0xff)); + return static_cast(((p[NODE_SIZE + 0] & 0xff) << 8) + ((p[NODE_SIZE + 1]) & 0xff)); } /** @@ -82,7 +82,7 @@ FORCE_INLINE uint16_t get_lower(const uint8_t *p) noexcept { * @return */ FORCE_INLINE uint16_t get_upper(const uint8_t *p) noexcept { - return static_cast(((p[NODE_SIZE + 2] & 0xff) << 8) + ((p[NODE_SIZE + 3]) & 0xff)); + return static_cast(((p[NODE_SIZE + 2] & 0xff) << 8) + ((p[NODE_SIZE + 3]) & 0xff)); } /** @@ -625,14 +625,14 @@ bool match(uint8_t *prog, size_t *branch_index_param) { lazy = true; NEDIT_FALLTHROUGH(); case BRACE: - min = static_cast(GET_OFFSET(scan + NEXT_PTR_SIZE)); - max = static_cast(GET_OFFSET(scan + (2 * NEXT_PTR_SIZE))); + min = static_cast(GET_OFFSET(scan + NEXT_PTR_SIZE)); + max = static_cast(GET_OFFSET(scan + (2 * NEXT_PTR_SIZE))); if (max <= REG_INFINITY) { max = std::numeric_limits::max(); } - next_op = OPERAND(scan + (2 * NEXT_PTR_SIZE)); + next_op = OPERAND(scan + (2 * NEXT_PTR_SIZE)); } save = eContext.Reg_Input; @@ -693,8 +693,8 @@ bool match(uint8_t *prog, size_t *branch_index_param) { break; case TEST_COUNT: - if (eContext.BraceCounts[*OPERAND(scan)] < static_cast(GET_OFFSET(scan + NEXT_PTR_SIZE + INDEX_SIZE))) { - next = scan + NODE_SIZE + INDEX_SIZE + NEXT_PTR_SIZE; + if (eContext.BraceCounts[*OPERAND(scan)] < static_cast(GET_OFFSET(scan + NEXT_PTR_SIZE + INDEX_SIZE))) { + next = scan + NODE_SIZE + INDEX_SIZE + NEXT_PTR_SIZE; } break; @@ -869,7 +869,7 @@ bool match(uint8_t *prog, size_t *branch_index_param) { node. The look-behind node is followed by a chain of branches (contents of the look-behind expression), and terminated by a look-behind-close node. */ - next = NEXT_PTR(OPERAND(scan) + LENGTH_SIZE); // 1st branch + next = NEXT_PTR(OPERAND(scan) + LENGTH_SIZE); // 1st branch // Skip the chained branches inside the look-ahead while (GET_OP_CODE(next) == BRANCH) { diff --git a/Regex/Regex.h b/Regex/Regex.h index b38ad5e5..4e03d8a9 100644 --- a/Regex/Regex.h +++ b/Regex/Regex.h @@ -14,9 +14,9 @@ /* Flags for CompileRE default settings (Markus Schwarzenberg) */ enum RE_DEFAULT_FLAG { - REDFLT_STANDARD = 0, - REDFLT_CASE_INSENSITIVE = 1 - /* REDFLT_MATCH_NEWLINE = 2 Currently not used. */ + RE_DEFAULT_STANDARD = 0, + RE_DEFAULT_CASE_INSENSITIVE = 1 + /* RE_DEFAULT_MATCH_NEWLINE = 2 Currently not used. */ }; class Regex { diff --git a/Regex/Substitute.cpp b/Regex/Substitute.cpp index 24826a1a..b7616b84 100644 --- a/Regex/Substitute.cpp +++ b/Regex/Substitute.cpp @@ -27,14 +27,14 @@ bool Regex::SubstituteRE(view::string_view source, std::string &dest) const { char ch = *in++; - char chgcase = '\0'; + char changeCase = '\0'; size_t paren_no = InvalidParenNumber; if (ch == '\\') { // Process any case altering tokens, i.e \u, \U, \l, \L. if (*in == 'u' || *in == 'U' || *in == 'l' || *in == 'L') { - chgcase = *in++; + changeCase = *in++; if (in == source.end()) { break; @@ -82,7 +82,7 @@ bool Regex::SubstituteRE(view::string_view source, std::string &dest) const { /* The tokens \u and \l only modify the first character while the * tokens \U and \L modify the entire string. */ - switch (chgcase) { + switch (changeCase) { case 'u': { int count = 0; std::transform(re->startp[paren_no], re->endp[paren_no], out, [&count](char ch) -> int { diff --git a/Regex/test/Test.cpp b/Regex/test/Test.cpp index 0e552d06..95f02d37 100644 --- a/Regex/test/Test.cpp +++ b/Regex/test/Test.cpp @@ -11,7 +11,7 @@ struct Test { }; int test_regex_match(view::string_view regex, view::string_view input) { - Regex re(regex, REDFLT_STANDARD); + Regex re(regex, RE_DEFAULT_STANDARD); if (re.execute(input)) { return 0; @@ -726,7 +726,7 @@ int main() { for (Test t : tests) { try { - Regex re(t.input, REDFLT_STANDARD); + Regex re(t.input, RE_DEFAULT_STANDARD); std::string bytes; @@ -773,17 +773,17 @@ int main() { return -1; } -#if 0 // testing "catastrophic backtracking" +#if 0 // testing "catastrophic backtracking" if (test_regex_match(R"((\\?.)*\\\n)", R"(Ada:Default\n\tAwk:Default\n\tC++:Default\n\tC:Default\n\tCSS:Default\n\tCsh:Default\n\tFortran:Default\n\tJava:Default\n\tJavaScript:Default\n\tLaTeX:Default\n\tLex:Default\n\tMakefile:Default\n\tMatlab:Default\n\tNEdit Macro:Default\n\tPascal:Default\n\tPerl:Default\n\tPostScript:Default\n\tPython:Default\n\tRegex:Default\n\tSGML HTML:Default\n\tSQL:Default\n\tSh Ksh Bash:Default\n\tTcl:Default\n\tVHDL:Default\n\tVerilog:Default\n\tXML:Default\n\tX Resources:Default\n\tYacc:Default)") != 0) { std::cerr << "ERROR : Failed to X resources match" << std::endl; - return -1; + return -1; } #endif #if defined(NEDIT_INCLUDE_DECOMPILER) for (Test t : tests) { try { - Regex re(t.input, REDFLT_STANDARD); + Regex re(t.input, RE_DEFAULT_STANDARD); decompileRegex(re); } catch (...) { std::cerr << "EXCEPTION: " << t.input.to_string() << '\n'; diff --git a/client/nc.cpp b/client/nc.cpp index 600d4c93..17d0e5c4 100644 --- a/client/nc.cpp +++ b/client/nc.cpp @@ -18,6 +18,7 @@ #include #include +#include #include #include @@ -271,7 +272,7 @@ boost::optional parseCommandLine(const QStringList &args) { int isTabbed; - /* determine if file is to be openned in new tab, by + /* determine if file is to be opened in new tab, by factoring the options -group, -tabbed & -untabbed */ if (group == 2) { isTabbed = 0; // start a new window for new group @@ -404,10 +405,10 @@ int startServer(const char *message, const QStringList &commandLineArgs) { } bool writeToSocket(QLocalSocket *socket, const QByteArray &data) { - int remaining = data.size(); - const char *ptr = data.data(); + int64_t remaining = data.size(); + const char *ptr = data.data(); - constexpr int MaxChunk = 4096; + constexpr int64_t MaxChunk = 4096; while (socket->isOpen() && remaining > 0) { const int64_t written = socket->write(ptr, std::min(MaxChunk, remaining)); @@ -482,7 +483,7 @@ int main(int argc, char *argv[]) { auto socket = std::make_unique(); socket->connectToServer(socketName, QIODevice::WriteOnly); - if (!socket->waitForConnected(timeout.count())) { + if (!socket->waitForConnected(gsl::narrow(timeout.count()))) { if (i == 0) { switch (startServer("No servers available, start one? (y|n) [y]: ", commandLine.arguments)) { case -1: // Start failed diff --git a/cspell.config.yaml b/cspell.config.yaml index e02dada1..8f1e6292 100644 --- a/cspell.config.yaml +++ b/cspell.config.yaml @@ -5,25 +5,23 @@ dictionaries: [] ignoreWords: [] import: [] words: - - Balinski - - Edel - - Greef - - Markus - - Rebecca - - Schwarzenberg - - Teran - - Vohlken - amai - backlighting + - Balinski + - bground - burlywood - calltip - calltips - clearcase - cornsilk - decompile + - Edel - eteran + - fground - gainsboro + - Greef - konsole + - Markus - nedit - overtype - pixmap @@ -36,7 +34,12 @@ words: - qvsnprintf - rangeset - rangesets + - Rebecca - reparse + - Schwarzenberg + - Teran + - unblank - unhighlight - unixware - untabbed + - Vohlken diff --git a/src/DialogFind.cpp b/src/DialogFind.cpp index 367f2765..e48f8ce1 100644 --- a/src/DialogFind.cpp +++ b/src/DialogFind.cpp @@ -257,10 +257,10 @@ boost::optional DialogFind::readFields() { int regexDefault; if (ui.checkCase->isChecked()) { fields.searchType = SearchType::Regex; - regexDefault = REDFLT_STANDARD; + regexDefault = RE_DEFAULT_STANDARD; } else { fields.searchType = SearchType::RegexNoCase; - regexDefault = REDFLT_CASE_INSENSITIVE; + regexDefault = RE_DEFAULT_CASE_INSENSITIVE; } /* If the search type is a regular expression, test compile it immediately and present error messages */ diff --git a/src/DialogLanguageModes.cpp b/src/DialogLanguageModes.cpp index 33032202..42e3cd1b 100644 --- a/src/DialogLanguageModes.cpp +++ b/src/DialogLanguageModes.cpp @@ -259,7 +259,7 @@ boost::optional DialogLanguageModes::readFields(Verbosity verbosit QString recognitionExpr = ui.editRegex->text(); if (!recognitionExpr.isEmpty()) { try { - auto compiledRE = make_regex(recognitionExpr, REDFLT_STANDARD); + auto compiledRE = make_regex(recognitionExpr, RE_DEFAULT_STANDARD); } catch (const RegexError &e) { if (verbosity == Verbosity::Verbose) { QMessageBox::warning(this, tr("Regex"), tr("Recognition expression:\n%1").arg(QString::fromLatin1(e.what()))); diff --git a/src/DialogReplace.cpp b/src/DialogReplace.cpp index 9948a795..103b6423 100644 --- a/src/DialogReplace.cpp +++ b/src/DialogReplace.cpp @@ -609,10 +609,10 @@ boost::optional DialogReplace::readFields() { int regexDefault; if (ui.checkCase->isChecked()) { fields.searchType = SearchType::Regex; - regexDefault = REDFLT_STANDARD; + regexDefault = RE_DEFAULT_STANDARD; } else { fields.searchType = SearchType::RegexNoCase; - regexDefault = REDFLT_CASE_INSENSITIVE; + regexDefault = RE_DEFAULT_CASE_INSENSITIVE; } /* If the search type is a regular expression, test compile it immediately and present error messages */ diff --git a/src/DocumentWidget.cpp b/src/DocumentWidget.cpp index fc37a9c6..6f2eba96 100644 --- a/src/DocumentWidget.cpp +++ b/src/DocumentWidget.cpp @@ -348,7 +348,7 @@ QLatin1String createRepeatMacro(int how) { ** Replaces '%' with and '#' with . But '%%' and '##' ** are replaced by '%' and '#'. */ -QString escapeCommand(const QString &command, const QString &fullName, int lineNumber) { +QString escapeCommand(const QString &command, const QString &fullName, int64_t lineNumber) { QString ret; for (int i = 0; i < command.size(); ++i) { auto c = command[i]; @@ -2217,7 +2217,7 @@ bool DocumentWidget::compareDocumentToFile(const QString &fileName) const { int64_t restLen = std::min(PREFERRED_CMPBUF_LEN, fileLen); TextCursor bufPos = {}; - int filePos = 0; + int64_t filePos = 0; char fileString[PREFERRED_CMPBUF_LEN + 2]; /* For large files, the comparison can take a while. If it takes too long, @@ -2231,7 +2231,7 @@ bool DocumentWidget::compareDocumentToFile(const QString &fileName) const { while (restLen > 0) { - size_t offset = 0; + int64_t offset = 0; if (pendingCR) { fileString[offset++] = pendingCR; } @@ -2789,7 +2789,7 @@ bool DocumentWidget::writeBckVersion() { #endif // Allocate I/O buffer - constexpr size_t IO_BUFFER_SIZE = (1024 * 1024); + constexpr size_t IO_BUFFER_SIZE = (1024ul * 1024ul); auto io_buffer = std::make_unique(IO_BUFFER_SIZE); // copy loop @@ -4438,7 +4438,7 @@ void DocumentWidget::setOverstrike(bool overstrike) { * @param lineNum * @param column */ -void DocumentWidget::gotoAP(TextArea *area, int line, int column) { +void DocumentWidget::gotoAP(TextArea *area, int64_t line, int64_t column) { TextCursor position; @@ -6004,7 +6004,7 @@ void DocumentWidget::startHighlighting(Verbosity verbosity) { ctx.prev_char = &prev_char; ctx.delimiters = documentDelimiters(); ctx.text = info_->buffer->BufAsString(); - const char *stringPtr = &ctx.text[0]; + const char *stringPtr = ctx.text.data(); Highlight::parseString( &highlightData->pass1Patterns[0], @@ -6349,12 +6349,12 @@ std::unique_ptr DocumentWidget::compilePatterns(const std::vect Input in(&patternSrc[i].startRE); Q_FOREVER { if (in.match(QLatin1Char('&'))) { - compiledPats[i].startSubexprs.push_back(0); + compiledPats[i].startSubexpressions.push_back(0); } else if (in.match(QLatin1Char('\\'))) { QString number; if (in.match(re, &number)) { - compiledPats[i].startSubexprs.push_back(number.toUInt()); + compiledPats[i].startSubexpressions.push_back(number.toUInt()); } else { break; } @@ -6370,12 +6370,12 @@ std::unique_ptr DocumentWidget::compilePatterns(const std::vect Input in(&patternSrc[i].endRE); Q_FOREVER { if (in.match(QLatin1Char('&'))) { - compiledPats[i].endSubexprs.push_back(0); + compiledPats[i].endSubexpressions.push_back(0); } else if (in.match(QLatin1Char('\\'))) { QString number; if (in.match(re, &number)) { - compiledPats[i].endSubexprs.push_back(number.toUInt()); + compiledPats[i].endSubexpressions.push_back(number.toUInt()); } else { break; } @@ -6483,7 +6483,7 @@ std::unique_ptr DocumentWidget::compilePatterns(const std::vect bigPattern.pop_back(); // remove last '|' character try { - compiledPats[patternNum].subPatternRE = std::make_unique(bigPattern, REDFLT_STANDARD); + compiledPats[patternNum].subPatternRE = std::make_unique(bigPattern, RE_DEFAULT_STANDARD); } catch (const RegexError &e) { qWarning("NEdit: Error compiling syntax highlight patterns:\n%s", e.what()); if (verbosity == Verbosity::Verbose) { @@ -6507,7 +6507,7 @@ std::unique_ptr DocumentWidget::compilePatterns(const std::vect std::unique_ptr DocumentWidget::compileRegexAndWarn(const QString &re) { try { - return make_regex(re, REDFLT_STANDARD); + return make_regex(re, RE_DEFAULT_STANDARD); } catch (const RegexError &e) { constexpr int MaxLength = 4096; @@ -7304,7 +7304,7 @@ void DocumentWidget::editTaggedLocation(TextArea *area, int i) { QPointer