diff options
author | Johannes Schindelin <johannes.schindelin@gmx.de> | 2017-08-23 13:31:16 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2017-08-23 13:31:16 +0100 |
commit | 5446bac31b5f02eb3337e7e528c3c24ff006bd8d (patch) | |
tree | 43bf3c212072f045c4e18542a16c266390cf3c2f | |
parent | 272b07a50f6c5b52243a4a53f4ea6c7f5ca4fe7f (diff) | |
download | busybox-w32-5446bac31b5f02eb3337e7e528c3c24ff006bd8d.tar.gz busybox-w32-5446bac31b5f02eb3337e7e528c3c24ff006bd8d.tar.bz2 busybox-w32-5446bac31b5f02eb3337e7e528c3c24ff006bd8d.zip |
sed: support the -b/--binary option
This option was introduced in Cygwin's and MSYS2's sed, to allow for
keeping Carriage Returns (otherwise, they would be stripped and the
output would always be LF-only).
Git for Windows' test suite relies on the presence of this option.
It was easy enough to implement, too.
Conditional compilation added by rmy.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Ron Yorston <rmy@pobox.com>
-rw-r--r-- | editors/sed.c | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/editors/sed.c b/editors/sed.c index d6e25aedc..e2c6690bb 100644 --- a/editors/sed.c +++ b/editors/sed.c | |||
@@ -77,6 +77,9 @@ | |||
77 | //usage: "\n Optionally back files up, appending SFX" | 77 | //usage: "\n Optionally back files up, appending SFX" |
78 | //usage: "\n -n Suppress automatic printing of pattern space" | 78 | //usage: "\n -n Suppress automatic printing of pattern space" |
79 | //usage: "\n -r,-E Use extended regex syntax" | 79 | //usage: "\n -r,-E Use extended regex syntax" |
80 | //usage: IF_PLATFORM_MINGW32( | ||
81 | //usage: "\n -b Keep CR/LF (Windows-only)" | ||
82 | //usage: ) | ||
80 | //usage: "\n" | 83 | //usage: "\n" |
81 | //usage: "\nIf no -e or -f, the first non-option argument is the sed command string." | 84 | //usage: "\nIf no -e or -f, the first non-option argument is the sed command string." |
82 | //usage: "\nRemaining arguments are input files (stdin if none)." | 85 | //usage: "\nRemaining arguments are input files (stdin if none)." |
@@ -135,6 +138,9 @@ static const char semicolon_whitespace[] ALIGN1 = "; \n\r\t\v"; | |||
135 | struct globals { | 138 | struct globals { |
136 | /* options */ | 139 | /* options */ |
137 | int be_quiet, regex_type; | 140 | int be_quiet, regex_type; |
141 | #if ENABLE_PLATFORM_MINGW32 | ||
142 | int keep_cr; | ||
143 | #endif | ||
138 | 144 | ||
139 | FILE *nonstdout; | 145 | FILE *nonstdout; |
140 | char *outname, *hold_space; | 146 | char *outname, *hold_space; |
@@ -1017,7 +1023,7 @@ static char *get_next_line(char *gets_char, char *last_puts_char) | |||
1017 | if (c == '\n' || c == '\0') { | 1023 | if (c == '\n' || c == '\0') { |
1018 | temp[len-1] = '\0'; | 1024 | temp[len-1] = '\0'; |
1019 | #if ENABLE_PLATFORM_MINGW32 | 1025 | #if ENABLE_PLATFORM_MINGW32 |
1020 | if (c == '\n' && len > 1 && temp[len-2] == '\r') { | 1026 | if (!G.keep_cr && c == '\n' && len > 1 && temp[len-2] == '\r') { |
1021 | temp[len-2] = '\0'; | 1027 | temp[len-2] = '\0'; |
1022 | } | 1028 | } |
1023 | #endif | 1029 | #endif |
@@ -1495,7 +1501,12 @@ int sed_main(int argc UNUSED_PARAM, char **argv) | |||
1495 | "quiet\0" No_argument "n" | 1501 | "quiet\0" No_argument "n" |
1496 | "silent\0" No_argument "n" | 1502 | "silent\0" No_argument "n" |
1497 | "expression\0" Required_argument "e" | 1503 | "expression\0" Required_argument "e" |
1504 | # if !ENABLE_PLATFORM_MINGW32 | ||
1498 | "file\0" Required_argument "f"; | 1505 | "file\0" Required_argument "f"; |
1506 | # else | ||
1507 | "file\0" Required_argument "f" | ||
1508 | "binary\0" No_argument "b"; | ||
1509 | # endif | ||
1499 | #endif | 1510 | #endif |
1500 | 1511 | ||
1501 | INIT_G(); | 1512 | INIT_G(); |
@@ -1519,6 +1530,7 @@ int sed_main(int argc UNUSED_PARAM, char **argv) | |||
1519 | */ | 1530 | */ |
1520 | opt = getopt32long(argv, "^" | 1531 | opt = getopt32long(argv, "^" |
1521 | "i::rEne:*f:*" | 1532 | "i::rEne:*f:*" |
1533 | IF_PLATFORM_MINGW32("b") | ||
1522 | "\0" "nn"/*count -n*/, | 1534 | "\0" "nn"/*count -n*/, |
1523 | sed_longopts, | 1535 | sed_longopts, |
1524 | &opt_i, &opt_e, &opt_f, | 1536 | &opt_i, &opt_e, &opt_f, |
@@ -1532,6 +1544,10 @@ int sed_main(int argc UNUSED_PARAM, char **argv) | |||
1532 | G.regex_type |= REG_EXTENDED; // -r or -E | 1544 | G.regex_type |= REG_EXTENDED; // -r or -E |
1533 | //if (opt & 8) | 1545 | //if (opt & 8) |
1534 | // G.be_quiet++; // -n (implemented with a counter instead) | 1546 | // G.be_quiet++; // -n (implemented with a counter instead) |
1547 | #if ENABLE_PLATFORM_MINGW32 | ||
1548 | if (opt & 0x40) | ||
1549 | G.keep_cr = 1; | ||
1550 | #endif | ||
1535 | while (opt_e) { // -e | 1551 | while (opt_e) { // -e |
1536 | add_cmd_block(llist_pop(&opt_e)); | 1552 | add_cmd_block(llist_pop(&opt_e)); |
1537 | } | 1553 | } |