Mercurial > ecos
comparison host/tools/ecostest/common/eCosTestUtils.cpp @ 76:435cced73e2f ecos-v1_3_1-release
eCos v1.3.1 merged from eCos master repository on 2000-03-27-23:22:51-BST
| author | jlarmour |
|---|---|
| date | Tue, 28 Mar 2000 14:10:45 +0000 |
| parents | |
| children | 6736c52df507 |
comparison
equal
deleted
inserted
replaced
| 75:41bf073c0c32 | 76:435cced73e2f |
|---|---|
| 1 //####COPYRIGHTBEGIN#### | |
| 2 // | |
| 3 // ---------------------------------------------------------------------------- | |
| 4 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc. | |
| 5 // | |
| 6 // This program is part of the eCos host tools. | |
| 7 // | |
| 8 // This program is free software; you can redistribute it and/or modify it | |
| 9 // under the terms of the GNU General Public License as published by the Free | |
| 10 // Software Foundation; either version 2 of the License, or (at your option) | |
| 11 // any later version. | |
| 12 // | |
| 13 // This program is distributed in the hope that it will be useful, but WITHOUT | |
| 14 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 15 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
| 16 // more details. | |
| 17 // | |
| 18 // You should have received a copy of the GNU General Public License along with | |
| 19 // this program; if not, write to the Free Software Foundation, Inc., | |
| 20 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
| 21 // | |
| 22 // ---------------------------------------------------------------------------- | |
| 23 // | |
| 24 //####COPYRIGHTEND#### | |
| 25 //================================================================= | |
| 26 // | |
| 27 // eCosTestUtils.cpp | |
| 28 // | |
| 29 // Utility functions | |
| 30 // | |
| 31 //================================================================= | |
| 32 //================================================================= | |
| 33 //#####DESCRIPTIONBEGIN#### | |
| 34 // | |
| 35 // Author(s): sdf | |
| 36 // Contributors: sdf | |
| 37 // Date: 1999-04-01 | |
| 38 // Description: This class contains utility functions for use in the testing infrastructure | |
| 39 // Usage: | |
| 40 // | |
| 41 //####DESCRIPTIONEND#### | |
| 42 | |
| 43 #include "eCosStd.h" | |
| 44 #include "eCosTestUtils.h" | |
| 45 #include "eCosThreadUtils.h" | |
| 46 #include "eCosTrace.h" | |
| 47 | |
| 48 LPCTSTR const CeCosTestUtils::Tail(LPCTSTR const pszFile) | |
| 49 { | |
| 50 LPCTSTR pszTail=_tcsrchr(pszFile,_TCHAR('/')); | |
| 51 if(0==pszTail){ | |
| 52 pszTail=_tcsrchr(pszFile,_TCHAR('\\')); | |
| 53 } | |
| 54 return (0==pszTail)?pszFile:pszTail+1; | |
| 55 } | |
| 56 | |
| 57 LPCTSTR CeCosTestUtils::HostName() | |
| 58 { | |
| 59 static bool bFirstTime=true; | |
| 60 static String str; | |
| 61 static int nErr; | |
| 62 if(bFirstTime){ | |
| 63 char szMyname[256]; | |
| 64 nErr=gethostname(szMyname,sizeof szMyname); | |
| 65 bFirstTime=false; | |
| 66 if(0==nErr){ | |
| 67 str=String::CStrToUnicodeStr(szMyname); | |
| 68 } else { | |
| 69 str=_T(""); | |
| 70 } | |
| 71 } | |
| 72 return str; | |
| 73 } | |
| 74 | |
| 75 LPCTSTR CeCosTestUtils::SimpleHostName() | |
| 76 { | |
| 77 static bool bFirstTime=true; | |
| 78 static String str; | |
| 79 if(bFirstTime){ | |
| 80 str=HostName(); | |
| 81 // Remove all after a '.' | |
| 82 LPCTSTR c=_tcschr(str,_TCHAR('.')); | |
| 83 if(c){ | |
| 84 str.SetLength(c-(LPCTSTR )str); | |
| 85 } | |
| 86 bFirstTime=false; | |
| 87 } | |
| 88 return str; | |
| 89 } | |
| 90 | |
| 91 | |
| 92 | |
| 93 // File iterator. Gets next file in directory, avoiding _T(".") and _T("..") | |
| 94 bool CeCosTestUtils::NextFile (void *&pHandle,String &str) | |
| 95 { | |
| 96 #ifdef _WIN32 | |
| 97 WIN32_FIND_DATA fd; | |
| 98 while(FindNextFile((HANDLE)pHandle,&fd)){ | |
| 99 LPCTSTR pszName=fd.cFileName; | |
| 100 #else // UNIX | |
| 101 struct dirent *d; | |
| 102 while((d=readdir((DIR *)pHandle))){ | |
| 103 LPCTSTR pszName=d->d_name; | |
| 104 #endif | |
| 105 if(pszName[0]!='.'){ | |
| 106 str=pszName; | |
| 107 return true; | |
| 108 } | |
| 109 } | |
| 110 return false; | |
| 111 } | |
| 112 | |
| 113 // Start file iteration and return first file. | |
| 114 bool CeCosTestUtils::StartSearch (void *&pHandle,String &str) | |
| 115 { | |
| 116 #ifdef _WIN32 | |
| 117 WIN32_FIND_DATA fd; | |
| 118 pHandle=(void *)FindFirstFile (_T("*.*"), &fd); | |
| 119 if(INVALID_HANDLE_VALUE==(HANDLE)pHandle){ | |
| 120 ERROR(_T("Failed to open dir\n")); | |
| 121 return false; | |
| 122 } else if (fd.cFileName[0]=='.') { | |
| 123 return NextFile((HANDLE)pHandle,str); | |
| 124 } else { | |
| 125 str=String(fd.cFileName); | |
| 126 return true; | |
| 127 } | |
| 128 #else // UNIX | |
| 129 pHandle=(void *)opendir(_T(".")); | |
| 130 if(0==pHandle){ | |
| 131 ERROR(_T("Failed to open dir\n")); | |
| 132 return false; | |
| 133 } | |
| 134 return NextFile(pHandle,str); | |
| 135 #endif | |
| 136 } | |
| 137 | |
| 138 // End file iteration | |
| 139 void CeCosTestUtils::EndSearch (void *&pHandle) | |
| 140 { | |
| 141 #ifdef _WIN32 | |
| 142 FindClose((HANDLE)pHandle); | |
| 143 #else // UNIX | |
| 144 closedir((DIR *)pHandle); | |
| 145 #endif | |
| 146 } | |
| 147 | |
| 148 | |
| 149 // deal with common command-line actions | |
| 150 bool CeCosTestUtils::CommandLine(int &argc,TCHAR **argv) | |
| 151 { | |
| 152 for(int i=1;i<argc;i++){ | |
| 153 if(_TCHAR('-')==*argv[i]){ | |
| 154 if(0==_tcscmp(argv[i],_T("-v"))){ | |
| 155 CeCosTrace ::EnableTracing(true); | |
| 156 // Shuffle the command line down to remove that which we have just seen: | |
| 157 for(TCHAR **a=argv+i;(a[0]=a[1]);a++); | |
| 158 argc--;i--; // counteract the increment | |
| 159 } else if(0==_tcscmp(argv[i],_T("-o"))){ | |
| 160 if(i+1<argc){ | |
| 161 if(!CeCosTrace::SetOutput(argv[i+1])){ | |
| 162 ERROR(_T("Failed to direct output to %s\n"),argv[i+1]); | |
| 163 } | |
| 164 // Shuffle the command line down to remove that which we have just seen: | |
| 165 for(TCHAR **a=argv+i;(a[0]=a[2]);a++); | |
| 166 argc-=2;i-=2; // counteract the increment | |
| 167 } else { | |
| 168 return false; | |
| 169 } | |
| 170 } else if(0==_tcscmp(argv[i],_T("-version"))){ | |
| 171 const TCHAR *pszTail=_tcsrchr(argv[0],_TCHAR('/')); | |
| 172 if(0==pszTail){ | |
| 173 pszTail=_tcsrchr(argv[0],_TCHAR('\\')); | |
| 174 } | |
| 175 _tprintf (_T("%s %s (%s %s)\n"), (0==pszTail)?argv[0]:pszTail+1,ECOS_VERSION, __DATE__, __TIME__); | |
| 176 exit(0); | |
| 177 } | |
| 178 } | |
| 179 } | |
| 180 return true; | |
| 181 } | |
| 182 |
