Browse Source

dump 23.05

Ivan Arkhipov 5 years ago
parent
commit
22f9333948
3 changed files with 31 additions and 15 deletions
  1. 4 2
      esh_init.c
  2. 21 12
      esh_main_loop.c
  3. 6 1
      esh_types.h

+ 4 - 2
esh_init.c

@@ -10,7 +10,8 @@ void EShInit(int argc, char** argv) {
 	EShProcessConfigFile();
 	EShProcessHistoryFile();
 
-	printf("===================================\n"
+	printf("\n"
+		   "===================================\n"
 		   "Hello, %s!\n"
 		   "This is Endevir Shell (ESh)\n"
 		   "ESh build %.8s\n"
@@ -22,7 +23,8 @@ void EShInit(int argc, char** argv) {
 		   "Max history lines: %d\n"
 		   "Max running jobs: %d\n"
 		   "Max single command length: %d\n"
-		   "===================================\n",
+		   "===================================\n"
+		   "\n",
 		   esh_info_global->user_data->pw_name, 
 		   esh_info_global->build_ref,
 		   esh_info_global->user_data->pw_dir,

+ 21 - 12
esh_main_loop.c

@@ -180,15 +180,12 @@ void EShRunLoop() {
 		}
 
 		EShAddCommandToHistory(command);
-		int pid = fork();
-		if (pid == 0) {
-			execlp(command, command, NULL);
-			printf("Esh: run command %s failed.\n", command);
-			exit(1); // execlp failed
-		} else {
-			waitpid(pid, NULL, 0);
-			printf("\n");
-		}
+		
+		EShJob* jobs;
+		int jobs_num;
+
+		EShParseCommandIntoJobs(command, &jobs, &jobs_num);
+		EShExecuteJobs(jobs_num, jobs);
 	}
 
     /* restore the original terminal attributes */
@@ -200,12 +197,14 @@ void EShShowMsg() {
 	printf("%s", esh_info_global->invite_message);
 }
 
-void EShParseCommandIntoJobs(char* command) {
+void EShParseCommandIntoJobs(char* command, EShJob** jobs_ptr, int* jobs_num_ptr) {
 
 }
 
 void EShExecuteJobs(int jobs_num, EShJob* jobs_list) {
-
+	for (int i = 0;  i < jobs_num; ++i) {
+		EShRunJob(jobs_list[i]);
+	}
 }
 
 void EShSetJobCommandType(EShJob* job) {
@@ -213,7 +212,17 @@ void EShSetJobCommandType(EShJob* job) {
 }
 
 void EShRunJob(EShJob* job) {
-
+	// TODO: PIPES INIT & BG PROCESS SUPPORT
+
+	int pid = fork();
+	if (pid == 0) {
+		execvp(job->command[0], job->command);
+		printf("Esh: run command %s failed.\n", job->command);
+		exit(1); // execlp failed
+	} else {
+		waitpid(pid, NULL, 0);
+		printf("\n");
+	}
 }
 
 int EmptyCommand(const char* command) {

+ 6 - 1
esh_types.h

@@ -30,13 +30,18 @@ typedef enum {
 } ESH_JOB_CONDITION;
 
 typedef struct {
-	char* command;
+	char** command;
+
 	ESH_COMMAND_TYPE command_type;
 	ESH_JOB_TYPE job_type;
 	ESH_JOB_CONDITION job_start_condition;
 
 	pid_t job_pid;
 
+	FILE* job_stdin;
+	FILE* job_stdout;
+	FILE* job_stderr;
+
 	int stdin_pipe[2];
 	int stdout_pipe[2]; // 0 is for writing in child process and for reading in parent process.
 	int stderr_pipe[2];	// 1 is for writing in parent process and for reading in child process.