1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708
|
public {
#include <glib.h>
#include "entity.h"
#include "js-ENodeAttrib.h"
};
package Entity;
native {
/*
* Javascript binding for Entity
* Copyright (c) 2000 Brian Bassett and Ian Main
*
* Authors: Brian Bassett <bbassett@bbassett.net>
* Ian Main <imain@gtk.org>
*/
/*
* This renderer is free software; please see the LICENSE file for
* specific information as to licensing conditions.
*/
/*
* $Source: /home/cvs/entity/renderers/javascript/ENode.jsi,v $
* $Id: ENode.jsi,v 1.45 2000/08/29 07:20:45 imain Exp $
*/
};
native {
void
js_return_enode (JSVirtualMachine *js_vm, JSBuiltinInfo *js_info,
JSNode *retval, ENode *node)
{
ENodeInstanceCtx *ni;
ni = js_calloc(js_vm, 1, sizeof(*ni));
ni->enode = node;
enode_ref (node);
js_vm_builtin_create(js_vm, retval, js_info, ni);
/* If all we ever do is call enode(), the vm will never
* do gc otherwise.. */
/*
if (js_vm->gc.bytes_allocated >= js_vm->gc.trigger) {
js_vm_garbage_collect (js_vm, retval, retval);
}
*/
}
static void
js_return_enode_array (JSVirtualMachine *js_vm, JSNode *js_retval,
JSBuiltinInfo *js_info, GSList *list)
{
ENodeInstanceCtx *ni;
gint i = 0;
GSList *tmp = list;
gint len = g_slist_length (tmp);
js_vm_make_array (js_vm, js_retval, len);
while (tmp) {
ENode *enode = tmp->data;
ni = js_calloc(js_vm, 1, sizeof(*ni));
ni->enode = enode;
enode_ref (enode);
js_vm_builtin_create(js_vm, &js_retval->u.varray->data[i],
js_info, ni);
i++;
tmp = tmp->next;
}
}
static void
js_return_ebuf_array (JSVirtualMachine *js_vm, JSNode *js_retval,
GSList *list)
{
gint i = 0;
GSList *tmp = list;
gint len = g_slist_length (tmp);
EDEBUG (("javascript", "Creating ebuf array of length %d\n", len));
js_vm_make_array (js_vm, js_retval, len);
while (tmp) {
EBufConst *buf = tmp->data;
js_retval->u.varray->data[i].type = JS_STRING;
js_vm_make_string (js_vm, &js_retval->u.varray->data[i],
buf->str, buf->len);
i++;
tmp = tmp->next;
}
}
static void
js_return_string_array (JSVirtualMachine *js_vm, JSNode *js_retval,
GSList *list)
{
gint i = 0;
GSList *tmp = list;
gint len = g_slist_length (tmp);
EDEBUG (("javascript", "Creating string array of length %d\n", len));
js_vm_make_array (js_vm, js_retval, len);
while (tmp) {
gchar *str = tmp->data;
js_retval->u.varray->data[i].type = JS_STRING;
js_vm_make_string (js_vm, &js_retval->u.varray->data[i],
str, strlen (str));
i++;
tmp = tmp->next;
}
}
};
standard "ENode IDL (docs/ENode.idl)";
class ENode {
native ENode *enode;
new (string basename) {
js_instance->enode = enode (enode_call_reference(), basename);
enode_ref (js_instance->enode);
};
/* Base Interface */
object function new_child (string basename) {
ENode *node = js_instance->enode;
ENode *new_child;
new_child = enode_new_child (node, basename, NULL);
js_return_enode (js_vm, js_info, js_retval, new_child);
};
string property type {
[[get]] {
ENode *node = js_instance->enode;
EBufConst *type;
type = enode_type (node);
js_retval->type = JS_STRING;
js_vm_make_string (js_vm, js_retval, type->str, type->len);
};
readonly;
dontdelete;
dontenum;
};
object property attrib {
[[get]] {
ENodeAttribInstanceCtx *ni;
JSBuiltinInfo *enode_info;
JSNode *enode_node;
enode_node = &js_vm->globals[js_vm_intern(js_vm, "ENodeAttrib")];
enode_info = enode_node->u.vbuiltin->info;
ni = js_calloc(js_vm, 1, sizeof(*ni));
ni->enode = js_instance->enode;
enode_ref (ni->enode);
js_vm_builtin_create(js_vm, js_retval, enode_info, ni);
};
readonly;
dontenum;
dontdelete;
};
object property attribval {
[[get]] {
ENodeAttribInstanceCtx *ni;
JSBuiltinInfo *enode_info;
JSNode *enode_node;
enode_node = &js_vm->globals[js_vm_intern(js_vm, "ENodeAttribVal")];
enode_info = enode_node->u.vbuiltin->info;
ni = js_calloc(js_vm, 1, sizeof(*ni));
ni->enode = js_instance->enode;
enode_ref (ni->enode);
js_vm_builtin_create(js_vm, js_retval, enode_info, ni);
};
readonly;
dontenum;
dontdelete;
};
string property path {
[[get]] {
ENode *node = js_instance->enode;
EBufFreeMe *path;
path = enode_path (node);
js_retval->type = JS_STRING;
js_vm_make_string (js_vm, js_retval, path->str, path->len);
ebuf_free (path);
};
readonly;
dontdelete;
dontenum;
};
string property basename {
[[get]] {
EBufFreeMe *basename;
ENode *node = js_instance->enode;
basename = enode_basename (node);
js_retval->type = JS_STRING;
js_vm_make_string (js_vm, js_retval, basename->str, basename->len);
ebuf_free (basename);
};
readonly;
dontdelete;
dontenum;
};
string property description {
[[get]] {
ENode *node = js_instance->enode;
gchar *description;
description = enode_description (node);
if (description) {
js_retval->type = JS_STRING;
js_vm_make_string (js_vm, js_retval, description, strlen (description));
} else {
js_retval->type = JS_NULL;
}
};
readonly;
dontdelete;
dontenum;
};
/* Node Seach Routines */
object function parent ([string search]) {
ENode *node;
ENode *parent;
node = js_instance->enode;
parent = enode_parent (node, search);
if (parent) {
js_return_enode (js_vm, js_info, js_retval, parent);
} else {
js_retval->type = JS_NULL;
}
};
object function child (string search) {
ENode *node;
ENode *child;
node = js_instance->enode;
child = enode_child (node, search);
if (child) {
js_return_enode (js_vm, js_info, js_retval, child);
} else {
js_retval->type = JS_NULL;
}
};
object function child_rx (string regex) {
ENode *node;
ENode *child;
node = js_instance->enode;
child = enode_child_rx (node, regex);
if (child) {
js_return_enode (js_vm, js_info, js_retval, child);
} else {
js_retval->type = JS_NULL;
}
};
array function children ([string search]) {
ENode *node;
GSList *children;
node = js_instance->enode;
children = enode_children (node, search);
if (children) {
js_return_enode_array (js_vm, js_retval,
js_info, children);
g_slist_free (children);
} else {
js_retval->type = JS_NULL;
}
};
array function children_rx (string regex) {
ENode *node;
GSList *children;
node = js_instance->enode;
children = enode_children_rx (node, regex);
if (children) {
js_return_enode_array (js_vm, js_retval,
js_info, children);
g_slist_free (children);
} else {
js_retval->type = JS_NULL;
}
};
array function children_attrib (string attrib, string attrval) {
ENode *node;
GSList *children;
EBufFreeMe *eval;
node = js_instance->enode;
eval = ebuf_new_with_str (attrval);
children = enode_children_attrib (node, attrib, eval);
ebuf_free (eval);
if (children) {
js_return_enode_array (js_vm, js_retval,
js_info, children);
g_slist_free (children);
} else {
js_retval->type = JS_NULL;
}
};
array function children_attrib_rx (string attrib, string regex) {
ENode *node;
GSList *children;
node = js_instance->enode;
children = enode_children_attrib_rx (node, attrib, regex);
if (children) {
js_return_enode_array (js_vm, js_retval,
js_info, children);
g_slist_free (children);
} else {
js_retval->type = JS_NULL;
}
};
string function call (string function, ...) {
EBufFreeMe *valret;
GSList *call_args = NULL;
char *fmt = NULL;
if (js_varargc > 1) {
js_vm_to_string (js_vm, &js_varargv[0], &js_tempnode);
fmt = js_string_to_c_string (js_vm, &js_tempnode);
/* Advance start of varargs to next entry */
js_varargv = &js_varargv[1];
js_varargc--;
}
if (fmt) {
int i;
int n_args = strlen (fmt);
EDEBUG(("js-embed", "node.call: got the function name %s, argstring '%s'",
function, fmt));
if (n_args != js_varargc) {
js_vm_set_err (js_vm, "call(): argument list does not match argument count");
js_vm_error (js_vm);
}
/* We start at 1 because the fmt argument is the first real vararg */
for (i = 0; i < js_varargc; i++) {
JSNode js_tempnode;
char *str;
int vint;
switch(fmt[i]) {
case 'n':
EDEBUG(("js-embed", "call(): processing got an enode"));
if (js_varargv[i].type == JS_BUILTIN) {
ENodeInstanceCtx *ni;
ni = js_varargv[i].u.vbuiltin->instance_context;
if (ni)
call_args = enode_call_push_node(call_args, ni->enode);
} else {
js_vm_set_err (js_vm,
"call(): argument does not match format (node not an Object)");
js_vm_error (js_vm);
}
break;
/* We're just gonna make strings for all of these for now */
case 'e':
case 'b':
js_vm_to_string (js_vm, &js_varargv[i], &js_tempnode);
call_args = enode_call_push_data (call_args,
js_tempnode.u.vstring->data,
js_tempnode.u.vstring->len);
break;
case 's':
js_vm_to_string (js_vm, &js_varargv[i], &js_tempnode);
str = js_string_to_c_string (js_vm, &js_tempnode);
call_args = enode_call_push_str (call_args, str);
EDEBUG(("js-embed", "call(): vararg %d: string '%s'",
i, str));
break;
case 'i':
js_vm_to_number (js_vm, &js_varargv[i], &js_tempnode);
vint = js_tempnode.u.vinteger;
call_args = enode_call_push_int (call_args, vint);
EDEBUG(("js-embed", "call(): vararg %d: int '%d'",
i, vint));
break;
default:
/* bad args string */
enode_call_free_arg_list (call_args);
js_vm_set_err (js_vm, "call(): Bad argument character '%s'", fmt[i]);
js_vm_error (js_vm);
}
}
}
valret = enode_call_with_list (js_instance->enode, function, call_args);
if (!valret) {
EDEBUG(("js-embed", "call(): retval was NULL. returning none"));
js_retval->type = JS_NULL;
} else {
js_retval->type = JS_STRING;
js_vm_make_string (js_vm, js_retval, valret->str, valret->len);
ebuf_free(valret);
}
};
string function attrib_quiet (string attrib, [string value]) {
ENode *node;
EBufConst *valret;
EBuf *val = NULL;
node = js_instance->enode;
if (value)
val = ebuf_new_with_str (value);
valret = enode_attrib_quiet (node, attrib, val);
if (valret) {
js_retval->type = JS_STRING;
js_vm_make_string (js_vm, js_retval, valret->str, valret->len);
} else {
js_retval->type = JS_NULL;
}
};
boolean function attrib_is_true (string attrib) {
js_retval->type= JS_BOOLEAN;
js_retval->u.vboolean = enode_attrib_is_true (js_instance->enode, attrib);
};
array function list_set_attribs () {
GSList *lst;
lst = enode_list_set_attribs (js_instance->enode);
if (lst) {
js_return_ebuf_array (js_vm, js_retval, lst);
g_slist_free (lst);
} else {
js_retval->type = JS_NULL;
}
};
array function supported_attribs () {
GSList *lst;
lst = enode_supported_attribs (js_instance->enode);
if (lst) {
js_return_string_array (js_vm, js_retval, lst);
g_slist_free (lst);
} else {
js_retval->type = JS_NULL;
}
};
string function attrib_description (string attrib) {
gchar *ret;
ret = enode_attrib_description (js_instance->enode, attrib);
if (ret) {
js_retval->type = JS_STRING;
js_vm_make_string (js_vm, js_retval, ret, strlen (ret));
} else {
js_retval->type = JS_NULL;
}
};
string function attrib_value_type (string attrib) {
gchar *ret;
ret = enode_attrib_value_type (js_instance->enode, attrib);
if (ret) {
js_retval->type = JS_STRING;
js_vm_make_string (js_vm, js_retval, ret, strlen (ret));
} else {
js_retval->type = JS_NULL;
}
};
string function attrib_possible_values (string attrib) {
gchar *ret;
ret = enode_attrib_possible_values (js_instance->enode, attrib);
if (ret) {
js_retval->type = JS_STRING;
js_vm_make_string (js_vm, js_retval, ret, strlen (ret));
} else {
js_retval->type = JS_NULL;
}
};
undefined function attribs_sync () {
enode_attribs_sync (js_instance->enode);
};
undefined function destroy () {
enode_destroy (js_instance->enode);
};
/* Node destruction functions */
delete () {
/* g_print ("deleting node %s\n", js_instance->enode->element->str); */
enode_unref (js_instance->enode);
};
undefined function destroy_children () {
ENode *node;
node = js_instance->enode;
enode_destroy_children (node);
};
/* Raw XML Interfaces */
string function get_xml () {
ENode *node;
EBufFreeMe *xml;
node = js_instance->enode;
xml = enode_get_xml (node);
if (xml) {
js_retval->type = JS_STRING;
js_vm_make_string (js_vm, js_retval, xml->str, xml->len);
}
};
string function get_child_xml () {
ENode *node;
EBufFreeMe *xml;
node = js_instance->enode;
xml = enode_get_child_xml (node);
if (xml) {
js_retval->type = JS_STRING;
js_vm_make_string (js_vm, js_retval, xml->str, xml->len);
ebuf_free (xml);
} else {
js_retval->type = JS_NULL;
}
};
undefined function append_xml (string xml) {
ENode *node;
EBuf *xmlbuf;
node = js_instance->enode;
xmlbuf = ebuf_new_with_str (xml);
enode_append_xml (node, xmlbuf);
ebuf_free (xmlbuf);
};
undefined function set_data (string data) {
EBufFreeMe *databuf;
databuf = ebuf_new_with_data (js_tempnode.u.vstring->data,
js_tempnode.u.vstring->len);
enode_set_data (js_instance->enode, databuf);
ebuf_free (databuf);
};
string function get_data () {
EBufConst *data;
data = enode_get_data (js_instance->enode);
if (data) {
js_retval->type = JS_STRING;
js_vm_make_string (js_vm, js_retval, data->str, data->len);
} else {
js_retval->type = JS_NULL;
}
};
undefined function append_data (string data) {
EBufFreeMe *databuf;
databuf = ebuf_new_with_data (js_tempnode.u.vstring->data,
js_tempnode.u.vstring->len);
enode_append_data (js_instance->enode, databuf);
ebuf_free (databuf);
};
undefined function insert_data (int offset, string data) {
EBufFreeMe *databuf;
databuf = ebuf_new_with_data (js_tempnode.u.vstring->data,
js_tempnode.u.vstring->len);
enode_insert_data (js_instance->enode, offset, databuf);
ebuf_free (databuf);
};
undefined function delete_data (int offset, int count) {
enode_delete_data (js_instance->enode, offset, count);
};
};
object function enode (string basename) {
ENode *node;
JSBuiltinInfo *enode_info;
node = enode (enode_call_reference(), basename);
if (node) {
JSNode *enode_node;
enode_node = &js_vm->globals[js_vm_intern(js_vm, "ENode")];
enode_info = enode_node->u.vbuiltin->info;
js_return_enode (js_vm, enode_info, js_retval, node);
} else {
js_retval->type = JS_NULL;
}
};
object function enode_rx (string regex) {
ENode *node;
JSBuiltinInfo *enode_info;
node = enode_rx (enode_call_reference(), regex);
if (node) {
JSNode *enode_node;
enode_node = &js_vm->globals[js_vm_intern(js_vm, "ENode")];
enode_info = enode_node->u.vbuiltin->info;
js_return_enode (js_vm, enode_info, js_retval, node);
} else {
js_retval->type = JS_NULL;
}
};
|