Пример #1
0
void		set_tab(char ***map, t_fdf *fdf)
{
	int		i;
	int		j;
	int		len;

	i = -1;
	if (fdf)
	{
		if (!fdf->tab)
			if (!(fdf->tab = (t_coord**)malloc(sizeof(t_coord*)
					* (fdf->tab_h))))
				check_errors(MALLOC, "fdf->tab", "set_tab.c");
		while (*(map + ++i))
		{
			if ((len = line_size(*(map + i))) > fdf->tab_w)
				fdf->tab_w = len;
			*(fdf->tab + i) = (t_coord*)malloc(sizeof(t_coord) * (len + 1));
			if (!(fdf->tab + i))
				check_errors(MALLOC, "fdf->tab + i", "set_tab.c");
			j = -1;
			while (*(*(map + i) + ++j))
				fill_coord(fdf, map[i][j], i, j);
			fdf->tab[i][j].end = 0;
		}
	}
}
void init(int port)
{
    pool = ( memory_pool *) malloc(sizeof(memory_pool));
    init_pool(pool);
    logger_.log("Memory pool is ready");

    server_fd = resolve_name_and_bind(port);

    int return_code = listen (server_fd, MAXCONN);
    check_errors("listen", return_code);

    epoll_fd = epoll_create (1);
    check_errors("epoll_create", epoll_fd);

    modify_epoll_context(epoll_fd, EPOLL_CTL_ADD, server_fd, EPOLLIN, &server_fd);
    modify_epoll_context(epoll_fd, EPOLL_CTL_MOD, server_fd, EPOLLIN, &server_fd);
    events = (epoll_event *)calloc(MAXEVENTS, sizeof(epoll_event));

    struct sigaction action;
    memset(&action, 0, sizeof(action));
    sigemptyset(&action.sa_mask);
    action.sa_sigaction = &interrupt_handler;
    action.sa_flags = SA_SIGINFO;

    return_code = sigaction(SIGINT, &action, NULL);
    check_errors("sigaction SIGINT", return_code);

    return_code = sigaction(SIGTERM, &action, NULL);
    check_errors("sigaction SIGTERM", return_code);

    logger_.log("Event loop is ready. Waiting for connections on port = %d...", port);
}
static int make_socket_non_blocking (int sfd)
{
    int flags = fcntl (sfd, F_GETFL, 0);
    check_errors("fcntl", flags);

    flags |= O_NONBLOCK;
    int s = fcntl (sfd, F_SETFL, flags);
    check_errors("fcntl", s);
    return 0;
}
Пример #4
0
void message_queue_test_case()
{
	pid_t pid = fork();
	check_errors(pid, "fork");
	if (pid == 0)
	{
		// Writer
		int msgflg = IPC_CREAT | 0666;
		key_t key = 1234;
		static struct message_buf send_data;
		//size_t buf_length;

		int msqid = msgget(key, msgflg);
		check_errors(msqid, "msgget");

		send_data.mtype = 1;

		for (size_t i = 0; i < sizeof(send_data.buffer); i++)
			send_data.buffer[i] = (unsigned char)(i);

		char *current = (char*)send_data.buffer;
		while(current - (char*)send_data.buffer < DATA_SIZE)
		{
			int result = msgsnd(msqid, &current, MSGSIZE + 1, IPC_NOWAIT);
			check_errors(result, "msgsnd");

			current += MSGSIZE;
		}

//		strcpy(send_data.buffer, "Did you get this?");
//		buf_length = strlen(send_data.buffer) + 1 ;

//		int result = msgsnd(msqid, &send_data, buf_length, IPC_NOWAIT);
//		check_errors(result, "msgsnd");

		//printf("Message: \"%s\" Sent\n", send_data.buffer);
		exit(0);
	}
	else
	{
		// Reader
		my_sleep(0 ,10);

		key_t key = 1234;
		static struct message_buf recieved_data;

		int msqid = msgget(key, 0666);
		check_errors(msqid, "msgget");

		int result = msgrcv(msqid, &recieved_data, DATA_SIZE, 1, 0);
		check_errors(result, "msgrcv");

		printf("I recieved: %s\n", recieved_data.buffer);
	}
}
Пример #5
0
Audio::Stream :: Stream(std::string fn):
    m_Filename(fn)
{
    auto l = Audio::lock();
    
    if(Headless::enabled())
        return;
    
    // clear errors
    clear_errors();
    
    int r;
    if((r = ov_fopen((char*)&fn[0], &m_Ogg)) < 0)
        ERROR(READ, Filesystem::getFileName(fn));
    
    if(check_errors())
        ERROR(READ, Filesystem::getFileName(fn));

    m_VorbisInfo = ov_info(&m_Ogg, -1);
    m_VorbisComment = ov_comment(&m_Ogg, -1);
    
    if(check_errors())
        ERROR(READ, Filesystem::getFileName(fn));
 
    if(m_VorbisInfo->channels == 1)
        m_Format = AL_FORMAT_MONO16;
    else
        m_Format = AL_FORMAT_STEREO16;
    
    alGenBuffers(2, m_Buffers);

    if(check_errors())
        ERROR(READ, Filesystem::getFileName(fn));

    flags |= Source::F_LOOP;

    //std::cout
    //    << "version         " << m_VorbisInfo->version         << "\n"
    //    << "channels        " << m_VorbisInfo->channels        << "\n"
    //    << "rate (hz)       " << m_VorbisInfo->rate            << "\n"
    //    << "bitrate upper   " << m_VorbisInfo->bitrate_upper   << "\n"
    //    << "bitrate nominal " << m_VorbisInfo->bitrate_nominal << "\n"
    //    << "bitrate lower   " << m_VorbisInfo->bitrate_lower   << "\n"
    //    << "bitrate window  " << m_VorbisInfo->bitrate_window  << "\n"
    //    << "\n"
    //    << "vendor " << m_VorbisComment->vendor << "\n";
        
    //for(int i = 0; i < m_VorbisComment->comments; i++)
    //    std::cout << "   " << m_VorbisComment->user_comments[i] << "\n";
        
    //std::cout << std::endl;

    m_bOpen = true;
}
Пример #6
0
/*
 * It's important that DATA_SIZE mod CHUNK_SIZE == 0!

 * In C every pointer may be casting on every another pointer
   (but casting function ptr to object ptr is UB). However remember about
   strict aliasing which e.g may breaks quake3 fast square root code:
   http://stackoverflow.com/questions/15818906/does-this-pointer-casting-break-strict-aliasing-rule

 * strange thing because unix_domain_sockets_server (which is child) is killed after parent death
   (shouldn't be orphan and still live?). When server is parent all is OK.
 */
int unix_domain_sockets_server()
{
	int server_socket, client_socket, len;
	struct sockaddr_un local, remote;
	static char buffer[SOCKETS_DATA_SIZE];

	server_socket = socket(AF_UNIX, SOCK_STREAM, 0);
	check_errors(server_socket, "Socket failed");

	local.sun_family = AF_UNIX;
	strcpy(local.sun_path, SOCK_PATH);
	unlink(local.sun_path);
	len = strlen(local.sun_path) + sizeof(local.sun_family);

	int result = bind(server_socket, (struct sockaddr *)&local, len);
	check_errors(result, "Bind failed");

	// mark server_socket to be listening socket. Second argument - 'backlog' =
	// max. number of connections we can accept.
	result = listen(server_socket, 5);
	check_errors(result, "Listen failed");

	for(;;)
	{
		printf("Waiting for a connection\n");
		int remote_address_size = sizeof(remote);
		// waiting for connect() in blocking accept. Accept returns socket per client which represent remote
		// connection endpoint
        client_socket = accept(server_socket, (struct sockaddr *)&remote, (struct socklen_t *)&remote_address_size);
		check_errors(client_socket, "Accept failed");

		printf("Connected with client on socket %d\n", client_socket);
		while (1)
		{
			int read_bytes_number = recv(client_socket, buffer, SOCKETS_CHUNK_SIZE, 0);
			if (read_bytes_number <= 0)
			{
				check_errors(read_bytes_number, "Recv failed");
				break;
			}

			if (send(client_socket, buffer, read_bytes_number, 0) < 0)
			{
				perror("send");
				break;
			}
		}
		close(client_socket);
	}
	return 0;
}
Пример #7
0
/*
 * No bind, listen and accept
 * There is many sockaddr structs which represents address.
   Here sockaddr_un where address is path to file.
 */
int unix_domain_sockets_client()
{
	static unsigned char data_to_send[SOCKETS_DATA_SIZE];
	static unsigned char recieved_data[SOCKETS_DATA_SIZE];

	for (size_t i = 0; i < sizeof(data_to_send); i++)
		data_to_send[i] = (unsigned char)(i);

	struct sockaddr_un remote;

	int socket_fd = socket(AF_UNIX, SOCK_STREAM, 0);
	check_errors(socket_fd, "Socket failed");

	printf("Trying to connect...\n");

	remote.sun_family = AF_UNIX;
	strcpy(remote.sun_path, SOCK_PATH);
	int len = strlen(remote.sun_path) + sizeof(remote.sun_family);

	int result = connect(socket_fd, (struct sockaddr *)&remote, len);
	check_errors(result, "Connect failed");

	printf("Connected with server\n");

	char *current_send = (char *)data_to_send;
	char *current_recieve = (char *)recieved_data;

	while (current_send - (char *)data_to_send < SOCKETS_DATA_SIZE)
	{
		int send_bytes = send(socket_fd, current_send, SOCKETS_CHUNK_SIZE, 0);
		current_send += send_bytes;

		check_errors(send_bytes - SOCKETS_CHUNK_SIZE, "Send too little\n");

		int read_bytes_number = recv(socket_fd, current_recieve, SOCKETS_CHUNK_SIZE, 0);
		current_recieve += read_bytes_number;

		check_errors(read_bytes_number - SOCKETS_CHUNK_SIZE, "Recieved too little\n");
	}

	close(socket_fd);

	if (memcmp(data_to_send, recieved_data, sizeof(recieved_data)) == 0)
		printf("OK. Send and recieved data are the same!\n");
	else
		printf("Error. Send and recieved data are NOT the same!\n");
	return 0;
}
Пример #8
0
static const char *run_case(struct Worker *client, struct Worker *server)
{
	struct event_base *base = NULL;
	int spair[2];
	const char *res = "huh";
	bool done = false;

	ignore_sigpipe();

	base = event_init();
	client->evbase = base;
	server->evbase = base;

	tt_assert(socketpair(AF_UNIX, SOCK_STREAM, 0, spair) == 0);
	tt_assert(socket_setup(spair[0], true));
	tt_assert(socket_setup(spair[1], true));

	str_check(start_worker(client, spair[1]), "OK");
	str_check(start_worker(server, spair[0]), "OK");

	while (client->ctx || server->ctx)
		tt_assert(event_base_loop(base, EVLOOP_ONCE) == 0);

	done = true;
end:
	res = check_errors(client, server);
	free_worker(client);
	free_worker(server);
	event_base_free(base);
	return done ? res : "fail";
}
Пример #9
0
int main(int argc, char* argv[]){
	dim_t order;
	dim_t nA;
	dim_t permutation[FLA_MAX_ORDER];

	FLA_Init();

	//Parse input
	if(parse_input(argc, argv, &order, &nA, permutation) == FLA_FAILURE){
		Usage();
		FLA_Finalize();
		return 0;
	}

	if(check_errors(order, nA, permutation) == FLA_FAILURE){
		Usage();
		FLA_Finalize();
		return 0;
	}

	test_permute_tensor(order, nA, permutation);

	FLA_Finalize();

	return 0;
}
Пример #10
0
/********************************************//**
 *
 * This is the main method which will start the compiler.
 * 1) Check if the file name contains .ps, if not it will exit.
 * 2) Do the first Transition.
 * 3) Do the second transition.
 * 4) Check for errors, if errors exist it will print them and exit the program
 *    before writing the files.
 * 5) Generate the required files.
 *
 ***********************************************/
int main(int argc, char *argv[]) {
	Compiler *compiler = NULL;
	int curFileIdx = 1;

	if (argc == 1) {
		printf("No input files to compile!\n");
		exit(0);
	} else {
		while (--argc) {

			if (is_valid_filename(argv[curFileIdx]) == FALSE)
				exit(0);

			init_compiler(&compiler, BASE_OFFSET, argv[curFileIdx]);
			first_transition(compiler);
			second_transition(compiler);

			if (check_errors(compiler)) {
				//printf("errors\n");
				print_errors(compiler);
				exit(0);
			} else
				generate_files(compiler);

			free(compiler);
			curFileIdx++;
		}
	}

	printf("Compilation finished successfully.\n");
	return 0;
}
Пример #11
0
void				set_lights_tok_tab(t_light_tok **t,
						char **tab, int *index, int len)
{
	int			i;
	char		**tmp;

	i = 0;
	tmp = NULL;
	if (t && tab)
	{
		while (*t)
		{
			if (i < len)
			{
				tmp = ft_strsplit(tab[index[i]], SEP_2);
				if (tmp && tmp[0] && tmp[1])
					set_light_tok_var(*t, tmp[1]);
				else
					check_errors(NUL, "light bad format", tab[index[i]]);
				i++;
				free_tab(&tmp);
			}
			t++;
		}
	}
}
Пример #12
0
END_TEST

START_TEST(test_comps_parse5)
{
    FILE *fp;
    //char *err_log;
    COMPS_Parsed *parsed;
    //COMPS_ListItem *it;
    //int ret
    int i;
    fprintf(stderr, "## Running test_parse5\n\n");
    COMPS_LogEntry* known_errors[2];

    known_errors[0] = __log_entry_x(COMPS_ERR_TEXT_BETWEEN, 3,
                                    comps_str("some stray"), comps_num(6),
                                    comps_num(4));
    known_errors[1] = __log_entry_x(COMPS_ERR_TEXT_BETWEEN, 3,
                                    comps_str("    some stray"), comps_num(189),
                                    comps_num(2));

    parsed = comps_parse_parsed_create();
    comps_parse_parsed_init(parsed, "UTF-8", 1);
    fp = fopen("sample_comps_bad3.xml", "r");
    comps_parse_file(parsed, fp, NULL);
    //comps_log_print(parsed->log);

    fail_if(parsed->log->entries->first == NULL);
    check_errors(parsed->log, known_errors, 2);
    //comps2xml_f(parsed->comps_doc, "fed2.xml", 0);

    for (i = 0; i < 2; i++) {
        comps_log_entry_destroy(known_errors[i]);
    }
    comps_parse_parsed_destroy(parsed);
}
Пример #13
0
void
nfs_read_cb(void * callback, uintptr_t token, struct pbuf *pbuf)
{
    int err = 0, status = -1;
    fattr_t pattrs;
    char *data = NULL;
    int size = 0;
    void (*cb) (uintptr_t, int, fattr_t *, int, char *) = callback;

    err = check_errors(pbuf);

    assert(callback != NULL);

    if (err == 0) {
	/* get the status out */
	getfrombuf(pbuf, (char*) &status, sizeof(status));

	if (status == NFS_OK) {
	    /* it worked, so take out the return stuff! */
	    getfrombuf(pbuf, (void*) &pattrs, 
		   sizeof(fattr_t));
	    getfrombuf(pbuf, (void*) &size, 
		   sizeof(int));
	    data = getpointfrombuf(pbuf, pattrs.size);
	}
    }

    cb(token, status, &pattrs, size, data);

    return;
}
Пример #14
0
void FileAccessWindows::seek_end(int64_t p_position) {

	ERR_FAIL_COND(!f);
	if (fseek(f, p_position, SEEK_END))
		check_errors();
	prev_op = 0;
}
Пример #15
0
void
nfs_write_cb(void * callback, uintptr_t token, struct pbuf *pbuf)
{
    int err = 0, status = -1;
    fattr_t pattrs;
    void (*cb) (uintptr_t, int, fattr_t *) = callback;

    err = check_errors(pbuf);

    assert(callback != NULL);

    if (err == 0) {
	/* get the status out */
	getfrombuf(pbuf, (char*) &status, sizeof(status));

	if (status == NFS_OK) {
	    /* it worked, so take out the return stuff! */
	    getfrombuf(pbuf, (void*) &pattrs, 
		   sizeof(fattr_t));
	}
    }

    cb(token, status, &pattrs);

    return;
}
Пример #16
0
void
nfs_create_cb(void * callback, uintptr_t token, struct pbuf *pbuf)
{
    int err = 0, status = -1;
    struct cookie new_fh;
    fattr_t pattrs;
    void (*cb) (uintptr_t, int, struct cookie *, fattr_t *) = callback;

    assert(callback != NULL);

    err = check_errors(pbuf);

    if (err == 0) {
	/* get the status out */
	getfrombuf(pbuf, (char*) &status, sizeof(status));

	if (status == NFS_OK) {
	    /* it worked, so take out the return stuff! */
	    getfrombuf(pbuf, (void*) &new_fh, 
		   sizeof(struct cookie));
	    getfrombuf(pbuf, (void*) &pattrs, 
		   sizeof(fattr_t));
	}
    }

    debug("NFS CREATE CALLBACK\n");
    cb(token, status, &new_fh, &pattrs);

    return;

}
Пример #17
0
int FileAccessUnix::get_buffer(uint8_t *p_dst, int p_length) const {

	ERR_FAIL_COND_V(!f,-1);
	int read = fread(p_dst, 1, p_length, f);
	check_errors();
	return read;
};
Пример #18
0
void FileAccessWindows::seek(size_t p_position) {

    ERR_FAIL_COND(!f);
    last_error=OK;
    if ( fseek(f,p_position,SEEK_SET) )
        check_errors();
}
Пример #19
0
END_TEST

START_TEST(test_comps_parse5)
{
    FILE *fp;
    char *err_log;
    COMPS_Parsed *parsed;
    COMPS_ListItem *it;
    int ret, i;
    COMPS_List * tmplist;
    COMPS_LoggerEntry* known_errors[2];

    known_errors[0] = comps_log_entry_create("some stray", 0,
                      COMPS_ERR_TEXT_BETWEEN, 6, 4, 0);
    known_errors[1] = comps_log_entry_create("    some stray", 0,
                      COMPS_ERR_TEXT_BETWEEN, 189, 2, 0);

    parsed = comps_parse_parsed_create();
    comps_parse_parsed_init(parsed, "UTF-8", 1);
    fp = fopen("sample_comps_bad3.xml", "r");
    comps_parse_file(parsed, fp);

    fail_if(parsed->log->logger_data->len == 0);
    check_errors(parsed->log, known_errors, 2);

    for (i = 0; i < 2; i++) {
        comps_log_entry_destroy(known_errors[i]);
    }
    comps_parse_parsed_destroy(parsed);
}
Пример #20
0
END_TEST

START_TEST(test_comps_parse3)
{
    FILE *fp;
    //char *err_log,
    char *tmp_ch;
    COMPS_Parsed *parsed;
    COMPS_ObjListIt *it;
    int i;
    COMPS_ObjList *tmplist;
    COMPS_LogEntry* known_errors[3];
    char *str;
    COMPS_Object *tmpobj;

    fprintf(stderr, "## Running test_parse3\n\n");

    known_errors[0] = __log_entry_x(COMPS_ERR_ELEM_REQUIRED, 3,
                                             comps_str("id"), comps_num(188),
                                             comps_num(2));
    known_errors[1] = __log_entry_x(COMPS_ERR_ELEM_REQUIRED, 3,
                                            comps_str("name"), comps_num(188),
                                            comps_num(2));
    known_errors[2] = __log_entry_x(COMPS_ERR_ELEM_REQUIRED, 3,
                                             comps_str("description"),
                                             comps_num(188), comps_num(2));

    parsed = comps_parse_parsed_create();
    comps_parse_parsed_init(parsed, "UTF-8", 1);
    fp = fopen("sample_comps_bad1.xml", "r");
    comps_parse_file(parsed, fp, NULL);

    fail_if(parsed->log->entries->first == NULL);
    check_errors(parsed->log, known_errors, 3);

    for (i = 0; i < 3; i++) {
        comps_log_entry_destroy(known_errors[i]);
    }
    tmplist = comps_doc_groups(parsed->comps_doc);
    it = tmplist->first;

    /*pairlist = comps_rtree_pairs(((COMPS_DocCategory*)it->data)->properties);
    for (hsit = pairlist->first; hsit != NULL; hsit = hsit->next){
        printf("%s = %s\n", ((COMPS_RTreePair*)hsit->data)->key,
                          ((COMPS_RTreePair*)hsit->data)->data);
    }*/
    COMPS_OBJECT_DESTROY(tmplist);

    tmpobj = comps_docgroup_get_id((COMPS_DocGroup*)it->comps_obj);
    fail_if(tmpobj, "%d. category should have NULL id\n");
    COMPS_OBJECT_DESTROY(tmpobj);
    tmpobj = comps_docgroup_get_name((COMPS_DocGroup*)it->comps_obj);
    fail_if(tmpobj, "%d. category should have NULL name\n");
    COMPS_OBJECT_DESTROY(tmpobj);
    tmpobj = comps_docgroup_get_desc((COMPS_DocGroup*)it->comps_obj);
    fail_if(tmpobj, "%d. category should have NULL description\n");
    COMPS_OBJECT_DESTROY(tmpobj);
    comps_parse_parsed_destroy(parsed);
}
Пример #21
0
void
nfs_readdir_cb(void * callback, uintptr_t token, struct pbuf *pbuf)
{
    int err = 0, status = -1, num_entries = 0, next_cookie = 0;
    struct nfs_filename *entries = NULL;
    void (*cb) (uintptr_t , int, int, struct nfs_filename *, int) = callback;
    int count = 0;

    debug("NFS READDIR CALLBACK\n");

    assert(callback != NULL);

    err = check_errors(pbuf);

    if (err == 0) {
	/* get the status out */
	getfrombuf(pbuf, (char*) &status, sizeof(status));

	if (status == NFS_OK) {
	    int tmp, fileid, cookie;
	    debug("Getting entries\n");
	    num_entries = getentries_readdir(pbuf, &next_cookie);
	    entries = malloc(sizeof(struct nfs_filename) * 
		     num_entries);

	    
	    getfrombuf(pbuf, (char*) &tmp, sizeof(tmp));
	    debug("Got entry: %d\n", tmp);
	    
	    while(tmp) {
		int size;
		getfrombuf(pbuf, (char*) &fileid, 
		       sizeof(fileid));
		debug("Got filed: %d\n", fileid);
		getfrombuf(pbuf, (char*) &entries[count].size,
		       sizeof(int));
		debug("Got size: %d\n", entries[count].size);
		entries[count].file = pbuf->arg[0];
		size = entries[count].size;
		if (size % 4)
		    size += 4 - (size % 4);
		pbuf_adv_arg(pbuf, 0, size);
		debug("Got size: %p\n", pbuf->arg[0]);
		
		getfrombuf(pbuf, (char*) &cookie, sizeof(int));
		
		count++;
		getfrombuf(pbuf, (char*) &tmp, sizeof(tmp));
	    }
	}
    }

    cb(token, status, num_entries, entries, next_cookie);
    if (entries)
	free(entries);

    return;

}
Пример #22
0
void yaml_oarchive_t::end_map()
{
	RAMEN_ASSERT( map_level() > 0);

	out_ << YAML::EndMap;
	--map_level_;
	check_errors();
}
Пример #23
0
void GLRenderer::load_shader(boost::shared_ptr<State> data)
{
	if( data->RenderData || !_UseShaders )	return;
	shared_ptr<Resource> res( new GLProgram(data) );
	data->RenderData = res;

	check_errors();
}
Пример #24
0
void FileWindows::seek_end(signed int p_position) {

	if (!f)
		return;
		
	if ( fseek(f,p_position,SEEK_END) )
		check_errors();
}
Пример #25
0
void GLRenderer::load_render_target(boost::shared_ptr<State> data)
{
	if( data->RenderData || !_UseFBOs )	return;
	shared_ptr<Resource> res( new GLTarget(data) );
	data->RenderData = res;

	check_errors();
}
Пример #26
0
void Audio::Source :: refresh() {
    if(!buffer_id)
        return;
    auto l = Audio::lock();
    check_errors();
    alSourcei(id, AL_BUFFER, buffer_id);
    alSourcef(id, AL_PITCH, pitch);
    alSourcef(id, AL_GAIN, kit::clamp<float>(gain, 0.0f, 1.0f - K_EPSILON));
    alSourcei(id, AL_SOURCE_RELATIVE, (flags & F_AMBIENT) ? AL_TRUE : AL_FALSE);
    alSourcefv(id, AL_POSITION, glm::value_ptr(pos));
    alSourcefv(id, AL_VELOCITY, glm::value_ptr(vel));
    alSourcef(id, AL_ROLLOFF_FACTOR, 1.0f);
    alSourcef(id, AL_MAX_DISTANCE, 2048.0f);
    alSourcef(id, AL_REFERENCE_DISTANCE, 256.0f);
    alSourcei(id, AL_LOOPING, (flags & F_LOOP) ? AL_TRUE : AL_FALSE);
    check_errors();
}
Пример #27
0
size_t FileAccessWindows::get_pos() const {

	size_t aux_position = 0;
	if (!(aux_position = ftell(f))) {
		check_errors();
	};
	return aux_position;
}
Пример #28
0
void GLRenderer::load_texture(boost::shared_ptr<State> data)
{
	if( data->RenderData )	return;
	shared_ptr<Resource> res( new GLTexture(data) );
	data->RenderData = res;

	check_errors();
}
Пример #29
0
static game_state *execute_move(game_state *from, char *move)
{
    int w = from->par.w, a = w*w;
    game_state *ret;
    int x, y, i, n;

    if (move[0] == 'S') {
	ret = dup_game(from);
	ret->completed = ret->cheated = TRUE;

	for (i = 0; i < a; i++) {
	    if (move[i+1] < '1' || move[i+1] > '0'+w) {
		free_game(ret);
		return NULL;
	    }
	    ret->grid[i] = move[i+1] - '0';
	    ret->pencil[i] = 0;
	}

	if (move[a+1] != '\0') {
	    free_game(ret);
	    return NULL;
	}

	return ret;
    } else if ((move[0] == 'P' || move[0] == 'R') &&
	sscanf(move+1, "%d,%d,%d", &x, &y, &n) == 3 &&
	x >= 0 && x < w && y >= 0 && y < w && n >= 0 && n <= w) {
	if (from->clues->immutable[y*w+x])
	    return NULL;

	ret = dup_game(from);
        if (move[0] == 'P' && n > 0) {
            ret->pencil[y*w+x] ^= 1L << n;
        } else {
            ret->grid[y*w+x] = n;
            ret->pencil[y*w+x] = 0;

            if (!ret->completed && !check_errors(ret, NULL))
                ret->completed = TRUE;
        }
	return ret;
    } else if (move[0] == 'M') {
	/*
	 * Fill in absolutely all pencil marks everywhere. (I
	 * wouldn't use this for actual play, but it's a handy
	 * starting point when following through a set of
	 * diagnostics output by the standalone solver.)
	 */
	ret = dup_game(from);
	for (i = 0; i < a; i++) {
	    if (!ret->grid[i])
		ret->pencil[i] = (1L << (w+1)) - (1L << 1);
	}
	return ret;
    } else
	return NULL;		       /* couldn't parse move string */
}
Пример #30
0
void FileLibC::seek(unsigned int p_position) {

	if (!f)
		return;

	last_error=OK;
	if ( fseek(f,p_position,SEEK_SET) )
		check_errors();
}