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
10 function load_rc_file (file) {
12 var prefix = "file://";
14 if (typeof file == "string")
16 else if (file instanceof Ci.nsIURI)
19 uri = prefix + file.path;
21 subscript_loader.loadSubScript(uri, conkeror);
27 function load_rc_directory (file_o) {
28 var entries = file_o.directoryEntries;
30 while (entries.hasMoreElements()) {
31 var entry = entries.getNext();
32 entry.QueryInterface(Ci.nsIFile);
33 if (entry.leafName.match(/^[^.].*\.js$/i)) {
37 files.sort(function (a, b) {
38 if (a.leafName < b.leafName) {
40 } else if (a.leafName > b.leafName) {
46 for (var i = 0; i < files.length; i++) {
47 load_rc_file(files[i]);
53 * The file to load may be specified as an nsILocalFile, an nsIURI or
54 * a string uri or file path or null. If path specifies a directory
55 * all `.js' files in that directory will be loaded. The default,
56 * for a null path, is specified by the preference `conkeror.rcfile'
57 * if it is set, otherwise it is $HOME/.conkerorrc. A uri that is
58 * not of file or chrome scheme will fail.
60 function load_rc (path, resolve) {
63 if (typeof path == "object")
65 if (typeof path == "string") {
67 file = make_uri(path);
73 if (file instanceof Ci.nsIURI && file.schemeIs("chrome"))
75 file = make_file_from_chrome(file);
76 } catch (e) { /* ignore */ }
77 if (file instanceof Ci.nsIURI && file.schemeIs("file"))
78 file = make_file(file.path);
81 if (pref_has_user_value("conkeror.rcfile")) {
82 var rcfile = get_pref("conkeror.rcfile");
88 file = get_home_directory();
89 file.appendRelativePath(".conkerorrc");
96 file = make_file(path);
98 if (file instanceof Ci.nsILocalFile) {
101 throw interactive_error("File not found: " + path);
103 if (file instanceof Ci.nsIURI)
106 if (file instanceof Ci.nsILocalFile && file.isDirectory()) {
107 load_rc_directory(file);