Exemple #1
0
int main() {
	{
		char tmpFileName[L_tmpnam + 1];
		tmpnam(tmpFileName);

		FILE* fp = fopen(tmpFileName, "wb");
		check_bool(true, write_int(fp, 1231));
		check_bool(true, write_int(fp, 1));
		check_bool(true, write_int(fp, 441));
		check_int(0, fclose(fp));

		int_sorter(tmpFileName);

		fp = fopen(tmpFileName, "rb");
		check_int(1, read_int(fp));
		check_int(441, read_int(fp));
		check_int(1231, read_int(fp));
		check_int(0, fclose(fp));
	}

	{
		char tmpFileName[L_tmpnam + 1];
		tmpnam(tmpFileName);

		FILE* fp = fopen(tmpFileName, "w");
		check_int(0, fclose(fp));

		int_sorter(tmpFileName);
	}
}
static int rbody_ranged_scatter (lua_State *L)
{
TRY_START
        check_args(L, 12);
        GET_UD_MACRO(RigidBody, self, 1, RBODY_TAG);
        std::string mat    = check_path(L, 2);
        GET_UD_MACRO(GfxRangedInstancesPtr, gri, 3, GFXRANGEDINSTANCES_TAG);
        float density       = check_float(L, 4);
        float min_slope     = check_float(L, 5);
        float max_slope     = check_float(L, 6);
        float min_elevation = check_float(L, 7);
        float max_elevation = check_float(L, 8);
        bool no_z           = check_bool(L, 9);
        bool rotate         = check_bool(L, 10);
        bool align_slope    = check_bool(L, 11);
        unsigned seed       = check_t<unsigned>(L, 12);

        SimpleTransform world_trans(self.getPosition(), self.getOrientation());

        self.colMesh->scatter(phys_mats.getMaterial(mat)->id,
                              world_trans, density, min_slope, max_slope, min_elevation,
                              max_elevation, no_z, rotate, align_slope, seed,
                              *gri);

        return 0;
TRY_END
}
static int global_physics_test (lua_State *L)
{
TRY_START
        LuaTestCallback lcb;
        push_cfunction(L, my_lua_error_handler);
        int error_handler = lua_gettop(L);
        if (lua_gettop(L)==5) {
                float radius = lua_tonumber(L, 1);
                Vector3 pos = check_v3(L, 2);
                bool only_dyn = check_bool(L, 3);
                if (lua_type(L, 4) != LUA_TFUNCTION)
                        my_lua_error(L, "Parameter 4 should be a function.");

                physics_test_sphere(radius, pos, only_dyn, lcb);
                lcb.pushResults(L, 4, error_handler);
        } else {
                check_args(L, 6);
                std::string col_mesh_name = check_path(L, 1);
                DiskResource *col_mesh_ = disk_resource_get_or_make(col_mesh_name);
                CollisionMesh *col_mesh = dynamic_cast<CollisionMesh*>(col_mesh_);
                if (col_mesh==NULL) my_lua_error(L, "Not a collision mesh: \""+col_mesh_name+"\"");
                if (!col_mesh->isLoaded()) my_lua_error(L, "Not loaded: \""+col_mesh_name+"\"");
                Vector3 pos = check_v3(L, 2);
                Quaternion quat = check_quat(L, 3);
                bool only_dyn = check_bool(L, 4);
                if (lua_type(L, 5) != LUA_TFUNCTION)
                        my_lua_error(L, "Parameter 5 should be a function.");

                physics_test(col_mesh, pos, quat, only_dyn, lcb);
                lcb.pushResults(L, 5, error_handler);
        }
        lua_pop(L, 1); // error handler
        return 0;
TRY_END
}
static int global_physics_sweep_col_mesh (lua_State *L)
{
TRY_START
        int base_line = 7;
        check_args_min(L, base_line);

        std::string col_mesh_name = check_path(L, 1);
        DiskResource *col_mesh_ = disk_resource_get_or_make(col_mesh_name);
        CollisionMesh *col_mesh = dynamic_cast<CollisionMesh*>(col_mesh_);
        Quaternion q = check_quat(L, 2);
        Vector3 start = check_v3(L, 3);
        Vector3 ray = check_v3(L, 4);
        bool nearest_only = check_bool(L, 5);
        unsigned long flags = check_t<unsigned long>(L, 6);
        if (lua_type(L, 7) != LUA_TFUNCTION)
                my_lua_error(L, "Parameter 5 should be a function.");

        LuaSweepCallback lcb(nearest_only, flags);
        init_cast_blacklist(L, base_line, lcb);

        physics_sweep_col_mesh(start, q, start + ray, q, lcb, col_mesh);

        push_cfunction(L, my_lua_error_handler);
        int error_handler = lua_gettop(L);

        lcb.pushResults(L, 7, error_handler);
        return 0;
TRY_END
}
boost::shared_ptr< Base<EncodingT> >
ConnectionInterpreter<EncodingT>::selectForUpdate(boost::shared_ptr< Base<EncodingT> > const& columns,
                                                  boost::shared_ptr< Base<EncodingT> > const& tables,
                                                  boost::shared_ptr< Base<EncodingT> > const& filter,
                                                  boost::shared_ptr< Base<EncodingT> > const& nowait)
{
    boost::shared_ptr< Base<EncodingT> > res(new StatementInterpreter<EncodingT>());
    clearError();
    try
    {
        bool nativeNoWait;
        std::vector<typename EncodingT::string_t> nativeColumns, nativeTables;
        typename EncodingT::string_t nativeFilter;
        if (check_string<EncodingT>(filter, nativeFilter) &&
            check_string_array(columns, nativeColumns) &&
            check_string_array(tables, nativeTables) &&
            check_bool(nowait, nativeNoWait))
        {
            res.reset(new StatementInterpreter<EncodingT>(m_object->selectForUpdate(nativeColumns, nativeTables, nativeFilter, nativeNoWait)));
        }
    }
    catch (std::exception& e)
    {
        setError(e);
    }
    return res;
}
void CppEnumInterpreterAccess<EncodingT>::fillOneCppEnumConstant(boost::shared_ptr< Base<EncodingT> >& refCppEnum,
				const boost::shared_ptr< Base<EncodingT> >& identifier,
				const boost::shared_ptr< Base<EncodingT> >& nowait)
{
	clearError();
	try
	{
		bool nativeNoWait;
		boost::shared_ptr< _CppEnum<EncodingT> > nativeRefCppEnum;
		int nativeIdentifier;
		if (check_cppEnum(refCppEnum, nativeRefCppEnum) && 
			check_numeric(identifier, nativeIdentifier) &&
			check_bool(nowait, nativeNoWait))
		{
			m_object->fillOneCppEnumConstant(nativeRefCppEnum,
				nativeIdentifier,
				nativeNoWait);
			reset_cppEnum(refCppEnum, nativeRefCppEnum);
		}
	}
	catch (std::exception& e)
	{
		setError(e);
	}
}
static int rbody_scatter (lua_State *L)
{
TRY_START
        check_args(L, 11);
        GET_UD_MACRO(RigidBody, self, 1, RBODY_TAG);
        std::string mat = check_path(L, 2);
        SimpleTransform world_trans(self.getPosition(), self.getOrientation());
        float density       = check_float(L, 3);
        float min_slope     = check_float(L, 4);
        float max_slope     = check_float(L, 5);
        float min_elevation = check_float(L, 6);
        float max_elevation = check_float(L, 7);
        bool no_z           = check_bool(L, 8);
        bool rotate         = check_bool(L, 9);
        bool align_slope    = check_bool(L, 10);
        unsigned seed       = check_t<unsigned>(L, 11);

        std::vector<SimpleTransform> r;
        self.colMesh->scatter(phys_mats.getMaterial(mat)->id,
                              world_trans, density, min_slope, max_slope, min_elevation,
                              max_elevation, no_z, rotate, align_slope, seed,
                              r);

        lua_newtable(L);
        for (size_t j=0 ; j<r.size(); ++j) {
                const Quaternion &q = r[j].quat;
                const Vector3 &p = r[j].pos;
                lua_pushnumber(L, p.x);
                lua_rawseti(L, -2, 7*j+1);
                lua_pushnumber(L, p.y);
                lua_rawseti(L, -2, 7*j+1+1);
                lua_pushnumber(L, p.z);
                lua_rawseti(L, -2, 7*j+2+1);
                lua_pushnumber(L, q.w);
                lua_rawseti(L, -2, 7*j+3+1);
                lua_pushnumber(L, q.x);
                lua_rawseti(L, -2, 7*j+4+1);
                lua_pushnumber(L, q.y);
                lua_rawseti(L, -2, 7*j+5+1);
                lua_pushnumber(L, q.z);
                lua_rawseti(L, -2, 7*j+6+1);
        }

        return 1;
TRY_END
}
Exemple #8
0
static bool
check_enable_state(char *enum_name, GLenum enum_value, bool expected)
{
	GLboolean b;

	bool pass = true;
	printf("Trying glIsEnabled(%s): ", enum_name);
	b = glIsEnabled(enum_value);
	pass = piglit_check_gl_error(GL_NO_ERROR) && check_bool(b, expected)
		&& print_ok() && pass;

	printf("Trying glGetBooleanv(%s): ", enum_name);
	glGetBooleanv(enum_value, &b);
	pass = piglit_check_gl_error(GL_NO_ERROR) && check_bool(b, expected)
		&& print_ok() && pass;

	return pass;
}
static int rbody_set_part_enabled (lua_State *L)
{
TRY_START
        check_args(L, 3);
        GET_UD_MACRO(RigidBody, self, 1, RBODY_TAG);
        int i = (int)check_int(L, 2, 0, self.getNumElements()-1);
        bool b = check_bool(L, 3);
        self.setElementEnabled(i, b);
        return 0;
TRY_END
}
static int rbody_local_vel (lua_State *L)
{
TRY_START
        check_args(L, 3);
        GET_UD_MACRO(RigidBody, self, 1, RBODY_TAG);
        Vector3 pos = check_v3(L, 2);
        bool world_space = check_bool(L, 3);
        Vector3 local_pos = pos;
        if (world_space) {
                local_pos -= self.getPosition();
        }
        Vector3 local_vel = self.getLocalVelocity(local_pos);
        push_v3(L, local_vel);
        return 1;
TRY_END
}
void CppEnumInterpreterAccess<EncodingT>::fillAllCppEnumConstants(boost::shared_ptr< Base<EncodingT> >& cppEnum, const boost::shared_ptr< Base<EncodingT> >& nowait)
{
	clearError();
	try
	{
		bool nativeNoWait;
		boost::shared_ptr< _CppEnum<EncodingT> > nativeCppEnum;
		if (check_cppEnum(cppEnum, nativeCppEnum) && 
			check_bool(nowait, nativeNoWait))
		{
			m_object->fillAllCppEnumConstants(nativeCppEnum, nativeNoWait);
			reset_cppEnum(cppEnum, nativeCppEnum);
		}
	}
	catch (std::exception& e)
	{
		setError(e);
	}
}
static int global_physics_cast_ray (lua_State *L)
{
TRY_START
        int base_line = 4;
        check_args_min(L, base_line);

        Vector3 start = check_v3(L, 1);
        Vector3 ray = check_v3(L, 2);
        bool nearest_only = check_bool(L, 3);
        unsigned long flags = check_t<unsigned long>(L, 4);

        LuaSweepCallback lcb(nearest_only, flags);
        init_cast_blacklist(L, base_line, lcb);

        physics_ray(start, start+ray, lcb);

        return lcb.pushResults(L);

TRY_END
}
boost::shared_ptr< Base<EncodingT> > CppEnumInterpreterAccess<EncodingT>::selectManyCppEnums(const boost::shared_ptr< Base<EncodingT> >& filter, const boost::shared_ptr< Base<EncodingT> >& nowait)
{
	boost::shared_ptr< Base<EncodingT> > res(new Array<EncodingT>());
	clearError();
	try
	{
		typename EncodingT::string_t nativeFilter;
		bool nativeNoWait;
		if (check_string<EncodingT>(filter, nativeFilter) &&
			check_bool(nowait, nativeNoWait))
		{
			res = convert_array(m_object->selectManyCppEnums(nativeFilter, nativeNoWait));
		}
	}
	catch (std::exception& e)
	{
		setError(e);
	}
	return res;
}
boost::shared_ptr< Base<EncodingT> > CppEnumInterpreterAccess<EncodingT>::selectOneCppEnum(boost::shared_ptr< Base<EncodingT> > const& identifier,
				const boost::shared_ptr< Base<EncodingT> >& nowait)
{
	boost::shared_ptr< Base<EncodingT> > res(new CppEnumInterpreter<EncodingT>());
	clearError();
	try
	{
		bool nativeNoWait;
		int nativeIdentifier;
		if (check_numeric(identifier, nativeIdentifier) &&
			check_bool(nowait, nativeNoWait))
		{
			res.reset(new CppEnumInterpreter<EncodingT>(m_object->selectOneCppEnum(nativeIdentifier,
				nativeNoWait)));
		}
	}
	catch (std::exception& e)
	{
		setError(e);
	}
	return res;
}
static int global_physics_sweep_cylinder (lua_State *L)
{
TRY_START
        int base_line = 7;
        check_args_min(L, base_line);

        float radius = check_float(L, 1);
        float height = check_float(L, 2);
        Quaternion q = check_quat(L, 3);
        Vector3 start = check_v3(L, 4);
        Vector3 ray = check_v3(L, 5);
        bool nearest_only = check_bool(L, 6);
        unsigned long flags = check_t<unsigned long>(L, 7);

        LuaSweepCallback lcb(nearest_only, flags);
        init_cast_blacklist(L, base_line, lcb);

        physics_sweep_cylinder(start, q, start+ray, lcb, radius, height);

        return lcb.pushResults(L);

TRY_END
}
Exemple #16
0
/*---------------------------------------------------------------------------*
 *                              run tests                                    *
 *---------------------------------------------------------------------------*/
int
main()
{
    int res;

    /* foreach_slice() test */
    check_int("foreach_slice()", call_foreach_slice(), (1 + 2 + 3) + 2);

    /* foreach_slice_params() tests */
    check_int("foreach_slice_params(1, 2)",
              call_foreach_slice_params(1, 2),
              11 + 0);

    check_int("foreach_slice_params(0, 6)",
              call_foreach_slice_params(0, 6),
              (10 + 11 + 12 + 13 + 14 + 15) +
              (0 + 1 + 2 + 3 + 4 + 5));

    check_int("foreach_slice_params(3, 5)",
              call_foreach_slice_params(3, 5),
              (13 + 14) + (0 + 1));

    /* foreach_shorthand_slice() tests */
    check_int("foreach_shorthand_slice(0, -1)",
              call_foreach_shorthand_slice(0, -1),
              -1 * 4 * 6 * 8 * 10 * 12 * 14 * 16);

    check_int("foreach_shorthand_slice(4, 3)",
              call_foreach_shorthand_slice(4, 3),
              2 * 4 * 6 * 8 * 3 * 12 * 14 * 16);

    /* foreach_value_auto_type() tests */
    check_bool("foreach_value_auto_type(13)",
               call_foreach_value_auto_type(13), true);

    check_bool("foreach_value_auto_type(14)",
               call_foreach_value_auto_type(14), true);

    check_bool("foreach_value_auto_type(15)",
               call_foreach_value_auto_type(15), false);

    check_bool("foreach_value_auto_type(16)",
               call_foreach_value_auto_type(16), false);

    /* 
     * foreach_index_auto_type() and
     * run_foreach_index_auto_type() tests
     */
    check_int("run_foreach_index_auto_type(97)",
              call_run_foreach_index_auto_type(97),
              0);

    check_int("run_foreach_index_auto_type(211)",
              call_run_foreach_index_auto_type(211),
              2);

    check_int("run_foreach_index_auto_type(36)",
              call_run_foreach_index_auto_type(36),
              5);

    check_int("run_foreach_index_auto_type(-15)",
              call_run_foreach_index_auto_type(-15),
              -1);

    check_int("run_foreach_index_auto_type(4)",
              call_run_foreach_index_auto_type(4),
              -1);

    /* foreach_body_loc_vars() tests */
    check_int("foreach_body_loc_vars([0 0 0 0])",
              call_foreach_body_loc_vars(0),
              19341 + 19341 + 19341 + 19341);

    check_int("foreach_body_loc_vars([2 4 5 3])",
              call_foreach_body_loc_vars(1),
              48352 + 49081 + 23112 + 28360);

    check_int("foreach_body_loc_vars([15 14 13 12])",
              call_foreach_body_loc_vars(2),
              41092 + 56732 + 38528 + 37889);

    check_int("foreach_body_loc_vars([0 1 18 3])",
              call_foreach_body_loc_vars(3),
              -1);

    check_int("call_foreach_body_loc_vars(4)",
              call_foreach_body_loc_vars(4),
              -2);

    /* foreach_bool_arry() tests */
    check_int("foreach_bool_arry([false, false, false, false, false, false])",
              call_foreach_bool_arry(0), 0);

    check_int("foreach_bool_arry([true, true, true, true, true, true])",
              call_foreach_bool_arry(1),
              11 + 12 + 13 + 14 + 15 + 16);

    check_int("foreach_bool_arry([false, false, true, false, false, true])",
              call_foreach_bool_arry(2),
              13 + 16);

    check_int("foreach_bool_arry([true, false, false, true, false, true])",
              call_foreach_bool_arry(3),
              11 + 14 + 16);

    check_int("foreach_bool_arry([true, false, true, false, false, false])",
              call_foreach_bool_arry(4),
              11 + 13);

    check_int("call_foreach_bool_arry(5)", call_foreach_bool_arry(5), -1);

    /* foreach_break() tests */
    check_uint("foreach_break(0)", foreach_break(0), 4);
    check_uint("foreach_break(8)", foreach_break(8), 3);
    check_uint("foreach_break(1)", foreach_break(1), 2);
    check_uint("foreach_break(7)", foreach_break(7), 1);
    check_uint("foreach_break(2)", foreach_break(2), 0);
    check_uint("foreach_break(-1)", foreach_break(-1), 4);

    check_exit();
}
Exemple #17
0
void
test2()
{
	unsigned char *s;
	unsigned char *buf;
	int i, j;
	size_t n;
	wchar_t c, d;
	mbstate_t state;

	s = malloc(256);
	if (!s) {
		bad++;
		return;
	}
	buf = malloc(MB_CUR_MAX);
	if (!buf) {
		bad++;
		free(s);
		return;
	}
	for (i = 0; i < 256; i++)
		s[i] = i+1;

	j = 0;
	mbrtowc(NULL, NULL, 1, &state);
	printf(" %02x: ", 0);

	while ((n = mbrtowc(&c, s+j, 256-j, &state)) == 1) {
		printf(" %02x: ", s[j]);
		check_bool(isalnum(s[j]), iswalnum(c), '1');
		check_bool(isalpha(s[j]), iswalpha(c), '2');
		check_bool(isblank(s[j]), iswblank(c), '3');
		check_bool(iscntrl(s[j]), iswcntrl(c), '4');
		check_bool(isdigit(s[j]), iswdigit(c), '5');
		check_bool(isgraph(s[j]), iswgraph(c), '6');
		check_bool(islower(s[j]), iswlower(c), '6');
		check_bool(isprint(s[j]), iswprint(c), '7');
		check_bool(ispunct(s[j]), iswpunct(c), '8');
		check_bool(isspace(s[j]), iswspace(c), '9');
		check_bool(isupper(s[j]), iswupper(c), 'a');
		check_bool(isxdigit(s[j]), iswxdigit(c), 'b');
		d = towlower(c);
		if (wctomb(buf, d) == 1) {	
			check_value(tolower(s[j]), buf[0], 'c');
		} else {
			bad++;
		}
		d = towupper(c);
		if (wctomb(buf, d) == 1) {	
			check_value(toupper(s[j]), buf[0], 'c');
		} else {
			bad++;
		}
		if (s[j] % 8 == 7)
			printf("\n");
		j++;
	}
	if (n != 0 || j != 255) {
		bad++;
	}
	free(s);
	free(buf);
}
Exemple #18
0
int main() {
	{
		void* table[2];
		ArrayList buf = new_array_list(table);

		check_int(2, buf.capacity);
		check_int((size_t)0, buf.size(&buf));
		check_int(table, buf.pBuf);

		char str1[] = "hello";
		buf.add(&buf, str1);

		check_int(2, buf.capacity);
		check_int((size_t)1, buf.size(&buf));
		check_int(table, buf.pBuf);

		char str2[] = "world";
		buf.add(&buf, str2);

		check_int(2, buf.capacity);
		check_int((size_t)2, buf.size(&buf));
		check_int(table, buf.pBuf);

		//check_int(str1, buf.remove(&buf, str1));
		check_str(str1, (char*)buf.remove(&buf, str1));

		check_int(2, buf.capacity);
		check_int((size_t)1, buf.size(&buf));
		check_str(str2, (char*)buf.get(&buf, 0));

		check_int(NULL, buf.remove(&buf, str1));

		check_int(2, buf.capacity);
		check_int((size_t)1, buf.size(&buf));
		check_str(str2, (char*)buf.get(&buf, 0));

		//check_int(str2, buf.remove(&buf, str2));
		check_str(str2, (char*)buf.remove(&buf, str2));

		check_int(2, buf.capacity);
		check_int((size_t)0, buf.size(&buf));

		check_int(NULL, buf.remove(&buf, str2));
	}

	{
		char tmpFileName[L_tmpnam + 1];
		tmpnam(tmpFileName);

		FILE* fp = fopen(tmpFileName, "wb");
		check_bool(true, write_int(fp, 1231));
		check_bool(true, write_int(fp, 1));
		check_bool(true, write_int(fp, 441));
		check_int(0, fclose(fp));

		int_sorter(tmpFileName);

		fp = fopen(tmpFileName, "rb");
		check_int(1, read_int(fp));
		check_int(441, read_int(fp));
		check_int(1231, read_int(fp));
		check_int(0, fclose(fp));
	}

	{
		char tmpFileName[L_tmpnam + 1];
		tmpnam(tmpFileName);

		FILE* fp = fopen(tmpFileName, "w");
		check_int(0, fclose(fp));

		int_sorter(tmpFileName);
	}

	{
		int_sorter("--------------xxxxxxxxxxxxxxxxxxxxx");
	}
}
Exemple #19
0
static const char *test_v7_exec(void) {
  struct v7_val *v;
  struct v7 *v7 = v7_create();

  ASSERT((v = v7_exec(v7, "")) == NULL);
  ASSERT((v = v7_exec(v7, "-2;")) != NULL);
  ASSERT(check_num(v7, v, -2.0));
  ASSERT((v = v7_exec(v7, "3 + 4")) != NULL);
  ASSERT(check_num(v7, v, 7.0));
  ASSERT((v = v7_exec(v7, "123.456")) != NULL);
  ASSERT(check_num(v7, v, 123.456));
  ASSERT((v = v7_exec(v7, "NaN")) != NULL);
  ASSERT(check_num(v7, v, NAN));

  // TODO: fix infinity handling under MSVC6
#ifndef _WIN32
  ASSERT((v = v7_exec(v7, "Infinity")) != NULL);
  ASSERT(check_num(v7, v, INFINITY));
  ASSERT((v = v7_exec(v7, "-Infinity")) != NULL);
  ASSERT(check_num(v7, v, -INFINITY));
#endif

  ASSERT((v = v7_exec(v7, "2()")) == NULL);
  ASSERT((v = v7_exec(v7, " 15 +	2 \r\n * 2  / 1 - 3 * 4 ; ")) != NULL);

  ASSERT((v = v7_exec(v7, "( (5  ) );")) != NULL);
  ASSERT(check_num(v7, v, 5.0));

  ASSERT((v = v7_exec(v7, "(2 + (12 / 4));")) != NULL);
  ASSERT(check_num(v7, v, 5.0));

  ASSERT((v = v7_exec(v7, "1;2 7")) != NULL);
  ASSERT(check_num(v7, v, 7.0));

  v = v7_exec(v7, "a=undefined; a + 5");
  ASSERT(check_num(v7, v, NAN));

  /* ReferenceErrors are not thrown yet, treat as undefined */
  v = v7_exec(v7, "a + 5");
  ASSERT(check_num(v7, v, NAN));

  ASSERT((v = v7_exec(v7, "print();")) != NULL);
  ASSERT((v = v7_exec(v7, "print(this);")) != NULL);

  ASSERT((v = v7_exec(v7, "a = 7;")) != NULL);
  ASSERT(check_num(v7, v, 7.0));
  ASSERT((v = v7_exec(v7, "print(this);")) != NULL);

  ASSERT((v = v7_exec(v7, "b = a + 3;")) != NULL);
  ASSERT(check_num(v7, v, 10.0));
  ASSERT((v = v7_exec(v7, "c = b * (a + 3) / 2;")) != NULL);
  ASSERT(check_num(v7, v, 50.0));
  ASSERT((v = v7_exec(v7, "print(this);")) != NULL);

  ASSERT((v = v7_exec(v7, "var x = 1.23; x")) != NULL);
  ASSERT(check_num(v7, v, 1.23));

  ASSERT((v = v7_exec(v7, "b = 7; a = b *= 4;")) != NULL);

  ASSERT((v = v7_exec(v7, "var x = 12 + 2 - a + b+ 3 / 4 * a; x;")) != NULL);
  ASSERT((v = v7_exec(v7, "x + 1")) != NULL);
  ASSERT((v = v7_exec(v7, "b + 2; x + 3 + 1 z = x -2;")) != NULL);
  ASSERT((v = v7_exec(v7, "x; var y, z;")) != NULL);
  ASSERT((v = v7_exec(v7, "1 2 3")) != NULL);

  ASSERT((v = v7_exec(v7, "var k = true; k ")) != NULL);
  ASSERT(check_bool(v7, v, 1));

  ASSERT((v = v7_exec(v7, "var blah = 'kuku'; blah")) != NULL);
  ASSERT(check_str(v7, v, "kuku"));

  // Test that k.y does exist
  ASSERT((v = v7_exec(v7, "k = { y: 17 };")) != NULL);
  ASSERT((v = v7_exec(v7, "k.y")) != NULL);
  ASSERT(check_num(v7, v, 17.0));
  v7_exec(v7, "print(this);");

  // Delete k.y and make sure it's gone
  ASSERT((v = v7_exec(v7, "delete k.y;")) != NULL);
  ASSERT((v = v7_exec(v7, "k.y;")) != NULL);
  ASSERT(v7_type(v) == V7_TYPE_UNDEF);
  ASSERT((v = v7_exec(v7, "delete b; b;")) != NULL);
  ASSERT(v7_type(v) == V7_TYPE_UNDEF);

  ASSERT((v = v7_exec(v7, "k = { key1: {x:3}, key2: ':-)', y: 5 };")) != NULL);
  ASSERT(v7_type(v) == V7_TYPE_OBJ);

  ASSERT((v = v7_exec(v7, "k.x = 47;")) != NULL);
  ASSERT((v = v7_exec(v7, "k.qwe = { foo: 5 };")) != NULL);
  ASSERT((v = v7_exec(v7, "k.qwe.foo = 15;")) != NULL);

  ASSERT((v = v7_exec(v7, "k.key1.x + 4")) != NULL);
  ASSERT(check_num(v7, v, 7.0));

  ASSERT((v = v7_exec(v7, "k.foo")) != NULL);
  ASSERT(v7_type(v) == V7_TYPE_UNDEF);

  ASSERT((v = v7_exec(v7, "var z = 'key1'; k[z]['x']")) != NULL);
  ASSERT(check_num(v7, v, 3.0));

  ASSERT((v = v7_exec(v7, "var stk = 1; stk")) != NULL);
  ASSERT(check_num(v7, v, 1.0));

  ASSERT((v = v7_exec(v7, "var f1 = function(x, y) { }; typeof f1 ")) != NULL);
  ASSERT(check_str(v7, v, "function"));

  ASSERT((v = v7_exec(v7, "var f1 = function(x, y) { return x * y }")) != NULL);
  //ASSERT(v7_is_class(v7_top(v7)[-1], V7_CLASS_FUNCTION));
  ASSERT((v = v7_exec(v7, "f1(2, 3)")) != NULL);
  ASSERT(check_num(v7, v, 6.0));
  ASSERT((v = v7_exec(v7, "f1(12, 4) + 1;")) != NULL);
  ASSERT(check_num(v7, v, 49.0));
  ASSERT((v = v7_exec(v7, "f1(12, 4) * 2;")) != NULL);
  ASSERT(check_num(v7, v, 96.0));

  ASSERT((v = v7_exec(v7, "f = function(x,y,z) {print(this);};")) != NULL);
  ASSERT(v7_type(v) == V7_TYPE_OBJ);
  //ASSERT(v7_is_class(v7->stack[0], V7_CLASS_FUNCTION));
  ASSERT((v = v7_exec(v7, "f();")) != NULL);
  ASSERT((v = v7_exec(v7, "f({});")) != NULL);
  ASSERT((v = v7_exec(v7, "f(1, 2);")) != NULL);
  ASSERT((v = v7_exec(v7, "f(123, {});")) != NULL);

  ASSERT((v = v7_exec(v7, "if (0) f1 = 2; ")) == NULL);
  ASSERT((v = v7_exec(v7, "if (5) { f1 = 3; f2 = function(){}; } ")) != NULL);

  ASSERT((v = v7_exec(v7, "0 ? 1 : 2;")) != NULL);
  ASSERT(check_num(v7, v, 2.0));

  ASSERT((v = v7_exec(v7, "k = true ? 1 : 2;")) != NULL);
  ASSERT(check_num(v7, v, 1.0));

  ASSERT((v = v7_exec(v7, "var f = function(){var x=12; return x + 1;};")) != NULL);

  ASSERT((v = v7_exec(v7, "k = f(1,2,3);")) != NULL);
  ASSERT(check_num(v7, v, 13.0));

  ASSERT((v = v7_exec(v7, "(function() { return f() + 7; })()")) != NULL);
  ASSERT(check_num(v7, v, 20.0));

  ASSERT((v = v7_exec(v7, "var a = 1; if (a == 1) { a = 2; }; a;")) != NULL);
  ASSERT(check_num(v7, v, 2.0));

  ASSERT((v = v7_exec(v7, "var a = 'foo'; a == 'foo';")) != NULL);
  ASSERT(check_bool(v7, v, 1));

  ASSERT((v = v7_exec(v7, "a = { x: function(p) { print(this); } }")) != NULL);
  ASSERT((v = v7_exec(v7, "a.x(2);")) != NULL);

  ASSERT((v = v7_exec(v7, "(74).toString()")) != NULL);
  ASSERT(check_str(v7, v, "74"));
  ASSERT((v = v7_exec(v7, "'hello'.length")) != NULL);
  ASSERT(check_num(v7, v, 5.0));

  ASSERT((v = v7_exec(v7, "k = { x : function() { if (1) 2; } }")) != NULL);

  ASSERT((v = v7_exec(v7, "'foo' + 'bar'")) != NULL);
  ASSERT(check_str(v7, v, "foobar"));

  ASSERT((v = v7_exec(v7, "var x = [1, 'foo', true, 7];")) != NULL);
  ASSERT((v = v7_exec(v7, "x.length")) != NULL);
  ASSERT(check_num(v7, v, 4.0));
  ASSERT((v = v7_exec(v7, "x[1]")) != NULL);
  ASSERT(check_str(v7, v, "foo"));

  ASSERT((v = v7_exec(v7, "var f1 = function() { 1; };")) != NULL);
  ASSERT((v = v7_exec(v7, "var f2 = function(x) { if (x) return x; };")) != NULL);
  ASSERT((v = v7_exec(v7, "f1()")) != NULL);
  ASSERT(v7_type(v) == V7_TYPE_UNDEF);
  ASSERT((v = v7_exec(v7, "f2(false)")) != NULL);
  ASSERT(v7_type(v) == V7_TYPE_UNDEF);
  ASSERT((v = v7_exec(v7, "f2(17)")) != NULL);
  ASSERT(check_num(v7, v, 17.0));
  ASSERT((v = v7_exec(v7, "f2(true)")) != NULL);
  ASSERT(check_bool(v7, v, 1.0));

  ASSERT((v = v7_exec(v7, "1 <= 2 ? 7 : 8")) != NULL);
  ASSERT(check_num(v7, v, 7.0));

  ASSERT((v = v7_exec(v7, "function a (t) { return t * t }; ")) != NULL);
  ASSERT((v = v7_exec(v7, "a(2)")) != NULL);
  ASSERT(check_num(v7, v, 4.0));
  ASSERT((v = v7_exec(v7, "a(0)")) != NULL);
  ASSERT(check_num(v7, v, 0.0));

  ASSERT((v = v7_exec(v7, "function fac(x) { "
         "return x <= 1 ? 1 : x * fac(x - 1); }")) != NULL);
  ASSERT((v = v7_exec(v7, "fac(1)")) != NULL);
  ASSERT(check_num(v7, v, 1.0));
  ASSERT((v = v7_exec(v7, "fac(5)")) != NULL);
  ASSERT(check_num(v7, v, 120.0));
  ASSERT((v = v7_exec(v7, "fac(20)")) != NULL);

  ASSERT((v = v7_exec(v7, "function qq(a,b) { return a + b; }")) != NULL);
  ASSERT((v = v7_exec(v7, "qq(1,2)")) != NULL);
  ASSERT(check_num(v7, v, 3.0));

  ASSERT((v = v7_exec(v7, "1 < 2 == 2 < 3")) != NULL);
  ASSERT(check_bool(v7, v, 1.0));

  ASSERT((v = v7_exec(v7, "5 % 3 * 3")) != NULL);
  ASSERT(check_num(v7, v, 6.0));
  ASSERT((v = v7_exec(v7, "76 & 13")) != NULL);
  ASSERT(check_num(v7, v, 12.0));
  ASSERT((v = v7_exec(v7, "34325 ^ 190992 & 74832")) != NULL);
  ASSERT(check_num(v7, v, 42501.0));

  ASSERT((v = v7_exec(v7, "a = 12;")) != NULL);
  ASSERT((v = v7_exec(v7, "a += 44; a;")) != NULL);
  ASSERT(check_num(v7, v, 56.0));
  ASSERT((v = v7_exec(v7, "a -= a / 2; a;")) != NULL);
  ASSERT(check_num(v7, v, 28.0));
  ASSERT((v = v7_exec(v7, "a *= 0.5; a;")) != NULL);
  ASSERT(check_num(v7, v, 14.0));
#ifndef _WIN32
  ASSERT((v = v7_exec(v7, "a /= 0; a;")) != NULL);
  ASSERT(check_num(v7, v, INFINITY));
#endif

  ASSERT((v = v7_exec(v7, "!5")) != NULL);
  ASSERT(check_bool(v7, v, 0.0));
  ASSERT((v = v7_exec(v7, "!''")) != NULL);
  ASSERT(check_bool(v7, v, 1.0));
  ASSERT((v = v7_exec(v7, "1 != 2")) != NULL);
  ASSERT(check_bool(v7, v, 1.0));
  ASSERT((v = v7_exec(v7, "7 >= 0")) != NULL);
  ASSERT(check_bool(v7, v, 1.0));

  ASSERT((v = v7_exec(v7, "if (false) 3; ")) == NULL);
  ASSERT((v = v7_exec(v7, "if (true) { if (1) {2;} 5; } ")) != NULL);
  ASSERT(check_num(v7, v, 5.0));
  ASSERT((v = v7_exec(v7, "if ('') 3; ")) == NULL);
  ASSERT((v = v7_exec(v7, "if ('0') 9; ")) != NULL);
  ASSERT(check_num(v7, v, 9.0));
  ASSERT((v = v7_exec(v7, "if (false) 1; else 3;")) != NULL);
  ASSERT(check_num(v7, v, 3.0));
  ASSERT((v = v7_exec(v7, "if (false) 1; else if (0) { 3 } else { 2 }")) != NULL);
  ASSERT(check_num(v7, v, 2.0));
  ASSERT((v = v7_exec(v7, "if (false) 1; else if (1) { 3 } else { 2 }")) != NULL);
  ASSERT(check_num(v7, v, 3.0));

  ASSERT((v = v7_exec(v7, "a = 32; 2 + a++;")) != NULL);
  ASSERT(check_num(v7, v, 34.0));

  ASSERT((v = v7_exec(v7, "print()")) != NULL);
  ASSERT((v = v7_exec(v7, "print(['hi', 1, true, null, /\\s+/])")) != NULL);

  ASSERT((v = v7_exec(v7, "a = {};")) != NULL);
  ASSERT((v = v7_exec(v7, "a.foo = function(x) { var y = "
                 "x.substr(1).split() }")) != NULL);

  ASSERT((v = v7_exec(v7, "typeof 2")) != NULL);
  ASSERT(check_str(v7, v, "number"));

  ASSERT((v = v7_exec(v7, "a = { b: { k: 44 } };")) != NULL);
  STOP = 1;
  ASSERT((v = v7_exec(v7, "a.b['x'] = 79;")) != NULL);
  ASSERT((v = v7_exec(v7, "a.b.x")) != NULL);
  ASSERT(check_num(v7, v, 79.0));

  v7_destroy(&v7);
  return NULL;
}
int main (int argc, char* argv [])
{
   #define check(ol, al) if (argv [i][ol] || \
                             badarg(argc - i - 1,argv + i + 1, al)) \
                            goto badopt
                            
   #define check_bool(olen, var) switch (argv [i][olen]) { \
                             case '\0': var = !var; break; \
                             case 'y': case 'Y': case 't': case 'T': \
                             case '+': case '1': var = 1; break; \
                             case 'n': case 'N': case 'f': case 'F': \
                             case '-': case '0': var = 0; break; \
                             default: goto badopt; \
                          }   

   int loadflags = IO_CHECK | IO_SCENE | IO_TREE | IO_BOUNDS, rval, i, j, n;
   char **portLp = photonPortList, **sensLp = photonSensorList,
        **amblp = NULL;
   struct stat pmstat;

   /* Global program name */
   progname = fixargv0(argv [0]);
   /* Initialize object types */
   initotypes();
   
   /* Parse options */
   for (i = 1; i < argc; i++) {
      /* Eggs-pand arguments */
      while ((rval = expandarg(&argc, &argv, i)))
         if (rval < 0) {
            sprintf(errmsg, "cannot eggs-pand '%s'", argv [i]);
            error(SYSTEM, errmsg);
         }
         
      if (argv[i] == NULL) 
         break;
         
      if (!strcmp(argv [i], "-version")) {
         puts(VersionID);
         quit(0);
      }
      
      if (!strcmp(argv [i], "-defaults") || !strcmp(argv [i], "-help")) {
         printdefaults();
         quit(0);
      }
      
      /* Get octree */
      if (i == argc - 1) {
         octname = argv [i];
         break;
      }
            
      switch (argv [i][1]) {
         case 'a': /* Ambient */
            switch (argv [i][2]) {
               case 'i': /* Ambient include */
               case 'I':
                  check(3, "s");
                  if (ambincl != 1) {
                     ambincl = 1;
                     amblp = amblist;
                  }
                  if (argv [i][2] == 'I') {	
                     /* Add modifiers from file */
                     rval = wordfile(amblp, AMBLLEN - (amblp - amblist),
                                     getpath(argv [++i], 
                                     getrlibpath(), R_OK));
                     if (rval < 0) {
                        sprintf(errmsg, 
                                "cannot open ambient include file \"%s\"",
                                argv [i]);
                        error(SYSTEM, errmsg);
                     }
                     amblp += rval;
                  } 
                  else {
                     /* Add modifier from next arg */
                     *amblp++ = savqstr(argv [++i]);
                     *amblp = NULL;
                  }
                  break;

               case 'e': /* Ambient exclude */
               case 'E':
                  check(3, "s");
                  if (ambincl != 0) {
                     ambincl = 0;
                     amblp = amblist;
                  }
                  if (argv [i][2] == 'E') { 
                     /* Add modifiers from file */
                     rval = wordfile(amblp, AMBLLEN - (amblp - amblist),
                                     getpath(argv [++i], 
                                     getrlibpath(), R_OK));
                     if (rval < 0) {
                        sprintf(errmsg,
                                "cannot open ambient exclude file \"%s\"", 
                                argv [i]);
                        error(SYSTEM, errmsg);
                     }
                     amblp += rval;
                  } 
                  else {
                     /* Add modifier from next arg */ 
                     *amblp++ = savqstr(argv [++i]);
                     *amblp = NULL;
                  }
                  break;
            
               case 'p': /* Pmap-specific */
                  switch (argv [i][3]) {			
                     case 'g': /* Global photon map */
                        check(4, "ss");
                        globalPmapParams.fileName = argv [++i];
                        globalPmapParams.distribTarget = 
                           parseMultiplier(argv [++i]);
                        if (!globalPmapParams.distribTarget) 
                           goto badopt;                         
                        globalPmapParams.minGather = 
                           globalPmapParams.maxGather = 0;
                        break;
            
                     case 'p': /* Precomputed global photon map */
                        check(4, "ssi");
                        preCompPmapParams.fileName = argv [++i];
                        preCompPmapParams.distribTarget = 
                           parseMultiplier(argv [++i]);
                        if (!preCompPmapParams.distribTarget) 
                           goto badopt;
                        preCompPmapParams.minGather = 
                           preCompPmapParams.maxGather = atoi(argv [++i]);
                        if (!preCompPmapParams.maxGather) 
                           goto badopt;
                        break;
            
                     case 'c': /* Caustic photon map */
                        check(4, "ss");
                        causticPmapParams.fileName = argv [++i];
                        causticPmapParams.distribTarget = 
                           parseMultiplier(argv [++i]);
                        if (!causticPmapParams.distribTarget) 
                           goto badopt;
                        break;
                  
                     case 'v': /* Volume photon map */
                        check(4, "ss");
                        volumePmapParams.fileName = argv [++i];
                        volumePmapParams.distribTarget = 
                           parseMultiplier(argv [++i]);
                        if (!volumePmapParams.distribTarget) 
                           goto badopt;                      
                        break;
                     
                     case 'd': /* Direct photon map */
                        check(4, "ss");
                        directPmapParams.fileName = argv [++i];
                        directPmapParams.distribTarget = 
                           parseMultiplier(argv [++i]);
                        if (!directPmapParams.distribTarget) 
                           goto badopt;
                        break;
                     
                     case 'C': /* Contribution photon map */
                        check(4, "ss");
                        contribPmapParams.fileName = argv [++i];
                        contribPmapParams.distribTarget =
                           parseMultiplier(argv [++i]);
                        if (!contribPmapParams.distribTarget)
                           goto badopt;
                        break;

                     case 'D': /* Predistribution factor */
                        check(4, "f");
                        preDistrib = atof(argv [++i]);
                        if (preDistrib <= 0)
                           error(USER, "predistrib factor must be > 0");
                        break;

                     case 'M': /* Max predistribution passes */
                        check(4, "i");
                        maxPreDistrib = atoi(argv [++i]);
                        if (maxPreDistrib <= 0)
                           error(USER, "max predistrib passes must be > 0");
                        break;

#if 1
                     /* Kept for backwards compat, to be phased out by -lr */
                     case 'm': /* Max photon bounces */
                        check(4, "i");
                        photonMaxBounce = atol(argv [++i]);
                        if (photonMaxBounce <= 0) 
                           error(USER, "max photon bounces must be > 0");
                        break;
#endif

#ifdef PMAP_EKSPERTZ                     
                     case 'i': /* Add region of interest */
                        check(4, "ffffff");                        
                        n = pmapNumROI;
                        pmapROI = realloc(pmapROI,
                                          ++pmapNumROI * sizeof(PhotonMapROI));
                        if (!pmapROI)
                           error(SYSTEM, "failed to allocate ROI");
                        pmapROI [n].min [0] = atof(argv [++i]);
                        pmapROI [n].min [1] = atof(argv [++i]);
                        pmapROI [n].min [2] = atof(argv [++i]);
                        pmapROI [n].max [0] = atof(argv [++i]);
                        pmapROI [n].max [1] = atof(argv [++i]);
                        pmapROI [n].max [2] = atof(argv [++i]);                        
                        for (j = 0; j < 3; j++)
                           if (pmapROI [n].min [j] >= pmapROI [n].max [j])
                              error(USER, "invalid region of interest "
                                    "(swapped min/max?)");
                        break;
#endif             

                     case 'P': /* Global photon precomp ratio */
                        check(4, "f");
                        finalGather = atof(argv [++i]);
                        if (finalGather <= 0 || finalGather > 1)
                           error(USER, "global photon precomputation ratio "
                                 "must be in range ]0, 1]");
                        break;
                     
                     case 'o': /* Photon port */ 
                     case 'O':
                        check(4, "s");
                        if (argv [i][3] == 'O') {	
                           /* Add port modifiers from file */
                           rval = wordfile(portLp, 
                                           MAXSET - (portLp - photonPortList),
                                           getpath(argv [++i],
                                           getrlibpath(), R_OK));
                           if (rval < 0) {
                               sprintf(errmsg, 
                                       "cannot open photon port file %s", 
                                       argv [i]);
                               error(SYSTEM, errmsg);
                           }
                           portLp += rval;
                        } 
                        else {
                           /* Add port modifier from next arg, mark end with
                            * NULL */
                           *portLp++ = savqstr(argv [++i]);
                           *portLp = NULL;
                        }
                        break;
                     
                     case 'r': /* Random seed */
                        check(4, "i");
                        randSeed = atoi(argv [++i]);
                        break;                   

                     case 's': /* Antimatter sensor */ 
                     case 'S':
                        check(4, "s");
                        if (argv[i][3] == 'S') {	
                           /* Add sensor modifiers from file */
                           rval = wordfile(sensLp, 
                                           MAXSET - (sensLp - photonSensorList),
                                           getpath(argv [++i], 
                                           getrlibpath(), R_OK));
                           if (rval < 0) {
                               sprintf(errmsg, 
                                       "cannot open antimatter sensor file %s",
                                       argv [i]);
                               error(SYSTEM, errmsg);
                           }
                           sensLp += rval;
                        } 
                        else {
                           /* Append modifier to sensor list, mark end with
                            * NULL */
                           *sensLp++ = savqstr(argv [++i]);
                           *sensLp = NULL;
                        }
                        break;

                     default: goto badopt;
                  }
                  break;
                  
               default: goto badopt;
            }
            break;
                
         case 'b': /* Back face visibility */
            if (argv [i][2] == 'v') {
               check_bool(3, backvis);
            }
            else goto badopt;
            break;
                   
         case 'd': /* Direct */
            switch (argv [i][2]) {
               case 'p': /* PDF samples */
                  check(3, "f");
                  pdfSamples = atof(argv [++i]);
                  break;
                  
               case 's': /* Source partition size ratio */
                  check(3, "f");
                  srcsizerat = atof(argv [++i]);
                  break;
                  
               default: goto badopt;
            }                   
            break;
                   
         case 'e': /* Diagnostics file */
            check(2, "s");
            diagFile = argv [++i];
            break;
                  
         case 'f': /* Force overwrite */
            if (argv [i][2] == 'o') {
               check_bool(3, clobber);
            }
            else goto badopt;
            break; 

#ifdef PMAP_EKSPERTZ
         case 'l': /* Limits */
            switch (argv [i][2]) {
               case 'd': /* Limit photon path distance */
                  check(3, "f");
                  photonMaxDist = atof(argv [++i]);
                  if (photonMaxDist <= 0)
                     error(USER, "max photon distance must be > 0");
                  break;
                 
               case 'r': /* Limit photon bounces */               
                  check(3, "i");               
                  photonMaxBounce = atol(argv [++i]);
                  if (photonMaxBounce <= 0) 
                     error(USER, "max photon bounces must be > 0");
                  break;
               
               default: goto badopt;
            }
            break;
#endif

         case 'm': /* Medium */
            switch (argv[i][2]) {
               case 'e':	/* Eggs-tinction coefficient */
                  check(3, "fff");
                  setcolor(cextinction, atof(argv [i + 1]),
                           atof(argv [i + 2]), atof(argv [i + 3]));
                  i += 3;
                  break;
                                
               case 'a':	/* Albedo */
                  check(3, "fff");
                  setcolor(salbedo, atof(argv [i + 1]), 
                           atof(argv [i + 2]), atof(argv [i + 3]));
                  i += 3;
                  break;
                                
               case 'g':	/* Scattering eccentricity */
                  check(3, "f");
                  seccg = atof(argv [++i]);
                  break;
                                
               default: goto badopt;
            }                   
            break;
            
#if NIX
         case 'n': /* Num parallel processes (NIX only) */
            check(2, "i");
            nproc = atoi(argv [++i]);
            
            if (nproc > PMAP_MAXPROC) {
               nproc = PMAP_MAXPROC;
               sprintf(errmsg, "too many parallel processes, clamping to "
                       "%d\n", nproc);
               error(WARNING, errmsg);
            }            
            break;                   
#endif

         case 't': /* Timer */
            check(2, "i");
            photonRepTime = atoi(argv [++i]);
            break;
            
         case 'v':   /* Verbosity */
            check_bool(2, verbose);
            break;
            
#ifdef EVALDRC_HACK
         case 'A':   /* Angular source file */
            check(2,"s");
            angsrcfile = argv[++i];
            break;                   
#endif

        default: goto badopt;
      }
   }
   
   /* Open diagnostics file */
   if (diagFile) {
      if (!freopen(diagFile, "a", stderr)) quit(2);
      fprintf(stderr, "**************\n*** PID %5d: ", getpid());
      printargs(argc, argv, stderr);
      putc('\n', stderr);
      fflush(stderr);
   }
   
#ifdef NICE
   /* Lower priority */
   nice(NICE);
#endif

   if (octname == NULL) 
      error(USER, "missing octree argument");
      
   /* Allocate photon maps and set parameters */
   for (i = 0; i < NUM_PMAP_TYPES; i++) {
      setPmapParam(photonMaps + i, pmapParams + i);
      
      /* Don't overwrite existing photon map unless clobbering enabled */
      if (photonMaps [i] && !stat(photonMaps [i] -> fileName, &pmstat) &&
          !clobber) {
         sprintf(errmsg, "photon map file %s exists, not overwritten",
                 photonMaps [i] -> fileName);
         error(USER, errmsg);
      }
   }
       
   for (i = 0; i < NUM_PMAP_TYPES && !photonMaps [i]; i++);   
   if (i >= NUM_PMAP_TYPES)
      error(USER, "no photon maps specified");
   
   readoct(octname, loadflags, &thescene, NULL);
#ifdef EVALDRC_HACK   
   if (angsrcfile)
      readobj(angsrcfile);    /* load angular sources */
#endif         
   nsceneobjs = nobjects;
   
   /* Get sources */
   marksources();

   /* Do forward pass and build photon maps */
   if (contribPmap)
      /* Just build contrib pmap, ignore others */
      distribPhotonContrib(contribPmap, nproc);
   else
      distribPhotons(photonMaps, nproc);
   
   /* Save photon maps; no idea why GCC needs an explicit cast here... */
   savePmaps((const PhotonMap**)photonMaps, argc, argv);
   cleanUpPmaps(photonMaps);
   
   quit(0);

badopt:
   sprintf(errmsg, "command line error at '%s'", argv[i]);
   error(USER, errmsg);

   #undef check
   #undef check_bool
   return 0;
}
Exemple #21
0
static const char *test_stdlib(void) {
  struct v7_val *v;
  struct v7 *v7 = v7_create();

  // Number
#ifndef _WIN32
  ASSERT((v = v7_exec(v7, "Math.PI")) != NULL);
  ASSERT(check_num(v7, v, M_PI));
  ASSERT((v = v7_exec(v7, "Number.NaN")) != NULL);
  ASSERT(check_num(v7, v, NAN));
#endif
  ASSERT((v = v7_exec(v7, "1 == 2")) != NULL);
  ASSERT(check_bool(v7, v, 0));
  ASSERT((v = v7_exec(v7, "1 + 2 * 7 === 15")) != NULL);
  ASSERT(check_bool(v7, v, 1));
  ASSERT((v = v7_exec(v7, "Number(1.23) === 1.23")) != NULL);
  ASSERT(check_bool(v7, v, 1));
  ASSERT((v = v7_exec(v7, "Number(1.23)")) != NULL);
  ASSERT(check_num(v7, v, 1.23));
#ifdef TODO /* New operator: Assertion failed: (v7->root_scope.proto == &s_global), function do_exec, file src/util.c, line 557. */
  ASSERT((v = v7_exec(v7, "new Number(21.23)")) != NULL);
#endif

  // String
  ASSERT((v = v7_exec(v7, "'hello'.charCodeAt(1)")) != NULL);
  ASSERT(check_num(v7, v, 'e'));
  ASSERT((v = v7_exec(v7, "'hello'.charCodeAt(4)")) != NULL);
  ASSERT(check_num(v7, v, 'o'));
  ASSERT((v = v7_exec(v7, "'hello'.charCodeAt(5) == Number.NaN")) != NULL);
  ASSERT(check_bool(v7, v, 1.0));
  ASSERT((v = v7_exec(v7, "'hello'.indexOf()")) != NULL);
  ASSERT(check_num(v7, v, -1.0));
  ASSERT((v = v7_exec(v7, "'HTTP/1.0\\r\\n'.indexOf('\\r\\n')")) != NULL);
  ASSERT(check_num(v7, v, 8.0));
  ASSERT((v = v7_exec(v7, "'hi there'.indexOf('e')")) != NULL);
  ASSERT(check_num(v7, v, 5.0));
  ASSERT((v = v7_exec(v7, "'hi there'.indexOf('e', 6)")) != NULL);
  ASSERT(check_num(v7, v, 7.0));
  ASSERT((v = v7_exec(v7, "'hi there'.substr(3, 2)")) != NULL);
  ASSERT(check_str(v7, v, "th"));
  ASSERT((v = v7_exec(v7, "'hi there'.substring(3, 5)")) != NULL);
  ASSERT(check_str(v7, v, "th"));
  ASSERT((v = v7_exec(v7, "'hi there'.substr(3)")) != NULL);
  ASSERT(check_str(v7, v, "there"));
  ASSERT((v = v7_exec(v7, "'hi there'.substr(-2)")) != NULL);
  ASSERT(check_str(v7, v, "hi there"));
  ASSERT((v = v7_exec(v7, "'hi there'.substr(NaN)")) != NULL);
  ASSERT(check_str(v7, v, "hi there"));
  ASSERT((v = v7_exec(v7, "'hi there'.substr(0, 300)")) != NULL);
  ASSERT(check_str(v7, v, "hi there"));
  ASSERT((v = v7_exec(v7, "'dew dee'.match(/\\d+/)")) != NULL);
  ASSERT(v7_type(v) == V7_TYPE_NULL);
  ASSERT((v = v7_exec(v7, "m = 'foo 1234 bar'.match(/\\S+ (\\d+)/)")) != NULL);
  ASSERT((v = v7_exec(v7, "m.length")) != NULL);
#ifdef TODO /* got: [foo 1234] i.e. 1 length array with input string !! */
  ASSERT(check_num(v7, v, 2.0));
  ASSERT((v = v7_exec(v7, "m[0]")) != NULL);
  ASSERT(check_str(v7, v, "foo 1234"));
  ASSERT((v = v7_exec(v7, "m[1]")) != NULL);
  ASSERT(check_str(v7, v, "1234"));
  ASSERT((v = v7_exec(v7, "m[2]")) != NULL);
  ASSERT(v7_type(v) == V7_TYPE_UNDEF);
#endif
  ASSERT((v = v7_exec(v7, "m = 'aa bb cc'.split(); m.length")) != NULL);
  ASSERT(check_num(v7, v, 1.0));
#ifdef TODO  /* doesn't split at every char */
  ASSERT((v = v7_exec(v7, "m = 'aa bb cc'.split(''); m.length")) != NULL);
  ASSERT(check_num(v7, v, 8.0));
#endif
  ASSERT((v = v7_exec(v7, "m = 'aa bb cc'.split(' '); m.length")) != NULL);
  ASSERT(check_num(v7, v, 3.0));
  ASSERT((v = v7_exec(v7, "m = 'aa bb cc'.split(' ', 2); m.length")) != NULL);
  ASSERT(check_num(v7, v, 2.0));
  ASSERT((v = v7_exec(v7, "m = 'aa bb cc'.split(/ /, 2); m.length")) != NULL);
  ASSERT(check_num(v7, v, 2.0));
  ASSERT((v = v7_exec(v7, "'aa bb cc'.substr(0, 4).split(' ').length")) != NULL);
  ASSERT(check_num(v7, v, 2.0));
  ASSERT((v = v7_exec(v7, "'aa bb cc'.substr(0, 4).split(' ')[1]")) != NULL);
  ASSERT(check_str(v7, v, "b"));
#ifdef TODO  /* doesn't split at every char */
  ASSERT((v = v7_exec(v7, "{z: '123456'}.z.substr(0, 3).split('').length")) != NULL);
  ASSERT(check_num(v7, v, 3.0));
#endif
  ASSERT((v = v7_exec(v7, "String('hi')")) != NULL);
  ASSERT(check_str(v7, v, "hi"));
#ifdef TODO /* New operator: Assertion failed: (v7->root_scope.proto == &s_global), function do_exec, file src/util.c, line 557. */
  ASSERT((v = v7_exec(v7, "new String('blah')")) != NULL);
#endif

  // Math
  ASSERT((v = v7_exec(v7, "Math.sqrt(144)")) != NULL);
  ASSERT(check_num(v7, v, 12.0));

  // Regexp
  ASSERT((v = v7_exec(v7, "re = /GET (\\S+) HTTP/; re")) != NULL);
  ASSERT((v = v7_exec(v7, "re = /GET (\\S+) HTTP/;")) != NULL);
  ASSERT((v = v7_exec(v7, "re = /GET (\\S+) HTTP/ ")) != NULL);
  ASSERT((v = v7_exec(v7, "re = /GET (\\S+) HTTP/\n")) != NULL);
  ASSERT((v = v7_exec(v7, "re = /GET (\\S+) HTTP/")) != NULL);

  v7_destroy(&v7);
  return NULL;
}
static int rbody_newindex (lua_State *L)
{
TRY_START
        check_args(L, 3);
        GET_UD_MACRO(RigidBody, self, 1, RBODY_TAG);
        const char *key = luaL_checkstring(L, 2);
        if (!::strcmp(key, "linearVelocity")) {
                Vector3 v = check_v3(L, 3);
                self.setLinearVelocity(v);
        } else if (!::strcmp(key, "angularVelocity")) {
                Vector3 v = check_v3(L, 3);
                self.setAngularVelocity(v);
        } else if (!::strcmp(key, "worldPosition")) {
                Vector3 v = check_v3(L, 3);
                self.setPosition(v);
        } else if (!::strcmp(key, "worldOrientation")) {
                Quaternion v = check_quat(L, 3);
                self.setOrientation(v);
        } else if (!::strcmp(key, "contactProcessingThreshold")) {
                float v = check_float(L, 3);
                self.setContactProcessingThreshold(v);
        } else if (!::strcmp(key, "linearDamping")) {
                float v = check_float(L, 3);
                self.setLinearDamping(v);
        } else if (!::strcmp(key, "angularDamping")) {
                float v = check_float(L, 3);
                self.setAngularDamping(v);
        } else if (!::strcmp(key, "linearSleepThreshold")) {
                float v = check_float(L, 3);
                self.setLinearSleepThreshold(v);
        } else if (!::strcmp(key, "angularSleepThreshold")) {
                float v = check_float(L, 3);
                self.setAngularSleepThreshold(v);
        } else if (!::strcmp(key, "mass")) {
                float v = check_float(L, 3);
                self.setMass(v);
        } else if (!::strcmp(key, "ghost")) {
                bool v = check_bool(L, 3);
                self.setGhost(v);
        } else if (!::strcmp(key, "updateCallback")) {
                self.updateCallbackPtr.set(L);
        } else if (!::strcmp(key, "stepCallback")) {
                self.stepCallbackPtr.set(L);
        } else if (!::strcmp(key, "collisionCallback")) {
                self.collisionCallbackPtr.set(L);
        } else if (!::strcmp(key, "stabiliseCallback")) {
                self.stabiliseCallbackPtr.set(L);
        } else if (!::strcmp(key, "inertia")) {
                Vector3 v = check_v3(L, 3);
                self.setInertia(v);
        } else if (!::strcmp(key, "owner")) {
                if (lua_isnil(L, 3)) {
                        self.owner.setNull();
                } else {
                        GET_UD_MACRO(GritObjectPtr, v, 3, GRITOBJ_TAG);
                        self.owner = v;
                }

        } else {
               my_lua_error(L, "Not a writeable RigidBody member: "+std::string(key));
        }
        return 0;
TRY_END
}
Exemple #23
0
void
test1()
{
	int i;

	for (i = 0; i < 256; i++) {
		printf(" %02x: ", i);
		check_bool(isalnum(i), iswalnum(i), '1');
		check_bool(isalpha(i), iswalpha(i), '2');
		check_bool(isblank(i), iswblank(i), '3');
		check_bool(iscntrl(i), iswcntrl(i), '4');
		check_bool(isdigit(i), iswdigit(i), '5');
		check_bool(isgraph(i), iswgraph(i), '6');
		check_bool(islower(i), iswlower(i), '6');
		check_bool(isprint(i), iswprint(i), '7');
		check_bool(ispunct(i), iswpunct(i), '8');
		check_bool(isspace(i), iswspace(i), '9');
		check_bool(isupper(i), iswupper(i), 'a');
		check_bool(isxdigit(i), iswxdigit(i), 'b');
		check_value(tolower(i), towlower(i), 'c');
		check_value(toupper(i), towupper(i), 'd');
		if (i % 8 == 7)
			printf("\n");
	}
	printf("%\n");
}
Exemple #24
0
bool lt(ast * n1, ast * n2) {
    unsigned num;
 start:
    if (n1 == n2)
        return false;
    check_value(n1->get_kind(), n2->get_kind());
    switch(n1->get_kind()) {
    case AST_SORT:
        check_symbol(to_sort(n1)->get_name(), to_sort(n2)->get_name());
        check_value(to_sort(n1)->get_num_parameters(), to_sort(n2)->get_num_parameters());
        num = to_sort(n1)->get_num_parameters();
        SASSERT(num > 0);
        for (unsigned i = 0; i < num; i++) {
            parameter p1 = to_sort(n1)->get_parameter(i);
            parameter p2 = to_sort(n2)->get_parameter(i);
            check_parameter(p1, p2);
        }
        UNREACHABLE();
        return false;
    case AST_FUNC_DECL:
        check_symbol(to_func_decl(n1)->get_name(), to_func_decl(n2)->get_name());
        check_value(to_func_decl(n1)->get_arity(), to_func_decl(n2)->get_arity());
        check_value(to_func_decl(n1)->get_num_parameters(), to_func_decl(n2)->get_num_parameters());
        num = to_func_decl(n1)->get_num_parameters();
        for (unsigned i = 0; i < num; i++) {
            parameter p1 = to_func_decl(n1)->get_parameter(i);
            parameter p2 = to_func_decl(n2)->get_parameter(i);
            check_parameter(p1, p2);
        }
        num = to_func_decl(n1)->get_arity();
        for (unsigned i = 0; i < num; i++) {
            ast * d1 = to_func_decl(n1)->get_domain(i);
            ast * d2 = to_func_decl(n2)->get_domain(i);
            check_ast(d1, d2);
        }
        n1 = to_func_decl(n1)->get_range();
        n2 = to_func_decl(n2)->get_range();
        goto start;
    case AST_APP:
        check_value(to_app(n1)->get_num_args(), to_app(n2)->get_num_args());
        check_value(to_app(n1)->get_depth(), to_app(n2)->get_depth());
        check_ast(to_app(n1)->get_decl(), to_app(n2)->get_decl());
        num = to_app(n1)->get_num_args();
        for (unsigned i = 0; i < num; i++) {
            expr * arg1 = to_app(n1)->get_arg(i);
            expr * arg2 = to_app(n2)->get_arg(i);
            check_ast(arg1, arg2);
        }
        UNREACHABLE();
        return false;
    case AST_QUANTIFIER:
        check_bool(to_quantifier(n1)->is_forall(), to_quantifier(n2)->is_forall());
        check_value(to_quantifier(n1)->get_num_decls(), to_quantifier(n2)->get_num_decls());
        check_value(to_quantifier(n1)->get_num_patterns(), to_quantifier(n2)->get_num_patterns());
        check_value(to_quantifier(n1)->get_num_no_patterns(), to_quantifier(n2)->get_num_no_patterns());
        check_value(to_quantifier(n1)->get_weight(), to_quantifier(n2)->get_weight());
        num = to_quantifier(n1)->get_num_decls();
        for (unsigned i = 0; i < num; i++) {
            check_symbol(to_quantifier(n1)->get_decl_name(i), to_quantifier(n2)->get_decl_name(i));
            check_ast(to_quantifier(n1)->get_decl_sort(i), to_quantifier(n2)->get_decl_sort(i));
        }
        num = to_quantifier(n1)->get_num_patterns();
        for (unsigned i = 0; i < num; i++) {
            check_ast(to_quantifier(n1)->get_pattern(i), to_quantifier(n2)->get_pattern(i));
        }
        num = to_quantifier(n1)->get_num_no_patterns();
        for (unsigned i = 0; i < num; i++) {
            check_ast(to_quantifier(n1)->get_no_pattern(i), to_quantifier(n2)->get_no_pattern(i));
        }
        n1 = to_quantifier(n1)->get_expr();
        n2 = to_quantifier(n2)->get_expr();
        goto start;
    case AST_VAR:
        check_value(to_var(n1)->get_idx(), to_var(n2)->get_idx());
        n1 = to_var(n1)->get_sort();
        n2 = to_var(n2)->get_sort();
        goto start;
    default:
        UNREACHABLE();
        return false;
    }
}
static int gritobj_newindex (lua_State *L)
{
TRY_START
        check_args(L,3);
        GET_UD_MACRO(GritObjectPtr,self,1,GRITOBJ_TAG);
        std::string key = check_string(L,2);

        if (key=="destroy") {
                my_lua_error(L,"Not a writeable GritObject member: "+key);
        } else if (key=="near") {
                if (lua_isnil(L,3)) {
                        self->setNearObj(self,GritObjectPtr());
                } else {
                        GET_UD_MACRO(GritObjectPtr,v,3,GRITOBJ_TAG);
                        self->setNearObj(self,v);
                }
        } else if (key=="far") {
                if (lua_isnil(L,3)) {
                        self->setNearObj(self,GritObjectPtr());
                } else {
                        GET_UD_MACRO(GritObjectPtr,v,3,GRITOBJ_TAG);
                        self->setFarObj(self,v);
                }
        } else if (key=="fade") {
                my_lua_error(L,"Not a writeable GritObject member: "+key);
        } else if (key=="updateSphere") {
                my_lua_error(L,"Not a writeable GritObject member: "+key);
        } else if (key=="pos") {
                self->updateSphere(check_v3(L,3));
        } else if (key=="renderingDistance") {
                self->updateSphere(check_float(L,3));
        } else if (key=="getSphere") {
                my_lua_error(L,"Not a writeable GritObject member: "+key);
        } else if (key=="activated") {
                my_lua_error(L,"Not a writeable GritObject member: "+key);
        } else if (key=="deactivate") {
                my_lua_error(L,"Not a writeable GritObject member: "+key);
        } else if (key=="activate") {
                my_lua_error(L,"Not a writeable GritObject member: "+key);
        } else if (key=="instance") {
                my_lua_error(L,"Not a writeable GritObject member: "+key);
        } else if (key=="hintAdvancePrepare") {
                my_lua_error(L,"Not a writeable GritObject member: "+key);
        } else if (key=="getAdvancePrepareHints") {
                my_lua_error(L,"Not a writeable GritObject member: "+key);
        } else if (key=="destroyed") {
                my_lua_error(L,"Not a writeable GritObject member: "+key);
        } else if (key=="class") {
                my_lua_error(L,"Not a writeable GritObject member: "+key);
        } else if (key=="className") {
                my_lua_error(L,"Not a writeable GritObject member: "+key);
        } else if (key=="name") {
                my_lua_error(L,"Not a writeable GritObject member: "+key);
        } else if (key=="needsFrameCallbacks") {
                self->setNeedsFrameCallbacks(self, check_bool(L,3));
        } else if (key=="needsStepCallbacks") {
                self->setNeedsStepCallbacks(self, check_bool(L,3));
        } else {
                GritClass *c = self->getClass();
                if (c==NULL) my_lua_error(L,"GritObject destroyed");
                const char *err = self->userValues.luaSet(L);
                if (err) my_lua_error(L, err);
        }

        return 0;
TRY_END
}
Exemple #26
0
int main() {
	{
		int buf[16];
		Stack stack = newStack(buf);
		check_bool(false, pop(&stack, 0));
	}

	{
		int buf[16];
		Stack stack = newStack(buf);

		check_bool(true, push(&stack, 123));

		int ret;
		check_bool(true, pop(&stack, &ret));
		check_int(123, ret);

		check_bool(false, pop(&stack, &ret));
	}

	{
		int buf[16];
		Stack stack = newStack(buf);

		for (int i = 0; i < 16; ++i) push(&stack, i);
		check_bool(false, push(&stack, 100));

		int ret;
		check_bool(true, pop(&stack, &ret));
		check_int(15, ret);
	}

	{
		int buf[16];
		RangeValidator validator = newRangeValidator(0, 9);
		Stack stack = newStackWithValidator(buf, &validator.base);
		check_bool(false, push(&stack, -1));
		check_bool(false, push(&stack, 10));
	}

	{
		int buf[16];
		PreviousValueValidator validator = newPreviousValueValidator;
		Stack stack = newStackWithValidator(buf, &validator.base);
		check_bool(true, push(&stack, 3));
		check_bool(false, push(&stack, 2));
	}

	{
		ChainedValidator trueChainedValidator = newChainedValidator(&trueValidator.base, NULL);
		check_bool(true, trueChainedValidator.base.validate(&trueChainedValidator.base, 0));

		ChainedValidator falseChainedValidator = newChainedValidator(&falseValidator.base, NULL);
		check_bool(false, falseChainedValidator.base.validate(&falseChainedValidator.base, 0));
	}

	{
		ChainedValidator falseChain = newChainedValidator(&falseValidator.base, NULL);
		ChainedValidator trueFalseChain = newChainedValidator(&trueValidator.base, &falseChain.base);
		check_bool(false, trueFalseChain.base.validate(&trueFalseChain.base, 0));
	}

	{
		ChainedValidator trueChain = newChainedValidator(&trueValidator.base, NULL);
		ChainedValidator falseTrueChain = newChainedValidator(&falseValidator.base, &trueChain.base);
		check_bool(false, falseTrueChain.base.validate(&falseTrueChain.base, 0));
	}

	{
		ChainedValidator trueChain = newChainedValidator(&trueValidator.base, NULL);
		ChainedValidator trueTrueChain = newChainedValidator(&trueValidator.base, &trueChain.base);
		check_bool(true, trueTrueChain.base.validate(&trueTrueChain.base, 0));
	}

	{
		ChainedValidator falseChain = newChainedValidator(&falseValidator.base, NULL);
		ChainedValidator falseFalseChain = newChainedValidator(&falseValidator.base, &falseChain.base);
		check_bool(false, falseFalseChain.base.validate(&falseFalseChain.base, 0));
	}

	{
		RangeValidator rangeValidator = newRangeValidator(0, 9);
		PreviousValueValidator preValidator = newPreviousValueValidator;
		ChainedValidator preChain = newChainedValidator(&preValidator.base, NULL);
		ChainedValidator rangeChain = newChainedValidator(&rangeValidator.base, &preChain);
		int buf[16];
		Stack stack = newStackWithValidator(buf, &rangeChain.base);
		check_bool(false, push(&stack, -1));
		check_bool(true, push(&stack, 5));
		check_bool(false, push(&stack, 4));
		check_bool(true, push(&stack, 9));
		check_bool(false, push(&stack, 10));
	}
}
Exemple #27
0
/*---------------------------------------------------------------------------*
 *                              run tests                                    *
 *---------------------------------------------------------------------------*/
int
main()
{
    unsigned idx;

    /* int_array_lit_assigment() tests */
    check_int("int_array_lit_assigment(0)",
              call_int_array_lit_assigment(0), 3 + 3);
    check_int("int_array_lit_assigment(1)",
              call_int_array_lit_assigment(1), 3 + 1);
    check_int("int_array_lit_assigment(2)",
              call_int_array_lit_assigment(2), 3 + 4);

    /* int_array_lit_init() tests */
    check_int("int_array_lit_init(0)",
              call_int_array_lit_init(0), 2);
    check_int("int_array_lit_init(1)",
              call_int_array_lit_init(1), 7);
    check_int("int_array_lit_init(2)",
              call_int_array_lit_init(2), 1);
    check_int("int_array_lit_init(3)",
              call_int_array_lit_init(3), 8);
    check_int("int_array_lit_init(3)",
              call_int_array_lit_init(4), 2);

    /* intops() tests */
    check_int("intops(0, 20)", call_intops(0, 20), 20 + 2 + 3);
    check_int("intops(1, 0)", call_intops(1, 0), 1 + 0 + 3);
    check_int("intops(2, -20)", call_intops(2, -20), 1 + 2 + (-20));

    /* bool_array_lit_assigment() tests */
    check_bool("bool_array_lit_assigment(0)",
               call_bool_array_lit_assigment(0), true);
    check_bool("bool_array_lit_assigment(1)",
               call_bool_array_lit_assigment(1), false);
    check_bool("bool_array_lit_assigment(2)",
               call_bool_array_lit_assigment(2), true);
    check_bool("bool_array_lit_assigment(3)",
               call_bool_array_lit_assigment(3), false);

    /* bool_array_lit_init() tests */
    check_bool("bool_array_lit_init(true)",
               call_bool_array_lit_init(true), true);
    check_bool("bool_array_lit_init(false)",
               call_bool_array_lit_init(false), false);

    /* boolops() tests */
    check_bool("boolops(0, -1)", call_boolops(0, -1), false);
    check_bool("boolops(1, 10)", call_boolops(1, 10), true);
    check_bool("boolops(2, 0)", call_boolops(2, 0), false);

    /* char_array() tests */
    check_char("char_array('X', 0)", call_char_array('X', 0), 'X');
    check_char("char_array('X', 1)", call_char_array('X', 1), 'b');
    check_char("char_array('X', 2)", call_char_array('X', 2), 'c');
    check_char("char_array('X', 3)", call_char_array('X', 3), 'd');
    check_char("char_array('X', 4)", call_char_array('X', 4), 'e');
    check_char("char_array('X', 5)", call_char_array('X', 5), 'X');

    /* dyn_array_sum() tests */
    check_int("invoke_dyn_array_sum_handle(0)",
              call_invoke_dyn_array_sum_handle(0), 1 + 10 + 15 + 0 + 5);

    check_int("invoke_dyn_array_sum_handle(1)",
              call_invoke_dyn_array_sum_handle(1), 5 -12);

    check_int("invoke_dyn_array_sum_handle(2)",
              call_invoke_dyn_array_sum_handle(2), 0);

    check_int("invoke_dyn_array_sum_handle(3)",
              call_invoke_dyn_array_sum_handle(3), -1);

    check_int("invoke_dyn_array_sum_lit(0)",
              call_invoke_dyn_array_sum_lit(0), 3 + 1 + 4 + 1 + 5);

    check_int("invoke_dyn_array_sum_lit(1)",
              call_invoke_dyn_array_sum_lit(1), 50 + 23);

    check_int("invoke_dyn_array_sum_lit(2)",
              call_invoke_dyn_array_sum_lit(2), 0);

    check_int("invoke_dyn_array_sum_lit(3)",
              call_invoke_dyn_array_sum_lit(3), -1);

    /* dyn_array_slice_assigment() tests */
    for (idx = 0; idx < 5; idx += 1)
    {
      check_int("dyn_array_slice_assigment(false, idx)",
                  call_dyn_array_slice_assigment(false, idx), (int)(idx + 1));
    }
    check_int("dyn_array_slice_assigment(true, 0)",
              call_dyn_array_slice_assigment(true, 0), 1);
    check_int("dyn_array_slice_assigment(true, 1)",
              call_dyn_array_slice_assigment(true, 1), 2);
    check_int("dyn_array_slice_assigment(true, 2)",
              call_dyn_array_slice_assigment(true, 2), 11);
    check_int("dyn_array_slice_assigment(true, 3)",
              call_dyn_array_slice_assigment(true, 3), 22);
    check_int("dyn_array_slice_assigment(true, 4)",
              call_dyn_array_slice_assigment(true, 4), 5);

    /* dyn_array_slice_assigment_length() tests */
    check_uint("dyn_array_slice_assigment_length(0)",
               call_dyn_array_slice_assigment_length(0), 0);
    check_uint("dyn_array_slice_assigment_length(1)",
               call_dyn_array_slice_assigment_length(1), 0);
    check_uint("dyn_array_slice_assigment_length(2)",
               call_dyn_array_slice_assigment_length(2), 0);
    check_uint("dyn_array_slice_assigment_length(3)",
               call_dyn_array_slice_assigment_length(3), 99);
    check_uint("dyn_array_slice_assigment_length(4)",
               call_dyn_array_slice_assigment_length(4), 98);
    check_uint("dyn_array_slice_assigment_length(5)",
               call_dyn_array_slice_assigment_length(5), 97);

    /* dyn_array_slice_shorthand() tests */
    for (idx = 0; idx < 5; idx += 1)
    {
      check_int("dyn_array_slice_shorthand(false, idx)",
                call_dyn_array_slice_shorthand(false, idx), -1);
    }
    check_int("dyn_array_slice_shorthand(true, 0)",
              call_dyn_array_slice_shorthand(true, 0), 11);
    check_int("dyn_array_slice_shorthand(true, 1)",
              call_dyn_array_slice_shorthand(true, 1), 22);
    check_int("dyn_array_slice_shorthand(true, 2)",
              call_dyn_array_slice_shorthand(true, 2), 33);
    check_int("dyn_array_slice_shorthand(true, 3)",
              call_dyn_array_slice_shorthand(true, 3), 44);
    check_int("dyn_array_slice_shorthand(true, 4)",
              call_dyn_array_slice_shorthand(true, 4), 55);

    /* find_int() tests */
    check_bool("invoke_find_int(0)",
               call_invoke_find_int(0), true);
    check_bool("invoke_find_int(1)",
               call_invoke_find_int(1), false);
    check_bool("invoke_find_int(2)",
               call_invoke_find_int(2), false);
    check_bool("invoke_find_int(3)",
               call_invoke_find_int(3), false);
    check_bool("invoke_find_int(4)",
               call_invoke_find_int(4), true);

    /* array_null_assign() tests */
    check_uint("array_null_assign(true)", array_null_assign(true), 0);
    check_uint("array_null_assign(false)", array_null_assign(false), 4);

    /* array_null_arg() tests */
    check_int("array_null_arg(true)", array_null_arg(true), 0);
    check_int("array_null_arg(false)", array_null_arg(false), 10 + 2 + 3);

    check_exit();
}
int
main(int argc, char *argv[])
{
#define	 check(ol,al)		if (argv[i][ol] || \
				badarg(argc-i-1,argv+i+1,al)) \
				goto badopt
#define	 check_bool(olen,var)		switch (argv[i][olen]) { \
				case '\0': var = !var; break; \
				case 'y': case 'Y': case 't': case 'T': \
				case '+': case '1': var = 1; break; \
				case 'n': case 'N': case 'f': case 'F': \
				case '-': case '0': var = 0; break; \
				default: goto badopt; }
	char  *octnm = NULL;
	char  *err;
	int  rval;
	int  i;
					/* global program name */
	progname = argv[0] = fixargv0(argv[0]);
					/* set our defaults */
	shadthresh = .1;
	shadcert = .25;
	directrelay = 0;
	vspretest = 128;
	srcsizerat = 0.;
	specthresh = .3;
	specjitter = 1.;
	maxdepth = 6;
	minweight = 1e-2;
	ambacc = 0.3;
	ambres = 32;
	ambdiv = 256;
	ambssamp = 64;
					/* option city */
	for (i = 1; i < argc; i++) {
						/* expand arguments */
		while ((rval = expandarg(&argc, &argv, i)) > 0)
			;
		if (rval < 0) {
			sprintf(errmsg, "cannot expand '%s'", argv[i]);
			error(SYSTEM, errmsg);
		}
		if (argv[i] == NULL || argv[i][0] != '-')
			break;			/* break from options */
		if (!strcmp(argv[i], "-version")) {
			puts(VersionID);
			quit(0);
		}
		if (!strcmp(argv[i], "-defaults") ||
				!strcmp(argv[i], "-help")) {
			printdefaults();
			quit(0);
		}
		if (!strcmp(argv[i], "-devices")) {
			printdevices();
			quit(0);
		}
		rval = getrenderopt(argc-i, argv+i);
		if (rval >= 0) {
			i += rval;
			continue;
		}
		rval = getviewopt(&ourview, argc-i, argv+i);
		if (rval >= 0) {
			i += rval;
			continue;
		}
		switch (argv[i][1]) {
		case 'n':				/* # processes */
			check(2,"i");
			nproc = atoi(argv[++i]);
			if (nproc <= 0)
				error(USER, "bad number of processes");
			break;
		case 'v':				/* view file */
			if (argv[i][2] != 'f')
				goto badopt;
			check(3,"s");
			rval = viewfile(argv[++i], &ourview, NULL);
			if (rval < 0) {
				sprintf(errmsg,
				"cannot open view file \"%s\"",
						argv[i]);
				error(SYSTEM, errmsg);
			} else if (rval == 0) {
				sprintf(errmsg,
					"bad view file \"%s\"",
						argv[i]);
				error(USER, errmsg);
			}
			break;
		case 'b':				/* grayscale */
			check_bool(2,greyscale);
			break;
		case 'p':				/* pixel */
			switch (argv[i][2]) {
			case 's':				/* sample */
				check(3,"i");
				psample = atoi(argv[++i]);
				break;
			case 't':				/* threshold */
				check(3,"f");
				maxdiff = atof(argv[++i]);
				break;
			case 'e':				/* exposure */
				check(3,"f");
				exposure = atof(argv[++i]);
				if (argv[i][0] == '+' || argv[i][0] == '-')
					exposure = pow(2.0, exposure);
				break;
			default:
				goto badopt;
			}
			break;
		case 'w':				/* warnings */
			rval = erract[WARNING].pf != NULL;
			check_bool(2,rval);
			if (rval) erract[WARNING].pf = wputs;
			else erract[WARNING].pf = NULL;
			break;
		case 'e':				/* error file */
			check(2,"s");
			errfile = argv[++i];
			break;
		case 'o':				/* output device */
			check(2,"s");
			dvcname = argv[++i];
			break;
		case 'R':				/* render input file */
			check(2,"s");
			strcpy(rifname, argv[++i]);
			break;
		default:
			goto badopt;
		}
	}
	err = setview(&ourview);	/* set viewing parameters */
	if (err != NULL)
		error(USER, err);
						/* set up signal handling */
	sigdie(SIGINT, "Interrupt");
	sigdie(SIGTERM, "Terminate");
#if !defined(_WIN32) && !defined(_WIN64)
	sigdie(SIGHUP, "Hangup");
	sigdie(SIGPIPE, "Broken pipe");
	sigdie(SIGALRM, "Alarm clock");
#endif
					/* open error file */
	if (errfile != NULL) {
		if (freopen(errfile, "a", stderr) == NULL)
			quit(2);
		fprintf(stderr, "**************\n*** PID %5d: ",
				getpid());
		printargs(argc, argv, stderr);
		putc('\n', stderr);
		fflush(stderr);
	}
#ifdef	NICE
	nice(NICE);			/* lower priority */
#endif
					/* get octree */
	if (i == argc)
		octnm = NULL;
	else if (i == argc-1)
		octnm = argv[i];
	else
		goto badopt;
	if (octnm == NULL)
		error(USER, "missing octree argument");
					/* set up output & start process(es) */
	SET_FILE_BINARY(stdout);
	
	ray_init(octnm);		/* also calls ray_init_pmap() */
	
/* temporary shortcut, until winrview is refactored into a "device" */
#ifndef WIN_RVIEW
	rview();			/* run interactive viewer */


	devclose();			/* close output device */
#endif

	/* PMAP: free photon maps */
	ray_done_pmap();
	
#ifdef WIN_RVIEW
	return 1;
#endif
	quit(0);

badopt:
	sprintf(errmsg, "command line error at '%s'", argv[i]);
	error(USER, errmsg);
	return 1; /* pro forma return */

#undef	check
#undef	check_bool
}
Exemple #29
0
void parse_args(int argc, char **argv)
{
    int i, j;

    for(i = 0; i < argc; i += 1)
    {
        if(stricmp("-vdriver", argv[i]) == 0)
        {
            for(j = 0; video_driver_table[j].token != NULL; j += 1)
            {
                if(stricmp(argv[i+1], video_driver_table[j].token) == 0)
                {
                    option.video_driver = video_driver_table[j].value;
                }
            }
        }

        if(stricmp("-res", argv[i]) == 0)
        {
            option.video_width = atoi(argv[i+1]);
            option.video_height = atoi(argv[i+2]);
        }

        if(stricmp("-depth", argv[i]) == 0)
        {
            option.video_depth = atoi(argv[i+1]);
        }

        if(stricmp("-remap", argv[i]) == 0)
        {
            option.remap = check_bool(argv[i+1]);
        }

        if(stricmp("-scanlines", argv[i]) == 0)
        {
            option.scanlines = check_bool(argv[i+1]);
        }

        if(stricmp("-scale", argv[i]) == 0)
        {
            option.scale = check_bool(argv[i+1]);
        }

        if(stricmp("-vsync", argv[i]) == 0)
        {
            option.vsync = check_bool(argv[i+1]);
        }

        if(stricmp("-throttle", argv[i]) == 0)
        {
            option.throttle = check_bool(argv[i+1]);
        }

        if(stricmp("-skip", argv[i]) == 0)
        {
            option.skip = atoi(argv[i+1]);
            if(!option.skip) option.skip = 1;
        }

        if(stricmp("-sound", argv[i]) == 0)
        {
            option.sound = check_bool(argv[i+1]);
        }

        if(stricmp("-sndcard", argv[i]) == 0)
        {
            option.sndcard = atoi(argv[i+1]);
        }

        if(stricmp("-sndrate", argv[i]) == 0)
        {
            option.sndrate = atoi(argv[i+1]);
        }

        if(stricmp("-swap", argv[i]) == 0)
        {
            option.swap = check_bool(argv[i+1]);
        }

        if(stricmp("-joy", argv[i]) == 0)
        {
            for(j = 0; joy_driver_table[j].token != NULL; j += 1)
            {
                if(stricmp(argv[i+1], joy_driver_table[j].token) == 0)
                {
                    option.joy_driver = joy_driver_table[j].value;
                }
            }
        }
    }

   if(option.remap) option.video_depth = 8;
}
int
main(int  argc, char  *argv[])
{
#define	 check(ol,al)		if (argv[i][ol] || \
				badarg(argc-i-1,argv+i+1,al)) \
				goto badopt
#define	 check_bool(olen,var)		switch (argv[i][olen]) { \
				case '\0': var = !var; break; \
				case 'y': case 'Y': case 't': case 'T': \
				case '+': case '1': var = 1; break; \
				case 'n': case 'N': case 'f': case 'F': \
				case '-': case '0': var = 0; break; \
				default: goto badopt; }
	char  *err;
	char  *recover = NULL;
	char  *outfile = NULL;
	char  *zfile = NULL;
	int  loadflags = ~IO_FILES;
	int  seqstart = 0;
	int  persist = 0;
	int  duped1 = -1;
	int  rval;
	int  i;
					/* record start time */
	tstart = time((time_t *)NULL);
					/* global program name */
	progname = argv[0] = fixargv0(argv[0]);
					/* option city */
	for (i = 1; i < argc; i++) {
						/* expand arguments */
		while ((rval = expandarg(&argc, &argv, i)) > 0)
			;
		if (rval < 0) {
			sprintf(errmsg, "cannot expand '%s'", argv[i]);
			error(SYSTEM, errmsg);
		}
		if (argv[i] == NULL || argv[i][0] != '-')
			break;			/* break from options */
		if (!strcmp(argv[i], "-version")) {
			puts(VersionID);
			quit(0);
		}
		if (!strcmp(argv[i], "-defaults") ||
				!strcmp(argv[i], "-help")) {
			printdefaults();
			quit(0);
		}
		rval = getrenderopt(argc-i, argv+i);
		if (rval >= 0) {
			i += rval;
			continue;
		}
		rval = getviewopt(&ourview, argc-i, argv+i);
		if (rval >= 0) {
			i += rval;
			continue;
		}
						/* rpict options */
		switch (argv[i][1]) {
		case 'v':				/* view file */
			if (argv[i][2] != 'f')
				goto badopt;
			check(3,"s");
			rval = viewfile(argv[++i], &ourview, NULL);
			if (rval < 0) {
				sprintf(errmsg,
				"cannot open view file \"%s\"",
						argv[i]);
				error(SYSTEM, errmsg);
			} else if (rval == 0) {
				sprintf(errmsg,
					"bad view file \"%s\"",
						argv[i]);
				error(USER, errmsg);
			}
			break;
		case 'p':				/* pixel */
			switch (argv[i][2]) {
			case 's':				/* sample */
				check(3,"i");
				psample = atoi(argv[++i]);
				break;
			case 't':				/* threshold */
				check(3,"f");
				maxdiff = atof(argv[++i]);
				break;
			case 'j':				/* jitter */
				check(3,"f");
				dstrpix = atof(argv[++i]);
				break;
			case 'a':				/* aspect */
				check(3,"f");
				pixaspect = atof(argv[++i]);
				break;
			case 'm':				/* motion */
				check(3,"f");
				mblur = atof(argv[++i]);
				break;
			case 'd':				/* aperture */
				check(3,"f");
				dblur = atof(argv[++i]);
				break;
			default:
				goto badopt;
			}
			break;
		case 'x':				/* x resolution */
			check(2,"i");
			hresolu = atoi(argv[++i]);
			break;
		case 'y':				/* y resolution */
			check(2,"i");
			vresolu = atoi(argv[++i]);
			break;
		case 'S':				/* slave index */
			check(2,"i");
			seqstart = atoi(argv[++i]);
			break;
		case 'o':				/* output file */
			check(2,"s");
			outfile = argv[++i];
			break;
		case 'z':				/* z file */
			check(2,"s");
			zfile = argv[++i];
			break;
		case 'r':				/* recover file */
			if (argv[i][2] == 'o') {		/* +output */
				check(3,"s");
				outfile = argv[i+1];
			} else
				check(2,"s");
			recover = argv[++i];
			break;
		case 't':				/* timer */
			check(2,"i");
			ralrm = atoi(argv[++i]);
			break;
#ifdef  PERSIST
		case 'P':				/* persist file */
			if (argv[i][2] == 'P') {
				check(3,"s");
				persist = PARALLEL;
			} else {
				check(2,"s");
				persist = PERSIST;
			}
			persistfile(argv[++i]);
			break;
#endif
		case 'w':				/* warnings */
			rval = erract[WARNING].pf != NULL;
			check_bool(2,rval);
			if (rval) erract[WARNING].pf = wputs;
			else erract[WARNING].pf = NULL;
			break;
		case 'e':				/* error file */
			check(2,"s");
			errfile = argv[++i];
			break;
		default:
			goto badopt;
		}
	}
	err = setview(&ourview);	/* set viewing parameters */
	if (err != NULL)
		error(USER, err);
					/* initialize object types */
	initotypes();
					/* initialize urand */
	if (rand_samp) {
		srandom((long)time(0));
		initurand(0);
	} else {
		srandom(0L);
		initurand(2048);
	}
					/* set up signal handling */
	sigdie(SIGINT, "Interrupt");
#ifdef SIGHUP
	sigdie(SIGHUP, "Hangup");
#endif
	sigdie(SIGTERM, "Terminate");
#ifdef SIGPIPE
	sigdie(SIGPIPE, "Broken pipe");
#endif
#ifdef SIGALRM
	sigdie(SIGALRM, "Alarm clock");
#endif
#ifdef	SIGXCPU
	sigdie(SIGXCPU, "CPU limit exceeded");
	sigdie(SIGXFSZ, "File size exceeded");
#endif
					/* open error file */
	if (errfile != NULL) {
		if (freopen(errfile, "a", stderr) == NULL)
			quit(2);
		fprintf(stderr, "**************\n*** PID %5d: ",
				getpid());
		printargs(argc, argv, stderr);
		putc('\n', stderr);
		fflush(stderr);
	}
#ifdef	NICE
	nice(NICE);			/* lower priority */
#endif
					/* get octree */
	if (i == argc)
		octname = NULL;
	else if (i == argc-1)
		octname = argv[i];
	else
		goto badopt;
	if (seqstart > 0 && octname == NULL)
		error(USER, "missing octree argument");
					/* set up output */
#ifdef  PERSIST
	if (persist) {
		if (recover != NULL)
			error(USER, "persist option used with recover file");
		if (seqstart <= 0)
			error(USER, "persist option only for sequences");
		if (outfile == NULL)
		duped1 = dup(fileno(stdout));	/* don't lose our output */
		openheader();
	} else
#endif
	if (outfile != NULL)
		openheader();
#if defined(_WIN32) || defined(_WIN64)
	SET_FILE_BINARY(stdout);
	if (octname == NULL)
		SET_FILE_BINARY(stdin);
#endif
	readoct(octname, loadflags, &thescene, NULL);
	nsceneobjs = nobjects;

	if (loadflags & IO_INFO) {	/* print header */
		printargs(i, argv, stdout);
		printf("SOFTWARE= %s\n", VersionID);
	}
	          
	ray_init_pmap();     /* PMAP: set up & load photon maps */

	marksources();			/* find and mark sources */

	setambient();			/* initialize ambient calculation */
	
#ifdef  PERSIST
	if (persist) {
		fflush(stdout);
		if (outfile == NULL) {		/* reconnect stdout */
			dup2(duped1, fileno(stdout));
			close(duped1);
		}
		if (persist == PARALLEL) {	/* multiprocessing */
			preload_objs();		/* preload scene */
			shm_boundary = (char *)malloc(16);
			strcpy(shm_boundary, "SHM_BOUNDARY");
			while ((rval=fork()) == 0) {	/* keep on forkin' */
				pflock(1);
				pfhold();
				tstart = time((time_t *)NULL);
				ambsync();		/* load new values */
			}
			if (rval < 0)
				error(SYSTEM, "cannot fork child for persist function");
			pfdetach();		/* parent will run then exit */
		}
	}
runagain:
	if (persist) {
		if (outfile == NULL)			/* if out to stdout */
			dupheader();			/* send header */
		else					/* if out to file */
			duped1 = dup(fileno(stdout));	/* hang onto pipe */
	}
#endif
					/* batch render picture(s) */
	rpict(seqstart, outfile, zfile, recover);
					/* flush ambient file */
	ambsync();
#ifdef  PERSIST
	if (persist == PERSIST) {	/* first run-through */
		if ((rval=fork()) == 0) {	/* child loops until killed */
			pflock(1);
			persist = PCHILD;
		} else {			/* original process exits */
			if (rval < 0)
				error(SYSTEM, "cannot fork child for persist function");
			pfdetach();		/* parent exits */
		}
	}
	if (persist == PCHILD) {	/* wait for a signal then go again */
		if (outfile != NULL)
			close(duped1);		/* release output handle */
		pfhold();
		tstart = time((time_t *)NULL);	/* reinitialize */
		raynum = nrays = 0;
		goto runagain;
	}
#endif


	ray_done_pmap();           /* PMAP: free photon maps */
	
	quit(0);

badopt:
	sprintf(errmsg, "command line error at '%s'", argv[i]);
	error(USER, errmsg);
	return 1; /* pro forma return */

#undef	check
#undef	check_bool
}