move the remove variable sysmbols function to utils

This commit is contained in:
Chris Cromer 2021-07-17 21:27:39 -04:00
parent 8f57501927
commit 56a6747e06
4 changed files with 22 additions and 21 deletions

View File

@ -219,17 +219,3 @@ void echo(StringArray *args) {
}
free_string_array(no_variables);
}
char *remove_variable_symbol(char *original_variable) {
char *variable = malloc((strlen(original_variable)) * sizeof(char *));
if (variable == NULL) {
perror("malloc");
exit(EXIT_FAILURE);
}
memset(variable, 0, strlen(original_variable));
for (size_t i = 0; i < strlen(original_variable); i++) {
variable[i] = original_variable[i + 1];
}
return variable;
}

View File

@ -62,11 +62,4 @@ void set_variable(StringArray *args);
*/
void echo(StringArray *args);
/**
* Remove the $ symbol from a variable name.
* @param original_variable The original variable name.
* @return Returns the string without the $ symbool.
*/
char *remove_variable_symbol(char *original_variable);
#endif

View File

@ -27,4 +27,12 @@ void remove_new_line(char *line);
* @return Returns the current working directory.
*/
char *get_working_directory();
/**
* Remove the $ symbol from a variable name.
* @param original_variable The original variable name.
* @return Returns the string without the $ symbool.
*/
char *remove_variable_symbol(char *original_variable);
#endif

View File

@ -33,3 +33,17 @@ char *get_working_directory() {
}
return cwd;
}
char *remove_variable_symbol(char *original_variable) {
char *variable = malloc((strlen(original_variable)) * sizeof(char *));
if (variable == NULL) {
perror("malloc");
exit(EXIT_FAILURE);
}
memset(variable, 0, strlen(original_variable));
for (size_t i = 0; i < strlen(original_variable); i++) {
variable[i] = original_variable[i + 1];
}
return variable;
}