esh_types.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 struct {
  27. char** command;
  28. ESH_COMMAND_TYPE command_type;
  29. ESH_JOB_TYPE job_type;
  30. ESH_JOB_CONDITION job_start_condition;
  31. pid_t job_pid;
  32. FILE* job_stdin;
  33. FILE* job_stdout;
  34. FILE* job_stderr;
  35. int stdin_pipe[2];
  36. int stdout_pipe[2]; // 0 is for writing in child process and for reading in parent process.
  37. int stderr_pipe[2]; // 1 is for writing in parent process and for reading in child process.
  38. } EShJob;
  39. typedef struct {
  40. char* build_ref;
  41. struct passwd* user_data;
  42. char* current_working_dir;
  43. char* config_file_path; // path to file, containing configurations (changeable via cmd line args)
  44. char* history_file_path; // path to file, where entered commands history is stored (changeable via settings/cmd line args)
  45. int history_limit; // max lines of commands, which can be stored (changeable via settings/cmd line args)
  46. int max_jobs_number; // max active jobs (foreground & background) limit (changeable via settings/cmd line args)
  47. int max_command_length; // max length of single command (changeable via settings/cmd line args)
  48. char** history_command_list;
  49. int history_command_list_size;
  50. int max_invite_message_len;
  51. char* invite_message;
  52. int jobs_number;
  53. EShJob* jobs_list;
  54. int exited; // used to stop threads on exiting
  55. } EShInfo;
  56. extern EShInfo* esh_info_global;
  57. #endif // ESH_TYPES_H