_getline.c- int _getline(char *input, int size)
- int exit_shell(char *line)
|
- Description
- _getline() uses _strprint to reads an entire line from standard input, storing the address of the buffer containing the text into *lineptr. The buffer is null-terminated and includes the newline character, if one was found.
- Return value
- If *input is NULL, then _getline() will allocate a buffer for storing the line, which should be freed by the user program. (In this case, the value in *n is ignored.)
- On success, _getline() return the number of characters read, including the delimiter character, but not including the terminating null byte ('\0'). This value can be used to handle embedded null bytes in the line read.
- Both functions return -1 on failure to read a line (including end-of-file condition). In the event of an error, errno is set to indicate the cause.
|
_strtok.c- int count_words(char *str, char delim)
- int _wrdlen(char *s, char delim)
- char **strtow(char *str, char delim)
|
- Description
- This program is our implementation of the strtok() function which extracts tokens from strings.
- The _strtok() function breaks a string into a sequence of zero or more nonempty tokens. On the first call to _strtok() the string to be parsed should be specified in
str . In each subsequent call that should parse the same string, str must be NULL. - The delim argument specifies a set of bytes that delimit the tokens in the parsed string. The caller may specify different strings in delim in successive calls that parse the same string.
- Each call to _strtok() returns a pointer to a null-terminated string containing the next token. This string does not include the delimiting byte. If no more tokens are found, _strtok() returns
NULL .
- Return value
- Returns string tokenized into words
- The
_strtok() functions return a pointer to the next token, or NULL if there are no more tokens.
|
array_list.cint arr_size(char **arr) list_t *array_to_list(char **array)
|
- Description
- This program builds a linked list of an array of pointers.
- Return value
- A pointer of type
list_t to head
|
lists.csize_t print_list(const list_t *h) size_t list_len(const list_t *h) list_t *add_node(list_t \*\*head, const char *str) list_t *add_node_end(list_t \*\*head, const char *str) void free_list(list_t *head)
|
- Description
print_list(const list_t *h) prints all elements of a linked list pointed to by *hsize_t list_len(const list_t *h) calculates the number of elements in a linked list pointed to by *hlist_t *add_node(list_t **head, const char *str) adds node to the beginning of a linked listlist_t *add_node_end(list_t **head, const char *str) adds node to the end of a linked listvoid free_list(list_t *head) frees a linked list of type
- Return value
print_list() prints elements of list to stdoutsize_t list_len() length of listlist_t *add_node() address of the new element, NULL if failedlist_t *add_node_end() address of the new element, NULL if failedvoid free_list() n/a
|
main.c |
- |
more_strings.c - _strcmp(char *s1, char *s2)
- char *_strchr(const char *str, char c)
- int len_to_char(char *str, char c)
|
- Description
int _strcmp(char *s1, char *s2) - compare strings s1 and s2- char *_strchr(const char *str, char c) - locate character in a string
int len_to_cha r(char *str, char c) - calculate length of string str up to char c <\ul>- Return value
int _strcmp(char *s1, char *s2) - return an integer less than, equal to, or greater than zero if s1 is found to be less than, to match, or to be greater than s2- char *_strchr(const char *str, char c) - a pointer to the matched character or NULL if the character is not found.
- int len_to_char(char *str, char c) - length of string before char, 0 if char not found
|
prints.c - int _putchar(char c)
- void _strprint(char *str)
- void print_array(char **array)
|
- Description
_putchar - writes the character c to stdout- _strprint - prints a string
- print_array - Prints an array of strings
- Return value
- Return: On success 1. On error, -1 is returned, and errno is set appropriately.
|
shell.h |
- Description
- header file for ScarJo shell
- Return value
|
strings.c - int _strlen(char *s)
- int _strncmp(char *s1, char *s2, int n)
- char *_strcpy(char *dest, char *src)
- char *_strcat(char *dest, char *src)
- char *_strdup(char *str)
|
- Description
_strlen(const char *s) returns the length of a string- int _strncmp(char *s1, const char *s2, int n) - compares two strings for n amount of chars
- char *_strcpy(char *dest, const char *src) - copies the string with \0 to the buffer
- char *_strcat(char *dest, const char *src) - appends the src string to the dest string
- char *_strdup(char *str) - returns a pointer to a newly allocated space in memory, which contains a copy of the string given as a parameter
- Return value
- _strlen(const char *s) - Return: 0 on success
- int _strncmp(char *s1, const char *s2, int n) - Return: 0 if identical
- char *_strcpy(char *dest, const char *src) - Return: the pointer to dest
- char *_strcat(char *dest, const char *src) - pointer to resulting string dest
- char *_strdup(char *str) - pointer to new string or NULL if str = NULL
|
built_ins.c - int built_ins(char **input, list_t **env_head)
- int exit_bi(char **line)
- int print_env(char **line, list_t **env_head)
- int set_env(char **line, list_t **env_head)
- int unset_env(char **line, list_t **env_head)
|
- Description
built_ins - checks if command is a built-in @input: tokenized line from the command line @env_head: pointer to environ list- exit_bi - exits shell with given status @line: tokenized line from command line @env_head: pointer to environ list
- print_env - prints current environ @line: tokenized line from command line @env_head: pointer to environ list
- set_env - initializes a new environment variable, or modify an existing one @line: tokenized line from command line @env_head: pointer to environ list
- unset_env - removes environment variable @line: tokenized line from command line @env_head: pointer to environ list
- Return value
built_ins - 0 on success, 1 on error, -1 if not found- exit_bi - 0 on success, 1 on error
- print_env - 0 on success, 1 on error
- set_env - 0 on success, 1 on error
- unset_env - 0 on success, 1 on error
|
cmd_line_loop.c int cmd_line_loop(char *buffer, char *line, list_t **env_head) |
- Description
- cmd_line_loop - calls getline until user enters exit or EOF(ctrl^D) @buffer: pointer to buffer to store input @line: pointer to a string of line input @env_head: pointer to head of environ list
- Return value
- Return: 0 on success or 1 if _realloc failed
|
new_env.c char *_getenv(char *name, list_t **env_head) int _setenv(char *name, char *value, list_t **env_head) int _unsetenv(char *name, list_t **env_head) int delete_node(list_t **head, char *string) char *var_str(char *name, char *value)
|
- Description
- _getenv - gets an environment variable. (without using getenv) @name: environment variable name @env_head: pointer to environ list
- _setenv - changes or adds the variable to the environment with the value, if variable does not already exist. If it does exist in the environment, then its value is changed to value @name: name of the variable @value: value of the variable @env_head: pointer to environ list
- _unsetenv - deletes the variable name from the environment. If name does not exist in the environment, then the function succeeds, and the environment is unchanged. @name:name of the environment variable @env_head: pointer to environ list
- delete_node - deletes the node with string of a list_t @head: pointer to head pointer @string: pointer to the node that should be deleted
- var_str - creates new variable string @name: name of the variable @value: value of the variable
- Return value
- _getenv - pointer to a string with that env variable or NULL if not found
- _setenv - pointer to head of the list or NULL if it failed
- _unsetenv - Always 0 on success, or 1 on error
- delete_node - 0 if it succeeded, 1 if it failed
- var_str - pointer to new string or NULL if failed
|
run_command.c char **path_dirs_array(list_t **env_head) char *cmd_in_path(char *str, list_t **env_head) int run_command(char **line_tok, list_t **env_head, char *buffer)
|
Descriptionpath_dirs_array - makes array of pointers for all dirs in the PATHcmd_in_path - finds command in the PATH @str: pointer to first string in input line (command) @env_head: pointer to environ listrun_command - runs the command typed into shell prompt @line_tok: tokenized input line @env_head: pointer to environ list Return valuepath_dirs_array - Return: Array of pointerscmd_in_path - Return: pointer to absolute path of command or NULL if not foundrun_command - Return: Always 0 on success, 1 on error
|
environment.cchar \*_getenv(const char *name) - int _putenv(char *str)
- int _setenv(const char *name, const char *value, int overwrite)
- int _unsetenv(const char *name)
int delete_node(list_t \*\*head, char *string)
|
- Description
- Contains helper functions that interact with environment variables.
-
*_getenv(const char *name) searches environment list to find environment variable name and returns a pointer to the corresponding value string. -
int _putenv(char *str) changes or adds value of an environment variable -
int _setenv(const char *name, const char *value, int overwrite) change or add an environment variable -
int _unsetenv(const char *name) deletes the environment variable name from the environment -
int delete_node(list_t \**head, char *string) deletes the node with string of of a list_t
- Return value
*\_getenv(const char *name) returns a pointer to the value in the environment, or NULL if there is no match \_putenv() returns zero on success, or nonzero if an error occurs. In the event of an error, errno is set to indicate the cause. \_setenv() returns zero on success, or -1 on error, with errno set to indicate the cause of the error \_unsetenv() returns zero on success, or -1 on error, with errno set to indicate the cause of the error delete_node() returns 0 on success, or -1 on error
|