1
0
mirror of https://gitlab.com/klmp200/fish.git synced 2024-11-21 16:23:20 +00:00

Settings terminées

This commit is contained in:
Ame 2017-06-12 13:29:19 +02:00
parent 40fda08947
commit e72f28c95c
3 changed files with 43 additions and 1 deletions

View File

@ -72,7 +72,7 @@ void fishLoop(Settings * settings){
pipe_redirection *r = getRedirection(); pipe_redirection *r = getRedirection();
do { do {
printf("%s", settings->PS1); printPS(settings->PS1, settings);
line = fishReadLine(); line = fishReadLine();
r->to_use = 0; r->to_use = 0;

View File

@ -46,6 +46,45 @@ void freeSettings(Settings *settings){
} }
} }
void printPS(char* PS, Settings* s){
int buf= FISH_BUFFER_SIZE;
int i = 0;
int slashed = 0;
char* path = NULL;
while (PS[i] != '\0'){
if(slashed){
switch (PS[i])
{
case 'u':
printf("%s",s->passwd->pw_name);
break;
case 'p':
path = (char*) malloc(sizeof(char)*buf);
while(getcwd(path,buf) == NULL){
buf+=FISH_BUFFER_SIZE;
free(path);
path = (char*) malloc(sizeof(char)*buf);
}
printf("%s",path);
free(path);
path = NULL;
break;
default:printf("%c",PS[i]);
}
slashed = 0;
}
else if(PS[i] == '\\'){
slashed = 1;
}else{
printf("%c",PS[i]);
}
++i;
}
}
char* extractVariable(char* filename, char* var){ char* extractVariable(char* filename, char* var){
FILE *file = fopen ( filename, "r" ); FILE *file = fopen ( filename, "r" );
int var_size = strlen(var); int var_size = strlen(var);
@ -81,3 +120,5 @@ char* extractVariable(char* filename, char* var){
} }

View File

@ -9,6 +9,7 @@
Settings * getSettings(); //TESTEDssssss Settings * getSettings(); //TESTEDssssss
void freeSettings(Settings *settings); //TESTED void freeSettings(Settings *settings); //TESTED
char* extractVariable(char* filename, char* var);//TESTED char* extractVariable(char* filename, char* var);//TESTED
void printPS(char* PS, Settings* s);
#endif //FISH_FISH_SETTINGS_H #endif //FISH_FISH_SETTINGS_H