예제 #1
0
/* Display forest. */
void display( char forest[ ][ Side ], char msg[ ] )
{
    int i, j;

    printf( "\n\t\t%s\n", msg );
    print_border();

    for ( i = 0; i < Side; i++ ) {
        printf( "\n" );
        for ( j = 0; j < Side; j++ )
            printf( "|%c", forest[ i ][ j ] );
        printf( "|" );
        print_border();
    }
    printf( "\n" );
}
예제 #2
0
void print_board(struct board_t board) {	
	print_player(board.pl[0]);
	print_border('_');
	printf("\n");
	print_hand(board.pl[0]);
	print_border('#');
	printf("\n");
	print_field(board, 0);
	printf("\n");
	print_field(board, 1);
	printf("\n");
	print_border('#');
	print_hand(board.pl[1]);
	print_border('_');
	printf("\n");
	print_player(board.pl[1]);	
}
예제 #3
0
void create_map(char *map_name, int load){
	FILE *map;
	char temp[100];
	int y = y1b + 1, x = x1b + 1;
	int i, j;
	switch(load){
	case 0: strcpy(temp,"Levels\\"); strcat(temp,map_name); break;
	case 1: strcpy(temp,"Saved Games\\"); strcat(temp,map_name); break;
	case 2: strcpy(temp,"Saved Maps\\"); strcat(temp,map_name); break;
	}
	map = fopen(temp, "rb");
	print_border();  //okvir
	for (i = y; i<y2b; i++){
		fread(matrix[i - y1b] + x - x1b, sizeof(char), 89, map);
	}
	for (i = y - 2; i < y2b - 2; i++)
		for (j = x - x1b; j<x2b - 2; j++){
			what_to_print(i + 2, j + 2, i + 2, j + 2, matrix[i][j]);
			if (matrix[i][j] == '.') matrix[i][j] = ' ';
		}
	fclose(map);
	refresh();
}
예제 #4
0
파일: purge.c 프로젝트: factotvm/purge
void print_entry(struct dirent *entry, struct stat s)
{
  #define value_len 20
  static const char *time_fmt = "%F %T";
  static const char thick = '=';
  static const char thin = '-';
  static const int width = 72;
  static const int col = 12;

  print_border(thick, width, 0);
  print_row(entry->d_name, NULL, width, 0);
  print_border(thick, width, col);
  char size[value_len];
  format_bytes(size, value_len, s.st_size);
  print_row("Size", size, width, col);
  print_border(thin, width, col);
  char *type;
  switch (entry->d_type) {
    case DT_REG:
      type = "Regular file";
      break;
    case DT_LNK:
      type = "Symbolic link";
      break;
    default:
      type = "Unrecognized";
      break;
  }
  print_row("Type", type, width, col);
  print_border(thin, width, col);
  char mtime[value_len];
  strftime(mtime, value_len, time_fmt, localtime(&s.st_mtimespec.tv_sec));
  print_row("Modified", mtime, width, col);
  print_border(thin, width, col);
  char atime[value_len];
  strftime(atime, value_len, time_fmt, localtime(&s.st_atimespec.tv_sec));
  print_row("Accessed", atime, width, col);
  print_border(thick, width, 0);
}
예제 #5
0
파일: image.c 프로젝트: cslarsen/jp2a
void decompress(FILE *fp, FILE *fout) {
	int row_stride;
	struct jpeg_error_mgr jerr;
	struct jpeg_decompress_struct jpg;
	JSAMPARRAY buffer;
	Image image;

	jpg.err = jpeg_std_error(&jerr);
	jpeg_create_decompress(&jpg);
	jpeg_stdio_src(&jpg, fp);
	jpeg_read_header(&jpg, TRUE);
	jpeg_start_decompress(&jpg);

	if ( jpg.data_precision != 8 ) {
		fprintf(stderr,
			"Image has %d bits color channels, we only support 8-bit.\n",
			jpg.data_precision);
		exit(1);
	}

	row_stride = jpg.output_width * jpg.output_components;

	buffer = (*jpg.mem->alloc_sarray)((j_common_ptr) &jpg, JPOOL_IMAGE, row_stride, 1);

	aspect_ratio(jpg.output_width, jpg.output_height);

	malloc_image(&image);
	clear(&image);

	if ( verbose ) print_info(&jpg);

	init_image(&image, &jpg);

	while ( jpg.output_scanline < jpg.output_height ) {
		jpeg_read_scanlines(&jpg, buffer, 1);
		process_scanline(&jpg, buffer[0], &image);
		if ( verbose ) print_progress(&jpg);
	}

	if ( verbose ) {
		fprintf(stderr, "\n");
		fflush(stderr);
	}

	normalize(&image);

	if ( clearscr ) {
		fprintf(fout, "%c[2J", 27); // ansi code for clear
		fprintf(fout, "%c[0;0H", 27); // move to upper left
	}

	if ( html && !html_rawoutput ) print_html_start(html_fontsize, fout);
	if ( use_border ) print_border(image.width);

	(!usecolors? print_image : print_image_colors) (&image, (int) strlen(ascii_palette) - 1, fout);

	if ( use_border ) print_border(image.width);
	if ( html && !html_rawoutput ) print_html_end(fout);

	free_image(&image);

	jpeg_finish_decompress(&jpg);
	jpeg_destroy_decompress(&jpg);
}
예제 #6
0
int save_map(){
	int i = 0, j = 115, tru = 1;
	char Key;
	buffer[0] = '\0';
	int x1 = 100, y1 = 2, x2 = 145, y2 = 17, min = 115, max = 130, mv = 8, ind1 = 4;
	FILE  *saved_maps;

	print_border(y1, x1, y2, x2);
	mvprintw(y1 + 1, x1 + 15, " S A V E  M A P  A S");
	mvprintw(y1 + 6, x1 + 2, " Map Name :  _______________");
	mvprintw(y1 + 13, x1 + 2, "ESC : Return to main menu ");
	attron(COLOR_WHITE | A_REVERSE);
	mvprintw(y1 + 11, x1 + 1, " Max. 15 characters(letters & num allowed!)");
	attroff(COLOR_WHITE | A_REVERSE);
	refresh();
	while (tru)
	{

		switch (Key = getch()){
		case KEY_UP: case KEY_DOWN: case KEY_LEFT: case KEY_RIGHT:  break;
		case ENTER:if (buffer[0] == '\0') name_it(); else  tru = check_if_legit(buffer); break;
		default: if (j < max) 
		{ buffer[i++] = Key; buffer[i] = '\0'; mvaddch(y1 + 6, j++, Key); 
		}; refresh(); break;
		case BACKSPACE: if (j > min) 
		{ 
			buffer[--i] = '\0'; mvaddch(y1 + 6, --j, '_'); 
		}; refresh(); break;
		case ESC: delete_menu(y1, x1, y2, x2); return 1; break;
		}
	}
	buffer[i] = '.'; buffer[i + 1] = buffer[i + 3] = 't'; buffer[i + 2] = 'x'; buffer[i + 4] = '\0';
	save_it();
	if (!(saved_maps = fopen("saved_maps.txt", "r+"))) saved_maps = fopen("saved_maps.txt", "w");
	i = 0;
	while ((Key = fgetc(saved_maps)) != EOF){   // does this map already exist in the file?
		while (Key == buffer[i])
		{
			Key = fgetc(saved_maps);
			i++;
		}
		if (i == strlen(buffer)) break; else i = 0;
	}
	if (i == strlen(buffer)) fclose(saved_maps); else // if it does->do nothing, if it doesn't, then save it in the file;
	{
		fprintf(saved_maps, "%s\n", buffer);
		fclose(saved_maps);
	}

	delete_menu(y1, x1, y2, x2);
	print_border(y1, x1, y2, x2);
	mvprintw(y1 + 4, x1 + 2, " Continue with editting this map?");
	attron(COLOR_PAIR(8));
	mvprintw(y1 + 6, x1 + 18, " Yes ");
	attroff(COLOR_PAIR(8));
	mvprintw(y1 + 8, x1 + 18, " No ");
	refresh();
	while (1){
		switch (getch()){
		case KEY_UP: menu_up(&mv, y1 + 6, &ind1, x1 + 18); break;
		case KEY_DOWN: menu_down(&mv, y1 + 8, &ind1, x1 + 18); break;
		case ENTER: if (mv == 8)
		{
			delete_menu(y1, x1, y2, x2); return 0;
		}
					else
					{
						delete_menu(y1, x1, y2, x2); return 1;
					}
					break;
		}
	}


}
예제 #7
0
int print_qr_code(
                FILE *output,
                const void *seed,
                size_t seed_size,
                uint64_t start,
                uint64_t interval,
                const char *hn,
                sd_id128_t machine) {

        FILE *f;
        char *url = NULL;
        size_t url_size = 0, i;
        QRcode* qr;
        unsigned x, y;

        assert(seed);
        assert(seed_size > 0);

        f = open_memstream(&url, &url_size);
        if (!f)
                return -ENOMEM;

        fputs_unlocked("fss://", f);

        for (i = 0; i < seed_size; i++) {
                if (i > 0 && i % 3 == 0)
                        fputc_unlocked('-', f);
                fprintf(f, "%02x", ((uint8_t*) seed)[i]);
        }

        fprintf(f, "/%"PRIx64"-%"PRIx64"?machine=" SD_ID128_FORMAT_STR,
                start,
                interval,
                SD_ID128_FORMAT_VAL(machine));

        if (hn)
                fprintf(f, ";hostname=%s", hn);

        if (ferror(f)) {
                fclose(f);
                free(url);
                return -ENOMEM;
        }

        fclose(f);

        qr = QRcode_encodeString(url, 0, QR_ECLEVEL_L, QR_MODE_8, 1);
        free(url);

        if (!qr)
                return -ENOMEM;

        print_border(output, qr->width);

        for (y = 0; y < (unsigned) qr->width; y += 2) {
                const uint8_t *row1, *row2;

                row1 = qr->data + qr->width * y;
                row2 = row1 + qr->width;

                fputs(WHITE_ON_BLACK, output);
                for (x = 0; x < 4; x++)
                        fputs("\342\226\210", output);

                for (x = 0; x < (unsigned) qr->width; x ++) {
                        bool a, b;

                        a = row1[x] & 1;
                        b = (y+1) < (unsigned) qr->width ? (row2[x] & 1) : false;

                        if (a && b)
                                fputc(' ', output);
                        else if (a)
                                fputs("\342\226\204", output);
                        else if (b)
                                fputs("\342\226\200", output);
                        else
                                fputs("\342\226\210", output);
                }

                for (x = 0; x < 4; x++)
                        fputs("\342\226\210", output);
                fputs(NORMAL "\n", output);
        }

        print_border(output, qr->width);

        QRcode_free(qr);
        return 0;
}