2 * (C) Copyright 2004-2007 Shawn Betts
3 * (C) Copyright 2007-2008 John J. Foerch
4 * (C) Copyright 2007-2008 Jeremy Maitin-Shepard
6 * Use, modification, and distribution are subject to the terms specified in the
12 function load_rc_file (file) {
14 var prefix = "file://";
16 if (typeof file == "string")
18 else if (file instanceof Ci.nsIURI)
21 uri = prefix + file.path;
23 subscript_loader.loadSubScript(uri, conkeror);
29 function load_rc_directory (file_o) {
30 var entries = file_o.directoryEntries;
32 while (entries.hasMoreElements()) {
33 var entry = entries.getNext();
34 entry.QueryInterface(Ci.nsIFile);
35 if (entry.leafName.match(/^[^.].*\.js$/i)) {
39 files.sort(function (a, b) {
40 if (a.leafName < b.leafName) {
42 } else if (a.leafName > b.leafName) {
48 for (var i = 0; i < files.length; i++) {
49 load_rc_file(files[i]);
55 * The file to load may be specified as an nsILocalFile, an nsIURI or
56 * a string uri or file path or null. If path specifies a directory
57 * all `.js' files in that directory will be loaded. The default,
58 * for a null path, is specified by the preference `conkeror.rcfile'
59 * if it is set, otherwise it is $HOME/.conkerorrc. A uri that is
60 * not of file or chrome scheme will fail.
62 function load_rc (path, resolve) {
65 if (typeof path == "object")
67 if (typeof path == "string") {
69 file = make_uri(path);
75 if (file instanceof Ci.nsIURI && file.schemeIs("chrome"))
77 file = make_file_from_chrome(file);
78 } catch (e) { /* ignore */ }
79 if (file instanceof Ci.nsIURI && file.schemeIs("file"))
80 file = make_file(file.path);
83 if (pref_has_user_value("conkeror.rcfile")) {
84 var rcfile = get_pref("conkeror.rcfile");
90 file = get_home_directory();
91 file.appendRelativePath(".conkerorrc");
98 file = make_file(path);
100 if (file instanceof Ci.nsILocalFile) {
103 throw interactive_error("File not found: " + path);
105 if (file instanceof Ci.nsIURI)
108 if (file instanceof Ci.nsILocalFile && file.isDirectory()) {
109 load_rc_directory(file);