/****************************************************************************** * This program simply writes characters from the alphabet to a file. * * Copyright © 2020 Richard Lesh. All rights reserved. *****************************************************************************/ #![allow(dead_code)] #![allow(non_snake_case)] #![allow(non_upper_case_globals)] #[macro_use] mod utils; use std::env; use std::fs::{File}; use std::io::{BufWriter, Write}; use std::process::{self}; fn write_text_file(filespec:&str) -> Result<(), utils::CustomError> { let mut ofh:BufWriter = BufWriter::new(File::create(filespec)?); // Latin alphabet { let mut c:u32 = 0x41; while c <= 0x5A { utils::put_codepoint(&mut ofh, c); c += 1; } } write!(ofh, "{}", '\n')?; // Greek alphabet { let mut c:u32 = 0x391; while c <= 0x3A9 { utils::put_codepoint(&mut ofh, c); c += 1; } } write!(ofh, "{}", '\n')?; // Cyrillic alphabet { let mut c:u32 = 0x410; while c <= 0x42F { utils::put_codepoint(&mut ofh, c); c += 1; } } write!(ofh, "{}", '\n')?; // Katakana alphabet { let mut c:u32 = 0x30A0; while c <= 0x30FF { utils::put_codepoint(&mut ofh, c); c += 1; } } write!(ofh, "{}", '\n')?; ofh.flush()?; return Ok(()); } fn main() { let args: Vec = env::args().collect(); if args.len() != 2 { println!("Syntax: FileIO4 {{filename}}"); process::exit(1); } let filespec:String = args[1].to_string(); match (|| -> Result<(), utils::CustomError>{ write_text_file(&filespec)?; return Ok(()); })() { Ok(()) => {}, Err(ex) => { match ex { utils::CustomError::IOError(ex) => { println!("Error: {}", format!("{}", ex)); } _ => { println!("Unexpected File Read Error"); } } } }; }