Browse Source

Added configuration file reading impl

Ivan Arkhipov 5 years ago
parent
commit
23d8d44f2c
1 changed files with 27 additions and 1 deletions
  1. 27 1
      esh_init.c

+ 27 - 1
esh_init.c

@@ -18,13 +18,17 @@ void EShInit(int argc, char** argv) {
 		   "Default shell program: %s\n"
 		   "Config file path: %s\n"
 		   "Commands history file path: %s\n"
+		   "Max history lines: %d\n"
+		   "Max running jobs: %d\n"
 		   "===================================\n",
 		   esh_info_global->user_data->pw_name, 
 		   esh_info_global->build_ref,
 		   esh_info_global->user_data->pw_dir,
 		   esh_info_global->user_data->pw_shell,
 		   esh_info_global->config_file_path,
-		   esh_info_global->history_file_path);
+		   esh_info_global->history_file_path,
+		   esh_info_global->history_limit,
+		   esh_info_global->max_jobs_number);
 }
  
 void EShInitInfo(int argc, char** argv) {
@@ -100,5 +104,27 @@ void EShProcessConfigFile() {
 		return;
 	}
 
+	char* line = NULL;
+	ssize_t len;
+	int line_length;
+    while ((line_length = getline(&line, &len, file)) != -1) {
+    	if (line[line_length - 1] == '\n') {
+    		line[line_length - 1] = '\0';
+    		--line_length;
+    	}
+
+		if (strstr(line, "history_path=") == line) {
+			strcpy(esh_info_global->history_file_path, line + strlen("history_path="));
+		}
+
+		if (strstr(line, "history_limit=") == line) {
+			sscanf(line + strlen("history_limit="), "%d", &esh_info_global->history_limit);
+		}
+
+		if (strstr(line, "max_active_jobs=") == line) {
+			sscanf(line + strlen("max_active_jobs="), "%d", &esh_info_global->max_jobs_number);
+		}
+    }
+
 	fclose(file);
 }