mirror of
https://github.com/moparisthebest/FireTray
synced 2024-11-17 14:25:01 -05:00
add debug() facility to print to terminal stderr
This commit is contained in:
parent
29bf5a42bd
commit
1b68487af8
85
src/modules/LibC.js
Normal file
85
src/modules/LibC.js
Normal file
@ -0,0 +1,85 @@
|
||||
/* -*- Mode: javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
|
||||
var EXPORTED_SYMBOLS = ["LibC"];
|
||||
|
||||
const LIB_C = "libc.so.6";
|
||||
|
||||
const Cu = Components.utils;
|
||||
const Cc = Components.classes;
|
||||
const Ci = Components.interfaces;
|
||||
|
||||
Cu.import("resource://gre/modules/ctypes.jsm");
|
||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
|
||||
XPCOMUtils.defineLazyGetter(this, "libc", function() {
|
||||
var libc = ctypes.open(LIB_C);
|
||||
if (!libc)
|
||||
throw "libc is unavailable";
|
||||
|
||||
return libc;
|
||||
});
|
||||
|
||||
XPCOMUtils.defineLazyGetter(this, "FILE", function() {
|
||||
return ctypes.StructType("FILE");
|
||||
});
|
||||
|
||||
XPCOMUtils.defineLazyGetter(this, "fdopen", function() {
|
||||
var fdopen = libc.declare(
|
||||
"fdopen", ctypes.default_abi, FILE.ptr,
|
||||
ctypes.int,
|
||||
ctypes.char.ptr
|
||||
);
|
||||
|
||||
if (!fdopen)
|
||||
throw "fdopen is unavailable";
|
||||
|
||||
return fdopen;
|
||||
});
|
||||
|
||||
|
||||
XPCOMUtils.defineLazyGetter(this, "puts", function() {
|
||||
var puts = libc.declare(
|
||||
"puts", ctypes.default_abi, ctypes.int32_t,
|
||||
ctypes.char.ptr
|
||||
);
|
||||
|
||||
if (!puts)
|
||||
throw "puts is unavailable";
|
||||
|
||||
return puts;
|
||||
});
|
||||
|
||||
XPCOMUtils.defineLazyGetter(this, "fputs", function() {
|
||||
var fputs = libc.declare(
|
||||
"fputs", ctypes.default_abi, ctypes.int32_t,
|
||||
ctypes.char.ptr,
|
||||
FILE.ptr
|
||||
);
|
||||
|
||||
if (!fputs)
|
||||
throw "fputs is unavailable";
|
||||
|
||||
return fputs;
|
||||
});
|
||||
|
||||
XPCOMUtils.defineLazyGetter(this, "fflush", function() {
|
||||
var fflush = libc.declare(
|
||||
"fflush", ctypes.default_abi, ctypes.int32_t,
|
||||
FILE.ptr
|
||||
);
|
||||
|
||||
if (!fflush)
|
||||
throw "fflush is unavailable";
|
||||
|
||||
return fflush;
|
||||
});
|
||||
|
||||
var LibC = {
|
||||
stderr: this.fdopen(2, "a"),
|
||||
|
||||
FILE: FILE,
|
||||
fdopen: fdopen,
|
||||
puts: puts,
|
||||
fputs: fputs,
|
||||
fflush: fflush,
|
||||
}
|
@ -10,6 +10,9 @@ var EXPORTED_SYMBOLS = [ "mozt", "Cc", "Ci" ];
|
||||
|
||||
const Cc = Components.classes;
|
||||
const Ci = Components.interfaces;
|
||||
const Cu = Components.utils;
|
||||
|
||||
Cu.import("resource://moztray/LibC.js");
|
||||
|
||||
const FIREFOX_ID = "{ec8030f7-c20a-464f-9b0e-13a3a9e97384}";
|
||||
const THUNDERBIRD_ID = "{3550f703-e582-4d05-9a08-453d09bdfdc6}";
|
||||
@ -64,6 +67,11 @@ mozt.Debug = {
|
||||
this.dump(str);
|
||||
},
|
||||
|
||||
// dump to terminal (stderr)
|
||||
debug: function(str) {
|
||||
LibC.fputs(str + "\n", LibC.stderr);
|
||||
LibC.fflush(LibC.stderr);
|
||||
},
|
||||
};
|
||||
// build it !
|
||||
mozt.Debug.init();
|
||||
|
Loading…
Reference in New Issue
Block a user