From 70a4dff190f5b471c671007f830ce42bbad4d24b Mon Sep 17 00:00:00 2001 From: Doug Kearns Date: Tue, 16 Oct 2007 01:53:37 +0000 Subject: [PATCH] move LocalFile and fopen to a vimperator.io namespace --- content/completion.js | 2 +- content/file.js | 41 +++++++++++++++++++++++------------------ content/mappings.js | 2 +- content/vimperator.js | 13 ++++--------- 4 files changed, 29 insertions(+), 29 deletions(-) diff --git a/content/completion.js b/content/completion.js index c35950dd..7971e328 100644 --- a/content/completion.js +++ b/content/completion.js @@ -254,7 +254,7 @@ vimperator.completion = (function() // {{{ try { - var fd = vimperator.fopen(dir); + var fd = vimperator.io.fopen(dir); } catch (e) { diff --git a/content/file.js b/content/file.js index 5295be3e..9f4e2cac 100644 --- a/content/file.js +++ b/content/file.js @@ -27,22 +27,27 @@ the provisions above, a recipient may use your version of this file under the terms of any one of the MPL, the GPL or the LGPL. }}} ***** END LICENSE BLOCK *****/ +vimperator.io = {}; -const PERM_IWOTH = 00002; /* write permission, others */ -const PERM_IWGRP = 00020; /* write permission, group */ - -const MODE_RDONLY = 0x01; -const MODE_WRONLY = 0x02; -const MODE_RDWR = 0x04; -const MODE_CREATE = 0x08; -const MODE_APPEND = 0x10; -const MODE_TRUNCATE = 0x20; -const MODE_SYNC = 0x40; -const MODE_EXCL = 0x80; - - -function LocalFile(file, mode, perms, tmp) // {{{ +vimperator.io.fopen = function(path, mode, perms, tmp) { + return new vimperator.io.LocalFile(path, mode, perms, tmp); +} + +vimperator.io.LocalFile = function(file, mode, perms, tmp) // {{{ +{ + const PERM_IWOTH = 00002; /* write permission, others */ + const PERM_IWGRP = 00020; /* write permission, group */ + + const MODE_RDONLY = 0x01; + const MODE_WRONLY = 0x02; + const MODE_RDWR = 0x04; + const MODE_CREATE = 0x08; + const MODE_APPEND = 0x10; + const MODE_TRUNCATE = 0x20; + const MODE_SYNC = 0x40; + const MODE_EXCL = 0x80; + const classes = Components.classes; const interfaces = Components.interfaces; @@ -116,7 +121,7 @@ function LocalFile(file, mode, perms, tmp) // {{{ } -LocalFile.prototype.write = +vimperator.io.LocalFile.prototype.write = function fo_write(buf) { if (!("outputStream" in this)) @@ -125,7 +130,7 @@ function fo_write(buf) return this.outputStream.write(buf, buf.length); } -LocalFile.prototype.read = +vimperator.io.LocalFile.prototype.read = function fo_read(max) { if (this.localFile.isDirectory()) @@ -155,7 +160,7 @@ function fo_read(max) return rv; } -LocalFile.prototype.close = +vimperator.io.LocalFile.prototype.close = function fo_close() { if ("outputStream" in this) @@ -164,7 +169,7 @@ function fo_close() this.inputStream.close(); } -LocalFile.prototype.flush = +vimperator.io.LocalFile.prototype.flush = function fo_close() { return this.outputStream.flush(); diff --git a/content/mappings.js b/content/mappings.js index 4e944073..7d493bc5 100644 --- a/content/mappings.js +++ b/content/mappings.js @@ -951,7 +951,7 @@ function Mappings() //{{{ if (url.match(/^file:\/\//) || url.match(/^\//)) { var stripedFilename = url.replace(/^(file:\/\/)?(.*)/, "$2"); - var file = vimperator.fopen(stripedFilename, '<'); + var file = vimperator.io.fopen(stripedFilename, '<'); if (!file) return false; diff --git a/content/vimperator.js b/content/vimperator.js index 50b1db99..62a2bf39 100644 --- a/content/vimperator.js +++ b/content/vimperator.js @@ -269,11 +269,6 @@ const vimperator = (function() //{{{ content.focus(); // FIXME: shouldn't be window.document.content? }, - fopen: function(path, mode, perms, tmp) - { - return new LocalFile(path, mode, perms, tmp); - }, - // partial sixth level expression evaluation eval: function(string) { @@ -582,7 +577,7 @@ const vimperator = (function() //{{{ if (input) { filein = getTempFile(); - var fdin = vimperator.fopen(filein, ">"); + var fdin = vimperator.io.fopen(filein, ">"); fdin.write(input); fdin.close(); command += " < \"" + filein.path.replace('"', '\\"') + "\""; @@ -594,7 +589,7 @@ const vimperator = (function() //{{{ else res = this.run("sh", ["-c", command], true); - var fd = vimperator.fopen(fileout, "<"); + var fd = vimperator.io.fopen(fileout, "<"); if (!fd) return ""; @@ -619,7 +614,7 @@ const vimperator = (function() //{{{ try { - var fd = vimperator.fopen(filename, "<"); + var fd = vimperator.io.fopen(filename, "<"); if (!fd) return; @@ -773,7 +768,7 @@ const vimperator = (function() //{{{ if (plugin_dir) { - var fd = vimperator.fopen(plugin_dir); + var fd = vimperator.io.fopen(plugin_dir); var entries = fd.read(); fd.close(); vimperator.log("Sourcing plugin directory...", 3);