strlist.cpp

来自「Decompilation Dos Program is a technique」· C++ 代码 · 共 81 行

CPP
81
字号
#include "StrList.h"
StringList::StringList()
{
  Data = NULL;
  Next = NULL;
  addr = -1;
}
StringList::~StringList()
{
  if (Data) delete[] Data;
  Data=NULL;
  if (Next) delete Next;
  Next=NULL;
}
StringList *StringList::GetList(int Pos)
{
   StringList *ptr = this;
   while(Pos--)
     ptr = ptr->Next;
   return ptr;
}
int StringList::GetPos(StringList *s)
{
   StringList *ptr = this;
   int pos=0;
   do
   {
     if (ptr==s) return pos;
     ptr = ptr->Next;
     pos++;
   }while(ptr);
   return -1;
}
void StringList::Replace(const char *t)
{
  if (Data) delete[] Data;
  Data = NULL;
  Add(t,addr);
}
void StringList::Add(const char *t,int _addr)
{
  if (Data)
  {
    if (!Next) Next = new StringList;
    Next->Add(t,_addr);
  }
  else
  {
    Data = new char[strlen(t)+1];
    assert(Data);
    strcpy(Data,t);
    addr=_addr;
  }
}
/*-------------------------------------------------------------
Insert - inserts the given string in the current position and
 pushes everything else down by one unit.
*** Data in 'this' stringlist is replaced by the new one.
-------------------------------------------------------------*/
void StringList::Insert(const char *t)
{
  if (Data)
  {
    StringList *tmp = Next;
    Next = new StringList;
    Next->Add(Data,addr);
    Next->Next = tmp;
    delete[] Data;
    Data=NULL;
  }
  Add(t);
}
void StringList::Delete(StringList *s)
{
  assert(s!=this);
  StringList *ptr = this;
  while(ptr->Next!=s) ptr = ptr->Next;
  ptr->Next = s->Next;
  s->Next = NULL;
  delete s;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?