tools.c 628 B

1234567891011121314151617181920212223242526272829303132333435
  1. #include "sh.h"
  2. void sighandler(void)
  3. {
  4. ft_printf("\n%s", PROMPT);
  5. }
  6. void error_message(char *one, char *two, char *three)
  7. {
  8. if (three == NULL || ft_strcmp(three, "exit") == 0)
  9. {
  10. ft_dprintf(2, ">21sh: %s: %s.\n", one, two);
  11. if (three != NULL && ft_strcmp(three, "exit") == 0)
  12. exit(0);
  13. }
  14. else
  15. ft_dprintf(2, ">21sh: %s: %s: %s.\n", one, two, three);
  16. }
  17. /*
  18. ** Check if command contain printable characters to prevent segfault.
  19. */
  20. int check_cmd_presence(char *cmd)
  21. {
  22. int i;
  23. i = -1;
  24. if (ft_strlen(cmd) == 0)
  25. return (2);
  26. while (cmd[++i] != '\0')
  27. if (ft_isvisible(cmd[i]) == 1)
  28. return (1);
  29. return (0);
  30. }