From a6c06caa4dc62765df203e0ed2d6944f598af842 Mon Sep 17 00:00:00 2001 From: John Foerch Date: Wed, 7 Apr 2010 12:35:51 -0400 Subject: [PATCH] load_rc_directory: remove; refactor it into load_rc simpler setup of the conkeror.rcfile pref default load_rc: better error reporting --- modules/command-line.js | 4 +- modules/rc.js | 138 ++++++++++++++++++++++++------------------------ 2 files changed, 72 insertions(+), 70 deletions(-) rewrite modules/rc.js (60%) diff --git a/modules/command-line.js b/modules/command-line.js index 931a40e..df357d5 100644 --- a/modules/command-line.js +++ b/modules/command-line.js @@ -165,7 +165,9 @@ function handle_command_line (cmdline) { if (! suppress_rc && initial_launch) { try { load_rc(); - } catch (e) { dump(e + "\n"); } + } catch (e) { + dump_error(e); + } } else if (suppress_rc && ! initial_launch) { dumpln("w: attempt to suppress loading of rc in remote invocation"); } diff --git a/modules/rc.js b/modules/rc.js dissimilarity index 60% index d1f97a3..780d6ed 100644 --- a/modules/rc.js +++ b/modules/rc.js @@ -1,69 +1,69 @@ -/** - * (C) Copyright 2004-2007 Shawn Betts - * (C) Copyright 2007-2010 John J. Foerch - * (C) Copyright 2007-2008 Jeremy Maitin-Shepard - * - * Use, modification, and distribution are subject to the terms specified in the - * COPYING file. -**/ - -in_module(null); - -function load_rc_directory (file_o) { - var entries = file_o.directoryEntries; - var files = []; - while (entries.hasMoreElements()) { - var entry = entries.getNext(); - entry.QueryInterface(Ci.nsIFile); - if (entry.leafName.substr(-3).toLowerCase() == '.js') - files.push(entry); - } - files.sort(function (a, b) { - if (a.leafName < b.leafName) - return -1; - else if (a.leafName > b.leafName) - return 1; - else - return 0; - }); - for (var i = 0; files[i]; i++) { - try { - load(files[i]); - } catch (e) { - dump_error(e); - } - } -} - - -function load_rc () { - var path; - if (pref_has_user_value("conkeror.rcfile")) { - let rcfile = get_pref("conkeror.rcfile"); - if (rcfile.length) - path = make_file(rcfile); - else - //FIXME: log that the rc is disabled - return; - } else { - path = get_home_directory(); - path.appendRelativePath(".conkerorrc"); - if (! path.exists()) - //FIXME: log that ~/.conkerorrc does not exist - return; - } - - if (path.isDirectory()) - load_rc_directory(path); - else - load(path); - - //FIXME: log the load instead of returning a value to be logged by the - // caller. - if (path.isDirectory()) - return path.path + "/*.js"; - else - return path.path; -} - -provide("rc"); +/** + * (C) Copyright 2004-2007 Shawn Betts + * (C) Copyright 2007-2010 John J. Foerch + * (C) Copyright 2007-2008 Jeremy Maitin-Shepard + * + * Use, modification, and distribution are subject to the terms specified in the + * COPYING file. +**/ + +in_module(null); + +let (default_rc = get_home_directory()) { + default_rc.appendRelativePath(".conkerorrc"); + default_pref("conkeror.rcfile", default_rc.path); +} + +function load_rc () { + var path; + var rcfile = get_pref("conkeror.rcfile"); + if (rcfile.length == 0) + //FIXME: log that the rc is disabled + return; + path = make_file(rcfile); + if (! path.exists()) { + if (path.isSymlink()) + dumpln("w: broken symlink, \""+rcfile+"\""); + else if (pref_has_user_value("conkeror.rcfile")) + dumpln("w: preference conkeror.rcfile is set to "+ + "non-existent path, \""+rcfile+"\""); + //FIXME: else log that the rc does not exist + return; + } + var files = []; + var ret; + if (path.isDirectory()) { + var entries = path.directoryEntries; + while (entries.hasMoreElements()) { + var entry = entries.getNext(); + entry.QueryInterface(Ci.nsIFile); + if (entry.leafName.substr(-3).toLowerCase() == '.js') + files.push(entry); + } + files.sort(function (a, b) { + if (a.leafName < b.leafName) + return -1; + else if (a.leafName > b.leafName) + return 1; + else + return 0; + }); + path.appendRelativePath("a"); + ret = path.path.substr(0, path.path.length - 1) + "*.js"; + } else { + files.push(path); + ret = path.path; + } + for (var i = 0; files[i]; i++) { + try { + load(files[i]); + } catch (e) { + dump_error(e); + } + } + //FIXME: log what was loaded instead of returning the value to be + // logged by the caller. + return ret; +} + +provide("rc"); -- 2.11.4.GIT