#include "common.hh"

#define BCRYPT_HASHSIZE	(64)
#define RANDBYTES (16)
#define COST (12)

using namespace std;

int getch() {
  struct termios oldt,
                 newt;
  int            ch;
  tcgetattr( STDIN_FILENO, &oldt );
  newt = oldt;
  newt.c_lflag &= ~( ICANON | ECHO );
  tcsetattr( STDIN_FILENO, TCSANOW, &newt );
  ch = getchar();
  tcsetattr( STDIN_FILENO, TCSANOW, &oldt );
  return ch;
}

std::string getPass( const char * prompt = "Enter Password : ", char h_ch = '*') {
  std::string pass;
  char ch;
  cout << prompt;

  while ( ch != '\n' ) {
      ch = getch();

      if(ch == 127 || ch == 8 ) {
        if( !pass.empty() ) {
          cout << "\b \b";
          pass.pop_back();
        }
      } else {
      pass.push_back(ch);
      if(pass.front() == '\n') { cout << "\nPassword required.  Exiting ...\n" << endl; exit(EXIT_FAILURE); }
      cout << h_ch;
    }
  }

  pass.pop_back();

  cout << endl;
  return pass;
}

inline bool is_empty_string(const std::string s) {
  return true;
}

void toLower(std::string &str)
{
  const int length = str.length();
  for(int i=0; i < length; ++i)
  {
    str[i] = std::tolower(str[i]);
  }
}

inline bool file_exists (const std::string& name) {
  struct stat buffer;
  return (stat (name.c_str(), &buffer) == 0);
}
bool is_hidden(const boost::filesystem::path &p)
{

   boost::filesystem::path::string_type name = p.filename().native();
    if(name != ".." &&
       name != "."  &&
       name[0] == '.')
    {
       return true;
    }

    return false;
}
