Advertisement
Guest User

check_builtins.c

a guest
May 26th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.99 KB | None | 0 0
  1. /*
  2. ** EPITECH PROJECT, 2019
  3. ** PSU_minishell2_2018
  4. ** File description:
  5. ** check_builtins
  6. */
  7.  
  8. #include "my.h"
  9.  
  10. const builtin_t cmd_builtins[] = {
  11.     {"env", display_env},
  12.     {"unsetenv", my_unsetenv},
  13.     {"setenv", my_setenv},
  14.     {"exit", my_exit},
  15.     {"cd", cd_cmd},
  16.     {"echo", my_echo},
  17.     {NULL, NULL}
  18. };
  19.  
  20. void my_echo(env_t *env, command_t *cmd)
  21. {
  22.     (void)env;
  23.     if (cmd->args[1][0] == '$') {
  24.         cmd->args[1]++;
  25.         printf("%s\n", find_node(env, cmd->args[1])->content);
  26.     } else {
  27.         for (int i = 1; cmd->args[i] != NULL; i++) {
  28.             my_putstr(cmd->args[i]);
  29.             (cmd->args[i + 1] != NULL) ? my_putstr(" ") : 0;
  30.         }
  31.         my_putstr("\n");
  32.     }
  33. }
  34.  
  35. int check_builtins(command_t *cmd, env_t *env)
  36. {
  37.     for (int i = 0; cmd_builtins[i].cmd != NULL; i++) {
  38.         if (my_strcmp(cmd->cmd, cmd_builtins[i].cmd) == 0) {
  39.             cmd_builtins[i].funct(env, cmd);
  40.             return (1);
  41.         }
  42.     }
  43.     return (0);
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement