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;
22 subscript_loader.loadSubScript(uri, conkeror);
28 function load_rc_directory (file_o) {
29 var entries = file_o.directoryEntries;
31 while (entries.hasMoreElements()) {
32 var entry = entries.getNext();
33 entry.QueryInterface(Ci.nsIFile);
34 if (entry.leafName.substr(-3).toLowerCase() == '.js')
37 files.sort(function (a, b) {
38 if (a.leafName < b.leafName)
40 else if (a.leafName > b.leafName)
45 for (var i = 0; files[i]; i++) {
46 load_rc_file(files[i]);
52 * The file to load may be specified as an nsILocalFile, an nsIURI or
53 * a string uri or file path or null. If path specifies a directory
54 * all `.js' files in that directory will be loaded. The default,
55 * for a null path, is specified by the preference `conkeror.rcfile'
56 * if it is set, otherwise it is $HOME/.conkerorrc. A uri that is
57 * not of file or chrome scheme will fail.
59 function load_rc (path, resolve) {
62 if (typeof path == "object")
64 else if (typeof path == "string") {
66 file = make_uri(path);
72 if (file instanceof Ci.nsIURI && file.schemeIs("chrome"))
74 file = make_file_from_chrome(file);
75 } catch (e) { /* ignore */ }
76 if (file instanceof Ci.nsIURI && file.schemeIs("file"))
77 file = make_file(file.path);
80 if (pref_has_user_value("conkeror.rcfile")) {
81 var rcfile = get_pref("conkeror.rcfile");
87 file = get_home_directory();
88 file.appendRelativePath(".conkerorrc");
95 file = make_file(path);
97 if (file instanceof Ci.nsILocalFile) {
100 throw interactive_error("File not found: " + path);
102 if (file instanceof Ci.nsIURI)
105 if (file instanceof Ci.nsILocalFile && file.isDirectory())
106 load_rc_directory(file);