Example #1
0
TOOLSPACE_BEGIN

// 存在函数声明和定义两部分时,默认参数只可以在函数声明中设定一次
DString FileTools::extractDirectory(const DString & in_strPath, char in_cDelimiter)
{
    return in_strPath.substr(0, in_strPath.find_last_of(in_cDelimiter) + 1);
}
Example #2
0
void ObjFileEditDialog::OnChangeMaterial(wxCommandEvent &e)
{
	if(NULL == m_pEntityListMaterialComboBox
	|| NULL == m_pMaterialListMaterialComboBox)
	return;

	DString entmatname			  = m_pEntityListMaterialComboBox->GetStringSelection().c_str();

	DString matmatname			  = m_pMaterialListMaterialComboBox->GetStringSelection().c_str();

	if(entmatname.empty() && matmatname.empty())
		return;

	DString matname;
	if(entmatname.empty())
	{
		matname = matmatname;
	}
	else
	{
		matname = entmatname;
	}

	Fairy::CGod* pModel = GetDataManipulatr()->FindModel(GetDataManipulatr()->m_CurModelName);

	if(NULL == pModel)
		return;

	std::vector<Ogre::String> matvec = Ogre::StringUtil::split(matname,".");


	pModel->ChangeMat(matvec[0],matvec[0]);
}
  BaseGDL* sem_create(EnvT *e)
  {
    SizeT nParam = e->NParam(1); // 1 is the minimal number of parameter required

    DString name;
    e->AssureStringScalarPar(0, name); // IDL accepts null-string name

    int destroyIx = e->KeywordIx("DESTROY_SEMAPHORE");
    bool destroyKWPresent = e->KeywordPresent(destroyIx);
    DLong destroy = 0;
    if (destroyKWPresent) 
    {
      destroy = (*e->GetKWAs<DLongGDL>(0))[0];
    }

    bool owner = true;
#if defined(_WIN32) && !defined(__CYGWIN__)
    // TODO: Needs error handling with name length > 256
    const char* cname = name.c_str();
    WCHAR tname[256] = {0,};

    MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, cname, strlen(cname), tname, 256);
    HANDLE sem = CreateSemaphoreW(NULL,1,1,tname);
    if (sem == NULL) {
	owner = false;
	return new DIntGDL(0);
    }
#else
    sem_t *sem = sem_open(name.c_str(), O_CREAT | O_EXCL, 0666, 1);
    if (sem == SEM_FAILED)
    {  // semaphore exists. make another one, locked (value=0)
      owner = false;
      if (errno == EEXIST)
      {
        sem = sem_open(name.c_str(), O_CREAT ,0666, 0);
      }
      if (sem == SEM_FAILED)
      {
        return new DIntGDL(0);
      }
    }
#endif

    // Behavior for different values of DESTROY_SEMAPHORE:
    // DESTROY_SEMAPHORE | owner    | other (== !owner)
    // ------------------+----------+-----------
    // not set           | delete   | ignore
    // != 0              | delete   | delete
    // 0                 | ignore   | ignore
    sem_data_t data;
    data.sem = sem;

    sem_set_owner(data, owner);
    sem_set_deletable(data, (!destroyKWPresent && owner) || (destroy != 0));
    sem_set_locked(data, false);

    sem_add(name, data);

    return new DIntGDL(1);
  }
Example #4
0
File: grib.cpp Project: cenit/GDL
  BaseGDL* grib_get_size_fun(EnvT* e)
  {
#ifndef USE_GRIB
    e->Throw("GDL was compiled without support for GRIB");
    return NULL;
#else
    {
      SizeT nParam = e->NParam(2);
    }

    DLong gribid;
    e->AssureScalarPar<DLongGDL>(0, gribid);

    if (GribHandleList.find(gribid) == GribHandleList.end()) e->Throw("unrecognized message id: " + i2s(gribid));

    DString key;
    e->AssureScalarPar<DStringGDL>(1, key);

    size_t size;
    int err = GRIB_SUCCESS;
    if (GRIB_SUCCESS != (err = grib_get_size(GribHandleList[gribid], key.c_str(), &size)))
      e->Throw("failed to get size of: " + key + "\n%   GRIB API message: " + grib_get_error_message(err)); 

    return new DLongGDL(size);
#endif
  }
Example #5
0
void ObjFileEditDialog::OnChangeLocator(wxCommandEvent &e)
{
	if(NULL == m_pLocatorNameComboBox
	|| NULL == GetDataManipulatr())

	 return;

	Fairy::CGod* pModel = GetDataManipulatr()->FindModel(GetDataManipulatr()->m_CurModelName);

	if(NULL == pModel)
		return;

	DString locatorname			  = m_pLocatorNameComboBox->GetStringSelection().c_str();

	if(locatorname.empty())
		locatorname			      = m_pLocatorNameComboBox->GetValue().c_str();

	if(locatorname.empty())
		return;

	std::vector<Ogre::String> locatorvec = Ogre::StringUtil::split(locatorname,"\\");

	if(locatorvec.size() < 2)
		return;

	const DString bone			  = locatorvec[0];

	const DString locator		  = locatorvec[1];

	pModel->UpdateLocatorPosAndOriData(locator);
}
Example #6
0
	sockaddr_in DSocket::parseAddress( const DString& addr, uint16 port )
	{
		sockaddr_in ret;
		std::memset(&ret, 0, sizeof(ret));

		if (addr.empty())
		{
			ret.sin_addr.s_addr = htonl(INADDR_ANY);
		}
		else
		{
			ret.sin_addr.s_addr = inet_addr(addr.c_str());
		}

		if (INADDR_NONE == ret.sin_addr.s_addr)
		{
			hostent* pHostEnt = gethostbyname(addr.c_str());
			if (pHostEnt != NULL)
			{
				std::memcpy(&ret.sin_addr.s_addr,
					pHostEnt->h_addr_list[0], pHostEnt->h_length);
			}
			else
			{
				DUEL_EXCEPT_BRIEF(DException::ET_InvalidParameters,
					"Invalid address: " + addr,
					"Duel::DSocket::parseAddress");	
			}
		}

		ret.sin_family = AF_INET;
		ret.sin_port = htons(port);

		return ret;
	}
Example #7
0
void ObjFileEditDialog::OnChangeSlot(wxCommandEvent &e)
{
	if(NULL == m_pLocatorNameComboBox)
		return;

	Fairy::CGod* pModel = GetDataManipulatr()->FindModel(GetDataManipulatr()->m_CurModelName);

	if(NULL == pModel)
		return;

	DString attachobjname		  = m_pAttachObjNameComboBox->GetStringSelection().c_str();

	DString slotname		      = m_pSlotNameComboBox->GetStringSelection().c_str();

	int nResult = pModel->ChangeSlot(slotname,attachobjname);

	if(0 == nResult)
	{
		wxMessageBox(wxString::Format("不存在slot<%s>对应的骨头,请检查美术资源!",slotname.c_str()));
	}
	else if(2 == nResult)
	{
		wxMessageBox(wxString::Format("属性slot<%s>的提示说明不为挂点!",slotname.c_str()));
	}
	else if(3 == nResult)
	{
		wxMessageBox(wxString::Format("未找到插槽slot<%s>对应的属性,请检查obj模板!",slotname.c_str()));
	}
}
Example #8
0
void ObjFileEditDialog::OnSelObjTemplate(wxCommandEvent &e)
{
	if(NULL == GetDataManipulatr())
		return;

	Fairy::CGod* pModel = GetDataManipulatr()->FindModel(GetDataManipulatr()->m_CurModelName);

	if(NULL == pModel)
	{
		wxMessageBox("请选择需要创建obj文件的模型!");
		return;
	}

	if(!pModel->m_IsCanSelectTemplate)
	{
		wxMessageBox("该模型已有对应的obj文件,如要生成obj文件,请使用mesh文件创建!");
		return;
	}

	DString templatename			  = m_pObjFileTable->GetStringSelection().c_str();

	if(templatename.empty())
		templatename			      = m_pObjFileTable->GetValue().c_str();

	pModel->m_IsAvatarTemplate = false;

	pModel->UpdateObjTemplateData(templatename);
}
Example #9
0
int DServerSock::sendPacket ( int hSock, const DString & packet, bool checkSock )
{
	ssize_t numberChar;
	fd_set stFdSet;
	struct timeval stTime;
	DString buffer;
	long int timeout;

	if ( checkSock )
	{
		// check if socket is opened
		timeout = m_timeout;
		setTimeout ( 10 );
		m_status = readMessage ( hSock, buffer );
		setTimeout ( timeout );
	}

	if ( m_hSocket < 0 || m_status == NO_SOCKET )
	{
		m_status = NO_SOCKET;
		m_lastError = "No opened socket found";
		return m_status;
	}
	FD_ZERO ( &stFdSet );
	FD_SET ( hSock, &stFdSet );
	stTime.tv_sec = m_timeout;
	stTime.tv_usec = 0;

	if (m_debug)
	{
		printMessage(packet);
	}
	// Check if data can be sent without any blocking
	if ( ( select ( hSock+1, NULL, &stFdSet, NULL, &stTime ) != -1 ) &&
			  ( FD_ISSET ( hSock, &stFdSet ) ) )
	{
		numberChar = send ( hSock, packet.c_str(), packet.length(), 0 );
		if ( numberChar == static_cast<ssize_t> ( packet.length() ) )
		{
			m_lastError = "";
			m_status = SUCCESS;
		}
		else
		{
			m_lastError = "No data sent, ";
			m_lastError =  + strerror ( errno );
			m_status = NO_SEND;
		}
	}
	else
	{
		m_lastError = "No data sent, ";
		m_lastError =  + strerror ( errno );
		m_status = NO_SEND;
	}
	return m_status;
}
Example #10
0
  BaseGDL* sem_create(EnvT *e)
  {
    SizeT nParam = e->NParam(1); // 1 is the minimal number of parameter required

    DString name;
    e->AssureStringScalarPar(0, name); // IDL accepts null-string name

    int destroyIx = e->KeywordIx("DESTROY_SEMAPHORE");
    bool destroyKWPresent = e->KeywordPresent(destroyIx);
    DLong destroy = 0;
    if (destroyKWPresent) 
    {
      destroy = (*e->GetKWAs<DLongGDL>(0))[0];
    }

    bool owner = true;
#ifdef _MSC_VER
    HANDLE sem = CreateSemaphore(NULL,1,1,name.c_str());
    if (sem == NULL) {
	owner = false;
	return new DIntGDL(0);
    }
#else
    sem_t *sem = sem_open(name.c_str(), O_CREAT | O_EXCL, 0666, 1);
    if (sem == SEM_FAILED)
    {
      owner = false;
      if (errno == EEXIST)
      {
        sem = sem_open(name.c_str(), 0);
      }
      if (sem == SEM_FAILED)
      {
        return new DIntGDL(0);
      }
    }
#endif

    // Behavior for different values of DESTROY_SEMAPHORE:
    // DESTROY_SEMAPHORE | owner    | other (== !owner)
    // ------------------+----------+-----------
    // not set           | delete   | ignore
    // != 0              | delete   | delete
    // 0                 | ignore   | ignore
    sem_data_t data;
    data.sem = sem;

    sem_set_owner(data, owner);
    sem_set_deletable(data, (!destroyKWPresent && owner) || (destroy != 0));
    sem_set_locked(data, false);

    sem_add(name, data);

    return new DIntGDL(1);
  }
Example #11
0
DString cadence::operator+(DString m, const DString &str) {
	int s = m.size();
	int s2 = str.size();

	for (int i=0; i<s2; i++) {
		m.m_obj[s+i].set(str.m_obj.get(i), true);
	}

	m.m_obj[Size].set(s+s2);

	return m;
}
Example #12
0
void ObjFileEditDialog::OnDelSkeleton(wxCommandEvent &e)
{
	if(NULL == m_pSkeletonAdd
	|| NULL == m_pSkeletonName
	|| NULL == GetDataManipulatr())

	return;

	Fairy::CGod* pModel = GetDataManipulatr()->FindModel(GetDataManipulatr()->m_CurModelName);

	if(NULL == pModel)
		return;

	DString skeletonname			  = m_pSkeletonName->GetStringSelection().c_str();

	if(skeletonname.empty())
	{
		wxMessageBox("请选择要删除的骨骼!");
		return;
	}

	int nSize = pModel->m_AniSkelist.size();

	DStringList::iterator it;

	for(int i=0;i<nSize;i++)
	{
		it = pModel->m_AniSkelist.begin()+i;

		if(skeletonname.compare(pModel->m_AniSkelist[i]) == 0)
		{
			pModel->m_AniSkelist.erase(it);
			break;
		}
	}

	Fairy::CGod::AniSkelistLink::iterator itlink = pModel->m_AniSkelistLink.find(skeletonname);

	if(itlink != pModel->m_AniSkelistLink.end())
	{
		pModel->m_AniSkelistLink.erase(skeletonname);
	}

	wxMessageBox(wxString::Format("删除骨骼<%s>成功!",skeletonname.c_str()));

	m_pSkeletonName->Clear();

	for(int i=0;i<(int)pModel->m_AniSkelist.size();i++)
	{
		m_pSkeletonName->AppendString(pModel->m_AniSkelist[i].c_str());
	}
}
Example #13
0
void DSock::printMessage(DString message)
{
	DString buffer;
	std::ofstream file;
	
	if (m_debug)
	{
		buffer = message.replaceEscapeSequence();
	}
	if ( ( m_debug & DEBUG_STDOUT ) == DEBUG_STDOUT )
	{
		std::cout << buffer << std::endl;
	}
	if ( ( m_debug & DEBUG_FILE ) == DEBUG_FILE )
	{
		if (!m_debugfile.isEmpty())
		{
			file.open(m_debugfile.c_str(), std::ios::out |  std::ios::app);
			if (file)
			{
				file << buffer << std::endl;
				file.close();
			}
		}
	}
}
Example #14
0
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// PBook::StripOpcode:
//    Strips the specified opcode from every position in the book.
//    Only the first occurrence of an opcode is removed for any position,
//    but opcodes are not supposed to occur more than once anyway.
//    Returns the number of positions where an opcode was removed.
uint
PBook::StripOpcode (const char * opcode)
{
    char * searchCode = new char [strLength(opcode) + 2];
    strCopy (searchCode, opcode);
    strAppend (searchCode, " ");
    DString dstr;
    uint countFound = 0;

    for (uint i=0; i < NodeListCount; i++) {
        bookNodeT * node = NodeList[i];
        if (node == NULL) { continue; }
        const char * s = node->data.comment;
        int startIndex = -1;
        int index = 0;
        // Look for a line with a matching opcode:
        while (*s != 0) {
            while (*s == '\n'  ||  *s == ' ') { s++; index++; }
            if (strIsPrefix (searchCode, s)) {
                startIndex = index;
                countFound++;
                break;
            }
            while (*s != 0  &&  *s != '\n') { s++; index++; }
        }
        if (startIndex > -1) {
            s = node->data.comment;
            index = 0;
            // Add all characters before the line to be stripped:
            dstr.Clear();
            while (index < startIndex) {
                dstr.AddChar (s[index]);
                index++;
            }
            // Now find the end of this line:
            s = &(s[startIndex + 1]);
            while (*s != 0  &&  *s != '\n') { s++; }
            if (*s == '\n') { s++; }
            while (*s != 0) { dstr.AddChar (*s);  s++; }

            delete[] node->data.comment;
            node->data.comment = strDuplicate (dstr.Data());
        }
    }
    delete[] searchCode;
    return countFound;
}
Example #15
0
  BaseGDL* ncdf_groupdef(EnvT* e)
  {
    size_t nParam=e->NParam(2);

    DLong grpid;
    e->AssureLongScalarPar( 0, grpid);

    DString s;
    e->AssureScalarPar<DStringGDL>(1, s);

    int status;
    int new_grpid;

    status=nc_def_grp(grpid, s.c_str(), &new_grpid);
    ncdf_handle_error(e, status,"NCDF_GROUPDEF");

    return new DLongGDL(new_grpid);
  }
Example #16
0
void Search::readStrGraph(Patterns &patterns,StrGraph &desc) {
    clear();
    map<StrGraph::Node*,Node*> recollect;
    for(StrGraph::node_iter ni = desc.nodes().begin(); ni!=desc.nodes().end(); ++ni) {
        Node *n = create_node(gd<Name>(*ni));
        recollect[*ni] = n;
        SearchStage &stage = gd<SearchStage>(n);
        DString limit = gd<StrAttrs>(*ni).look("limit","50");
        stage.limit = atoi(limit.c_str());
        DString action = gd<StrAttrs>(*ni).look("action","union");
        if(action=="union")
            stage.type = UnionInquiry;
        else if(action=="intersection")
            stage.type = IntersectionInquiry;
        else if(action=="pattern") {
            stage.type = PatternInquiry;
            DString pattern = gd<StrAttrs>(*ni).look("pattern","");
            Patterns::iterator pi = patterns.find(pattern);
            if(pi==patterns.end())
                throw UndefinedPattern(pattern);
            stage.pattern = &pi->second;
        }
        else if(action=="path") {
            stage.type = PathInquiry;
            DString ways = gd<StrAttrs>(*ni)["ways"];
            if(ways=="in")
                stage.goIn = true, stage.goOut = false;
            else if(ways=="both")
                stage.goIn = stage.goOut = true;
            else  // ways=="out" default
                stage.goIn = false, stage.goOut = true;
            stage.firstOnly = gd<StrAttrs>(*ni)["firstonly"]=="true";
            stage.shortest = gd<StrAttrs>(*ni)["shortest"]=="true";
            stage.weightattr = gd<StrAttrs>(*ni).look("weightattr","weight");
        }
        else
            throw UnknownAction(action);
    }
    for(StrGraph::graphedge_iter ei = desc.edges().begin(); ei!=desc.edges().end(); ++ei) {
        Edge *e = create_edge(recollect[(*ei)->tail],recollect[(*ei)->head]).first;
        DString input = gd<StrAttrs>(*ei).look("input","");
        gd<Name>(e) = input;
    }
}
Example #17
0
  BaseGDL* ncdf_ncidinq(EnvT* e)
  {
 
    // it is mandatory to have 2 parameters !
    size_t nParam=e->NParam(2);

    // in fact, we can use the "grpid" to check the file format it-self.
    DLong grpid;
    e->AssureLongScalarPar( 0, grpid);

    DString s;
    e->AssureScalarPar<DStringGDL>(1, s);

    // before going further we have to chech the file format, must be NetCDF-4

    int status;
    int fileformat;
    status=nc_inq_format(grpid, &fileformat);
    ncdf_handle_error(e, status,"NCDF_NCIDINQ");

    if (fileformat == NC_FORMAT_CLASSIC) 
      Warning("NCDF_NCIDINQ: NetCDF 3 Classic format found. not OK");
    if (fileformat == NC_FORMAT_64BIT)
      Warning("NCDF_NCIDINQ: NetCDF 3 64-BIT format found. not OK");
    
    if ((fileformat == NC_FORMAT_64BIT) || (fileformat == NC_FORMAT_CLASSIC)) {
      return new DLongGDL(-1);
    }

    int sub_grpid;
    status=nc_inq_ncid(grpid, s.c_str(), &sub_grpid);

    if (status != 0) {
      if (status == -125) {
	Warning("NCDF_NCIDINQ: No group found. (NC_ERROR=-125)");      
	return new DLongGDL(-1);
      } else {
	ncdf_handle_error(e, status,"NCDF_NCIDINQ");
      }
    }
    return new DLongGDL(sub_grpid);

  }
Example #18
0
void CFindOptions::AddStartDir( const DString &startDir )
{
	DString _lowercase = startDir.ToLower();

	for(auto _it : mStartDirVec)
	{
		if(_lowercase.compare(_it.ToLower()) == 0) return;
	}

	mStartDirVec.push_back( startDir );
}
Example #19
0
DString cadence::operator+(DString m, const char *str) {
	int s = m.size();
	int s2 = strlen(str);

	for (int i=0; i<s2; i++) {
		m.m_obj[s+i].set(str[i], true);
	}
	
	m.m_obj[Size].set(s+s2);

	return m;
}
  void sem_delete(EnvT *e)
  {
    SizeT nParam = e->NParam(1);

    DString name;
    e->AssureStringScalarPar(0, name);

    const sem_data_t &data = sem_get_data(name, e);
#if defined(_WIN32) && !defined(__CYGWIN__)
    CloseHandle(data.sem);
#else
    sem_close(data.sem);

    if (sem_is_deletable(data))
    {
      sem_unlink(name.c_str());
    }
#endif

    sem_remove(name);
  }
Example #21
0
void ObjFileEditDialog::OnChangeAttributeHints(wxCommandEvent &e)
{

	if(NULL == m_pAttributeHintsComboBox
	|| NULL == m_pAttributeNameComboBox
	|| NULL == GetDataManipulatr())
		return;

	Fairy::CGod* pModel = GetDataManipulatr()->FindModel(GetDataManipulatr()->m_CurModelName);

	if(NULL == pModel)
		return;
	
	DString Attributename = m_pAttributeNameComboBox->GetStringSelection().c_str();

	if(Attributename.empty())
		Attributename     = m_pAttributeNameComboBox->GetValue().c_str();

	DString AttributeHints = m_pAttributeHintsComboBox->GetStringSelection().c_str();

	bool bResult = pModel->ChangeHints(Attributename,AttributeHints);

	if(bResult)
	{
		wxMessageBox(wxString::Format("成功修改属性<%s>提示为<%s>!",Attributename.c_str(),AttributeHints.c_str()));
	}
	else
	{
		wxMessageBox(wxString::Format("操作失败!没有找到属性<%s>!",Attributename.c_str()));
	}
}
Example #22
0
void ObjFileEditDialog::OnAddSkeleton(wxCommandEvent &e)
{
	if(NULL == m_pSkeletonAdd
	|| NULL == m_pSkeletonTable
	|| NULL == m_pSkeletonName
	|| NULL == GetDataManipulatr())

	return;

	Fairy::CGod* pModel = GetDataManipulatr()->FindModel(GetDataManipulatr()->m_CurModelName);

	if(NULL == pModel)
		return;

	DString skeletonname			  = m_pSkeletonTable->GetStringSelection().c_str();

	if(skeletonname.empty())
		skeletonname			      = m_pSkeletonTable->GetValue().c_str();

	if(skeletonname.empty())
	{
		wxMessageBox("请选择要添加的骨骼!");
		return;
	}

	pModel->m_AniSkelist.push_back(skeletonname);

	DStringList Anilist;

	pModel->m_AniSkelistLink.insert(Fairy::CGod::AniSkelistLink::value_type(skeletonname,Anilist));

	wxMessageBox(wxString::Format("添加骨骼<%s>成功!",skeletonname.c_str()));

	m_pSkeletonName->Clear();

	for(int i=0;i<(int)pModel->m_AniSkelist.size();i++)
	{
		m_pSkeletonName->AppendString(pModel->m_AniSkelist[i].c_str());
	}
}
Example #23
0
int32 DexSkinMesh::FindMaterial(DString materialName)
{
	int32 index = -1;
	for (size_t i = 0; i < m_vecMaterials.size(); ++i)
	{
		if (dexstrcmp(materialName.c_str(), m_vecMaterials[i].name) == 0)
		{
			index = i;
			break;
		}
	}
	return index;
}
Example #24
0
void CFindOptions::RemoveStartDir( const DString &startDir )
{
	DString _lowercase = startDir.ToLower();

	for(auto _it = mStartDirVec.begin();_it<mStartDirVec.end();_it++)
	{
		if(_lowercase.compare(_it->ToLower()) == 0) 
		{
			mStartDirVec.erase(_it);
			return;
		}
	}
}
Example #25
0
void TestDSMTP::html_test()
{
	DSMTP mail;
	DSMTP::ERRNO code;
	DURL server;
	DStringList transaction, charlist;
	DStringList::const_iterator it;
	int i = 2;

	server.setURL( "smtp://localhost.localdomain:25" );

	mail.setHost ( server );
	mail.setSender ( "root@localhost" );
	mail.addReceiver ( "root@localhost" );
	
	DString buffer = "This is just a simple DLibs test, SMTP part\n\n";
	buffer += utf8chars;
	
	charlist = utf8chars.split( " " );
	DString html = "<!DOCTYPE html>\n<html>\n<body>\n<h1>This is just a simple DLibs test, SMTP part</h1>\n";
	html += "<table>\n";
	html += "<tr>\n";
	for ( it = charlist.begin() ; it != charlist.end() ; ++it )
	{
		if ( ! ( i % 16 ) )
		{
			html += "</tr>\n";
			html += "<tr>\n";
		}
		html += "<td>";
		html += it->toHTML();
		html += "</td>\n";
		i++;
	}

	html += "</tr>\n";
	html += "</table>\n";
	html += "</body>\n</html>";
	mail.setEmail ( "DLibs test", buffer, html );
	code = mail.send();
	
	TEST_ASSERT_MSG( mail.getLastError() == DString::empty(), "Error reported when sending email" )
	TEST_ASSERT_MSG( code == DSMTP::SUCCESS, "Email not sent" )
	
	transaction = mail.getTransactionLog();
	for ( it = transaction.begin() ; it != transaction.end() ; it++ )
	{
		std::cout << *it << std::endl;
	}
}
Example #26
0
int DClientSock::openSock ( const DString & host, int port )
{
	string buffer;
	struct sockaddr_in serv_addr;
	struct hostent *host_addr;

	// Open the socket
	m_hSocket = socket ( AF_INET, SOCK_STREAM, 0 );
	if ( m_hSocket < 0 )
	{
		m_lastError = "Cannot open the socket, ";
		m_lastError += strerror ( errno );
		m_status = NO_SOCKET;
		return m_status;
	}

	// Connect socket to host
	memset ( reinterpret_cast<char *> ( &serv_addr ), 0x00, sizeof ( struct sockaddr_in ) );
	serv_addr.sin_family = AF_INET;

	host_addr = gethostbyname(host.c_str());
	if (!host_addr)
	{
		//m_lastError = "Cannot get address by hostname";
		m_lastError = "Cannot get address of hostname " + host + ", ";
		m_lastError += strerror ( errno );
		return NO_HOST;
	}
	serv_addr.sin_addr.s_addr = ((struct in_addr*) host_addr->h_addr)->s_addr;
	//serv_addr.sin_addr.s_addr =  inet_addr ( host.c_str() );
	serv_addr.sin_port = htons ( port );

	if ( connect ( m_hSocket, reinterpret_cast<struct sockaddr *> ( &serv_addr ),
	               sizeof ( serv_addr ) ) < 0 )
	{
		m_lastError = "Cannot connect to host " + host + ", ";
		m_lastError += strerror ( errno );
		m_status = NO_HOST;
		this->closeSock();
		return m_status;
	}
	m_lastError = "";
	m_status = SUCCESS;

	// to have an non-blocked socket
	fcntl ( m_hSocket, F_SETFL, O_NONBLOCK );

	return m_status;
}
Example #27
0
DString cadence::operator+(DString m, const OID &o) {
	char buf[200];
	o.toString(buf,200);

	int s = m.size();
	int s2 = strlen(buf);

	for (int i=0; i<s2; i++) {
		m.m_obj[s+i].set(buf[i], true);
	}
	
	m.m_obj[Size].set(s+s2);

	return m;
}
Example #28
0
File: grib.cpp Project: cenit/GDL
  BaseGDL* grib_open_file_fun(EnvT* e)
  {
#ifndef USE_GRIB
    e->Throw("GDL was compiled without support for GRIB");
    return NULL;
#else
    {
      SizeT nParam = e->NParam(1);
    }

    DString filename;
    e->AssureScalarPar<DStringGDL>( 0, filename); 

    FILE* in = NULL; 
    // TODO: handle RO/RW parameters (but currently anyhow no write methods are implemented...)
    in = fopen(filename.c_str(), "r"); 
    if (!in) e->Throw("unable to open file: " + filename);

    DLong ifile = GribFileList.end()->first;
    GribFileList[ifile] = in;
 
    return new DLongGDL(ifile);
#endif
  }
Example #29
0
pair<Layout::Node*,bool> View::getNode(DString id,bool create) {
	if(id.empty())
		id = randomName('n');
	Layout::Node *n = nodes[id];
	if(n)
		return make_pair(n,false);
	if(!create) 
		return make_pair<Layout::Node*>(0,false);
    NodeAttrs *NA = new NodeAttrs();
	n = layout.create_node(*NA);
    delete NA;
	gd<Name>(n) = id;
	nodes[id] = n;
	return make_pair(n,true);
}
Example #30
0
void DProcess::run()
{
	DString buffer;
	DString cmode;
	DStringList::iterator it;
	char * buf;
	int bufsize = 80 * sizeof( char );

	// construct exe line
	buffer = m_exe;
	for ( it = m_args.begin() ; it != m_args.end() ; ++it )
	{
		if ( !buffer.isEmpty() )
		{
			buffer.append( " " );
		}
		buffer.append( *it );
	}

	if ( m_com_mode == READ_ONLY)
	{
		cmode = "r";
	}
	else
	{
		cmode = "w";
	}
	m_file = popen( buffer.c_str(), cmode.c_str() );

	if ( !m_file )
	{
		return;
	}
	
	if ( m_com_mode == READ_ONLY)
	{
		buf = new char[ bufsize ];

		while ( fgets( buf, bufsize, m_file ) != 0 )
		{
			addOutput( buf );
		}
		delete[]( buf );
	}
	
	pclose( m_file );

	m_file = 0;
}