|
@@ -11,12 +11,22 @@
|
|
|
#include "mysh.h"
|
|
|
|
|
|
/* --- Fonctions privées --- */
|
|
|
-void test_write(){
|
|
|
+void test_write() {
|
|
|
char* a = "azerty\n";
|
|
|
int tmp = write(1, a, strlen(a));
|
|
|
printf("%d\n", tmp);
|
|
|
}
|
|
|
|
|
|
+/* --- Fonctions utilitaires --- */
|
|
|
+void show_current_dir(const char* before, const char* after) {
|
|
|
+ char buffer[512];
|
|
|
+ if (getcwd(buffer, sizeof (buffer)) == NULL) {
|
|
|
+ perror("Erreur getcwd() : ");
|
|
|
+ } else {
|
|
|
+ printf("%s%s%s", before, buffer, after);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
/* --- Main --- */
|
|
|
int main(int argc, char* argv[]) {
|
|
|
|
|
@@ -35,10 +45,10 @@ int main(int argc, char* argv[]) {
|
|
|
a = parse_all_command(&ct);
|
|
|
printf("Result : %d\n\n", a);
|
|
|
//Affiche resultat
|
|
|
- for(int i = 0; i < ct.length; i++){
|
|
|
+ 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++){
|
|
|
+ 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);
|
|
@@ -50,35 +60,22 @@ int main(int argc, char* argv[]) {
|
|
|
}
|
|
|
|
|
|
/* --- Commandes internes --- */
|
|
|
-void cd(int argc, char** argv){
|
|
|
+void cd(int argc, char** argv) {
|
|
|
//Si trop d'arguments
|
|
|
- if(argc > 2) {
|
|
|
- printf("too many arguments : 1 required, %d given\n", argc-1);
|
|
|
- }
|
|
|
- else {
|
|
|
+ if (argc > 2) {
|
|
|
+ printf("too many arguments : 1 required, %d given\n", argc - 1);
|
|
|
+ } else {
|
|
|
//Si aucun argument on vas à la racine
|
|
|
- if(argc == 1) {
|
|
|
- if(chdir("/") == ERR){
|
|
|
+ if (argc == 1) {
|
|
|
+ if (chdir("/") == ERR) {
|
|
|
perror("Erreur chdir() : ");
|
|
|
}
|
|
|
- }
|
|
|
- //Sinon on va dans le dossier indiqué par l'utilisateur
|
|
|
+ } //Sinon on va dans le dossier indiqué par l'utilisateur
|
|
|
else {
|
|
|
- if(chdir(argv[1]) == ERR){
|
|
|
+ if (chdir(argv[1]) == ERR) {
|
|
|
printf("path does not exist\n");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
//show_current_dir("current working directory is: ", "\n");
|
|
|
-}
|
|
|
-
|
|
|
-/* --- Fonctions utilitaires --- */
|
|
|
-void show_current_dir(const char* before, const char* after){
|
|
|
- char buffer[512];
|
|
|
- if (getcwd(buffer, sizeof(buffer)) == NULL){
|
|
|
- perror("Erreur getcwd() : ");
|
|
|
- }
|
|
|
- else {
|
|
|
- printf("%s%s%s", before, buffer, after);
|
|
|
- }
|
|
|
}
|