GPAK  1.0.0
A general-purpose archive library

◆ filesystem_iterator_next_directory()

GPAK_API filesystem_tree_node_t* filesystem_iterator_next_directory ( filesystem_tree_iterator_t _iterator)
Brief Description:\n Retrieves the next directory in the filesystem tree.

This function returns the next directory node in the filesystem tree using a depth-first search algorithm.

Parameters
_iteratorA pointer to the filesystem_tree_iterator_t.
Returns
A pointer to the next directory node or NULL if there are no more directories.

Definition at line 294 of file filesystem_tree.c.

295 {
296  if (_iterator->stack_size_ == 0)
297  return NULL;
298 
299  filesystem_iterator_state_t current_state = _iterator->stack_[_iterator->stack_size_ - 1];
300 
301  if (current_state.child_index_ < current_state.node_->num_children_)
302  {
303  filesystem_tree_node_t* next_directory = current_state.node_->children_[current_state.child_index_];
304  filesystem_iterator_state_t child_state = { .node_ = next_directory, .child_index_ = 0, .file_index_ = 0 };
305 
306  // Update the current state's child_index
307  current_state.child_index_++;
308  _iterator->stack_[_iterator->stack_size_ - 1] = current_state;
309 
310  // Push the child_state onto the stack
311  _iterator_stack_push(_iterator, child_state);
312 
313  return next_directory;
314  }
315  else
316 
317  // If there are no more children, remove the current state from the stack
318  _iterator_stack_pop(_iterator);
319 
320  // Call the function recursively to find the next directory
321  return filesystem_iterator_next_directory(_iterator);
322 }
GPAK_API filesystem_tree_node_t * filesystem_iterator_next_directory(filesystem_tree_iterator_t *_iterator)
filesystem_tree_node_t * node_
Definition: gpak_data.h:347
filesystem_iterator_state_t * stack_
Definition: gpak_data.h:367
struct filesystem_tree_node ** children_
Definition: gpak_data.h:326

References filesystem_iterator_state::child_index_, filesystem_tree_node::children_, filesystem_iterator_state::node_, filesystem_tree_node::num_children_, filesystem_tree_iterator::stack_, and filesystem_tree_iterator::stack_size_.

Referenced by _gpak_compressor_generate_dictionary().