I/O


FIXME: Make this the __len metamethod
length: Find the length of a file
  f: file name
returns
  len: length of file, or nil on error


FIXME: Use this POSIX implementation
require "posix"
function length (f)
local s = posix.stat (f)
  if s then
    return s.size
  else
    return nil
  end
end


readLines: Read a file into a list of lines and close it
  [h]: file handle or name [io.input ()]
returns
  l: list of lines


writeLine: Write values adding a newline after each
  [h]: file handle [io.output ()]
  ...: values to write (as for write)


basename: POSIX basename
  @param path
returns
  base: base name


dirname: POSIX dirname
  @param path
returns
  dir: directory component


changeSuffix: Change the suffix of a filename
  from: suffix to change (".-" for any suffix)
  to: suffix to replace with
  name: file name to change
returns
  name_: file name with new suffix


addSuffix: Add a suffix to a filename if not already present
  suff: suffix to add
  name: file name to change
returns
  name_: file name with new suffix


shell: Perform a shell command and return its output
  c: command
returns
  o: output, or nil if error


processFiles: Process files specified on the command-line
If no files given, process io.stdin; in list of files, "-" means
io.stdin
  f: function to process files with
    name: the name of the file being read
    i: the number of the argument