summaryrefslogtreecommitdiff
path: root/editors/sed.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--editors/sed.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/editors/sed.c b/editors/sed.c
index bb39de149..a5cedbd8d 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";
132struct globals { 135struct 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);
@@ -1498,7 +1509,12 @@ int sed_main(int argc UNUSED_PARAM, char **argv)
1498 "quiet\0" No_argument "n" 1509 "quiet\0" No_argument "n"
1499 "silent\0" No_argument "n" 1510 "silent\0" No_argument "n"
1500 "expression\0" Required_argument "e" 1511 "expression\0" Required_argument "e"
1512# if !ENABLE_PLATFORM_MINGW32
1501 "file\0" Required_argument "f"; 1513 "file\0" Required_argument "f";
1514# else
1515 "file\0" Required_argument "f"
1516 "binary\0" No_argument "b";
1517# endif
1502#endif 1518#endif
1503 1519
1504 INIT_G(); 1520 INIT_G();
@@ -1522,6 +1538,7 @@ int sed_main(int argc UNUSED_PARAM, char **argv)
1522 */ 1538 */
1523 opt = getopt32long(argv, "^" 1539 opt = getopt32long(argv, "^"
1524 "i::rEne:*f:*" 1540 "i::rEne:*f:*"
1541 IF_PLATFORM_MINGW32("b")
1525 "\0" "nn"/*count -n*/, 1542 "\0" "nn"/*count -n*/,
1526 sed_longopts, 1543 sed_longopts,
1527 &opt_i, &opt_e, &opt_f, 1544 &opt_i, &opt_e, &opt_f,
@@ -1535,6 +1552,10 @@ int sed_main(int argc UNUSED_PARAM, char **argv)
1535 G.regex_type |= REG_EXTENDED; // -r or -E 1552 G.regex_type |= REG_EXTENDED; // -r or -E
1536 //if (opt & 8) 1553 //if (opt & 8)
1537 // G.be_quiet++; // -n (implemented with a counter instead) 1554 // G.be_quiet++; // -n (implemented with a counter instead)
1555#if ENABLE_PLATFORM_MINGW32
1556 if (opt & 0x40)
1557 G.keep_cr = 1;
1558#endif
1538 while (opt_e) { // -e 1559 while (opt_e) { // -e
1539 add_cmd_block(llist_pop(&opt_e)); 1560 add_cmd_block(llist_pop(&opt_e));
1540 } 1561 }