Just renaming some class members and adding Jim Park's comments
git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@6049 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
parent
f5df185ba2
commit
9852de80be
8 changed files with 176 additions and 133 deletions
|
@ -45,8 +45,8 @@ struct version_string_list
|
||||||
|
|
||||||
CVersionStrigList::~CVersionStrigList()
|
CVersionStrigList::~CVersionStrigList()
|
||||||
{
|
{
|
||||||
struct version_string_list *itr = (struct version_string_list *) gr.get();
|
struct version_string_list *itr = (struct version_string_list *) m_gr.get();
|
||||||
int i = gr.getlen() / sizeof(struct version_string_list);
|
int i = m_gr.getlen() / sizeof(struct version_string_list);
|
||||||
|
|
||||||
while (i--)
|
while (i--)
|
||||||
{
|
{
|
||||||
|
@ -60,27 +60,27 @@ int CVersionStrigList::add(LANGID langid, int codepage)
|
||||||
_stprintf(Buff, _T("%04x"), langid);
|
_stprintf(Buff, _T("%04x"), langid);
|
||||||
int pos = SortedStringListND<struct version_string_list>::add(Buff);
|
int pos = SortedStringListND<struct version_string_list>::add(Buff);
|
||||||
if (pos == -1) return false;
|
if (pos == -1) return false;
|
||||||
((struct version_string_list*)gr.get())[pos].pChildStrings = new DefineList;
|
((struct version_string_list*)m_gr.get())[pos].pChildStrings = new DefineList;
|
||||||
((struct version_string_list*)gr.get())[pos].codepage = codepage;
|
((struct version_string_list*)m_gr.get())[pos].codepage = codepage;
|
||||||
((struct version_string_list*)gr.get())[pos].lang_id = langid;
|
((struct version_string_list*)m_gr.get())[pos].lang_id = langid;
|
||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
LANGID CVersionStrigList::get_lang(int idx)
|
LANGID CVersionStrigList::get_lang(int idx)
|
||||||
{
|
{
|
||||||
version_string_list *data=(version_string_list *)gr.get();
|
version_string_list *data=(version_string_list *)m_gr.get();
|
||||||
return data[idx].lang_id;
|
return data[idx].lang_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CVersionStrigList::get_codepage(int idx)
|
int CVersionStrigList::get_codepage(int idx)
|
||||||
{
|
{
|
||||||
version_string_list *data=(version_string_list *)gr.get();
|
version_string_list *data=(version_string_list *)m_gr.get();
|
||||||
return data[idx].codepage;
|
return data[idx].codepage;
|
||||||
}
|
}
|
||||||
|
|
||||||
DefineList* CVersionStrigList::get_strings(int idx)
|
DefineList* CVersionStrigList::get_strings(int idx)
|
||||||
{
|
{
|
||||||
version_string_list *data=(version_string_list *)gr.get();
|
version_string_list *data=(version_string_list *)m_gr.get();
|
||||||
return data[idx].pChildStrings;
|
return data[idx].pChildStrings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,12 +93,12 @@ int CVersionStrigList::find(LANGID lang_id, int codepage)
|
||||||
|
|
||||||
int CVersionStrigList::getlen()
|
int CVersionStrigList::getlen()
|
||||||
{
|
{
|
||||||
return strings.getlen();
|
return m_strings.getlen();
|
||||||
}
|
}
|
||||||
|
|
||||||
int CVersionStrigList::getnum()
|
int CVersionStrigList::getnum()
|
||||||
{
|
{
|
||||||
return gr.getlen()/sizeof(struct version_string_list);
|
return m_gr.getlen()/sizeof(struct version_string_list);
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
|
|
||||||
ConstantsStringList::ConstantsStringList()
|
ConstantsStringList::ConstantsStringList()
|
||||||
{
|
{
|
||||||
index = 0;
|
m_index = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ConstantsStringList::add(const TCHAR *name, int value1, int value2)
|
int ConstantsStringList::add(const TCHAR *name, int value1, int value2)
|
||||||
|
@ -28,13 +28,13 @@ int ConstantsStringList::add(const TCHAR *name, int value1, int value2)
|
||||||
int pos=SortedStringListND<struct constantstring>::add(name);
|
int pos=SortedStringListND<struct constantstring>::add(name);
|
||||||
if (pos == -1) return -1;
|
if (pos == -1) return -1;
|
||||||
|
|
||||||
((struct constantstring*)gr.get())[pos].index = index;
|
((struct constantstring*)m_gr.get())[pos].index = m_index;
|
||||||
((struct constantstring*)gr.get())[pos].pos = pos;
|
((struct constantstring*)m_gr.get())[pos].pos = pos;
|
||||||
((struct constantstring*)gr.get())[pos].value1 = value1;
|
((struct constantstring*)m_gr.get())[pos].value1 = value1;
|
||||||
((struct constantstring*)gr.get())[pos].value2 = value2;
|
((struct constantstring*)m_gr.get())[pos].value2 = value2;
|
||||||
|
|
||||||
int temp = index;
|
int temp = m_index;
|
||||||
index++;
|
m_index++;
|
||||||
|
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
|
@ -43,42 +43,42 @@ int ConstantsStringList::get(TCHAR *name, int n_chars /*= -1*/)
|
||||||
{
|
{
|
||||||
int v=SortedStringListND<struct constantstring>::find(name, n_chars);
|
int v=SortedStringListND<struct constantstring>::find(name, n_chars);
|
||||||
if (v==-1) return -1;
|
if (v==-1) return -1;
|
||||||
return (((struct constantstring*)gr.get())[v].index);
|
return (((struct constantstring*) m_gr.get())[v].index);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ConstantsStringList::getnum()
|
int ConstantsStringList::getnum()
|
||||||
{
|
{
|
||||||
return index;
|
return m_index;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ConstantsStringList::get_value1(int idx)
|
int ConstantsStringList::get_value1(int idx)
|
||||||
{
|
{
|
||||||
int pos=get_internal_idx(idx);
|
int pos=get_internal_idx(idx);
|
||||||
if (pos==-1) return -1;
|
if (pos==-1) return -1;
|
||||||
return (((struct constantstring*)gr.get())[pos].value1);
|
return (((struct constantstring*) m_gr.get())[pos].value1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ConstantsStringList::get_value2(int idx)
|
int ConstantsStringList::get_value2(int idx)
|
||||||
{
|
{
|
||||||
int pos=get_internal_idx(idx);
|
int pos=get_internal_idx(idx);
|
||||||
if (pos==-1) return -1;
|
if (pos==-1) return -1;
|
||||||
return (((struct constantstring*)gr.get())[pos].value2);
|
return (((struct constantstring*) m_gr.get())[pos].value2);
|
||||||
}
|
}
|
||||||
|
|
||||||
TCHAR* ConstantsStringList::idx2name(int idx)
|
TCHAR* ConstantsStringList::idx2name(int idx)
|
||||||
{
|
{
|
||||||
int pos=get_internal_idx(idx);
|
int pos=get_internal_idx(idx);
|
||||||
if (pos==-1) return NULL;
|
if (pos==-1) return NULL;
|
||||||
struct constantstring *data=(struct constantstring *)gr.get();
|
struct constantstring *data=(struct constantstring *) m_gr.get();
|
||||||
return ((TCHAR*)strings.get() + data[pos].name);
|
return ((TCHAR*) m_strings.get() + data[pos].name);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ConstantsStringList::get_internal_idx(int idx)
|
int ConstantsStringList::get_internal_idx(int idx)
|
||||||
{
|
{
|
||||||
struct constantstring *data=(struct constantstring *)gr.get();
|
struct constantstring *data=(struct constantstring *) m_gr.get();
|
||||||
|
|
||||||
// We do a linear search because the strings are sorted.
|
// We do a linear search because the strings are sorted.
|
||||||
for (int i = 0; i < index; i++)
|
for (int i = 0; i < m_index; i++)
|
||||||
{
|
{
|
||||||
if (data[i].index == idx)
|
if (data[i].index == idx)
|
||||||
{
|
{
|
||||||
|
|
|
@ -42,7 +42,7 @@ class ConstantsStringList : public SortedStringListND<struct constantstring>
|
||||||
TCHAR *idx2name(int idx);
|
TCHAR *idx2name(int idx);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int index;
|
int m_index;
|
||||||
int get_internal_idx(int idx);
|
int get_internal_idx(int idx);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -149,7 +149,7 @@ NLFString NLFStrings[NLF_STRINGS] = {
|
||||||
// ==============
|
// ==============
|
||||||
|
|
||||||
LangStringList::LangStringList() {
|
LangStringList::LangStringList() {
|
||||||
count = 0;
|
m_count = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int LangStringList::add(const TCHAR *name, int *sn/*=0*/)
|
int LangStringList::add(const TCHAR *name, int *sn/*=0*/)
|
||||||
|
@ -157,12 +157,12 @@ int LangStringList::add(const TCHAR *name, int *sn/*=0*/)
|
||||||
int pos = SortedStringListND<struct langstring>::add(name);
|
int pos = SortedStringListND<struct langstring>::add(name);
|
||||||
if (pos == -1) return -1;
|
if (pos == -1) return -1;
|
||||||
|
|
||||||
((struct langstring*)gr.get())[pos].sn = count;
|
((struct langstring*)m_gr.get())[pos].sn = m_count;
|
||||||
if (sn) *sn = count;
|
if (sn) *sn = m_count;
|
||||||
count++;
|
m_count++;
|
||||||
((struct langstring*)gr.get())[pos].index = -1;
|
((struct langstring*)m_gr.get())[pos].index = -1;
|
||||||
((struct langstring*)gr.get())[pos].uindex = -1;
|
((struct langstring*)m_gr.get())[pos].uindex = -1;
|
||||||
((struct langstring*)gr.get())[pos].process = 1;
|
((struct langstring*)m_gr.get())[pos].process = 1;
|
||||||
|
|
||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
|
@ -174,19 +174,19 @@ int LangStringList::get(const TCHAR *name, int *sn/*=0*/, int *index/*=0*/, int
|
||||||
if (sn) *sn = -1;
|
if (sn) *sn = -1;
|
||||||
int v=find(name);
|
int v=find(name);
|
||||||
if (v==-1) return -1;
|
if (v==-1) return -1;
|
||||||
if (index) *index = ((struct langstring*)gr.get())[v].index;
|
if (index) *index = ((struct langstring*)m_gr.get())[v].index;
|
||||||
if (uindex) *uindex = ((struct langstring*)gr.get())[v].uindex;
|
if (uindex) *uindex = ((struct langstring*)m_gr.get())[v].uindex;
|
||||||
if (sn) *sn = ((struct langstring*)gr.get())[v].sn;
|
if (sn) *sn = ((struct langstring*)m_gr.get())[v].sn;
|
||||||
if (process) *process = ((struct langstring*)gr.get())[v].process;
|
if (process) *process = ((struct langstring*)m_gr.get())[v].process;
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LangStringList::set(int pos, int index/*=-1*/, int uindex/*=-1*/, int process/*=-1*/)
|
void LangStringList::set(int pos, int index/*=-1*/, int uindex/*=-1*/, int process/*=-1*/)
|
||||||
{
|
{
|
||||||
if ((unsigned int)pos > (gr.getlen() / sizeof(struct langstring)))
|
if ((unsigned int)pos > (m_gr.getlen() / sizeof(struct langstring)))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
struct langstring *data=(struct langstring *)gr.get();
|
struct langstring *data=(struct langstring *)m_gr.get();
|
||||||
|
|
||||||
if (index >= 0)
|
if (index >= 0)
|
||||||
data[pos].index = index;
|
data[pos].index = index;
|
||||||
|
@ -203,25 +203,25 @@ void LangStringList::set(const TCHAR *name, int index, int uindex/*=-1*/, int pr
|
||||||
|
|
||||||
const TCHAR* LangStringList::pos2name(int pos)
|
const TCHAR* LangStringList::pos2name(int pos)
|
||||||
{
|
{
|
||||||
struct langstring *data=(struct langstring *)gr.get();
|
struct langstring *data=(struct langstring *) m_gr.get();
|
||||||
|
|
||||||
if ((unsigned int)pos > (gr.getlen() / sizeof(struct langstring)))
|
if ((unsigned int)pos > (m_gr.getlen() / sizeof(struct langstring)))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return ((const TCHAR*)strings.get() + data[pos].name);
|
return ((const TCHAR*) m_strings.get() + data[pos].name);
|
||||||
}
|
}
|
||||||
|
|
||||||
const TCHAR* LangStringList::offset2name(int name)
|
const TCHAR* LangStringList::offset2name(int name)
|
||||||
{
|
{
|
||||||
if ((unsigned int)name > (unsigned int)strings.getlen())
|
if ((unsigned int)name > (unsigned int)m_strings.getlen())
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return (const TCHAR*)strings.get() + name;
|
return (const TCHAR*) m_strings.get() + name;
|
||||||
}
|
}
|
||||||
|
|
||||||
int LangStringList::getnum()
|
int LangStringList::getnum()
|
||||||
{
|
{
|
||||||
return gr.getlen() / sizeof(struct langstring);
|
return m_gr.getlen() / sizeof(struct langstring);
|
||||||
}
|
}
|
||||||
|
|
||||||
int LangStringList::compare_index(const void *item1, const void *item2)
|
int LangStringList::compare_index(const void *item1, const void *item2)
|
||||||
|
@ -235,11 +235,11 @@ int LangStringList::compare_index(const void *item1, const void *item2)
|
||||||
langstring* LangStringList::sort_index(int *num)
|
langstring* LangStringList::sort_index(int *num)
|
||||||
{
|
{
|
||||||
if (!num) return 0;
|
if (!num) return 0;
|
||||||
sortbuf.resize(0);
|
m_sortbuf.resize(0);
|
||||||
sortbuf.add(gr.get(), gr.getlen());
|
m_sortbuf.add(m_gr.get(), m_gr.getlen());
|
||||||
*num = sortbuf.getlen() / sizeof(struct langstring);
|
*num = m_sortbuf.getlen() / sizeof(struct langstring);
|
||||||
qsort(sortbuf.get(), *num, sizeof(struct langstring), compare_index);
|
qsort(m_sortbuf.get(), *num, sizeof(struct langstring), compare_index);
|
||||||
return (struct langstring*) sortbuf.get();
|
return (struct langstring*) m_sortbuf.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
int LangStringList::compare_uindex(const void *item1, const void *item2)
|
int LangStringList::compare_uindex(const void *item1, const void *item2)
|
||||||
|
@ -253,11 +253,11 @@ int LangStringList::compare_uindex(const void *item1, const void *item2)
|
||||||
langstring* LangStringList::sort_uindex(int *num)
|
langstring* LangStringList::sort_uindex(int *num)
|
||||||
{
|
{
|
||||||
if (!num) return 0;
|
if (!num) return 0;
|
||||||
sortbuf.resize(0);
|
m_sortbuf.resize(0);
|
||||||
sortbuf.add(gr.get(), gr.getlen());
|
m_sortbuf.add(m_gr.get(), m_gr.getlen());
|
||||||
*num = sortbuf.getlen() / sizeof(struct langstring);
|
*num = m_sortbuf.getlen() / sizeof(struct langstring);
|
||||||
qsort(sortbuf.get(), *num, sizeof(struct langstring), compare_uindex);
|
qsort(m_sortbuf.get(), *num, sizeof(struct langstring), compare_uindex);
|
||||||
return (struct langstring*) sortbuf.get();
|
return (struct langstring*) m_sortbuf.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
// ============
|
// ============
|
||||||
|
@ -266,14 +266,15 @@ langstring* LangStringList::sort_uindex(int *num)
|
||||||
|
|
||||||
StringsArray::StringsArray()
|
StringsArray::StringsArray()
|
||||||
{
|
{
|
||||||
offsets.set_zeroing(1);
|
// We make zero an invalid index. Using 0 will get back an empty string.
|
||||||
|
m_offsets.set_zeroing(1);
|
||||||
|
|
||||||
strings.add(_T(""), sizeof(_T("")));
|
m_strings.add(_T(""), sizeof(_T("")));
|
||||||
}
|
}
|
||||||
|
|
||||||
void StringsArray::resize(int num)
|
void StringsArray::resize(int num)
|
||||||
{
|
{
|
||||||
offsets.resize(num * sizeof(int));
|
m_offsets.resize(num * sizeof(int));
|
||||||
}
|
}
|
||||||
|
|
||||||
int StringsArray::set(int idx, const TCHAR *str)
|
int StringsArray::set(int idx, const TCHAR *str)
|
||||||
|
@ -281,22 +282,23 @@ int StringsArray::set(int idx, const TCHAR *str)
|
||||||
if (idx < 0)
|
if (idx < 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (idx >= (int)(offsets.getlen() / sizeof(int)))
|
if (idx >= (int)(m_offsets.getlen() / sizeof(int)))
|
||||||
resize(idx+1);
|
resize(idx+1);
|
||||||
|
|
||||||
int old = ((int*)offsets.get())[idx];
|
int old = ((int*) m_offsets.get())[idx];
|
||||||
|
|
||||||
((int*)offsets.get())[idx] = strings.add(str, (_tcsclen(str)+1)*sizeof(TCHAR))/sizeof(TCHAR);
|
// Need to store the TCHAR index so we divide the return value of add by sizeof(TCHAR).
|
||||||
|
((int*)m_offsets.get())[idx] = m_strings.add(str, (_tcsclen(str)+1)*sizeof(TCHAR))/sizeof(TCHAR);
|
||||||
|
|
||||||
return old;
|
return old;
|
||||||
}
|
}
|
||||||
|
|
||||||
const TCHAR* StringsArray::get(int idx)
|
const TCHAR* StringsArray::get(int idx)
|
||||||
{
|
{
|
||||||
if ((unsigned int)idx >= (offsets.getlen() / sizeof(int)))
|
if ((unsigned int)idx >= (m_offsets.getlen() / sizeof(int)))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return (const TCHAR *)strings.get() + ((int*)offsets.get())[idx];
|
return (const TCHAR *) m_strings.get() + ((int*) m_offsets.get())[idx];
|
||||||
}
|
}
|
||||||
|
|
||||||
// =========
|
// =========
|
||||||
|
|
|
@ -152,8 +152,8 @@ class LangStringList : public SortedStringListND<struct langstring>
|
||||||
langstring *sort_uindex(int *num);
|
langstring *sort_uindex(int *num);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int count;
|
int m_count; // Used to set string number (sn)
|
||||||
TinyGrowBuf sortbuf;
|
TinyGrowBuf m_sortbuf; // Used only to sort.
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -195,8 +195,8 @@ class StringsArray
|
||||||
const TCHAR *get(int idx);
|
const TCHAR *get(int idx);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TinyGrowBuf offsets;
|
TinyGrowBuf m_offsets; /* Positional offsets of the stored string. */
|
||||||
GrowBuf strings;
|
GrowBuf m_strings; /* Storage of the actual strings. */
|
||||||
};
|
};
|
||||||
|
|
||||||
#define NLF_VERSION 6
|
#define NLF_VERSION 6
|
||||||
|
|
|
@ -12,6 +12,8 @@
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty.
|
* warranty.
|
||||||
|
*
|
||||||
|
* Doxygen comments by Jim Park -- 08/01/2007
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "strlist.h"
|
#include "strlist.h"
|
||||||
|
@ -20,7 +22,7 @@ int StringList::add(const TCHAR *str, int case_sensitive)
|
||||||
{
|
{
|
||||||
int a=find(str,case_sensitive);
|
int a=find(str,case_sensitive);
|
||||||
if (a >= 0 && case_sensitive!=-1) return a;
|
if (a >= 0 && case_sensitive!=-1) return a;
|
||||||
return gr.add(str,(_tcsclen(str)+1)*sizeof(TCHAR))/sizeof(TCHAR);
|
return m_gr.add(str,(_tcsclen(str)+1)*sizeof(TCHAR))/sizeof(TCHAR);
|
||||||
}
|
}
|
||||||
|
|
||||||
// use 2 for case sensitive end-of-string matches too
|
// use 2 for case sensitive end-of-string matches too
|
||||||
|
@ -29,14 +31,18 @@ int StringList::find(const TCHAR *str, int case_sensitive, int *idx/*=NULL*/) co
|
||||||
const TCHAR *s=get();
|
const TCHAR *s=get();
|
||||||
int ml=getlen();
|
int ml=getlen();
|
||||||
int offs=0;
|
int offs=0;
|
||||||
|
|
||||||
if (idx) *idx=0;
|
if (idx) *idx=0;
|
||||||
while (offs < ml)
|
while (offs < ml)
|
||||||
{
|
{
|
||||||
|
// Check if the whole string matches str.
|
||||||
if ((case_sensitive && !_tcscmp(s+offs,str)) ||
|
if ((case_sensitive && !_tcscmp(s+offs,str)) ||
|
||||||
(!case_sensitive && !_tcsicmp(s+offs,str)))
|
(!case_sensitive && !_tcsicmp(s+offs,str)))
|
||||||
{
|
{
|
||||||
return offs;
|
return offs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if just the end of the string matches str.
|
||||||
if (case_sensitive==2 &&
|
if (case_sensitive==2 &&
|
||||||
_tcslen(str) < _tcslen(s+offs) && // check for end of string
|
_tcslen(str) < _tcslen(s+offs) && // check for end of string
|
||||||
!_tcscmp(s+offs+_tcslen(s+offs)-_tcslen(str),str))
|
!_tcscmp(s+offs+_tcslen(s+offs)-_tcslen(str),str))
|
||||||
|
@ -44,25 +50,33 @@ int StringList::find(const TCHAR *str, int case_sensitive, int *idx/*=NULL*/) co
|
||||||
return offs+_tcslen(s+offs)-_tcslen(str);
|
return offs+_tcslen(s+offs)-_tcslen(str);
|
||||||
}
|
}
|
||||||
offs+=_tcslen(s+offs)+1;
|
offs+=_tcslen(s+offs)+1;
|
||||||
|
|
||||||
if (idx) (*idx)++;
|
if (idx) (*idx)++;
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// pos is the position in TCHARs, not bytes.
|
||||||
void StringList::delbypos(int pos)
|
void StringList::delbypos(int pos)
|
||||||
{
|
{
|
||||||
TCHAR *s=(TCHAR*)gr.get();
|
TCHAR *s=(TCHAR*) m_gr.get();
|
||||||
int len=_tcslen(s+pos)+1;
|
int len=_tcslen(s+pos)+1;
|
||||||
if (pos+len < gr.getlen()) memcpy(s+pos,s+pos+len,gr.getlen()-(pos+len));
|
|
||||||
gr.resize(gr.getlen()-len);
|
if (pos+len < m_gr.getlen())
|
||||||
|
{
|
||||||
|
// Move everything after the string position to the current position.
|
||||||
|
memcpy(s+pos,s+pos+len,m_gr.getlen()-(pos+len));
|
||||||
|
}
|
||||||
|
m_gr.resize(m_gr.getlen()-len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// idx corresponds to the nth string in the list.
|
||||||
int StringList::idx2pos(int idx) const
|
int StringList::idx2pos(int idx) const
|
||||||
{
|
{
|
||||||
TCHAR *s=(TCHAR*)gr.get();
|
TCHAR *s=(TCHAR*) m_gr.get();
|
||||||
int offs=0;
|
int offs=0;
|
||||||
int cnt=0;
|
int cnt=0;
|
||||||
if (idx>=0) while (offs < gr.getlen())
|
if (idx>=0) while (offs < m_gr.getlen())
|
||||||
{
|
{
|
||||||
if (cnt++ == idx) return offs;
|
if (cnt++ == idx) return offs;
|
||||||
offs+=_tcslen(s+offs)+1;
|
offs+=_tcslen(s+offs)+1;
|
||||||
|
@ -72,8 +86,8 @@ int StringList::idx2pos(int idx) const
|
||||||
|
|
||||||
int StringList::getnum() const
|
int StringList::getnum() const
|
||||||
{
|
{
|
||||||
TCHAR *s=(TCHAR*)gr.get();
|
TCHAR *s=(TCHAR*) m_gr.get();
|
||||||
int ml=gr.getlen();
|
int ml=m_gr.getlen();
|
||||||
int offs=0;
|
int offs=0;
|
||||||
int idx=0;
|
int idx=0;
|
||||||
while (offs < ml)
|
while (offs < ml)
|
||||||
|
@ -86,22 +100,26 @@ int StringList::getnum() const
|
||||||
|
|
||||||
const TCHAR *StringList::get() const
|
const TCHAR *StringList::get() const
|
||||||
{
|
{
|
||||||
return (const TCHAR*)gr.get();
|
return (const TCHAR*) m_gr.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
int StringList::getlen() const
|
int StringList::getlen() const
|
||||||
{
|
{
|
||||||
return gr.getlen();
|
return m_gr.getlen();
|
||||||
}
|
}
|
||||||
|
|
||||||
// ==========
|
// ==========
|
||||||
// DefineList
|
// DefineList
|
||||||
// ==========
|
// ==========
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Since the SortedStringList base class handles the memory for .name values,
|
||||||
|
* this destructor handles all the .value values in struct define.
|
||||||
|
*/
|
||||||
DefineList::~DefineList()
|
DefineList::~DefineList()
|
||||||
{
|
{
|
||||||
struct define *s=(struct define*)gr.get();
|
struct define *s=(struct define*) m_gr.get();
|
||||||
int num=gr.getlen()/sizeof(struct define);
|
int num=m_gr.getlen()/sizeof(struct define);
|
||||||
|
|
||||||
for (int i=0; i<num; i++) {
|
for (int i=0; i<num; i++) {
|
||||||
free(s[i].value);
|
free(s[i].value);
|
||||||
|
@ -116,9 +134,11 @@ int DefineList::add(const TCHAR *name, const TCHAR *value/*=_T("")*/)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
TCHAR **newvalue=&(((struct define*)gr.get())[pos].value);
|
TCHAR **newvalue=&(((struct define*) m_gr.get())[pos].value);
|
||||||
size_t size_in_bytes = (_tcslen(value) + 1) * sizeof(TCHAR);
|
size_t size_in_bytes = (_tcslen(value) + 1) * sizeof(TCHAR);
|
||||||
|
|
||||||
*newvalue=(TCHAR*)malloc(size_in_bytes);
|
*newvalue=(TCHAR*)malloc(size_in_bytes);
|
||||||
|
|
||||||
if (!(*newvalue))
|
if (!(*newvalue))
|
||||||
{
|
{
|
||||||
extern FILE *g_output;
|
extern FILE *g_output;
|
||||||
|
@ -142,7 +162,7 @@ TCHAR *DefineList::find(const TCHAR *name)
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return ((struct define*)gr.get())[v].value;
|
return ((struct define*) m_gr.get())[v].value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns 0 on success, 1 otherwise
|
// returns 0 on success, 1 otherwise
|
||||||
|
@ -151,7 +171,7 @@ int DefineList::del(const TCHAR *str)
|
||||||
int pos=SortedStringList<struct define>::find(str);
|
int pos=SortedStringList<struct define>::find(str);
|
||||||
if (pos==-1) return 1;
|
if (pos==-1) return 1;
|
||||||
|
|
||||||
struct define *db=(struct define *)gr.get();
|
struct define *db=(struct define *) m_gr.get();
|
||||||
free(db[pos].value);
|
free(db[pos].value);
|
||||||
delbypos(pos);
|
delbypos(pos);
|
||||||
|
|
||||||
|
@ -160,21 +180,21 @@ int DefineList::del(const TCHAR *str)
|
||||||
|
|
||||||
int DefineList::getnum()
|
int DefineList::getnum()
|
||||||
{
|
{
|
||||||
return gr.getlen()/sizeof(define);
|
return m_gr.getlen()/sizeof(define);
|
||||||
}
|
}
|
||||||
|
|
||||||
TCHAR *DefineList::getname(int num)
|
TCHAR *DefineList::getname(int num)
|
||||||
{
|
{
|
||||||
if ((unsigned int)getnum() <= (unsigned int)num)
|
if ((unsigned int)getnum() <= (unsigned int)num)
|
||||||
return 0;
|
return 0;
|
||||||
return ((struct define*)gr.get())[num].name;
|
return ((struct define*) m_gr.get())[num].name;
|
||||||
}
|
}
|
||||||
|
|
||||||
TCHAR *DefineList::getvalue(int num)
|
TCHAR *DefineList::getvalue(int num)
|
||||||
{
|
{
|
||||||
if ((unsigned int)getnum() <= (unsigned int)num)
|
if ((unsigned int)getnum() <= (unsigned int)num)
|
||||||
return 0;
|
return 0;
|
||||||
return ((struct define*)gr.get())[num].value;
|
return ((struct define*) m_gr.get())[num].value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ==============
|
// ==============
|
||||||
|
@ -185,21 +205,21 @@ int FastStringList::add(const TCHAR *name, int case_sensitive/*=0*/)
|
||||||
{
|
{
|
||||||
int pos = SortedStringListND<struct string_t>::add(name, case_sensitive);
|
int pos = SortedStringListND<struct string_t>::add(name, case_sensitive);
|
||||||
if (pos == -1) return -1;
|
if (pos == -1) return -1;
|
||||||
return ((struct string_t*)gr.get())[pos].name;
|
return ((struct string_t*) m_gr.get())[pos].name;
|
||||||
}
|
}
|
||||||
|
|
||||||
TCHAR *FastStringList::get() const
|
TCHAR *FastStringList::get() const
|
||||||
{
|
{
|
||||||
return (TCHAR*)strings.get();
|
return (TCHAR*)m_strings.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
int FastStringList::getlen() const
|
int FastStringList::getlen() const
|
||||||
{
|
{
|
||||||
return strings.getlen();
|
return m_strings.getlen();
|
||||||
}
|
}
|
||||||
|
|
||||||
int FastStringList::getnum() const
|
int FastStringList::getnum() const
|
||||||
{
|
{
|
||||||
return gr.getlen()/sizeof(struct string_t);
|
return m_gr.getlen()/sizeof(struct string_t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -102,7 +102,7 @@ public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the buffer straight as a const TCHAR pointer. Very unwise to use.
|
* Get the buffer straight as a const TCHAR pointer. Very unwise to use.
|
||||||
* @return gr.m_s cast as a TCHAR*.
|
* @return m_gr.m_s cast as a TCHAR*.
|
||||||
*/
|
*/
|
||||||
const TCHAR *get() const;
|
const TCHAR *get() const;
|
||||||
|
|
||||||
|
@ -113,7 +113,7 @@ public:
|
||||||
int getlen() const;
|
int getlen() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
GrowBuf gr;
|
GrowBuf m_gr;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -135,8 +135,8 @@ class SortedStringList
|
||||||
*/
|
*/
|
||||||
virtual ~SortedStringList()
|
virtual ~SortedStringList()
|
||||||
{
|
{
|
||||||
T *s=(T*)gr.get();
|
T *s=(T*) m_gr.get();
|
||||||
size_t num=gr.getlen()/sizeof(T);
|
size_t num = m_gr.getlen()/sizeof(T);
|
||||||
|
|
||||||
for (size_t i=0; i<num; i++) {
|
for (size_t i=0; i<num; i++) {
|
||||||
free(s[i].name);
|
free(s[i].name);
|
||||||
|
@ -172,10 +172,10 @@ class SortedStringList
|
||||||
quit();
|
quit();
|
||||||
}
|
}
|
||||||
_tcscpy(newstruct.name,name);
|
_tcscpy(newstruct.name,name);
|
||||||
gr.add(&newstruct,sizeof(T));
|
m_gr.add(&newstruct,sizeof(T));
|
||||||
|
|
||||||
T *s=(T*)gr.get();
|
T *s=(T*) m_gr.get();
|
||||||
memmove(s+pos+1,s+pos,gr.getlen()-((pos+1)*sizeof(T)));
|
memmove(s+pos+1,s+pos, m_gr.getlen()-((pos+1)*sizeof(T)));
|
||||||
memcpy(s+pos,&newstruct,sizeof(T));
|
memcpy(s+pos,&newstruct,sizeof(T));
|
||||||
|
|
||||||
return pos;
|
return pos;
|
||||||
|
@ -199,8 +199,8 @@ class SortedStringList
|
||||||
*/
|
*/
|
||||||
int find(const TCHAR *str, int case_sensitive=0, int returnbestpos=0)
|
int find(const TCHAR *str, int case_sensitive=0, int returnbestpos=0)
|
||||||
{
|
{
|
||||||
T *data=(T *)gr.get();
|
T *data=(T *) m_gr.get();
|
||||||
int ul=gr.getlen()/sizeof(T);
|
int ul= m_gr.getlen()/sizeof(T);
|
||||||
int ll=0;
|
int ll=0;
|
||||||
int nextpos=(ul+ll)/2;
|
int nextpos=(ul+ll)/2;
|
||||||
|
|
||||||
|
@ -244,14 +244,14 @@ class SortedStringList
|
||||||
*/
|
*/
|
||||||
void delbypos(int pos)
|
void delbypos(int pos)
|
||||||
{
|
{
|
||||||
T *db=(T *)gr.get();
|
T *db=(T *) m_gr.get();
|
||||||
free(db[pos].name);
|
free(db[pos].name);
|
||||||
memmove(db+pos,db+pos+1,gr.getlen()-(pos*sizeof(T))-sizeof(T));
|
memmove(db+pos,db+pos+1, m_gr.getlen()-(pos*sizeof(T))-sizeof(T));
|
||||||
gr.resize(gr.getlen()-sizeof(T));
|
m_gr.resize(m_gr.getlen()-sizeof(T));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
TinyGrowBuf gr;
|
TinyGrowBuf m_gr;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define mymin(x, y) ((x < y) ? x : y)
|
#define mymin(x, y) ((x < y) ? x : y)
|
||||||
|
@ -302,12 +302,12 @@ class SortedStringListND // no delete - can be placed in GrowBuf
|
||||||
if (pos==-1) return alwaysreturnpos ? where : -1;
|
if (pos==-1) return alwaysreturnpos ? where : -1;
|
||||||
|
|
||||||
// Note that .name is set with the TCHAR* offset into m_strings.
|
// Note that .name is set with the TCHAR* offset into m_strings.
|
||||||
newstruct.name=strings.add(name,(_tcsclen(name)+1)*sizeof(TCHAR))/sizeof(TCHAR);
|
newstruct.name=m_strings.add(name,(_tcsclen(name)+1)*sizeof(TCHAR))/sizeof(TCHAR);
|
||||||
|
|
||||||
gr.add(&newstruct,sizeof(T));
|
m_gr.add(&newstruct,sizeof(T));
|
||||||
T *s=(T*)gr.get();
|
T *s=(T*) m_gr.get();
|
||||||
memmove(s+pos+1,s+pos,gr.getlen()-((pos+1)*sizeof(T)));
|
memmove(s+pos+1, s+pos, m_gr.getlen()-((pos+1)*sizeof(T)));
|
||||||
memcpy(s+pos,&newstruct,sizeof(T));
|
memcpy(s+pos, &newstruct, sizeof(T));
|
||||||
|
|
||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
|
@ -354,16 +354,16 @@ class SortedStringListND // no delete - can be placed in GrowBuf
|
||||||
int* where=0 /* */
|
int* where=0 /* */
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
T *data=(T *)gr.get();
|
T *data=(T *) m_gr.get();
|
||||||
int ul=gr.getlen()/sizeof(T);
|
int ul = m_gr.getlen()/sizeof(T);
|
||||||
int ll=0;
|
int ll = 0;
|
||||||
int nextpos=(ul+ll)/2;
|
int nextpos = (ul+ll)/2;
|
||||||
|
|
||||||
// Do binary search on m_gr which is sorted. m_strings is NOT sorted.
|
// Do binary search on m_gr which is sorted. m_strings is NOT sorted.
|
||||||
while (ul > ll)
|
while (ul > ll)
|
||||||
{
|
{
|
||||||
int res;
|
int res;
|
||||||
const TCHAR *pCurr = (TCHAR*)strings.get() + data[nextpos].name;
|
const TCHAR *pCurr = (TCHAR*) m_strings.get() + data[nextpos].name;
|
||||||
if (n_chars < 0)
|
if (n_chars < 0)
|
||||||
{
|
{
|
||||||
if (case_sensitive)
|
if (case_sensitive)
|
||||||
|
@ -406,8 +406,9 @@ class SortedStringListND // no delete - can be placed in GrowBuf
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
TinyGrowBuf gr;
|
TinyGrowBuf m_gr; // Sorted array of Ts
|
||||||
GrowBuf strings;
|
GrowBuf m_strings; // Unsorted array of TCHAR strings
|
||||||
|
// (contains the .names)
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -12,6 +12,8 @@
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty.
|
* warranty.
|
||||||
|
*
|
||||||
|
* Doxygen comments by Jim Park -- 07/25/2007
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef ___USERVARS___H_____
|
#ifndef ___USERVARS___H_____
|
||||||
|
@ -29,23 +31,33 @@ struct uservarstring {
|
||||||
class UserVarsStringList : public SortedStringListND<struct uservarstring>
|
class UserVarsStringList : public SortedStringListND<struct uservarstring>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
/* Default constructor */
|
||||||
UserVarsStringList()
|
UserVarsStringList()
|
||||||
{
|
{
|
||||||
index = 0;
|
m_index = 0;
|
||||||
}
|
}
|
||||||
|
/* Destructor */
|
||||||
~UserVarsStringList() { }
|
~UserVarsStringList() { }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a name to the UserVarsStringList. Sets reference count to
|
||||||
|
* ref_count.
|
||||||
|
*
|
||||||
|
* @param name The User variable string to store.
|
||||||
|
* @param ref_count The reference count to store. Default is 0.
|
||||||
|
* @return The index of the added variable string.
|
||||||
|
*/
|
||||||
int add(const TCHAR *name, int ref_count = 0 )
|
int add(const TCHAR *name, int ref_count = 0 )
|
||||||
{
|
{
|
||||||
int pos=SortedStringListND<struct uservarstring>::add(name);
|
int pos=SortedStringListND<struct uservarstring>::add(name);
|
||||||
if (pos == -1) return -1;
|
if (pos == -1) return -1;
|
||||||
|
|
||||||
((struct uservarstring*)gr.get())[pos].index = index;
|
((struct uservarstring*)m_gr.get())[pos].index = m_index;
|
||||||
((struct uservarstring*)gr.get())[pos].pos = pos;
|
((struct uservarstring*)m_gr.get())[pos].pos = pos;
|
||||||
((struct uservarstring*)gr.get())[pos].reference = ref_count;
|
((struct uservarstring*)m_gr.get())[pos].reference = ref_count;
|
||||||
|
|
||||||
int temp = index;
|
int temp = m_index;
|
||||||
index++;
|
m_index++;
|
||||||
|
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
|
@ -61,9 +73,9 @@ class UserVarsStringList : public SortedStringListND<struct uservarstring>
|
||||||
*/
|
*/
|
||||||
int get(const TCHAR *name, int n_chars = -1)
|
int get(const TCHAR *name, int n_chars = -1)
|
||||||
{
|
{
|
||||||
int v=SortedStringListND<struct uservarstring>::find(name, n_chars);
|
int v = SortedStringListND<struct uservarstring>::find(name, n_chars);
|
||||||
if (v==-1) return -1;
|
if (v == -1) return -1;
|
||||||
return (((struct uservarstring*)gr.get())[v].index);
|
return (((struct uservarstring*) m_gr.get())[v].index);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -73,7 +85,7 @@ class UserVarsStringList : public SortedStringListND<struct uservarstring>
|
||||||
*/
|
*/
|
||||||
int getnum()
|
int getnum()
|
||||||
{
|
{
|
||||||
return index;
|
return m_index;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -86,7 +98,7 @@ class UserVarsStringList : public SortedStringListND<struct uservarstring>
|
||||||
{
|
{
|
||||||
int pos=get_internal_idx(idx);
|
int pos=get_internal_idx(idx);
|
||||||
if (pos==-1) return -1;
|
if (pos==-1) return -1;
|
||||||
return (((struct uservarstring*)gr.get())[pos].reference);
|
return (((struct uservarstring*) m_gr.get())[pos].reference);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -98,24 +110,32 @@ class UserVarsStringList : public SortedStringListND<struct uservarstring>
|
||||||
int inc_reference(int idx)
|
int inc_reference(int idx)
|
||||||
{
|
{
|
||||||
int pos=get_internal_idx(idx);
|
int pos=get_internal_idx(idx);
|
||||||
((struct uservarstring*)gr.get())[pos].reference++;
|
((struct uservarstring*)m_gr.get())[pos].reference++;
|
||||||
return (((struct uservarstring*)gr.get())[pos].reference)-1;
|
return (((struct uservarstring*)m_gr.get())[pos].reference)-1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Given the index of the structure, return the string value
|
||||||
|
* of the name.
|
||||||
|
*
|
||||||
|
* @return String value of the name as TCHAR*.
|
||||||
|
* If not found, returns NULL.
|
||||||
|
*/
|
||||||
TCHAR *idx2name(int idx)
|
TCHAR *idx2name(int idx)
|
||||||
{
|
{
|
||||||
int pos=get_internal_idx(idx);
|
int pos=get_internal_idx(idx);
|
||||||
if (pos==-1) return NULL;
|
if (pos==-1) return NULL;
|
||||||
struct uservarstring *data=(struct uservarstring *)gr.get();
|
struct uservarstring *data=(struct uservarstring *) m_gr.get();
|
||||||
return ((TCHAR*)strings.get() + data[pos].name);
|
return ((TCHAR*) m_strings.get() + data[pos].name);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int index;
|
int m_index;
|
||||||
|
|
||||||
int get_internal_idx(int idx)
|
int get_internal_idx(int idx)
|
||||||
{
|
{
|
||||||
struct uservarstring *data=(struct uservarstring *)gr.get();
|
struct uservarstring *data=(struct uservarstring *) m_gr.get();
|
||||||
for (int i = 0; i < index; i++)
|
for (int i = 0; i < m_index; i++)
|
||||||
{
|
{
|
||||||
if (data[i].index == idx)
|
if (data[i].index == idx)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue