49 50 char *value = ::getenv((TCHAR*) name.c_str()); 51 52 if (value != NULL) { 53 result = value; 54 } 55 56 return result; 57 } 58 59 LinuxPlatform::LinuxPlatform(void) : Platform(), 60 PosixPlatform() { 61 FMainThread = pthread_self(); 62 } 63 64 LinuxPlatform::~LinuxPlatform(void) { 65 } 66 67 TString LinuxPlatform::GetPackageAppDirectory() { 68 return FilePath::IncludeTrailingSeparator( 69 GetPackageRootDirectory()) + _T("app"); 70 } 71 72 TString LinuxPlatform::GetAppName() { 73 TString result = GetModuleFileName(); 74 result = FilePath::ExtractFileName(result); 75 return result; 76 } 77 78 TString LinuxPlatform::GetPackageLauncherDirectory() { 79 return GetPackageRootDirectory(); 80 } 81 82 TString LinuxPlatform::GetPackageRuntimeBinDirectory() { 83 return FilePath::IncludeTrailingSeparator(GetPackageRootDirectory()) + _T("runtime/bin"); 84 } 85 86 void LinuxPlatform::ShowMessage(TString title, TString description) { 87 printf("%s %s\n", PlatformString(title).toPlatformString(), 88 PlatformString(description).toPlatformString()); 89 fflush(stdout); 90 } 91 92 void LinuxPlatform::ShowMessage(TString description) { 93 TString appname = GetModuleFileName(); 94 appname = FilePath::ExtractFileName(appname); 95 ShowMessage(PlatformString(appname).toPlatformString(), 96 PlatformString(description).toPlatformString()); 97 } 98 99 TCHAR* LinuxPlatform::ConvertStringToFileSystemString(TCHAR* Source, 100 bool &release) { 101 // Not Implemented. 102 return NULL; 103 } 108 return NULL; 109 } 110 111 TString LinuxPlatform::GetModuleFileName() { 112 ssize_t len = 0; 113 TString result; 114 DynamicBuffer<TCHAR> buffer(MAX_PATH); 115 if (buffer.GetData() == NULL) { 116 return result; 117 } 118 119 if ((len = readlink("/proc/self/exe", buffer.GetData(), 120 MAX_PATH - 1)) != -1) { 121 buffer[len] = '\0'; 122 result = buffer.GetData(); 123 } 124 125 return result; 126 } 127 128 void LinuxPlatform::SetCurrentDirectory(TString Value) { 129 chdir(PlatformString(Value).toPlatformString()); 130 } 131 132 TString LinuxPlatform::GetPackageRootDirectory() { 133 TString filename = GetModuleFileName(); 134 return FilePath::ExtractFilePath(filename); 135 } 136 137 TString LinuxPlatform::GetAppDataDirectory() { 138 TString result; 139 TString home = GetEnv(_T("HOME")); 140 141 if (home.empty() == false) { 142 result += FilePath::IncludeTrailingSeparator(home) + _T(".local"); 143 } 144 145 return result; 146 } 147 148 ISectionalPropertyContainer* LinuxPlatform::GetConfigFile(TString FileName) { 149 IniFile *result = new IniFile(); 150 if (result == NULL) { 151 return NULL; 152 } 153 154 result->LoadFromFile(FileName); 844 /* Create node for new element tag */ 845 node = CreateXMLNode(xmlTagType, JPACKAGE_STRDUP(CurTokenName)); 846 /* We need to save root node pointer to be able to cleanup 847 if an error happens during parsing */ 848 if (!root_node) { 849 root_node = node; 850 } 851 /* Parse attributes. This section eats a all input until 852 EOF, a > or a /> */ 853 attr = ParseXMLAttribute(); 854 while (attr != NULL) { 855 attr->_next = node->_attributes; 856 node->_attributes = attr; 857 attr = ParseXMLAttribute(); 858 } 859 860 /* This will eihter be a TOKEN_EOF, TOKEN_CLOSE_BRACKET, or a 861 * TOKEN_EMPTY_CLOSE_BRACKET */ 862 GetNextToken(); 863 864 /* Skip until '>', '/>' or EOF. This should really be an error, */ 865 /* but we are loose */ 866 // if(CurTokenType == TOKEN_EMPTY_CLOSE_BRACKET || 867 // CurTokenType == TOKEN_CLOSE_BRACKET || 868 // CurTokenType == TOKEN_EOF) { 869 // println("XML Parsing error: wrong kind of token found"); 870 // return NULL; 871 // } 872 873 if (CurTokenType == TOKEN_EMPTY_CLOSE_BRACKET) { 874 GetNextToken(); 875 /* We are done with the sublevel - fall through to continue */ 876 /* parsing tags at the same level */ 877 } else if (CurTokenType == TOKEN_CLOSE_BRACKET) { 878 GetNextToken(); 879 880 /* Parse until end tag if found */ 881 node->_sub = ParseXMLElement(); 882 883 if (CurTokenType == TOKEN_END_TAG) { 884 /* Find closing bracket '>' for end tag */ 885 do { 886 GetNextToken(); 887 } while (CurTokenType != TOKEN_EOF && 888 CurTokenType != TOKEN_CLOSE_BRACKET); 889 GetNextToken(); 890 } 891 } 892 1004 1005 static void FreeXMLAttribute(XMLAttribute* attr) { 1006 if (attr == NULL) return; 1007 free(attr->_name); 1008 free(attr->_value); 1009 FreeXMLAttribute(attr->_next); 1010 free(attr); 1011 } 1012 1013 /* Find element at current level with a given name */ 1014 XMLNode* FindXMLChild(XMLNode* root, const TCHAR* name) { 1015 if (root == NULL) return NULL; 1016 1017 if (root->_type == xmlTagType && JPACKAGE_STRCMP(root->_name, name) == 0) { 1018 return root; 1019 } 1020 1021 return FindXMLChild(root->_next, name); 1022 } 1023 1024 /* Search for an attribute with the given name and returns the contents. Returns NULL if 1025 * attribute is not found 1026 */ 1027 TCHAR* FindXMLAttribute(XMLAttribute* attr, const TCHAR* name) { 1028 if (attr == NULL) return NULL; 1029 if (JPACKAGE_STRCMP(attr->_name, name) == 0) return attr->_value; 1030 return FindXMLAttribute(attr->_next, name); 1031 } 1032 1033 void PrintXMLDocument(XMLNode* node, int indt) { 1034 if (node == NULL) return; 1035 1036 if (node->_type == xmlTagType) { 1037 JPACKAGE_PRINTF(_T("\n")); 1038 indent(indt); 1039 JPACKAGE_PRINTF(_T("<%s"), node->_name); 1040 PrintXMLAttributes(node->_attributes); 1041 if (node->_sub == NULL) { 1042 JPACKAGE_PRINTF(_T("/>\n")); 1043 } else { 1044 JPACKAGE_PRINTF(_T(">")); 1045 PrintXMLDocument(node->_sub, indt + 1); | 49 50 char *value = ::getenv((TCHAR*) name.c_str()); 51 52 if (value != NULL) { 53 result = value; 54 } 55 56 return result; 57 } 58 59 LinuxPlatform::LinuxPlatform(void) : Platform(), 60 PosixPlatform() { 61 FMainThread = pthread_self(); 62 } 63 64 LinuxPlatform::~LinuxPlatform(void) { 65 } 66 67 TString LinuxPlatform::GetPackageAppDirectory() { 68 return FilePath::IncludeTrailingSeparator( 69 GetPackageRootDirectory()) + _T("lib/app"); 70 } 71 72 TString LinuxPlatform::GetAppName() { 73 TString result = GetModuleFileName(); 74 result = FilePath::ExtractFileName(result); 75 return result; 76 } 77 78 TString LinuxPlatform::GetPackageLauncherDirectory() { 79 return FilePath::IncludeTrailingSeparator( 80 GetPackageRootDirectory()) + _T("bin"); 81 } 82 83 TString LinuxPlatform::GetPackageRuntimeBinDirectory() { 84 return FilePath::IncludeTrailingSeparator(GetPackageRootDirectory()) 85 + _T("runtime/bin"); 86 } 87 88 void LinuxPlatform::ShowMessage(TString title, TString description) { 89 printf("%s %s\n", PlatformString(title).toPlatformString(), 90 PlatformString(description).toPlatformString()); 91 fflush(stdout); 92 } 93 94 void LinuxPlatform::ShowMessage(TString description) { 95 TString appname = GetModuleFileName(); 96 appname = FilePath::ExtractFileName(appname); 97 ShowMessage(PlatformString(appname).toPlatformString(), 98 PlatformString(description).toPlatformString()); 99 } 100 101 TCHAR* LinuxPlatform::ConvertStringToFileSystemString(TCHAR* Source, 102 bool &release) { 103 // Not Implemented. 104 return NULL; 105 } 110 return NULL; 111 } 112 113 TString LinuxPlatform::GetModuleFileName() { 114 ssize_t len = 0; 115 TString result; 116 DynamicBuffer<TCHAR> buffer(MAX_PATH); 117 if (buffer.GetData() == NULL) { 118 return result; 119 } 120 121 if ((len = readlink("/proc/self/exe", buffer.GetData(), 122 MAX_PATH - 1)) != -1) { 123 buffer[len] = '\0'; 124 result = buffer.GetData(); 125 } 126 127 return result; 128 } 129 130 TString LinuxPlatform::GetPackageRootDirectory() { 131 TString result; 132 TString filename = GetModuleFileName(); 133 TString binPath = FilePath::ExtractFilePath(filename); 134 135 size_t slash = binPath.find_last_of(TRAILING_PATHSEPARATOR); 136 if (slash != TString::npos) { 137 result = binPath.substr(0, slash); 138 } 139 140 return result; 141 } 142 143 TString LinuxPlatform::GetAppDataDirectory() { 144 TString result; 145 TString home = GetEnv(_T("HOME")); 146 147 if (home.empty() == false) { 148 result += FilePath::IncludeTrailingSeparator(home) + _T(".local"); 149 } 150 151 return result; 152 } 153 154 ISectionalPropertyContainer* LinuxPlatform::GetConfigFile(TString FileName) { 155 IniFile *result = new IniFile(); 156 if (result == NULL) { 157 return NULL; 158 } 159 160 result->LoadFromFile(FileName); 850 /* Create node for new element tag */ 851 node = CreateXMLNode(xmlTagType, JPACKAGE_STRDUP(CurTokenName)); 852 /* We need to save root node pointer to be able to cleanup 853 if an error happens during parsing */ 854 if (!root_node) { 855 root_node = node; 856 } 857 /* Parse attributes. This section eats a all input until 858 EOF, a > or a /> */ 859 attr = ParseXMLAttribute(); 860 while (attr != NULL) { 861 attr->_next = node->_attributes; 862 node->_attributes = attr; 863 attr = ParseXMLAttribute(); 864 } 865 866 /* This will eihter be a TOKEN_EOF, TOKEN_CLOSE_BRACKET, or a 867 * TOKEN_EMPTY_CLOSE_BRACKET */ 868 GetNextToken(); 869 870 if (CurTokenType == TOKEN_EMPTY_CLOSE_BRACKET) { 871 GetNextToken(); 872 /* We are done with the sublevel - fall through to continue */ 873 /* parsing tags at the same level */ 874 } else if (CurTokenType == TOKEN_CLOSE_BRACKET) { 875 GetNextToken(); 876 877 /* Parse until end tag if found */ 878 node->_sub = ParseXMLElement(); 879 880 if (CurTokenType == TOKEN_END_TAG) { 881 /* Find closing bracket '>' for end tag */ 882 do { 883 GetNextToken(); 884 } while (CurTokenType != TOKEN_EOF && 885 CurTokenType != TOKEN_CLOSE_BRACKET); 886 GetNextToken(); 887 } 888 } 889 1001 1002 static void FreeXMLAttribute(XMLAttribute* attr) { 1003 if (attr == NULL) return; 1004 free(attr->_name); 1005 free(attr->_value); 1006 FreeXMLAttribute(attr->_next); 1007 free(attr); 1008 } 1009 1010 /* Find element at current level with a given name */ 1011 XMLNode* FindXMLChild(XMLNode* root, const TCHAR* name) { 1012 if (root == NULL) return NULL; 1013 1014 if (root->_type == xmlTagType && JPACKAGE_STRCMP(root->_name, name) == 0) { 1015 return root; 1016 } 1017 1018 return FindXMLChild(root->_next, name); 1019 } 1020 1021 /* Search for an attribute with the given name and returns the contents. 1022 * Returns NULL if attribute is not found 1023 */ 1024 TCHAR* FindXMLAttribute(XMLAttribute* attr, const TCHAR* name) { 1025 if (attr == NULL) return NULL; 1026 if (JPACKAGE_STRCMP(attr->_name, name) == 0) return attr->_value; 1027 return FindXMLAttribute(attr->_next, name); 1028 } 1029 1030 void PrintXMLDocument(XMLNode* node, int indt) { 1031 if (node == NULL) return; 1032 1033 if (node->_type == xmlTagType) { 1034 JPACKAGE_PRINTF(_T("\n")); 1035 indent(indt); 1036 JPACKAGE_PRINTF(_T("<%s"), node->_name); 1037 PrintXMLAttributes(node->_attributes); 1038 if (node->_sub == NULL) { 1039 JPACKAGE_PRINTF(_T("/>\n")); 1040 } else { 1041 JPACKAGE_PRINTF(_T(">")); 1042 PrintXMLDocument(node->_sub, indt + 1); |