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()
|
||||
{
|
||||
struct version_string_list *itr = (struct version_string_list *) gr.get();
|
||||
int i = gr.getlen() / sizeof(struct version_string_list);
|
||||
struct version_string_list *itr = (struct version_string_list *) m_gr.get();
|
||||
int i = m_gr.getlen() / sizeof(struct version_string_list);
|
||||
|
||||
while (i--)
|
||||
{
|
||||
|
@ -60,27 +60,27 @@ int CVersionStrigList::add(LANGID langid, int codepage)
|
|||
_stprintf(Buff, _T("%04x"), langid);
|
||||
int pos = SortedStringListND<struct version_string_list>::add(Buff);
|
||||
if (pos == -1) return false;
|
||||
((struct version_string_list*)gr.get())[pos].pChildStrings = new DefineList;
|
||||
((struct version_string_list*)gr.get())[pos].codepage = codepage;
|
||||
((struct version_string_list*)gr.get())[pos].lang_id = langid;
|
||||
((struct version_string_list*)m_gr.get())[pos].pChildStrings = new DefineList;
|
||||
((struct version_string_list*)m_gr.get())[pos].codepage = codepage;
|
||||
((struct version_string_list*)m_gr.get())[pos].lang_id = langid;
|
||||
return pos;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -93,12 +93,12 @@ int CVersionStrigList::find(LANGID lang_id, int codepage)
|
|||
|
||||
int CVersionStrigList::getlen()
|
||||
{
|
||||
return strings.getlen();
|
||||
return m_strings.getlen();
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
index = 0;
|
||||
m_index = 0;
|
||||
}
|
||||
|
||||
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);
|
||||
if (pos == -1) return -1;
|
||||
|
||||
((struct constantstring*)gr.get())[pos].index = index;
|
||||
((struct constantstring*)gr.get())[pos].pos = pos;
|
||||
((struct constantstring*)gr.get())[pos].value1 = value1;
|
||||
((struct constantstring*)gr.get())[pos].value2 = value2;
|
||||
((struct constantstring*)m_gr.get())[pos].index = m_index;
|
||||
((struct constantstring*)m_gr.get())[pos].pos = pos;
|
||||
((struct constantstring*)m_gr.get())[pos].value1 = value1;
|
||||
((struct constantstring*)m_gr.get())[pos].value2 = value2;
|
||||
|
||||
int temp = index;
|
||||
index++;
|
||||
int temp = m_index;
|
||||
m_index++;
|
||||
|
||||
return temp;
|
||||
}
|
||||
|
@ -43,42 +43,42 @@ int ConstantsStringList::get(TCHAR *name, int n_chars /*= -1*/)
|
|||
{
|
||||
int v=SortedStringListND<struct constantstring>::find(name, n_chars);
|
||||
if (v==-1) return -1;
|
||||
return (((struct constantstring*)gr.get())[v].index);
|
||||
return (((struct constantstring*) m_gr.get())[v].index);
|
||||
}
|
||||
|
||||
int ConstantsStringList::getnum()
|
||||
{
|
||||
return index;
|
||||
return m_index;
|
||||
}
|
||||
|
||||
int ConstantsStringList::get_value1(int idx)
|
||||
{
|
||||
int pos=get_internal_idx(idx);
|
||||
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 pos=get_internal_idx(idx);
|
||||
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)
|
||||
{
|
||||
int pos=get_internal_idx(idx);
|
||||
if (pos==-1) return NULL;
|
||||
struct constantstring *data=(struct constantstring *)gr.get();
|
||||
return ((TCHAR*)strings.get() + data[pos].name);
|
||||
struct constantstring *data=(struct constantstring *) m_gr.get();
|
||||
return ((TCHAR*) m_strings.get() + data[pos].name);
|
||||
}
|
||||
|
||||
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.
|
||||
for (int i = 0; i < index; i++)
|
||||
for (int i = 0; i < m_index; i++)
|
||||
{
|
||||
if (data[i].index == idx)
|
||||
{
|
||||
|
|
|
@ -42,7 +42,7 @@ class ConstantsStringList : public SortedStringListND<struct constantstring>
|
|||
TCHAR *idx2name(int idx);
|
||||
|
||||
private:
|
||||
int index;
|
||||
int m_index;
|
||||
int get_internal_idx(int idx);
|
||||
};
|
||||
|
||||
|
|
|
@ -149,7 +149,7 @@ NLFString NLFStrings[NLF_STRINGS] = {
|
|||
// ==============
|
||||
|
||||
LangStringList::LangStringList() {
|
||||
count = 0;
|
||||
m_count = 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);
|
||||
if (pos == -1) return -1;
|
||||
|
||||
((struct langstring*)gr.get())[pos].sn = count;
|
||||
if (sn) *sn = count;
|
||||
count++;
|
||||
((struct langstring*)gr.get())[pos].index = -1;
|
||||
((struct langstring*)gr.get())[pos].uindex = -1;
|
||||
((struct langstring*)gr.get())[pos].process = 1;
|
||||
((struct langstring*)m_gr.get())[pos].sn = m_count;
|
||||
if (sn) *sn = m_count;
|
||||
m_count++;
|
||||
((struct langstring*)m_gr.get())[pos].index = -1;
|
||||
((struct langstring*)m_gr.get())[pos].uindex = -1;
|
||||
((struct langstring*)m_gr.get())[pos].process = 1;
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
@ -174,19 +174,19 @@ int LangStringList::get(const TCHAR *name, int *sn/*=0*/, int *index/*=0*/, int
|
|||
if (sn) *sn = -1;
|
||||
int v=find(name);
|
||||
if (v==-1) return -1;
|
||||
if (index) *index = ((struct langstring*)gr.get())[v].index;
|
||||
if (uindex) *uindex = ((struct langstring*)gr.get())[v].uindex;
|
||||
if (sn) *sn = ((struct langstring*)gr.get())[v].sn;
|
||||
if (process) *process = ((struct langstring*)gr.get())[v].process;
|
||||
if (index) *index = ((struct langstring*)m_gr.get())[v].index;
|
||||
if (uindex) *uindex = ((struct langstring*)m_gr.get())[v].uindex;
|
||||
if (sn) *sn = ((struct langstring*)m_gr.get())[v].sn;
|
||||
if (process) *process = ((struct langstring*)m_gr.get())[v].process;
|
||||
return v;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
struct langstring *data=(struct langstring *)gr.get();
|
||||
struct langstring *data=(struct langstring *)m_gr.get();
|
||||
|
||||
if (index >= 0)
|
||||
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)
|
||||
{
|
||||
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 ((const TCHAR*)strings.get() + data[pos].name);
|
||||
return ((const TCHAR*) m_strings.get() + data[pos].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 (const TCHAR*)strings.get() + name;
|
||||
return (const TCHAR*) m_strings.get() + name;
|
||||
}
|
||||
|
||||
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)
|
||||
|
@ -235,11 +235,11 @@ int LangStringList::compare_index(const void *item1, const void *item2)
|
|||
langstring* LangStringList::sort_index(int *num)
|
||||
{
|
||||
if (!num) return 0;
|
||||
sortbuf.resize(0);
|
||||
sortbuf.add(gr.get(), gr.getlen());
|
||||
*num = sortbuf.getlen() / sizeof(struct langstring);
|
||||
qsort(sortbuf.get(), *num, sizeof(struct langstring), compare_index);
|
||||
return (struct langstring*) sortbuf.get();
|
||||
m_sortbuf.resize(0);
|
||||
m_sortbuf.add(m_gr.get(), m_gr.getlen());
|
||||
*num = m_sortbuf.getlen() / sizeof(struct langstring);
|
||||
qsort(m_sortbuf.get(), *num, sizeof(struct langstring), compare_index);
|
||||
return (struct langstring*) m_sortbuf.get();
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
if (!num) return 0;
|
||||
sortbuf.resize(0);
|
||||
sortbuf.add(gr.get(), gr.getlen());
|
||||
*num = sortbuf.getlen() / sizeof(struct langstring);
|
||||
qsort(sortbuf.get(), *num, sizeof(struct langstring), compare_uindex);
|
||||
return (struct langstring*) sortbuf.get();
|
||||
m_sortbuf.resize(0);
|
||||
m_sortbuf.add(m_gr.get(), m_gr.getlen());
|
||||
*num = m_sortbuf.getlen() / sizeof(struct langstring);
|
||||
qsort(m_sortbuf.get(), *num, sizeof(struct langstring), compare_uindex);
|
||||
return (struct langstring*) m_sortbuf.get();
|
||||
}
|
||||
|
||||
// ============
|
||||
|
@ -266,14 +266,15 @@ langstring* LangStringList::sort_uindex(int *num)
|
|||
|
||||
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)
|
||||
{
|
||||
offsets.resize(num * sizeof(int));
|
||||
m_offsets.resize(num * sizeof(int));
|
||||
}
|
||||
|
||||
int StringsArray::set(int idx, const TCHAR *str)
|
||||
|
@ -281,22 +282,23 @@ int StringsArray::set(int idx, const TCHAR *str)
|
|||
if (idx < 0)
|
||||
return 0;
|
||||
|
||||
if (idx >= (int)(offsets.getlen() / sizeof(int)))
|
||||
if (idx >= (int)(m_offsets.getlen() / sizeof(int)))
|
||||
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;
|
||||
}
|
||||
|
||||
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 (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);
|
||||
|
||||
private:
|
||||
int count;
|
||||
TinyGrowBuf sortbuf;
|
||||
int m_count; // Used to set string number (sn)
|
||||
TinyGrowBuf m_sortbuf; // Used only to sort.
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -195,8 +195,8 @@ class StringsArray
|
|||
const TCHAR *get(int idx);
|
||||
|
||||
private:
|
||||
TinyGrowBuf offsets;
|
||||
GrowBuf strings;
|
||||
TinyGrowBuf m_offsets; /* Positional offsets of the stored string. */
|
||||
GrowBuf m_strings; /* Storage of the actual strings. */
|
||||
};
|
||||
|
||||
#define NLF_VERSION 6
|
||||
|
|
|
@ -12,6 +12,8 @@
|
|||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty.
|
||||
*
|
||||
* Doxygen comments by Jim Park -- 08/01/2007
|
||||
*/
|
||||
|
||||
#include "strlist.h"
|
||||
|
@ -20,7 +22,7 @@ int StringList::add(const TCHAR *str, int case_sensitive)
|
|||
{
|
||||
int a=find(str,case_sensitive);
|
||||
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
|
||||
|
@ -29,14 +31,18 @@ int StringList::find(const TCHAR *str, int case_sensitive, int *idx/*=NULL*/) co
|
|||
const TCHAR *s=get();
|
||||
int ml=getlen();
|
||||
int offs=0;
|
||||
|
||||
if (idx) *idx=0;
|
||||
while (offs < ml)
|
||||
{
|
||||
// Check if the whole string matches str.
|
||||
if ((case_sensitive && !_tcscmp(s+offs,str)) ||
|
||||
(!case_sensitive && !_tcsicmp(s+offs,str)))
|
||||
{
|
||||
return offs;
|
||||
}
|
||||
|
||||
// Check if just the end of the string matches str.
|
||||
if (case_sensitive==2 &&
|
||||
_tcslen(str) < _tcslen(s+offs) && // check for end of string
|
||||
!_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);
|
||||
}
|
||||
offs+=_tcslen(s+offs)+1;
|
||||
|
||||
if (idx) (*idx)++;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
// pos is the position in TCHARs, not bytes.
|
||||
void StringList::delbypos(int pos)
|
||||
{
|
||||
TCHAR *s=(TCHAR*)gr.get();
|
||||
TCHAR *s=(TCHAR*) m_gr.get();
|
||||
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
|
||||
{
|
||||
TCHAR *s=(TCHAR*)gr.get();
|
||||
TCHAR *s=(TCHAR*) m_gr.get();
|
||||
int offs=0;
|
||||
int cnt=0;
|
||||
if (idx>=0) while (offs < gr.getlen())
|
||||
if (idx>=0) while (offs < m_gr.getlen())
|
||||
{
|
||||
if (cnt++ == idx) return offs;
|
||||
offs+=_tcslen(s+offs)+1;
|
||||
|
@ -72,8 +86,8 @@ int StringList::idx2pos(int idx) const
|
|||
|
||||
int StringList::getnum() const
|
||||
{
|
||||
TCHAR *s=(TCHAR*)gr.get();
|
||||
int ml=gr.getlen();
|
||||
TCHAR *s=(TCHAR*) m_gr.get();
|
||||
int ml=m_gr.getlen();
|
||||
int offs=0;
|
||||
int idx=0;
|
||||
while (offs < ml)
|
||||
|
@ -86,22 +100,26 @@ int StringList::getnum() const
|
|||
|
||||
const TCHAR *StringList::get() const
|
||||
{
|
||||
return (const TCHAR*)gr.get();
|
||||
return (const TCHAR*) m_gr.get();
|
||||
}
|
||||
|
||||
int StringList::getlen() const
|
||||
{
|
||||
return gr.getlen();
|
||||
return m_gr.getlen();
|
||||
}
|
||||
|
||||
// ==========
|
||||
// DefineList
|
||||
// ==========
|
||||
|
||||
/**
|
||||
* Since the SortedStringList base class handles the memory for .name values,
|
||||
* this destructor handles all the .value values in struct define.
|
||||
*/
|
||||
DefineList::~DefineList()
|
||||
{
|
||||
struct define *s=(struct define*)gr.get();
|
||||
int num=gr.getlen()/sizeof(struct define);
|
||||
struct define *s=(struct define*) m_gr.get();
|
||||
int num=m_gr.getlen()/sizeof(struct define);
|
||||
|
||||
for (int i=0; i<num; i++) {
|
||||
free(s[i].value);
|
||||
|
@ -116,9 +134,11 @@ int DefineList::add(const TCHAR *name, const TCHAR *value/*=_T("")*/)
|
|||
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);
|
||||
|
||||
*newvalue=(TCHAR*)malloc(size_in_bytes);
|
||||
|
||||
if (!(*newvalue))
|
||||
{
|
||||
extern FILE *g_output;
|
||||
|
@ -142,7 +162,7 @@ TCHAR *DefineList::find(const TCHAR *name)
|
|||
{
|
||||
return NULL;
|
||||
}
|
||||
return ((struct define*)gr.get())[v].value;
|
||||
return ((struct define*) m_gr.get())[v].value;
|
||||
}
|
||||
|
||||
// returns 0 on success, 1 otherwise
|
||||
|
@ -151,7 +171,7 @@ int DefineList::del(const TCHAR *str)
|
|||
int pos=SortedStringList<struct define>::find(str);
|
||||
if (pos==-1) return 1;
|
||||
|
||||
struct define *db=(struct define *)gr.get();
|
||||
struct define *db=(struct define *) m_gr.get();
|
||||
free(db[pos].value);
|
||||
delbypos(pos);
|
||||
|
||||
|
@ -160,21 +180,21 @@ int DefineList::del(const TCHAR *str)
|
|||
|
||||
int DefineList::getnum()
|
||||
{
|
||||
return gr.getlen()/sizeof(define);
|
||||
return m_gr.getlen()/sizeof(define);
|
||||
}
|
||||
|
||||
TCHAR *DefineList::getname(int num)
|
||||
{
|
||||
if ((unsigned int)getnum() <= (unsigned int)num)
|
||||
return 0;
|
||||
return ((struct define*)gr.get())[num].name;
|
||||
return ((struct define*) m_gr.get())[num].name;
|
||||
}
|
||||
|
||||
TCHAR *DefineList::getvalue(int num)
|
||||
{
|
||||
if ((unsigned int)getnum() <= (unsigned int)num)
|
||||
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);
|
||||
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
|
||||
{
|
||||
return (TCHAR*)strings.get();
|
||||
return (TCHAR*)m_strings.get();
|
||||
}
|
||||
|
||||
int FastStringList::getlen() const
|
||||
{
|
||||
return strings.getlen();
|
||||
return m_strings.getlen();
|
||||
}
|
||||
|
||||
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.
|
||||
* @return gr.m_s cast as a TCHAR*.
|
||||
* @return m_gr.m_s cast as a TCHAR*.
|
||||
*/
|
||||
const TCHAR *get() const;
|
||||
|
||||
|
@ -113,7 +113,7 @@ public:
|
|||
int getlen() const;
|
||||
|
||||
private:
|
||||
GrowBuf gr;
|
||||
GrowBuf m_gr;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -135,8 +135,8 @@ class SortedStringList
|
|||
*/
|
||||
virtual ~SortedStringList()
|
||||
{
|
||||
T *s=(T*)gr.get();
|
||||
size_t num=gr.getlen()/sizeof(T);
|
||||
T *s=(T*) m_gr.get();
|
||||
size_t num = m_gr.getlen()/sizeof(T);
|
||||
|
||||
for (size_t i=0; i<num; i++) {
|
||||
free(s[i].name);
|
||||
|
@ -172,10 +172,10 @@ class SortedStringList
|
|||
quit();
|
||||
}
|
||||
_tcscpy(newstruct.name,name);
|
||||
gr.add(&newstruct,sizeof(T));
|
||||
m_gr.add(&newstruct,sizeof(T));
|
||||
|
||||
T *s=(T*)gr.get();
|
||||
memmove(s+pos+1,s+pos,gr.getlen()-((pos+1)*sizeof(T)));
|
||||
T *s=(T*) m_gr.get();
|
||||
memmove(s+pos+1,s+pos, m_gr.getlen()-((pos+1)*sizeof(T)));
|
||||
memcpy(s+pos,&newstruct,sizeof(T));
|
||||
|
||||
return pos;
|
||||
|
@ -199,8 +199,8 @@ class SortedStringList
|
|||
*/
|
||||
int find(const TCHAR *str, int case_sensitive=0, int returnbestpos=0)
|
||||
{
|
||||
T *data=(T *)gr.get();
|
||||
int ul=gr.getlen()/sizeof(T);
|
||||
T *data=(T *) m_gr.get();
|
||||
int ul= m_gr.getlen()/sizeof(T);
|
||||
int ll=0;
|
||||
int nextpos=(ul+ll)/2;
|
||||
|
||||
|
@ -244,14 +244,14 @@ class SortedStringList
|
|||
*/
|
||||
void delbypos(int pos)
|
||||
{
|
||||
T *db=(T *)gr.get();
|
||||
T *db=(T *) m_gr.get();
|
||||
free(db[pos].name);
|
||||
memmove(db+pos,db+pos+1,gr.getlen()-(pos*sizeof(T))-sizeof(T));
|
||||
gr.resize(gr.getlen()-sizeof(T));
|
||||
memmove(db+pos,db+pos+1, m_gr.getlen()-(pos*sizeof(T))-sizeof(T));
|
||||
m_gr.resize(m_gr.getlen()-sizeof(T));
|
||||
}
|
||||
|
||||
protected:
|
||||
TinyGrowBuf gr;
|
||||
TinyGrowBuf m_gr;
|
||||
};
|
||||
|
||||
#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;
|
||||
|
||||
// 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));
|
||||
T *s=(T*)gr.get();
|
||||
memmove(s+pos+1,s+pos,gr.getlen()-((pos+1)*sizeof(T)));
|
||||
memcpy(s+pos,&newstruct,sizeof(T));
|
||||
m_gr.add(&newstruct,sizeof(T));
|
||||
T *s=(T*) m_gr.get();
|
||||
memmove(s+pos+1, s+pos, m_gr.getlen()-((pos+1)*sizeof(T)));
|
||||
memcpy(s+pos, &newstruct, sizeof(T));
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
@ -354,16 +354,16 @@ class SortedStringListND // no delete - can be placed in GrowBuf
|
|||
int* where=0 /* */
|
||||
)
|
||||
{
|
||||
T *data=(T *)gr.get();
|
||||
int ul=gr.getlen()/sizeof(T);
|
||||
int ll=0;
|
||||
int nextpos=(ul+ll)/2;
|
||||
T *data=(T *) m_gr.get();
|
||||
int ul = m_gr.getlen()/sizeof(T);
|
||||
int ll = 0;
|
||||
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)
|
||||
{
|
||||
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 (case_sensitive)
|
||||
|
@ -406,8 +406,9 @@ class SortedStringListND // no delete - can be placed in GrowBuf
|
|||
}
|
||||
|
||||
protected:
|
||||
TinyGrowBuf gr;
|
||||
GrowBuf strings;
|
||||
TinyGrowBuf m_gr; // Sorted array of Ts
|
||||
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
|
||||
* warranty.
|
||||
*
|
||||
* Doxygen comments by Jim Park -- 07/25/2007
|
||||
*/
|
||||
|
||||
#ifndef ___USERVARS___H_____
|
||||
|
@ -29,23 +31,33 @@ struct uservarstring {
|
|||
class UserVarsStringList : public SortedStringListND<struct uservarstring>
|
||||
{
|
||||
public:
|
||||
/* Default constructor */
|
||||
UserVarsStringList()
|
||||
{
|
||||
index = 0;
|
||||
m_index = 0;
|
||||
}
|
||||
/* Destructor */
|
||||
~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 pos=SortedStringListND<struct uservarstring>::add(name);
|
||||
if (pos == -1) return -1;
|
||||
|
||||
((struct uservarstring*)gr.get())[pos].index = index;
|
||||
((struct uservarstring*)gr.get())[pos].pos = pos;
|
||||
((struct uservarstring*)gr.get())[pos].reference = ref_count;
|
||||
((struct uservarstring*)m_gr.get())[pos].index = m_index;
|
||||
((struct uservarstring*)m_gr.get())[pos].pos = pos;
|
||||
((struct uservarstring*)m_gr.get())[pos].reference = ref_count;
|
||||
|
||||
int temp = index;
|
||||
index++;
|
||||
int temp = m_index;
|
||||
m_index++;
|
||||
|
||||
return temp;
|
||||
}
|
||||
|
@ -61,9 +73,9 @@ class UserVarsStringList : public SortedStringListND<struct uservarstring>
|
|||
*/
|
||||
int get(const TCHAR *name, int n_chars = -1)
|
||||
{
|
||||
int v=SortedStringListND<struct uservarstring>::find(name, n_chars);
|
||||
if (v==-1) return -1;
|
||||
return (((struct uservarstring*)gr.get())[v].index);
|
||||
int v = SortedStringListND<struct uservarstring>::find(name, n_chars);
|
||||
if (v == -1) return -1;
|
||||
return (((struct uservarstring*) m_gr.get())[v].index);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -73,7 +85,7 @@ class UserVarsStringList : public SortedStringListND<struct uservarstring>
|
|||
*/
|
||||
int getnum()
|
||||
{
|
||||
return index;
|
||||
return m_index;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -86,7 +98,7 @@ class UserVarsStringList : public SortedStringListND<struct uservarstring>
|
|||
{
|
||||
int pos=get_internal_idx(idx);
|
||||
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 pos=get_internal_idx(idx);
|
||||
((struct uservarstring*)gr.get())[pos].reference++;
|
||||
return (((struct uservarstring*)gr.get())[pos].reference)-1;
|
||||
((struct uservarstring*)m_gr.get())[pos].reference++;
|
||||
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)
|
||||
{
|
||||
int pos=get_internal_idx(idx);
|
||||
if (pos==-1) return NULL;
|
||||
struct uservarstring *data=(struct uservarstring *)gr.get();
|
||||
return ((TCHAR*)strings.get() + data[pos].name);
|
||||
struct uservarstring *data=(struct uservarstring *) m_gr.get();
|
||||
return ((TCHAR*) m_strings.get() + data[pos].name);
|
||||
}
|
||||
|
||||
private:
|
||||
int index;
|
||||
int m_index;
|
||||
|
||||
int get_internal_idx(int idx)
|
||||
{
|
||||
struct uservarstring *data=(struct uservarstring *)gr.get();
|
||||
for (int i = 0; i < index; i++)
|
||||
struct uservarstring *data=(struct uservarstring *) m_gr.get();
|
||||
for (int i = 0; i < m_index; i++)
|
||||
{
|
||||
if (data[i].index == idx)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue