diff --git a/iash/iash.cpp b/iash/iash.cpp index 0058423..daa3166 100644 --- a/iash/iash.cpp +++ b/iash/iash.cpp @@ -7,9 +7,9 @@ iash::iash (string app_nm, bool useInPrompt) m_appName = app_nm; f_useAppNameInPrompt = useInPrompt; - setenv("APP_NAME",m_appName); - setenv("APP_NAME_IN_PROMPT",f_useAppNameInPrompt); - setenv("SYNC_ENV", true); + setenv("IASH_APP_NAME",m_appName); + setenv("IASH_APP_NAME_IN_PROMPT",f_useAppNameInPrompt); + setenv("IASH_SYNC_ENV", true); } vector iash::getCmdLine() @@ -20,15 +20,19 @@ vector iash::getCmdLine() clear(); - if (getenv_bool("SYNC_ENV")) + if (getenv_bool("IASH_SYNC_ENV")) updateAttached(); - if (f_useAppNameInPrompt) - cout< "; - else - cout<<">>> "; + do + { + if (f_useAppNameInPrompt) + cout< "; + else + cout<<">>> "; + + getline(cin,raw); + } while (raw == ""); - getline(cin,raw); lastSpace = 0; do @@ -169,9 +173,19 @@ void iash::setenv(string name, bool value) } } +string iash::getenv_string(string name) +{ + int x; + + for (x = 0; x < name.length(); x++) + name[x] = toupper(name[x]); + + return m_env.at(name); +} + bool iash::getenv_bool(string name) { - if (m_env.at(name) == "true") + if (getenv_string(name) == "true") return true; else return false; @@ -179,20 +193,27 @@ bool iash::getenv_bool(string name) void iash::rmenv(string name) { - if (name != "APP_NAME" && name != "APP_NAME_IN_PROMPT" && name != "SYNC_ENV") + int x; + + for (x = 0; x < name.length(); x++) + name[x] = toupper(name[x]); + + if (name.find("IASH_") == string::npos) m_env.erase(name); + else + cout<<"Error: cannot remove required environment variable '"< cmd) if (cmd.size() > 2) { if (cmd[2] == "quit" || cmd[2] == "exit") - exit(0); + exit(EXIT_SUCCESS); else if (cmd[2] == "kill" || cmd[2] == "crash") - exit(1); + exit(EXIT_FAILURE); else if (cmd[2] == "name" && cmd.size() == 4) - setenv("APP_NAME",cmd[3]); + setenv("IASH_APP_NAME",cmd[3]); else cout< cmd) void iash::updateAttached() { - if (getenv_string("APP_NAME") != m_appName) - m_appName = getenv_string("APP_NAME"); + if (getenv_string("IASH_APP_NAME") != m_appName) + m_appName = getenv_string("IASH_APP_NAME"); - if (getenv_bool("APP_NAME_IN_PROMPT") != f_useAppNameInPrompt) - f_useAppNameInPrompt = getenv_bool("APP_NAME_IN_PROMPT"); + if (getenv_bool("IASH_APP_NAME_IN_PROMPT") != f_useAppNameInPrompt) + f_useAppNameInPrompt = getenv_bool("IASH_APP_NAME_IN_PROMPT"); } diff --git a/iash/iash.h b/iash/iash.h index 0bb65ec..502d5e2 100644 --- a/iash/iash.h +++ b/iash/iash.h @@ -84,9 +84,9 @@ class iash * @param name: The name of the variable * @return: The variable */ - string getenv_string (string name) { return m_env.at(name); } - int getenv_int (string name) { return stoi(m_env.at(name)); } - float getenv_float (string name) { return stof(m_env.at(name)); } + string getenv_string (string name); + int getenv_int (string name) { return stoi(getenv_string(name)); } + float getenv_float (string name) { return stof(getenv_string(name)); } bool getenv_bool (string name); /**