diff options
Diffstat (limited to 'editors')
-rw-r--r-- | editors/awk.c | 22 | ||||
-rw-r--r-- | editors/vi.c | 13 |
2 files changed, 26 insertions, 9 deletions
diff --git a/editors/awk.c b/editors/awk.c index d1fedb572..76385f33b 100644 --- a/editors/awk.c +++ b/editors/awk.c | |||
@@ -272,7 +272,8 @@ typedef struct tsplitter_s { | |||
272 | /* if previous token class is CONCAT1 and next is CONCAT2, concatenation */ | 272 | /* if previous token class is CONCAT1 and next is CONCAT2, concatenation */ |
273 | /* operator is inserted between them */ | 273 | /* operator is inserted between them */ |
274 | #define TC_CONCAT1 (TC_VARIABLE | TC_ARRTERM | TC_SEQTERM \ | 274 | #define TC_CONCAT1 (TC_VARIABLE | TC_ARRTERM | TC_SEQTERM \ |
275 | | TC_STRING | TC_NUMBER | TC_UOPPOST) | 275 | | TC_STRING | TC_NUMBER | TC_UOPPOST \ |
276 | | TC_LENGTH) | ||
276 | #define TC_CONCAT2 (TC_OPERAND | TC_UOPPRE) | 277 | #define TC_CONCAT2 (TC_OPERAND | TC_UOPPRE) |
277 | 278 | ||
278 | #define OF_RES1 0x010000 | 279 | #define OF_RES1 0x010000 |
@@ -1074,8 +1075,10 @@ static uint32_t next_token(uint32_t expected) | |||
1074 | const uint32_t *ti; | 1075 | const uint32_t *ti; |
1075 | 1076 | ||
1076 | if (t_rollback) { | 1077 | if (t_rollback) { |
1078 | debug_printf_parse("%s: using rolled-back token\n", __func__); | ||
1077 | t_rollback = FALSE; | 1079 | t_rollback = FALSE; |
1078 | } else if (concat_inserted) { | 1080 | } else if (concat_inserted) { |
1081 | debug_printf_parse("%s: using concat-inserted token\n", __func__); | ||
1079 | concat_inserted = FALSE; | 1082 | concat_inserted = FALSE; |
1080 | t_tclass = save_tclass; | 1083 | t_tclass = save_tclass; |
1081 | t_info = save_info; | 1084 | t_info = save_info; |
@@ -1204,7 +1207,11 @@ static uint32_t next_token(uint32_t expected) | |||
1204 | goto readnext; | 1207 | goto readnext; |
1205 | 1208 | ||
1206 | /* insert concatenation operator when needed */ | 1209 | /* insert concatenation operator when needed */ |
1207 | if ((ltclass & TC_CONCAT1) && (tc & TC_CONCAT2) && (expected & TC_BINOP)) { | 1210 | debug_printf_parse("%s: %x %x %x concat_inserted?\n", __func__, |
1211 | (ltclass & TC_CONCAT1), (tc & TC_CONCAT2), (expected & TC_BINOP)); | ||
1212 | if ((ltclass & TC_CONCAT1) && (tc & TC_CONCAT2) && (expected & TC_BINOP) | ||
1213 | && !(ltclass == TC_LENGTH && tc == TC_SEQSTART) /* but not for "length(..." */ | ||
1214 | ) { | ||
1208 | concat_inserted = TRUE; | 1215 | concat_inserted = TRUE; |
1209 | save_tclass = tc; | 1216 | save_tclass = tc; |
1210 | save_info = t_info; | 1217 | save_info = t_info; |
@@ -1212,6 +1219,7 @@ static uint32_t next_token(uint32_t expected) | |||
1212 | t_info = OC_CONCAT | SS | P(35); | 1219 | t_info = OC_CONCAT | SS | P(35); |
1213 | } | 1220 | } |
1214 | 1221 | ||
1222 | debug_printf_parse("%s: t_tclass=tc=%x\n", __func__, t_tclass); | ||
1215 | t_tclass = tc; | 1223 | t_tclass = tc; |
1216 | } | 1224 | } |
1217 | ltclass = t_tclass; | 1225 | ltclass = t_tclass; |
@@ -1222,6 +1230,7 @@ static uint32_t next_token(uint32_t expected) | |||
1222 | EMSG_UNEXP_EOS : EMSG_UNEXP_TOKEN); | 1230 | EMSG_UNEXP_EOS : EMSG_UNEXP_TOKEN); |
1223 | } | 1231 | } |
1224 | 1232 | ||
1233 | debug_printf_parse("%s: returning, ltclass:%x t_double:%f\n", __func__, ltclass, t_double); | ||
1225 | return ltclass; | 1234 | return ltclass; |
1226 | #undef concat_inserted | 1235 | #undef concat_inserted |
1227 | #undef save_tclass | 1236 | #undef save_tclass |
@@ -1286,7 +1295,7 @@ static node *parse_expr(uint32_t iexp) | |||
1286 | glptr = NULL; | 1295 | glptr = NULL; |
1287 | 1296 | ||
1288 | } else if (tc & (TC_BINOP | TC_UOPPOST)) { | 1297 | } else if (tc & (TC_BINOP | TC_UOPPOST)) { |
1289 | debug_printf_parse("%s: TC_BINOP | TC_UOPPOST\n", __func__); | 1298 | debug_printf_parse("%s: TC_BINOP | TC_UOPPOST tc:%x\n", __func__, tc); |
1290 | /* for binary and postfix-unary operators, jump back over | 1299 | /* for binary and postfix-unary operators, jump back over |
1291 | * previous operators with higher priority */ | 1300 | * previous operators with higher priority */ |
1292 | vn = cn; | 1301 | vn = cn; |
@@ -1391,7 +1400,12 @@ static node *parse_expr(uint32_t iexp) | |||
1391 | 1400 | ||
1392 | case TC_LENGTH: | 1401 | case TC_LENGTH: |
1393 | debug_printf_parse("%s: TC_LENGTH\n", __func__); | 1402 | debug_printf_parse("%s: TC_LENGTH\n", __func__); |
1394 | next_token(TC_SEQSTART | TC_OPTERM | TC_GRPTERM); | 1403 | next_token(TC_SEQSTART /* length(...) */ |
1404 | | TC_OPTERM /* length; (or newline)*/ | ||
1405 | | TC_GRPTERM /* length } */ | ||
1406 | | TC_BINOPX /* length <op> NUM */ | ||
1407 | | TC_COMMA /* print length, 1 */ | ||
1408 | ); | ||
1395 | rollback_token(); | 1409 | rollback_token(); |
1396 | if (t_tclass & TC_SEQSTART) { | 1410 | if (t_tclass & TC_SEQSTART) { |
1397 | /* It was a "(" token. Handle just like TC_BUILTIN */ | 1411 | /* It was a "(" token. Handle just like TC_BUILTIN */ |
diff --git a/editors/vi.c b/editors/vi.c index 948b95ae6..131c018a2 100644 --- a/editors/vi.c +++ b/editors/vi.c | |||
@@ -2317,7 +2317,6 @@ static char *get_one_address(char *p, int *addr) // get colon addr, if present | |||
2317 | int st; | 2317 | int st; |
2318 | char *q; | 2318 | char *q; |
2319 | IF_FEATURE_VI_YANKMARK(char c;) | 2319 | IF_FEATURE_VI_YANKMARK(char c;) |
2320 | IF_FEATURE_VI_SEARCH(char *pat;) | ||
2321 | 2320 | ||
2322 | *addr = -1; // assume no addr | 2321 | *addr = -1; // assume no addr |
2323 | if (*p == '.') { // the current line | 2322 | if (*p == '.') { // the current line |
@@ -2342,16 +2341,20 @@ static char *get_one_address(char *p, int *addr) // get colon addr, if present | |||
2342 | #endif | 2341 | #endif |
2343 | #if ENABLE_FEATURE_VI_SEARCH | 2342 | #if ENABLE_FEATURE_VI_SEARCH |
2344 | else if (*p == '/') { // a search pattern | 2343 | else if (*p == '/') { // a search pattern |
2345 | q = strchrnul(++p, '/'); | 2344 | q = strchrnul(p + 1, '/'); |
2346 | pat = xstrndup(p, q - p); // save copy of pattern | 2345 | if (p + 1 != q) { |
2346 | // save copy of new pattern | ||
2347 | free(last_search_pattern); | ||
2348 | last_search_pattern = xstrndup(p, q - p); | ||
2349 | } | ||
2347 | p = q; | 2350 | p = q; |
2348 | if (*p == '/') | 2351 | if (*p == '/') |
2349 | p++; | 2352 | p++; |
2350 | q = char_search(dot, pat, (FORWARD << 1) | FULL); | 2353 | q = char_search(next_line(dot), last_search_pattern + 1, |
2354 | (FORWARD << 1) | FULL); | ||
2351 | if (q != NULL) { | 2355 | if (q != NULL) { |
2352 | *addr = count_lines(text, q); | 2356 | *addr = count_lines(text, q); |
2353 | } | 2357 | } |
2354 | free(pat); | ||
2355 | } | 2358 | } |
2356 | #endif | 2359 | #endif |
2357 | else if (*p == '$') { // the last line in file | 2360 | else if (*p == '$') { // the last line in file |