0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
HsClientState.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2007-2015 Hypertable, Inc.
3  *
4  * This file is part of Hypertable.
5  *
6  * Hypertable is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 3
9  * of the License, or any later version.
10  *
11  * Hypertable is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  * 02110-1301, USA.
20  */
21 
22 #include "Common/Compat.h"
23 #include "Common/Error.h"
24 #include "HsClientState.h"
25 
26 namespace Hyperspace {
27  namespace HsClientState {
28  int exit_status = 0;
29  String cwd = "/";
31  }
32 
33  void Util::normalize_pathname(String name, String &normal_name) {
34  normal_name = "";
35  if (name[0] != '/')
36  normal_name += "/";
37 
38  if (name.find('/', name.length()-1) == String::npos)
39  normal_name += name;
40  else
41  normal_name += name.substr(0, name.length()-1);
42  }
43 
44  uint64_t Util::get_handle(std::string name) {
45  String normal_name;
46 
47  normalize_pathname(name, normal_name);
48 
49  HsClientState::FileMap::iterator iter =
50  HsClientState::file_map.find(normal_name);
51  if (iter == HsClientState::file_map.end())
52  HT_THROWF(Error::HYPERSPACE_CLI_PARSE_ERROR, "Unable to find '%s' in "
53  "open file map", normal_name.c_str());
54 
55  return (*iter).second;
56  }
57 
58 }
std::string String
A String is simply a typedef to std::string.
Definition: String.h:44
uint64_t get_handle(std::string name)
Hyperspace definitions
void normalize_pathname(std::string name, std::string &normal_name)
Compatibility Macros for C/C++.
std::unordered_map< String, uint64_t > FileMap
Definition: HsClientState.h:35
#define HT_THROWF(_code_, _fmt_,...)
Definition: Error.h:490
Error codes, Exception handling, error logging.