move comments to headers
This commit is contained in:
@@ -17,40 +17,126 @@
|
||||
|
||||
#ifndef _MYSHELLIN_ARRAY
|
||||
#define _MYSHELLIN_ARRAY
|
||||
|
||||
/**
|
||||
* This struct houses a dynamically sized string array.
|
||||
*/
|
||||
typedef struct {
|
||||
/**
|
||||
* The array.
|
||||
*/
|
||||
char **array;
|
||||
|
||||
/**
|
||||
* The amount of elements in the array.
|
||||
*/
|
||||
size_t size;
|
||||
} StringArray;
|
||||
|
||||
/**
|
||||
* This struct is used to clean up memory on exit.
|
||||
*/
|
||||
typedef struct {
|
||||
/**
|
||||
* The array of memory to clean.
|
||||
*/
|
||||
void **array;
|
||||
|
||||
/**
|
||||
* The amount of elements in the array.
|
||||
*/
|
||||
size_t size;
|
||||
} CleanArray;
|
||||
|
||||
/**
|
||||
* This struct has an array list with key value pairs based on strings.
|
||||
*/
|
||||
typedef struct {
|
||||
/**
|
||||
* The keys array.
|
||||
*/
|
||||
StringArray *keys;
|
||||
|
||||
/**
|
||||
* The values array.
|
||||
*/
|
||||
StringArray *values;
|
||||
|
||||
/**
|
||||
* The amount of elements in the array list.
|
||||
*/
|
||||
size_t size;
|
||||
} ArrayList;
|
||||
|
||||
/**
|
||||
* A global clean array to use on exit.
|
||||
*/
|
||||
CleanArray clean;
|
||||
|
||||
/**
|
||||
* A global variables array used for environment variables and values.
|
||||
*/
|
||||
ArrayList *variables;
|
||||
|
||||
/**
|
||||
* Create a String Array by initializing its structure.
|
||||
* @return Returns a new String Array.
|
||||
*/
|
||||
StringArray *create_string_array();
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
/**
|
||||
* Free the String Array and all of its strings.
|
||||
* @param string_array The String Array to free.
|
||||
*/
|
||||
void free_string_array(StringArray *string_array);
|
||||
|
||||
/**
|
||||
* Create a new Array List.
|
||||
* @return Returns the newly created Array List.
|
||||
*/
|
||||
ArrayList *create_array_list();
|
||||
|
||||
/**
|
||||
* Set a key inside the Array List.
|
||||
* @param array_list The Array List to work on.
|
||||
* @param key The key to insert/update.
|
||||
* @param value The value to insert/update.
|
||||
*/
|
||||
void set_array_list(ArrayList *array_list, char *key, char *value);
|
||||
|
||||
/**
|
||||
* Get a value based on a key from an Array List.
|
||||
* @param array_list The Array List to work on.
|
||||
* @param key The key to search for.
|
||||
* @return Returns the value if the key is found in the Array List otherwise it returns NULL.
|
||||
*/
|
||||
char *get_array_list(ArrayList *array_list, char *key);
|
||||
|
||||
/**
|
||||
* Remove a key from the Array List.
|
||||
* @param array_list The Array List to work on.
|
||||
* @param key The key to remove.
|
||||
*/
|
||||
void unset_array_list(ArrayList *array_list, char *key);
|
||||
|
||||
/**
|
||||
* Free all the memory used in the Array List.
|
||||
* @param array_list The Array List to free.
|
||||
*/
|
||||
void free_array_list(ArrayList *array_list);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -18,11 +18,30 @@
|
||||
|
||||
#ifndef _MYSHELLIN_BUILTINS
|
||||
#define _MYSHELLIN_BUILTINS
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
/**
|
||||
* Run the builtin command.
|
||||
* @param args An array of strings containing the arguments to run.
|
||||
*/
|
||||
void run_builtin(StringArray *args);
|
||||
|
||||
/**
|
||||
* Exit the shell.
|
||||
* @param args The arguments that were used to call exit. This is used to free the memory before exit.
|
||||
*/
|
||||
void exit_shell(StringArray *args);
|
||||
|
||||
/**
|
||||
* Change the directory to what the user inputs.
|
||||
* @param args The arguments the user input.
|
||||
*/
|
||||
void change_directory(StringArray *args);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -15,17 +15,42 @@
|
||||
|
||||
#ifndef _MYSHELLIN_CONSOLE_LINE
|
||||
#define _MYSHELLIN_CONSOLE_LINE
|
||||
|
||||
#define CONSOLE_BUFFER_SIZE 1024
|
||||
|
||||
/**
|
||||
* Remove new line from the end of a string.
|
||||
* @param line The string to remove the new line from.
|
||||
*/
|
||||
void remove_new_line(char *line);
|
||||
|
||||
/**
|
||||
* Get the logged in user's username.
|
||||
* @return Returns the logged in user's username.
|
||||
*/
|
||||
char *get_username();
|
||||
|
||||
/**
|
||||
* Get the hostname of the machine.
|
||||
* @return Returns the hostname.
|
||||
*/
|
||||
char *get_hostname();
|
||||
|
||||
/**
|
||||
* Get the current working directory of the shell.
|
||||
* @return Returns the current working directory.
|
||||
*/
|
||||
char *get_working_directory();
|
||||
|
||||
/**
|
||||
* Print the console line before the user input.
|
||||
*/
|
||||
void print_input_line();
|
||||
|
||||
/**
|
||||
* Get input from the console.
|
||||
* @return Returns a string input by the user.
|
||||
*/
|
||||
char *get_console_input();
|
||||
|
||||
#endif
|
||||
|
||||
@@ -17,5 +17,11 @@
|
||||
|
||||
#ifndef _MYSHELLIN_LAUNCH
|
||||
#define _MYSHELLIN_LAUNCH
|
||||
|
||||
/**
|
||||
* Launch programs from the OS.
|
||||
* @param args The arguments to launch.
|
||||
*/
|
||||
void launch_program(StringArray *args);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -15,9 +15,21 @@
|
||||
|
||||
#ifndef _MYSHELLIN_LOOP
|
||||
#define _MYSHELLIN_LOOP
|
||||
|
||||
/**
|
||||
* Add memory address to array to be cleaned up later.
|
||||
* @param data The data to be cleaned up on exit.
|
||||
*/
|
||||
void add_to_cleanup(void *data);
|
||||
|
||||
/**
|
||||
* Cleanup memory when exiting.
|
||||
*/
|
||||
void exit_cleanup();
|
||||
|
||||
/**
|
||||
* This is the loop that checks for user input and acts on it.
|
||||
*/
|
||||
void loop();
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user