[Kst] branches/work/kst/1.6/kst/src
Andrew Walker
arwalker at sumusltd.com
Tue Oct 30 20:19:00 CET 2007
SVN commit 731122 by arwalker:
enhance functionality of the JavaScript Debug object
M +36 -2 extensions/js/bind_debug.cpp
M +27 -2 extensions/js/bind_debug.h
M +0 -2 extensions/js/bind_debuglog.cpp
M +1 -3 extensions/js/bind_debuglog.h
M +164 -165 extensions/js/kstcmd.cpp
M +7 -0 libkst/kstdebug.cpp
M +2 -0 libkst/kstdebug.h
--- branches/work/kst/1.6/kst/src/extensions/js/bind_debug.cpp #731121:731122
@@ -60,12 +60,16 @@
{ "error", &KstBindDebug::error },
{ "notice", &KstBindDebug::notice },
{ "debug", &KstBindDebug::debug },
+ { "clearNewError", &KstBindDebug::clearNewError },
{ 0L, 0L }
};
static DebugProperties debugProperties[] = {
{ "log", 0L, &KstBindDebug::log },
+ { "newError", 0L, &KstBindDebug::newError },
+ { "version", 0L, &KstBindDebug::version },
+ { "revision", 0L, &KstBindDebug::revision },
{ 0L, 0L, 0L }
};
@@ -103,7 +107,7 @@
return (this->*debugProperties[i].get)(exec);
}
}
-
+
return KstBinding::get(exec, propertyName);
}
@@ -219,9 +223,39 @@
}
+KJS::Value KstBindDebug::clearNewError(KJS::ExecState *exec, const KJS::List& args) {
+ if (args.size() != 0) {
+ KJS::Object eobj = KJS::Error::create(exec, KJS::SyntaxError);
+ exec->setException(eobj);
+ return KJS::Undefined();
+ }
+
+ KstDebug::self()->clearHasNewError();
+ return KJS::Undefined();
+}
+
+
KJS::Value KstBindDebug::log(KJS::ExecState *exec) const {
return KJS::Object(new KstBindDebugLog(exec));
}
-// vim: ts=2 sw=2 et
+KJS::Value KstBindDebug::newError(KJS::ExecState *exec) const {
+ Q_UNUSED(exec)
+
+ return KJS::Boolean(KstDebug::self()->hasNewError());
+}
+
+
+KJS::Value KstBindDebug::version(KJS::ExecState *exec) const {
+ Q_UNUSED(exec)
+
+ return KJS::String(KstDebug::self()->kstVersion());
+}
+
+
+KJS::Value KstBindDebug::revision(KJS::ExecState *exec) const {
+ Q_UNUSED(exec)
+
+ return KJS::String(KstDebug::self()->kstRevision());
+}
--- branches/work/kst/1.6/kst/src/extensions/js/bind_debug.h #731121:731122
@@ -43,38 +43,63 @@
@description Logs a warning message to the Kst log.
*/
KJS::Value warning(KJS::ExecState *exec, const KJS::List& args);
+
/* @method error
@arg string message
@description Logs an error message to the Kst log.
*/
KJS::Value error(KJS::ExecState *exec, const KJS::List& args);
+
/* @method notice
@arg string message
@description Logs a notice to the Kst log.
*/
KJS::Value notice(KJS::ExecState *exec, const KJS::List& args);
+
/* @method debug
@arg string message
@description Logs a debug message to the Kst log.
*/
KJS::Value debug(KJS::ExecState *exec, const KJS::List& args);
+
/* @method clear
@description Clears the Kst log.
*/
KJS::Value clear(KJS::ExecState *exec, const KJS::List& args);
+ /* @method clearNewError
+ @description Clears the new error flag.
+ */
+ KJS::Value clearNewError(KJS::ExecState *exec, const KJS::List& args);
+
/* @property DebugLog log
@readonly
@description Provides access to the Kst log contents.
*/
KJS::Value log(KJS::ExecState *exec) const;
+ /* @property boolean newError
+ @readonly
+ @description Return the value of the new error flag.
+ */
+ KJS::Value newError(KJS::ExecState *exec) const;
+
+ /* @property string version
+ @readonly
+ @description Return the version of Kst.
+ */
+ KJS::Value version(KJS::ExecState *exec) const;
+
+ /* @property string revision
+ @readonly
+ @description Return the revision of Kst.
+ */
+ KJS::Value revision(KJS::ExecState *exec) const;
+
protected:
KstBindDebug(int id);
void addBindings(KJS::ExecState *exec, KJS::Object& obj);
};
-
#endif
-// vim: ts=2 sw=2 et
--- branches/work/kst/1.6/kst/src/extensions/js/bind_debuglog.cpp #731121:731122
@@ -195,5 +195,3 @@
return KJS::String(log);
}
-
-// vim: ts=2 sw=2 et
--- branches/work/kst/1.6/kst/src/extensions/js/bind_debuglog.h #731121:731122
@@ -46,12 +46,12 @@
KJS::ReferenceList propList(KJS::ExecState *exec, bool recursive = true);
bool hasProperty(KJS::ExecState *exec, const KJS::Identifier& propertyName) const;
- // properties
/* @property number length
@readonly
@description The number of entries in the log.
*/
KJS::Value length(KJS::ExecState *exec) const;
+
/* @property string text
@readonly
@description The text contents of the log as a single large string with
@@ -64,7 +64,5 @@
void addBindings(KJS::ExecState *exec, KJS::Object& obj);
};
-
#endif
-// vim: ts=2 sw=2 et
--- branches/work/kst/1.6/kst/src/extensions/js/kstcmd.cpp #731121:731122
@@ -37,103 +37,103 @@
#include <unistd.h>
-#define ERR_NONE 0
-#define ERR_NO_SESSION -1
-#define ERR_ATTACHING -2
-#define ERR_KST_TERMINATED -3
-#define ERR_STARTING_SESSION -4
+#define ERR_NONE 0
+#define ERR_NO_SESSION -1
+#define ERR_ATTACHING -2
+#define ERR_KST_TERMINATED -3
+#define ERR_STARTING_SESSION -4
#define _T(x) i18n(x).local8Bit().data()
QCString kstName;
void ping(int) {
- DCOPClient *client = KApplication::dcopClient();
- if (!client->registeredApplications().contains(kstName)) {
- printf("%s", _T("Kst application process has terminated.\n"));
- rl_cleanup_after_signal();
- exit(ERR_KST_TERMINATED);
- }
+ DCOPClient *client = KApplication::dcopClient();
+ if (!client->registeredApplications().contains(kstName)) {
+ printf("%s", _T("Kst application process has terminated.\n"));
+ rl_cleanup_after_signal();
+ exit(ERR_KST_TERMINATED);
+ }
}
int run(DCOPRef& ref) {
- DCOPClient *client = KApplication::dcopClient();
+ DCOPClient *client = KApplication::dcopClient();
- // Disable completion for now. We might want to add completion of JS
- // keywords and Kst objects at some point.
- rl_bind_key('\t', rl_insert);
+ // Disable completion for now. We might want to add completion of JS
+ // keywords and Kst objects at some point.
+ rl_bind_key('\t', rl_insert);
- kstName = ref.app();
+ kstName = ref.app();
#ifndef SOLARIS
- signal(SIGALRM, &ping);
- itimerval tv = { { 1, 0 }, { 1, 0 } };
- itimerval old;
- setitimer(ITIMER_REAL, &tv, &old);
+ signal(SIGALRM, &ping);
+ itimerval tv = { { 1, 0 }, { 1, 0 } };
+ itimerval old;
+ setitimer(ITIMER_REAL, &tv, &old);
#endif
- for (;;) {
- if (!client->registeredApplications().contains(kstName)) {
- printf("%s", _T("Kst application process has terminated.\n"));
- return ERR_KST_TERMINATED;
- }
+ for (;;) {
+ if (!client->registeredApplications().contains(kstName)) {
+ printf("%s", _T("Kst application process has terminated.\n"));
+ return ERR_KST_TERMINATED;
+ }
- char *l = 0L;
- const char *prompt = "kst> ";
- QString line;
- do {
- if (!line.isEmpty()) {
- // replace \ with \n
- line[line.length() - 1] = '\n';
- }
+ char *l = 0L;
+ const char *prompt = "kst> ";
+ QString line;
+ do {
+ if (!line.isEmpty()) {
+ // replace \ with \n
+ line[line.length() - 1] = '\n';
+ }
- l = readline(prompt);
+ l = readline(prompt);
- prompt = "";
+ prompt = "";
- if (!l) {
- return 0;
- }
- line += QString(l);
- free(l);
- l = 0L;
- } while (line.endsWith("\\"));
+ if (!l) {
+ return 0;
+ }
+ line += QString(l);
+ free(l);
+ l = 0L;
+ } while (line.endsWith("\\"));
- QString clean = line.stripWhiteSpace();
+ QString clean = line.stripWhiteSpace();
- if (clean == "exit") {
- return ERR_NONE;
- }
+ if (clean == "exit") {
+ return ERR_NONE;
+ }
- if (clean == "session") {
- printf("%s\n", ref.app().data());
- continue;
- }
+ if (clean == "session") {
+ printf("%s\n", ref.app().data());
+ continue;
+ }
- if (clean == "help") {
- printf("%s", _T("Help:\n"));
- printf("%s", _T("session\t\tDisplay the name of the session in use\n"));
- printf("%s", _T("help\t\tDisplay help\n"));
- printf("%s", _T("exit\t\tExit the command-line interpreter\n"));
- continue;
- }
+ if (clean == "help") {
+ printf("%s", _T("Help:\n"));
+ printf("%s", _T("session\t\tDisplay the name of the session in use\n"));
+ printf("%s", _T("help\t\tDisplay help\n"));
+ printf("%s", _T("exit\t\tExit the command-line interpreter\n"));
+ continue;
+ }
- if (clean.isEmpty()) {
- continue;
- }
+ if (clean.isEmpty()) {
+ continue;
+ }
- add_history(line.latin1());
+ add_history(line.latin1());
- DCOPReply r = ref.call("evaluate", clean);
- if (r.isValid()) {
- QString res;
- r.get(res);
- if (!res.isEmpty()) {
- printf("%s\n", res.latin1());
- }
- }
- }
+ DCOPReply r = ref.call("evaluate", clean);
+ if (r.isValid()) {
+ QString res;
+ r.get(res);
+ if (!res.isEmpty()) {
+ printf("%s\n", res.latin1());
+ }
+ }
+ }
}
@@ -144,113 +144,112 @@
int main(int argc, char **argv) {
- KAboutData about("kstcmd", I18N_NOOP("Kst Command Line"), "1.0",
- I18N_NOOP("Kst Command Line"),
- KAboutData::License_GPL,
- I18N_NOOP("(c) 2005-2006 The University of Toronto"), 0,
- "http://kst.kde.org/");
+ KAboutData about("kstcmd", I18N_NOOP("Kst Command Line"), "1.0",
+ I18N_NOOP("Kst Command Line"),
+ KAboutData::License_GPL,
+ I18N_NOOP("(c) 2005-2006 The University of Toronto"), 0,
+ "http://kst.kde.org/");
- about.addAuthor("Staikos Computing Services Inc.", I18N_NOOP("Developed for the University of Toronto"), "info at staikos.net");
+ about.addAuthor("Staikos Computing Services Inc.", I18N_NOOP("Developed for the University of Toronto"), "info at staikos.net");
- KCmdLineArgs::init(argc, argv, &about);
- KCmdLineArgs::addCmdLineOptions(options);
- KApplication a(false, false);
+ KCmdLineArgs::init(argc, argv, &about);
+ KCmdLineArgs::addCmdLineOptions(options);
+ KApplication a(false, false);
- QCString session;
- KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
- if (args->count() > 0) {
- session = args->arg(0);
- }
+ QCString session;
+ KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
+ if (args->count() > 0) {
+ session = args->arg(0);
+ }
- setvbuf(stdout, 0, _IONBF, 0);
+ setvbuf(stdout, 0, _IONBF, 0);
- if (session.isEmpty()) {
- DCOPClient *client = KApplication::dcopClient();
- QCStringList apps = client->registeredApplications();
- QCStringList ksts;
+ if (session.isEmpty()) {
+ DCOPClient *client = KApplication::dcopClient();
+ QCStringList apps = client->registeredApplications();
+ QCStringList ksts;
- for (QCStringList::ConstIterator i = apps.begin(); i != apps.end(); ++i) {
- if ((*i).left(4) == "kst-") {
- ksts += *i;
- }
- }
+ for (QCStringList::ConstIterator i = apps.begin(); i != apps.end(); ++i) {
+ if ((*i).left(4) == "kst-") {
+ ksts += *i;
+ }
+ }
+ if (ksts.isEmpty()) {
+ char *l = readline(_T("Kst does not appear to be running. Start a new session? "));
+ if (!l) {
+ return ERR_NONE;
+ }
- if (ksts.isEmpty()) {
- char *l = readline(_T("Kst does not appear to be running. Start a new session? "));
- if (!l) {
- return ERR_NONE;
- }
+ QString lstr = l;
+ free(l);
+ l = 0L;
+ if (lstr.stripWhiteSpace().lower()[0] != 'y') {
+ return ERR_NONE;
+ }
+ int pid = 0;
+ QString err;
+ int rc = KApplication::startServiceByDesktopName("kst", QString::null, &err, &session, &pid);
+ if (rc != 0) {
+ printf(_T("Error starting session: %s\n"), err.latin1());
+ return ERR_STARTING_SESSION;
+ }
- QString lstr = l;
- free(l);
- l = 0L;
- if (lstr.stripWhiteSpace().lower()[0] != 'y') {
- return ERR_NONE;
- }
- int pid = 0;
- QString err;
- int rc = KApplication::startServiceByDesktopName("kst", QString::null, &err, &session, &pid);
- if (rc != 0) {
- printf(_T("Error starting session: %s\n"), err.latin1());
- return ERR_STARTING_SESSION;
- }
+ if (session.isEmpty()) {
+ session = QString("kst-%1").arg(pid).latin1();
+ }
- if (session.isEmpty()) {
- session = QString("kst-%1").arg(pid).latin1();
- }
+ time_t startTime = time(NULL);
+ printf("%s", _T("Waiting for Kst to start."));
+ while (!client->isApplicationRegistered(session)) {
+ if (time(NULL) - startTime > 30) {
+ printf("%s", _T("\nTimeout waiting for Kst to start\n"));
+ return ERR_STARTING_SESSION;
+ }
+ printf(".");
+ sleep(1);
+ }
+ printf("\n");
+ } else if (ksts.count() > 1) {
+ QCString parentKst = QCString("kst-") + QString::number(getppid()).latin1();
+ if (ksts.contains(parentKst)) {
+ session = parentKst;
+ } else {
+ printf("%s", _T("Please choose a session number to attach to:\n"));
+ int j = 0;
+ for (QCStringList::ConstIterator i = ksts.begin(); i != ksts.end(); ++i) {
+ printf(_T("%2d: %s\n"), ++j, (*i).data());
+ }
+ printf("> ");
+ char choice[10];
+ QString l = fgets(choice, 4, stdin);
+ l = l.stripWhiteSpace();
+ if (l.isEmpty()) {
+ printf("%s", _T("No session found.\n"));
+ return ERR_NO_SESSION;
+ }
+ bool ok = false;
+ int nchoice = l.toInt(&ok);
+ if (ok && nchoice > 0 && nchoice <= j) {
+ session = ksts[nchoice - 1];
+ } else {
+ printf("%s", _T("No session found.\n"));
+ return ERR_NO_SESSION;
+ }
+ }
+ } else {
+ session = ksts[0];
+ }
+ }
- time_t startTime = time(NULL);
- printf("%s", _T("Waiting for Kst to start."));
- while (!client->isApplicationRegistered(session)) {
- if (time(NULL) - startTime > 30) {
- printf("%s", _T("\nTimeout waiting for Kst to start\n"));
- return ERR_STARTING_SESSION;
- }
- printf(".");
- sleep(1);
- }
- printf("\n");
- } else if (ksts.count() > 1) {
- QCString parentKst = QCString("kst-") + QString::number(getppid()).latin1();
- if (ksts.contains(parentKst)) {
- session = parentKst;
- } else {
- printf("%s", _T("Please choose a session number to attach to:\n"));
- int j = 0;
- for (QCStringList::ConstIterator i = ksts.begin(); i != ksts.end(); ++i) {
- printf(_T("%2d: %s\n"), ++j, (*i).data());
- }
- printf("> ");
- char choice[10];
- QString l = fgets(choice, 4, stdin);
- l = l.stripWhiteSpace();
- if (l.isEmpty()) {
- printf("%s", _T("No session found.\n"));
- return ERR_NO_SESSION;
- }
- bool ok = false;
- int nchoice = l.toInt(&ok);
- if (ok && nchoice > 0 && nchoice <= j) {
- session = ksts[nchoice - 1];
- } else {
- printf("%s", _T("No session found.\n"));
- return ERR_NO_SESSION;
- }
- }
- } else {
- session = ksts[0];
- }
- }
+ DCOPRef ref(session.data(), "KstScript");
+ if (ref.isNull()) {
+ printf(_T("Error attaching to session %s\n"), session.data());
+ return ERR_ATTACHING;
+ }
- DCOPRef ref(session.data(), "KstScript");
- if (ref.isNull()) {
- printf(_T("Error attaching to session %s\n"), session.data());
- return ERR_ATTACHING;
- }
+ printf(_T("Attached to Kst session %s\n"), session.data());
- printf(_T("Attached to Kst session %s\n"), session.data());
-
- return run(ref);
+ return run(ref);
}
--- branches/work/kst/1.6/kst/src/libkst/kstdebug.cpp #731121:731122
@@ -47,6 +47,7 @@
_applyLimit = false;
_limit = 10000;
_kstRevision = QString::fromLatin1(KSTREVISION);
+ _kstVersion = QString::fromLatin1(KSTVERSION);
_hasNewError = false;
}
@@ -182,6 +183,12 @@
}
+const QString& KstDebug::kstVersion() const {
+ QMutexLocker ml(&_lock);
+ return _kstVersion;
+}
+
+
const QString& KstDebug::kstRevision() const {
QMutexLocker ml(&_lock);
return _kstRevision;
--- branches/work/kst/1.6/kst/src/libkst/kstdebug.h #731121:731122
@@ -54,6 +54,7 @@
KstDebug::LogMessage message(unsigned n) const;
QStringList dataSourcePlugins() const;
QString label(LogLevel level) const;
+ const QString& kstVersion() const;
const QString& kstRevision() const;
int limit() const;
@@ -84,6 +85,7 @@
QMap<QString,int> _drawCounter;
#endif
QGuardedPtr<QObject> _handler;
+ QString _kstVersion;
QString _kstRevision;
};
More information about the Kst
mailing list