diff options
author | Solderpunk <solderpunk@sdf.org> | 2018-12-08 13:19:26 +0000 |
---|---|---|
committer | Solderpunk <solderpunk@sdf.org> | 2018-12-08 13:19:26 +0000 |
commit | 0ef3cf5bfe7de296d954674b0ec551af7ab7108f (patch) | |
tree | 8af60f7b3add0cb388bc045a36bb2c6e5a8ec182 | |
parent | Add "last" option to "type" command. (diff) |
Declare many things as local variables.
Diffstat (limited to '')
-rwxr-xr-x | telem.lua | 47 |
1 files changed, 23 insertions, 24 deletions
@@ -39,9 +39,8 @@ function show_prompt() end function getchar() - local char os.execute("/bin/stty -icanon") - char = io.read(1) + local char = io.read(1) os.execute("/bin/stty icanon") return char end @@ -50,7 +49,7 @@ function get_threads(board) local threads = {} for topic in lfs.dir(path.join(_BBS_ROOT, "boards", board)) do if bad_topics[topic] == nil then - thread = {} + local thread = {} thread.filename = topic thread.directory = path.join(_BBS_ROOT, "boards", board, topic) _, _, timestamp, thread.author = string.find(topic, "(%d+)-(%g+)") @@ -60,7 +59,7 @@ function get_threads(board) thread.subject = io.read("*line") io.input(io.stdin) - posts = get_posts(thread) + local posts = get_posts(thread) thread.post_count = #posts thread.updated = 0 for _, post in ipairs(posts) do @@ -81,7 +80,7 @@ function get_posts(thread) for reply in lfs.dir(thread.directory) do if string.sub(reply, 1,1) == "." then goto continue end if reply == "subject" then goto continue end - post = {} + local post = {} post.filename = path.join(thread.directory, reply) if reply == "original" then post.author = thread.author @@ -102,18 +101,18 @@ function do_board() -- Get details io.write("New board name? (Max 18 chars) ") - board = string.upper(io.read()) + local board = string.upper(io.read()) if string.len(board) > 18 then print("Board names must be 18 characters or less!") return end io.write("Description? ") - desc = io.read() + local desc = io.read() -- Create directory - board_dir = path.join(_BBS_ROOT, "boards", board) + local board_dir = path.join(_BBS_ROOT, "boards", board) lfs.mkdir(board_dir) -- Write topic file - topic_file = path.join(board_dir, "topic") + local topic_file = path.join(board_dir, "topic") file.write(topic_file, desc) -- Update representation of BBS boards[board] = true @@ -125,7 +124,7 @@ end function do_go() io.write("Go to which board? ") - board = string.upper(io.read()) + local board = string.upper(io.read()) if board == "" then do_list() elseif boards[board] == nil then @@ -149,7 +148,7 @@ end function do_list() for _,b in pairs(board_names) do - posts = -3 -- Don't want to count "topic" file or "." or ".." + local posts = -3 -- Don't want to count "topic" file or "." or ".." for topic in lfs.dir(path.join(_BBS_ROOT, "boards", b)) do posts = posts +1 end @@ -177,27 +176,27 @@ function do_new() end -- Get subject for new thread io.write("Subject? ") - subject = io.read() + local subject = io.read() if string.len(subject) > 48 then print("Thread subjects must be 48 characters or less!") return end -- Save body of post to temp file - filename = os.tmpname() + local filename = os.tmpname() os.execute("$EDITOR " .. filename) -- TODO: show and confirm -- Make thread dir - timestamp = tostring(os.time()) - thread_dir = timestamp .. "-" .. username - thread_path = path.join(_BBS_ROOT, "boards", current_board, thread_dir) + local timestamp = tostring(os.time()) + local thread_dir = timestamp .. "-" .. username + local thread_path = path.join(_BBS_ROOT, "boards", current_board, thread_dir) lfs.mkdir(thread_path) -- Write subject file file.write(path.join(thread_path, "subject"), subject) -- Move post file - post_file = thread_dir -- first post and thread directory names are the same! - newpath = path.join(thread_path, post_file) - ret, str = file.move(filename, newpath) + local post_file = thread_dir -- first post and thread directory names are the same! + local newpath = path.join(thread_path, post_file) + local ret, str = file.move(filename, newpath) if not ret then print(str) end @@ -232,12 +231,12 @@ function do_type_prev() end function do_type_reply() - filename = os.tmpname() + local filename = os.tmpname() os.execute("$EDITOR " .. filename) - timestamp = tostring(os.time()) - newfilename = timestamp .. "-" .. username - newpath = path.join(thread.directory, newfilename) - ret, str = file.move(filename, newpath) + local timestamp = tostring(os.time()) + local newfilename = timestamp .. "-" .. username + local newpath = path.join(thread.directory, newfilename) + local ret, str = file.move(filename, newpath) if not ret then print(str) end |