static void test_lstDel(t_test *test) { t_info *info; int i; int result; char str[] = " mamie mange de la compote"; test->debug = 1; i = 0; result = 0; int j; j = 0; info = (t_info *)malloc(sizeof(t_info)); info->term = NULL; info = ft_init(info); while (str[j] != '\0') info->term = lstAdd(info->term, str[j++]); while (info->term) { if (info->term->c != str[i++]) result = 1; info->term = info->term->next; } mt_assert((result == 0 ? 1 : 0)); free_list(info); }
void displayAddPatientForm(struct Page* p, void* args) { Bool valid = False; struct Patient* pat = (struct Patient*) allocatePatient(); struct FormEntry* entry = (struct FormEntry*) lstGet(p->form->entries,0); // update fields values strcpy(entry->field, " "); entry = (struct FormEntry*) lstGet(p->form->entries, 1); strcpy(entry->field, " "); entry = (struct FormEntry*) lstGet(p->form->entries, 2); strcpy(entry->field, " "); while(!valid) { frmDisplay(p->form); // get form data entry = (struct FormEntry*) lstGet(p->form->entries, 0); strcpy(pat->name, entry->field); entry = (struct FormEntry*) lstGet(p->form->entries, 1); strcpy(pat->surname, entry->field); entry = (struct FormEntry*) lstGet(p->form->entries, 2); strcpy(pat->tel, entry->field); valid = validateNewPatForm(pat); } struct Patient* lastPatient = (struct Patient*) lstGetLastElement(gPatients)->data; pat->id = lastPatient->id + 1; lstAdd(gPatients, pat); }
void wdAddPolygon(World* W, Polygon* P) { lstAdd(&W->Polygons, P); /* Ajout du centre si nécessaire */ if(polyGetCenter(P) != NULL) wdAddVertex(W, polyGetCenter(P)); }
/*-------------------------- Implementation------------------------------*/ void mnuAddEntry(struct Menu *mnu, const char *text, const char *helpText, Bool (*exec)(char *)) { struct MenuEntry* mnuEntry = (struct MenuEntry*) malloc( sizeof(struct MenuEntry)); mnuEntry->exec = exec; strcpy(mnuEntry->helpText, helpText); strcpy(mnuEntry->text, text); lstAdd(mnu->menuEntries, mnuEntry); }
/*lint -e429*/ BST_VOID BST_CTaskSchdler::Attach ( BST_CORE_CPTask *pC_PTask ) { BST_CORE_PTASK_NODE_STRU *pstPtaskNode; if ( !BST_OS_IsTimerValid (m_ulTimerId) ) { BST_RLS_LOG1( "BST_CTaskSchdler::Attach m_ulTimerId=%u is invalid", m_ulTimerId ); return; } if ( BST_NULL_PTR == pC_PTask ) { BST_RLS_LOG( "BST_CTaskSchdler::Attach pC_PTask=NULL" ); return; } for ( pstPtaskNode = (BST_CORE_PTASK_NODE_STRU *)lstFirst( &g_stPTaskList ); pstPtaskNode!= BST_NULL_PTR; pstPtaskNode = (BST_CORE_PTASK_NODE_STRU *)lstNext((NODE *)pstPtaskNode) ) { if( pstPtaskNode->pcTask == pC_PTask ) { return; } } /* * 申请链表节点资源,用于存储任务 */ pstPtaskNode = ( BST_CORE_PTASK_NODE_STRU *)BST_OS_MALLOC ( BST_OS_SIZEOF( BST_CORE_PTASK_NODE_STRU ) ); if( BST_NULL_PTR == pstPtaskNode ) { BST_RLS_LOG( "BST_CTaskSchdler::Attach pstPtaskNode=NULL" ); return; } /* * 初始化任务数据,添加如任务列表 */ pC_PTask->m_ulSuspCounter = 0; pstPtaskNode->pcTask = pC_PTask; lstAdd( &g_stPTaskList, (NODE *)pstPtaskNode ); /* * 如果此时系统TICK定时已经关闭,且PS域服务状态正常,那么需要再次启动定时 */ if( BST_TRUE == BST_OS_TimerIsStop( m_ulTimerId ) ) { m_ulSystemTick = 0; BST_OS_TimerStart ( m_ulTimerId, BST_TASK_SYS_BASE_TIMELEN ); BST_DBG_LOG1( "BST_CTaskSchdler::Attach Start Scheduler Timer:%u", BST_TASK_SYS_BASE_TIMELEN ); } }
Object* cpyObject(Object* O) { List CT; lstInit(&CT); Node* it = lstFirst(&O->CoordTex); while(!nodeEnd(it)) { Vec2* CoordTex = newVec2(); vec2Cp(CoordTex, *((Vec2*) nodeGetData(it))); lstAdd(&CT, CoordTex); it = nodeGetNext(it); } return newObject(cpyPolygon(O->Shape), O->Tex, CT); }
static void test_lstLast_null(t_test *test) { char *tab_c = ""; t_info *info; int i = 0; info = (t_info *)malloc(sizeof(t_info)); info->term = NULL; info = ft_init(info); while (tab_c[i]) info->term = lstAdd(info->term, tab_c[i++]); mt_assert((!lstLast(info->term) ? 1 : 0)); free_list(info); }
static void test_lstLast_simple(t_test *test) { char *tab_c = "abcdefghijklmnopqrstuvwxyz"; t_info *info; int i = 0; info = (t_info *)malloc(sizeof(t_info)); info->term = NULL; info = ft_init(info); while (tab_c[i]) info->term = lstAdd(info->term, tab_c[i++]); mt_assert((lstLast(info->term)->c == 'z' ? 1 : 0)); free_list(info); }
t_info *create_list(void) { t_info *info; int i; char str[] = " mamie mange de la compote"; i = 0; info = (t_info *)malloc(sizeof(t_info)); info->term = NULL; info = ft_init(info); while (str[i] != '\0') info->term = lstAdd(info->term, str[i++]); return (info); }
struct List* getUnwarnedAppointements(Int32 patId) { struct List* retVal = lstCreate(gAppointments->_allocateData, gAppointments->_printData, gAppointments->_cloneData); struct List* uwApts = lstFilter(gAppointments,NULL, &isUnwarned); struct ListNode* n = uwApts->rootNode; while( n != NULL ) { struct Appointment* apt = (struct Appointment*) n->data; // ajouter le rdv si le patient n'a pas déjà été ajouté if(apt->fk_pat == patId ) lstAdd(retVal, retVal->_cloneData(apt)); n = n->next; } lstDestroy(uwApts); return retVal; }
BST_VOID BST_SYS_MntnAddTask( BST_UINT16 usType, BST_UINT16 usTaskId ) { BST_SYS_MNTN_APP_NODE_STRU *pstAppInfoNode; BST_OS_LOCKCNT_T tThreadLockCnt; if ( !BST_SYS_MNTN_IsMntnInited() ) { return; } if ( (BST_UINT32)BST_SYS_MNTN_GetAppNumber() >= BST_SYS_MNTN_MAX_APP_NUMBER ) { return; } tThreadLockCnt = BST_OS_ThreadLock(); if ( BST_NULL_PTR != BST_SYS_MntnSrchAppByTask( usType, usTaskId ) ) { BST_OS_ThreadUnLock( tThreadLockCnt ); return; } pstAppInfoNode = ( BST_SYS_MNTN_APP_NODE_STRU *)BST_OS_MALLOC ( BST_OS_SIZEOF(BST_SYS_MNTN_APP_NODE_STRU) ); if ( BST_NULL_PTR == pstAppInfoNode ) { BST_OS_ThreadUnLock( tThreadLockCnt ); return; } BST_OS_MEMSET( &(pstAppInfoNode->stAppInfo), 0, BST_OS_SIZEOF(OM_BST_APP_INFO_STRU) ); pstAppInfoNode->stAppInfo.usAppType = usType; pstAppInfoNode->stAppInfo.usTaskId = usTaskId; lstAdd( BST_SYS_MNTN_GetAppListHead(), (NODE *)pstAppInfoNode ); BST_RLS_LOG3( "[Mntn] Add Task: TypeId=, TaskId=, Total=", usType, usTaskId, BST_SYS_MNTN_GetAppNumber() ); BST_SYS_MntnChangedInd(); BST_OS_ThreadUnLock( tThreadLockCnt ); /*lint -e429*/ }
Polygon* cpyPolygon(Polygon* P) { unsigned int i; Polygon* newP; List* vxList = newList(); // Copie des Vertices for(i = 0; i < polyGetVxCount(P); i++) { lstAdd(vxList, cpyVertex(polyGetVertex(P, i))); } // Cas N-Gone if(polyGetCenter(P) != NULL) { newP = polyNGone(*vxList); const DynArr* vxDA = polyGetVertexDA(P); // Ajout des Internals non lié au centre for(i = 0; i < polyGetInternalRdCount(P); i++) { // Si relié au center, ce sera toujours le deuxième vertice (voir constructeur de N-Gone) if(rdGetV2(polyGetInternalRigid(P, i)) != polyGetCenter(P)) polyAddInternal(newP, daGetID(vxDA, rdGetV1(polyGetInternalRigid(P, i))), daGetID(vxDA, rdGetV2(polyGetInternalRigid(P, i))), -1); } } else { // Cas classique newP = newPolygonL(*vxList); const DynArr* vxDA = polyGetVertexDA(P); for(i = 0; i < polyGetInternalRdCount(P); i++) { polyAddInternal(newP, daGetID(vxDA, rdGetV1(polyGetInternalRigid(P, i))), daGetID(vxDA, rdGetV2(polyGetInternalRigid(P, i))), -1); } } newP->Fixed = polyIsFixed(P); delList(vxList); return newP; }
static void test_lstMove(t_test *test) { char tab_c[] = "abcdefghijklmnopqrstuvwxyz"; t_info *info; t_term *begin; int i = 0; info = (t_info *)malloc(sizeof(t_info)); info->term = NULL; info = ft_init(info); while (tab_c[i]) info->term = lstAdd(info->term, tab_c[i++]); // Test default cursor begin = info->term; while (begin && !begin->cursor) begin = begin->next; mt_assert((begin->c == 'z' ? 1 : 0)); // Test left simple begin = info->term; begin = lstMove(begin, 'l'); while (begin && !begin->cursor) begin = begin->next; mt_assert((begin->c == 'y' ? 1 : 0)); begin = lstMove(begin, 'r'); // Test left right begin = info->term; begin = lstMove(begin, 'l'); begin = lstMove(begin, 'r'); while (begin && !begin->cursor) begin = begin->next; mt_assert((begin->c == 'z' ? 1 : 0)); // Test right simple begin = info->term; begin = lstMove(begin, 'r'); while (begin && !begin->cursor) begin = begin->next; free_list(info); }
//lint -sem(lstAdd,custodial(2)) BST_ERR_ENUM_UINT8 BST_OS_SendMail( BST_OS_MBX_T *pstMbx, BST_VOID *pMsg ) { BST_OS_MAIL_T *pstContent; BST_OS_LOCKCNT_T tThreadLockCnt; BST_ASSERT_NULL_RTN( pstMbx, BST_ERR_INVALID_PTR ); BST_ASSERT_NULL_RTN( pstMbx->hSem, BST_ERR_INVALID_PTR ); pstContent = BST_OS_MALLOC( BST_OS_SIZEOF(BST_OS_MAIL_T) ); BST_ASSERT_NULL_RTN( pstContent, BST_ERR_NO_MEMORY ); tThreadLockCnt = (BST_OS_LOCKCNT_T)BST_OS_SpinLock( &g_MboxLock ); pstContent->ulContent = pMsg; lstAdd( &pstMbx->hList, ( NODE * )pstContent ); BST_OS_SpinUnLock( &g_MboxLock,(BST_UINT32)tThreadLockCnt ); BST_OS_SendSem( pstMbx->hSem ); return( BST_NO_ERROR_MSG ); }
STATUS etherOutputHookAdd ( FUNCPTR outputHook /* routine to receive Ethernet output */ ) { HOOK_ENTRY *pHookEnt; pHookEnt = malloc(sizeof(HOOK_ENTRY)); if (pHookEnt == NULL) return (ERROR); if (etherOutputHookRtn == NULL) { etherOutputHookRtn = etherOutputHook; lstInit(&outputHookList); } pHookEnt->routine = outputHook; lstAdd(&outputHookList, &pHookEnt->node); return (OK); }
void initPatients() { Bool status = False; gPatients = lstCreate(&allocatePatient, &printPatient, &clonePatient); status = lstDeserialize(gPatients, sizeof(struct Patient), FILE_PATIENTS); if(status == False || lstIsEmpty(gPatients)) { // initialisation à partir des structures hardcodées Uint8 cpt; for(cpt = 0; cpt < NB_DEF_PATIENTS; ++cpt) { struct Patient* pat = (struct Patient*) allocatePatient(); *pat = DEFAULT_PATIENTS[cpt]; lstAdd(gPatients, (void*) pat); } } }
struct List* getUnwarnedPatients() { struct List* retVal = lstCreate(gPatients->_allocateData, gPatients->_printData, gPatients->_cloneData); struct List* uwApts = lstFilter(gAppointments,NULL, &isUnwarned); struct ListNode* n = uwApts->rootNode; while( n != NULL ) { struct Appointment* apt = (struct Appointment*) n->data; // ajouter le rdv si le patient n'a pas déjà été ajouté struct Patient* found = (struct Patient*) lstFind(retVal, &apt->fk_pat, &checkPatientId); struct Patient* toAdd = (struct Patient*) lstFind(gPatients, &apt->fk_pat, &checkPatientId); if(!found) lstAdd(retVal, retVal->_cloneData(toAdd)); n = n->next; } lstDestroy(uwApts); return retVal; }
int etherMultiAdd ( LIST *pList, /* pointer to list of multicast addresses */ char* pAddress /* address you want to add to list */ ) { ETHER_MULTI* pCurr; /* * Verify that we have valid Ethernet multicast addresses. */ if ((pAddress[0] & 0x01) != 1) { if (etherMultiDebug) logMsg("Invalid address!\n", 1, 2, 3, 4, 5, 6); return (EINVAL); } /* * See if the address range is already in the list. */ for (pCurr = (ETHER_MULTI *)lstFirst(pList); pCurr != NULL && (bcmp(pCurr->addr, pAddress, 6) != 0); pCurr = (ETHER_MULTI *)lstNext(&pCurr->node)); if (pCurr != NULL) { /* * Found it; just increment the reference count. */ if (etherMultiDebug) logMsg("Address already exists!\n", 1, 2, 3, 4, 5, 6); ++pCurr->refcount; return (0); } /* * New address or range; malloc a new multicast record * and link it into the interface's multicast list. */ pCurr = (ETHER_MULTI *) KHEAP_ALLOC(sizeof(ETHER_MULTI)); if (pCurr == NULL) { if (etherMultiDebug) logMsg("Cannot allocate memory!\n", 1, 2, 3, 4, 5, 6); return (ENOBUFS); } bcopy((char *)pAddress, (char *)pCurr->addr, 6); pCurr->refcount = 1; lstAdd(pList, &pCurr->node); if (etherMultiDebug) { logMsg("Added address is %x:%x:%x:%x:%x:%x\n", pCurr->addr[0], pCurr->addr[1], pCurr->addr[2], pCurr->addr[3], pCurr->addr[4], pCurr->addr[5]); } /* * Return ENETRESET to inform the driver that the list has changed * and its reception filter should be adjusted accordingly. */ return (ENETRESET); }
STATUS etherInputHookAdd ( FUNCPTR inputHook, /* routine to receive Ethernet input */ char* pName, /* name of device if MUX/END is being used */ int unit /* unit of device if MUX/END is being used */ ) { HOOK_ENTRY *pHookEnt; HOOK_ENTRY *pHookCurr; void * pBinding = NULL; /* Existing END device binding, if any. */ BOOL tkDevice=FALSE; if (pName != NULL) /* We are dealing with an END. */ { if (etherInputHookActive == FALSE) /* First END driver hook? */ { if (etherInputHookRtn == NULL) { /* Initialize list - first network driver of either type. */ lstInit (&inputHookList); } etherInputHookActive = TRUE; } /* Check if bind is necessary and eliminate duplicate hook routine. */ for (pHookCurr = (HOOK_ENTRY *)lstFirst(&inputHookList); pHookCurr != NULL; pHookCurr = (HOOK_ENTRY *)lstNext(&pHookCurr->node)) { /* Ignore BSD device hook entries. */ if (pHookCurr->pCookie == NULL) continue; if (STREQ(pHookCurr->name, pName) && (pHookCurr->unit == unit)) { if (pHookCurr->routine == inputHook) return (ERROR); /* Additional hook for same device - reuse binding. */ pBinding = pHookCurr->pCookie; } } pHookEnt = malloc (sizeof (HOOK_ENTRY)); if (pHookEnt == NULL) return (ERROR); bzero ( (char *)pHookEnt, sizeof (HOOK_ENTRY)); if (pBinding == NULL) /* No hook entry for this END device? */ { /* Attach Ethernet input hook handler for this device. */ tkDevice = muxTkDrvCheck (pName); if (tkDevice) { pBinding = muxTkBind (pName, unit, nptEtherInputHookRtn, NULL, NULL, NULL, MUX_PROTO_SNARF, "etherInputHook", pHookEnt, NULL, NULL); } else { pBinding = muxBind (pName, unit, endEtherInputHookRtn, NULL, NULL, NULL, MUX_PROTO_SNARF, "etherInputHook", pHookEnt); } if (pBinding == NULL) { free (pHookEnt); return (ERROR); } } /* * Assign (new or existing) handler attachment for the device, * allowing hook deletion in any order. */ pHookEnt->pCookie = pBinding; strcpy (pHookEnt->name, pName); pHookEnt->unit = unit; pHookEnt->routine = inputHook; lstAdd (&inputHookList, &pHookEnt->node); } else /* Old style driver. */ { /* Check for duplicate hook routine. */ for (pHookCurr = (HOOK_ENTRY *)lstFirst(&inputHookList); pHookCurr != NULL; pHookCurr = (HOOK_ENTRY *)lstNext(&pHookCurr->node)) { if (pHookCurr->pCookie) /* Ignore END device hook entries. */ continue; if (pHookCurr->routine == inputHook) return (ERROR); } pHookEnt = malloc(sizeof(HOOK_ENTRY)); if (pHookEnt == NULL) return (ERROR); bzero ( (char *)pHookEnt, sizeof (HOOK_ENTRY)); if (etherInputHookRtn == NULL) /* First BSD driver hook? */ { etherInputHookRtn = etherInputHook; if (!etherInputHookActive) { /* Initialize list - first network driver of either type. */ lstInit (&inputHookList); } } pHookEnt->routine = inputHook; lstAdd(&inputHookList, &pHookEnt->node); } return (OK); }
void wdAddElastic(World* W, Elastic* E) { lstAdd(&W->Elastics, E); }
void wdAddRigid(World* W, Rigid* R) { lstAdd(&W->Rigids, R); }
void wdAddVertex(World* W, Vertex* V) { lstAdd(&W->Vertices, V); }
} /*********************************************************************************************************************************** Internal add -- the string must have been created in the list's mem context before being passed ***********************************************************************************************************************************/ static StringList * strLstAddInternal(StringList *this, String *string) { FUNCTION_TEST_BEGIN(); FUNCTION_TEST_PARAM(STRING_LIST, this); FUNCTION_TEST_PARAM(STRING, string); FUNCTION_TEST_END(); ASSERT(this != NULL); FUNCTION_TEST_RETURN((StringList *)lstAdd((List *)this, &string)); } /*********************************************************************************************************************************** Internal insert -- the string must have been created in the list's mem context before being passed ***********************************************************************************************************************************/ static StringList * strLstInsertInternal(StringList *this, unsigned int listIdx, String *string) { FUNCTION_TEST_BEGIN(); FUNCTION_TEST_PARAM(STRING_LIST, this); FUNCTION_TEST_PARAM(UINT, listIdx); FUNCTION_TEST_PARAM(STRING, string); FUNCTION_TEST_END(); ASSERT(this != NULL);
STATUS hostAdd ( char *hostName, /* host name */ char *hostAddr /* host addr in standard Internet format */ ) { HOSTNAME *pHostNamePrev = NULL; /* pointer to previous host name entry */ FAST HOSTNAME *pHostName; /* pointer to host name entry */ FAST HOSTENTRY *pHostEntry; struct in_addr netAddr; /* network address */ if (hostName == NULL || hostAddr == NULL) { errnoSet (S_hostLib_INVALID_PARAMETER); return (ERROR); } if ((netAddr.s_addr = inet_addr (hostAddr)) == ERROR) return (ERROR); if (semTake (hostListSem, WAIT_FOREVER) == ERROR) return (ERROR); for (pHostEntry = (HOSTENTRY *)lstFirst (&hostList); pHostEntry != NULL; pHostEntry = (HOSTENTRY *)lstNext (&pHostEntry->node)) { if (pHostEntry->netAddr.s_addr == netAddr.s_addr) { /* host internet address already in table, add name as an alias */ pHostNamePrev = &pHostEntry->hostName; for (pHostName = &pHostEntry->hostName; pHostName != NULL; pHostName = pHostName->link) { /* make sure name is not already used for this address */ if (strcmp (pHostName->name, hostName) == 0) { semGive (hostListSem); errnoSet (S_hostLib_HOST_ALREADY_ENTERED); return (ERROR); } pHostNamePrev = pHostName; } if (pHostNamePrev == NULL) { /* XXX corrupted list! */ return (ERROR); } /* name not used for this address, add it as an alias */ if ((pHostNamePrev->link = (HOSTNAME *) KHEAP_ALLOC(sizeof (HOSTNAME))) == NULL) { semGive (hostListSem); return (ERROR); } bzero ((char *)pHostNamePrev->link, sizeof(HOSTNAME)); if (hostNameFill (pHostNamePrev->link, hostName) == ERROR) { semGive (hostListSem); return (ERROR); } semGive (hostListSem); return (OK); } } /* host name and internet address not in host table, add new host */ if ((pHostEntry = (HOSTENTRY *) KHEAP_ALLOC(sizeof (HOSTENTRY))) == NULL) { semGive (hostListSem); return (ERROR); } bzero ((char *)pHostEntry, sizeof(HOSTENTRY)); if ((hostNameFill (&pHostEntry->hostName, hostName)) == ERROR) { semGive (hostListSem); return (ERROR); } pHostEntry->netAddr = netAddr; lstAdd (&hostList, &pHostEntry->node); semGive (hostListSem); return (OK); }