From 12d1777236e01f69a16fb21f64d3d3e2e2c02a8b Mon Sep 17 00:00:00 2001
From: Jeremy Soller <jackpot51@gmail.com>
Date: Thu, 3 Dec 2015 09:54:00 -0700
Subject: [PATCH] Minor cleanup, add ps and free to shell

---
 main.rs | 35 +++++++++++++++++++++++++++++++++--
 1 file changed, 33 insertions(+), 2 deletions(-)

diff --git a/main.rs b/main.rs
index 1cd2c45c..155d37e3 100644
--- a/main.rs
+++ b/main.rs
@@ -9,7 +9,6 @@ use std::io::*;
 use std::env::*;
 use std::time::Duration;
 use std::to_num::*;
-use std::hashmap::HashMap;
 use std::process;
 
 macro_rules! readln {
@@ -139,6 +138,22 @@ impl<'a> Command<'a> {
             main: Box::new(|_: &Vec<String>| {}),
         });
 
+        commands.push(Command {
+            name: "free",
+            help: "Show memory information\n    free",
+            main: Box::new(|_: &Vec<String>| {
+                if let Some(mut file) = File::open("memory:") {
+                    let mut string = String::new();
+                    match file.read_to_string(&mut string) {
+                        Some(_) => println!("{}", string),
+                        None => println!("Failed to read: memory:"),
+                    }
+                } else {
+                    println!("Failed to open file: memory:");
+                }
+            }),
+        });
+
         commands.push(Command {
             name: "if",
             help: "",
@@ -174,6 +189,22 @@ impl<'a> Command<'a> {
             }),
         });
 
+        commands.push(Command {
+            name: "ps",
+            help: "Show process list\n    ps",
+            main: Box::new(|_: &Vec<String>| {
+                if let Some(mut file) = File::open("context:") {
+                    let mut string = String::new();
+                    match file.read_to_string(&mut string) {
+                        Some(_) => println!("{}", string),
+                        None => println!("Failed to read: context:"),
+                    }
+                } else {
+                    println!("Failed to open file: context:");
+                }
+            }),
+        });
+
         commands.push(Command {
             name: "pwd",
             help: "To output the path of the current directory\n    pwd",
@@ -342,7 +373,7 @@ impl<'a> Command<'a> {
 
         // TODO: Someone should implement FromIterator for HashMap before
         //       changing the type back to HashMap
-        let mut command_helper: BTreeMap<String, String> = commands
+        let command_helper: BTreeMap<String, String> = commands
             .iter()
             .map(|c| (c.name.to_string(), c.help.to_string()))
             .collect();
-- 
GitLab