1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-09 14:11:29 +00:00

Make conditional.lua use read_line too.

This commit is contained in:
d33tah
2013-09-04 14:33:39 +00:00
parent e718536eaf
commit 4b07187873

View File

@@ -2,6 +2,25 @@
--input and makes a decision according to what the user entered. All happens
--in an infinite loop.
--This function reads a line of at most 8096 bytes (or whatever the first
--parameter says) from standard input. Returns the string and a boolean value
--that is true if we hit the newline (defined as "\r" or "\n") or false if the
--line had to be truncated. This is here because io.stdin:read("*line") could
--read to memory exhaustion if we received gigabytes of characters with no
--newline.
function read_line(max_len)
local ret = ""
for i = 1, (max_len or 8096) do
local chr = io.read(1)
if chr == "\r" or chr == "\n" then
return ret, true
end
ret = ret .. chr
end
return ret, false
end
while true do
print "Here's a menu for you: "
@@ -10,7 +29,7 @@ while true do
io.write "Please enter your choice: "
io.flush(io.stdout)
i = io.read()
i = read_line()
--WARNING! Without this line, the script will go into an infinite loop
--that keeps consuming system resources when the connection gets broken.