Quellcode durchsuchen

:tada: Creation fichiers execute (pour lancer commande)

Loquicom vor 6 Jahren
Ursprung
Commit
efdc8bda8b
4 geänderte Dateien mit 52 neuen und 4 gelöschten Zeilen
  1. 22 0
      execute.c
  2. 18 0
      execute.h
  3. 5 3
      makefile
  4. 7 1
      mysh.c

+ 22 - 0
execute.c

@@ -0,0 +1,22 @@
+/* 
+ * File:   execute.c
+ * Author: Arthur Brandao
+ *
+ * Created on 9 novembre 2018
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include "error.h"
+#include "execute.h"
+
+/* --- Fonctions publiques --- */
+boolean is_executable_file(const char * cmd) {
+    int result;
+    result = access(cmd, X_OK);
+    if(result == ERR){
+        return false;
+    }
+    return true;
+}

+ 18 - 0
execute.h

@@ -0,0 +1,18 @@
+/* 
+ * File:   execute.h
+ * Author: Arthur Brandao
+ *
+ * Created on 9 novembre 2018
+ */
+
+#ifndef EXECUTE_H
+#define EXECUTE_H
+
+/* --- Include --- */
+#include "constante.h"
+
+/* --- Fonctions publiques --- */
+boolean is_executable_file(const char *);
+
+#endif /* EXECUTE_H */
+

+ 5 - 3
makefile

@@ -3,7 +3,7 @@
 #
 
 EXEC = mysh
-OBJETS = error.o str.o parser.o wildcard.o command.o
+OBJETS = error.o str.o parser.o wildcard.o command.o execute.o
 NOM_PROJET = mini-shell
 
 #
@@ -92,5 +92,7 @@ error.o: error.c str.h error.h
 str.o: str.c str.h
 parser.o: parser.c error.h str.h wildcard.h constante.h parser.h
 wildcard.o: wildcard.c error.h wildcard.h constante.h
-command.o: command.c str.h command.h constante.h
-mysh.o: mysh.c error.h str.h parser.h constante.h command.h mysh.h
+command.o: command.c error.h str.h parser.h constante.h command.h
+execute.o: execute.c error.h execute.h constante.h
+mysh.o: mysh.c error.h str.h parser.h constante.h command.h execute.h \
+ mysh.h

+ 7 - 1
mysh.c

@@ -12,6 +12,7 @@
 #include "str.h"
 #include "parser.h"
 #include "command.h"
+#include "execute.h"
 #include "mysh.h"
 
 #include <sys/types.h>
@@ -51,7 +52,12 @@ int main(int argc, char* argv[]) {
     char str[BUFFER_SIZE];
     int a;
     //Initialisation erreur
-    error_finit("mysh.log");   
+    error_finit("mysh.log");
+    
+    printf("%d\n", is_executable_file("../TP4/exo1"));
+    
+    error.exit();
+    
     //Recup ligne
     //printf("%s\n", fgets(str, 500, stdin));&
     memset(str, 0, 500);