|
@@ -31,76 +31,9 @@ int result_cmd = -1;
|
|
|
char base_path[BUFFER_SIZE];
|
|
|
pid_list pidlist;
|
|
|
|
|
|
+/* --- Globale --- */
|
|
|
int job = 1;
|
|
|
|
|
|
-/* --- Fonctions privées --- */
|
|
|
-void test_write() {
|
|
|
- char* a = "azerty\n";
|
|
|
- int tmp = write(1, a, strlen(a));
|
|
|
- printf("%d\n", tmp);
|
|
|
-}
|
|
|
-
|
|
|
-void test_tmp_file(){
|
|
|
- int a;
|
|
|
- FILE* f = tmpfile();
|
|
|
- printf("F : %d\n", f == NULL);
|
|
|
- int fd = fileno(f);
|
|
|
- printf("%d : %ld\n", fd, write(fd, "bonjour", 8));
|
|
|
- a = lseek(fd, 0L, SEEK_SET);
|
|
|
- sleep(2);
|
|
|
- char buf[10];
|
|
|
- memset(buf, 0 , 10);
|
|
|
- a = read(fd, buf, 10);
|
|
|
- printf("%d : %s\n", a, buf);
|
|
|
- close(fd);
|
|
|
-}
|
|
|
-
|
|
|
-void test(){
|
|
|
- CommandTab ct;
|
|
|
- char str[BUFFER_SIZE];
|
|
|
- int a;
|
|
|
- //Initialisation structures
|
|
|
- error_finit("mysh.log");
|
|
|
- ini_pid_list(&pidlist);
|
|
|
-
|
|
|
- //Recup ligne
|
|
|
- //printf("%s\n", fgets(str, 500, stdin));&
|
|
|
- memset(str, 0, 500);
|
|
|
- a = read(STDIN, str, 500);
|
|
|
- printf("%s\n", str);
|
|
|
- //Separe les commandes
|
|
|
- a = parse_line(&ct, str);
|
|
|
- if(a == SHELL_ERR){
|
|
|
- addserror("Erreur lors du parse de la ligne");
|
|
|
- error.exit_err();
|
|
|
- }
|
|
|
- //Parse les commandes
|
|
|
- a = parse_all_command(&ct);
|
|
|
- if(a == SHELL_FAIL){
|
|
|
- addserror("Erreur lors du parse des commandes");
|
|
|
- error.exit_err();
|
|
|
- }
|
|
|
- //Affiche resultat
|
|
|
- for (int i = 0; i < ct.length; i++) {
|
|
|
- Command* c = ct.cmd[i];
|
|
|
- printf("Commande %d (%s) : \n", i, c->name);
|
|
|
- for (int j = 0; j < c->argc; j++) {
|
|
|
- printf(" Argument %d : %s\n", j, c->argv[j]);
|
|
|
- }
|
|
|
- printf("Commande en fond : %d\n\n", ct.bck);
|
|
|
- //Si c'est une commande interne on l'execute
|
|
|
- if(is_internal_cmd(ct.cmd[i]->name)){
|
|
|
- show_current_dir(NULL, "\n");
|
|
|
- printf("Result : %d\n", launch_internal_command(ct.cmd[i]));
|
|
|
- show_current_dir(NULL, "\n");
|
|
|
- }
|
|
|
- }
|
|
|
- //Nettoyage structures
|
|
|
- clean_command(&ct);
|
|
|
- clean_pid(&pidlist);
|
|
|
- error.exit();
|
|
|
-}
|
|
|
-
|
|
|
/* --- Fonctions utilitaires --- */
|
|
|
void show_current_dir(const char* before, const char* after) {
|
|
|
char buffer[BUFFER_SIZE];
|