diff options
Diffstat (limited to '')
-rw-r--r-- | editors/sed.c | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/editors/sed.c b/editors/sed.c index 6179c5e80..204417108 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)." |
@@ -138,6 +141,9 @@ static const char semicolon_whitespace[] ALIGN1 = "; \n\r\t\v"; | |||
138 | struct globals { | 141 | struct globals { |
139 | /* options */ | 142 | /* options */ |
140 | int be_quiet, regex_type; | 143 | int be_quiet, regex_type; |
144 | #if ENABLE_PLATFORM_MINGW32 | ||
145 | int keep_cr; | ||
146 | #endif | ||
141 | 147 | ||
142 | FILE *nonstdout; | 148 | FILE *nonstdout; |
143 | char *outname, *hold_space; | 149 | char *outname, *hold_space; |
@@ -251,7 +257,12 @@ static FILE *sed_xfopen_w(const char *fname) | |||
251 | 257 | ||
252 | static void cleanup_outname(void) | 258 | static void cleanup_outname(void) |
253 | { | 259 | { |
254 | if (G.outname) unlink(G.outname); | 260 | if (G.outname) { |
261 | #if ENABLE_PLATFORM_MINGW32 | ||
262 | fclose(G.nonstdout); | ||
263 | #endif | ||
264 | unlink(G.outname); | ||
265 | } | ||
255 | } | 266 | } |
256 | 267 | ||
257 | /* strcpy, replacing "\from" with 'to'. If to is NUL, replacing "\any" with 'any' */ | 268 | /* strcpy, replacing "\from" with 'to'. If to is NUL, replacing "\any" with 'any' */ |
@@ -1065,6 +1076,11 @@ static char *get_next_line(char *gets_char, char *last_puts_char) | |||
1065 | char c = temp[len-1]; | 1076 | char c = temp[len-1]; |
1066 | if (c == '\n' || c == '\0') { | 1077 | if (c == '\n' || c == '\0') { |
1067 | temp[len-1] = '\0'; | 1078 | temp[len-1] = '\0'; |
1079 | #if ENABLE_PLATFORM_MINGW32 | ||
1080 | if (!G.keep_cr && c == '\n' && len > 1 && temp[len-2] == '\r') { | ||
1081 | temp[len-2] = '\0'; | ||
1082 | } | ||
1083 | #endif | ||
1068 | gc = c; | 1084 | gc = c; |
1069 | if (c == '\0') { | 1085 | if (c == '\0') { |
1070 | int ch = fgetc(fp); | 1086 | int ch = fgetc(fp); |
@@ -1541,7 +1557,12 @@ int sed_main(int argc UNUSED_PARAM, char **argv) | |||
1541 | "quiet\0" No_argument "n" | 1557 | "quiet\0" No_argument "n" |
1542 | "silent\0" No_argument "n" | 1558 | "silent\0" No_argument "n" |
1543 | "expression\0" Required_argument "e" | 1559 | "expression\0" Required_argument "e" |
1560 | # if !ENABLE_PLATFORM_MINGW32 | ||
1544 | "file\0" Required_argument "f"; | 1561 | "file\0" Required_argument "f"; |
1562 | # else | ||
1563 | "file\0" Required_argument "f" | ||
1564 | "binary\0" No_argument "b"; | ||
1565 | # endif | ||
1545 | #endif | 1566 | #endif |
1546 | 1567 | ||
1547 | INIT_G(); | 1568 | INIT_G(); |
@@ -1565,6 +1586,7 @@ int sed_main(int argc UNUSED_PARAM, char **argv) | |||
1565 | */ | 1586 | */ |
1566 | opt = getopt32long(argv, "^" | 1587 | opt = getopt32long(argv, "^" |
1567 | "i::rEne:*f:*" | 1588 | "i::rEne:*f:*" |
1589 | IF_PLATFORM_MINGW32("b") | ||
1568 | "\0" "nn"/*count -n*/, | 1590 | "\0" "nn"/*count -n*/, |
1569 | sed_longopts, | 1591 | sed_longopts, |
1570 | &opt_i, &opt_e, &opt_f, | 1592 | &opt_i, &opt_e, &opt_f, |
@@ -1578,6 +1600,10 @@ int sed_main(int argc UNUSED_PARAM, char **argv) | |||
1578 | G.regex_type |= REG_EXTENDED; // -r or -E | 1600 | G.regex_type |= REG_EXTENDED; // -r or -E |
1579 | //if (opt & 8) | 1601 | //if (opt & 8) |
1580 | // G.be_quiet++; // -n (implemented with a counter instead) | 1602 | // G.be_quiet++; // -n (implemented with a counter instead) |
1603 | #if ENABLE_PLATFORM_MINGW32 | ||
1604 | if (opt & 0x40) | ||
1605 | G.keep_cr = 1; | ||
1606 | #endif | ||
1581 | while (opt_e) { // -e | 1607 | while (opt_e) { // -e |
1582 | add_cmd_block(llist_pop(&opt_e)); | 1608 | add_cmd_block(llist_pop(&opt_e)); |
1583 | } | 1609 | } |