C Map String to Function
- by Scriptonaut
So, I'm making a Unix minishell, and have come to a roadblock. I need to be able to execute built-in functions, so I made a function:
int exec_if_built_in(char **args)
It takes an array of strings(the first being the command, and the rest being arguments). For non built-in commands I simply use something like execvp, however I need to find a way to map the first string to a function. I was thinking of making two arrays, one of strings, and another with their corresponding function pointers. However, since many of these functions will be different(return and accept different things), this approach won't work. I also thought of making an array of structs with a name property and a function pointer property, however once again due to the varied nature of the functions I'll be using, this won't work.
So, what's the best way to execute a function based on the input of a string? How do I map a string to a certain function? I'm not very familiar with function pointers so I may be missing something.
Thank you guys for the help :)