esh_types.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #include <stdio.h>
  2. #include <pthread.h>
  3. #include <time.h>
  4. #include <stdlib.h>
  5. #include <pwd.h>
  6. #include <string.h>
  7. #include <unistd.h>
  8. #include <limits.h>
  9. #include <termios.h>
  10. #include <sys/wait.h>
  11. #ifndef ESH_TYPES_H
  12. #define ESH_TYPES_H
  13. typedef enum {
  14. BACKGROUND,
  15. FOREGROUND
  16. } ESH_JOB_TYPE;
  17. typedef enum {
  18. INNER_CMD,
  19. EXEC_CMD
  20. } ESH_COMMAND_TYPE;
  21. typedef enum {
  22. NO_CONDITION, // ex. commands delimited by ';'
  23. PREVIOUS_EXIT_SUCCESS, // ex. commands delimited by '&&'
  24. PREVIOUS_EXIT_FAILED // ex. commands delimited by '||'
  25. } ESH_JOB_CONDITION;
  26. typedef enum {
  27. LOGIC_AND = 1,
  28. LOGIC_OR = 2,
  29. SEMICOLON = 3,
  30. BIT_AND = 4,
  31. BIT_OR = 5,
  32. NOT_A_DELIMITER = 0
  33. } ESH_JOB_DELIMITER;
  34. typedef struct {
  35. char* command;
  36. char** command_tokens;
  37. int command_tokens_num;
  38. ESH_COMMAND_TYPE command_type;
  39. ESH_JOB_TYPE job_type;
  40. ESH_JOB_CONDITION job_start_condition;
  41. pid_t job_pid;
  42. FILE* job_stdin;
  43. FILE* job_stdout;
  44. FILE* job_stderr;
  45. int stdin_pipe[2];
  46. int stdout_pipe[2]; // 0 is for writing in child process and for reading in parent process.
  47. int stderr_pipe[2]; // 1 is for writing in parent process and for reading in child process.
  48. } EShJob;
  49. typedef struct {
  50. char* build_ref;
  51. struct passwd* user_data;
  52. char* current_working_dir;
  53. char* config_file_path; // path to file, containing configurations (changeable via cmd line args)
  54. char* history_file_path; // path to file, where entered commands history is stored (changeable via settings/cmd line args)
  55. int history_limit; // max lines of commands, which can be stored (changeable via settings/cmd line args)
  56. // TODO: set this to max background jobs limit!
  57. int max_jobs_number; // max active jobs (foreground & background) limit (changeable via settings/cmd line args)
  58. int max_command_length; // max length of single command (changeable via settings/cmd line args)
  59. int max_command_tokens; // TODO: max arguments of single command
  60. int max_command_token_size; // TODO
  61. char** history_command_list;
  62. int history_command_list_size;
  63. int max_invite_message_len;
  64. char* invite_message;
  65. int jobs_number;
  66. EShJob* jobs_list;
  67. int exited; // used to stop threads on exiting
  68. } EShInfo;
  69. extern EShInfo* esh_info_global;
  70. #endif // ESH_TYPES_H