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 6179c5e80..107e664a0 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; |
@@ -1065,6 +1071,11 @@ static char *get_next_line(char *gets_char, char *last_puts_char) | |||
1065 | char c = temp[len-1]; | 1071 | char c = temp[len-1]; |
1066 | if (c == '\n' || c == '\0') { | 1072 | if (c == '\n' || c == '\0') { |
1067 | temp[len-1] = '\0'; | 1073 | temp[len-1] = '\0'; |
1074 | #if ENABLE_PLATFORM_MINGW32 | ||
1075 | if (!G.keep_cr && c == '\n' && len > 1 && temp[len-2] == '\r') { | ||
1076 | temp[len-2] = '\0'; | ||
1077 | } | ||
1078 | #endif | ||
1068 | gc = c; | 1079 | gc = c; |
1069 | if (c == '\0') { | 1080 | if (c == '\0') { |
1070 | int ch = fgetc(fp); | 1081 | int ch = fgetc(fp); |
@@ -1541,7 +1552,12 @@ int sed_main(int argc UNUSED_PARAM, char **argv) | |||
1541 | "quiet\0" No_argument "n" | 1552 | "quiet\0" No_argument "n" |
1542 | "silent\0" No_argument "n" | 1553 | "silent\0" No_argument "n" |
1543 | "expression\0" Required_argument "e" | 1554 | "expression\0" Required_argument "e" |
1555 | # if !ENABLE_PLATFORM_MINGW32 | ||
1544 | "file\0" Required_argument "f"; | 1556 | "file\0" Required_argument "f"; |
1557 | # else | ||
1558 | "file\0" Required_argument "f" | ||
1559 | "binary\0" No_argument "b"; | ||
1560 | # endif | ||
1545 | #endif | 1561 | #endif |
1546 | 1562 | ||
1547 | INIT_G(); | 1563 | INIT_G(); |
@@ -1565,6 +1581,7 @@ int sed_main(int argc UNUSED_PARAM, char **argv) | |||
1565 | */ | 1581 | */ |
1566 | opt = getopt32long(argv, "^" | 1582 | opt = getopt32long(argv, "^" |
1567 | "i::rEne:*f:*" | 1583 | "i::rEne:*f:*" |
1584 | IF_PLATFORM_MINGW32("b") | ||
1568 | "\0" "nn"/*count -n*/, | 1585 | "\0" "nn"/*count -n*/, |
1569 | sed_longopts, | 1586 | sed_longopts, |
1570 | &opt_i, &opt_e, &opt_f, | 1587 | &opt_i, &opt_e, &opt_f, |
@@ -1578,6 +1595,10 @@ int sed_main(int argc UNUSED_PARAM, char **argv) | |||
1578 | G.regex_type |= REG_EXTENDED; // -r or -E | 1595 | G.regex_type |= REG_EXTENDED; // -r or -E |
1579 | //if (opt & 8) | 1596 | //if (opt & 8) |
1580 | // G.be_quiet++; // -n (implemented with a counter instead) | 1597 | // G.be_quiet++; // -n (implemented with a counter instead) |
1598 | #if ENABLE_PLATFORM_MINGW32 | ||
1599 | if (opt & 0x40) | ||
1600 | G.keep_cr = 1; | ||
1601 | #endif | ||
1581 | while (opt_e) { // -e | 1602 | while (opt_e) { // -e |
1582 | add_cmd_block(llist_pop(&opt_e)); | 1603 | add_cmd_block(llist_pop(&opt_e)); |
1583 | } | 1604 | } |