[hackers] [sbase] Add strings(1) || sin
 
commit 0ed2a550037fdd96af7756639cf3210a20deb852
Author: sin <sin_AT_2f30.org>
Date:   Wed Aug 14 10:41:55 2013 +0100
    Add strings(1)
diff --git a/Makefile b/Makefile
index 80f916e..fcf28f3 100644
--- a/Makefile
+++ b/Makefile
_AT_@ -70,6 +70,7 @@ SRC = \
         sort.c     \
         split.c    \
         sponge.c   \
+	strings.c  \
         sync.c     \
         tail.c     \
         tar.c      \
diff --git a/strings.1 b/strings.1
new file mode 100644
index 0000000..11e2293
--- /dev/null
+++ b/strings.1
_AT_@ -0,0 +1,10 @@
+.TH STRINGS 1 sbase\-VERSION
+.SH NAME
+strings \- print the strings of printable characters in files
+.SH SYNOPSIS
+.B strings
+.IR [file...]
+.SH DESCRIPTION
+.B strings
+prints the printable character sequences that are at least 6 characters
+long.  If no files are given then it uses stdin.
diff --git a/strings.c b/strings.c
new file mode 100644
index 0000000..55a8f07
--- /dev/null
+++ b/strings.c
_AT_@ -0,0 +1,56 @@
+/* See LICENSE file for copyright and license details. */
+#include <stdio.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include "util.h"
+
+static void dostrings(FILE *fp, const char *fname);
+
+static void
+usage(void)
+{
+	eprintf("usage: %s file
", argv0);
+}
+
+int
+main(int argc, char *argv[])
+{
+	FILE *fp;
+
+	ARGBEGIN {
+	default:
+		usage();
+	} ARGEND;
+
+	if (argc > 0) {
+		if (!(fp = fopen(argv[0], "r")))
+			eprintf("open %s:", argv[0]);
+		dostrings(fp, argv[0]);
+		fclose(fp);
+	} else {
+		dostrings(stdin, "<stdin>");
+	}
+
+	return 0;
+}
+
+static void
+dostrings(FILE *fp, const char *fname)
+{
+	unsigned char buf[BUFSIZ];
+	int c, i = 0;
+	off_t offset = 0;
+
+	do {
+		offset++;
+		if (isprint(c = getc(fp)))
+			buf[i++] = c;
+		if ((!isprint(c) && i >= 6) || i == sizeof(buf) - 1) {
+			buf[i] = '
Received on Sat Oct 05 2013 - 16:29:39 CEST
This archive was generated by hypermail 2.3.0
: Sat Oct 05 2013 - 16:36:51 CEST