JSValueRef function_import_script(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef args[], JSValueRef* exception) { if (argc == 1 && JSValueGetType(ctx, args[0]) == kJSTypeString) { JSStringRef path_str_ref = JSValueToStringCopy(ctx, args[0], NULL); assert(JSStringGetLength(path_str_ref) < 100); char tmp[100]; tmp[0] = '\0'; JSStringGetUTF8CString(path_str_ref, tmp, 100); JSStringRelease(path_str_ref); char *path = tmp; if (str_has_prefix(path, "goog/../") == 0) { path = path + 8; } char *source = NULL; if (out_path == NULL) { source = bundle_get_contents(path); } else { char *full_path = str_concat(out_path, path); source = get_contents(full_path, NULL); free(full_path); } if (source != NULL) { evaluate_script(ctx, source, path); free(source); } } return JSValueMakeUndefined(ctx); }
JSValueRef function_import_script(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef args[], JSValueRef *exception) { if (argc == 1 && JSValueGetType(ctx, args[0]) == kJSTypeString) { JSStringRef path_str_ref = JSValueToStringCopy(ctx, args[0], NULL); assert(JSStringGetLength(path_str_ref) < 100); char tmp[100]; tmp[0] = '\0'; JSStringGetUTF8CString(path_str_ref, tmp, 100); JSStringRelease(path_str_ref); bool can_skip_load = false; char *path = tmp; if (str_has_prefix(path, "goog/../") == 0) { path = path + 8; } else { unsigned long h = hash((unsigned char *) path); if (is_loaded(h)) { can_skip_load = true; } else { add_loaded_hash(h); } } if (!can_skip_load) { char *source = NULL; if (config.out_path == NULL) { source = bundle_get_contents(path); } else { char *full_path = str_concat(config.out_path, path); source = get_contents(full_path, NULL); free(full_path); } if (source != NULL) { evaluate_script(ctx, source, path); display_launch_timing(path); free(source); } } } return JSValueMakeUndefined(ctx); }
MainWindow::MainWindow(QWidget* parent) : CGAL::Qt::DemosMainWindow(parent) { ui = new Ui::MainWindow; ui->setupUi(this); // remove the Load Script menu entry, when the demo has not been compiled with QT_SCRIPT_LIB #if !defined(QT_SCRIPT_LIB) ui->menuBar->removeAction(ui->actionLoad_Script); #endif // Save some pointers from ui, for latter use. sceneView = ui->sceneView; viewer = ui->viewer; // do not save the state of the viewer (anoying) viewer->setStateFileName(QString::null); // setup scene scene = new Scene(this); viewer->setScene(scene); { QShortcut* shortcut = new QShortcut(QKeySequence(Qt::ALT+Qt::Key_Q), this); connect(shortcut, SIGNAL(activated()), this, SLOT(setFocusToQuickSearch())); } proxyModel = new QSortFilterProxyModel(this); proxyModel->setSourceModel(scene); connect(ui->searchEdit, SIGNAL(textChanged(QString)), proxyModel, SLOT(setFilterFixedString(QString))); sceneView->setModel(proxyModel); // setup the sceneview: delegation and columns sizing... sceneView->setItemDelegate(new SceneDelegate(this)); sceneView->header()->setStretchLastSection(false); sceneView->header()->setSectionResizeMode(Scene::NameColumn, QHeaderView::Stretch); sceneView->header()->setSectionResizeMode(Scene::NameColumn, QHeaderView::Stretch); sceneView->header()->setSectionResizeMode(Scene::ColorColumn, QHeaderView::ResizeToContents); sceneView->header()->setSectionResizeMode(Scene::RenderingModeColumn, QHeaderView::Fixed); sceneView->header()->setSectionResizeMode(Scene::ABColumn, QHeaderView::Fixed); sceneView->header()->setSectionResizeMode(Scene::VisibleColumn, QHeaderView::Fixed); sceneView->resizeColumnToContents(Scene::ColorColumn); sceneView->resizeColumnToContents(Scene::RenderingModeColumn); sceneView->resizeColumnToContents(Scene::ABColumn); sceneView->resizeColumnToContents(Scene::VisibleColumn); // setup connections connect(scene, SIGNAL(dataChanged(const QModelIndex &, const QModelIndex & )), this, SLOT(updateInfo())); connect(scene, SIGNAL(dataChanged(const QModelIndex &, const QModelIndex & )), this, SLOT(updateDisplayInfo())); connect(scene, SIGNAL(dataChanged(const QModelIndex &, const QModelIndex & )), viewer, SLOT(updateGL())); connect(scene, SIGNAL(updated()), viewer, SLOT(updateGL())); connect(scene, SIGNAL(updated()), this, SLOT(selectionChanged())); connect(scene, SIGNAL(itemAboutToBeDestroyed(Scene_item*)), this, SLOT(removeManipulatedFrame(Scene_item*))); connect(scene, SIGNAL(updated_bbox()), this, SLOT(updateViewerBBox())); connect(scene, SIGNAL(selectionChanged(int)), this, SLOT(selectSceneItem(int))); connect(sceneView->selectionModel(), SIGNAL(selectionChanged ( const QItemSelection & , const QItemSelection & ) ), this, SLOT(updateInfo())); connect(sceneView->selectionModel(), SIGNAL(selectionChanged ( const QItemSelection & , const QItemSelection & ) ), this, SLOT(updateDisplayInfo())); connect(sceneView->selectionModel(), SIGNAL(selectionChanged ( const QItemSelection & , const QItemSelection & ) ), this, SLOT(selectionChanged())); sceneView->setContextMenuPolicy(Qt::CustomContextMenu); connect(sceneView, SIGNAL(customContextMenuRequested(const QPoint & )), this, SLOT(showSceneContextMenu(const QPoint &))); connect(viewer, SIGNAL(selected(int)), this, SLOT(selectSceneItem(int))); connect(viewer, SIGNAL(selectedPoint(double, double, double)), this, SLOT(showSelectedPoint(double, double, double))); connect(viewer, SIGNAL(selectionRay(double, double, double, double, double, double)), scene, SIGNAL(selectionRay(double, double, double, double, double, double))); connect(viewer, SIGNAL(requestContextMenu(QPoint)), this, SLOT(contextMenuRequested(QPoint))); // The contextMenuPolicy of infoLabel is now the default one, so that one // can easily copy-paste its text. // connect(ui->infoLabel, SIGNAL(customContextMenuRequested(const QPoint & )), // this, SLOT(showSceneContextMenu(const QPoint &))); connect(ui->actionRecenterScene, SIGNAL(triggered()), viewer, SLOT(update())); connect(ui->actionAntiAliasing, SIGNAL(toggled(bool)), viewer, SLOT(setAntiAliasing(bool))); connect(ui->actionDraw_two_sides, SIGNAL(toggled(bool)), viewer, SLOT(setTwoSides(bool))); // add the "About CGAL..." and "About demo..." entries this->addAboutCGAL(); this->addAboutDemo(":/cgal/Polyhedron_3/about.html"); // Connect the button "addButton" with actionLoad ui->addButton->setDefaultAction(ui->actionLoad); // Same with "removeButton" and "duplicateButton" ui->removeButton->setDefaultAction(ui->actionErase); ui->duplicateButton->setDefaultAction(ui->actionDuplicate); // Connect actionQuit (Ctrl+Q) and qApp->quit() connect(ui->actionQuit, SIGNAL(triggered()), this, SLOT(quit())); // Connect "Select all items" connect(ui->actionSelect_all_items, SIGNAL(triggered()), this, SLOT(selectAll())); // Recent files menu this->addRecentFiles(ui->menuFile, ui->actionQuit); connect(this, SIGNAL(openRecentFile(QString)), this, SLOT(open(QString))); // Reset the "Operation menu" clearMenu(ui->menuOperations); #ifdef QT_SCRIPT_LIB std::cerr << "Enable scripts.\n"; script_engine = new QScriptEngine(this); qScriptRegisterMetaType<Scene_item*>(script_engine, myScene_itemToScriptValue, myScene_itemFromScriptValue); # ifdef QT_SCRIPTTOOLS_LIB QScriptEngineDebugger* debugger = new QScriptEngineDebugger(this); debugger->setObjectName("qt script debugger"); QAction* debuggerMenuAction = menuBar()->addMenu(debugger->createStandardMenu()); debuggerMenuAction->setText(tr("Qt Script &debug")); for(unsigned int i = 0; i < 9; ++i) { QDockWidget* dock = new QDockWidget(debug_widgets_names[i], this); dock->setObjectName(debug_widgets_names[i]); dock->setWidget(debugger->widget(debug_widgets[i])); this->addDockWidget(Qt::BottomDockWidgetArea, dock); dock->hide(); } debugger->setAutoShowStandardWindow(false); debugger->attachTo(script_engine); # endif // QT_SCRIPTTOOLS_LIB QScriptValue fun = script_engine->newFunction(myPrintFunction); script_engine->globalObject().setProperty("print", fun); // evaluate_script("print('hello', 'world', 'from QtScript!')"); QScriptValue mainWindowObjectValue = script_engine->newQObject(this); script_engine->globalObject().setProperty("main_window", mainWindowObjectValue); QScriptValue sceneObjectValue = script_engine->newQObject(scene); mainWindowObjectValue.setProperty("scene", sceneObjectValue); script_engine->globalObject().setProperty("scene", sceneObjectValue); QScriptValue viewerObjectValue = script_engine->newQObject(viewer); mainWindowObjectValue.setProperty("viewer", viewerObjectValue); script_engine->globalObject().setProperty("viewer", viewerObjectValue); QScriptValue cameraObjectValue = script_engine->newQObject(viewer->camera()); viewerObjectValue.setProperty("camera", cameraObjectValue); script_engine->globalObject().setProperty("camera", cameraObjectValue); evaluate_script("var plugins = new Array();"); # ifdef QT_SCRIPTTOOLS_LIB QScriptValue debuggerObjectValue = script_engine->newQObject(debugger); script_engine->globalObject().setProperty("debugger", debuggerObjectValue); # endif #endif readSettings(); // Among other things, the column widths are stored. // Load plugins, and re-enable actions that need it. loadPlugins(); // Setup the submenu of the View menu that can toggle the dockwidgets Q_FOREACH(QDockWidget* widget, findChildren<QDockWidget*>()) { ui->menuDockWindows->addAction(widget->toggleViewAction()); }
int main(int argc, char **argv) { struct option long_options[] = { {"help", no_argument, NULL, 'h'}, {"legal", no_argument, NULL, 'l'}, {"verbose", no_argument, NULL, 'v'}, {"quiet", no_argument, NULL, 'q'}, {"repl", no_argument, NULL, 'r'}, {"static-fns", no_argument, NULL, 's'}, {"elide-asserts", no_argument, NULL, 'a'}, {"cache", required_argument, NULL, 'k'}, {"eval", required_argument, NULL, 'e'}, {"theme", required_argument, NULL, 't'}, {"classpath", required_argument, NULL, 'c'}, {"auto-cache", no_argument, NULL, 'K'}, {"init", required_argument, NULL, 'i'}, {"main", required_argument, NULL, 'm'}, // development options {"javascript", no_argument, NULL, 'j'}, {"out", required_argument, NULL, 'o'}, {0, 0, 0, 0} }; int opt, option_index; while ((opt = getopt_long(argc, argv, "h?lvrsak:je:t:c:o:Ki:qm:", long_options, &option_index)) != -1) { switch (opt) { case 'h': usage(argv[0]); exit(0); case 'l': legal(); return 0; case 'v': verbose = true; break; case 'q': quiet = true; break; case 'r': repl = true; break; case 's': static_fns = true; break; case 'a': elide_asserts = true; break; case 'k': cache_path = argv[optind - 1]; break; case 'K': cache_path = ".planck_cache"; { char *path_copy = strdup(cache_path); char *dir = dirname(path_copy); if (mkdir_p(dir) < 0) { fprintf(stderr, "Could not create %s: %s\n", cache_path, strerror(errno)); } free(path_copy); } break; case 'j': javascript = true; break; case 'e': num_scripts += 1; scripts = realloc(scripts, num_scripts * sizeof(struct script)); scripts[num_scripts - 1].type = "text"; scripts[num_scripts - 1].expression = true; scripts[num_scripts - 1].source = argv[optind - 1]; break; case 'i': num_scripts += 1; scripts = realloc(scripts, num_scripts * sizeof(struct script)); scripts[num_scripts - 1].type = "path"; scripts[num_scripts - 1].expression = false; scripts[num_scripts - 1].source = argv[optind - 1]; break; case 'm': main_ns_name = argv[optind - 1]; case 't': theme = argv[optind - 1]; break; case 'c': { char *classpath = argv[optind - 1]; char *source = strtok(classpath, ":"); while (source != NULL) { char *type = "src"; if (str_has_suffix(source, ".jar") == 0) { type = "jar"; } num_src_paths += 1; src_paths = realloc(src_paths, num_src_paths * sizeof(struct src_path)); src_paths[num_src_paths - 1].type = type; src_paths[num_src_paths - 1].path = strdup(source); source = strtok(NULL, ":"); } break; } case 'o': out_path = argv[optind - 1]; break; case '?': usage(argv[0]); exit(1); default: printf("unhandled argument: %c\n", opt); } } int num_rest_args = 0; char **rest_args = NULL; if (optind < argc) { num_rest_args = argc - optind; rest_args = malloc((argc - optind) * sizeof(char*)); int i = 0; while (optind < argc) { rest_args[i++] = argv[optind++]; } } if (num_scripts == 0 && main_ns_name == NULL && num_rest_args == 0) { repl = true; } if (main_ns_name != NULL && repl) { printf("Only one main-opt can be specified."); } JSGlobalContextRef ctx = JSGlobalContextCreate(NULL); JSStringRef nameRef = JSStringCreateWithUTF8CString("planck"); JSGlobalContextSetName(ctx, nameRef); evaluate_script(ctx, "var global = this;", "<init>"); register_global_function(ctx, "AMBLY_IMPORT_SCRIPT", function_import_script); bootstrap(ctx, out_path); register_global_function(ctx, "PLANCK_CONSOLE_LOG", function_console_log); register_global_function(ctx, "PLANCK_CONSOLE_ERROR", function_console_error); evaluate_script(ctx, "var console = {};"\ "console.log = PLANCK_CONSOLE_LOG;"\ "console.error = PLANCK_CONSOLE_ERROR;", "<init>"); evaluate_script(ctx, "var PLANCK_VERSION = \"" PLANCK_VERSION "\";", "<init>"); // require app namespaces evaluate_script(ctx, "goog.require('planck.repl');", "<init>"); // without this things won't work evaluate_script(ctx, "var window = global;", "<init>"); register_global_function(ctx, "PLANCK_READ_FILE", function_read_file); register_global_function(ctx, "PLANCK_LOAD", function_load); register_global_function(ctx, "PLANCK_LOAD_DEPS_CLJS_FILES", function_load_deps_cljs_files); register_global_function(ctx, "PLANCK_CACHE", function_cache); register_global_function(ctx, "PLANCK_EVAL", function_eval); register_global_function(ctx, "PLANCK_GET_TERM_SIZE", function_get_term_size); register_global_function(ctx, "PLANCK_PRINT_FN", function_print_fn); register_global_function(ctx, "PLANCK_PRINT_ERR_FN", function_print_err_fn); register_global_function(ctx, "PLANCK_SET_EXIT_VALUE", function_set_exit_value); is_tty = isatty(STDIN_FILENO) == 1; register_global_function(ctx, "PLANCK_RAW_READ_STDIN", function_raw_read_stdin); register_global_function(ctx, "PLANCK_RAW_WRITE_STDOUT", function_raw_write_stdout); register_global_function(ctx, "PLANCK_RAW_FLUSH_STDOUT", function_raw_flush_stdout); register_global_function(ctx, "PLANCK_RAW_WRITE_STDERR", function_raw_write_stderr); register_global_function(ctx, "PLANCK_RAW_FLUSH_STDERR", function_raw_flush_stderr); { JSValueRef arguments[num_rest_args]; for (int i = 0; i < num_rest_args; i++) { arguments[i] = c_string_to_value(ctx, rest_args[i]); } JSValueRef args_ref = JSObjectMakeArray(ctx, num_rest_args, arguments, NULL); JSValueRef global_obj = JSContextGetGlobalObject(ctx); JSStringRef prop = JSStringCreateWithUTF8CString("PLANCK_INITIAL_COMMAND_LINE_ARGS"); JSObjectSetProperty(ctx, JSValueToObject(ctx, global_obj, NULL), prop, args_ref, kJSPropertyAttributeNone, NULL); JSStringRelease(prop); } evaluate_script(ctx, "cljs.core.set_print_fn_BANG_.call(null,PLANCK_PRINT_FN);", "<init>"); evaluate_script(ctx, "cljs.core.set_print_err_fn_BANG_.call(null,PLANCK_PRINT_ERR_FN);", "<init>"); char *elide_script = str_concat("cljs.core._STAR_assert_STAR_ = ", elide_asserts ? "false" : "true"); evaluate_script(ctx, elide_script, "<init>"); free(elide_script); { JSValueRef arguments[4]; arguments[0] = JSValueMakeBoolean(ctx, repl); arguments[1] = JSValueMakeBoolean(ctx, verbose); JSValueRef cache_path_ref = NULL; if (cache_path != NULL) { JSStringRef cache_path_str = JSStringCreateWithUTF8CString(cache_path); cache_path_ref = JSValueMakeString(ctx, cache_path_str); } arguments[2] = cache_path_ref; arguments[3] = JSValueMakeBoolean(ctx, static_fns); JSValueRef ex = NULL; JSObjectCallAsFunction(ctx, get_function(ctx, "planck.repl", "init"), JSContextGetGlobalObject(ctx), 4, arguments, &ex); debug_print_value("planck.repl/init", ctx, ex); } if (repl) { evaluate_source(ctx, "text", "(require '[planck.repl :refer-macros [apropos dir find-doc doc source pst]])", true, false, "cljs.user", "dumb"); } evaluate_script(ctx, "goog.provide('cljs.user');", "<init>"); evaluate_script(ctx, "goog.require('cljs.core');", "<init>"); evaluate_script(ctx, "cljs.core._STAR_assert_STAR_ = true;", "<init>"); // Process init arguments for (int i = 0; i < num_scripts; i++) { // TODO: exit if not successfull evaluate_source(ctx, scripts[i].type, scripts[i].source, scripts[i].expression, false, NULL, theme); } // Process main arguments if (main_ns_name != NULL) { run_main_in_ns(ctx, main_ns_name, num_rest_args, rest_args); } else if (!repl && num_rest_args > 0) { char *path = rest_args[0]; struct script script; if (strcmp(path, "-") == 0) { char *source = read_all(stdin); script.type = "text"; script.source = source; script.expression = false; } else { script.type = "path"; script.source = path; script.expression = false; } evaluate_source(ctx, script.type, script.source, script.expression, false, NULL, theme); } else if (repl) { if (!quiet) { banner(); } char *home = getenv("HOME"); char *history_path = NULL; if (home != NULL) { char history_name[] = ".planck_history"; int len = strlen(home) + strlen(history_name) + 2; history_path = malloc(len * sizeof(char)); snprintf(history_path, len, "%s/%s", home, history_name); linenoiseHistoryLoad(history_path); } char *prompt = javascript ? " > " : " => "; char *line; while ((line = linenoise(prompt)) != NULL) { if (javascript) { JSValueRef res = evaluate_script(ctx, line, "<stdin>"); print_value("", ctx, res); } else { evaluate_source(ctx, "text", line, true, true, "cljs.user", theme); } linenoiseHistoryAdd(line); if (history_path != NULL) { linenoiseHistorySave(history_path); } free(line); } } return exit_value; }
tree evaluate_impl (tree t) { //cout << "Really evaluate " << t << LF; switch (L(t)) { /* Typesetting primitives with side effects */ case DATOMS: return evaluate_formatting (t, ATOM_DECORATIONS); case DLINES: return evaluate_formatting (t, LINE_DECORATIONS); case DPAGES: return evaluate_formatting (t, PAGE_DECORATIONS); case TFORMAT: return evaluate_formatting (t, CELL_FORMAT); case TABLE: return evaluate_table (t); /* Primitives for macro expansion */ case ASSIGN: return evaluate_assign (t); case WITH: return evaluate_with (t); case PROVIDES: return evaluate_provides (t); case VALUE: return evaluate_value (t); case QUOTE_VALUE: return evaluate_quote_value (t); case MACRO: return copy (t); case DRD_PROPS: return evaluate_drd_props (t); #ifdef CLASSICAL_MACRO_EXPANSION case ARG: return evaluate_arg (t); case QUOTE_ARG: return evaluate_quote_arg (t); #endif case COMPOUND: return evaluate_compound (t); case XMACRO: return copy (t); case GET_LABEL: return evaluate_get_label (t); case GET_ARITY: return evaluate_get_arity (t); /* Primitives for quoting and evaluation */ case MAP_ARGS: return evaluate_rewrite (t); case EVAL_ARGS: return evaluate_eval_args (t); case MARK: return tree (MARK, copy (t[0]), evaluate (t[1])); case EXPAND_AS: return evaluate (t[1]); case EVAL: return evaluate (evaluate (t[0])); case QUOTE: return t[0]; case QUASI: return evaluate (evaluate_quasiquote (t[0])); case QUASIQUOTE: return evaluate_quasiquote (t[0]); case UNQUOTE: case VAR_UNQUOTE: return evaluate (t[0]); case COPY: return copy (evaluate (t[0])); /* Control structures */ case IF: case VAR_IF: return evaluate_if (t); case CASE: return evaluate_case (t); case WHILE: return evaluate_while (t); case FOR_EACH: return evaluate_for_each (t); case EXTERN: return evaluate_rewrite (t); case VAR_INCLUDE: return evaluate_include (t); case WITH_PACKAGE: return evaluate_rewrite (t); case USE_PACKAGE: return evaluate_use_package (t); case USE_MODULE: return evaluate_use_module (t); /* Computational markup */ case OR: return evaluate_or (t); case XOR: return evaluate_xor (t); case AND: return evaluate_and (t); case NOT: return evaluate_not (t); case PLUS: case MINUS: return evaluate_plus_minus (t); case TIMES: case OVER: return evaluate_times_over (t); case DIV: return evaluate_divide (t); case MOD: return evaluate_modulo (t); case MATH_SQRT: return evaluate_math_sqrt (t); case EXP: return evaluate_exp (t); case LOG: return evaluate_log (t); case POW: return evaluate_pow (t); case COS: return evaluate_cos (t); case SIN: return evaluate_sin (t); case TAN: return evaluate_tan (t); case MERGE: return evaluate_merge (t); case LENGTH: return evaluate_length (t); case RANGE: return evaluate_range (t); case NUMBER: return evaluate_number (t); case _DATE: return evaluate_date (t); case TRANSLATE: return evaluate_translate (t); case CHANGE_CASE: return evaluate_change_case (t); case FIND_FILE: return evaluate_find_file (t); case IS_TUPLE: return evaluate_is_tuple (t); case LOOK_UP: return evaluate_lookup (t); case EQUAL: return evaluate_equal (t); case UNEQUAL: return evaluate_unequal (t); case LESS: return evaluate_less (t); case LESSEQ: return evaluate_lesseq (t); case GREATER: return evaluate_greater (t); case GREATEREQ: return evaluate_greatereq (t); case BLEND: return evaluate_blend (t); /* Length units */ case CM_LENGTH: return evaluate_cm_length (); case MM_LENGTH: return evaluate_mm_length (); case IN_LENGTH: return evaluate_in_length (); case PT_LENGTH: return evaluate_pt_length (); case BP_LENGTH: return evaluate_bp_length (); case DD_LENGTH: return evaluate_dd_length (); case PC_LENGTH: return evaluate_pc_length (); case CC_LENGTH: return evaluate_cc_length (); case FS_LENGTH: return evaluate_fs_length (); case FBS_LENGTH: return evaluate_fbs_length (); case EM_LENGTH: return evaluate_em_length (); case LN_LENGTH: return evaluate_ln_length (); case SEP_LENGTH: return evaluate_sep_length (); case YFRAC_LENGTH: return evaluate_yfrac_length (); case EX_LENGTH: return evaluate_ex_length (); case FN_LENGTH: return evaluate_fn_length (); case FNS_LENGTH: return evaluate_fns_length (); case BLS_LENGTH: return evaluate_bls_length (); case FNBOT_LENGTH: return evaluate_fnbot_length (); case FNTOP_LENGTH: return evaluate_fntop_length (); case SPC_LENGTH: return evaluate_spc_length (); case XSPC_LENGTH: return evaluate_xspc_length (); case PAR_LENGTH: return evaluate_par_length (); case PAG_LENGTH: return evaluate_pag_length (); case GW_LENGTH: return evaluate_gw_length (); case GH_LENGTH: return evaluate_gh_length (); case GU_LENGTH: return evaluate_gu_length (); case TMPT_LENGTH: return evaluate_tmpt_length (); case PX_LENGTH: return evaluate_px_length (); case MSEC_LENGTH: return evaluate_msec_length (); case SEC_LENGTH: return evaluate_sec_length (); case MIN_LENGTH: return evaluate_min_length (); case HR_LENGTH: return evaluate_hr_length (); /* Primitives for stylesheet editing */ case STYLE_WITH: case VAR_STYLE_WITH: return evaluate (t[N(t)-1]); case STYLE_ONLY: case VAR_STYLE_ONLY: case ACTIVE: case VAR_ACTIVE: case INACTIVE: case VAR_INACTIVE: return evaluate_compound (t); case REWRITE_INACTIVE: return evaluate_rewrite (t); /* Linking primitives */ case HARD_ID: return evaluate_hard_id (t[0]); case SCRIPT: return evaluate_script (t); case HLINK: case ACTION: return evaluate_compound (t); case SET_BINDING: return evaluate_set_binding (t); case GET_BINDING: return evaluate_get_binding (t); /* Graphical primitives */ case PATTERN: return evaluate_pattern (t); case _POINT: return evaluate_point (t); /* case BOX_INFO: return evaluate_box_info (t); case FRAME_DIRECT: return evaluate_frame_direct (t); case FRAME_INVERSE: return evaluate_frame_inverse (t); */ /* User extensions */ default: if (L(t) < START_EXTENSIONS) { int i, n= N(t); tree r (t, n); for (i=0; i<n; i++) r[i]= evaluate (t[i]); transfer_ip (t, r); return r; } else { tree r= evaluate_compound (t); return r; } } }
static int eval_count (int argc, SCRIPT_NODE **argv, SCRIPT_NODE *result) { long item, n; SCRIPT_NODE *identifier = argc > 0 ? argv [0] : NULL, *condition = argc > 1 ? argv [1] : NULL; char *name, *xml_name; SCOPE_BLOCK *for_block; SCOPE_ITEM *scope_item; XML_ITEM *from_xml, *xml_item; Bool error = FALSE; if (identifier-> type == GG_SYMBOL) { if ((evaluate_script_node (identifier-> op1) != 0) || (evaluate_script_node (identifier-> op2) != 0)) return -1; from_xml = lookup_from_xml (identifier-> op1); if (! from_xml) return -1; name = (identifier-> op2) ? string_result (identifier-> op2) : NULL; } else { gg_report_error ('E', "Function argument must be an identifier."); return -1; } n = 0; if (from_xml) { for_block = create_scope_block ("count"); for_block-> children = TRUE; xml_item = xml_first_child (from_xml); item = 0; while (xml_item) { while (xml_item) { xml_name = xml_item_name (xml_item); if (xml_name && name) { if (ignorecase) { if (lexcmp (xml_name, name) == 0) break; } else { if (streq (xml_name, name)) break; } } else /* Take all named children; others are part of value */ if (xml_name && (! name)) break; xml_item = xml_next_sibling (xml_item); } item++; if (xml_item) { if (condition) { scope_item = create_scope_item (for_block, xml_item, item); for_block-> scope_item = scope_item; for_block-> xml_item = xml_item; if (evaluate_script (condition) != 0) { error = TRUE; break; } number_result (condition); if ((condition-> result_type == TYPE_NUMBER) && (condition-> result_n != 0)) n++; gg_clean (condition); } else n++; xml_item = xml_next_sibling (xml_item); } } destroy_scope_block (); if (error) return -1; } result-> result_type = TYPE_NUMBER; result-> result_n = n; return 0; }