43 namespace Hypertable {
namespace ClusterDefinitionFile {
namespace TokenizerTools {
46 return isalpha(c) || c ==
'_';
54 const char *ptr = name.c_str();
57 for (ptr=ptr+1; *ptr; ptr++) {
68 long val = strtol(str.c_str(), &end, 10);
70 if ((errno == ERANGE && (val == LONG_MAX || val == LONG_MIN))
71 || (errno != 0 && val == 0))
80 bool find_token(
const string &token,
const char *base,
const char *end,
size_t *offsetp) {
82 const char *ptr = base;
84 end -= token.length() - 1;
86 if (quote_char == 0) {
87 if (*ptr ==
'"' || *ptr ==
'\'' || *ptr ==
'`')
89 else if (*ptr ==
'#') {
90 while (ptr < end && *ptr !=
'\n')
95 else if (strncmp(ptr, token.c_str(), token.length()) == 0) {
101 if (*ptr == quote_char && *(ptr-1) !=
'\\')
111 const char *ptr = base;
113 if (quote_char == 0) {
114 if (*ptr ==
'"' || *ptr ==
'\'' || *ptr ==
'`')
116 else if (*ptr ==
'#') {
117 while (*ptr && *ptr !=
'\n')
127 *lengthp = ptr - base;
132 if (*ptr == quote_char && *(ptr-1) !=
'\\')
145 HT_ASSERT(*base ==
'"' || *base ==
'\'' || *base ==
'`' || *base ==
'{');
148 const char *ptr = base+1;
152 if (scope.top() ==
'"') {
153 if (*ptr ==
'"' && *(ptr-1) !=
'\\') {
159 else if (scope.top() ==
'\'') {
160 if (*ptr ==
'\'' && *(ptr-1) !=
'\\') {
166 else if (scope.top() ==
'`') {
177 while (*ptr && *ptr !=
'\n')
182 else if (*ptr ==
'}') {
187 else if (*ptr ==
'"' || *ptr ==
'\'' || *ptr ==
'`')
189 else if (*ptr ==
'{') {
190 if (*(ptr-1) ==
'$') {
191 while (*ptr && *ptr !=
'}')
201 if (*ptr ==
'\n' && linep)
214 map<string, string> control_flow_token_map;
215 control_flow_token_map[
"if"] =
"fi";
216 control_flow_token_map[
"for"] =
"done";
217 control_flow_token_map[
"until"] =
"done";
218 control_flow_token_map[
"while"] =
"done";
219 control_flow_token_map[
"case"] =
"esac";
220 const char *ptr = *basep;
222 while (*ptr && isspace(*ptr))
232 string token(ptr+offset, length);
233 auto iter = control_flow_token_map.find(token);
234 if (iter == control_flow_token_map.end()) {
240 scope.push(control_flow_token_map[token]);
242 ptr = ptr+offset+length;
244 token = string(ptr+offset, length);
245 if (token.compare(scope.top()) == 0) {
248 *basep = ptr+offset+length;
252 else if (control_flow_token_map.find(token) != control_flow_token_map.end())
253 scope.push(control_flow_token_map[token]);
254 ptr += (offset+length);
264 for (
const char *ptr=base; ptr<end; ptr++) {
272 const char *ptr = *endp;
273 while (*ptr && *ptr !=
'\n')
276 return (*ptr ==
'\n');
280 map<string, string> &vmap) {
282 string translated_text;
283 const char *base = input.c_str();
284 const char *ptr = strchr(base,
'$');
286 if (ptr > base && *(ptr-1) ==
'\\') {
288 translated_text.append(base, ptr-base);
290 ptr = strchr(base,
'$');
293 translated_text.append(base, ptr-base);
295 if (base[1] ==
'{') {
296 if ((ptr = strchr(base,
'}')) !=
nullptr) {
297 string variable(base+2, (ptr-base)-2);
298 auto iter = vmap.find(variable);
299 if (iter != vmap.end()) {
300 translated_text.append(vmap[variable]);
304 translated_text.append(base, (ptr-base)+1);
314 string variable(base+1, (ptr-base)-1);
315 auto iter = vmap.find(variable);
316 if (iter != vmap.end()) {
317 translated_text.append(vmap[variable]);
321 translated_text.append(base, ptr-base);
324 ptr = strchr(base,
'$');
326 translated_text.append(base);
328 output.append(translated_text);
Po::typed_value< String > * str(String *v=0)
Logging routines and macros.
Compatibility Macros for C/C++.