예제 #1
0
void ResourceManager::_findDataPaths() {
    mDataPathsSearched = true;

    // check recursively upwards
    QDir dir(QCoreApplication::applicationDirPath());

    while(!dir.isRoot()) {
        QDir data(dir.absolutePath() + "/data");
        if(data.exists()) {
            addDataPath(data.absolutePath());
            break;
        }
        dir.cdUp();
    }

    // check compiled-in path (DT_DATA_PATH)
#ifdef DT_DATA_PATH
    QDir data_path(DT_DATA_PATH);
    if(data_path.exists()) {
        AddDataPath(data_path.absolutePath());
    } else {
        Logger::Get().Error("Compiled-in data path <" + DT_DATA_PATH + "> not found.");
    }
#else
    // warn if we also did not find one previously
    if(dir.isRoot()) {
        // did not find the data path
        Logger::get().warning("No relative data path found.");
    }
#endif
}
예제 #2
0
static void init_valid_table(void)
{
	if (valid_table) {
		return;
	}

	valid_table = (uint8 *)map_file(data_path(talloc_tos(), "valid.dat"), 0x10000);
	if (!valid_table) {
		smb_panic("Could not load valid.dat file required for mangle method=hash");
		return;
	}
}
예제 #3
0
파일: main.cpp 프로젝트: dtbinh/crapengine
int main( void )
{

#ifndef CRAP_NO_DEBUG

#ifdef CRAP_COMPILER_MSVC
	crap::string256 data_path("../../../data/");
#else
	crap::string256 data_path("../data/");
#endif //CRAP_COMPILER_MSVC

#else
	crap::string256 data_path("./");
#endif //CRAP_NO_DEBUG

	crap::Game game(10, data_path + "TestGame/");
	game.start();


	return 0;
}
예제 #4
0
파일: physics.c 프로젝트: andi2/cgame
void physics_init()
{
    /* init pools, maps */
    pool = entitypool_new(PhysicsInfo);
    debug_draw_map = entitymap_new(false);

    /* init cpSpace */
    space = cpSpaceNew();
    cpSpaceSetGravity(space, cpv(0, -9.8));

    /* init draw stuff */
    program = gfx_create_program(data_path("phypoly.vert"),
                                 NULL,
                                 data_path("phypoly.frag"));
    glUseProgram(program);
    glGenVertexArrays(1, &vao);
    glBindVertexArray(vao);
    glGenBuffers(1, &vbo);
    glBindBuffer(GL_ARRAY_BUFFER, vbo);
    gfx_bind_vertex_attrib(program, GL_FLOAT, 2, "position", Vec2, x);
}
예제 #5
0
void init_valid_table(void)
{
	static int mapped_file;
	int i;
	const char *allowed = ".!#$%&'()_-@^`~";
	uint8 *valid_file;

	if (mapped_file) {
		/* Can't unmap files, so stick with what we have */
		return;
	}

	valid_file = (uint8 *)map_file(data_path("valid.dat"), 0x10000);
	if (valid_file) {
		valid_table = valid_file;
		mapped_file = 1;
		valid_table_use_unmap = True;
		return;
	}

	/* Otherwise, we're using a dynamically created valid_table.
	 * It might need to be regenerated if the code page changed.
	 * We know that we're not using a mapped file, so we can
	 * free() the old one. */
	SAFE_FREE(valid_table);

	/* use free rather than unmap */
	valid_table_use_unmap = False;

	DEBUG(2,("creating default valid table\n"));
	valid_table = (uint8 *)SMB_MALLOC(0x10000);
	SMB_ASSERT(valid_table != NULL);
	for (i=0;i<128;i++) {
		valid_table[i] = isalnum(i) || strchr(allowed,i);
	}

	lazy_initialize_conv();

	for (;i<0x10000;i++) {
		smb_ucs2_t c;
		SSVAL(&c, 0, i);
		valid_table[i] = check_dos_char_slowly(c);
	}
}
예제 #6
0
vector<WorkUnit> WorkUnit::available_wus() {
    fs::path data_path(_data_dir);
    std::vector<WorkUnit> wus;

    if (fs::exists(data_path)) {
        if (fs::is_directory(data_path)) {
            for (auto p = fs::directory_iterator(data_path); p != fs::directory_iterator(); ++p) {
                if (fs::is_directory(p->path())) {
                    WorkUnit wu(p->path());
                    wus.push_back(wu);
                }
            }
        } else
            throw std::runtime_error(boost::str(boost::format("%1% exists, but is not a directory.") % data_path));
    } else
        throw std::runtime_error(boost::str(boost::format("%1% does not exist.") % data_path));

    return wus;

}
예제 #7
0
bool Presentation::_loadPresentationBindings(AV_View * pView)
{
  EV_EditMethodContainer * pEMC = m_pApp->getEditMethodContainer();
  g_return_val_if_fail (pEMC != 0, FALSE);
  if(m_pApp->getBindingMap("Presentation") != NULL)
  {
      return true;
  }
  // get the path where our app data is located
  XAP_App * pApp = static_cast<XAP_App*>(XAP_App::getApp());
  UT_String data_path( pApp->getAbiSuiteLibDir() );
  data_path += G_DIR_SEPARATOR;
  data_path += "Presentation.xml";

  EV_EditMethod * pLoadB = pEMC->findEditMethodByName ("com.abisource.abiword.loadbindings.fromURI");
  g_return_val_if_fail (pLoadB != 0, false);
  EV_EditMethodCallData calldata(data_path.c_str(),data_path.size());
  calldata.m_xPos = 0;
  calldata.m_yPos = 0;
  return (pLoadB->Fn(pView,&calldata) ? TRUE : FALSE);
}
예제 #8
0
파일: lang_tdb.c 프로젝트: AIdrifter/samba
/* initialise the message translation subsystem. If the "lang" argument
   is NULL then get the language from the normal environment variables */
bool lang_tdb_init(const char *lang)
{
	char *path = NULL;
	char *msg_path = NULL;
	struct stat st;
	static int initialised;
	time_t loadtime;
	bool result = False;

	/* we only want to init once per process, unless given
	   an override */
	if (initialised && !lang) 
		return True;

	if (initialised) {
		/* we are re-initialising, free up any old init */
		if (tdb) {
			tdb_close(tdb);
			tdb = NULL;
		}
		SAFE_FREE(current_lang);
	}

	initialised = 1;

	if (!lang) {
		/* no lang given, use environment */
		lang = get_lang();
	}

	/* if no lang then we don't translate */
	if (!lang) 
		return True;

	if (asprintf(&msg_path, "%s.msg",
		     data_path(talloc_tos(), (const char *)lang)) == -1) {
		DEBUG(0, ("asprintf failed\n"));
		goto done;
	}
	if (stat(msg_path, &st) != 0) {
		/* the msg file isn't available */
		DEBUG(10, ("lang_tdb_init: %s: %s\n", msg_path, 
			   strerror(errno)));
		goto done;
	}
	
	if (asprintf(&path, "%s%s.tdb", lock_path("lang_"), lang) == -1) {
		DEBUG(0, ("asprintf failed\n"));
		goto done;
	}

	DEBUG(10, ("lang_tdb_init: loading %s\n", path));

	tdb = tdb_open_log(path, 0, TDB_DEFAULT, O_RDWR|O_CREAT, 0644);
	if (!tdb) {
		tdb = tdb_open_log(path, 0, TDB_DEFAULT, O_RDONLY, 0);
		if (!tdb) {
			DEBUG(10, ("lang_tdb_init: %s: %s\n", path,
				   strerror(errno)));
			goto done;
		}
		current_lang = SMB_STRDUP(lang);
		result = True;
		goto done;
	}

	loadtime = tdb_fetch_int32(tdb, "/LOADTIME/");

	if (loadtime == -1 || loadtime < st.st_mtime) {
		load_msg(msg_path);
		tdb_store_int32(tdb, "/LOADTIME/", (int)time(NULL));
	}

	current_lang = SMB_STRDUP(lang);
	result = True;

 done:
	SAFE_FREE(msg_path);
	SAFE_FREE(path);

	return result;
}
예제 #9
0
void actuarial_table::parse_table()
{
    LMI_ASSERT(-1 == table_type_    );
    LMI_ASSERT(-1 == min_age_       );
    LMI_ASSERT(-1 == max_age_       );
    LMI_ASSERT(-1 == select_period_ );
    LMI_ASSERT(-1 == max_select_age_);

    fs::path data_path(filename_);
    data_path = fs::change_extension(data_path, ".dat");
    fs::ifstream data_ifs(data_path, ios_in_binary());
    if(!data_ifs)
        {
        fatal_error()
            << "File '"
            << data_path
            << "' is required but could not be found. Try reinstalling."
            << LMI_FLUSH
            ;
        }

    data_ifs.seekg(table_offset_, std::ios::beg);
    LMI_ASSERT(table_offset_ == data_ifs.tellg());

    while(data_ifs)
        {
        boost::int16_t record_type;
        read_datum(data_ifs, record_type, sizeof(boost::int16_t));

        soa_table_length_type nominal_length;
        read_datum(data_ifs, nominal_length, sizeof(boost::int16_t));

        switch(record_type)
            {
            case 2: // 4-byte integer: Table number.
                {
                boost::int32_t z;
                read_datum(data_ifs, z, nominal_length);
                LMI_ASSERT(z == table_number_);
                }
                break;
            case 3: // [unsigned] char: Table type.
                {
                // Meaning: {A, D, S} --> {age, duration, select}.
                // SOA apparently permits upper or lower case.
                LMI_ASSERT(-1 == table_type_);
                unsigned char z;
                read_datum(data_ifs, z, nominal_length);
                z = static_cast<unsigned char>(std::toupper(z));
                LMI_ASSERT('A' == z || 'D' == z || 'S' == z);
                table_type_ = z;
                }
                break;
            case 12: // 2-byte integer: Minimum age.
                {
                LMI_ASSERT(-1 == min_age_);
                boost::int16_t z;
                read_datum(data_ifs, z, nominal_length);
                LMI_ASSERT(0 <= z && z <= methuselah);
                min_age_ = z;
                }
                break;
            case 13: // 2-byte integer: Maximum age.
                {
                LMI_ASSERT(-1 == max_age_);
                boost::int16_t z;
                read_datum(data_ifs, z, nominal_length);
                LMI_ASSERT(0 <= z && z <= methuselah);
                max_age_ = z;
                }
                break;
            case 14: // 2-byte integer: Select period.
                {
                LMI_ASSERT(-1 == select_period_);
                boost::int16_t z;
                read_datum(data_ifs, z, nominal_length);
                LMI_ASSERT(0 <= z && z <= methuselah);
                select_period_ = z;
                }
                break;
            case 15: // 2-byte integer: Maximum select age.
                {
                LMI_ASSERT(-1 == max_select_age_);
                boost::int16_t z;
                read_datum(data_ifs, z, nominal_length);
                LMI_ASSERT(0 <= z && z <= methuselah);
                max_select_age_ = z;
                }
                break;
            case 17: // 8-byte doubles: Table values.
                {
                read_values(data_ifs, nominal_length);
                }
                break;
            case 9999: // End of table.
                {
                goto done;
                }
            default:
                {
                char skipped[65536];
                data_ifs.read(skipped, nominal_length);
                }
            }
        }

  done:
    LMI_ASSERT(-1 != table_type_    );
    LMI_ASSERT(-1 != min_age_       );
    LMI_ASSERT(-1 != max_age_       );
    LMI_ASSERT(-1 != select_period_ );
    LMI_ASSERT(-1 != max_select_age_);
}
예제 #10
0
void engine::load_ico(const char* ico) {
	SDL_WM_SetIcon(IMG_Load(data_path(ico)), NULL);
}
예제 #11
0
/*! there is no function currently
 */
engine::engine(const char* datapath) {
	engine::datapath = datapath;
	cursor_visible = true;
	fps_limit = 10;
	flags = 0;
	position = NULL;
	rotation = NULL;
	screen = NULL;
	key_repeat = 200;
	width = 640;
	height = 480;
	depth = 16;
	zbuffer = 16;
	stencil = 8;
	fullscreen = false;
	shadow_type = 0;
	filtering = 0;
	hdr = false;
	hdr_rgba16 = true;

	m = new msg();
	f = new file_io(m);
	c = new core(m, f);
	x = new xml(m);
	e = new event(datapath, m, x);
	g = new gfx();
	t = new texman(m, f);
	l = new lua(m);
	gf = new gui_font(m);

	server = new server_data();
	client = new client_data();

	// load config
	if(!x->open(data_path("config.xml"))) {
		m->print(msg::MERROR, "engine.cpp", "engine(): couldn't open config file - using standard settings!");
	}
	else {
		while(x->process()) {
			if(strcmp(x->get_node_name(), "screen") == 0) {
				if(x->get_attribute((char*)(char*)"width") != NULL) {
					width = (unsigned int)atoi(x->get_attribute((char*)"width"));
				}

				if(x->get_attribute((char*)"height") != NULL) {
					height = (unsigned int)atoi(x->get_attribute((char*)"height"));
				}

				if(x->get_attribute((char*)"depth") != NULL) {
					depth = (unsigned int)atoi(x->get_attribute((char*)"depth"));
				}

				if(x->get_attribute((char*)"zbuffer") != NULL) {
					zbuffer = (unsigned int)atoi(x->get_attribute((char*)"zbuffer"));
				}

				if(x->get_attribute((char*)"stencil") != NULL) {
					stencil = (unsigned int)atoi(x->get_attribute((char*)"stencil"));
				}

				if(x->get_attribute((char*)"fullscreen") != NULL) {
					if(atoi(x->get_attribute((char*)"fullscreen")) != 0) {
						engine::fullscreen = true;
					}
				}
			}
			else if(strcmp(x->get_node_name(), "gui") == 0) {
				if(x->get_attribute((char*)"color_scheme") != NULL) {
					color_scheme = x->get_attribute((char*)"color_scheme");
				}

				if(x->get_attribute((char*)"shadow_type") != NULL) {
					shadow_type = (unsigned int)atoi(x->get_attribute((char*)"shadow_type"));
				}
			}
			else if(strcmp(x->get_node_name(), "key_repeat") == 0) {
				if(x->get_attribute((char*)"time") != NULL) {
					key_repeat = (unsigned int)atoi(x->get_attribute((char*)"time"));
				}
			}
			else if(strcmp(x->get_node_name(), "sleep") == 0) {
				if(x->get_attribute((char*)"time") != NULL) {
					fps_limit = (unsigned int)atoi(x->get_attribute((char*)"time"));
				}
			}
			else if(strcmp(x->get_node_name(), "thread") == 0) {
				if(x->get_attribute((char*)"count") != NULL) {
					thread_count = (unsigned int)atoi(x->get_attribute((char*)"count"));
					if(thread_count == 0) thread_count = omp_get_max_threads();
				}
			}
			else if(strcmp(x->get_node_name(), "server") == 0) {
				if(x->get_attribute((char*)"port") != NULL) {
					server->port = (unsigned short int)atoi(x->get_attribute((char*)"port"));
				}

				if(x->get_attribute((char*)"max_clients") != NULL) {
					server->max_clients = (unsigned int)atoi(x->get_attribute((char*)"max_clients"));
				}
			}
			else if(strcmp(x->get_node_name(), "client") == 0) {
				if(x->get_attribute((char*)"server") != NULL) {
					client->server_name = x->get_attribute((char*)"server");
				}

				if(x->get_attribute((char*)"port") != NULL) {
					client->port = (unsigned short int)atoi(x->get_attribute((char*)"port"));
				}

				if(x->get_attribute((char*)"lis_port") != NULL) {
					client->lis_port = (unsigned short int)atoi(x->get_attribute((char*)"lis_port"));
				}

				if(x->get_attribute((char*)"name") != NULL) {
					client->client_name = x->get_attribute((char*)"name");
				}
			}
			else if(strcmp(x->get_node_name(), "keyset") == 0) {
				if(x->get_attribute((char*)"set") != NULL) {
					keyset = x->get_attribute((char*)"set");
				}
			}
			else if(strcmp(x->get_node_name(), "graphic") == 0) {
				if(x->get_attribute((char*)"filtering") != NULL) {
					filtering = (unsigned int)atoi(x->get_attribute((char*)"filtering"));
				}

				if(x->get_attribute((char*)"hdr") != NULL) {
					hdr = atoi(x->get_attribute((char*)"hdr")) ? true : false;
				}

				if(x->get_attribute((char*)"hdr_rgba16") != NULL) {
					hdr_rgba16 = atoi(x->get_attribute((char*)"hdr_rgba16")) ? true : false;
				}
			}
		}

		x->close();
	}

	// load keyset
	e->load_keyset((char*)keyset.c_str());
}
예제 #12
0
파일: main.cpp 프로젝트: dtbinh/crapengine
int main( void )
{
	//debug:: lets find the path
#ifdef CRAP_COMPILER_MSVC
	crap::string256 data_path("../../../data/");
#else
	crap::string256 data_path("../data/");
#endif

	//logger
    crap::logger< crap::log_time_time, crap::log_channel_core, crap::log_type_debug, crap::log_target_cout, 512 > unit_logger;

    //system
    crap::System system;

	//lets config
	crap::string256 ini_path = data_path + "configuration.ini";
	crap::Configuration config( 1024*10, 100 );

	config.load( ini_path.c_str() );

	//set config as subsystem
	crap::SubSystem config_sys( "Configuration", &config, &system );

	//taskmanager
	const uint32_t tasksMaxNumber = config.getValue<uint32_t>("TASKS_MAX_NUM");
	const uint32_t tasksDeattachedMaxNumber = config.getValue<uint32_t>("TASKS_DEATTACHED_MAX_NUM");
	crap::TaskManager taskManager( tasksMaxNumber, tasksDeattachedMaxNumber );

	//set TaskManager as Subsystem
	crap::SubSystem tasks_sys( "TaskManager", &taskManager, &system );

	//eventsystem
	const uint32_t eventMaxNumber = config.getValue<uint32_t>("EVENTS_MAX_NUM");
	crap::EventSystem eventSystem( eventMaxNumber );

	//set EventSystem as SubSystem
	crap::SubSystem events_sys( "EventSystem", &eventSystem, &system );

	//resourcemanager
	const uint32_t resoureMemory = config.getValue<uint32_t>("RESOURCE_MEMORY");
	const uint32_t resoureNumber = config.getValue<uint32_t>("RESOURCE_NUMBER");
	const crap::string64 resourceFile = config.getValue<crap::string64>("RESOURCE_FILE");
	const bool resourceXML = config.getValue<uint32_t>("RESOURCE_XML") == 1;

	crap::ResourceManager resourceManager( resoureMemory, resoureNumber, data_path, &system );
	if( resourceXML )
		resourceManager.loadXML( resourceFile );
	else
		resourceManager.loadPackage( resourceFile );

	// set resourcemanager as subsystem
	crap::SubSystem resource_sys( "ResourceManager", &resourceManager, &system );

	//AudioSystem
	const uint32_t audioBufferNumber = config.getValue<uint32_t>("AUDIO_BUFFER_NUM");
	const uint32_t audioSourceNumber = config.getValue<uint32_t>("AUDIO_SOURCE_NUM");
	crap::AudioSystem AudioSystem(audioBufferNumber, audioSourceNumber);

	//set AudioSystem as subsystem
	crap::SubSystem audio_sys( "AudioSystem", &AudioSystem, &system );

	//componentsystem
	const uint32_t componentMemory = config.getValue<uint32_t>("COMPONENT_MEMORY");
	const uint32_t componentMaxNodes = config.getValue<uint32_t>("COMPONENT_MAX_NODES");
	crap::ComponentSystem componentSystem( componentMemory, componentMaxNodes , &system );

	//set componentsystem as subsystem
	crap::SubSystem component_sys( "ComponentSystem", &componentSystem, &system );

	//renderwindow
	const crap::string64 windowName = config.getValue<crap::string64>("RENDER_WINDOW_NAME");
	const uint32_t windowWidth = config.getValue<uint32_t>("RENDER_WINDOW_WIDTH");
	const uint32_t windowHeight = config.getValue<uint32_t>("RENDER_WINDOW_HEIGHT");
	const bool windowFullscreen = config.getValue<uint32_t>("RENDER_WINDOW_FULLSCREEN") == 1;
	const uint32_t windowMaxCallbacks = config.getValue<uint32_t>("RENDER_WINDOW_MAX_CALLBACKS");
	crap::RenderWindow renderWindow( windowMaxCallbacks );
	renderWindow.create( windowName.c_str(), windowWidth, windowHeight, windowFullscreen );

	//renderer
	crap::RenderSystem renderer( &renderWindow );
	renderer.init();

	//set renderer as subsystem
	crap::SubSystem renderer_sys("Renderer", &renderer, &system );

	//inputmanager
	const uint32_t inputMemory = config.getValue<uint32_t>("INPUT_MEMORY");
	crap::InputManager inputManager( inputMemory, renderWindow.getHandle() );

	//add keyboard
	crap::KeyboardInput keyboardInput("Keyboard", 20, &inputManager );
	keyboardInput.addListener<&exitFunc>( thekey, 0, true );

	//add mouse
	crap::MouseInput mouseInput("Mouse", 20, 20, 20, 20, &inputManager );
	mouseInput.addButtonListener<&clickFunc>( 0, 0, true );
	mouseInput.addPositionListener<&posFunc>( true );
	mouseInput.addScrollListener<&scrollFunc>( true );
	mouseInput.addEnterListener<&enterFunc>( true );

	//controller
	crap::ControllerInput controllerInput("Controller", 8, &inputManager );
	uint32_t joyID = controllerInput.leaseJoystickID();
	controllerInput.addAxisListener<&joyAxis>( joyID );
	controllerInput.addButtonListener<&joyButton>( joyID );

	/* Add directory update to taskmanager */
	taskManager.addTask<crap::InputManager, &crap::InputManager::update>("InputPolling", &inputManager, 50, true, false );

	/* Physic system 2D */
	crap::PhysicSystem2D physicSystem2D( 1000, 0.f, 10.f, 8, 2, 1.f/200.f );
	crap::SubSystem physic_sys2d( "PhysicSystem2D", &physicSystem2D, &system );

	taskManager.addTask< crap::PhysicSystem2D, &crap::PhysicSystem2D::update>( "Physic2DUpdate", &physicSystem2D, 20, true, false );

	//pluginmanager
	const uint32_t pluginNumber = config.getValue<uint32_t>("PLUGIN_NUMBER");
	const uint32_t pluginMemory = config.getValue<uint32_t>("PLUGIN_MEMORY");
	crap::PluginManager pluginManager(pluginNumber, pluginMemory, &system );

	//set pluginmanager as subsystem
	crap::SubSystem plugin_sys( "PluginManager", &pluginManager, &system );

	//set Directory listener
	const uint32_t pluginFunctionNumber = config.getValue<uint32_t>("PLUGIN_FUNCTION_NUM");
	const uint32_t pluginFileNumber = config.getValue<uint32_t>("PLUGIN_FILES_NUM");
	const crap::string256 pluginDir = data_path + config.getValue<crap::string64>("PLUGIN_SUBDIRECTORY");
	crap::DirectoryListener pluginDirectoryListener( pluginFunctionNumber, pluginFileNumber, pluginDir, false );
	pluginDirectoryListener.addCallback<crap::PluginManager, &crap::PluginManager::callbackFunction>( &pluginManager );

	/* Add directory update to taskmanager */
	taskManager.addTask<crap::DirectoryListener, &crap::DirectoryListener::update>("PluginPath", &pluginDirectoryListener, 1000, true, false );

	//init this.. (do that at last)
	pluginDirectoryListener.init();

	crap::Configuration* testconf = system.getSubSystem<crap::Configuration>( "Configuration" );
	if( testconf != 0 )
	{
		std::cout << "I've worked! " << testconf->getValue<crap::string64>("SOUND_VOLUME") << std::endl;
	}

	float32_t zero[3] = {0.f, 0.f, 0.f};
	float32_t one[3] = {1.f, 1.f, 1.f};
	float32_t dir[6] = {0.f, 0.f, 1.f, 0.f, 1.f, 0.f };

	crap::AudioSystem* am = system.getSubSystem<crap::AudioSystem>( "AudioSystem" );

	resourceManager.loadResource( "Nagut" );
	uint32_t sid = am->leaseSource( "Nagut" );

	am->setListenerData( zero, zero, dir );
	am->playSource( sid );

//	while( am->getIsPlaying(sid) )
//		crap::sleep_mil_sec(100);

	crap::log( LOG_CHANNEL_CORE | LOG_TYPE_INFO | LOG_TARGET_COUT, "We're done!" );

	crap::Renderer2D renderer2D( &renderWindow, 10, 10, 100 );
	crap::SubSystem renderer2d_sys( "Renderer2D", &renderer2D, &system );

	crap::Context2D* gc = renderer2D.getContext();
	resourceManager.loadResource( "Hasi" );
	resourceManager.loadResource( "Mieze" );
	uint32_t guiImage = renderer2D.getImage2D("Hasi");
	uint32_t guiImage2 = renderer2D.getImage2D("Mieze");

	resourceManager.loadResource("CalcFont");
	crap::Font2D font2d = renderer2D.getFont2D("CalcFont");

	crap::Node* cnode = componentSystem.createNode();
	crap::Component* trans2d = componentSystem.createComponent("Attributes2D", cnode );
	componentSystem.setComponentMember( trans2d, "posX", "600" );
	componentSystem.setComponentMember( trans2d, "posY", "600" );
	componentSystem.setComponentMember( trans2d, "rotation", "20" );
	componentSystem.setComponentMember( trans2d, "scale", "1.f" );
	trans2d->init( &system );


	crap::color_argb colorf;
	colorf.r = 0;
	colorf.b = 0;
	colorf.g = 255;
	colorf.a = 128;

	crap::color_argb colorb;

	//black
	colorb.r = 0;
	colorb.b = 0;
	colorb.g = 0;
	colorb.a = 255;

	crap::color_argb col = crap::argb::black;

	crap::string64 colstr("AABBCCDD");
	uint32_t lolali = strtol("AABBCCDD", 0, 16 );
	crap::color_argb colorino = crap::convert<crap::string64, crap::color_argb>( colstr );

	crap::string64 popo = crap::convert<crap::color_argb, crap::string64>( crap::argb::orange );

	crap::string64 buff = crap::convert<crap::color_argb, crap::string64>(colorf);
	crap::string64 bufb = crap::convert<crap::color_argb, crap::string64>(colorb);

	crap::Component* circle2d = componentSystem.createComponent("RoundedRectangle2D", cnode );

	componentSystem.setComponentMember( circle2d, "width", "150" );
	componentSystem.setComponentMember( circle2d, "height", "200" );
	componentSystem.setComponentMember( circle2d, "corner", "20" );
	componentSystem.setComponentMember( circle2d, "color", buff );
	componentSystem.setComponentMember( circle2d, "border", "5" );
	componentSystem.setComponentMember( circle2d, "borderColor", bufb );

	circle2d->init(&system);

	crap::Node* tnode = componentSystem.createNode();


	crap::Component* trans2dt = componentSystem.createComponent("Attributes2D", tnode );
	componentSystem.setComponentMember( trans2dt, "posX", "200" );
	componentSystem.setComponentMember( trans2dt, "posY", "600" );
	componentSystem.setComponentMember( trans2dt, "rotation", "0" );
	componentSystem.setComponentMember( trans2dt, "scale", "1.f" );
	trans2d->init( &system );

	crap::Component* text2d = componentSystem.createComponent("Text2D", tnode );
	componentSystem.setComponentMember( text2d, "fontName", "CalcFont" );
	componentSystem.setComponentMember( text2d, "text", "Hallo ich bin ein Test" );
	componentSystem.setComponentMember( text2d, "fontSize", "50" );
	componentSystem.setComponentMember( text2d, "color", bufb );
	componentSystem.setComponentMember( text2d, "blur", "1" );

	text2d->init(&system);

	//physic test
	crap::Node* pnode = componentSystem.createNode();
	crap::Component* ptrans2d = componentSystem.createComponent("Attributes2D", pnode );
	componentSystem.setComponentMember( ptrans2d, "posX", "770" );
	componentSystem.setComponentMember( ptrans2d, "posY", "550" );
	componentSystem.setComponentMember( ptrans2d, "rotation", "-0.3f" );
	componentSystem.setComponentMember( ptrans2d, "scale", "1.f" );

	crap::Component* rect2d = componentSystem.createComponent("Rectangle2D", pnode );
	componentSystem.setComponentMember( rect2d, "width", "300" );
	componentSystem.setComponentMember( rect2d, "height", "50" );
	componentSystem.setComponentMember( rect2d, "color", buff );
	componentSystem.setComponentMember( rect2d, "border", "0" );
	componentSystem.setComponentMember( rect2d, "borderColor", bufb );

	crap::Component* phys2d = componentSystem.createComponent("Rectangle2DPhysic", pnode );
	componentSystem.setComponentMember( phys2d, "width", "300" );
	componentSystem.setComponentMember( phys2d, "height", "50" );
	componentSystem.setComponentMember( phys2d, "density", "1.f" );
	componentSystem.setComponentMember( phys2d, "friction", "1.f" );
	componentSystem.setComponentMember( phys2d, "dynamic", "0" );

	ptrans2d->init(&system);
	rect2d->init(&system);
	phys2d->init(&system);

	//solid
	crap::Node* pnode2 = componentSystem.createNode();
	crap::Component* ptrans2d2 = componentSystem.createComponent("Attributes2D", pnode2 );
	componentSystem.setComponentMember( ptrans2d2, "posX", "550" );
	componentSystem.setComponentMember( ptrans2d2, "posY", "400" );
	componentSystem.setComponentMember( ptrans2d2, "rotation", "0.2" );
	componentSystem.setComponentMember( ptrans2d2, "scale", "1.f" );

	crap::Component* rect2d2 = componentSystem.createComponent("Rectangle2D", pnode2 );
	componentSystem.setComponentMember( rect2d2, "width", "300" );
	componentSystem.setComponentMember( rect2d2, "height", "50" );
	componentSystem.setComponentMember( rect2d2, "color", bufb );
	componentSystem.setComponentMember( rect2d2, "border", "0" );
	componentSystem.setComponentMember( rect2d2, "borderColor", bufb );

	crap::Component* phys2d2 = componentSystem.createComponent("Rectangle2DPhysic", pnode2 );
	componentSystem.setComponentMember( phys2d2, "width", "300" );
	componentSystem.setComponentMember( phys2d2, "height", "50" );
	componentSystem.setComponentMember( phys2d2, "density", "1.f" );
	componentSystem.setComponentMember( phys2d2, "friction", "1.f" );
	componentSystem.setComponentMember( phys2d2, "dynamic", "0" );

	ptrans2d2->init(&system);
	rect2d2->init(&system);
	phys2d2->init(&system);

	//circle
	crap::Node* pnode3 = componentSystem.createNode();
	crap::Component* ptrans2d3 = componentSystem.createComponent("Attributes2D", pnode3 );
	componentSystem.setComponentMember( ptrans2d3, "posX", "600" );
	componentSystem.setComponentMember( ptrans2d3, "posY", "50" );
	componentSystem.setComponentMember( ptrans2d3, "rotation", "0" );
	componentSystem.setComponentMember( ptrans2d3, "scale", "1.f" );

	crap::Component* rect2d3 = componentSystem.createComponent("Circle2D", pnode3 );
	componentSystem.setComponentMember( rect2d3, "radius", "20" );
	componentSystem.setComponentMember( rect2d3, "color", "FF0080FF" );
	componentSystem.setComponentMember( rect2d3, "border", "0" );
	componentSystem.setComponentMember( rect2d3, "borderColor", "FF0000F" );

	crap::Component* phys2d3 = componentSystem.createComponent("Cirlce2DPhysic", pnode3 );
	componentSystem.setComponentMember( phys2d3, "radius", "20" );
	componentSystem.setComponentMember( phys2d3, "density", "1.f" );
	componentSystem.setComponentMember( phys2d3, "friction", "1.f" );
	componentSystem.setComponentMember( phys2d3, "dynamic", "1" );

	ptrans2d3->init(&system);
	rect2d3->init(&system);
	phys2d3->init(&system);

	crap::color_argb bord;
	bord.value = 0;
	float32_t rot = 0.f;
	while( running && !renderWindow.shouldClose() )
	{
		renderer.drawBegin();
		renderer2D.drawBegin();
//		crap::drawColoredRectangle( gc, 100.f, 100.f, 100.f, 100.f, -rot*0.1, 255, 0, 255, 255 );
//		//crap::drawColoredCircle( gc, 500.f, (int32_t)(rot*100) % renderWindow.getHeight(), 50.f, 255, 0, 0, 255 );
//		rot += 0.1f;
//		crap::drawColoredRoundedRectangle( gc, 150.f, 150.f, 200.f, 200.f, rot, 0, 0, 255, 128, 20.f );
//
//		crap::drawColorTriangle( gc, 400, 400, 140, 100, 0.f, 0, 255, 0, 255 );
//
//		crap::drawImageRectangle( gc, (int32_t)(rot*10) % renderWindow.getWidth(), 400, 100, 100, rot*0.1, guiImage, 100.f, 100.f, 0.f, 0.f, 0.f, 1.f );
//
//		crap::drawImageCircle( gc, 600, 200, 50, guiImage2, 255, 100.f, 100.f, 0.f, -10,10-rot*2, 0.3f);
//
//		crap::drawText(gc, 400, 400, font2d, "Hallo, du Welt.", 30.f ,0.f , 0, 255, 0, 255, 0, 1, 10.f, crap::align::left);

		bord.value++;
		bord.value %= 100;
		componentSystem.setComponentMember( circle2d, "corner", crap::convert<crap::color_argb, crap::string64>(bord) );
		componentSystem.setComponentMember( text2d, "fontSize", "100" );

		renderer2D.render();

		renderer2D.drawEnd();
		renderer.drawEnd();
		//renderWindow.swap();
		taskManager.update();
	}

	renderer2D.removeImage2D( "Mieze" );
	renderer2D.removeImage2D( "Hasi" );

	renderWindow.destroy();

#ifdef CRAP_COMPILER_MSVC
//    std::cout << "Press a button" << std::endl;
//	getchar();
#endif

	pluginDirectoryListener.removeCallback<crap::PluginManager, &crap::PluginManager::callbackFunction>( &pluginManager );
	pluginManager.unloadAll();

	return 0;
}
int main()
{
	time_t start_time = time(NULL);
	std::string data_path("D:/Zmisc/Github/NLP/Naive-Bayes-Document-Classifier-master/trial/reuters_modified/"); //change this path according to your local data path
	std::ifstream file_cate((data_path+std::string("cats.txt")).c_str());
	//if file can't be opened, we exit
	if(!file_cate.good())
	{
		std::cerr << "Can't open cats.txt to read.\n";
		//exit(1); which is the same as 
		return EXIT_FAILURE;
	}
	
	
	std::string line;
	std::string token;
	std::string word1;
	std::string word2;
	std::string file_name;
	std::string min_cat;
	std::string train("training");
	std::string tes("test");
	
	//using the tree map implementation with O(log n) time for insertion, search, deletion etc 
	//because there are no hash table implementations in c++ stl
	
	std::map<std::string,std::string > test_map; //test file to category map
	std::map<std::string,std::string > train_map; //train file to category map
	std::map<std::string,std::string >::iterator fi_itr;
	std::map<std::string,std::string >::const_iterator cfi_itr;
	
	std::map<std::string,int > cate_num_docs_map;
	std::map<std::string,int > cate_num_docs_test_map;
	std::map<std::string,int >::iterator itr;
	std::map<std::string,int >::const_iterator citr;
	
	std::set<std::string> words_set; 
	std::set<std::string>::iterator set_itr;
	std::set<std::string>::const_iterator cset_itr;
	
	
	std::map<std::string, std::map<std::string,unsigned int> > word_cates_num_map;
	std::map<std::string, std::map<std::string,unsigned int> >::iterator big_itr;
	std::map<std::string, std::map<std::string,unsigned int> >::const_iterator cbig_itr;
	std::map<std::string,unsigned int>::iterator small_itr;
	std::map<std::string,unsigned int>::const_iterator csmall_itr;
//Create a map with a word as the key and a map as the value
// in the inner map the category as key and number of documents in that category where it occurs as value
	
	std::map<std::string, std::vector<unsigned int> > cates_results;
	std::map<std::string, std::vector<unsigned int> >::iterator res_itr;
	std::map<std::string, std::vector<unsigned int> >::const_iterator cres_itr;

	
	unsigned int len_train;
	unsigned int counter;
	unsigned int error_counter;
	unsigned int len_test;
	int nct;
	double time_diff;
	double minimum_neg_log_prob;
	double neg_log_prob;
	double ratio;
	
	
	
	
	//Format of each line of categs file - filename cate1 cate 2(if any) cate3(if any)
	while(getline(file_cate,line))
	{
		counter = 0;
		std::istringstream iss(line);
		while(iss >> token)
		{
			++counter;
			if(counter==1)
				word1 = token;
			else if(counter==2)
				word2 = token;
		}
			
		if(counter>2) //we only consider files which are in 1 category
			continue;
			
		if(word1.compare(0,4,tes)==0)
		{
			file_name = word1.substr(5);
			test_map[file_name] = word2;
			++cate_num_docs_test_map[word2];
		}
			
		
		
		else if(word1.compare(0,8,train)==0)
		{
			file_name = word1.substr(9);
			train_map[file_name] = word2;
			++cate_num_docs_map[word2];
		}

	}
	
	file_cate.close();
	
	
	
	//Removing categories with less than 21 files in either the training set or test set
	prune_rare_categories(cate_num_docs_map,cate_num_docs_test_map);
	
	
	for(cfi_itr = train_map.begin();cfi_itr!=train_map.end();++cfi_itr)
	{
		itr = cate_num_docs_map.find(cfi_itr->second);
		
		//File belongs to a low category
		if(itr==cate_num_docs_map.end())
			continue;
	
		file_name = data_path+std::string("training/")+cfi_itr->first;
		std::ifstream file_obj(file_name.c_str());
		//if file can't be opened, we exit
		if(!file_obj.good())
		{
			std::cerr << "Can't open training file to read.\n";
			//exit(1); which is the same as 
			return EXIT_FAILURE;
		}
		
		words_set.clear();
		while(file_obj >> token)
			words_set.insert(token);
		
		for(cset_itr = words_set.begin();cset_itr!=words_set.end();++cset_itr)
		{
			big_itr = word_cates_num_map.find(*cset_itr);	
			++word_cates_num_map[*cset_itr][cfi_itr->second];
		}
		file_obj.close();
		++len_train;
	}
	
	time_diff = difftime(time(NULL),start_time);
	std::cout << "The Classifier is trained and it took "<< time_diff << " seconds.\n" ;

	start_time = time(NULL);
	
	//Initialize cates_results
	for(citr=cate_num_docs_map.begin();citr!=cate_num_docs_map.end();++citr)		
	{
		cates_results[citr->first].push_back(0);
		cates_results[citr->first].push_back(0);
		cates_results[citr->first].push_back(0);
		cates_results[citr->first].push_back(0);
	}
	
	for(cfi_itr = test_map.begin();cfi_itr!=test_map.end();++cfi_itr)
	{
		itr = cate_num_docs_map.find(cfi_itr->second);
		
		//File belongs to a low category
		if(itr==cate_num_docs_map.end())
			continue;
		
		
		file_name = data_path+std::string("test/")+cfi_itr->first;
		std::ifstream file_obj(file_name.c_str());
		//if file can't be opened, we exit
		if(!file_obj.good())
		{
			std::cerr << "Can't open test file to read.\n";
			//exit(1); which is the same as 
			return EXIT_FAILURE;
		}
		
		words_set.clear();
		while(file_obj >> token)
			words_set.insert(token);
	
		minimum_neg_log_prob=1000000000;
		min_cat = "";
	
		for(citr=cate_num_docs_map.begin();citr!=cate_num_docs_map.end();++citr)		
		{
			neg_log_prob = -log(citr->second/(len_train*1.0));
			for(cbig_itr = word_cates_num_map.begin(); cbig_itr!=word_cates_num_map.end();++cbig_itr)
			{
				set_itr = words_set.find(cbig_itr->first);
				nct = word_cates_num_map[cbig_itr->first][citr->first];
				ratio = (nct+1)/(citr->second+2.0);
				if(set_itr!=words_set.end())
					neg_log_prob-= log(ratio);
				else
					neg_log_prob-=log(1-ratio);
			}
		
			if(minimum_neg_log_prob>neg_log_prob)
			{
				min_cat = citr->first;
				minimum_neg_log_prob = neg_log_prob;
			}
		}
		file_obj.close();
		++len_test;
		
		if(min_cat!=cfi_itr->second)
			++error_counter;
		
		for(cres_itr = cates_results.begin();cres_itr!=cates_results.end();++cres_itr)
		{
			word2 = cres_itr->first;
			if(word2==min_cat)
			{
				if(word2==cfi_itr->second)
					++cates_results[word2][0];
				else
					++cates_results[word2][1];
			}
			else
			{
				if(word2==cfi_itr->second)
					++cates_results[word2][2];
				else
					++cates_results[word2][3];
			}
		}
	}

	std::cout << "The fraction of errors is " << error_counter/(len_test*1.0) << "\n";
	
	//Evaluation by finer measures
	f_measure(cates_results);
	
	time_diff = difftime(time(NULL),start_time);
	std::cout << "The Classifier has run and it took "<< time_diff << " seconds.\n" ;	
	return 0;
}
예제 #14
0
void load_case_tables(void)
{
	char *old_locale = NULL, *saved_locale = NULL;
	int i;
	TALLOC_CTX *frame = NULL;

	if (initialized) {
		return;
	}
	initialized = true;

	frame = talloc_stackframe();

	upcase_table = (smb_ucs2_t *)map_file(data_path("upcase.dat"),
					      0x20000);
	upcase_table_use_unmap = ( upcase_table != NULL );

	lowcase_table = (smb_ucs2_t *)map_file(data_path("lowcase.dat"),
					       0x20000);
	lowcase_table_use_unmap = ( lowcase_table != NULL );

#ifdef HAVE_SETLOCALE
	/* Get the name of the current locale.  */
	old_locale = setlocale(LC_ALL, NULL);

	if (old_locale) {
		/* Save it as it is in static storage. */
		saved_locale = SMB_STRDUP(old_locale);
	}

	/* We set back the locale to C to get ASCII-compatible toupper/lower functions. */
	setlocale(LC_ALL, "C");
#endif

	/* we would like Samba to limp along even if these tables are
	   not available */
	if (!upcase_table) {
		DEBUG(1,("creating lame upcase table\n"));
		upcase_table = (smb_ucs2_t *)SMB_MALLOC(0x20000);
		for (i=0;i<0x10000;i++) {
			smb_ucs2_t v;
			SSVAL(&v, 0, i);
			upcase_table[v] = i;
		}
		for (i=0;i<256;i++) {
			smb_ucs2_t v;
			SSVAL(&v, 0, UCS2_CHAR(i));
			upcase_table[v] = UCS2_CHAR(islower(i)?toupper(i):i);
		}
	}

	if (!lowcase_table) {
		DEBUG(1,("creating lame lowcase table\n"));
		lowcase_table = (smb_ucs2_t *)SMB_MALLOC(0x20000);
		for (i=0;i<0x10000;i++) {
			smb_ucs2_t v;
			SSVAL(&v, 0, i);
			lowcase_table[v] = i;
		}
		for (i=0;i<256;i++) {
			smb_ucs2_t v;
			SSVAL(&v, 0, UCS2_CHAR(i));
			lowcase_table[v] = UCS2_CHAR(isupper(i)?tolower(i):i);
		}
	}

#ifdef HAVE_SETLOCALE
	/* Restore the old locale. */
	if (saved_locale) {
		setlocale (LC_ALL, saved_locale);
		SAFE_FREE(saved_locale);
	}
#endif
	TALLOC_FREE(frame);
}
예제 #15
0
int main (int argc, char * const * argv)
{
	nano::set_umask ();

	boost::program_options::options_description description ("Command line options");

	// clang-format off
	description.add_options ()
		("help", "Print out options")
		("daemon", "Start RPC daemon")
		("data_path", boost::program_options::value<std::string> (), "Use the supplied path as the data directory")
		("network", boost::program_options::value<std::string> (), "Use the supplied network (live, beta or test)")
		("version", "Prints out version");
	// clang-format on

	boost::program_options::variables_map vm;
	try
	{
		boost::program_options::store (boost::program_options::parse_command_line (argc, argv, description), vm);
	}
	catch (boost::program_options::error const & err)
	{
		std::cerr << err.what () << std::endl;
		return 1;
	}
	boost::program_options::notify (vm);
	int result (0);

	auto network (vm.find ("network"));
	if (network != vm.end ())
	{
		auto err (nano::network_constants::set_active_network (network->second.as<std::string> ()));
		if (err)
		{
			std::cerr << err.get_message () << std::endl;
			std::exit (1);
		}
	}

	auto data_path_it = vm.find ("data_path");
	if (data_path_it == vm.end ())
	{
		std::string error_string;
		if (!nano::migrate_working_path (error_string))
		{
			std::cerr << error_string << std::endl;

			return 1;
		}
	}

	boost::filesystem::path data_path ((data_path_it != vm.end ()) ? data_path_it->second.as<std::string> () : nano::working_path ());
	if (vm.count ("daemon") > 0)
	{
		run (data_path);
	}
	else if (vm.count ("version"))
	{
		if (NANO_VERSION_PATCH == 0)
		{
			std::cout << "Version " << NANO_MAJOR_MINOR_VERSION << std::endl;
		}
		else
		{
			std::cout << "Version " << NANO_MAJOR_MINOR_RC_VERSION << std::endl;
		}
	}
	else
	{
		std::cout << description << std::endl;
		result = -1;
	}

	return 1;
}