Ejemplo n.º 1
0
bool mse::check_card_match(){	

	if(dataset1->get_num_points() == dataset2->get_num_points())
		return true;

	string err_ps("Mismatched number of coordinates: Dataset 1 = ");
	err_ps += itoa(dataset1->get_num_points());
	err_ps += ", Dataset 2 = ";
	err_ps += itoa(dataset2->get_num_points());

	error_out(err_ps);

	return false;
}
Ejemplo n.º 2
0
	SoundElement* AudioSystem::LoadSoundElement(const char* Path)
	{
		Mix_Chunk* mix_music = Mix_LoadWAV(Path);
		if (mix_music == NULL) 
		{
			error_out("SDLMixerAudioSystem::LoadSoundElement - "
				"无法读取文件 %s , 错误信息", Path, Mix_GetError());
			return NULL;
		}

		SoundElement* se = new SoundElement();
		se->sdl_mix_music = mix_music;
		return se;
	}
Ejemplo n.º 3
0
int main(int argc, char *argv[])
{
	int r;
	const char *memname = "/mymem";
	const size_t region_size = 1024;
	/* 打开共享内存文件 */
	int fd = shm_open(memname, O_CREAT | O_TRUNC | O_RDWR, 0666);
	if (fd == -1) error_out("shm_open");
	/* 将文件截取至指定的大小 */
	r = ftruncate(fd, region_size);
	if (r != 0) error_out("ftruncate");
	/* 将文件映射为内存 */
	void *ptr = mmap(0, region_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
	if (ptr == MAP_FAILED) error_out("mmap");
	/* 关闭文件 */
	close(fd);
	/* 产生新进程 */
	pid_t pid = fork();
	if (pid == 0) {
		/* 子进程向共享内存写入数据 */
		unsigned long *d = (unsigned long *) ptr;
		*d = 0xdeadbeef;
		exit(0);
	} else {
		/* 父进程等待子进程结束并读共享内存 */
		int status;
		waitpid(pid, &status, 0);
		printf("The data child wrote is %#lx\n", *(unsigned long *)ptr);
	}
	/* 取消内存映射 */
	r = munmap(ptr, region_size);
	if (r != 0) error_out("munmap");
	/* 删除共享内存文件 */
	r = shm_unlink(memname);
	if (r != 0) error_out("shm_unlink");
	return 0;
}
Ejemplo n.º 4
0
int main(string args) {
    string *words;

    if (!args) {
        return 0;
    }

    words = explode(args, " ");
    switch (sizeof(words)) {
        case 1:
            return teleport_to(words[0]);
        case 2:
            return teleport_player(words[0], words[1]);
        default:
            return error_out(usage());
    }
}
Ejemplo n.º 5
0
bool difmap::check_card_match(){	
	if(dataset1->get_num_points() != dataset2->get_num_points()){

		string err_ps("Mismatched number of coordinates: Dataset 1 = ");
		err_ps += itoa(dataset1->get_num_points());
		err_ps += ", Dataset 2 = ";
		err_ps += itoa(dataset2->get_num_points());

		error_out(err_ps);
		
		return false;
	}

	//TODO
	//Check dimensions

	return true;
}
Ejemplo n.º 6
0
Archivo: lso.c Proyecto: rmanis/lil
int main(string dir) {
    string path = resolve_path(this_player()->query_cwd(), dir);
    string *files;
    string *fulls;
    mixed *combined;

    if (!sizeof(stat(path))) {
	return error_out(sprintf("No such file or directory: %s", path));
    }

    if (dirp(path) && path != "/") {
	path += "/";
    }

    files = filter(get_dir(path), (: $1[0] != '.' :));

    if (filep(path)) {
        fulls = ({ path });
    } else {
Ejemplo n.º 7
0
Archivo: qmq.cpp Proyecto: bjzu/qmq
int main(int argc, char *const *argv)
{
  int c;
  while ((c = getopt(argc, argv, "hV")) != -1) {
    switch (c) {
      case 'V':
        show_version();
        break;
      case 'h':
        show_help();
        break;
      case '?':
        error_out("See -h for correct options");
        break;
    }
  }

  exit(EXIT_SUCCESS);
}
Ejemplo n.º 8
0
int teleport_player(string player, string place) {
    object *players = users();
    object destination;
    object victim;
    string name = player;
    string room = place;
    string msg = "";
    int index;
    player = lower_case(player);

    switch (lower_case(player)) {
        case "me":
        case "myself":
            name = lower_case(previous_object()->query_name());
    }
    switch (lower_case(place)) {
        case "here":
            room = file_name(here());
    }

    index = member_array(name, map(players,
                (: lower_case($1->query_name()) :)));
    if (index >= 0) {
        victim = players[index];
    }

    destination =
        load_object(resolve_path(previous_object()->query_cwd(), room));

    if (!victim) {
        msg = "Could not find player " + player;
    }
    if (!destination) {
        msg += (strlen(msg) ? "\n" : "" ) + "Could not find place " + place;
    }

    if (!msg) {
        return teleport(victim, destination);
    }

    return error_out(msg);
}
Ejemplo n.º 9
0
int main(string arg) {
    string *usernames = explode(arg, " ");
    object *users = map(usernames, "find_player", "/single/simul_efun");
    int arg_count = usernames && sizeof(usernames);
    int i;

    if (!arg_count) {
        return error_out(usage());
    }

    for (i = 0; i < arg_count; i++) {
        if (users[i]) {
            operate(users[i]);
        } else {
            MESSAGE_D->tell(previous_object(), "Could not find user " + usernames[i] + "\n");
        }
    }

    return 1;
}
Ejemplo n.º 10
0
void demo_res (int Screen_Mode, int X_max, int Y_max)
{

char 	*Error1 = "Failure while calling SET_MODEX";
char	*Error2 = "Failure during READ_PIXEL test";

char	*Abort_Msg = "Demo aborted by User";

char	*Demo_Msg = " This is a MODE X demo ";
char	*Scrn_Msg = "Screen Resolution is     by    ";
char	*Cont_Msg = "Press <ANY KEY> to Continue";

char    *Line_Msg = "LINE TEST";
char	*Fill_Msg = "FILL TEST";
char	*Pixel_Msg = "PIXEL TEST";

char	Text[10];

int		x1, y1, x2, y2 = 0;
int		x, y, z = 0;
int		X_Center, gap = 0;


	if (set_modex (Screen_Mode) == 0)
	{
		error_out (Error1);
	}

	X_Center = X_max / 2;

	x1 = 10;
	y1 = 10;
	x2 = X_max - 1;
	y2 = Y_max - 1;

	for (z = 0; z <= 3; z++)
	{
		y = 31 - z -z;
		draw_line (x1+z, y1+z, x2-z, y1+z, y);
		draw_line (x1+z, y1+z, x1+z, y2-z, y);
		draw_line (x1+z, y2-z, x2-z, y2-z, y);
		draw_line (x2-z, y1+z, x2-z, y2-z, y);
	}

	for (x = 0; x < (X_max / 10); x++)
	{
		tgprintc (48 + ((x+1) % 10), x*10+1, 1, 9 + ((x/8) % 7) );
		draw_line (x*10+9, 0, x*10+9, 3, c_bWHITE);
	}

	for (y = 0; y < (Y_max / 10); y++)
	{
		tgprintc (48 + ((y+1) % 10), 1, y*10+1, 9 + ((y/10) % 7) );
		draw_line (0, y*10+9, 3, y*10+9, c_bWHITE);
	}

	for (x = 0; x <= 63; x++)
	{
		z = 15 + (x * 3 / 4);
		set_dac_register (64+x, z, z, z);
		set_dac_register (128+x, 0, z, z);

		draw_line (103-x, 60, 40+x, 123, 64+x);
		draw_line (40, 60+x, 103, 123-x, 128+x);

	}

	tprint_str (Line_Msg, 9, 37, 130, c_BLUE);

	y = 60;
	gap = 0;
	for (x = 0; x <= 9; x++)
	{
		fill_block (120, y, 120+x, y+gap, 64+x);
		fill_block (140 - (15-x), y, 150+x, y+gap, 230+x);
		fill_block (170 - (15-x), y, 170, y+gap, 128+x);
		y = y + gap + 2;
		gap++;
	}

	tprint_str (Fill_Msg, 9, 110, 46, c_GREEN);

	for (x = 190; x <= 250; x+=2)
	{
		for (y = 60; y <= 122; y+=2)
		{
			z = (x+x+y+y) & 0xff;
			set_point (x, y, z);
		}
	}

	tprint_str (Pixel_Msg, 10, 182, 130, c_RED);

	for (x = 190; x <= 250; x+=2)
	{
		for (y = 60; y <= 122; y+=2)
		{
			z = (x+x+y+y) & 0xff;
			if (read_point(x, y) != z)
			{
				error_out (Error2);
			}
		}
	}

	print_str (Demo_Msg, 23, X_Center - 92, 20, c_bRED, c_BLUE);

	x = X_Center - 124;
	print_str (Scrn_Msg, 28, x, 30, c_bGREEN, c_BLACK);

	sprintf (Text, "%3d", X_max);
	print_str (Text, 3, x+168, 30, c_bPURPLE, c_BLACK);

	sprintf (Text, "%3d", Y_max);
	print_str (Text, 3, x + 224, 30, c_bWHITE, c_BLACK);

	for (x = 0; x <= 15; x++)
	{
		set_dac_register (230+x, 63-x*4, 0, 15+x*3);
		draw_line (30+x, Y_max-6-x, X_max-20-x, Y_max-6-x, 230+x);
	}

	tprint_str (Cont_Msg, 27, X_Center - 103, Y_max-18, c_YELLOW);

	if (get_key () == Ky_ESC)
	{
		error_out (Abort_Msg);
	}

	return ;

}
Ejemplo n.º 11
0
void load_shapes ()
{

unsigned char 	Grid[33][33];

char	*Error1 = "Bad Shape Selected Error";

int		Shape;
int		x, y, z;
int		Style, Color;
int		X_Width, Y_Width, Center, S_Width;
int		Hollow_X, Hollow_Y;

	for (Shape = 0; Shape < MAX_SHAPES; Shape++)
	{
		for (y = 0; y <= 32; y++)
		{
			for (x = 0; x <= 32; x++)
			{
				Grid[x][y] = c_BLACK;
			}
		}

		Style = random_int (6);
		Color = 1 + random_int (15);

		switch (Style)

		{
				/* SOLID BOXES */

			case 0:

			{
				do
				{
					X_Width = 3 + random_int(30);
					Y_Width = 3 + random_int(30);

				} while ( (X_Width * Y_Width) >= 512);

				for (x = 1; x <= X_Width; x++)
				{
					for (y = 1; y <= Y_Width; y++)
					{
					   Grid[x][y] = Color;
					}
				}

				break;

			}
				/* HOLLOW BOXES */

			case 1:

			{
				do {
					X_Width = 6 + random_int(27);
					Y_Width = 6 + random_int(27);
				} while ( (X_Width * Y_Width) >= 512);

				for (y = 1; y <= Y_Width; y++)
				{
					for (x = 1; x <= X_Width; x++)
					{
						Grid[x][y] = Color;
					}
				}

				Hollow_X = 1 + random_int ((X_Width / 2) -1);
				Hollow_Y = 1 + random_int ((Y_Width / 2) -1);

				for (y = Hollow_Y+1; y <= Y_Width-Hollow_Y; y++)
				{
					for (x = Hollow_X+1; x <= X_Width-Hollow_X; x++)
					{
						Grid[x][y] = c_BLACK;
					}
				}

				break;

			}

				/* SOLID DIAMOND */

			case 2:

			{

				X_Width = 3 + 2 * random_int(10);
				Y_Width = X_Width;
				Center = X_Width / 2;

				for (y = 0; y <= Center; y++)
				{
					for (x = 0; x <= y; x++)
					{
						Grid [Center-x+1][y+1] = Color;
						Grid [Center+x+1][y+1] = Color;
						Grid [Center-x+1][Y_Width-y] = Color;
						Grid [Center+x+1][Y_Width-y] = Color;
					}
				}

				break;

			}

				/* HOLLOW DIAMOND */

			case 3:

			{

				X_Width = 3 + 2 * random_int(10);
				Y_Width = X_Width;
				Center = X_Width / 2;
				S_Width = random_int (Center);

				for (y = 0; y <= Center; y++)
				{
					for (x = 0; x <= y; x++)
					{
						if ( x+(Center-y) >= S_Width )
						{
							Grid [Center-x+1][y+1] = Color;
							Grid [Center+x+1][y+1] = Color;
							Grid [Center-x+1][Y_Width-y] = Color;
							Grid [Center+x+1][Y_Width-y] = Color;
						}
					}
				}

				break;

			}

				/* BALL */

			case 4:

			{

				X_Width = 7 + 2 * random_int (8);
				Y_Width = X_Width;
				Center  = 1 + X_Width / 2;

				for (y = 1; y <= Y_Width; y++)
				{
					for (x = 1; x <= X_Width; x++)
					{
						z = int_sqrt(Center-x, Center-y);
						if (z < Center)
						{
							Grid[x][y] = 150 + Color * 2 + z * 3;
						}
					}
				}

				break;
			}

				/* HOLLOW BALLS */

			case 5:

			{
				X_Width = 7 + 2 * random_int (8);
				Y_Width = X_Width;
				Center  = 1 + X_Width / 2;
				S_Width = random_int (X_Width);

				for (y = 1; y <= Y_Width; y++)
				{
					for (x = 1; x <= X_Width; x++)
					{
						z = int_sqrt(Center-x, Center-y);
						if ( (z < Center) && (z >= S_Width) )
						{
							Grid[x][y] = 150 + Color * 2 + z * 3;
						}
					}
				}


				break;
			}

			default:

			{
				error_out (Error1);
				break;

			}

		}

		z = 0;
		for (y = 1; y <= Y_Width; y++)
		{
			for (x = 1; x <= X_Width; x++)
			{
				Img[Shape].Image[z] = Grid[x][y];
				z++;
			}
		}

		Img[Shape].X_Width = X_Width;
		Img[Shape].Y_Width = Y_Width;

	}

	return;
}
Ejemplo n.º 12
0
/*
 * Export authlist to the userspace
 */
static int read_authlist(struct authlist *authlist,
			 void __user *buffer,
			 size_t *lenp, loff_t *ppos)
{
	struct user_namespace *ns = current_user_ns();
	char *memblk = NULL;
	char *vp = NULL;
	int error = 0;
	int len;
	uid_t uid;
	gid_t gid;

	down_read(&authlist->rws);

	if (authlist->nentries == 0) {
		switch (authlist->initial_value) {
		case AUTHLIST_KIND_EVERYBODY:
			vp = (char *) tag_everybody;
			break;

		case AUTHLIST_KIND_NOBODY:
		default:
			vp = (char *) tag_nobody;
			break;
		}
	} else {
		struct authlist_entry *entry;
		/* <space>noguid:4294967295 */
		size_t maxentrysize = 1 + 6 + 1 + 10;
		size_t alloc_size = maxentrysize * authlist->nentries + 1;
		int ne;

		memblk = kmalloc(alloc_size, GFP_KERNEL);
		if (memblk == NULL) {
			up_read(&authlist->rws);
			return -ENOMEM;
		}

		vp = memblk;
		*vp = '\0';
		entry = authlist->entries;
		for (ne = 0;  ne < authlist->nentries;  ne++, entry++) {
			vp += strlen(vp);
			if (ne != 0)
				*vp++ = ' ';
			switch (entry->kind) {
			case AUTHLIST_KIND_UID:
				uid = from_kuid(ns, entry->kuid);
				if (uid == (uid_t) -1) {
					error = EIDRM;
					break;
				}
				sprintf(vp, "%s:%u", tag_uid, (unsigned) uid);
				break;

			case AUTHLIST_KIND_NOUID:
				uid = from_kuid(ns, entry->kuid);
				if (uid == (uid_t) -1) {
					error = EIDRM;
					break;
				}
				sprintf(vp, "%s:%u", tag_nouid, (unsigned) uid);
				break;

			case AUTHLIST_KIND_GID:
				gid = from_kgid(ns, entry->kgid);
				if (gid == (gid_t) -1) {
					error = EIDRM;
					break;
				}
				sprintf(vp, "%s:%u", tag_gid, (unsigned) gid);
				break;

			case AUTHLIST_KIND_NOGID:
				gid = from_kgid(ns, entry->kgid);
				if (gid == (gid_t) -1) {
					error = EIDRM;
					break;
				}
				sprintf(vp, "%s:%u", tag_nogid, (unsigned) gid);
				break;

			case AUTHLIST_KIND_EVERYBODY:
				strcpy(vp, tag_everybody);
				break;

			case AUTHLIST_KIND_NOBODY:
				strcpy(vp, tag_nobody);
				break;
			}

			if (unlikely(error != 0)) {
				up_read(&authlist->rws);
				kfree(memblk);
				return error;
			}
		}

		vp = memblk;
	}

	up_read(&authlist->rws);

	len = strlen(vp);

	/* ensure atomic transfer */
	if (*ppos != 0) {
		if (*ppos == len + 1) {
			*lenp = 0;
			goto out;
		}
		error_out(-EINVAL);
	}

	if (len + 2 > *lenp)
		error_out(-ETOOSMALL);

	if (likely(len) && copy_to_user(buffer, vp, len))
		error_out(-EFAULT);

	if (copy_to_user(buffer + len, "\n", 2))
		error_out(-EFAULT);

	*lenp = len + 1;
	*ppos += len + 1;

out:

	kfree(memblk);

	return error;
}
Ejemplo n.º 13
0
/*
 * Import authlist from the userspace
 */
static int write_authlist(struct authlist *authlist, void __user *buffer,
			  size_t *lenp, loff_t *ppos)
{
	struct authlist_entry *entries = NULL, *old_entries;
	char *memblk = NULL;
	int error = 0;
	int nentries;
	int ne;
	int terminal = -1;
	const char *p;

	/* ensure atomic transfer */
	if (*ppos != 0)
		return -EINVAL;

	if (*lenp > AUTHLIST_LENGTH_LIMIT)
		return -EINVAL;

	memblk = kmalloc(*lenp + 1, GFP_KERNEL);
	if (memblk == NULL)
		return -ENOMEM;

	if (copy_from_user(memblk, buffer, *lenp))
		error_out(-EFAULT);

	memblk[*lenp] = '\0';

	nentries = count_entries(memblk);
	if (nentries == 0)
		error_out(-EINVAL);

	entries = kmalloc(sizeof(struct authlist_entry) * nentries, GFP_KERNEL);
	if (entries == NULL)
		error_out(-ENOMEM);

	for (p = memblk, ne = 0;; ne++) {
		/* skip leading whitespace */
		while (is_ws(*p))
			p++;

		/* reached the end of the string? */
		if (*p == '\0')
			break;

		error = parse_entry(&p, entries + ne);
		if (error)
			goto out;

		switch (entries[ne].kind) {
		case AUTHLIST_KIND_EVERYBODY:
		case AUTHLIST_KIND_NOBODY:
			if (terminal != -1)
				error_out(-EINVAL);
			terminal = ne;
			break;

		default:
			break;
		}
	}

	/*
	 * Last entry must be everybody/nobody.
	 * Intermediate entry cannot be everybody/nobody.
	 */
	if (terminal != nentries - 1)
		error_out(-EINVAL);

	down_write(&authlist->rws);
	old_entries = authlist->entries;
	authlist->nentries = nentries;
	authlist->entries = entries;
	up_write(&authlist->rws);

	kfree(old_entries);
	entries = NULL;

	*ppos += *lenp;

out:

	kfree(memblk);
	kfree(entries);

	return error;
}