#include "esh_misc.h" void EShOptimiseCurrentWorkingDirectory() { if (strstr(esh_info_global->current_working_dir, esh_info_global->user_data->pw_dir) == esh_info_global->current_working_dir) { char new_cwd[PATH_MAX + 1]; memset(new_cwd, 0, PATH_MAX + 1); strcat(new_cwd, "~"); strcat(new_cwd, esh_info_global->current_working_dir + strlen(esh_info_global->user_data->pw_dir)); strcpy(esh_info_global->current_working_dir, new_cwd); } } void EShUpdateInviteMessage() { memset(esh_info_global->invite_message, 0, (esh_info_global->max_invite_message_len + 1) * sizeof(char)); strcat(esh_info_global->invite_message, ANSI_COLOR_BLUE); strcat(esh_info_global->invite_message, esh_info_global->user_data->pw_name); strcat(esh_info_global->invite_message, ANSI_COLOR_RESET); strcat(esh_info_global->invite_message, "@"); strcat(esh_info_global->invite_message, ANSI_COLOR_GREEN); strcat(esh_info_global->invite_message, esh_info_global->current_working_dir); strcat(esh_info_global->invite_message, ANSI_COLOR_RESET); strcat(esh_info_global->invite_message, " ยป "); } void EShShowHelpAndExit() { printf(ANSI_COLOR_RED "ESh (Endevir Shell) build %.8s\n" ANSI_COLOR_RESET "\n" "Usage: esh [-h] [-config FILENAME] [-history FILENAME] [-history_limit INT] [-max_active_jobs INT] [-max_command_length INT]\n" "\n" "Description:\n" "This is a simple shell, written in C\n" "\n" "Parameters:\n" "-h shows this message and exits\n" "-config FILENAME uses file with name FILENAME as config file (default: ~/.esh_conf)\n" "-history_path FILENAME uses file with name FILENAME as storage for entered commands history (default: ~/.esh_history)\n" "-history_limit INT limits commands number to keep up to INT (default: 5000 lines)\n" "-max_active_jobs INT limits shell active jobs number up to INT (default: 64)\n" "-max_command_length INT limits maximum length of single command up to INT (default: 1024 chars)\n" "\n" "\n" "Copyleft. Written by Ivan Arkhipov aka Endevir (me@endevir.ru), MIPT, Dolgoprudny, Russia, 2019.\n", esh_info_global->build_ref); exit(0); } int EShIsShellLetter(char c) { // TODO: Russian symbols return (c >= 32 && c <= 127); } ESH_JOB_DELIMITER EshIsJobDelimiter(char* c) { if (strstr(c, "&&") == c) { return LOGIC_AND; } if (strstr(c, "||") == c) { return LOGIC_OR; } if (strstr(c, "&") == c) { return BIT_AND; } if (strstr(c, "|") == c) { return BIT_OR; } if (strstr(c, ";") == c || strstr(c, "\n") == c) { return SEMICOLON; } return NOT_A_DELIMITER; } int EShGetJobDelimiterSize(ESH_JOB_DELIMITER delim) { if (delim == LOGIC_AND || delim == LOGIC_OR) { return 2; } if (delim == BIT_AND || delim == BIT_OR || delim == SEMICOLON) { return 1; } return 0; }