1/* 2 * Copyright 2008, Haiku. 3 * Distributed under the terms of the MIT license. 4 * 5 * Authors: 6 * Michael Pfeiffer <laplace@users.sourceforge.net> 7 */ 8 9#include "StatementWrapper.h" 10 11static const char* kOpenUIStatement = "OpenUI"; 12static const char* kCloseUIStatement = "CloseUI"; 13 14static const char* kOpenGroupStatement = "OpenGroup"; 15static const char* kCloseGroupStatement = "CloseGroup"; 16static const char* kOpenSubGroupStatement = "OpenSubGroup"; 17static const char* kCloseSubGroupStatement = "CloseSubGroup"; 18 19// JCL 20static const char* kJCL = "JCL"; 21static const char* kJCLOpenUIStatement = "JCLOpenUI"; 22static const char* kJCLCloseUIStatement = "JCLCloseUI"; 23 24 25StatementWrapper::StatementWrapper(Statement* statement) 26 : fStatement(statement) 27{ 28 // nothing to do 29} 30 31GroupStatement::GroupStatement(Statement* statement) 32 : StatementWrapper(statement) 33{ 34 // nothing to do 35} 36 37bool GroupStatement::IsUIGroup() 38{ 39 return strcmp(GetKeyword(), kOpenUIStatement) == 0; 40} 41 42bool GroupStatement::IsGroup() 43{ 44 return strcmp(GetKeyword(), kOpenGroupStatement) == 0; 45} 46 47bool GroupStatement::IsSubGroup() 48{ 49 return strcmp(GetKeyword(), kOpenSubGroupStatement) == 0; 50} 51 52bool GroupStatement::IsJCL() 53{ 54 return strstr(GetKeyword(), kJCL) == GetKeyword(); 55} 56 57bool GroupStatement::IsOpenGroup() 58{ 59 const char* keyword = GetKeyword(); 60 61 return strcmp(keyword, kOpenUIStatement) == 0 || 62 strcmp(keyword, kOpenGroupStatement) == 0 || 63 strcmp(keyword, kOpenSubGroupStatement) == 0 || 64 strcmp(keyword, kJCLOpenUIStatement) == 0; 65} 66 67bool GroupStatement::IsCloseGroup() 68{ 69 const char* keyword = GetKeyword(); 70 71 return strcmp(keyword, kCloseUIStatement) == 0 || 72 strcmp(keyword, kCloseGroupStatement) == 0 || 73 strcmp(keyword, kCloseSubGroupStatement) == 0 || 74 strcmp(keyword, kJCLCloseUIStatement) == 0; 75} 76 77Value* GroupStatement::GetValue() 78{ 79 if (strcmp(GetKeyword(), kOpenUIStatement) == 0 || 80 strcmp(GetKeyword(), kJCLOpenUIStatement) == 0) { 81 return GetStatement()->GetOption(); 82 } else { 83 return GetStatement()->GetValue(); 84 } 85} 86 87const char* GroupStatement::GetGroupName() 88{ 89 Value* value = GetValue(); 90 if (value == NULL) return NULL; 91 BString* string = value->GetValue(); 92 if (string == NULL) return NULL; 93 const char* name = string->String(); 94 if (name != NULL && *name == '*') { 95 // skip '*' 96 name ++; 97 } 98 return name; 99} 100 101const char* GroupStatement::GetGroupTranslation() 102{ 103 Value* value = GetValue(); 104 if (value == NULL) return NULL; 105 BString* string = value->GetTranslation(); 106 if (string == NULL) return NULL; 107 return string->String(); 108} 109 110GroupStatement::Type GroupStatement::GetType() 111{ 112 const char* type = GetStatement()->GetValueString(); 113 if (type == NULL) return kUnknown; 114 115 if (strstr(type, "PickOne") != NULL) return kPickOne; 116 if (strstr(type, "PickMany") != NULL) return kPickMany; 117 if (strstr(type, "Boolean") != NULL) return kBoolean; 118 119 return kUnknown; 120} 121