Exemple #1
1
static void do_texio_ini_print(lua_State * L, const char *extra)
{
    const char *s;
    int i = 1;
    int l = term_and_log;
    int n = lua_gettop(L);
    if (n > 1) {
        if (get_selector_value(L, i, &l))
            i++;
    }
    for (; i <= n; i++) {
        if (lua_isstring(L, i)) {
            s = lua_tostring(L, i);
            if (l == term_and_log || l == term_only)
                fprintf(stdout, "%s%s", extra, s);
            if (l == log_only || l == term_and_log) {
                if (loggable_info == NULL) {
                    loggable_info = strdup(s);
                } else {
                    char *v = concat3(loggable_info, extra, s);
                    free(loggable_info);
                    loggable_info = v;
                }
            }
        }
    }
}
Exemple #2
0
static int do_texio_print(lua_State * L, texio_printer printfunction)
{
    const char *s;
    int i = 1;
    int save_selector = selector;
    int n = lua_gettop(L);
    if (n == 0 || !lua_isstring(L, -1)) {
	luaL_error(L, "no string to print");
    }
    if (n > 1) {
        if (get_selector_value(L, i, &selector))
            i++;
    }
    if (selector != log_only && selector != term_only
        && selector != term_and_log) {
        normalize_selector();   /* sets selector */
    }
    for (; i <= n; i++) {
        if (lua_isstring(L, i)) {
            s = lua_tostring(L, i);
            printfunction(s);
        } else {
            luaL_error(L, "argument is not a string");
        }
    }
    selector = save_selector;
    return 0;
}
static object* read_class(resource_mgr_t *resmgr, int script, int positions[1000]) {
	resource_t* r = scir_find_resource(resmgr, sci_script, script, 0);
	unsigned char* raw;
	int pos;
	object* obj;

	printf("Searching for class in script %03d\n", script);

	if (r == 0) return fake_object("<resource not found>");

	/*Skip to the next class*/
#ifdef SCRIPT_DEBUG
	printf("pre skip: pos=%#x\n", positions[script]);
#endif
	pos = find_frame(r, 6, positions[script]);
#ifdef SCRIPT_DEBUG
	printf("post skip: pos=%#x\n", pos);
#endif
	if (pos == -1) return fake_object("<no more classes in script>");
	else positions[script] = pos + get_length(r->data + pos);
#ifdef SCRIPT_DEBUG
	printf("post post: pos=%#x (len=%#x)\n", positions[script], get_length(r->data + pos));
#endif

	/*Construct the object*/
	obj = object_new();
	raw = r->data + pos;

	/*Fill in the name*/
	if (get_selector_count(raw) < 4) obj->name = "<anonymous>";
	else {
		if (get_selector_value(raw, 3))
			obj->name = (char *) r->data + get_selector_value(raw, 3);
		else obj->name = "<null>";
	}

	/*Fill in the parent*/
	if (get_selector_count(raw) == 0) obj->parent = object_root;
	else {
		int superclass_id = get_selector_value(raw, 1);
		printf("superclass==%d\n", superclass_id);
		if (superclass_id >= fobjects.used) {
			free(obj);
			return fake_object("<no such superclass>");
		}
		if (superclass_id < 1) obj->parent = object_root;
		else obj->parent = fobjects.data[superclass_id];
	}

	/*Add the class to the hierarchy*/
	if (!obj->parent) {
		free(obj);
		return fake_object("<null parent>");
	}
	if (add_child(obj->parent, obj)) {
		free(obj);
		return fake_object("<add_child failed>");
	}
	if (add_object(obj)) {
		free(obj);
		return fake_object("<add_object failed>");
	}

	/*FIXME: decode selectors and methods here*/

	return obj;
}
static object* read_object(resource_mgr_t *resmgr, int script, int positions[1000]) {
	resource_t* r = scir_find_resource(resmgr, sci_script, script, 0);
	unsigned char* raw;
	int pos;
	object* obj;

	printf("Searching for object in script %03d\n", script);

	if (r == 0) return 0;

	/*Skip to the next object*/
#ifdef SCRIPT_DEBUG
	printf("pre skip: pos=%#x\n", positions[script]);
#endif
	pos = find_frame(r, 1, positions[script]);
#ifdef SCRIPT_DEBUG
	printf("post skip: pos=%#x\n", pos);
#endif
	if (pos == -1) return 0;
	else positions[script] = pos + get_length(r->data + pos);
#ifdef SCRIPT_DEBUG
	printf("post post: pos=%#x (len=%#x)\n", positions[script], get_length(r->data + pos));
#endif

	/*Construct the object*/
	obj = object_new();
	raw = r->data + pos;

	/*Fill in the name*/
	if (get_selector_count(raw) < 4) obj->name = "<anonymous>";
	else {
		if (get_selector_value(raw, 3))
			obj->name = (char *) r->data + get_selector_value(raw, 3);
		else obj->name = "<null>";
	}

	/*Fill in the class*/
	if (get_selector_count(raw) == 0) obj->parent = object_root;
	else {
		int parent_id = get_selector_value(raw, 1);
		if (parent_id >= fobjects.used) {
			free(obj);
			return 0;
		}
		if (parent_id < 1) obj->parent = object_root;
		else obj->parent = fobjects.data[parent_id];
	}

	/*Add the object to the class*/
	if (!obj->parent) {
		free(obj);
		return 0;
	}
	if (add_child(obj->parent, obj)) {
		free(obj);
		return 0;
	}
	if (add_object(obj)) {
		free(obj);
		return 0;
	}

	/*FIXME: decode selectors here*/

	obj->method_count = get_method_count(raw);
	obj->methods = (script_method**)sci_malloc(obj->method_count * sizeof(script_method));
	if (obj->methods == 0) {
		free(obj);
		return 0;
	} else {
		int i;
		for (i = 0; i < obj->method_count; i++) {
			int number = get_method_number(raw, i);
			int position = get_method_location(raw, i);

			if ((obj->methods[i] = decode_method(r->data + position)) == 0) {
				obj->method_count = i - 1;
				break;
			}
			obj->methods[i]->number = number;
		}
	}

	return obj;
}