]> Repositorios git - scryer-prolog.git/commitdiff
check for and load .scryerrc from the user's home directory
authorMark Thom <[email protected]>
Thu, 5 Sep 2019 05:30:48 +0000 (23:30 -0600)
committerMark Thom <[email protected]>
Thu, 5 Sep 2019 05:30:48 +0000 (23:30 -0600)
Cargo.toml
src/prolog/machine/mod.rs
src/prolog/mod.rs

index 8593888a8034efb0a7a30f4644f360f7226f64e9..34c495529bca6e8ea7599c603470c5d913d670de 100644 (file)
@@ -1,6 +1,6 @@
 [package]
 name = "scryer-prolog"
-version = "0.8.87"
+version = "0.8.88"
 authors = ["Mark Thom <[email protected]>"]
 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"
index 8c33f0a6bfecefdba2ff6ea3b8efd2e85eb47d88..9d6ef0e99b1dc59e515b186caed4d0a01f586a89 100644 (file)
@@ -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
     }
index d7747718ecf35baff91f020d65bec41694c90e1e..435f20f8bc43d75c2d0a0e9c83eda50ba3caf5b3 100644 (file)
@@ -1,3 +1,4 @@
+extern crate dirs;
 extern crate ordered_float;
 extern crate prolog_parser;
 extern crate rug;