void List::Insert(ListNode **after, ListNode **c, Object *ptr) { if(c == NULL || *c == NULL) return; if(after == NULL || *after == NULL) { AddHead(c,ptr); return; } else if(m_bContainer && m_eSort != Nosort) { AddHead(c,ptr); // will add and sort return; } else { (*c)->m_pCurrent = ptr; (*c)->m_pPast = *after; (*c)->m_pNext = (*after)->m_pNext; (*after)->m_pNext = *c; if((*c)->m_pNext != NULL) (*c)->m_pNext->m_pPast = *c; } }
// Add path PathNode *function_add_path(FunctionHandle *handle,PathList *list,Lister *lister,char *path) { PathNode *node; // Allocate node if ((node=AllocMemH(handle->memory,sizeof(PathNode)))) { // Copy path if (path) strcpy(node->path_buf,path); // Store lister pointer node->lister=lister; // Add to path list AddHead((struct List *)list,(struct Node *)node); // Make this the current path list->current=node; // Set appropriate flag if (list==&handle->source_paths) handle->func_flags|=FUNCF_GOT_SOURCE; else handle->func_flags|=FUNCF_GOT_DEST; } return node; }
void CPTRList::InsertBefore( int n,void *pData) { if ( n<0 ) { AddTail(pData); return; } if ( n==0 ) { AddHead(pData); return ; } GetAt(n); nCurrent = -1; PTR_BLK *pNew = new PTR_BLK; pNew->pData = pData; pNew->pPrev = pCur->pPrev; pNew->pNext = pCur; pCur->pPrev->pNext = pNew; pCur->pPrev = pNew; nMax++; }
/* * Slowly load the contents of "List.c" into the * linked list. */ DWORD WINAPI LoadThreadFunc(LPVOID n) { int nBatchCount; Node *pNode; FILE* fp = fopen("List.c", "r"); if (!fp) { fprintf(stderr, "ReadWrit.c not found\n"); exit(EXIT_FAILURE); } pNode = GlobalAlloc(GPTR, sizeof(Node)); nBatchCount = (rand() % 10) + 2; AcquireWriteLock(&gpList->lock); while (fgets(pNode->szBuffer, sizeof(Node), fp)) { AddHead(gpList, pNode); // Try not to hog the lock if (--nBatchCount == 0) { ReleaseWriteLock(&gpList->lock); Sleep(rand() % 5); nBatchCount = (rand() % 10) + 2; AcquireWriteLock(&gpList->lock); } pNode = GlobalAlloc(GPTR, sizeof(Node)); } ReleaseWriteLock(&gpList->lock); return 0; }
// Compile function list into function void funced_compile(FuncEdData *data) { FunctionEntry *entry; Cfg_Instruction *ins; Att_Node *node; // Free existing instructions FreeInstructionList(data->function); // Got a label? if (data->label[0]) { // Create label instruction if ((ins=NewInstruction(0,INST_LABEL,data->label))) AddHead((struct List *)&data->function->instructions,(struct Node *)ins); } // Go through instructions for (node=(Att_Node *)data->function_list->list.lh_Head; node->node.ln_Succ; node=(Att_Node *)node->node.ln_Succ) { // Get function entry entry=(FunctionEntry *)node->data; // Create a new instruction if ((ins=NewInstruction(0,entry->type,entry->buffer))) { // Add to function list AddTail((struct List *)&data->function->instructions,(struct Node *)ins); } } }
FILE *fdopen(int filedes,const char *mode) { extern int _lx_addflags(int,int); if (mode!=NULL) { struct filenode *node = (struct filenode *)calloc(1,sizeof(*node)); if(node!=NULL) { if((node->FILE.buffer=(char *)malloc(BUFSIZ))!=NULL) { node->FILE.bufsize=BUFSIZ; node->FILE.file=filedes; node->FILE.flags|=__SMBF; /* Buffer is malloc'ed */ if(isatty(filedes)) node->FILE.flags|=__SLBF; /* set linebuffered flag */ if(_lx_addflags(filedes,*mode=='a'?O_APPEND:0)&O_WRONLY) node->FILE.flags|=__SWO; /* set write-only flag */ AddHead((struct List *)&__filelist,(struct Node *)&node->node); return &node->FILE; } else errno=ENOMEM; free(node); } else errno=ENOMEM; } return NULL; }
POSITION CPtrList::InsertBefore(POSITION position, void* newElement) { ASSERT_VALID(this); if (position == NULL) return AddHead(newElement); // insert before nothing -> head of the list // Insert it before position CNode* pOldNode = (CNode*) position; CNode* pNewNode = NewNode(pOldNode->pPrev, pOldNode); pNewNode->data = newElement; if (pOldNode->pPrev != NULL) { ASSERT(AfxIsValidAddress(pOldNode->pPrev, sizeof(CNode))); pOldNode->pPrev->pNext = pNewNode; } else { ASSERT(pOldNode == m_pNodeHead); m_pNodeHead = pNewNode; } pOldNode->pPrev = pNewNode; return (POSITION) pNewNode; }
BOOL pkt_init(void) { packet_t *p; int i; UBYTE *pkt_data; /* allocate packets with nodes for tx and rx queue */ int totalPkt = tx_pkt_size + rx_pkt_size; pkts_size = totalPkt * sizeof(packet_t); pkts = (packet_t *)AllocMem(pkts_size, MEMF_CLEAR); if(pkts == NULL) { return FALSE; } /* allocate packet data for rx packets */ rx_pkt_data_size = rx_pkt_size * max_pkt_size; rx_pkt_data = (UBYTE *)AllocMem(rx_pkt_data_size, MEMF_CLEAR); if(rx_pkt_data == NULL) { return FALSE; } NewList(&tx_free); NewList(&rx_free); InitSemaphore(&tx_sem); InitSemaphore(&rx_sem); /* init tx queue packets and insert them into free list */ p = pkts; for(i=0;i<tx_pkt_size;i++) { AddHead(&tx_free, &p->p_Node); p++; } /* init rx queue packets and insert them into free list store the pre-allocated buffer as */ pkt_data = rx_pkt_data; for(i=0;i<rx_pkt_size;i++) { AddHead(&rx_free, &p->p_Node); p->p_OwnBuffer = pkt_data; p->p_OwnBufferSize = max_pkt_size; pkt_data += max_pkt_size; p++; } return TRUE; }
void moveInfoFree( MoveInfo *theMoveInfo ) { Move *aMove; while( aMove = ( Move * )RemHead( &theMoveInfo->mi_Moves )) moveFree( aMove ); AddHead( &FreeMoveInfos, ( struct Node * )theMoveInfo ); }
//--------------------------------------------------------------------------- // 인 수: pNewList:다른 리스트 | // 반환값: 없음 | // 설 명: 다른 리스트의 Tail값을 리스트의 Head에 삽입한다. | //--------------------------------------------------------------------------- void CVoidList::AddHead(CVoidList* pNewList) { if (pNewList == NULL) return; // add a list of same elements to head (maintain order) POSITION_ pos = pNewList->GetTailPosition(); while (pos != NULL) AddHead(pNewList->GetPrev(pos)); }
void CRecentFuncList::AddFunc(CFunc func) { POSITION rPos = GetHeadPosition(); while (rPos) { POSITION pos = rPos; if (GetNext(rPos) == func) RemoveAt(pos); } AddHead(func); if (GetCount() > m_MaxSize) RemoveTail(); }
void Imagemap::AddRectangle(DocRect rectToAdd, TCHAR* pcURL, TCHAR* pcFrame) { //Create a new ImagemapClickableRectangle with the rectangle we've been given ImagemapClickableRectangle* pRectangle=new ImagemapClickableRectangle(rectToAdd, pcURL, pcFrame); //And add it to the imagemap //Note that we add it to the head of the list. That's because, in imagemaps, //the first clickable area found in the file is the one nearest the front. AddHead(pRectangle); }
void Imagemap::AddPolygon(Path* pthToAdd, TCHAR* pcURL, TCHAR* pcFrame) { //Create a new ImagemapClickableCircle with the path we've been given ImagemapClickablePolygon* pPolygon=new ImagemapClickablePolygon(pthToAdd, pcURL, pcFrame); //And add it to the imagemap //Note that we add it to the head of the list. That's because, in imagemaps, //the first clickable area found in the file is the one nearest the front. AddHead(pPolygon); }
void Imagemap::AddCircle(Path* pthToAdd, TCHAR* pcURL, TCHAR* pcFrame) { //Create a new ImagemapClickableCircle with our scaled path ImagemapClickableCircle* pCircle=new ImagemapClickableCircle(pthToAdd, pcURL, pcFrame); //And add it to the imagemap //Note that we add it to the head of the list. That's because, in imagemaps, //the first clickable area found in the file is the one nearest the front. AddHead(pCircle); }
/* this function puts the packet back on the message list of our * message port. */ VOID AS_RequeuePacket( AsyncFile *file ) { #ifdef ASIO_NOEXTERNALS struct ExecBase *SysBase = file->af_SysBase; #endif AddHead( &file->af_PacketPort.mp_MsgList, &file->af_Packet.sp_Msg.mn_Node ); file->af_PacketPending = TRUE; }
ListNode * List::AddSorted(Object *ptr) { ListNode *n; if(m_eSort == Ascending) n= AddHead(ptr); else n= AddTail(ptr); if(m_bContainer) Sort(); return n; }
template <class Type> LISTNODE List<Type>::AddSorted(const Type &item, LPVOID pfn) { ListNode<Type> *pNode = NULL; LISTNODE pCurrNode = NULL; LISTNODE pPrevNode = NULL; int i; Type curItem; LONG (*pFN) (const Type item1, const Type item2); pFN = (LONG (*) (const Type item1, const Type item2))pfn; if(_pHead == NULL) { return AddHead(item); } else { pCurrNode = GetHeadPosition(); curItem = ((ListNode<Type> *) pCurrNode)->GetItem(); for (i = 0; i < _iCount; i++) { if (pFN(item, curItem) < 1) { NEW_CONSTR(pNode, ListNode<Type>(item)); if (pNode) { pNode->SetPrev((ListNode<Type> *)pPrevNode); pNode->SetNext((ListNode<Type> *)pCurrNode); // update pPrevNode if(pPrevNode) { ((ListNode<Type> *)pPrevNode)->SetNext(pNode); } else { _pHead = pNode; } // update pCurrNode ((ListNode<Type> *)pCurrNode)->SetPrev(pNode); _iCount++; } break; } pPrevNode = pCurrNode; GetNext(pCurrNode); if(i+1 == _iCount) { return AddTail(item); } else { _ASSERTE(pCurrNode); curItem = GetAt(pCurrNode); } } } return (LISTNODE)pNode; }
void CStringList::AddHead(CStringList* pNewList) { ASSERT_VALID(this); ASSERT(pNewList != NULL); ASSERT(pNewList->IsKindOf(RUNTIME_CLASS(CStringList))); ASSERT_VALID(pNewList); // add a list of same elements to head (maintain order) POSITION pos = pNewList->GetTailPosition(); while (pos != NULL) AddHead(pNewList->GetPrev(pos)); }
LIterator LStrList::AddHead(__in PCWSTR lpString) { LAutoLock al(m_lock); if (IsUnicode()) { LPtrList::AddHead(&lpString); } else { LStringA str = lpString; AddHead(str); } return m_itHead; }
bool CDVDPositionList::AddEntry(ULONGLONG llDVDGuid) { // Look for the file position POSITION pos = GetHeadPosition(); while (pos) { DVD_POSITION& dvdPosition = GetAt(pos); // If we find it, we move it at the top of the list if (dvdPosition.llDVDGuid == llDVDGuid) { if (pos != GetHeadPosition()) { AddHead(dvdPosition); RemoveAt(pos); // Save asynchronously the list SaveAsync(); } return false; } GetNext(pos); } // Add the new position DVD_POSITION dvdPosition = { llDVDGuid, 0, 0 }; AddHead(dvdPosition); // Ensure the list doesn't grow indefinitely if (GetCount() > m_nMaxSize) { RemoveTail(); } // Save asynchronously the list SaveAsync(); return true; }
bool CFilePositionList::AddEntry(LPCTSTR lpszFileName) { // Look for the file position POSITION pos = GetHeadPosition(); while (pos) { FILE_POSITION& filePosition = GetAt(pos); // If we find it, we move it at the top of the list if (filePosition.strFile == lpszFileName) { if (pos != GetHeadPosition()) { AddHead(filePosition); RemoveAt(pos); // Save asynchronously the list SaveAsync(); } return false; } GetNext(pos); } // Add the new position FILE_POSITION filePosition = { lpszFileName, 0 }; AddHead(filePosition); // Ensure the list doesn't grow indefinitely if (GetCount() > m_nMaxSize) { RemoveTail(); } // Save asynchronously the list SaveAsync(); return true; }
int main(int argc, char *argv[]) { char *dpyName = NULL; int i; if (argc == 1) { printf("manywin: open N simultaneous glx windows\n"); printf("Usage:\n"); printf(" manywin [-s] numWindows\n"); printf("Options:\n"); printf(" -s = swap immediately after drawing (see src code)\n"); printf("Example:\n"); printf(" manywin 10\n"); return 0; } else { int n = 3; for (i = 1; i < argc; i++) { if (strcmp(argv[i], "-s") == 0) { SwapSeparate = GL_FALSE; } else if (strcmp(argv[i], "-display") == 0 && i < argc) { dpyName = argv[i+1]; i++; } else { n = atoi(argv[i]); } } if (n < 1) n = 1; printf("%d windows\n", n); for (i = 0; i < n; i++) { char name[100]; struct head *h; sprintf(name, "%d", i); h = AddHead(dpyName, name); if (h) { PrintInfo(h); } } } EventLoop(); DestroyHeads(); return 0; }
BOOL Insert(List *pList, Node *afterNode, Node *newNode) { if (!WriteOK(&pList->lock)) return FatalError("Insert - not allowed to write!"); if (afterNode == NULL) { AddHead(pList, newNode); } else { newNode->pNext = afterNode->pNext; afterNode->pNext = newNode; } }
void CPtrList::AddHead(CPtrList* pNewList) { ASSERT_VALID(this); ASSERT_VALID(pNewList); if (pNewList == NULL) { AfxThrowInvalidArgException(); } ASSERT_KINDOF(CPtrList, pNewList); // add a list of same elements to head (maintain order) POSITION pos = pNewList->GetTailPosition(); while (pos != NULL) AddHead(pNewList->GetPrev(pos)); }
/******************************************************************************************************** Function: SetData Description: 设置数据 Protocol: Input: Output: *********************************************************************************************************/ int MHttp::SetData(char* pOutBuf,int nSize,char* szQlData, int nQlDataSize) { char *pS = ": "; int nHeadEnd; char szTmp[10]; sprintf(szTmp,"%d",nQlDataSize); AddHead(pOutBuf, nSize, "Content-Length", szTmp); strcat(pOutBuf, "\r\n\r\n"); //头结束 nHeadEnd = strlen(pOutBuf); memcpy(pOutBuf+nHeadEnd, szQlData, nQlDataSize); nHeadEnd += nQlDataSize; memcpy(pOutBuf+nHeadEnd , "\r\n\r\n", 4); pOutBuf[nHeadEnd+4] = 0; return nHeadEnd+4; }
void CPTRList::InsertBefore( void *pData) { if ( pCur==pTop ) { AddHead(pData); return ; } PTR_BLK *pNew = new PTR_BLK; pNew->pData = pData; pNew->pPrev = pCur->pPrev; pNew->pNext = pCur; pCur->pPrev->pNext = pNew; pCur->pPrev = pNew; nMax++; }
void CRunLog::WriteRunLog(const char *shm,...) { char buffer[MAX_LINE_SIZE]; va_list sp; AddHead(buffer); va_start(sp,shm); vsnprintf(buffer+strlen(buffer),MAX_LINE_SIZE - strlen(buffer),shm,sp); va_end(sp); strcat(buffer,"\n"); buffer[MAX_LINE_SIZE - 2] = '\n'; if (GetFileSize(this->LogFile) > this->FileSize) ResetFile(); if (NULL == fp) OpenFile(); WriteContent(buffer); }
/** * * thread = newthread(debug, id); * * Create a new thread. * **/ PUBLIC THREAD *newthread(DEBUG *debug, int id) { THREAD *thread; WINDOW *window; if ((window = wopen(debug->display)) == NULL) return NULL; thread = NEW(THREAD); thread->id = id; thread->loc.module = NULL; thread->loc.line = 0; thread->block = NULL; thread->function = NULL; thread->window = window; InitSemaphore(&thread->sync, 0); /* ACE: Not sure about this */ if (debug->threadlist.Head->Next == NULL) debug->thread = thread; AddHead(&debug->threadlist, &thread->node); return thread; }
static char *arg_fillbuf(){ char *p,*nlp;; if(ListEmpty(flist)){ if(++a_apos>a_argc)return(0); p=a_argv[a_apos]; }else{ struct fentry *f=(struct fentry *)ListHead(flist); if(!f->ptr){ do{ if(!fgets(f->buf,ARGLEN,f->fp)){ if(ferror(f->fp)){ fprintf(stderr, "I/O error on @file\n"); return(0); } fclose(f->fp); RemHead(&flist); free(f); return(arg_fillbuf()); } }while(f->buf[0]=='#'); /* comment */ if(nlp=strchr(f->buf,'\n'))*nlp='\0'; } p=splitline(f); if(p== (char *)-1)return(0); /* error */ if(!p)return(arg_fillbuf()); /* skip blank line */ } if(p && *p=='@'){ struct fentry *f=calloc(sizeof(struct fentry),1); f->fp=fopen(++p,"r"); if(!(f->fp)){ fprintf(stderr,"Can't open @file '%s'\n",p); free(f); return(0); } AddHead(&flist,(struct Node *)f); return(arg_fillbuf()); } return(p); }
/* Makes a copy of a list */ struct List *CpyList(int ListSize, int NodeSize, const struct List *List, const char *Name) { struct List *Copy; struct Node *Node, *NewNode; Copy=(struct List *)malloc(ListSize); if (Copy==NULL) return(NULL); memcpy(Copy,List,ListSize); InitList(Copy); if (Name!=CL_CPY_NAME) strncpy(Copy->Head.Name,Name,NODE_NAME_LENGTH); for(Node=(struct Node *)List->Head.Succ; Node!=&(List->Tail); Node=Node->Succ) { NewNode=CpyNode(NodeSize,Node,CN_CPY_NAME); if (NewNode==NULL) { FreeList(Copy); return(NULL); }; AddHead((*Copy),NewNode); }; return(Copy); }