Beispiel #1
0
/**
 * Applies the function fn to each element of the Queue.
 *
 * @param[in] queue the queue on which this operation is performed
 * @param[in] fn the operation function that is to be invoked on each queue element
 */
void queue_foreach(Queue *queue, void (*fn) (void*))
{
    deque_foreach(queue->d, fn);
}
Beispiel #2
0
/**
 * Removes and frees all element from the specified Deque.
 *
 * @note This function does not shrink the Deque's capacity.
 * @note This function should not be called on Deques that have some
 *       of their elements allocated on stack.
 *
 * @param[in] deque Deque from which all elements are being removed
 */
void deque_remove_all_free(Deque *deque)
{
    deque_foreach(deque, deque->mem_free);
    deque_remove_all(deque);
}
Beispiel #3
0
/**
 * Recursive iteration for file finding
 *
 * @param __dir - directory to search file in
 * @param __rel_dir - relative director name to search file in
 * @param __options - finding options
 * @param __res_wnd - window with results
 * @return zero on success, non-zero otherwise
 */
static int
find_iteration (const wchar_t *__dir, const wchar_t *__rel_dir,
                const action_find_options_t *__options,
                action_find_res_wnd_t *__res_wnd)
{
  int i, j, count;
  vfs_dirent_t **eps = NULL;
  size_t fn_len;
  wchar_t *format, *full_name;
  vfs_stat_t stat;
  vfs_stat_proc stat_proc;
  deque_t *dirs;
  wchar_t **dir_data;

  __res_wnd->dir_opened = FALSE;

  /* Get listing of directory */

  /*
   * TODO: Add separately displaying of directories and files
   */

  count = vfs_scandir (__dir, &eps, 0, vfs_alphasort);

  if (count < 0)
    {
      /* Error getting listing */
      return ACTION_ERR;
    }

  if (TEST_FLAG(__options->flags, AFF_FIND_RECURSIVELY))
    {
      dirs = deque_create ();
    }

  /* Get function for stat'ing */
  if (TEST_FLAG(__options->flags, AFF_FOLLOW_SYMLINKS))
    {
      stat_proc = vfs_stat;
    }
  else
    {
      stat_proc = vfs_lstat;
    }

  /* Allocate memory for full file name */
  fn_len = wcslen (__dir) + MAX_FILENAME_LEN + 1;
  full_name = malloc ((fn_len + 1) * sizeof (wchar_t));

  /* Get format mask for correct directory drilling */
  if (__dir[wcslen (__dir) - 1] == '/')
    {
      format = L"%ls%ls";
    }
  else
    {
      format = L"%ls/%ls";
    }

  for (i = 0; i < count; ++i)
    {
      if (IS_PSEUDODIR (eps[i]->name))
        {
          vfs_free_dirent (eps[i]);
          continue;
        }

      set_searching_status (__res_wnd, L"Searching in", __rel_dir);

      /* Get full file name */
      swprintf (full_name, fn_len, format, __dir, eps[i]->name);

      /* Stat current node of FS */
      if (!stat_proc (full_name, &stat) == VFS_OK)
        {
          /* Error getting status of file */
          vfs_free_dirent (eps[i]);
          continue;
        }

      if (S_ISREG (stat.st_mode))
        {
          if (check_regular_file (eps[i]->name, full_name,
                                  __options, __res_wnd))
            {
              append_result (__rel_dir, eps[i]->name, stat, __res_wnd);
              ++__res_wnd->found_files;
            }
        }
      else if (S_ISDIR (stat.st_mode))
        {
          /* Of user wants directories to be found... */
          if (TEST_FLAG(__options->flags, AFF_FIND_DIRECTORIES))
            {
              if (check_directory (eps[i]->name, full_name,
                                   __options, __res_wnd))
                {
                  append_result (__rel_dir, eps[i]->name, stat, __res_wnd);
                  ++__res_wnd->found_dirs;
                }
            }

          if (TEST_FLAG(__options->flags, AFF_FIND_RECURSIVELY))
            {
              dir_data = malloc (2 * sizeof (wchar_t));
              dir_data[0] = wcsdup (eps[i]->name);
              dir_data[1] = wcsdup (full_name);
              deque_push_back (dirs, (void*)dir_data);
            }
        }
      else
        {
          if (check_special_file (eps[i]->name, full_name,
                                  __options, __res_wnd))
            {
              append_result (__rel_dir, eps[i]->name, stat, __res_wnd);
              ++__res_wnd->found_files;
            }
        }

      vfs_free_dirent (eps[i]);

      hook_call (L"switch-task-hook", NULL);

      if (ACTION_PERFORMED (__res_wnd))
        {
          /* Free remain dirents */
          for (j = i + 1; j < count; ++j)
            {
              vfs_free_dirent (eps[j]);
            }
          break;
        }
    }

  SAFE_FREE (eps);
  free (full_name);

  if (TEST_FLAG(__options->flags, AFF_FIND_RECURSIVELY) &&
      !ACTION_PERFORMED (__res_wnd))
    {
      void *data;
      wchar_t *rel_name;

      if (__rel_dir[wcslen (__rel_dir) - 1] == '/')
        {
          format = L"%ls%ls";
        }
      else
        {
          format = L"%ls/%ls";
        }

      fn_len = wcslen (__dir) + MAX_FILENAME_LEN + 1;
      rel_name = malloc ((fn_len + 1) * sizeof (wchar_t));

      deque_foreach (dirs, data);
        /* Drill relative file name */

        dir_data = data;
        if (!ACTION_PERFORMED (__res_wnd))
          {
            swprintf (rel_name, fn_len, format, __rel_dir, dir_data[0]);
            find_iteration (dir_data[1], rel_name, __options, __res_wnd);
          }
        free (dir_data);
      deque_foreach_done
    }