Skip to content
Snippets Groups Projects
Commit ea0e4874 authored by Sébastien Gendre's avatar Sébastien Gendre
Browse files

Use prefix on functions

parent 774c3b2d
No related branches found
No related tags found
No related merge requests found
......@@ -3,7 +3,7 @@
#include "command.h"
int parse_user_input_to_command(char *user_input, cmd_t *cmd) {
int command_from_str(char *str, cmd_t *cmd) {
// Stor next command argument, used in the do…while loop
char* next_arg;
......@@ -15,7 +15,7 @@ int parse_user_input_to_command(char *user_input, cmd_t *cmd) {
cmd->foreground = true;
// Extract the commmand name
cmd->command = strtok(user_input, DELIMITERS);
cmd->command = strtok(str, DELIMITERS);
// Extract the command arguments
......@@ -43,7 +43,7 @@ int parse_user_input_to_command(char *user_input, cmd_t *cmd) {
}
void dispose_command(cmd_t *cmd) {
void command_dispose(cmd_t *cmd) {
// Free the command name str
free(cmd->command);
// Free all the command arguments str inside argv
......
......@@ -31,7 +31,7 @@ struct cmd {
* Return:
* -1 in case of error otherwise 0.
*/
int parse_user_input_for_command(char *user_input, cmd_t *cmd);
int command_from_str(char *str, cmd_t *cmd);
/* Dispose of the command, which free some allocated memory
......@@ -40,7 +40,7 @@ int parse_user_input_for_command(char *user_input, cmd_t *cmd);
* Parameters:
* - cmd: The command to dispose of
*/
void dispose_command(cmd_t *cmd);
void command_dispose(cmd_t *cmd);
#endif /* COMMAND_H */
......@@ -8,11 +8,11 @@
// user_input: a string with the user input. The user should take care of the
// allocation.
// return: 0 if an empty input was given, -1 if the function failed to read stdin
int ask_user_input(char* user_input) {
int interface_ask_user_input(char* user_input) {
// Show the prompt and get user input
printf(DEFAULT_PROMPT);
printf(PROMPT_DEFAULT);
printf(" ");
if(fgets(user_input, USER_INPUT_MAX_LENGTH, stdin) == NULL)
if(fgets(user_input, LIMIT_USER_INPUT_MAX_LENGTH, stdin) == NULL)
return -1;
//Ensure that the end of line chars are removed
......@@ -23,7 +23,7 @@ int ask_user_input(char* user_input) {
//Print command for debugging
void print_command(cmd_t cmd) {
void interface_print_command(cmd_t cmd) {
printf("Command:\n");
printf("\t- Name: %s\n", cmd.command);
printf("\t- Arguments count: %d\n", cmd.argc);
......
......@@ -19,7 +19,7 @@
Return:
0 if an empty input was given, -1 if the function failed to read stdin
*/
int ask_user_input(char* user_input);
int interface_ask_user_input(char* user_input);
/* Print command for debugging
......@@ -27,6 +27,6 @@ int ask_user_input(char* user_input);
- cmd: The command to print
*/
void print_command(cmd_t cmd);
void interface_print_command(cmd_t cmd);
#endif /* INTERFACES_H */
......@@ -5,6 +5,6 @@
#ifndef LIMITS_H
#define LIMITS_H
#define USER_INPUT_MAX_LENGTH 2048 //Maximum line length in the terminal
#define LIMIT_USER_INPUT_MAX_LENGTH 2048 //Maximum line length in the terminal
#endif /* LIMITS_H */
......@@ -5,7 +5,7 @@
#define PROMPT_H
// Default prombt to print
#define DEFAULT_PROMPT "$>"
#define PROMPT_DEFAULT "$>"
#endif /* PROMPT_H */
......@@ -14,12 +14,12 @@ int main(int argc, char *argv[])
cmd_t command;
int command_parse_result = 0;
user_input = calloc(USER_INPUT_MAX_LENGTH, sizeof(char));
user_input = calloc(LIMIT_USER_INPUT_MAX_LENGTH, sizeof(char));
while(1){
ask_user_input(user_input);
command_parse_result = parse_user_input_to_command(user_input, &command);
print_command(command);
interface_ask_user_input(user_input);
command_parse_result = command_from_str(user_input, &command);
interface_print_command(command);
}
return 0;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment