Debian package: Support xulrunner 9+10 in debian/conkeror.bin, drop support for unver...
[conkeror.git] / modules / rc.js
blob780d6ed2aeeb33a82846f13b5972e0e57917af6b
1 /**
2  * (C) Copyright 2004-2007 Shawn Betts
3  * (C) Copyright 2007-2010 John J. Foerch
4  * (C) Copyright 2007-2008 Jeremy Maitin-Shepard
5  *
6  * Use, modification, and distribution are subject to the terms specified in the
7  * COPYING file.
8 **/
10 in_module(null);
12 let (default_rc = get_home_directory()) {
13     default_rc.appendRelativePath(".conkerorrc");
14     default_pref("conkeror.rcfile", default_rc.path);
17 function load_rc () {
18     var path;
19     var rcfile = get_pref("conkeror.rcfile");
20     if (rcfile.length == 0)
21         //FIXME: log that the rc is disabled
22         return;
23     path = make_file(rcfile);
24     if (! path.exists()) {
25         if (path.isSymlink())
26             dumpln("w: broken symlink, \""+rcfile+"\"");
27         else if (pref_has_user_value("conkeror.rcfile"))
28             dumpln("w: preference conkeror.rcfile is set to "+
29                    "non-existent path, \""+rcfile+"\"");
30         //FIXME: else log that the rc does not exist
31         return;
32     }
33     var files = [];
34     var ret;
35     if (path.isDirectory()) {
36         var entries = path.directoryEntries;
37         while (entries.hasMoreElements()) {
38             var entry = entries.getNext();
39             entry.QueryInterface(Ci.nsIFile);
40             if (entry.leafName.substr(-3).toLowerCase() == '.js')
41                 files.push(entry);
42         }
43         files.sort(function (a, b) {
44             if (a.leafName < b.leafName)
45                 return -1;
46             else if (a.leafName > b.leafName)
47                 return 1;
48             else
49                 return 0;
50         });
51         path.appendRelativePath("a");
52         ret = path.path.substr(0, path.path.length - 1) + "*.js";
53     } else {
54         files.push(path);
55         ret = path.path;
56     }
57     for (var i = 0; files[i]; i++) {
58         try {
59             load(files[i]);
60         } catch (e) {
61             dump_error(e);
62         }
63     }
64     //FIXME: log what was loaded instead of returning the value to be
65     //       logged by the caller.
66     return ret;
69 provide("rc");