add missing documentation for functions
This commit is contained in:
parent
907af65b94
commit
4ea527064a
18
src/array.c
18
src/array.c
@ -16,11 +16,20 @@
|
||||
#include <string.h>
|
||||
#include "array.h"
|
||||
|
||||
/**
|
||||
* Create a String Array by initializing its structure.
|
||||
* @param string_array The String Array to create.
|
||||
*/
|
||||
void create_string_array(StringArray *string_array) {
|
||||
string_array->array = NULL;
|
||||
string_array->size = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert a string into the String Array.
|
||||
* @param string_array The String Array to insert into.
|
||||
* @param string The string to insert into the String Array.
|
||||
*/
|
||||
void insert_string_array(StringArray *string_array, char *string) {
|
||||
if (string_array->size == 0) {
|
||||
string_array->array = malloc(sizeof(char *));
|
||||
@ -33,6 +42,11 @@ void insert_string_array(StringArray *string_array, char *string) {
|
||||
string_array->size++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a string from the String Array.
|
||||
* @param string_array The String Array to delete from.
|
||||
* @param index The index in the String Array to delete.
|
||||
*/
|
||||
void delete_string_array(StringArray *string_array, int index) {
|
||||
if (string_array->size > 0 && string_array->size > index) {
|
||||
for (int i = index; i < string_array->size - 1; i++) {
|
||||
@ -48,6 +62,10 @@ void delete_string_array(StringArray *string_array, int index) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Free the String Array and all of its strings.
|
||||
* @param string_array The String Array to free.
|
||||
*/
|
||||
void free_string_array(StringArray *string_array) {
|
||||
for (int i = 0; i < string_array->size; i++) {
|
||||
free(string_array->array[i]);
|
||||
|
@ -18,6 +18,11 @@
|
||||
#include "array.h"
|
||||
#include "builtins.h"
|
||||
|
||||
/**
|
||||
* Check if the command is a builtin or not.
|
||||
* @param command String with the command name to check.
|
||||
* @return Returns true if it's a builtin or false otherwise.
|
||||
*/
|
||||
bool is_builtin(char *command) {
|
||||
if (strcmp(command, "exit") == 0) {
|
||||
return true;
|
||||
@ -30,12 +35,20 @@ bool is_builtin(char *command) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the builtin command.
|
||||
* @param string_array An array of strings containing the arguments to run.
|
||||
*/
|
||||
void run_builtin(StringArray *string_array) {
|
||||
if (strcmp(string_array->array[0], "exit") == 0) {
|
||||
exit_shell(string_array);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Exit the shell.
|
||||
* @param string_array The arguments that were used to call exit. This is used to free the memory before exit.
|
||||
*/
|
||||
void exit_shell(StringArray *string_array) {
|
||||
free_string_array(string_array);
|
||||
exit(EXIT_SUCCESS);
|
||||
|
@ -59,6 +59,10 @@ void print_input_line() {
|
||||
free(cwd);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get input from the console.
|
||||
* @return Returns a string input by the user.
|
||||
*/
|
||||
char *get_console_input() {
|
||||
size_t buffer_size = 0;
|
||||
char *line = NULL;
|
||||
|
Loading…
Reference in New Issue
Block a user