示例#1
0
static void make_level(
    const char* target,
    uint32_t depth,
    uint32_t width,
    uint32_t files,
    uint32_t file_size
) {
    if (chdir(target) == -1) {
        perror(target);
        return;
    }
    if (depth) {
        mode_t mode = 0775;
        for (size_t i = 0; i < width; i++) {
            char filename[18];
            snprintf(filename, sizeof(filename), "d%u", i);
            if (mkdir(filename, mode) == -1) {
                if (errno != EEXIST) {
                    perror(filename);
                    goto up;
                }
            }
            make_level(filename, depth - 1, width, files, file_size);
        }
    }
    FILE* rand = fopen("/dev/urandom", "r");
    if (rand == NULL) {
        perror("/dev/urandom");
        goto up;
    }
    for (size_t i = 0; i < files; i++) {
        char filename[17];
        snprintf(filename, sizeof(filename), "%u", i);
        FILE* f = fopen(filename, "w");
        if (f == NULL) {
            perror("fopen");
            goto up;
        }
        int fd = fileno(f);
        // if fallocate fails nbd
        posix_fallocate(fd, 0, file_size);
        const size_t chunk_size = 1000;
        char* buffer = malloc(chunk_size);
        for (size_t i = 0; i < file_size; i++) {
            // don't care if fread fails
            fread(buffer, 1, chunk_size, rand);
            size_t written = fwrite(buffer, 1, chunk_size, f);
            if (written < chunk_size) {
                perror(filename);
                goto cleanup;
            }
        }
        cleanup:
        free(buffer);
        fclose(f);
    }
    fclose(rand);
    up:
    chdir("..");
}
示例#2
0
文件: main.c 项目: masoo/rogueclone2s
int
main(int argc, char *argv[])
{
    int first = 1;
    char buf[80];

    progname = argv[0];

    if (init(argc, argv)) {	/* restored game */
	goto PL;
    }

    for (;;) {
	clear_level();
	make_level();
	put_objects();
	put_stairs();
	add_traps();
	put_mons();
	put_player(party_room);
	print_stats(STAT_ALL);
	if (first) {
	    sprintf(buf, mesg[10], nick_name);
	    message(buf, 0);
	}
    PL:
	first = 0;
	play_level();
	free_stuff(&level_objects);
	free_stuff(&level_monsters);
    }
}
示例#3
0
/*------------------------------------------*/
void SetupBILUT(matrix_t *mat, precon_t *prec,
options_t *opts) {
/*------------------------------------------*/
  int n,bn,i,j1,j2,p,dd,lusolgpu,*nrow,*noff;
  double tol,avgfil;
/*------------------------------------------*/
  n = mat->n;
  bn = opts->bilu_opt->bn;
  p = opts->bilu_opt->lfil;
  tol = opts->bilu_opt->tol;
  lusolgpu = opts->lusolgpu;
  dd = opts->bilu_opt->dd;
/*------------------------------------*/
  if (dd) {
    assert(prec->bilu);
    assert(prec->bilu->host);
  } else {
/*---- no domain domcop */
    assert(prec->bilu == NULL);
    Calloc(prec->bilu, 1, bilu_prec_t);
    Calloc(prec->bilu->host, 1, bilu_host_t);
    Malloc(nrow, bn, int);
    Malloc(noff, bn, int);
    for (i=0; i<bn; i++) {
      Partition1D(n, bn, i, j1, j2);
      noff[i] = j1;
      nrow[i] = j2 - j1;
    }
    prec->bilu->host->nrow = nrow;
    prec->bilu->host->noff = noff;
  }
/*--------------------*/
  prec->bilu->nb = bn;
/*------------ iluk fact for all blocks*/
  bilut(mat->h_csr, prec->bilu->host, 
  bn, p, tol, &avgfil);
  opts->result.bfilfact = avgfil;
/*----------------------------------------*/
  if (lusolgpu == 0) {
/*---------- cpu solve */
    prec->bilu->h_x = 
    (double*)cuda_malloc_host(n*sizeof(double));
    prec->bilu->h_b = 
    (double*)cuda_malloc_host(n*sizeof(double));
    return;
  }
/*---------- gpu solve */
/*---------- level scheduling */
  Malloc(prec->bilu->host->blev, bn, level_t);
  for (i=0; i<bn; i++)
    make_level(prec->bilu->host->blu+i, 
              prec->bilu->host->blev+i);
/*---------- copy to device */
  Calloc(prec->bilu->dev, 1, bilu_dev_t);
  blu_h2d(prec->bilu->host, prec->bilu->dev, n, bn);
  printf("%d block ilut prec ... done\n", bn);
}
示例#4
0
文件: main.c 项目: jgreco/snowballrl
int main()
{
	initscr();
	raw();
	keypad(stdscr, TRUE);
	noecho();
	curs_set(0);
	start_color();
	use_default_colors();

	init_pair(1, COLOR_BLUE, 144);/*COLOR_BLACK); */
	init_pair(2, COLOR_BLUE, 186);/*238); */
	init_pair(3, COLOR_BLUE, 187);/*245); */
	init_pair(4, COLOR_BLUE, COLOR_WHITE);


	init_pair(5, TREECOLOR, 144);/*COLOR_BLACK); */
	init_pair(6, TREECOLOR, 186);/*238); */
	init_pair(7, TREECOLOR, 187);/*245); */
	init_pair(8, TREECOLOR, COLOR_WHITE);

	init_pair(9, -1, COLOR_BLUE);
	init_pair(10, -1, COLOR_RED);

	assume_default_colors(COLOR_WHITE, COLOR_BLACK);

	srand(time(NULL));

	map = make_level(1000,1000);
	player = create_monster(PLAYER);
	player->x = 500;
	player->y = 500;
	player->hp = 100;
	snow_count = 10;

	offset_x = 0;
	offset_y = 0;

	messages = al_makenull(NULL);

	ninterface();

	endwin();

	return 0;
}
示例#5
0
void setup(const char* benchmark_file, const char* target) {
    FILE* f = fopen(benchmark_file, "r");
    uint32_t depth, width, files, file_size;
    int scanned = fscanf(f, "%u %u %u %u", &depth, &width, &files, &file_size);
    if (scanned == EOF) {
        printf("%s", strerror(errno));;
        goto close;
    }
    if (scanned < 4) {
        printf("malformed file");
        goto close;
    }
    // TODO permissions
    mode_t mode = 0775;
    int mk = mkdir(target, mode);
    if (mk == -1) {
        if (errno != EEXIST) {
            perror(target);
            goto close;
        }
    }
    char cwd[300];
    const char* curr = getcwd(cwd,sizeof(cwd));
    if (curr == NULL) {
        perror("cwd");
    }
    make_level(target, depth, width, files, file_size);
    int ret = chdir(cwd);
    if(ret == -1) {
        perror("chdir");
        goto close;
    }

    close:
    fclose(f);
}
示例#6
0
int
main(int ac, char *av[])
{
	bool		show_only;
	extern char	*Scorefile;
	int		score_wfd;     /* high score writable file descriptor */
	int		score_err = 0; /* hold errno from score file open */
	int		ch;
	extern int	optind;
	gid_t		gid;
#ifdef FANCY
	char		*sp;
#endif

	if ((score_wfd = open(Scorefile, O_RDWR)) < 0)
		score_err = errno;

	/* revoke privs */
	gid = getgid();
	setresgid(gid, gid, gid);

	show_only = FALSE;
	while ((ch = getopt(ac, av, "srajt")) != -1)
		switch (ch) {
		case 's':
			show_only = TRUE;
			break;
		case 'r':
			Real_time = TRUE;
			/* Could be a command-line option */
			tv.tv_sec = 3;
			tv.tv_usec = 0;
			FD_ZERO(&rset);
			break;
		case 'a':
			Start_level = 4;
			break;
		case 'j':
			Jump = TRUE;
			break;
		case 't':
			Teleport = TRUE;
			break;
		case '?':
		default:
			usage();
		}
	ac -= optind;
	av += optind;

	if (ac > 1)
		usage();
	if (ac == 1) {
		Scorefile = av[0];
		if (score_wfd >= 0)
			close(score_wfd);
		/* This file requires no special privileges. */
		if ((score_wfd = open(Scorefile, O_RDWR)) < 0)
			score_err = errno;
#ifdef	FANCY
		sp = strrchr(Scorefile, '/');
		if (sp == NULL)
			sp = Scorefile;
		if (strcmp(sp, "pattern_roll") == 0)
			Pattern_roll = TRUE;
		else if (strcmp(sp, "stand_still") == 0)
			Stand_still = TRUE;
		if (Pattern_roll || Stand_still)
			Teleport = TRUE;
#endif
	}

	if (show_only) {
		show_score();
		exit(0);
	}

	if (score_wfd < 0) {
		warnx("%s: %s; no scores will be saved", Scorefile,
			strerror(score_err));
		sleep(1);
	}

	initscr();
	signal(SIGINT, quit);
	cbreak();
	noecho();
	nonl();
	if (LINES != Y_SIZE || COLS != X_SIZE) {
		if (LINES < Y_SIZE || COLS < X_SIZE) {
			endwin();
			errx(1, "Need at least a %dx%d screen", Y_SIZE, X_SIZE);
		}
		delwin(stdscr);
		stdscr = newwin(Y_SIZE, X_SIZE, 0, 0);
	}

	srandomdev();
	do {
		init_field();
		for (Level = Start_level; !Dead; Level++) {
			make_level();
			play_level();
		}
		move(My_pos.y, My_pos.x);
		printw("AARRrrgghhhh....");
		refresh();
		score(score_wfd);
	} while (another());
	quit(0);
	/* NOT REACHED */
}
示例#7
0
文件: main.c 项目: a565109863/src
int
main(int ac, char *av[])
{
	bool		show_only;
	extern char	Scorefile[PATH_MAX];
	int		score_wfd;     /* high score writable file descriptor */
	int		score_err = 0; /* hold errno from score file open */
	int		ch;
	int		ret;
	extern int	optind;
	char		*home;
#ifdef FANCY
	char		*sp;
#endif

	if (pledge("stdio rpath wpath cpath tty", NULL) == -1)
		err(1, "pledge");

	home = getenv("HOME");
	if (home == NULL || *home == '\0')
		err(1, "getenv");

	ret = snprintf(Scorefile, sizeof(Scorefile), "%s/%s", home,
	    ".robots.scores");
	if (ret < 0 || ret >= PATH_MAX)
		errc(1, ENAMETOOLONG, "%s/%s", home, ".robots.scores");

	if ((score_wfd = open(Scorefile, O_RDWR | O_CREAT, 0666)) < 0)
		score_err = errno;

	show_only = FALSE;
	while ((ch = getopt(ac, av, "srajt")) != -1)
		switch (ch) {
		case 's':
			show_only = TRUE;
			break;
		case 'r':
			Real_time = TRUE;
			/* Could be a command-line option */
			tv.tv_sec = 3;
			break;
		case 'a':
			Start_level = 4;
			break;
		case 'j':
			Jump = TRUE;
			break;
		case 't':
			Teleport = TRUE;
			break;
		case '?':
		default:
			usage();
		}
	ac -= optind;
	av += optind;

	if (ac > 1)
		usage();
	if (ac == 1) {
		if (strlcpy(Scorefile, av[0], sizeof(Scorefile)) >=
		    sizeof(Scorefile))
			errc(1, ENAMETOOLONG, "%s", av[0]);
		if (score_wfd >= 0)
			close(score_wfd);
		/* This file requires no special privileges. */
		if ((score_wfd = open(Scorefile, O_RDWR | O_CREAT, 0666)) < 0)
			score_err = errno;
#ifdef	FANCY
		sp = strrchr(Scorefile, '/');
		if (sp == NULL)
			sp = Scorefile;
		if (strcmp(sp, "pattern_roll") == 0)
			Pattern_roll = TRUE;
		else if (strcmp(sp, "stand_still") == 0)
			Stand_still = TRUE;
		if (Pattern_roll || Stand_still)
			Teleport = TRUE;
#endif
	}

	if (show_only) {
		show_score();
		return 0;
	}

	if (score_wfd < 0) {
		warnx("%s: %s; no scores will be saved", Scorefile,
			strerror(score_err));
		sleep(1);
	}

	initscr();
	signal(SIGINT, quit);
	cbreak();
	noecho();
	nonl();
	if (LINES != Y_SIZE || COLS != X_SIZE) {
		if (LINES < Y_SIZE || COLS < X_SIZE) {
			endwin();
			errx(1, "Need at least a %dx%d screen", Y_SIZE, X_SIZE);
		}
		delwin(stdscr);
		stdscr = newwin(Y_SIZE, X_SIZE, 0, 0);
	}

	do {
		init_field();
		for (Level = Start_level; !Dead; Level++) {
			make_level();
			play_level();
		}
		if (My_pos.x > X_FIELDSIZE - 16)
			move(My_pos.y, X_FIELDSIZE - 16);
		else
			move(My_pos.y, My_pos.x);
		printw("AARRrrgghhhh....");
		refresh();
		score(score_wfd);
	} while (another());
	quit(0);
}
示例#8
0
int
main(int argc, char **argv)
{
	const char *word;
	bool show_only;
	int score_wfd; /* high score writable file descriptor */
	int score_err = 0; /* hold errno from score file open */
	int maximum = 0;
	int ch, i;

	score_wfd = open(Scorefile, O_RDWR);
	if (score_wfd < 0)
		score_err = errno;
	else if (score_wfd < 3)
		exit(1);

	/* Revoke setgid privileges */
	setgid(getgid());

	show_only = false;
	Num_games = 1;

	while ((ch = getopt(argc, argv, "Aajnrst")) != -1) {
		switch (ch) {
		    case 'A':
			Auto_bot = true;
			break;
		    case 'a':
			Start_level = 4;
			break;
		    case 'j':
			Jump = true;
			break;
		    case 'n':
			Num_games++;
			break;
		    case 'r':
			Real_time = true;
			break;
		    case 's':
			show_only = true;
			break;
		    case 't':
			Teleport = true;
			break;
		    default:
			errx(1,
			    "Usage: robots [-Aajnrst] [maximum] [scorefile]");
			break;
		}
	}

	for (i = optind; i < argc; i++) {
		word = argv[i];
		if (isdigit((unsigned char)word[0])) {
			maximum = atoi(word);
		} else {
			Scorefile = word;
			Max_per_uid = maximum;
			if (score_wfd >= 0)
				close(score_wfd);
			score_wfd = open(Scorefile, O_RDWR);
			if (score_wfd < 0)
				score_err = errno;
#ifdef FANCY
			word = strrchr(Scorefile, '/');
			if (word == NULL)
				word = Scorefile;
			if (strcmp(word, "pattern_roll") == 0)
				Pattern_roll = true;
			else if (strcmp(word, "stand_still") == 0)
				Stand_still = true;
			if (Pattern_roll || Stand_still)
				Teleport = true;
#endif
		}
	}

	if (show_only) {
		show_score();
		exit(0);
		/* NOTREACHED */
	}

	if (score_wfd < 0) {
		errno = score_err;
		warn("%s", Scorefile);
		warnx("High scores will not be recorded!");
		sleep(2);
	}

	if (!initscr())
		errx(0, "couldn't initialize screen");
	signal(SIGINT, quit);
	cbreak();
	noecho();
	nonl();
	if (LINES != Y_SIZE || COLS != X_SIZE) {
		if (LINES < Y_SIZE || COLS < X_SIZE) {
			endwin();
			printf("Need at least a %dx%d screen\n",
			    Y_SIZE, X_SIZE);
			exit(1);
		}
		delwin(stdscr);
		stdscr = newwin(Y_SIZE, X_SIZE, 0, 0);
	}

	srandom(time(NULL));
	if (Real_time)
		signal(SIGALRM, move_robots);
	do {
		while (Num_games--) {
			init_field();
			for (Level = Start_level; !Dead; Level++) {
				make_level();
				play_level();
				if (Auto_bot)
					sleep(1);
			}
			move(My_pos.y, My_pos.x);
			printw("AARRrrgghhhh....");
			refresh();
			if (Auto_bot)
				sleep(1);
			score(score_wfd);
			if (Auto_bot)
				sleep(1);
			refresh();
		}
		Num_games = 1;
	} while (!Auto_bot && another());
	quit(0);
	/* NOTREACHED */
	return(0);
}