Пример #1
0
StrArr *toGet(ifstream &file)
{
    StrArr *temp = new StrArr;
    char** enterArr = new char* [beginSize];
    for(int i = 0; i < beginSize ; ++i)
    {
        enterArr[i] = new char [length];
    }
    if (!file.is_open()) cout << "Файл не может быть открыт!\n";
    else
    {
        int cntr = 0;
        while(!file.eof())
        {
            file.getline(enterArr[cntr], length);
            temp->addStr(enterArr[cntr++]);
        }
    }
    file.close();
    for(int i = 0; i < beginSize ; ++i)
    {
        delete[] enterArr[i];
    }
    delete[] enterArr;
    return temp ;
}
Пример #2
0
void StrArr::concat(const StrArr &obj)
{
    int totalSize = 0;
    int toCmp = obj.getSize();
    char **tempArr = new char *[size];
    for(int i = 0; i < size; ++i)
    {
        if(i >= toCmp)
        {
            while (i < size)
            {
                tempArr[i] = new char[strlen(arr[i])];
                strcpy(tempArr[i], arr[i]);
                ++i;
            }
        }
        else
        {
            totalSize = strlen(arr[i]) + strlen(obj.getStr(i));
            tempArr[i] = new char[totalSize];
            int toAdd = strlen(arr[i]);
            strcpy(&tempArr[i][0], arr[i]);
            strcpy(&tempArr[i][toAdd], obj.getStr(i));
        }
    }
    for(int i = 0; i < size; ++i)
    {
        delete[] arr[i];
    }
    delete[] arr;
    arr = tempArr;
}
Пример #3
0
  // returns array of path strings
  const StrArr& GDLPath()
  {
    static StrArr sArr;
  
    // clear whatever old value is stored
    sArr.clear();
  
    // get the path
    DVar& pathSysVar=*sysVarList[pathIx];
    DString& path=static_cast<DStringGDL&>(*pathSysVar.Data())[0];
    
    if( path == "") return sArr;
  
    SizeT d;
    long   sPos=0;
   #ifdef _WIN32
      char pathsep[]=";";
    #else
      char pathsep[]=":";
    #endif

    do
      {
	d=path.find(pathsep[0],sPos);
	sArr.push_back(path.substr(sPos,d-sPos));
	sPos=d+1;
      }
    while( d != path.npos);

    return sArr;
  }
// returns the struct descriptor with name 'name'
// read/compiles 'name'__define.pro if necessary
// cN is the calling node, passed for (runtime) debug information
DStructDesc* GDLInterpreter::GetStruct(const string& name, ProgNodeP cN)
{                   
  // find struct 'id'
  DStructDesc* dStruct=FindInStructList( structList, name);

  // member function/pro declaration inserts an empty DStructDesc
  if( dStruct != NULL && dStruct->NTags() > 0) return dStruct;

  static StrArr getStructList;
  
  // read/compile of IDENTIFIER__define.pro
  string proName=name+"__DEFINE";

  for( StrArr::iterator i=getStructList.begin(); i != getStructList.end(); ++i)
    {
      if( proName == *i) 
		throw GDLException(cN, "Structure type not defined (recursive call): "+name,true,false);
    }

  StackSizeGuard<StrArr> guardStructList( getStructList);

  // append file to list
  getStructList.push_back(proName);

//   if( Called( proName))
//     {
//       throw GDLException(cN, "Structure type not defined (recursive call): "+name);
//     }
  
  /*bool found=*/ SearchCompilePro(proName, true);

  // if an exception occurs in SearchCompilePro, the struct is not compiled
            
  int proIx=ProIx(proName);
  if( proIx == -1)
    {
	throw GDLException(cN, "Procedure not found: "+proName, true, false);
    }
  
  // 'guard' call stack
  StackGuard<EnvStackT> guard(callStack);

  // interpret it
  EnvUDT* newEnv=new EnvUDT( cN, proList[proIx]);

  // push id.pro onto call stack
  callStack.push_back(newEnv);
  
  // make the call
  call_pro(static_cast<DSubUD*>(callStack.back()->GetPro())->GetTree());
  
  dStruct=FindInStructList( structList, name);
  if( dStruct == NULL)
    {
      throw GDLException(cN, "Structure type not defined: "+name,true,false);
    }
     
  return dStruct;
}
Пример #5
0
void StrArr::mergeArr(const StrArr &obj)
{
    int totalSize = size + (obj.getSize());
    char **tempArr = new char *[totalSize];
    int toAlloc = 0;
    int cntr = 0;
    int i=0;
    for(int k = 0; k < size; ++k)
    {
        int subcntr = 0;
        for(int j = 0; j < cntr; ++j)
        {
            if(strcmp(tempArr[j],arr[i])) ++subcntr;
        }
        if(cntr == subcntr)
        {
            toAlloc = strlen(arr[i]);
            tempArr[i] = new char[toAlloc];
            strcpy(tempArr[i], arr[i]);
            ++cntr;
            ++i;
        }
        else --totalSize;
    }
    for(int c = 0; c < obj.getSize(); ++c)
    {
        int subcntr = 0;
        for(int j = 0; j < cntr; ++j)
        {
            if(strcmp(tempArr[j],obj.getStr(c))) ++subcntr;
        }
        if(cntr == subcntr)
        {
            toAlloc = strlen(obj.getStr(c));
            tempArr[i] = new char[toAlloc];
            strcpy(tempArr[i], obj.getStr(c));
            ++cntr;
            ++i;
        }
        else --totalSize;
    }
    for(int i = 0; i < size; ++i)
    {
        delete[] arr[i];
    }
    delete[] arr;
    arr = tempArr;
    size = totalSize;
}
Пример #6
0
StrArr::StrArr(const StrArr &obj)
{
    cout << "test";
    size = 0;
    buffSize = startSize;
    arr = new char* [buffSize];
    int toAlloc = 0;
    for(int i = 0; i < buffSize; ++i)
    {
        toAlloc = strlen(obj.getStr(i));
        arr[i] = new char [toAlloc];
    }
    while(obj.getSize() != size)
    {
        this->addStr(obj.getStr(size));
    }
}
// searches and compiles procedure (searchForPro == true) or function (searchForPro == false)  'pro'
bool GDLInterpreter::SearchCompilePro(const string& pro, bool searchForPro) 
{
  static StrArr openFiles;

  string proFile=StrLowCase(pro)+".pro";
  //AppendIfNeeded( proFile, ".pro");

  bool found=CompleteFileName(proFile);
  if( !found) return false;
  
  // file already opened?
  for( StrArr::iterator i=openFiles.begin(); i != openFiles.end(); i++)
    {
      if( proFile == *i) return false;
    }

  StackSizeGuard<StrArr> guard( openFiles);

  // append file to list
  openFiles.push_back(proFile);

  return CompileFile( proFile, pro, searchForPro); // this might trigger recursion
}