File indexing completed on 2024-12-01 09:50:37
0001 /* 0002 * This file is part of the KDE libraries 0003 * Copyright (C) 2000 Harri Porten (porten@kde.org) 0004 * 0005 * This library is free software; you can redistribute it and/or 0006 * modify it under the terms of the GNU Library General Public 0007 * License as published by the Free Software Foundation; either 0008 * version 2 of the License, or (at your option) any later version. 0009 * 0010 * This library is distributed in the hope that it will be useful, 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0013 * Library General Public License for more details. 0014 * 0015 * You should have received a copy of the GNU Library General Public 0016 * License along with this library; if not, write to the Free Software 0017 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 0018 */ 0019 0020 /** 0021 * An interactive interpreter to test the ECMA Script language bindings 0022 * for the DOM of KHTML. 0023 * The 'document' property is preset to an instance of Document and serves 0024 * as an entrypoint. 0025 * 0026 * Example session: 0027 * 0028 * KJS> text = document.createTextNode('foo'); 0029 * KJS> document.appendChild(text); 0030 * KJS> debug(document.firstChild.nodeValue); 0031 * ---> foo 0032 */ 0033 0034 #include <stdio.h> 0035 #include <kjs/object.h> 0036 #include <kjs/interpreter.h> 0037 #include "dom/dom_doc.h" 0038 #include "dom/dom_string.h" 0039 #include "ecma/kjs_dom.h" 0040 0041 using namespace KJS; 0042 0043 int main(int, char **) 0044 { 0045 KJScript kjs; 0046 kjs.enableDebug(); 0047 DOM::Document doc; 0048 0049 DOMDocument *dd = new DOMDocument(&doc); 0050 Global::current().put("document", KJSO(dd)); 0051 0052 printf("Entering interactive mode.\n" 0053 "You may access the DOM via the 'document' property.\n" 0054 "Use debug() to print to the console. Press C-d or C-c to exit.\n\n"); 0055 0056 char buffer[1000]; 0057 FILE *in = fdopen(0, "r"); 0058 0059 while (1) { 0060 printf("KJS> "); 0061 if (!fgets(buffer, 999, in)) { 0062 break; 0063 } 0064 kjs.evaluate(buffer); 0065 } 0066 printf("\n"); 0067 }