diff options
Diffstat (limited to 'editors/sed.c')
-rw-r--r-- | editors/sed.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/editors/sed.c b/editors/sed.c index 57d3dda16..a93e5494a 100644 --- a/editors/sed.c +++ b/editors/sed.c | |||
@@ -74,6 +74,9 @@ | |||
74 | //usage: "\n Optionally back files up, appending SFX" | 74 | //usage: "\n Optionally back files up, appending SFX" |
75 | //usage: "\n -n Suppress automatic printing of pattern space" | 75 | //usage: "\n -n Suppress automatic printing of pattern space" |
76 | //usage: "\n -r,-E Use extended regex syntax" | 76 | //usage: "\n -r,-E Use extended regex syntax" |
77 | //usage: IF_PLATFORM_MINGW32( | ||
78 | //usage: "\n -b Keep CR/LF (Windows-only)" | ||
79 | //usage: ) | ||
77 | //usage: "\n" | 80 | //usage: "\n" |
78 | //usage: "\nIf no -e or -f, the first non-option argument is the sed command string." | 81 | //usage: "\nIf no -e or -f, the first non-option argument is the sed command string." |
79 | //usage: "\nRemaining arguments are input files (stdin if none)." | 82 | //usage: "\nRemaining arguments are input files (stdin if none)." |
@@ -132,6 +135,9 @@ static const char semicolon_whitespace[] ALIGN1 = "; \n\r\t\v"; | |||
132 | struct globals { | 135 | struct globals { |
133 | /* options */ | 136 | /* options */ |
134 | int be_quiet, regex_type; | 137 | int be_quiet, regex_type; |
138 | #if ENABLE_PLATFORM_MINGW32 | ||
139 | int keep_cr; | ||
140 | #endif | ||
135 | 141 | ||
136 | FILE *nonstdout; | 142 | FILE *nonstdout; |
137 | char *outname, *hold_space; | 143 | char *outname, *hold_space; |
@@ -1024,6 +1030,11 @@ static char *get_next_line(char *gets_char, char *last_puts_char) | |||
1024 | char c = temp[len-1]; | 1030 | char c = temp[len-1]; |
1025 | if (c == '\n' || c == '\0') { | 1031 | if (c == '\n' || c == '\0') { |
1026 | temp[len-1] = '\0'; | 1032 | temp[len-1] = '\0'; |
1033 | #if ENABLE_PLATFORM_MINGW32 | ||
1034 | if (!G.keep_cr && c == '\n' && len > 1 && temp[len-2] == '\r') { | ||
1035 | temp[len-2] = '\0'; | ||
1036 | } | ||
1037 | #endif | ||
1027 | gc = c; | 1038 | gc = c; |
1028 | if (c == '\0') { | 1039 | if (c == '\0') { |
1029 | int ch = fgetc(fp); | 1040 | int ch = fgetc(fp); |
@@ -1500,7 +1511,12 @@ int sed_main(int argc UNUSED_PARAM, char **argv) | |||
1500 | "quiet\0" No_argument "n" | 1511 | "quiet\0" No_argument "n" |
1501 | "silent\0" No_argument "n" | 1512 | "silent\0" No_argument "n" |
1502 | "expression\0" Required_argument "e" | 1513 | "expression\0" Required_argument "e" |
1514 | # if !ENABLE_PLATFORM_MINGW32 | ||
1503 | "file\0" Required_argument "f"; | 1515 | "file\0" Required_argument "f"; |
1516 | # else | ||
1517 | "file\0" Required_argument "f" | ||
1518 | "binary\0" No_argument "b"; | ||
1519 | # endif | ||
1504 | #endif | 1520 | #endif |
1505 | 1521 | ||
1506 | INIT_G(); | 1522 | INIT_G(); |
@@ -1524,6 +1540,7 @@ int sed_main(int argc UNUSED_PARAM, char **argv) | |||
1524 | */ | 1540 | */ |
1525 | opt = getopt32long(argv, "^" | 1541 | opt = getopt32long(argv, "^" |
1526 | "i::rEne:*f:*" | 1542 | "i::rEne:*f:*" |
1543 | IF_PLATFORM_MINGW32("b") | ||
1527 | "\0" "nn"/*count -n*/, | 1544 | "\0" "nn"/*count -n*/, |
1528 | sed_longopts, | 1545 | sed_longopts, |
1529 | &opt_i, &opt_e, &opt_f, | 1546 | &opt_i, &opt_e, &opt_f, |
@@ -1537,6 +1554,10 @@ int sed_main(int argc UNUSED_PARAM, char **argv) | |||
1537 | G.regex_type |= REG_EXTENDED; // -r or -E | 1554 | G.regex_type |= REG_EXTENDED; // -r or -E |
1538 | //if (opt & 8) | 1555 | //if (opt & 8) |
1539 | // G.be_quiet++; // -n (implemented with a counter instead) | 1556 | // G.be_quiet++; // -n (implemented with a counter instead) |
1557 | #if ENABLE_PLATFORM_MINGW32 | ||
1558 | if (opt & 0x40) | ||
1559 | G.keep_cr = 1; | ||
1560 | #endif | ||
1540 | while (opt_e) { // -e | 1561 | while (opt_e) { // -e |
1541 | add_cmd_block(llist_pop(&opt_e)); | 1562 | add_cmd_block(llist_pop(&opt_e)); |
1542 | } | 1563 | } |