From 4b22f80a772b46d16527c389da3c6169a4936199 Mon Sep 17 00:00:00 2001 From: Mark Thom Date: Wed, 4 Sep 2019 23:30:48 -0600 Subject: [PATCH] check for and load .scryerrc from the user's home directory --- Cargo.toml | 3 ++- src/prolog/machine/mod.rs | 27 +++++++++++++++++++++++++-- src/prolog/mod.rs | 1 + 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8593888a..34c49552 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "scryer-prolog" -version = "0.8.87" +version = "0.8.88" authors = ["Mark Thom "] repository = "https://github.com/mthom/scryer-prolog" description = "A modern Prolog implementation written mostly in Rust." @@ -11,6 +11,7 @@ default = ["readline_rs_compat"] [dependencies] cfg-if = "0.1.7" +dirs = "2.0.2" downcast = "0.10.0" indexmap = "1.0.2" ordered-float = "0.5.0" diff --git a/src/prolog/machine/mod.rs b/src/prolog/machine/mod.rs index 8c33f0a6..9d6ef0e9 100644 --- a/src/prolog/machine/mod.rs +++ b/src/prolog/machine/mod.rs @@ -39,6 +39,7 @@ use prolog::read::PrologStream; use std::collections::{HashMap, VecDeque}; use std::io::{Read, Write, stdout}; +use std::fs::File; use std::mem; use std::ops::Index; use std::rc::Rc; @@ -153,7 +154,8 @@ impl SubModuleUser for IndexStore { static BUILTINS: &str = include_str!("../lib/builtins.pl"); static TOPLEVEL: &str = include_str!("../toplevel.pl"); -static ERROR: &str = include_str!("../lib/error.pl"); +static BETWEEN: &str = include_str!("../lib/between.pl"); +static NON_ISO: &str = include_str!("../lib/non_iso.pl"); impl Machine { fn compile_special_forms(&mut self) { @@ -179,6 +181,24 @@ impl Machine { compile_user_module(self, parsing_stream(TOPLEVEL.as_bytes())); } + fn compile_scryerrc(&mut self) { + let mut path = match dirs::home_dir() { + Some(path) => path, + None => return + }; + + path.push(".scryerrc"); + + if path.is_file() { + let file_src = match File::open(&path) { + Ok(file_handle) => parsing_stream(file_handle), + Err(_) => return + }; + + compile_user_module(self, file_src); + } + } + #[cfg(test)] pub fn reset(&mut self) { self.prolog_stream = readline::input_stream(); @@ -209,7 +229,10 @@ impl Machine { wam.compile_special_forms(); wam.compile_top_level(); - compile_user_module(&mut wam, parsing_stream(ERROR.as_bytes())); + compile_user_module(&mut wam, parsing_stream(BETWEEN.as_bytes())); + compile_user_module(&mut wam, parsing_stream(NON_ISO.as_bytes())); + + wam.compile_scryerrc(); wam } diff --git a/src/prolog/mod.rs b/src/prolog/mod.rs index d7747718..435f20f8 100644 --- a/src/prolog/mod.rs +++ b/src/prolog/mod.rs @@ -1,3 +1,4 @@ +extern crate dirs; extern crate ordered_float; extern crate prolog_parser; extern crate rug; -- 2.54.0