Debian package: Declare compliance with Debian Policy 4.3.0
[conkeror.git] / modules / rc.js
blobf4051ebf2ef14243292e597717dcda70e438cfb9
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 **/
11     let default_rc = get_home_directory();
12     default_rc.appendRelativePath(".conkerorrc");
13     default_pref("conkeror.rcfile", default_rc.path);
16 function load_rc () {
17     var path;
18     var rcfile = get_pref("conkeror.rcfile");
19     if (rcfile.length == 0) {
20         dumpln("w:  preference conkeror.rcfile is unset");
21         return;
22     }
23     path = make_file(rcfile);
25     if (! path.exists()) {
26         if (file_symlink_p(path)) {
27             dumpln("w: broken symlink, \""+rcfile+"\"");
28         } else if (pref_has_user_value("conkeror.rcfile")) {
29             dumpln("w: preference conkeror.rcfile is set to "+
30                    "non-existent path, \""+rcfile+"\"");
31         } else {
32             dumpln("w: conkeror.rcfile \"" + rcfile +
33             "\" does not exist");
34         }
35         return;
36     }
38     var files = [];
39     var ret;
40     if (path.isDirectory()) {
41         var entries = path.directoryEntries;
42         while (entries.hasMoreElements()) {
43             var entry = entries.getNext();
44             entry.QueryInterface(Ci.nsIFile);
45             if (entry.leafName.substr(-3).toLowerCase() == '.js') {
46                 files.push(entry);
47             }
48         }
49         files.sort(function (a, b) {
50             if (a.leafName < b.leafName) {
51                 return -1;
52             } else if (a.leafName > b.leafName) {
53                 return 1;
54             } else {
55                 return 0;
56             }
57         });
58         path.appendRelativePath("a");
59         ret = path.path.substr(0, path.path.length - 1) + "*.js";
60     } else {
61         files.push(path);
62         ret = path.path;
63     }
64     var obs = Cc["@mozilla.org/observer-service;1"]
65         .getService(Ci.nsIObserverService);
66     obs.notifyObservers(null, "startupcache-invalidate", null);
67     for (var file of files) {
68         try {
69             load(file);
70             dumpln("i: loaded rc file " + file.leafName)
71         } catch (e) {
72             dump_error(e);
73         }
74     }
75     return ret;
78 provide("rc");