From 36fe342ffd3dd5cbbba9308b56e6054fb15bbeef Mon Sep 17 00:00:00 2001 From: dockes Date: Sun, 4 Dec 2005 17:10:22 +0000 Subject: [PATCH] split stdin --- src/common/textsplit.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/common/textsplit.cpp b/src/common/textsplit.cpp index fea9c006..28779fa0 100644 --- a/src/common/textsplit.cpp +++ b/src/common/textsplit.cpp @@ -1,5 +1,5 @@ #ifndef lint -static char rcsid[] = "@(#$Id: textsplit.cpp,v 1.14 2005-11-24 07:16:15 dockes Exp $ (C) 2004 J.F.Dockes"; +static char rcsid[] = "@(#$Id: textsplit.cpp,v 1.15 2005-12-04 17:10:22 dockes Exp $ (C) 2004 J.F.Dockes"; #endif #ifndef TEST_TEXTSPLIT @@ -372,6 +372,7 @@ static string thisprog; static string usage = " textsplit [opts] [filename]\n" " -q: query mode\n" + " if filename is 'stdin', will read stdin for data (end with ^D)\n" " \n\n" ; @@ -408,9 +409,15 @@ int main(int argc, char **argv) TextSplit splitter(&cb, (op_flags&OPT_q) ? true: false); if (argc == 1) { string data; - if (!file_to_string(*argv++, data)) + const char *filename = *argv++; argc--; + if (!strcmp(filename, "stdin")) { + char buf[1024]; + int nread; + while ((nread = read(0, buf, 1024)) > 0) { + data.append(buf, nread); + } + } else if (!file_to_string(filename, data)) exit(1); - argc--; splitter.text_to_words(data); } else { cout << endl << teststring << endl << endl;