/* * Checks of a valid pipes and calls IPC to launch childs and commands * * @param pl pipeline created by the command line phraser * @return exit status of the last child forked in the pipeline */ int process( pipeline pl ) { int totalP, status; Child *myChilds; /* Child ARRAY */ if(pl->cline == NULL) /* check if the cmd arg is not empty , should never happened by main */ return -1; totalP = pl->length; /* perform the build in commands */ /* children info array */ FATALCALL( (myChilds = (Child *) malloc (sizeof(Child) * totalP)) == NULL, "Invalid Malloc"); /* inialize child struct to EMPTY */ FATAL( (newChild( myChilds, totalP)) == -1, "Error") /* create the pipes */ status = IPC( pl, myChilds ); /* free the id's and return status */ free ( myChilds ); return status; }
void Qip::socketReadyRead() { // read from the server QTextStream stream( socket ); QString line; while ( socket->canReadLine() ) { line = stream.readLine(); if ( line.startsWith( "500" ) ) { error( ErrValid, line.mid( 4 ) ); } else if ( line.startsWith( "550" ) ) { error( ErrFileNotExisting, line.mid( 4 ) ); } else if ( line.startsWith( "212+" ) ) { if ( state != List ) { state = List; emit start( operationInProgress() ); } QUrlInfo inf; inf.setName( line.mid( 6 ) + QString( ( line[ 4 ] == 'D' ) ? "/" : "" ) ); inf.setDir( line[ 4 ] == 'D' ); inf.setSymLink( FALSE ); inf.setFile( line[ 4 ] == 'F' ); inf.setWritable( FALSE ); inf.setReadable( TRUE ); emit newChild( inf, operationInProgress() ); } else if ( line.startsWith( "213+" ) ) { state = Data; emit data( line.mid( 4 ).utf8(), operationInProgress() ); } if( line[3] == ' ' && state != Start) { state = Start; operationInProgress()->setState( StDone ); emit finished( operationInProgress() ); } } }
void Q3LocalFs::operationMkDir( Q3NetworkOperation *op ) { #ifdef QLOCALFS_DEBUG qDebug( "Q3LocalFs: operationMkDir" ); #endif op->setState( StInProgress ); QString dirname = op->arg( 0 ); dir = QDir( url()->path() ); if ( dir.mkdir( dirname ) ) { QFileInfo fi( dir, dirname ); QUrlInfo inf( fi.fileName(), convertPermissions(&fi), fi.owner(), fi.group(), fi.size(), fi.lastModified(), fi.lastRead(), fi.isDir(), fi.isFile(), fi.isSymLink(), fi.isWritable(), fi.isReadable(), fi.isExecutable() ); emit newChild( inf, op ); op->setState( StDone ); emit createdDirectory( inf, op ); emit finished( op ); } else { QString msg = tr( "Could not create directory\n%1" ).arg( dirname ); op->setState( StFailed ); op->setProtocolDetail( msg ); op->setErrorCode( (int)ErrMkDir ); emit finished( op ); } }
// add array JSONarray* JSONobject::addArray(string key, string content) { // create json array JSONarray* array = new JSONarray(content); JSONchild* child = newChild(key); // assign pointer to object child->array = array; // return array pointer return array; }
// add json object JSONobject* JSONobject::addObject(string key, string content) { // create object pointer JSONobject* object = new JSONobject(content); JSONchild* child = newChild(key); // assign pointer child->object = object; // return json object pointer return object; }
bool SimpleSceneGraph::insert(Entity& entity) { unique_ptr<SimpleSceneGraph> newChild(new SimpleSceneGraph); bool result = newChild->insertDirect(entity); newChild->setParent(this); children.push_back(move(newChild)); return result; }
CDataNode* CDataNode::Structure( const CString& nodeName , const CString& attribName , const CString& attribSequence , const char seperator ) {GUCEF_TRACE; // Prepare some variables for the first loop iteration CDataNode* node = this; CString attSeqRemnant = attribSequence; CString attValue = attSeqRemnant.SubstrToChar( seperator ); bool childExists = true; CDataNode* childNode = NULL; do { // First we check if we can skip the search for a child node // This is a minor optimization if ( childExists ) { // See if there already is a node of the given type childNode = node->FindChild( nodeName , attribName , attValue ); if ( childNode == NULL ) { childExists = false; } } // Check if we have to create a new node if ( childNode == NULL ) { // No such node exists, we will create it CDataNode newChild( nodeName ); newChild.AddAttribute( attribName, attValue ); childNode = node->AddChild( newChild ); } node = childNode; // Get the next segment attSeqRemnant = attSeqRemnant.CutChars( attValue.Length()+1, true ); attValue = attSeqRemnant.SubstrToChar( seperator ); } while ( attSeqRemnant.Length() > 0 ); return childNode; }
Node* Node::addChildNode(std::string action, GameStates::IGameState *state) { // Remove action connected to newNode, from list of not taken actions this->actionsNotTaken.erase(std::remove(this->actionsNotTaken.begin(), this->actionsNotTaken.end(), action), this->actionsNotTaken.end()); // Create new node for tree Node newChild(action, this, state); // Add new node to list of child nodes this->childNodes.push_back(newChild); // Return pointer to newly created node return &this->childNodes.back(); }
void Nntp::parseGroups() { if ( !commandSocket->canReadLine() ) return; // read one line after the other while ( commandSocket->canReadLine() ) { QString s = commandSocket->readLine(); // if the line starts with a dot, all groups or articles have been listed, // so we finished processing the listChildren() command if ( s[ 0 ] == '.' ) { readGroups = FALSE; operationInProgress()->setState( StDone ); emit finished( operationInProgress() ); return; } // if the code of the server response is 215 or 211 // the next line will be the first group or article (depending on what we read). // So let others know that we start reading now... if ( s.left( 3 ) == "215" || s.left( 3 ) == "211" ) { operationInProgress()->setState( StInProgress ); emit start( operationInProgress() ); continue; } // parse the line and create a QUrlInfo object // which describes the child (group or article) bool tab = s.find( '\t' ) != -1; QString group = s.mid( 0, s.find( tab ? '\t' : ' ' ) ); QUrlInfo inf; inf.setName( group ); QString path = url()->path(); inf.setDir( path.isEmpty() || path == "/" ); inf.setSymLink( FALSE ); inf.setFile( !inf.isDir() ); inf.setWritable( FALSE ); inf.setReadable( TRUE ); // let others know about our new child emit newChild( inf, operationInProgress() ); } }
bool QNetworkProtocol::qt_emit( int _id, QUObject* _o ) { switch ( _id - staticMetaObject()->signalOffset() ) { case 0: data((const QByteArray&)*((const QByteArray*)static_QUType_ptr.get(_o+1)),(QNetworkOperation*)static_QUType_ptr.get(_o+2)); break; case 1: connectionStateChanged((int)static_QUType_int.get(_o+1),(const QString&)static_QUType_QString.get(_o+2)); break; case 2: finished((QNetworkOperation*)static_QUType_ptr.get(_o+1)); break; case 3: start((QNetworkOperation*)static_QUType_ptr.get(_o+1)); break; case 4: newChildren((const QValueList<QUrlInfo>&)*((const QValueList<QUrlInfo>*)static_QUType_ptr.get(_o+1)),(QNetworkOperation*)static_QUType_ptr.get(_o+2)); break; case 5: newChild((const QUrlInfo&)*((const QUrlInfo*)static_QUType_ptr.get(_o+1)),(QNetworkOperation*)static_QUType_ptr.get(_o+2)); break; case 6: createdDirectory((const QUrlInfo&)*((const QUrlInfo*)static_QUType_ptr.get(_o+1)),(QNetworkOperation*)static_QUType_ptr.get(_o+2)); break; case 7: removed((QNetworkOperation*)static_QUType_ptr.get(_o+1)); break; case 8: itemChanged((QNetworkOperation*)static_QUType_ptr.get(_o+1)); break; case 9: dataTransferProgress((int)static_QUType_int.get(_o+1),(int)static_QUType_int.get(_o+2),(QNetworkOperation*)static_QUType_ptr.get(_o+3)); break; default: return QObject::qt_emit(_id,_o); } return TRUE; }
BufferItem *NetworkItem::bufferItem(const BufferInfo &bufferInfo) { BufferItem *bufferItem = findBufferItem(bufferInfo); if (bufferItem) return bufferItem; switch (bufferInfo.type()) { case BufferInfo::StatusBuffer: _statusBufferItem = new StatusBufferItem(bufferInfo, this); bufferItem = _statusBufferItem; disconnect(this, SIGNAL(networkDataChanged(int)), this, SIGNAL(dataChanged(int))); connect(this, SIGNAL(networkDataChanged(int)), bufferItem, SIGNAL(dataChanged(int))); connect(bufferItem, SIGNAL(dataChanged(int)), this, SIGNAL(dataChanged(int))); break; case BufferInfo::ChannelBuffer: bufferItem = new ChannelBufferItem(bufferInfo, this); break; case BufferInfo::QueryBuffer: bufferItem = new QueryBufferItem(bufferInfo, this); break; default: bufferItem = new BufferItem(bufferInfo, this); } newChild(bufferItem); // postprocess... this is necessary because Qt doesn't seem to like adding children which already have children on their own switch (bufferInfo.type()) { case BufferInfo::ChannelBuffer: { ChannelBufferItem *channelBufferItem = static_cast<ChannelBufferItem *>(bufferItem); if (_network) { IrcChannel *ircChannel = _network->ircChannel(bufferInfo.bufferName()); if (ircChannel) channelBufferItem->attachIrcChannel(ircChannel); } } break; default: break; } return bufferItem; }
void ChannelBufferItem::addUsersToCategory(const QList<IrcUser *> &ircUsers) { Q_ASSERT(_ircChannel); QHash<UserCategoryItem *, QList<IrcUser *> > categories; int categoryId = -1; UserCategoryItem *categoryItem = 0; foreach(IrcUser *ircUser, ircUsers) { categoryId = UserCategoryItem::categoryFromModes(_ircChannel->userModes(ircUser)); categoryItem = findCategoryItem(categoryId); if (!categoryItem) { categoryItem = new UserCategoryItem(categoryId, this); categories[categoryItem] = QList<IrcUser *>(); newChild(categoryItem); } categories[categoryItem] << ircUser; }
Tdim dim(char *txt, struct Tgraph * graph) { /* a linewidth mechanism were cool, i.e. automatic braking of the line */ /* baceline should jump current y down, x should be the maximum x of all lines */ /* a flag for linebreak should be placed, containing the y jump size */ /* so that the draw routines know when to add to y and reset x zo 0 */ int i; int len = strlen(txt); /* length of text passed * to parse */ Tdim our; /* the dimensions of our current object */ char *gpos; /* points to the tree node's text */ char *end; PRSDEF K; /* keynumber, result from the * keywordlookup */ our.x = 0; our.y = 1; our.baseline = 0; graph->children = 0; /* at the beginning the tree doesn't have * children. We must first find them */ graph->txt = (char *) malloc(len + 1); /* allocating the same * length is OK. Special * characters in output * are 2 chars * long--shorter than in * the input */ gpos = graph->txt; /* we setup now this pointer */ *gpos = 0; if (*(end=findLineEnd(txt))!='\0') { /* the current level contains one or more line ends */ /* the current level will become aan array of lines */ int nlines=0; char * start=txt; char **lines = (char **) malloc(sizeof(char *)); Tdim out; if (SYNTAX_ERR_FLAG==S_ERR) return out; *gpos = 1; /* See parsedef.h for the keyword * definitions */ gpos++; *gpos = (char) ARRAY; gpos++; *gpos = 0; newChild(graph); graph->down[graph->children - 1]->options = malloc((2)*sizeof(char)); graph->down[graph->children - 1]->options[0] = 'c'; /* default col alignment */ graph->down[graph->children - 1]->options[1] = '\0'; /* default col alignment */ /* count how many lines we have */ while (1) { lines =(char **) realloc(lines,(nlines + 1) * (sizeof(char *))); lines[nlines] = (char *) malloc(end - start + 1); strncpy(lines[nlines], start, end - start); lines[nlines][end - start] = '\0'; /* terminate the string */ nlines++; if (*end=='\0') break; start=end+1; end=findLineEnd(start); } /* fill the array with the lines */ #define Array (graph->down[graph->children-1]) Array->array = malloc(sizeof(Tarray)); Array->array->rows = nlines; Array->array->cols = 1; Array->array->rowy = (int *) calloc(nlines, sizeof(int)); Array->array->colx = (int *) calloc(1, sizeof(int)); for (i = 0; i < nlines; i++) { out = dim(lines[i], newChild(Array)); if (out.x > Array->array->colx[0]) Array->array->colx[0] = out.x; if (out.y > Array->array->rowy[i]) Array->array->rowy[i] = out.y; free(lines[i]); } free(lines); Array->dim.x = 0; Array->dim.x += Array->array->colx[0]; Array->dim.y = 0; for (i = 0; i < nlines; i++) Array->dim.y += Array->array->rowy[i]; Array->dim.y += Array->array->rows - 1; Array->dim.x += Array->array->cols - 1; Array->dim.baseline = Array->dim.y / 2; our.x += Array->dim.x; if (our.baseline < Array->dim.baseline) { our.y += Array->dim.baseline - our.baseline; our.baseline = Array->dim.baseline; } if (our.y < Array->dim.y) our.y = Array->dim.y; #undef Array graph->dim = our; return our; } for (i = 0; i < len; i++) { if(SYNTAX_ERR_FLAG==S_ERR) return our; if ((txt[i] != '\\') && (txt[i] != '_') && (txt[i] != '^')) { our.x++; *gpos = txt[i]; gpos++; *gpos = 0; } else { K = LookupKey(txt + i, Keys); switch (K) { case SUPER: i += dimSuperscript(txt + i, &gpos, &our, graph); break; case SUB: i += dimSubscript(txt + i, &gpos, &our, graph); break; case FRAC: i += dimFrac(txt + i, &gpos, &our, graph); break; case SQRT: i += dimSqrt(txt + i, &gpos, &our, graph); break; case OVERLINE: i += dimOverl(txt + i, &gpos, &our, graph); break; case UNDERLINE: i += dimUnderl(txt + i, &gpos, &our, graph); break; case LIMIT: i += dimLimit(txt + i, &gpos, &our, graph); break; case BRACES: i += dimBrace(txt + i, &gpos, &our, graph); break; case ARRAY: i += dimArray(txt + i, &gpos, &our, graph); break; case TO: i += dimTo(txt + i, &gpos, &our, graph); break; case LEADSTO: i += dimLeadsto(txt + i, &gpos, &our, graph); break; case SUM: i += dimSum(txt + i, &gpos, &our, graph); break; case PROD: i += dimProd(txt + i, &gpos, &our, graph); break; case INT: i += dimInt(txt + i, &gpos, &our, graph); break; case OINT: i += dimOint(txt + i, &gpos, &our, graph); break; case INFTY: strcat(gpos, "oo"); gpos += 2; our.x += 2; i += 5; break; case RCEIL: i += dimRceil(txt + i, &gpos, &our, graph); break; case LCEIL: i += dimLceil(txt + i, &gpos, &our, graph); break; case RFLOOR: i += dimRfloor(txt + i, &gpos, &our, graph); break; case LFLOOR: i += dimLfloor(txt + i, &gpos, &our, graph); break; case ESCAPE: i++; our.x++; *gpos = txt[i]; gpos++; *gpos = 0; break; case ERR: default: fprintf(stderr, "I screwed up in dim, this should never happen!\n"); exit(1); break; } } } graph->dim = our; return our; }
nsresult nsNetscapeProfileMigratorBase::RecursiveCopy(nsIFile* srcDir, nsIFile* destDir) { nsresult rv; bool isDir; rv = srcDir->IsDirectory(&isDir); if (NS_FAILED(rv)) return rv; if (!isDir) return NS_ERROR_INVALID_ARG; bool exists; rv = destDir->Exists(&exists); if (NS_SUCCEEDED(rv) && !exists) rv = destDir->Create(nsIFile::DIRECTORY_TYPE, 0775); if (NS_FAILED(rv)) return rv; bool hasMore = false; nsCOMPtr<nsISimpleEnumerator> dirIterator; rv = srcDir->GetDirectoryEntries(getter_AddRefs(dirIterator)); if (NS_FAILED(rv)) return rv; rv = dirIterator->HasMoreElements(&hasMore); if (NS_FAILED(rv)) return rv; nsCOMPtr<nsIFile> dirEntry; while (hasMore) { rv = dirIterator->GetNext((nsISupports**)getter_AddRefs(dirEntry)); if (NS_SUCCEEDED(rv)) { rv = dirEntry->IsDirectory(&isDir); if (NS_SUCCEEDED(rv)) { if (isDir) { nsCOMPtr<nsIFile> destClone; rv = destDir->Clone(getter_AddRefs(destClone)); if (NS_SUCCEEDED(rv)) { nsCOMPtr<nsILocalFile> newChild(do_QueryInterface(destClone)); nsAutoString leafName; dirEntry->GetLeafName(leafName); newChild->AppendRelativePath(leafName); rv = newChild->Exists(&exists); if (NS_SUCCEEDED(rv) && !exists) rv = newChild->Create(nsIFile::DIRECTORY_TYPE, 0775); rv = RecursiveCopy(dirEntry, newChild); } } else { // we aren't going to do any actual file copying here. Instead, add this to our // file transaction list so we can copy files asynchronously... fileTransactionEntry fileEntry; fileEntry.srcFile = dirEntry; fileEntry.destFile = destDir; mFileCopyTransactions.AppendElement(fileEntry); } } } rv = dirIterator->HasMoreElements(&hasMore); if (NS_FAILED(rv)) return rv; } return rv; }
Node *Node::newChild(){ return newChild(0.0, 0.0, 0.0); }
int dimLimit(char *found, char **Gpos, Tdim * Our, struct Tgraph *graph) /* The dimXxx routines all have the forllowing arguments: found -- Pointer to a sting containing the remaining part of the equation Gpos -- Pointer to a string which will contain the part of the equation relevant to the current parent with flags to indicate which drawing routines to use. Our -- dimention of the parent graph -- The parent The routines returns the number of characters it used of the found vector. */ { #define gpos (*Gpos) #define our (*Our) char *start, *end, *tmp; Tdim out; *gpos = 1; /* See parsedef.h for the keyword * definitions */ gpos++; *gpos = (char) LIMIT; gpos++; *gpos = 0; start = strchr(found, '{'); if (!start) { SyntaxError("Usage: \\limit{X}\n\tProduces a limit\n"); return 0; } end = findClosingBrace(start + 1); if (end - start < 2) { SyntaxError("Usage: \\limit{X}\n\tProduces a limit\n\te.g \\lim{x \\to \\infty}\n"); return 0; } *end = 0; tmp = strdup(start + 1); *end = '}'; out = dim(tmp, newChild(graph)); free(tmp); if (start - found - 6 > 0) SyntaxWarning("Warning: Spurious characters ignored in \\limit\n"); out.baseline = out.y; /* expressison under limit */ out.y++; /* add the line under for the limit text */ if (out.x > 3) our.x += out.x + 1; else our.x += 4; if (our.baseline < out.baseline) { our.y += (out.baseline - our.baseline); our.baseline = out.baseline; } if (our.y - our.baseline < (out.y - out.baseline)) { /* * our.baseline++; */ our.y = (out.y - out.baseline) + our.baseline; } return end - (found); #undef gpos #undef our }
Node *Node::newChild(const float inX, const float inY, const float inZ){ Vec4f position = {inX,inY,inZ,1.0}; return newChild(position); }
// add child (int) void JSONobject::addChild(string key, int value) { // create child JSONchild* child = newChild(key); // assign string to value child->value = boost::lexical_cast<string>(value); }
// add child (string) void JSONobject::addChild(string key, string value) { // create child JSONchild* child = newChild(key); // assign string to value child->value = value; }
void Pathfinding::AddNode( int x, int y, float newGcost, PathNodeSPtr parent, bool isDiagonal, PathNodeVec* openList, PathNodeVec* closedList, PathNodeSPtr endNode) { World* w = TheWorld::Instance(); // ---> check gif in grid boundary if(!w->IsBoundary(x, y)) return; int id = y * w->GetWorldWidth() + x; // check if id is a wall here if(!w->IsPassable(x, y)) return; // ---> check for corner skipping if(isDiagonal) { int px = parent->GetX(); int py = parent->GetY(); // --- top left if((x == px-1) && (y == py-1)) { if(!w->IsPassable(px-1, py)) return; if(!w->IsPassable(px, py-1)) return; } // --- top right if((x == px+1) && (y == py-1)) { if(!w->IsPassable(px+1, py)) return; if(!w->IsPassable(px, py-1)) return; } // --- bot right if((x == px+1) && (y == py+1)) { if(!w->IsPassable(px+1, py)) return; if(!w->IsPassable(px, py+1)) return; } // --- bot left if((x == px-1) && (y == py+1)) { if(!w->IsPassable(px-1, py)) return; if(!w->IsPassable(px, py+1)) return; } } // ---> check if in the closed list // ---> can be optimized? for(auto it = closedList->begin(); it != closedList->end(); it++) { if(id == (*it)->GetID()) { return; } } // ---> check if in the openlist // ---> can be optimized? for(auto it = openList->begin(); it != openList->end(); it++) { if(id == (*it)->GetID()) { if((*it)->GetG() <= newGcost) { return; } else { openList->erase(it); break; } } } PathNodeSPtr newChild(new PathNode(x, y, id, parent)); newChild->SetG(newGcost); newChild->Heuristic(endNode); openList->push_back(newChild); }