예제 #1
0
파일: fen.c 프로젝트: GBuella/Taltos
static char*
FEN_print_board(const struct position *pos, char *str, enum player turn)
{
	int empty_count;

	for (int rank = rank_8; ; rank += RSOUTH) {
		empty_count = 0;
		for (int file = file_a; is_valid_file(file); file += EAST) {
			int i = ind(rank, file);
			if (turn == black)
				i = flip_i(i);
			enum piece p = position_piece_at(pos, i);
			enum player player = position_player_at(pos, i);
			if (p != nonpiece) {
				if (empty_count > 0) {
					*str++ = '0' + (char)empty_count;
					empty_count = 0;
				}
				if (turn == black)
					player = opponent_of(player);
				*str++ = square_to_char(p, player);
			}
			else {
				++empty_count;
			}
		}
		if (empty_count > 0)
			*str++ = '0' + empty_count;
		if (rank == rank_1)
			return str;
		else
			*str++ = '/';
	}
}
예제 #2
0
static void cb_preview(raw_box* rb)
{
    char *name;

    name = gtk_file_chooser_get_filename(
                                GTK_FILE_CHOOSER(rb->dialog));
    if (!name)
        return;

    if (!is_valid_file(name))
        return;

    if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(rb->check)))
    {
        int samplerate = gtk_spin_button_get_value_as_int(
                                    GTK_SPIN_BUTTON(rb->samplerate));

        mixer_preview(name, samplerate,  rb->channels, get_format(rb),1);
    }
    else
    {
        int resamp = gtk_toggle_button_get_active(
                            GTK_TOGGLE_BUTTON(rb->resample_checkbox));
        mixer_preview(name, 0, 0, 0, resamp);
    }

    return;
}
예제 #3
0
int			main(int argc, char **argv)
{
	int			nbr_tetris;
	char		**grid;
	t_tetrimino	*tetris;
	t_coord		co;
	t_path		path;

	path.square_size = -1;
	path.path = ft_strnew(27);
	co.x = 0;
	co.y = 0;
	nbr_tetris = -1;
	if (argc != 2 || !(is_valid_file(argv[1])))
		write(1, "error\n", 6);
	else if (!(nbr_tetris = process_file(argv[1], 0, &tetris)))
		write(1, "error\n", 6);
	else
	{
		grid = create_grid(nbr_tetris);
		path = fill_grid(grid, tetris, co, nbr_tetris);
		ft_strrev(path.path);
		grid_from_str(path.path, grid, tetris, co);
		display_grid(grid);
		free_grid(grid);
	}
	return (0);
}
예제 #4
0
파일: rgenstat.c 프로젝트: GYGit/reactos
/* Win32 version */
static void
process_directory (char *path, char *cvspath)
{
  struct _finddata_t f;
  int findhandle;
  char searchbuf[MAX_PATH];
  char buf[MAX_PATH];
  char newcvspath[MAX_PATH];

  strcpy(searchbuf, path);
  strcat(searchbuf, "*.*");

  findhandle =_findfirst(searchbuf, &f);
  if (findhandle != -1)
    {
      do
      	{
          if (f.attrib & _A_SUBDIR)
      	    {
              if (f.name[0] != '.')
                {
                  strcpy(buf, path);
                  strcat(buf, f.name);
                  strcat(buf, DIR_SEPARATOR_STRING);

                  strcpy(newcvspath, cvspath);
                  strcat(newcvspath, f.name);
                  strcat(newcvspath, "/");

                  process_directory(buf, newcvspath);
                }
              continue;
      	    }

          strcpy(buf, path);
          strcat(buf, f.name);

          /* Must be a .c file */
          if (!is_valid_file(buf))
            {
              continue;
            }

          parse_file(buf, cvspath, f.name);
      	}
      while (_findnext(findhandle, &f) == 0);
      _findclose(findhandle);
    }
  else
    {
      printf("Cannot open directory '%s'", path);
      exit(1);
    }
}
예제 #5
0
int get_filesize(char* filename) {
  if (!(is_valid_file(filename)))
    return -1;

  FILE* f = fopen(filename, "r");
  fseek(f, 0L, SEEK_END);
  int filesize = (int) ftell(f);
  fseek(f, 0L, SEEK_SET);
  fclose(f);
  return filesize;
}
예제 #6
0
파일: fat16.c 프로젝트: cyrusmaintea/N64HDD
//returns real file index from filtered index 
uint32_t fat16_get_file_index(fat_entry *entry, uint32_t filtered_index) {
	int i;
	int j=0;
	for(i=0;i<__SWAP16(fat_boot.root_dir_entries);i++) {
		if(is_valid_file(&entry[i])==0){
			if(j==filtered_index)
				return i;
			j++;
		}				
	}
	return 0;
}
예제 #7
0
파일: file.c 프로젝트: RasterCode/wke
static CURLcode file_done(struct connectdata *conn,
                          CURLcode status, bool premature)
{
    struct FILEPROTO *file = conn->data->state.proto.file;
    (void)status; /* not used */
    (void)premature; /* not used */
    Curl_safefree(file->freepath);

    if(is_valid_file(file->fd))
        file_close((void*)file->fd);

    return CURLE_OK;
}
예제 #8
0
파일: menu.c 프로젝트: MarcDeletang/42_1
int				count_scene(t_env *e)
{
	int				nb_button;
	DIR				*dp;
	struct dirent	*ep;

	nb_button = 0;
	if ((dp = opendir("scenes/")))
	{
		while ((ep = readdir(dp)))
		{
			if (ep->d_name[0] != '.')
				nb_button = nb_button + is_valid_file(ep->d_name);
		}
		closedir(dp);
	}
	else
		ft_error(1, e, "Couldn't open the directory.");
	return (nb_button);
}
예제 #9
0
파일: rgenstat.c 프로젝트: GYGit/reactos
/* Linux version */
static void
process_directory (char *path, char *cvspath)
{
  DIR *dirp;
  struct dirent *entry;
  struct stat stbuf;
  char buf[MAX_PATH];
  char newcvspath[MAX_PATH];

#ifdef HAVE_D_TYPE
  dirp = opendir(path);
  if (dirp != NULL)
    {
      while ((entry = readdir(dirp)) != NULL)
        {
          if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)
            continue; // skip self and parent

      	  if (entry->d_type == DT_REG) // normal file
      	    {
              // Check for an absolute path
              if (path[0] == DIR_SEPARATOR_CHAR)
                {
                  strcpy(buf, path);
                  strcat(buf, DIR_SEPARATOR_STRING);
                  strcat(buf, entry->d_name);
                }
              else
                {
                  if (!getcwd(buf, sizeof(buf)))
                    {
                      printf("Can't get CWD: %s\n", strerror(errno));
                      return;
                    }
                  strcat(buf, DIR_SEPARATOR_STRING);
                  strcat(buf, path);
                  strcat(buf, entry->d_name);
                }

      	      if (stat(buf, &stbuf) == -1)
                {
                  printf("Can't access '%s' (%s)\n", buf, strerror(errno));
                  return;
                }

              if (S_ISDIR(stbuf.st_mode))
          	    {
                  strcpy(newcvspath, cvspath);
                  strcat(newcvspath, f.name);
                  strcat(newcvspath, "/");

                  process_directory(buf, newcvspath);
                  continue;
          	    }

              /* Must be a .c file */
              if (!is_valid_file(buf))
                {
                  continue;
                }

              parse_file(buf, cvspath, entry->d_name);
           }
      }
      closedir(dirp);
    }
  else
    {
      printf("Can't open %s\n", path);
      exit(1);
    }

#else

  dirp = opendir(path);
  if (dirp != NULL)
    {
      while ((entry = readdir(dirp)) != NULL)
      	{
          if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)
            continue; // skip self and parent

          // Check for an absolute path
          if (path[0] == DIR_SEPARATOR_CHAR)
            {
              strcpy(buf, path);
              strcat(buf, DIR_SEPARATOR_STRING);
              strcat(buf, entry->d_name);
            }
          else
            {
              if (!getcwd(buf, sizeof(buf)))
                {
                  printf("Can't get CWD: %s\n", strerror(errno));
                  return;
                }
              strcat(buf, DIR_SEPARATOR_STRING);
              strcat(buf, path);
              strcat(buf, entry->d_name);
            }

          if (stat(buf, &stbuf) == -1)
            {
              printf("Can't access '%s' (%s)\n", buf, strerror(errno));
              return;
            }

          if (S_ISDIR(stbuf.st_mode))
      	    {
              strcpy(newcvspath, cvspath);
              strcat(newcvspath, entry->d_name);
              strcat(newcvspath, "/");

              process_directory(buf, newcvspath);
              continue;
      	    }

          /* Must be a .c file */
          if (!is_valid_file(buf))
            {
              continue;
            }

          parse_file(buf, cvspath, entry->d_name);
        }
      closedir(dirp);
    }
  else
    {
      printf("Can't open %s\n", path);
      exit(1);
    }

#endif
}
예제 #10
0
파일: file.c 프로젝트: RasterCode/wke
/*
 * file_connect() gets called from Curl_protocol_connect() to allow us to
 * do protocol-specific actions at connect-time.  We emulate a
 * connect-then-transfer protocol and "connect" to the file here
 */
static CURLcode file_connect(struct connectdata *conn, bool *done)
{
    struct SessionHandle *data = conn->data;
    char *real_path = curl_easy_unescape(data, data->state.path, 0, NULL);
    struct FILEPROTO *file;
    int fd;
#ifdef DOS_FILESYSTEM
    int i;
    char *actual_path;
#endif

    if(!real_path)
        return CURLE_OUT_OF_MEMORY;

    /* If there already is a protocol-specific struct allocated for this
       sessionhandle, deal with it */
    Curl_reset_reqproto(conn);

    if(!data->state.proto.file) {
        file = calloc(1, sizeof(struct FILEPROTO));
        if(!file) {
            free(real_path);
            return CURLE_OUT_OF_MEMORY;
        }
        data->state.proto.file = file;
    }
    else {
        /* file is not a protocol that can deal with "persistancy" */
        file = data->state.proto.file;
        Curl_safefree(file->freepath);

        if(is_valid_file(file->fd))
            file_close((void*)file->fd);

        file->path = NULL;
        file->freepath = NULL;
        file->fd = -1;
    }

#ifdef DOS_FILESYSTEM
    /* If the first character is a slash, and there's
       something that looks like a drive at the beginning of
       the path, skip the slash.  If we remove the initial
       slash in all cases, paths without drive letters end up
       relative to the current directory which isn't how
       browsers work.

       Some browsers accept | instead of : as the drive letter
       separator, so we do too.

       On other platforms, we need the slash to indicate an
       absolute pathname.  On Windows, absolute paths start
       with a drive letter.
    */
    actual_path = real_path;
    if((actual_path[0] == '/') &&
            actual_path[1] &&
            (actual_path[2] == ':' || actual_path[2] == '|'))
    {
        actual_path[2] = ':';
        actual_path++;
    }
    /*wke++++++*/
    else if (actual_path[0] == '/')
    {
        actual_path++;
    }
    /*wke++++++*/

    /* change path separators from '/' to '\\' for DOS, Windows and OS/2 */
    for (i=0; actual_path[i] != '\0'; ++i)
        if(actual_path[i] == '/')
            actual_path[i] = '\\';

    fd = (int)file_open(actual_path); /* no CR/LF translation */
    file->path = actual_path;
#else
    fd = file_open(real_path);
    file->path = real_path;
#endif
    file->freepath = real_path; /* free this when done */

    file->fd = fd;
    if(!data->set.upload && !is_valid_file(fd)) {
        failf(data, "Couldn't open file %s", data->state.path);
        file_done(conn, CURLE_FILE_COULDNT_READ_FILE, FALSE);
        return CURLE_FILE_COULDNT_READ_FILE;
    }
    *done = TRUE;

    return CURLE_OK;
}