1
0
mirror of https://gitlab.com/klmp200/fish.git synced 2024-11-14 12:53:20 +00:00
fish/fish_shell/fish_commands.c

99 lines
1.9 KiB
C
Raw Normal View History

//
// Created by Antoine Bartuccio on 14/05/2017.
//
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include "fish_core.h"
#include "fish_types.h"
#include "fish_settings.h"
/* Necessary global variables */
char * builtinCommandsStr[] = {
(char *) "clear",
(char *) "kek",
2017-05-15 22:08:07 +00:00
(char *) "cd",
(char *) "help",
(char *) "exit"
};
builtinCommand *builtinCommands[] = {
&fishClear,
&fishKek,
2017-05-15 09:22:53 +00:00
&fishCd,
&fishHelp,
&fishExit
};
char ** getBuiltinCommandsStr(){
2017-05-15 09:22:53 +00:00
return builtinCommandsStr;
}
builtinCommand **getBuiltinCommands(){
2017-05-15 09:22:53 +00:00
return builtinCommands;
}
int fishCd(WordArray *args) {
2017-05-15 09:22:53 +00:00
if (args->size < 2){
//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;
}
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;
}
int fishExit(WordArray *args) {
args->size = args->size;
return EXIT_SIGNAL;
}
int fishKek(WordArray *args) {
freeWordArray(args);
printf("Praise kek !");
return EXIT_SUCCESS;
}
int getNbBuiltins() {
2017-05-15 09:22:53 +00:00
return sizeof(builtinCommandsStr) / sizeof(char*);
}
void fishSignalHandler(int s) {
switch (s) {
default:
break;
}
}
int fishClear(WordArray *args) {
if (args != NULL) freeWordArray(args);
system("clear");
return EXIT_SUCCESS;
}