aboutsummaryrefslogtreecommitdiff
path: root/editors
diff options
context:
space:
mode:
Diffstat (limited to 'editors')
-rw-r--r--editors/sed.c13
-rw-r--r--editors/vi.c79
2 files changed, 46 insertions, 46 deletions
diff --git a/editors/sed.c b/editors/sed.c
index e18e48ab5..2c64ad500 100644
--- a/editors/sed.c
+++ b/editors/sed.c
@@ -395,7 +395,9 @@ static int parse_subst_cmd(sed_cmd_t *sed_cmd, const char *substr)
395 /* process the flags */ 395 /* process the flags */
396 396
397 sed_cmd->which_match = 1; 397 sed_cmd->which_match = 1;
398 dbg("s flags:'%s'", substr + idx + 1);
398 while (substr[++idx]) { 399 while (substr[++idx]) {
400 dbg("s flag:'%c'", substr[idx]);
399 /* Parse match number */ 401 /* Parse match number */
400 if (isdigit(substr[idx])) { 402 if (isdigit(substr[idx])) {
401 if (match[0] != '^') { 403 if (match[0] != '^') {
@@ -403,7 +405,7 @@ static int parse_subst_cmd(sed_cmd_t *sed_cmd, const char *substr)
403 const char *pos = substr + idx; 405 const char *pos = substr + idx;
404/* FIXME: error check? */ 406/* FIXME: error check? */
405 sed_cmd->which_match = (unsigned)strtol(substr+idx, (char**) &pos, 10); 407 sed_cmd->which_match = (unsigned)strtol(substr+idx, (char**) &pos, 10);
406 idx = pos - substr; 408 idx = pos - substr - 1;
407 } 409 }
408 continue; 410 continue;
409 } 411 }
@@ -443,6 +445,7 @@ static int parse_subst_cmd(sed_cmd_t *sed_cmd, const char *substr)
443 case '}': 445 case '}':
444 goto out; 446 goto out;
445 default: 447 default:
448 dbg("s bad flags:'%s'", substr + idx);
446 bb_error_msg_and_die("bad option in substitution expression"); 449 bb_error_msg_and_die("bad option in substitution expression");
447 } 450 }
448 } 451 }
@@ -1519,12 +1522,16 @@ int sed_main(int argc UNUSED_PARAM, char **argv)
1519 1522
1520 /* -i: process each FILE separately: */ 1523 /* -i: process each FILE separately: */
1521 1524
1525 if (stat(*argv, &statbuf) != 0) {
1526 bb_simple_perror_msg(*argv);
1527 G.exitcode = EXIT_FAILURE;
1528 G.current_input_file++;
1529 continue;
1530 }
1522 G.outname = xasprintf("%sXXXXXX", *argv); 1531 G.outname = xasprintf("%sXXXXXX", *argv);
1523 nonstdoutfd = xmkstemp(G.outname); 1532 nonstdoutfd = xmkstemp(G.outname);
1524 G.nonstdout = xfdopen_for_write(nonstdoutfd); 1533 G.nonstdout = xfdopen_for_write(nonstdoutfd);
1525
1526 /* Set permissions/owner of output file */ 1534 /* Set permissions/owner of output file */
1527 stat(*argv, &statbuf);
1528 /* chmod'ing AFTER chown would preserve suid/sgid bits, 1535 /* chmod'ing AFTER chown would preserve suid/sgid bits,
1529 * but GNU sed 4.2.1 does not preserve them either */ 1536 * but GNU sed 4.2.1 does not preserve them either */
1530 fchmod(nonstdoutfd, statbuf.st_mode); 1537 fchmod(nonstdoutfd, statbuf.st_mode);
diff --git a/editors/vi.c b/editors/vi.c
index a6505e0bf..0c6906c6b 100644
--- a/editors/vi.c
+++ b/editors/vi.c
@@ -566,8 +566,7 @@ static void redraw(int); // force a full screen refresh
566static char* format_line(char* /*, int*/); 566static char* format_line(char* /*, int*/);
567static void refresh(int); // update the terminal from screen[] 567static void refresh(int); // update the terminal from screen[]
568 568
569static void Indicate_Error(void); // use flash or beep to indicate error 569static void indicate_error(void); // use flash or beep to indicate error
570#define indicate_error(c) Indicate_Error()
571static void Hit_Return(void); 570static void Hit_Return(void);
572 571
573#if ENABLE_FEATURE_VI_SEARCH 572#if ENABLE_FEATURE_VI_SEARCH
@@ -1840,11 +1839,11 @@ static char *bound_dot(char *p) // make sure text[0] <= P < "end"
1840{ 1839{
1841 if (p >= end && end > text) { 1840 if (p >= end && end > text) {
1842 p = end - 1; 1841 p = end - 1;
1843 indicate_error('1'); 1842 indicate_error();
1844 } 1843 }
1845 if (p < text) { 1844 if (p < text) {
1846 p = text; 1845 p = text;
1847 indicate_error('2'); 1846 indicate_error();
1848 } 1847 }
1849 return p; 1848 return p;
1850} 1849}
@@ -2023,16 +2022,9 @@ static char *char_insert(char *p, char c, int undo) // insert the char c at 'p'
2023 p = text_hole_delete(p, p, ALLOW_UNDO_QUEUED); // shrink buffer 1 char 2022 p = text_hole_delete(p, p, ALLOW_UNDO_QUEUED); // shrink buffer 1 char
2024 } 2023 }
2025 } else { 2024 } else {
2026#if ENABLE_FEATURE_VI_SETOPTS
2027 // insert a char into text[] 2025 // insert a char into text[]
2028 char *sp; // "save p"
2029#endif
2030
2031 if (c == 13) 2026 if (c == 13)
2032 c = '\n'; // translate \r to \n 2027 c = '\n'; // translate \r to \n
2033#if ENABLE_FEATURE_VI_SETOPTS
2034 sp = p; // remember addr of insert
2035#endif
2036#if ENABLE_FEATURE_VI_UNDO 2028#if ENABLE_FEATURE_VI_UNDO
2037# if ENABLE_FEATURE_VI_UNDO_QUEUE 2029# if ENABLE_FEATURE_VI_UNDO_QUEUE
2038 if (c == '\n') 2030 if (c == '\n')
@@ -2056,8 +2048,8 @@ static char *char_insert(char *p, char c, int undo) // insert the char c at 'p'
2056#endif /* ENABLE_FEATURE_VI_UNDO */ 2048#endif /* ENABLE_FEATURE_VI_UNDO */
2057 p += 1 + stupid_insert(p, c); // insert the char 2049 p += 1 + stupid_insert(p, c); // insert the char
2058#if ENABLE_FEATURE_VI_SETOPTS 2050#if ENABLE_FEATURE_VI_SETOPTS
2059 if (showmatch && strchr(")]}", *sp) != NULL) { 2051 if (showmatch && strchr(")]}", c) != NULL) {
2060 showmatching(sp); 2052 showmatching(p - 1);
2061 } 2053 }
2062 if (autoindent && c == '\n') { // auto indent the new line 2054 if (autoindent && c == '\n') { // auto indent the new line
2063 char *q; 2055 char *q;
@@ -2217,34 +2209,32 @@ static char *skip_thing(char *p, int linecnt, int dir, int type)
2217} 2209}
2218 2210
2219// find matching char of pair () [] {} 2211// find matching char of pair () [] {}
2212// will crash if c is not one of these
2220static char *find_pair(char *p, const char c) 2213static char *find_pair(char *p, const char c)
2221{ 2214{
2222 char match, *q; 2215 const char *braces = "()[]{}";
2216 char match;
2223 int dir, level; 2217 int dir, level;
2224 2218
2225 match = ')'; 2219 dir = strchr(braces, c) - braces;
2220 dir ^= 1;
2221 match = braces[dir];
2222 dir = ((dir & 1) << 1) - 1; /* 1 for ([{, -1 for )\} */
2223
2224 // look for match, count levels of pairs (( ))
2226 level = 1; 2225 level = 1;
2227 dir = 1; // assume forward 2226 for (;;) {
2228 switch (c) { 2227 p += dir;
2229 case '(': match = ')'; break; 2228 if (p < text || p >= end)
2230 case '[': match = ']'; break; 2229 return NULL;
2231 case '{': match = '}'; break; 2230 if (*p == c)
2232 case ')': match = '('; dir = -1; break;
2233 case ']': match = '['; dir = -1; break;
2234 case '}': match = '{'; dir = -1; break;
2235 }
2236 for (q = p + dir; text <= q && q < end; q += dir) {
2237 // look for match, count levels of pairs (( ))
2238 if (*q == c)
2239 level++; // increase pair levels 2231 level++; // increase pair levels
2240 if (*q == match) 2232 if (*p == match) {
2241 level--; // reduce pair level 2233 level--; // reduce pair level
2242 if (level == 0) 2234 if (level == 0)
2243 break; // found matching pair 2235 return p; // found matching pair
2236 }
2244 } 2237 }
2245 if (level != 0)
2246 q = NULL; // indicate no match
2247 return q;
2248} 2238}
2249 2239
2250#if ENABLE_FEATURE_VI_SETOPTS 2240#if ENABLE_FEATURE_VI_SETOPTS
@@ -2256,7 +2246,7 @@ static void showmatching(char *p)
2256 // we found half of a pair 2246 // we found half of a pair
2257 q = find_pair(p, *p); // get loc of matching char 2247 q = find_pair(p, *p); // get loc of matching char
2258 if (q == NULL) { 2248 if (q == NULL) {
2259 indicate_error('3'); // no matching char 2249 indicate_error(); // no matching char
2260 } else { 2250 } else {
2261 // "q" now points to matching pair 2251 // "q" now points to matching pair
2262 save_dot = dot; // remember where we are 2252 save_dot = dot; // remember where we are
@@ -2823,6 +2813,9 @@ static int mysleep(int hund) // sleep for 'hund' 1/100 seconds or stdin ready
2823#else 2813#else
2824 struct pollfd pfd[1]; 2814 struct pollfd pfd[1];
2825 2815
2816 if (hund != 0)
2817 fflush_all();
2818
2826 pfd[0].fd = STDIN_FILENO; 2819 pfd[0].fd = STDIN_FILENO;
2827 pfd[0].events = POLLIN; 2820 pfd[0].events = POLLIN;
2828 return safe_poll(pfd, 1, hund*10) > 0; 2821 return safe_poll(pfd, 1, hund*10) > 0;
@@ -3106,7 +3099,7 @@ static void flash(int h)
3106 redraw(TRUE); 3099 redraw(TRUE);
3107} 3100}
3108 3101
3109static void Indicate_Error(void) 3102static void indicate_error(void)
3110{ 3103{
3111#if ENABLE_FEATURE_VI_CRASHME 3104#if ENABLE_FEATURE_VI_CRASHME
3112 if (crashme > 0) 3105 if (crashme > 0)
@@ -3649,7 +3642,7 @@ static void do_cmd(int c)
3649 break; 3642 break;
3650 case 27: // esc 3643 case 27: // esc
3651 if (cmd_mode == 0) 3644 if (cmd_mode == 0)
3652 indicate_error(c); 3645 indicate_error();
3653 cmd_mode = 0; // stop insrting 3646 cmd_mode = 0; // stop insrting
3654 undo_queue_commit(); 3647 undo_queue_commit();
3655 end_cmd_q(); 3648 end_cmd_q();
@@ -3668,7 +3661,7 @@ static void do_cmd(int c)
3668 if ((unsigned)c1 <= 25) { // a-z? 3661 if ((unsigned)c1 <= 25) { // a-z?
3669 YDreg = c1; 3662 YDreg = c1;
3670 } else { 3663 } else {
3671 indicate_error(c); 3664 indicate_error();
3672 } 3665 }
3673 break; 3666 break;
3674 case '\'': // '- goto a specific mark 3667 case '\'': // '- goto a specific mark
@@ -3686,7 +3679,7 @@ static void do_cmd(int c)
3686 dot_begin(); // go to B-o-l 3679 dot_begin(); // go to B-o-l
3687 dot_skip_over_ws(); 3680 dot_skip_over_ws();
3688 } else { 3681 } else {
3689 indicate_error(c); 3682 indicate_error();
3690 } 3683 }
3691 break; 3684 break;
3692 case 'm': // m- Mark a line 3685 case 'm': // m- Mark a line
@@ -3699,7 +3692,7 @@ static void do_cmd(int c)
3699 // remember the line 3692 // remember the line
3700 mark[c1] = dot; 3693 mark[c1] = dot;
3701 } else { 3694 } else {
3702 indicate_error(c); 3695 indicate_error();
3703 } 3696 }
3704 break; 3697 break;
3705 case 'P': // P- Put register before 3698 case 'P': // P- Put register before
@@ -3760,7 +3753,7 @@ static void do_cmd(int c)
3760 // we found half of a pair 3753 // we found half of a pair
3761 p = find_pair(q, *q); 3754 p = find_pair(q, *q);
3762 if (p == NULL) { 3755 if (p == NULL) {
3763 indicate_error(c); 3756 indicate_error();
3764 } else { 3757 } else {
3765 dot = p; 3758 dot = p;
3766 } 3759 }
@@ -3768,7 +3761,7 @@ static void do_cmd(int c)
3768 } 3761 }
3769 } 3762 }
3770 if (*q == '\n') 3763 if (*q == '\n')
3771 indicate_error(c); 3764 indicate_error();
3772 break; 3765 break;
3773 case 'f': // f- forward to a user specified char 3766 case 'f': // f- forward to a user specified char
3774 last_forward_char = get_one_char(); // get the search char 3767 last_forward_char = get_one_char(); // get the search char
@@ -4101,7 +4094,7 @@ static void do_cmd(int c)
4101 // ZZ means to save file (if necessary), then exit 4094 // ZZ means to save file (if necessary), then exit
4102 c1 = get_one_char(); 4095 c1 = get_one_char();
4103 if (c1 != 'Z') { 4096 if (c1 != 'Z') {
4104 indicate_error(c); 4097 indicate_error();
4105 break; 4098 break;
4106 } 4099 }
4107 if (modified_count) { 4100 if (modified_count) {
@@ -4185,7 +4178,7 @@ static void do_cmd(int c)
4185 // could not recognize object 4178 // could not recognize object
4186 c = c1 = 27; // error- 4179 c = c1 = 27; // error-
4187 ml = 0; 4180 ml = 0;
4188 indicate_error(c); 4181 indicate_error();
4189 } 4182 }
4190 if (ml && whole) { 4183 if (ml && whole) {
4191 if (c == 'c') { 4184 if (c == 'c') {