From 580db706b7d3724a820bd3853d97cde27fc416ac Mon Sep 17 00:00:00 2001
From: Oliver Webb <aquahobbyist@proton.me>
Date: Mon, 29 Apr 2024 16:24:05 -0500
Subject: [PATCH] strings: -s

---
 toys/posix/strings.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/toys/posix/strings.c b/toys/posix/strings.c
index 816280b0..b8316566 100644
--- a/toys/posix/strings.c
+++ b/toys/posix/strings.c
@@ -12,7 +12,7 @@
  *
  * TODO: utf8 strings
 
-USE_STRINGS(NEWTOY(strings, "t:an#=4<1fo", TOYFLAG_USR|TOYFLAG_BIN))
+USE_STRINGS(NEWTOY(strings, "t:an#=4<1fow", TOYFLAG_USR|TOYFLAG_BIN))
 
 config STRINGS
   bool "strings"
@@ -26,6 +26,7 @@ config STRINGS
     -n	At least LEN characters form a string (default 4)
     -o	Show offset (ala -t d)
     -t	Show offset type (o=octal, d=decimal, x=hexadecimal)
+    -w  Count '\r' and '\n' as part of a string
 */
 
 #define FOR_strings
@@ -61,21 +62,22 @@ static void do_strings(int fd, char *filename)
     }
 
     offset++;
-    if ((toybuf[i]>=32 && toybuf[i]<=126) || toybuf[i]=='\t') {
+    if ((toybuf[i]>=32 && toybuf[i]<=126) || toybuf[i]=='\t' ||
+      (FLAG(w) && (toybuf[i] == '\n' || toybuf[i] == '\r'))) {
       if (count == wlen) fputc(toybuf[i], stdout);
       else {
         string[count++] = toybuf[i];
         if (count == wlen) {
           if (FLAG(f)) printf("%s: ", filename);
           if (FLAG(o) || FLAG(t)) printf(pattern, (long long)(offset - wlen));
-          printf("%s", string);
+          xputsn(string);
         }
       }
       continue;
     }
 flush:
     // End of previous string
-    if (count == wlen) xputc('\n');
+    if (count == wlen) xputsn("\n");
     count = 0;
   }
   xclose(fd);
-- 
2.44.0

