diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2017-07-27 12:34:56 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2017-07-27 12:34:56 +0200 |
commit | 6bdcee835710e9a7dda6e31a8d5bc3992037db28 (patch) | |
tree | ee938d1d773a6b33e02b350559c1df839ff3aa2c | |
parent | 7d2f33dc1f6dcd44671d88360bc598ad82c37a60 (diff) | |
download | busybox-w32-6bdcee835710e9a7dda6e31a8d5bc3992037db28.tar.gz busybox-w32-6bdcee835710e9a7dda6e31a8d5bc3992037db28.tar.bz2 busybox-w32-6bdcee835710e9a7dda6e31a8d5bc3992037db28.zip |
ed: fix "\n" removal in command line; make "w" set "dirty = 0"
function old new delta
doCommands 2184 2226 +42
getNum 345 343 -2
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 42/-2) Total: 40 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | editors/ed.c | 44 |
1 files changed, 24 insertions, 20 deletions
diff --git a/editors/ed.c b/editors/ed.c index b13c3ed59..7f21ded92 100644 --- a/editors/ed.c +++ b/editors/ed.c | |||
@@ -193,9 +193,9 @@ static NOINLINE int searchLines(const char *str, int num1, int num2) | |||
193 | 193 | ||
194 | /* | 194 | /* |
195 | * Parse a line number argument if it is present. This is a sum | 195 | * Parse a line number argument if it is present. This is a sum |
196 | * or difference of numbers, '.', '$', 'x, or a search string. | 196 | * or difference of numbers, ".", "$", "'c", or a search string. |
197 | * Returns pointer which stopped the scan if successful (whether or not | 197 | * Returns pointer which stopped the scan if successful |
198 | * there was a number). | 198 | * (whether or not there was a number). |
199 | * Returns NULL if there was a parsing error, with a message output. | 199 | * Returns NULL if there was a parsing error, with a message output. |
200 | * Whether there was a number is returned indirectly, as is the number. | 200 | * Whether there was a number is returned indirectly, as is the number. |
201 | */ | 201 | */ |
@@ -227,12 +227,13 @@ static const char* getNum(const char *cp, smallint *retHaveNum, int *retNum) | |||
227 | 227 | ||
228 | case '\'': | 228 | case '\'': |
229 | cp++; | 229 | cp++; |
230 | if ((*cp < 'a') || (*cp > 'z')) { | 230 | if ((unsigned)(*cp - 'a') >= 26) { |
231 | bb_error_msg("bad mark name"); | 231 | bb_error_msg("bad mark name"); |
232 | return NULL; | 232 | return NULL; |
233 | } | 233 | } |
234 | haveNum = TRUE; | 234 | haveNum = TRUE; |
235 | num = marks[*cp++ - 'a']; | 235 | num = marks[(unsigned)(*cp - 'a')]; |
236 | cp++; | ||
236 | break; | 237 | break; |
237 | 238 | ||
238 | case '/': | 239 | case '/': |
@@ -365,7 +366,7 @@ static void addLines(int num) | |||
365 | * Now we exit to ed prompt. Is in important? */ | 366 | * Now we exit to ed prompt. Is in important? */ |
366 | return; | 367 | return; |
367 | } | 368 | } |
368 | if ((buf[0] == '.') && (buf[1] == '\n') && (buf[2] == '\0')) | 369 | if (buf[0] == '.' && buf[1] == '\n' && buf[2] == '\0') |
369 | return; | 370 | return; |
370 | if (!insertLine(num++, buf, len)) | 371 | if (!insertLine(num++, buf, len)) |
371 | return; | 372 | return; |
@@ -791,7 +792,7 @@ static void doCommands(void) | |||
791 | len = read_line_input(NULL, ": ", buf, sizeof(buf), /*timeout*/ -1); | 792 | len = read_line_input(NULL, ": ", buf, sizeof(buf), /*timeout*/ -1); |
792 | if (len <= 0) | 793 | if (len <= 0) |
793 | return; | 794 | return; |
794 | while (len && isblank(buf[--len])) | 795 | while (len && isspace(buf[--len])) |
795 | buf[len] = '\0'; | 796 | buf[len] = '\0'; |
796 | 797 | ||
797 | if ((curNum == 0) && (lastNum > 0)) { | 798 | if ((curNum == 0) && (lastNum > 0)) { |
@@ -801,7 +802,7 @@ static void doCommands(void) | |||
801 | 802 | ||
802 | have1 = FALSE; | 803 | have1 = FALSE; |
803 | have2 = FALSE; | 804 | have2 = FALSE; |
804 | /* Don't pass &have1, &num1 to getNum() since this forces | 805 | /* Don't pass &haveN, &numN to getNum() since this forces |
805 | * compiler to keep them on stack, not in registers, | 806 | * compiler to keep them on stack, not in registers, |
806 | * which is usually quite suboptimal. | 807 | * which is usually quite suboptimal. |
807 | * Using intermediate variables shrinks code by ~150 bytes. | 808 | * Using intermediate variables shrinks code by ~150 bytes. |
@@ -811,7 +812,6 @@ static void doCommands(void) | |||
811 | continue; | 812 | continue; |
812 | have1 = h; | 813 | have1 = h; |
813 | num1 = n; | 814 | num1 = n; |
814 | |||
815 | cp = skip_whitespace(cp); | 815 | cp = skip_whitespace(cp); |
816 | if (*cp == ',') { | 816 | if (*cp == ',') { |
817 | cp = getNum(cp + 1, &h, &n); | 817 | cp = getNum(cp + 1, &h, &n); |
@@ -845,7 +845,7 @@ static void doCommands(void) | |||
845 | break; | 845 | break; |
846 | 846 | ||
847 | case 'f': | 847 | case 'f': |
848 | if (*cp && !isblank(*cp)) { | 848 | if (*cp != '\0' && *cp != ' ') { |
849 | bb_error_msg("bad file command"); | 849 | bb_error_msg("bad file command"); |
850 | break; | 850 | break; |
851 | } | 851 | } |
@@ -862,16 +862,18 @@ static void doCommands(void) | |||
862 | break; | 862 | break; |
863 | 863 | ||
864 | case 'i': | 864 | case 'i': |
865 | if (!have1 && lastNum == 0) | ||
866 | num1 = 1; | ||
865 | addLines(num1); | 867 | addLines(num1); |
866 | break; | 868 | break; |
867 | 869 | ||
868 | case 'k': | 870 | case 'k': |
869 | cp = skip_whitespace(cp); | 871 | cp = skip_whitespace(cp); |
870 | if ((*cp < 'a') || (*cp > 'z') || cp[1]) { | 872 | if ((unsigned)(*cp - 'a') >= 26 || cp[1]) { |
871 | bb_error_msg("bad mark name"); | 873 | bb_error_msg("bad mark name"); |
872 | break; | 874 | break; |
873 | } | 875 | } |
874 | marks[*cp - 'a'] = num2; | 876 | marks[(unsigned)(*cp - 'a')] = num2; |
875 | break; | 877 | break; |
876 | 878 | ||
877 | case 'l': | 879 | case 'l': |
@@ -900,7 +902,7 @@ static void doCommands(void) | |||
900 | break; | 902 | break; |
901 | 903 | ||
902 | case 'r': | 904 | case 'r': |
903 | if (*cp && !isblank(*cp)) { | 905 | if (*cp != '\0' && *cp != ' ') { |
904 | bb_error_msg("bad read command"); | 906 | bb_error_msg("bad read command"); |
905 | break; | 907 | break; |
906 | } | 908 | } |
@@ -922,20 +924,22 @@ static void doCommands(void) | |||
922 | break; | 924 | break; |
923 | 925 | ||
924 | case 'w': | 926 | case 'w': |
925 | if (*cp && !isblank(*cp)) { | 927 | if (*cp != '\0' && *cp != ' ') { |
926 | bb_error_msg("bad write command"); | 928 | bb_error_msg("bad write command"); |
927 | break; | 929 | break; |
928 | } | 930 | } |
929 | cp = skip_whitespace(cp); | 931 | cp = skip_whitespace(cp); |
932 | if (*cp == '\0') { | ||
933 | cp = fileName; | ||
934 | if (!cp) { | ||
935 | bb_error_msg("no file name specified"); | ||
936 | break; | ||
937 | } | ||
938 | } | ||
930 | if (!have1) { | 939 | if (!have1) { |
931 | num1 = 1; | 940 | num1 = 1; |
932 | num2 = lastNum; | 941 | num2 = lastNum; |
933 | } | 942 | dirty = FALSE; |
934 | if (*cp == '\0') | ||
935 | cp = fileName; | ||
936 | if (cp == NULL) { | ||
937 | bb_error_msg("no file name specified"); | ||
938 | break; | ||
939 | } | 943 | } |
940 | writeLines(cp, num1, num2); | 944 | writeLines(cp, num1, num2); |
941 | break; | 945 | break; |