static void lookup(void) { struct passwd *pw = NULL; #ifdef HAVE_GETPWUID_R struct passwd pwd; char buffer[1024]; ::getpwuid_r(geteuid(), &pwd, buffer, 1024, &pw); #else pw = ::getpwuid(geteuid()); #endif if(_pHome) delString(_pHome); if(_pUser) delString(_pUser); _pUser = _pHome = NULL; if(pw != NULL && pw->pw_dir != NULL) _pHome = newString(pw->pw_dir); if(pw != NULL && pw->pw_name != NULL) _pUser = newString(pw->pw_name); endpwent(); }
static void testStringTable(void) { int val; struct StringTable *st; int i; for (i = 0; i < 100; i += 1) { st = newStringTable(); rassert(st); rassert(findString(st, "dog") == NULL); rassert(putString(st, "cat", &val) == 0); rassert(findString(st, "cat") == &val); rassert(delString(st, "dog") == ERR_NOSTRING); rassert(delString(st, "cat") == 0); rassert(findString(st, "cat") == NULL); rassert(putString(st, "1", &val) == 0); rassert(putString(st, "2", &val) == 0); rassert(putString(st, "3", &val) == 0); allSum = 0; allStrings(st, allStringTester, NULL); rassert(allSum == 6); rassert(delString(st, "1") == 0); rassert(delString(st, "3") == 0); rassert(delString(st, "2") == 0); rassert(putString(st, "memcheck", &val) == 0); freeStringTable(st); } }
RpcStringBinding::RpcStringBinding ( DUALSTRINGARRAY* pdsa, int portNumber ) : m_ipAddress (0), m_portNumber (portNumber), m_protocolSeq (0), m_strFormat (0), m_strFormatNoPortNumber (0) { // Check the DUALSTRINGARRAY entries, to find one which can be // 'resolved' into an IP address on this machine. Win2K sometimes // provides hostnames as well as the IP numbers that NT usually // sends, so we need to scan the array to find an IP number... OLECHAR* pStart = pdsa->aStringArray; OLECHAR* pCurr = pStart; while ((pCurr - pStart) < pdsa->wNumEntries) { // Make a string-binding out of the DSA entry... char * pStr = new char [comWideStrLen (pCurr + 1) + 1]; comWideToAscii (pStr, pCurr + 1, comWideStrLen (pCurr + 1) + 1); initialiseFromString (pStr); delete []pStr; m_protocolSeq = *pCurr; // See if it can be 'resolved' into a viable IP number... if (! resolve ()) { S_ERR (LOG_DCOM, "Could not resolve " << ipAddress ()); // Free up the allocated strings. delString (m_ipAddress); delString (m_strFormat); delString (m_strFormatNoPortNumber); // Could not make sense of the address, so move on through // the array to the next entry, or the end of the array... while (((pCurr - pStart) < pdsa->wNumEntries) && (*pCurr)) ++pCurr; ++pCurr; } else { S_INFO (LOG_DCOM, "Resolved " << ipAddress ()); // Take the first one that is viable... break; } } // at this point the string binding may have worked or not so the calling // routine must make a call to resolve to determine if a valid address was // bound since the constructor can't /init }
RpcStringBinding& RpcStringBinding::operator=(const RpcStringBinding& rhs) { if (this != &rhs) { delString (m_ipAddress); delString (m_strFormat); delString (m_strFormatNoPortNumber); m_ipAddress = copyString (rhs.m_ipAddress); m_portNumber = rhs.m_portNumber; m_protocolSeq = rhs.m_protocolSeq; m_strFormat = copyString (rhs.m_strFormat); m_strFormatNoPortNumber = copyString (rhs.m_strFormatNoPortNumber); } return *this; }
//功能:删除读取到的代码中的双引号之间的内容 void delCmdString() { int i; for(i=0; i<cmdCount; i++) { delString(command[i]); } }
void IPV6Address::setAddress(const char *host) { if(hostname) delString(hostname); hostname = NULL; if(!host) // The way this is currently used, this can never happen host = "::"; #ifdef WIN32 if(!stricmp(host, "localhost")) host = "::1"; #endif if(!setIPAddress(host)) { struct addrinfo hint, *list = NULL, *first; memset(&hint, 0, sizeof(hint)); hint.ai_family = AF_INET6; struct in6_addr *addr; struct sockaddr_in6 *ip6addr; if(getaddrinfo(host, NULL, &hint, &list) || !list) { if(ipaddr) delete[] ipaddr; ipaddr = new struct in6_addr[1]; memset((void *)&ipaddr[0], 0, sizeof(ipaddr)); return; } // Count the number of IP addresses returned addr_count = 0; first = list; while(list) { ++addr_count; list = list->ai_next; } // Allocate enough memory if(ipaddr) delete[] ipaddr; // Cause this was allocated in base ipaddr = new struct in6_addr[addr_count]; // Now go through the list again assigning to // the member ipaddr; list = first; int i = 0; while(list) { ip6addr = (struct sockaddr_in6 *)list->ai_addr; addr = &ip6addr->sin6_addr; if(validator) (*validator)(*addr); ipaddr[i++] = *addr; list = list->ai_next; } freeaddrinfo(first); } }
IPV6Address::~IPV6Address() { if(ipaddr) { delete[] ipaddr; ipaddr = NULL; } if(hostname) { delString(hostname); hostname = NULL; } }
const char *IPV6Address::getHostname(void) const { struct hostent *hp = NULL; struct in6_addr addr0; static char strbuf[64]; memset(&addr0, 0, sizeof(addr0)); if(!memcmp(&addr0, &ipaddr[0], sizeof(addr0))) return NULL; if(!memcmp(&in6addr_loopback, &ipaddr[0], sizeof(addr0))) return "localhost"; #if defined(__GLIBC__) char hbuf[8192]; struct hostent hb; int rtn; if(gethostbyaddr_r((char *)&ipaddr[0], sizeof(addr0), AF_INET6, &hb, hbuf, sizeof(hbuf), &hp, &rtn)) hp = NULL; #elif defined(sun) char hbuf[8192]; struct hostent hb; int rtn; hp = gethostbyaddr_r((char *)&ipaddr[0], sizeof(addr0), AF_INET6, &hb, hbuf, (int)sizeof(hbuf), &rtn); #elif defined(__osf__) || defined(WIN32) hp = gethostbyaddr((char *)&ipaddr[0], sizeof(addr0), AF_INET6); #else mutex.enterMutex(); hp = gethostbyaddr((char *)&ipaddr[0], sizeof(addr0), AF_INET6); mutex.leaveMutex(); #endif if(hp) { if(hostname) delString(hostname); hostname = newString(hp->h_name); return hostname; } else { #ifdef WIN32 struct sockaddr saddr; struct sockaddr_in6 *paddr = (struct sockaddr_in6 *)&saddr; DWORD slen = sizeof(strbuf); memset(&saddr, 0, sizeof(saddr)); paddr->sin6_family = AF_INET6; paddr->sin6_addr = ipaddr[0]; WSAAddressToString(&saddr, sizeof(saddr), NULL, strbuf, &slen); return strbuf; #else return inet_ntop(AF_INET6, &ipaddr[0], strbuf, sizeof(strbuf)); #endif } }
IPV6Address &IPV6Address::operator=(struct in6_addr addr) { if(ipaddr) delete[] ipaddr; if ( validator ) (*validator)(addr); addr_count = 1; ipaddr = new struct in6_addr[1]; ipaddr[0] = addr; if(hostname) delString(hostname); hostname = NULL; return *this; }
IPV6Address &IPV6Address::operator=(const IPV6Address &rhs) { if(this == &rhs) return *this; addr_count = rhs.addr_count; if(ipaddr) delete[] ipaddr; ipaddr = new struct in6_addr[addr_count]; memcpy(ipaddr, rhs.ipaddr, sizeof(struct in6_addr) * addr_count); validator = rhs.validator; if(hostname) delString(hostname); hostname = NULL; return *this; }
IPV6Host &IPV6Host::operator&=(const IPV6Mask &ma) { for(size_t i = 0; i < addr_count; i++) { struct in6_addr mask = ma.getAddress(); unsigned char *a = (unsigned char *)&ipaddr[i]; unsigned char *m = (unsigned char *)&mask; for(size_t j = 0; j < sizeof(struct in6_addr); ++j) *(a++) &= *(m++); } if(hostname) delString(hostname); hostname = NULL; return *this; }
const char *IPV4Address::getHostname(void) const { struct hostent *hp = NULL; struct in_addr addr0; memset(&addr0, 0, sizeof(addr0)); if(!memcmp(&addr0, &ipaddr[0], sizeof(addr0))) return NULL; #ifdef _MSWINDOWS_ memset(&addr0, 0xff, sizeof(addr0)); if(!memcmp(&addr0, &ipaddr[0], sizeof(addr0))) return "255.255.255.255"; long a = inet_addr("127.0.0.1"); if(!memcmp(&a, &ipaddr[0], sizeof(a))) return "localhost"; #endif #if defined(__GLIBC__) char hbuf[8192]; struct hostent hb; int rtn; if(gethostbyaddr_r((char *)&ipaddr[0], sizeof(addr0), AF_INET, &hb, hbuf, sizeof(hbuf), &hp, &rtn)) hp = NULL; #elif defined(sun) char hbuf[8192]; struct hostent hb; int rtn; hp = gethostbyaddr_r((char *)&ipaddr[0], (int)sizeof(addr0), (int)AF_INET, &hb, hbuf, (int)sizeof(hbuf), &rtn); #elif defined(__osf__) || defined(_MSWINDOWS_) hp = gethostbyaddr((char *)&ipaddr[0], sizeof(addr0), AF_INET); #else mutex.enterMutex(); hp = gethostbyaddr((char *)&ipaddr[0], sizeof(addr0), AF_INET); mutex.leaveMutex(); #endif if(hp) { if(hostname) delString(hostname); hostname = newString(hp->h_name); return hostname; } else { return inet_ntoa(ipaddr[0]); } }
// "deleteTractFile()": delete tractogram file int fileManager::deleteTractFile ( const size_t tractNode ) const { std::string tractFilename = getNodeTractFilename(tractNode); // Variables for calling system commands std::string delString("rm -f "); std::string sysCommand(delString +tractFilename); if(m_zipFlag) { sysCommand = sysCommand +".gz"; } // remove file return system(sysCommand.c_str()); }// end fileManager::deleteTractFile(" -----------------------------------------------------------------
void QStringListWidget::contextMenuEvent(QContextMenuEvent* evt) { QMenu menu(this); QAction* addObjItem = menu.addAction(tr("Add Item")); QAction* delObjItem = menu.addAction(tr("Remove Item")); if (currentItem() == NULL) delObjItem->setEnabled(false); QAction* sel = menu.exec(evt->globalPos()); if (sel == addObjItem) { bool ok; QString str = QInputDialog::getText(this, tr("Add Item"), tr("Enter a string"), QLineEdit::Normal, QString(), &ok); if (ok) addString(str); } else if (sel == delObjItem) { delString(currentRow()); } }
MainWindow::MainWindow(const std::string &simulationName) { this->m_dw = NULL; this->m_gen = new Generator(simulationName); // // Menu // QMenu *menuFichier = menuBar()->addMenu("&File"); /* QAction *menuOpen = menuFichier->addAction("Open"); menuOpen->setDisabled(true); QAction *menuNew = menuFichier->addAction("New"); menuNew->setDisabled(true); QAction *menuSave = menuFichier->addAction("Save"); menuSave->setDisabled(true); QAction *menuSaveAs = menuFichier->addAction("Save as"); menuSaveAs->setDisabled(true); */ QAction *menuSavePix = menuFichier->addAction("Save as picture"); connect(menuSavePix, SIGNAL(triggered()), this, SLOT(SavePicture())); QAction *menuXml = menuFichier->addAction("Save as XML"); connect(menuXml, SIGNAL(triggered()), this, SLOT(SaveXml())); QAction *menuXmlLoad = menuFichier->addAction("Load XML file"); connect(menuXmlLoad, SIGNAL(triggered()), this, SLOT(LoadXml())); QAction *actionQuit = menuFichier->addAction("Quit"); connect(actionQuit, SIGNAL(triggered()), qApp, SLOT(quit())); QMenu *menuEdit = menuBar()->addMenu("&Edit"); QAction *actionConfig = menuEdit->addAction("Configuration"); actionConfig->setDisabled(true); //connect(actionConfig, SIGNAL(triggered()), this, SLOT(ConfigurationMenu())); QMenu *menuView = menuBar()->addMenu("&Generate"); QAction *actionCpp = menuView->addAction("&C++"); connect(actionCpp, SIGNAL(triggered()), this, SLOT(GenerateCpp())); QAction *actionPython = menuView->addAction("&Python"); connect(actionPython, SIGNAL(triggered()), this, SLOT(GeneratePython())); QMenu *menuHelp = menuBar()->addMenu("&Help"); QAction *menuOnlineHelp = menuHelp->addAction("Online Help"); menuOnlineHelp->setDisabled(true); //connect(menuOnlineHelp, SIGNAL(triggered()), this, SLOT(Help())); QAction *menuAbout = menuHelp->addAction("About"); connect(menuAbout, SIGNAL(triggered()), this, SLOT(About())); menuAbout = menuAbout; menuHelp = menuHelp; // // toolbar for add equipements. // QToolBar *toolBarFichier = addToolBar(""); //PC QIcon pcIcon(":/Ico/Pc.png"); QString pcString("Terminal"); QAction *pcAction = toolBarFichier->addAction(pcIcon, pcString); connect(pcAction, SIGNAL(triggered()), this, SLOT(CreatePc())); //Pc-group QIcon pcgIcon(":/Ico/Pc-group.png"); QString pcgString("Terminal Group"); QAction *pcgAction = toolBarFichier->addAction(pcgIcon, pcgString); connect(pcgAction, SIGNAL(triggered()), this, SLOT(CreatePcGroup())); //PC-Emu QIcon emuIcon(":/Ico/Emu.png"); QString emuString("PC with emu"); QAction *emuAction = toolBarFichier->addAction(emuIcon, emuString); connect(emuAction, SIGNAL(triggered()), this, SLOT(CreateEmu())); //PC-Tap QIcon tapIcon(":/Ico/Tap.png"); QString tapString("PC with tap"); QAction *tapAction = toolBarFichier->addAction(tapIcon, tapString); connect(tapAction, SIGNAL(triggered()), this, SLOT(CreateTap())); //AP-Wifi QIcon apIcon(":/Ico/Ap-Wifi.png"); QString apString("AP Wifi"); QAction *apAction = toolBarFichier->addAction(apIcon, apString); connect(apAction, SIGNAL(triggered()), this, SLOT(CreateAp())); //StationWifi QIcon stasIcon(":/Ico/StationWifi.png"); QString stasString("Station Wifi"); QAction *stasAction = toolBarFichier->addAction(stasIcon, stasString); connect(stasAction, SIGNAL(triggered()), this, SLOT(CreateStation())); //Hub QIcon hubIcon(":/Ico/Hub.png"); QString hubString("Hub"); QAction *hubAction = toolBarFichier->addAction(hubIcon, hubString); connect(hubAction, SIGNAL(triggered()), this, SLOT(CreateHub())); //Switch QIcon switchIcon(":/Ico/Switch.png"); QString switchString("Switch"); QAction *switchAction = toolBarFichier->addAction(switchIcon, switchString); connect(switchAction, SIGNAL(triggered()), this, SLOT(CreateSwitch())); //Router QIcon routerIcon(":/Ico/Router.png"); QString routerString("Router"); QAction *routerAction = toolBarFichier->addAction(routerIcon, routerString); connect(routerAction, SIGNAL(triggered()), this, SLOT(CreateRouter())); //separator toolBarFichier->addSeparator(); // Wired Link QIcon linkIcon(":/Ico/WiredLink.png"); QString linkString("Wired Link"); QAction *linkAction = toolBarFichier->addAction(linkIcon, linkString); connect(linkAction, SIGNAL(triggered()), this, SLOT(CreateWiredLink())); // Station link QIcon stasLinkIcon(":/Ico/Link.png"); QString stasLinkString("Station Link"); QAction *stasLinkAction = toolBarFichier->addAction(stasLinkIcon, stasLinkString); connect(stasLinkAction, SIGNAL(triggered()), this, SLOT(CreateWifiLink())); //P2P link QIcon p2pLinkIcon(":/Ico/P2pLink.png"); QString p2pLinkString("P2P Link"); QAction *p2pLinkAction = toolBarFichier->addAction(p2pLinkIcon, p2pLinkString); connect(p2pLinkAction, SIGNAL(triggered()), this, SLOT(CreateP2pLink())); //separator toolBarFichier->addSeparator(); QIcon appsLinkIcon(""); QString appsLinkString("Application"); QAction *appsLinkAction = toolBarFichier->addAction(appsLinkIcon, appsLinkString); connect(appsLinkAction, SIGNAL(triggered()), this, SLOT(CreateApplication())); //separator toolBarFichier->addSeparator(); //Delete button QIcon delIcon(":/Ico/Del.png"); QString delString("Delete"); this->m_delAction = toolBarFichier->addAction(delIcon, delString); this->m_delAction->setDisabled (true); connect(this->m_delAction, SIGNAL(triggered()), this, SLOT(DeleteObject())); // // Creation of Drag N Drop Area. // QHBoxLayout *dragLayout = new QHBoxLayout; this->m_dw = new DragWidget(); dragLayout->addWidget(this->m_dw); QWidget *zoneCentral = new QWidget; zoneCentral->setLayout(dragLayout); this->setCentralWidget(zoneCentral); // // // this->m_dw->SetMainWindow(this); }
void IPV6Address::setAddress(const char *host) { if(hostname) delString(hostname); hostname = NULL; if(!host) // The way this is currently used, this can never happen host = "::"; #ifdef WIN32 if(!stricmp(host, "localhost")) host = "::1"; #endif if(!setIPAddress(host)) { struct hostent *hp; struct in6_addr **bptr; #if defined(__GLIBC__) char hbuf[8192]; struct hostent hb; int rtn; if(gethostbyname2_r(host, AF_INET6, &hb, hbuf, sizeof(hbuf), &hp, &rtn)) hp = NULL; #elif defined(sun) char hbuf[8192]; struct hostent hb; int rtn; hp = gethostbyname2_r(host, AF_INET6, &hb, hbuf, sizeof(hbuf), &rtn); #elif (defined(__osf__) || defined(_OSF_SOURCE) || defined(__hpux)) hp = gethostbyname(host); #elif defined(WIN32) && (!defined(_MSC_VER) || _MSC_VER < 1300) hp = gethostbyname(host); #elif defined(WIN32) hp = gethostbyname2(host, AF_INET6); #else mutex.enterMutex(); hp = gethostbyname2(host, AF_INET6); mutex.leaveMutex(); #endif if(!hp) { if(ipaddr) delete[] ipaddr; ipaddr = new struct in6_addr[1]; memset((void *)&ipaddr[0], 0, sizeof(ipaddr)); return; } // Count the number of IP addresses returned addr_count = 0; for(bptr = (struct in6_addr **)hp->h_addr_list; *bptr != NULL; bptr++) { addr_count++; } // Allocate enough memory if(ipaddr) delete[] ipaddr; // Cause this was allocated in base ipaddr = new struct in6_addr[addr_count]; // Now go through the list again assigning to // the member ipaddr; bptr = (struct in6_addr **)hp->h_addr_list; for(unsigned int i = 0; i < addr_count; i++) { if ( validator ) (*validator)(*bptr[i]); ipaddr[i] = *bptr[i]; } } }
int delInt(struct StringTable *st, int key) { return delString(st, makeStringFromInt(key)); }
InputStrList::InputStrList( const QString & label, QWidget *parent, QStrList &sl, ListMode lm) : QWidget(parent), strList(sl) { QGridLayout *layout = new QGridLayout( this, 2, 2, 5 ); lab = new QLabel( label, this ); lab->setMinimumSize( lab->sizeHint() ); layout->addWidget( lab,0,0 ); QWidget *dw = new QWidget(this); /* dummy widget used for layouting */ QHBoxLayout *boxlayout = new QHBoxLayout( dw, 0, 5 ); le = new QLineEdit( dw ); le->setMinimumSize( le->sizeHint() ); boxlayout->addWidget( le, 1 ); add = new QPushButton( dw ); //add->setPixmap( QPixmap( add_xpm )); add->setText( "+" ); add->setMinimumSize( add->sizeHint() ); QToolTip::add(add,"Add item"); boxlayout->addWidget( add ); del = new QPushButton( dw ); //del->setPixmap( QPixmap( del_xpm )); del->setText( "-" ); del->setMinimumSize( del->sizeHint() ); QToolTip::add(del,"Delete selected item"); boxlayout->addWidget( del ); upd = new QPushButton( dw ); //upd->setPixmap( QPixmap( update_xpm )); upd->setText( "*" ); upd->setMinimumSize( upd->sizeHint() ); QToolTip::add(upd,"Update selected item"); boxlayout->addWidget( upd ); lb = new QListBox( this ); lb->setMinimumSize(400,100); init(); lb->setVScrollBarMode(QScrollView::Auto); lb->setHScrollBarMode(QScrollView::Auto); brFile=0; brDir=0; if (lm!=ListString) { if (lm&ListFile) { brFile = new QPushButton(dw); //brFile->setPixmap( QPixmap(file_xpm) ); brFile->setText("Select..."); brFile->setMinimumSize(brFile->sizeHint()); QToolTip::add(brFile,"Browse to a file"); boxlayout->addWidget( brFile ); } if (lm&ListDir) { brDir = new QPushButton(dw); //brDir->setPixmap( QPixmap(folder_xpm) ); brDir->setText("Select..."); brDir->setMinimumSize(brDir->sizeHint()); QToolTip::add(brDir,"Browse to a folder"); boxlayout->addWidget( brDir ); } } layout->addWidget( dw, 0,1 ); layout->addWidget( lb,1,1 ); layout->activate(); setMinimumSize( sizeHint() ); connect(le, SIGNAL(returnPressed()), this, SLOT(addString()) ); connect(add, SIGNAL(clicked()), this, SLOT(addString()) ); connect(del, SIGNAL(clicked()), this, SLOT(delString()) ); connect(upd, SIGNAL(clicked()), this, SLOT(updateString()) ); if (brFile) { connect(brFile, SIGNAL(clicked()), this, SLOT(browseFiles())); } if (brDir) { connect(brDir, SIGNAL(clicked()), this, SLOT(browseDir())); } connect(lb, SIGNAL(selected(const QString &)), this, SLOT(selectText(const QString &))); }
InputStrList::InputStrList( QGridLayout *layout,int &row, const QString & id, const QStringList &sl, ListMode lm, const QString & docs) : m_default(sl), m_strList(sl), m_docs(docs), m_id(id) { m_lab = new HelpLabel( id ); m_le = new QLineEdit; m_le->clear(); QToolBar *toolBar = new QToolBar; toolBar->setIconSize(QSize(24,24)); m_add = toolBar->addAction(QIcon(QString::fromAscii(":/images/add.png")),QString(), this,SLOT(addString())); m_add->setToolTip(tr("Add item")); m_del = toolBar->addAction(QIcon(QString::fromAscii(":/images/del.png")),QString(), this,SLOT(delString())); m_del->setToolTip(tr("Delete selected item")); m_upd = toolBar->addAction(QIcon(QString::fromAscii(":/images/refresh.png")),QString(), this,SLOT(updateString())); m_upd->setToolTip(tr("Update selected item")); m_lb = new QListWidget; //m_lb->setMinimumSize(400,100); foreach (QString s, m_strList) m_lb->addItem(s); m_brFile=0; m_brDir=0; if (lm!=ListString) { if (lm&ListFile) { m_brFile = toolBar->addAction(QIcon(QString::fromAscii(":/images/file.png")),QString(), this,SLOT(browseFiles())); m_brFile->setToolTip(tr("Browse to a file")); } if (lm&ListDir) { m_brDir = toolBar->addAction(QIcon(QString::fromAscii(":/images/folder.png")),QString(), this,SLOT(browseDir())); m_brDir->setToolTip(tr("Browse to a folder")); } } QHBoxLayout *rowLayout = new QHBoxLayout; rowLayout->addWidget( m_le ); rowLayout->addWidget( toolBar ); layout->addWidget( m_lab, row,0 ); layout->addLayout( rowLayout, row,1,1,2 ); layout->addWidget( m_lb, row+1,1,1,2 ); row+=2; m_value = m_strList; connect(m_le, SIGNAL(returnPressed()), this, SLOT(addString()) ); connect(m_lb, SIGNAL(currentTextChanged(const QString &)), this, SLOT(selectText(const QString &))); connect( m_lab, SIGNAL(enter()), SLOT(help()) ); connect( m_lab, SIGNAL(reset()), SLOT(reset()) ); }
RpcStringBinding::~RpcStringBinding () { delString (m_ipAddress); delString (m_strFormat); delString (m_strFormatNoPortNumber); }