Skip to content
Snippets Groups Projects
Commit f47c039b authored by iliya.saroukha's avatar iliya.saroukha
Browse files

finished exam template function

parent 13523003
No related branches found
No related tags found
No related merge requests found
......@@ -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();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment