+// Single command mode - command line arguments mode - evaluate the expression
+// given in the command line and quit
+fn run_command_line (args : &Vec<String>, match_num : ®ex::Regex) {
+ let mut expr = String::new ();
+ let mut i = 0;
+ // create the expression string to evaluate
+ for arg in args.iter() {
+ if i > 0 {
+ expr.push_str (&arg);
+ expr.push_str (" ");
+ }
+ i += 1;
+ }
+ // evaluate the result
+ let res = evaluate (&expr, &match_num);
+ // if Result is OK then print the result in green
+ if res.is_ok () {
+ let restxt = format! ("{}", res.unwrap());
+ println! ("{}", restxt.green ());
+ } else {
+ // print the error in purple
+ let errtxt = format! ("{}: {}", ERROR,
+ res.unwrap_err());
+ eprintln! ("{}", errtxt.purple ());
+ }
+}
+
+// get the history file name as string - home dir + .evpfhistory
+fn get_history_file () -> Result<String,String> {
+ // get the environment variable HOME
+ let home_path = env::var ("HOME");
+ // if not found, return an error
+ if home_path.is_err () {
+ return Err (HOMEDIR_NOT_FOUND.to_string());
+ }
+ // build the path for the history file i.e. homedir + .evpfhistory in
+ // platform independent way
+ let mut hist_file = PathBuf::new ();
+ hist_file.push (home_path.unwrap());
+ hist_file.push (".evpfhistory");
+
+ // if cannot convert to string return error
+ if hist_file.to_str ().is_none () {
+ return Err (HOMEDIR_NOT_FOUND.to_string());
+ }
+
+ // return the history file path as a string
+ let hist_file_path = String::from (hist_file.to_str().unwrap());
+ return Ok (hist_file_path);
+}
+
+// Interactive mode - display the prompt and evaluate expressions entered into
+// the prompt - until user quits
+fn run_interactive_mode (match_num : ®ex::Regex) {