2017-05-14 18:54:39 +00:00
|
|
|
//
|
|
|
|
// Created by Antoine Bartuccio on 14/05/2017.
|
|
|
|
//
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
2017-05-16 17:15:51 +00:00
|
|
|
#include <stdlib.h>
|
2017-05-14 18:54:39 +00:00
|
|
|
#include "fish_core.h"
|
2017-05-16 17:15:51 +00:00
|
|
|
#include "fish_types.h"
|
2017-06-07 16:56:22 +00:00
|
|
|
#include "fish_settings.h"
|
2017-05-14 18:54:39 +00:00
|
|
|
|
|
|
|
/* Necessary global variables */
|
|
|
|
char * builtinCommandsStr[] = {
|
2017-06-11 00:10:11 +00:00
|
|
|
(char *) "clear",
|
2017-05-20 14:25:00 +00:00
|
|
|
(char *) "kek",
|
2017-05-15 22:08:07 +00:00
|
|
|
(char *) "cd",
|
|
|
|
(char *) "help",
|
|
|
|
(char *) "exit"
|
2017-05-14 18:54:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
builtinCommand *builtinCommands[] = {
|
2017-06-11 00:10:11 +00:00
|
|
|
&fishClear,
|
2017-05-20 14:25:00 +00:00
|
|
|
&fishKek,
|
2017-05-15 09:22:53 +00:00
|
|
|
&fishCd,
|
|
|
|
&fishHelp,
|
|
|
|
&fishExit
|
2017-05-14 18:54:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
char ** getBuiltinCommandsStr(){
|
2017-05-15 09:22:53 +00:00
|
|
|
return builtinCommandsStr;
|
2017-05-14 18:54:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
builtinCommand **getBuiltinCommands(){
|
2017-05-15 09:22:53 +00:00
|
|
|
return builtinCommands;
|
2017-05-14 18:54:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int fishCd(WordArray *args) {
|
2017-05-15 09:22:53 +00:00
|
|
|
if (args->size < 2){
|
2017-06-07 16:56:22 +00:00
|
|
|
//fprintf(stderr, "fish: Où sont les arguments de ta commande \"cd\" connard ?!\n");
|
|
|
|
Settings* settings = getSettings();
|
|
|
|
|
|
|
|
if(chdir(settings->passwd->pw_dir) != 0){
|
|
|
|
perror("fish");
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
freeSettings(settings);
|
|
|
|
//return EXIT_SUCCESS;
|
|
|
|
|
2017-05-15 09:22:53 +00:00
|
|
|
} else {
|
|
|
|
if (chdir(args->words[1]) != 0){
|
|
|
|
perror("fish");
|
2017-05-26 16:34:30 +00:00
|
|
|
return EXIT_FAILURE;
|
2017-05-15 09:22:53 +00:00
|
|
|
}
|
|
|
|
}
|
2017-05-17 23:40:26 +00:00
|
|
|
freeWordArray(args);
|
|
|
|
return EXIT_SUCCESS;
|
2017-05-14 18:54:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int fishHelp(WordArray *args) {
|
2017-05-15 09:22:53 +00:00
|
|
|
int i;
|
|
|
|
printf("Bartuccio Antoine, Amalvy Arthur, Yann Chevanton\n");
|
|
|
|
printf("Tape tes putains de noms de programmes et tes arguments de merde et tabasse ENTER !\n");
|
2017-05-15 10:32:00 +00:00
|
|
|
printf("Les commandes suivantes sont internes :\n");
|
2017-05-15 09:22:53 +00:00
|
|
|
for (i=0; i < getNbBuiltins(); i++){
|
|
|
|
printf("\t%s\n", builtinCommandsStr[i]);
|
|
|
|
}
|
|
|
|
printf("Et sinon pour le reste, RTFM !");
|
2017-05-17 23:40:26 +00:00
|
|
|
freeWordArray(args);
|
|
|
|
return EXIT_SUCCESS;
|
2017-05-14 18:54:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int fishExit(WordArray *args) {
|
2017-05-18 00:09:44 +00:00
|
|
|
args->size = args->size;
|
2017-05-16 20:14:06 +00:00
|
|
|
return EXIT_SIGNAL;
|
2017-05-16 17:15:51 +00:00
|
|
|
|
2017-05-14 18:54:39 +00:00
|
|
|
}
|
|
|
|
|
2017-05-20 14:25:00 +00:00
|
|
|
int fishKek(WordArray *args) {
|
|
|
|
freeWordArray(args);
|
|
|
|
printf("Praise kek !");
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2017-05-14 18:54:39 +00:00
|
|
|
int getNbBuiltins() {
|
2017-05-15 09:22:53 +00:00
|
|
|
return sizeof(builtinCommandsStr) / sizeof(char*);
|
2017-05-14 18:54:39 +00:00
|
|
|
}
|
2017-06-11 00:10:11 +00:00
|
|
|
|
|
|
|
void fishSignalHandler(int s) {
|
|
|
|
switch (s) {
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int fishClear(WordArray *args) {
|
|
|
|
if (args != NULL) freeWordArray(args);
|
|
|
|
system("clear");
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|