MiniDevil As beautiful as a shell
export_ops.c File Reference

Export helpers. More...

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

Detailed Description

Export helpers.

Definition in file export_ops.c.

Functions

void export_no_value (t_env **env, char *key)
 Export a variable with no value (export KEY) More...
 
void export_assign (t_env **env, char *arg)
 Export a variable with a value (export KEY=value) More...
 
static char * get_append_value (t_env *env, char *key, char *append_str)
 Build the new value for an append operation. More...
 
void export_append (t_env **env, char *arg)
 Export a variable with append (export KEY+=value) More...
 

Function Documentation

◆ export_no_value()

void export_no_value ( t_env **  env,
char *  key 
)

Export a variable with no value (export KEY)

  • If the key already exists, do nothing
  • If it does not, create a new node with value=NULL
Parameters
envPointer to env list head
keyVariable name to export

Definition at line 26 of file export_ops.c.

References add_env_node(), t_env::key, t_env::next, and t_env::value.

Referenced by export_one().

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

◆ export_assign()

void export_assign ( t_env **  env,
char *  arg 
)

Export a variable with a value (export KEY=value)

Split the argument at = to extract key and value then call set_env_value() to create or update the variable

Parameters
envPointer to env list head
argFull argument string containing = somewhere

Definition at line 55 of file export_ops.c.

References set_env_value().

Referenced by export_one().

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

◆ get_append_value()

static char* get_append_value ( t_env env,
char *  key,
char *  append_str 
)
static

Build the new value for an append operation.

If the variable already exists, concatenates old value with append_str(), and if not then duplicates append_str as the new value

Parameters
envEnvironment list for looking up existing value
keyVariable name
append_strString to append
Returns
Newly allocated value

Definition at line 82 of file export_ops.c.

References append_str(), and get_env_value().

Referenced by export_append().

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

◆ export_append()

void export_append ( t_env **  env,
char *  arg 
)

Export a variable with append (export KEY+=value)

Splits at += and builds the appended value using get_append_value() then calls set_env_value() to update the variable

Parameters
envPointer to env list head
argFull arg string containing "+="

Definition at line 104 of file export_ops.c.

References get_append_value(), and set_env_value().

Referenced by export_one().

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

Go to the source code of this file.