2 Copyright (c) 2001, Loki software, inc.
5 Redistribution and use in source and binary forms, with or without modification,
6 are permitted provided that the following conditions are met:
8 Redistributions of source code must retain the above copyright notice, this list
9 of conditions and the following disclaimer.
11 Redistributions in binary form must reproduce the above copyright notice, this
12 list of conditions and the following disclaimer in the documentation and/or
13 other materials provided with the distribution.
15 Neither the name of Loki software nor the names of its contributors may be used
16 to endorse or promote products derived from this software without specific prior
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
20 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
23 DIRECT,INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 // this goes along with str.h and provides various utility classes
36 // and portability defines
37 // the file name (missing.h) is a legacy issue, it would be better to clean that up
38 // in a central 'portability' lib
48 #include <sys/types.h>
55 // LZ: very ugly hacks
56 inline int GetLastError() { return 0; };
59 inline int GetPrivateProfileInt( char* a, char* b, int i, char* c ) { return i; };
60 int GetFullPathName( const char *lpFileName, int nBufferLength, char *lpBuffer, char **lpFilePart );
66 int MemorySize( void *ptr );
67 #define _msize MemorySize
69 #define MK_LBUTTON 0x0001
70 #define MK_RBUTTON 0x0002
71 #define MK_SHIFT 0x0004
72 #define MK_CONTROL 0x0008
73 #define MK_MBUTTON 0x0010
87 { m_ptrs = g_ptr_array_new(); };
89 { g_ptr_array_free( m_ptrs, TRUE ); };
91 void* operator[]( int i ) const
92 { return g_ptr_array_index( m_ptrs,i ); };
93 void* GetAt( int i ) const
94 { return g_ptr_array_index( m_ptrs,i ); };
96 { return m_ptrs->len; };
98 { g_ptr_array_add( m_ptrs, ptr ); };
100 { g_ptr_array_set_size( m_ptrs, 0 ); };
101 void RemoveAt( int index, int count = 1 ){
102 if ( ( index < 0 ) || ( count < 0 ) || ( count + index > (int)m_ptrs->len ) ) {
105 for (; count > 0; count-- )
106 g_ptr_array_remove_index( m_ptrs, index );
108 void InsertAt( int nStartIndex, CPtrArray* pNewArray ){
109 for ( int i = 0; i < pNewArray->GetSize(); i++ )
110 InsertAt( nStartIndex + i, pNewArray->GetAt( i ) );
112 void InsertAt( int nIndex, void* newElement, int nCount = 1 ){
113 if ( (guint32)nIndex >= m_ptrs->len ) {
114 g_ptr_array_set_size( m_ptrs, nIndex + nCount ); // grow so nIndex is valid
118 // inserting in the middle of the array
119 int nOldSize = m_ptrs->len;
120 g_ptr_array_set_size( m_ptrs, m_ptrs->len + nCount );
121 // shift old data up to fill gap
122 memmove( &m_ptrs->pdata[nIndex + nCount], &m_ptrs->pdata[nIndex],
123 ( nOldSize - nIndex ) * sizeof( gpointer ) );
125 memset( &m_ptrs->pdata[nIndex], 0, nCount * sizeof( gpointer ) );
128 // insert new value in the gap
130 m_ptrs->pdata[nIndex++] = newElement;
132 void Copy( const CPtrArray& src ){
133 g_ptr_array_set_size( m_ptrs, src.m_ptrs->len );
134 memcpy( m_ptrs->pdata, src.m_ptrs->pdata, m_ptrs->len * sizeof( gpointer ) );
141 typedef struct stringmap_s
147 class CMapStringToString
150 CMapStringToString ()
151 { m_map = g_ptr_array_new(); };
152 ~CMapStringToString (){
153 for ( guint32 i = 0; i < m_map->len; i++ )
154 FreeElement( (stringmap_t*)g_ptr_array_index( m_map,i ) );
155 g_ptr_array_set_size( m_map, 0 );
156 g_ptr_array_free( m_map, TRUE );
158 void SetAt( char* key, char* newValue ){
159 for ( guint32 i = 0; i < m_map->len; i++ )
161 stringmap_t* entry = (stringmap_t*)g_ptr_array_index( m_map,i );
162 if ( strcmp( entry->key, key ) == 0 ) {
163 g_free( entry->value );
164 entry->value = g_strdup( newValue );
168 stringmap_t* entry = (stringmap_t*)g_malloc( sizeof( stringmap_t ) );
169 entry->key = g_strdup( key );
170 entry->value = g_strdup( newValue );
171 g_ptr_array_add( m_map, entry );
174 bool Lookup( const char* key, CString& rValue ) const {
175 for ( guint32 i = 0; i < m_map->len; i++ )
177 stringmap_t* entry = (stringmap_t*)g_ptr_array_index( m_map,i );
178 if ( strcmp( entry->key, key ) == 0 ) {
179 rValue = entry->value;
189 void FreeElement( stringmap_t* elem ){
191 g_free( elem->value );
198 FindFiles( const char *directory );
201 const char* NextFile();
206 WIN32_FIND_DATA findFileData;
212 bool radCopyTree( const char* source, const char* dest, bool fatal_on_error = true );
215 PATH_FAIL, // stat call failed (does not exist is likely)
220 // check a path for existence, return directory / file
221 EPathCheck CheckFile( const char *path );
223 bool radCreateDirectory( const char *directory, bool fatal_on_error = true );
224 bool radCopyFile( const char *lpExistingFileName, const char *lpNewFileName, bool fatal_on_error = true );
226 #endif // _MISSING_H_