Advertisement
Guest User

Untitled

a guest
Apr 9th, 2020
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.27 KB | None | 0 0
  1. #include "shellh.h"
  2.  
  3. /**
  4.  * main - Simple_shell main function
  5.  *
  6.  * @ac: args count
  7.  * @av: args array
  8.  *
  9.  * Return: Always 0.
  10.  */
  11. int main(int ac, char *av[])
  12. {
  13.     char *line;
  14.     size_t len = 0;
  15.     int status = 1, interactive = 0;
  16.     /* int j = 0; */
  17.     char **args;
  18.    
  19.     line = malloc(sizeof(char));
  20.  
  21.     /* revisa si hay una entrada conectada con el stdin */
  22.     if (isatty(STDIN_FILENO) != 0)
  23.             interactive = 1;
  24.     do
  25.     {
  26.         /* Imprime $ y espera el primer comando */
  27.         if(interactive)
  28.             printf("$ ");
  29.  
  30.         /* lee del stdin, controla ctrl + D */
  31.         if (getline(&line, &len, stdin) == -1) {
  32.             printf("\n");
  33.             continue;
  34.         }
  35.  
  36.         /*controla lineas vacias*/
  37.         if(strcmp(line, "\n") == 0){
  38.             continue;    
  39.         }
  40.  
  41.         /* parte la linea y la almacena en un char **str */
  42.         args = _split(line);  
  43.  
  44.         /* for(j = 0; args[j] != NULL; j++)
  45.         {
  46.             printf("posicion %d ----> %s\n",j , args[j]);
  47.            
  48.         } */
  49.  
  50.         /*procesa el array de str y ejecuta dependiendo del tipo */
  51.         status = _processing(args);      
  52.  
  53.     }while (status && interactive);
  54.     free(line);
  55.     free(args);
  56.  
  57.     return (0);
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement