#include "cmd.h" extern int yyparse(); char hostname[100]; char *username; char pwd[100]; int main(int argc, char **argv) { // get the hostname, username and current working directory // to show the prompt gethostname(hostname, sizeof(hostname)); getcwd(pwd, sizeof(pwd)); username = getpwuid(getuid())->pw_name; showPrompt(); while (true) { yyparse(); } return 0; } void showPrompt() { if (getuid() == 0) { printf("%s@%s:%s# ", username, hostname, pwd); } else { printf("\033[01;32m%s" "\033[35m@%s\033[00m:" "\033[33m%s\033[00m$ ", username, hostname, pwd); } fflush(stdout); } void argInsert(struct Command *cmd, char *s, bool isStr) { if (cmd->argc == 0) { cmd->args = malloc(2 * sizeof(char *)); } else { cmd->args = realloc(cmd->args, (cmd->argc + 2) * sizeof(char *)); } if (isStr) { cmd->args[cmd->argc] = strdup(s + 1); cmd->args[cmd->argc][strlen(cmd->args[cmd->argc]) - 1] = '\0'; free(s); } else { cmd->args[cmd->argc] = s; } cmd->args[cmd->argc + 1] = NULL; cmd->argc++; }