#include #include #include #include "helper_functions.c" #include "lsh_main_func.c" #include "lsh_builtins.c" typedef struct{ char *prompt; char *pre_prompt; } SHELL_OB; void lsh_loop(SHELL_OB *shell_obj) { char *line; char **args; int status; do { //get pwd char *cwd= getenv("PWD"); char *pwd=basename(cwd); snprintf(shell_obj->prompt,sizeof(char) * 1024,"%s %s> ",shell_obj->pre_prompt,pwd); free(pwd); printf("%s",shell_obj->prompt); line = lsh_read_line(); args = lsh_split_line(line); status = lsh_execute(args); free(line); int i=0; while (args[i]) free(args[i++]); free(args); } while (status); } int main(int argc, char **argv){ //set sh level char *shlvl = getenv("SHLVL"); if(shlvl != NULL){ int shlvli = atoi(shlvl); shlvli++; sprintf(shlvl,"%d",shlvli); setenv("SHLVL",shlvl,1); } //Set The prompt SHELL_OB shell_obj; shell_obj.prompt = (char *)malloce(sizeof(char) * 1024); shell_obj.pre_prompt = (char *)malloce(sizeof(char) * 1024); //get the hostname char *hostname = (char *)malloce(sizeof(char) * 1024); gethostname(hostname,sizeof(char) * 1024); //set the pre_prompt snprintf(shell_obj.pre_prompt,sizeof(char) * 1024,"%s@%s",getenv("USER"),hostname); free(hostname); lsh_loop(&shell_obj); free(shell_obj.prompt); free(shell_obj.pre_prompt); return EXIT_SUCCESS; }