-/*\r
-Copyright (c) 2001, Loki software, inc.\r
-All rights reserved.\r
-\r
-Redistribution and use in source and binary forms, with or without modification, \r
-are permitted provided that the following conditions are met:\r
-\r
-Redistributions of source code must retain the above copyright notice, this list \r
-of conditions and the following disclaimer.\r
-\r
-Redistributions in binary form must reproduce the above copyright notice, this\r
-list of conditions and the following disclaimer in the documentation and/or\r
-other materials provided with the distribution.\r
-\r
-Neither the name of Loki software nor the names of its contributors may be used \r
-to endorse or promote products derived from this software without specific prior \r
-written permission. \r
-\r
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' \r
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE \r
-IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE \r
-DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY \r
-DIRECT,INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES \r
-(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; \r
-LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON \r
-ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS \r
-SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \r
-*/\r
-\r
-#ifndef _MISSING_H_\r
-#define _MISSING_H_\r
-\r
-// NOTE TTimo\r
-// this goes along with str.h and provides various utility classes\r
-// and portability defines\r
-// the filename is a legecy issue, it would be better to clean that up\r
-// in a central 'portability' lib\r
-\r
-#include <glib.h>\r
-#include <string.h>\r
-\r
-#ifdef _WIN32\r
-#include <direct.h>\r
-#include <io.h>\r
-\r
-#define MyCopyFile(a,b) CopyFile(a,b,FALSE)\r
-\r
-#define S_ISDIR(mode) (mode & _S_IFDIR)\r
-#define R_OK 04\r
-#define mymkdir(a,b) _mkdir(a)\r
-\r
-#else\r
-\r
-#define MyCopyFile CopyFile\r
-#define mymkdir(a,b) mkdir(a,b)\r
-\r
-#endif\r
-\r
-#ifndef _WIN32\r
-\r
-// LZ: very ugly hacks\r
-inline int GetLastError () { return 0; };\r
-\r
-// temp stuff\r
-inline int GetPrivateProfileInt(char* a, char* b, int i, char* c) { return i; };\r
-#define VERIFY(a) a;\r
-int GetFullPathName(const char *lpFileName, int nBufferLength, char *lpBuffer, char **lpFilePart);\r
-bool CopyFile(const char *lpExistingFileName, const char *lpNewFileName);\r
-\r
-#ifndef APIENTRY\r
-#define APIENTRY\r
-#endif\r
-\r
-int MemorySize(void *ptr);\r
-#define _msize MemorySize\r
-\r
-#define MK_LBUTTON 0x0001\r
-#define MK_RBUTTON 0x0002\r
-#define MK_SHIFT 0x0004\r
-#define MK_CONTROL 0x0008\r
-#define MK_MBUTTON 0x0010\r
-\r
-#endif\r
-\r
-#define CString Str\r
-#include "str.h"\r
-\r
-class CPtrArray\r
-{\r
-public:\r
- CPtrArray ()\r
- { m_ptrs = g_ptr_array_new (); };\r
- virtual ~CPtrArray ()\r
- { g_ptr_array_free (m_ptrs, TRUE); };\r
- \r
- void* operator[](int i) const\r
- { return g_ptr_array_index (m_ptrs,i); };\r
- void* GetAt(int i) const\r
- { return g_ptr_array_index (m_ptrs,i); };\r
- int GetSize () const\r
- { return m_ptrs->len; };\r
- void Add (void* ptr)\r
- { g_ptr_array_add (m_ptrs, ptr); };\r
- void RemoveAll ()\r
- { g_ptr_array_set_size (m_ptrs, 0); };\r
- void RemoveAt(int index, int count = 1)\r
- {\r
- if ((index < 0) || (count < 0) || (count + index > (int)m_ptrs->len))\r
- return;\r
- for (; count > 0; count--)\r
- g_ptr_array_remove_index (m_ptrs, index);\r
- }\r
- void InsertAt(int nStartIndex, CPtrArray* pNewArray)\r
- {\r
- for (int i = 0; i < pNewArray->GetSize(); i++)\r
- InsertAt(nStartIndex+i, pNewArray->GetAt(i));\r
- }\r
- void InsertAt(int nIndex, void* newElement, int nCount = 1)\r
- {\r
- if ((guint32)nIndex >= m_ptrs->len)\r
- {\r
- g_ptr_array_set_size (m_ptrs, nIndex + nCount); // grow so nIndex is valid\r
- }\r
- else\r
- {\r
- // inserting in the middle of the array\r
- int nOldSize = m_ptrs->len;\r
- g_ptr_array_set_size (m_ptrs, m_ptrs->len + nCount);\r
- // shift old data up to fill gap\r
- memmove(&m_ptrs->pdata[nIndex+nCount], &m_ptrs->pdata[nIndex],\r
- (nOldSize-nIndex) * sizeof(gpointer));\r
- \r
- memset(&m_ptrs->pdata[nIndex], 0, nCount * sizeof(gpointer));\r
- }\r
- \r
- // insert new value in the gap\r
- while (nCount--)\r
- m_ptrs->pdata[nIndex++] = newElement;\r
- }\r
- void Copy(const CPtrArray& src)\r
- {\r
- g_ptr_array_set_size (m_ptrs, src.m_ptrs->len);\r
- memcpy (m_ptrs->pdata, src.m_ptrs->pdata, m_ptrs->len*sizeof(gpointer));\r
- }\r
- \r
-protected:\r
- GPtrArray* m_ptrs;\r
-};\r
-\r
-typedef struct stringmap_s\r
-{\r
- char* key;\r
- char* value;\r
-} stringmap_t;\r
-\r
-class CMapStringToString\r
-{\r
-public:\r
- CMapStringToString ()\r
- { m_map = g_ptr_array_new (); };\r
- ~CMapStringToString ()\r
- {\r
- for (guint32 i = 0; i < m_map->len; i++)\r
- FreeElement ((stringmap_t*)g_ptr_array_index (m_map,i));\r
- g_ptr_array_set_size (m_map, 0);\r
- g_ptr_array_free (m_map, TRUE);\r
- };\r
- void SetAt(char* key, char* newValue)\r
- {\r
- for (guint32 i = 0; i < m_map->len; i++)\r
- {\r
- stringmap_t* entry = (stringmap_t*)g_ptr_array_index (m_map,i);\r
- if (strcmp (entry->key, key) == 0)\r
- {\r
- g_free (entry->value);\r
- entry->value = g_strdup (newValue);\r
- return;\r
- }\r
- }\r
- stringmap_t* entry = (stringmap_t*)g_malloc (sizeof (stringmap_t));\r
- entry->key = g_strdup (key);\r
- entry->value = g_strdup (newValue);\r
- g_ptr_array_add (m_map, entry);\r
- }\r
- \r
- bool Lookup(const char* key, CString& rValue) const\r
- {\r
- for (guint32 i = 0; i < m_map->len; i++)\r
- {\r
- stringmap_t* entry = (stringmap_t*)g_ptr_array_index (m_map,i);\r
- if (strcmp (entry->key, key) == 0)\r
- {\r
- rValue = entry->value;\r
- return true;\r
- }\r
- }\r
- return false;\r
- }\r
- \r
-protected:\r
- GPtrArray* m_map;\r
- \r
- void FreeElement(stringmap_t* elem)\r
- { \r
- g_free (elem->key);\r
- g_free (elem->value);\r
- g_free (elem);\r
- };\r
-};\r
-\r
-#endif // _MISSING_H_\r
+/*
+Copyright (c) 2001, Loki software, inc.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+Redistributions of source code must retain the above copyright notice, this list
+of conditions and the following disclaimer.
+
+Redistributions in binary form must reproduce the above copyright notice, this
+list of conditions and the following disclaimer in the documentation and/or
+other materials provided with the distribution.
+
+Neither the name of Loki software nor the names of its contributors may be used
+to endorse or promote products derived from this software without specific prior
+written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
+DIRECT,INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#ifndef _MISSING_H_
+#define _MISSING_H_
+
+// NOTE TTimo
+// this goes along with str.h and provides various utility classes
+// and portability defines
+// the filename is a legecy issue, it would be better to clean that up
+// in a central 'portability' lib
+
+#include <glib.h>
+#include <string.h>
+
+#ifdef _WIN32
+#include <direct.h>
+#include <io.h>
+
+#define MyCopyFile(a,b) CopyFile(a,b,FALSE)
+
+#define S_ISDIR(mode) (mode & _S_IFDIR)
+#define R_OK 04
+#define mymkdir(a,b) _mkdir(a)
+
+#else
+
+#define MyCopyFile CopyFile
+#define mymkdir(a,b) mkdir(a,b)
+
+#endif
+
+#ifndef _WIN32
+
+// LZ: very ugly hacks
+inline int GetLastError () { return 0; };
+
+// temp stuff
+inline int GetPrivateProfileInt(char* a, char* b, int i, char* c) { return i; };
+#define VERIFY(a) a;
+int GetFullPathName(const char *lpFileName, int nBufferLength, char *lpBuffer, char **lpFilePart);
+bool CopyFile(const char *lpExistingFileName, const char *lpNewFileName);
+
+#ifndef APIENTRY
+#define APIENTRY
+#endif
+
+int MemorySize(void *ptr);
+#define _msize MemorySize
+
+#define MK_LBUTTON 0x0001
+#define MK_RBUTTON 0x0002
+#define MK_SHIFT 0x0004
+#define MK_CONTROL 0x0008
+#define MK_MBUTTON 0x0010
+
+#endif
+
+#define CString Str
+#include "str.h"
+
+class CPtrArray
+{
+public:
+ CPtrArray ()
+ { m_ptrs = g_ptr_array_new (); };
+ virtual ~CPtrArray ()
+ { g_ptr_array_free (m_ptrs, TRUE); };
+
+ void* operator[](int i) const
+ { return g_ptr_array_index (m_ptrs,i); };
+ void* GetAt(int i) const
+ { return g_ptr_array_index (m_ptrs,i); };
+ int GetSize () const
+ { return m_ptrs->len; };
+ void Add (void* ptr)
+ { g_ptr_array_add (m_ptrs, ptr); };
+ void RemoveAll ()
+ { g_ptr_array_set_size (m_ptrs, 0); };
+ void RemoveAt(int index, int count = 1)
+ {
+ if ((index < 0) || (count < 0) || (count + index > (int)m_ptrs->len))
+ return;
+ for (; count > 0; count--)
+ g_ptr_array_remove_index (m_ptrs, index);
+ }
+ void InsertAt(int nStartIndex, CPtrArray* pNewArray)
+ {
+ for (int i = 0; i < pNewArray->GetSize(); i++)
+ InsertAt(nStartIndex+i, pNewArray->GetAt(i));
+ }
+ void InsertAt(int nIndex, void* newElement, int nCount = 1)
+ {
+ if ((guint32)nIndex >= m_ptrs->len)
+ {
+ g_ptr_array_set_size (m_ptrs, nIndex + nCount); // grow so nIndex is valid
+ }
+ else
+ {
+ // inserting in the middle of the array
+ int nOldSize = m_ptrs->len;
+ g_ptr_array_set_size (m_ptrs, m_ptrs->len + nCount);
+ // shift old data up to fill gap
+ memmove(&m_ptrs->pdata[nIndex+nCount], &m_ptrs->pdata[nIndex],
+ (nOldSize-nIndex) * sizeof(gpointer));
+
+ memset(&m_ptrs->pdata[nIndex], 0, nCount * sizeof(gpointer));
+ }
+
+ // insert new value in the gap
+ while (nCount--)
+ m_ptrs->pdata[nIndex++] = newElement;
+ }
+ void Copy(const CPtrArray& src)
+ {
+ g_ptr_array_set_size (m_ptrs, src.m_ptrs->len);
+ memcpy (m_ptrs->pdata, src.m_ptrs->pdata, m_ptrs->len*sizeof(gpointer));
+ }
+
+protected:
+ GPtrArray* m_ptrs;
+};
+
+typedef struct stringmap_s
+{
+ char* key;
+ char* value;
+} stringmap_t;
+
+class CMapStringToString
+{
+public:
+ CMapStringToString ()
+ { m_map = g_ptr_array_new (); };
+ ~CMapStringToString ()
+ {
+ for (guint32 i = 0; i < m_map->len; i++)
+ FreeElement ((stringmap_t*)g_ptr_array_index (m_map,i));
+ g_ptr_array_set_size (m_map, 0);
+ g_ptr_array_free (m_map, TRUE);
+ };
+ void SetAt(char* key, char* newValue)
+ {
+ for (guint32 i = 0; i < m_map->len; i++)
+ {
+ stringmap_t* entry = (stringmap_t*)g_ptr_array_index (m_map,i);
+ if (strcmp (entry->key, key) == 0)
+ {
+ g_free (entry->value);
+ entry->value = g_strdup (newValue);
+ return;
+ }
+ }
+ stringmap_t* entry = (stringmap_t*)g_malloc (sizeof (stringmap_t));
+ entry->key = g_strdup (key);
+ entry->value = g_strdup (newValue);
+ g_ptr_array_add (m_map, entry);
+ }
+
+ bool Lookup(const char* key, CString& rValue) const
+ {
+ for (guint32 i = 0; i < m_map->len; i++)
+ {
+ stringmap_t* entry = (stringmap_t*)g_ptr_array_index (m_map,i);
+ if (strcmp (entry->key, key) == 0)
+ {
+ rValue = entry->value;
+ return true;
+ }
+ }
+ return false;
+ }
+
+protected:
+ GPtrArray* m_map;
+
+ void FreeElement(stringmap_t* elem)
+ {
+ g_free (elem->key);
+ g_free (elem->value);
+ g_free (elem);
+ };
+};
+
+#endif // _MISSING_H_