MiniDevil As beautiful as a shell
export_utils.c File Reference

Export utilities. More...

#include "builtins.h"
#include "libft.h"
+ Include dependency graph for export_utils.c:

Detailed Description

Export utilities.

Definition in file export_utils.c.

Functions

static int count_env (t_env *env)
 Count the number of nodes in an env list. More...
 
static t_env ** env_to_node_array (t_env *env, int count)
 Convert env linked list to an array of node pointers. More...
 
static void sort_env_array (t_env **arr, int count)
 Sort an array of env node pointers by key in alphabetical order. More...
 
static void print_one_export (t_env *var)
 Print a single env var in "declare -x" format. More...
 
void print_sorted_export (t_env *env)
 Print all env vars sorted in alphabetical order, in declare -x format. More...
 

Function Documentation

◆ count_env()

static int count_env ( t_env env)
static

Count the number of nodes in an env list.

Parameters
envHead of the env list
Returns
Number of nodes

Definition at line 22 of file export_utils.c.

References t_env::next.

Referenced by print_sorted_export().

+ Here is the caller graph for this function:

◆ env_to_node_array()

static t_env** env_to_node_array ( t_env env,
int  count 
)
static

Convert env linked list to an array of node pointers.

Doesn't copy the nodes themselves

Parameters
envHead of the env list
countNumber of nodes
Returns
Array of t_env pointers or NULL

Definition at line 44 of file export_utils.c.

References t_env::next.

Referenced by print_sorted_export().

+ Here is the caller graph for this function:

◆ sort_env_array()

static void sort_env_array ( t_env **  arr,
int  count 
)
static

Sort an array of env node pointers by key in alphabetical order.

Uses a bubble sort on the pointer array (doesn't modify the list)

Parameters
arrArray of env node pointers
countNumber of elements

Definition at line 71 of file export_utils.c.

Referenced by print_sorted_export().

+ Here is the caller graph for this function:

◆ print_one_export()

static void print_one_export ( t_env var)
static

Print a single env var in "declare -x" format.

Parameters
varEnv node to print

Definition at line 100 of file export_utils.c.

References t_env::key, and t_env::value.

Referenced by print_sorted_export().

+ Here is the caller graph for this function:

◆ print_sorted_export()

void print_sorted_export ( t_env env)

Print all env vars sorted in alphabetical order, in declare -x format.

Used by export with no arguments

Parameters
envHead of the env list

Definition at line 120 of file export_utils.c.

References count_env(), env_to_node_array(), print_one_export(), and sort_env_array().

Referenced by builtin_export().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Go to the source code of this file.