Mercurial > vim
comparison src/quickfix.c @ 19405:08f4dc2ba716 v8.2.0260
patch 8.2.0260: several lines of code are duplicated
Commit: https://github.com/vim/vim/commit/f4140488c72cad4dbf5449dba099cfa7de7bbb22
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Feb 15 23:06:45 2020 +0100
patch 8.2.0260: several lines of code are duplicated
Problem: Several lines of code are duplicated.
Solution: Move duplicated code to a function. (Yegappan Lakshmanan,
closes #5330)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 15 Feb 2020 23:15:04 +0100 |
parents | 102f9a44c8b3 |
children | 5512aa74cb62 |
comparison
equal
deleted
inserted
replaced
19404:7be3663e2f2b | 19405:08f4dc2ba716 |
---|---|
978 fields->type = *rmp->startp[midx]; | 978 fields->type = *rmp->startp[midx]; |
979 return QF_OK; | 979 return QF_OK; |
980 } | 980 } |
981 | 981 |
982 /* | 982 /* |
983 * Parse the match for '%+' format pattern. The whole matching line is included | 983 * Copy a non-error line into the error string. Return the matched line in |
984 * in the error string. Return the matched line in "fields->errmsg". | 984 * "fields->errmsg". |
985 */ | 985 */ |
986 static int | 986 static int |
987 qf_parse_fmt_plus(char_u *linebuf, int linelen, qffields_T *fields) | 987 copy_nonerror_line(char_u *linebuf, int linelen, qffields_T *fields) |
988 { | 988 { |
989 char_u *p; | 989 char_u *p; |
990 | 990 |
991 if (linelen >= fields->errmsglen) | 991 if (linelen >= fields->errmsglen) |
992 { | 992 { |
994 if ((p = vim_realloc(fields->errmsg, linelen + 1)) == NULL) | 994 if ((p = vim_realloc(fields->errmsg, linelen + 1)) == NULL) |
995 return QF_NOMEM; | 995 return QF_NOMEM; |
996 fields->errmsg = p; | 996 fields->errmsg = p; |
997 fields->errmsglen = linelen + 1; | 997 fields->errmsglen = linelen + 1; |
998 } | 998 } |
999 // copy whole line to error message | |
999 vim_strncpy(fields->errmsg, linebuf, linelen); | 1000 vim_strncpy(fields->errmsg, linebuf, linelen); |
1001 | |
1000 return QF_OK; | 1002 return QF_OK; |
1001 } | 1003 } |
1002 | 1004 |
1003 /* | 1005 /* |
1004 * Parse the match for error message ('%m') pattern in regmatch. | 1006 * Parse the match for error message ('%m') pattern in regmatch. |
1178 if (i == 0 && midx > 0) // %f | 1180 if (i == 0 && midx > 0) // %f |
1179 status = qf_parse_fmt_f(regmatch, midx, fields, idx); | 1181 status = qf_parse_fmt_f(regmatch, midx, fields, idx); |
1180 else if (i == 5) | 1182 else if (i == 5) |
1181 { | 1183 { |
1182 if (fmt_ptr->flags == '+' && !qf_multiscan) // %+ | 1184 if (fmt_ptr->flags == '+' && !qf_multiscan) // %+ |
1183 status = qf_parse_fmt_plus(linebuf, linelen, fields); | 1185 status = copy_nonerror_line(linebuf, linelen, fields); |
1184 else if (midx > 0) // %m | 1186 else if (midx > 0) // %m |
1185 status = qf_parse_fmt_m(regmatch, midx, fields); | 1187 status = qf_parse_fmt_m(regmatch, midx, fields); |
1186 } | 1188 } |
1187 else if (i == 6 && midx > 0) // %r | 1189 else if (i == 6 && midx > 0) // %r |
1188 status = qf_parse_fmt_r(regmatch, midx, tail); | 1190 status = qf_parse_fmt_r(regmatch, midx, tail); |
1305 * format in 'efm'). | 1307 * format in 'efm'). |
1306 */ | 1308 */ |
1307 static int | 1309 static int |
1308 qf_parse_line_nomatch(char_u *linebuf, int linelen, qffields_T *fields) | 1310 qf_parse_line_nomatch(char_u *linebuf, int linelen, qffields_T *fields) |
1309 { | 1311 { |
1310 char_u *p; | |
1311 | |
1312 fields->namebuf[0] = NUL; // no match found, remove file name | 1312 fields->namebuf[0] = NUL; // no match found, remove file name |
1313 fields->lnum = 0; // don't jump to this line | 1313 fields->lnum = 0; // don't jump to this line |
1314 fields->valid = FALSE; | 1314 fields->valid = FALSE; |
1315 if (linelen >= fields->errmsglen) | 1315 |
1316 { | 1316 return copy_nonerror_line(linebuf, linelen, fields); |
1317 // linelen + null terminator | |
1318 if ((p = vim_realloc(fields->errmsg, linelen + 1)) == NULL) | |
1319 return QF_NOMEM; | |
1320 fields->errmsg = p; | |
1321 fields->errmsglen = linelen + 1; | |
1322 } | |
1323 // copy whole line to error message | |
1324 vim_strncpy(fields->errmsg, linebuf, linelen); | |
1325 | |
1326 return QF_OK; | |
1327 } | 1317 } |
1328 | 1318 |
1329 /* | 1319 /* |
1330 * Parse multi-line error format prefixes (%C and %Z) | 1320 * Parse multi-line error format prefixes (%C and %Z) |
1331 */ | 1321 */ |