Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --- main.c
- +++ main.c
- @@ -3,20 +3,22 @@
- #include <string.h>
- #include "commands.h"
- -void getArgList(char (*argList)[255]);
- -char rutaActual[255];
- +int getArgList(char (*argList)[255]);
- int main(int argc, char* argv[])
- {
- char argList[20][255];
- + int argCount;
- - strcpy(rutaActual, "hola");
- + setcwd(); // asiganamos ruta actual
- + uname = getenv("USER"); // FIXME: esto devuelve un puntero a char que fue creado localmente, no desaparecerá?
- + host = getenv("HOSTNAME");
- while (1)
- {
- - getArgList(argList);
- + argCount = getArgList(argList);
- - // TEST BEGIN: imprimimos los argumentos
- + /*// TEST BEGIN: imprimimos los argumentos
- int i = 0;
- while (argList[i][0] != '\0')
- {
- @@ -24,35 +26,51 @@
- i++;
- }
- printf("\n");
- - // TEST END
- + // TEST END*/
- // Ejecutamos acciones
- - if (!strcmp(argList[0], ""))
- + if (argCount == 0)
- continue;
- if (!strcmp(argList[0], "quit") || !strcmp(argList[0], "exit") || !strcmp(argList[0], "fin"))
- break;
- if (!strcmp(argList[0], "pid"))
- {
- pid(argList);
- - break;
- + continue;
- + }
- + if (!strcmp(argList[0], "pwd"))
- + {
- + pwd(argList);
- + continue;
- + }
- + if (!strcmp(argList[0], "chdir"))
- + {
- + changedir(argList, argCount);
- + continue;
- + }
- + if (!strcmp(argList[0], "list"))
- + {
- + list(argList, argCount);
- + continue;
- }
- -
- - // TODO: Print error, command not found
- + printf("shell: %s: comando no encontrado...\n", argList[0]);
- }
- return 0;
- }
- -void getArgList(char (*argList)[255])
- +int getArgList(char (*argList)[255])
- {
- char buffer[256];
- - printf("[%s]$ ", rutaActual); // print prompt
- + printf("[%s@%s %s]$ ", uname, host, rutaActual); // print prompt
- fgets(buffer, 255, stdin);
- char* arg;
- int i = 0;
- arg = strtok(buffer, "\n \t");
- if (arg) strcpy(argList[i++], arg);
- - while ((arg = strtok(NULL, "\n \t")))
- + while ((arg = strtok(NULL, "\n \t")) && i <= 20)
- strcpy(argList[i++], arg);
- +
- + return i;
- }
Advertisement
Add Comment
Please, Sign In to add comment