do_edit (sample/psql.rb)

    # File sample/psql.rb, line 382
    def do_edit(filename_arg, query)
      if filename_arg
        fname = filename_arg
        error = FALSE
      else
        fname = sprintf("/tmp/psql.rb.%d", $$)
        p fname
        if test(?e, fname)
          File.unlink(fname)
        end

        if query
          begin
            fd = File.new(fname, "w")
            if query[query.length-1, 1] != "\n"
              query += "\n"
            end
            if fd.print(query) != query.length
              fd.close
              File.unlink(fname)
              error = TRUE
            else
              error = FALSE
            end
            fd.close
          rescue
            error = TRUE
          end
        else
          error = FALSE
        end
      end

      if error
        status = 1
      else
        editFile(fname)
        begin
        fd = File.new(fname, "r")
          query = fd.read
          fd.close
          if query == nil
            status = 1
          else
            query.sub!(/[ \t\f\r\n]*$/, "")
            if query.length != 0
              status = 3
            else
              query  = nil
              status = 1
            end
          end
        rescue
          status = 1
        ensure
          if !filename_arg
            if test(?e, fname)
              File.unlink(fname)
            end
          end
        end
      end
      return status, query
    end