diff --git a/src/main.rs b/src/main.rs index 9c43e980d423f26edf853dd1b4f10080c05eb963..4a7482b524d35844020f1cda6e7b8893db953c80 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,7 +7,7 @@ use std::fs::{create_dir, File}; use std::io::Write; use std::path::PathBuf; -pub fn algo_template() { +fn algo_template() { let current_dir = env::current_dir().expect("Failed at locating current directory"); let mut root = PathBuf::new(); @@ -90,7 +90,69 @@ pub fn algo_template() { .expect(&format!("Not able to write to {}", impl_filename)); } -fn exam_template() {} +fn exam_template() { + let current_dir = env::current_dir().expect("Failed at locating current directory"); + let mut root = PathBuf::new(); + + root.push(current_dir); + + let mut project_name = String::from("prog_seq_exam_"); + + print!("\nPlease specify the month: "); + let month = from_stdin::input_from_stdin(); + + project_name.push_str(&month); + + root.push(project_name); + + create_dir(&root).expect(&format!("Failed at creating {} directory", root.display())); + + print!("\nPlease specify the number of exercices: "); + let nb_exercices = from_stdin::input_from_stdin() + .parse::<u8>() + .expect("Please input an integer!"); + + for i in 1..nb_exercices + 1 { + let mut exam_subdir = String::from("ex"); + + exam_subdir.push_str(format!("{}", i).as_str()); + + let mut main_filename = exam_subdir.clone(); + main_filename.push_str(".c"); + + root.push(exam_subdir); + + create_dir(&root).expect(&format!("Failed at creating {} directory", root.display())); + + let mut main_file = File::create( + &(root.to_owned().into_os_string().into_string().unwrap() + "/" + &main_filename), + ) + .expect(&format!("Cannot create '{}' file", main_filename)); + + main_file + .write_all( + code_templates::template_for_examfile() + .to_string() + .as_bytes(), + ) + .expect(&format!("Not able to write to {}", main_filename)); + + let mut makefile = File::create( + &(root.to_owned().into_os_string().into_string().unwrap() + "/" + "Makefile"), + ) + .expect("Cannot create Makefile!"); + + makefile + .write_all( + code_templates::template_for_makefile_exam(main_filename) + .to_string() + .as_bytes(), + ) + .expect("Not able to write to Makefile"); + + root.pop(); + } +} fn main() { to_stdout::print_menu();