summaryrefslogtreecommitdiff
path: root/it.class
diff options
context:
space:
mode:
authorNathan Gass2025-08-26 11:57:39 +0200
committerNathan Gass2025-08-26 12:07:42 +0200
commit5bf20a8a1bd331c1f8e36212cffde2c0d6f94c9d (patch)
tree93690529c73b80f75bb676710cb0e11f007de7af /it.class
parent90a3b712e4f5df5832f219562703af4d43b1ae06 (diff)
downloaditools-5bf20a8a1bd331c1f8e36212cffde2c0d6f94c9d.tar.gz
itools-5bf20a8a1bd331c1f8e36212cffde2c0d6f94c9d.tar.bz2
itools-5bf20a8a1bd331c1f8e36212cffde2c0d6f94c9d.zip
add it::gets_all variant of it::gets
Diffstat (limited to 'it.class')
-rw-r--r--it.class16
1 files changed, 16 insertions, 0 deletions
diff --git a/it.class b/it.class
index 88724b1..ebdaf6e 100644
--- a/it.class
+++ b/it.class
@@ -1021,6 +1021,22 @@ static function _stdin_next()
}
/**
+ * Get all lines from command line arguments or stdin.
+ * Transparently reads existing files in the command line arguments and passes on all other arguments.
+ * Note: You need to call getopt() before using this function.
+ */
+static function gets_all()
+{
+ while (it::_stdin_next()) {
+ if (($fd = $GLOBALS['it_stdin']['fd']))
+ while ($line = fgets($fd))
+ yield rtrim($line, "\n");
+ else
+ yield $GLOBALS['it_stdin']['filename'];
+ }
+}
+
+/**
* Get one line from stdin (or files given on command line) a la Perl <>.
* Note: You need to call getopt() before using this function.
* @return Line (including newline) or false on eof