diff options
author | Mark Whitley | 2001-04-20 23:41:44 +0000 |
---|---|---|
committer | Mark Whitley | 2001-04-20 23:41:44 +0000 |
commit | 56c14a647354b6b77fdc0c2f6c5e2f1c433ec410 (patch) | |
tree | b5893656cf9a09d97b7bc6e28617a91bfadbd298 | |
parent | 497ef4658755762d44e1b83e067c985f79f8cba5 (diff) | |
download | busybox-56c14a647354b6b77fdc0c2f6c5e2f1c433ec410.zip busybox-56c14a647354b6b77fdc0c2f6c5e2f1c433ec410.tar.gz |
Fixed a buglet where an extra newline was being added after an insert command
in some cases.
-rw-r--r-- | editors/sed.c | 17 | ||||
-rw-r--r-- | sed.c | 17 |
2 files changed, 20 insertions, 14 deletions
diff --git a/editors/sed.c b/editors/sed.c index 07e3a3e..1342a66 100644 --- a/editors/sed.c +++ b/editors/sed.c @@ -333,17 +333,20 @@ static int parse_edit_cmd(struct sed_cmd *sed_cmd, const char *editstr) } out: - ptr[idx] = '\n'; - ptr[idx+1] = 0; - /* this accounts for discrepancies between the modified string and the * original string passed in to this function */ idx += slashes_eaten; - /* this accounts for the fact that A) we started at index 3, not at index - * 0 and B) that we added an extra '\n' at the end (if you think the next - * line should read 'idx += 4' remember, arrays are zero-based) */ - idx += 3; + /* figure out if we need to add a newline */ + if (ptr[idx-1] != '\n') { + ptr[idx] = '\n'; + idx++; + } + + /* terminate string */ + ptr[idx]= 0; + /* adjust for opening 2 chars [aic]\ */ + idx += 2; return idx; } @@ -333,17 +333,20 @@ static int parse_edit_cmd(struct sed_cmd *sed_cmd, const char *editstr) } out: - ptr[idx] = '\n'; - ptr[idx+1] = 0; - /* this accounts for discrepancies between the modified string and the * original string passed in to this function */ idx += slashes_eaten; - /* this accounts for the fact that A) we started at index 3, not at index - * 0 and B) that we added an extra '\n' at the end (if you think the next - * line should read 'idx += 4' remember, arrays are zero-based) */ - idx += 3; + /* figure out if we need to add a newline */ + if (ptr[idx-1] != '\n') { + ptr[idx] = '\n'; + idx++; + } + + /* terminate string */ + ptr[idx]= 0; + /* adjust for opening 2 chars [aic]\ */ + idx += 2; return idx; } |