示例#1
0
文件: hw6.c 项目: ckcks12/Homework
void sort()
{
    char data[MAX_PATH_LEN];
    HeadNode* hn;
    Node* n;
    size_t idx;

    dll_init(&hn);

    while( fgets(data, MAX_PATH_LEN, stdin) != NULL )
    {
	n = dll_searchPredict(hn, data, &lessPredict);
	if( n == NULL )
	{
	    dll_insert(hn, hn->size, data);
	}
	else
	{
	    idx = dll_index(hn, &n);
	    dll_insert(hn, idx, data);
	}
    }

    //dll_printList(hn);
    for( idx=0; idx<hn->size; idx++ )
    {
	printf("%s", dll_at(hn, idx)->data);
    }

    dll_close(&hn);
}
示例#2
0
文件: wdbLib.c 项目: andy345/vxworks5
void wdbExternRegSetObjAdd
    (
    WDB_REG_SET_OBJ *	pRegSet			/* reg class object */
    )
    {
    dll_insert (&pRegSet->node, &wdbRegSetList);
    }
示例#3
0
void dllhashtable_insert(struct DLLHASHTABLE* dllhashtable_ptr,
	void* key, void* value)
{
	struct DLL* dll_ptr;
	struct HASHTABLE* hashtable_ptr;
	struct DLLHASHTABLE_DLLITEM* dllitem_ptr;
	struct DLLHASHTABLE_HASHTABLEVALUE* hashtablevalue_ptr;
	struct HASHITEM* hashitem_ptr;

	dll_ptr = dllhashtable_ptr->dll_ptr;
	hashtable_ptr = dllhashtable_ptr->hashtable_ptr;

	hashtablevalue_ptr = (struct DLLHASHTABLE_HASHTABLEVALUE*)
		malloc(sizeof(struct DLLHASHTABLE_HASHTABLEVALUE));
	hashtablevalue_ptr->value = value;
	hashtablevalue_ptr->dllitem_ptr = NULL;	
	hashtablevalue_ptr->delvaluefunc = 
		dllhashtable_ptr->hashtable_delvaluefunc;
	
	hashitem_ptr = hashtable_insert(hashtable_ptr, key, 
		hashtablevalue_ptr);
	// printf("hashitem_ptr = %p\n", hashitem_ptr);
	// printf("hashtablevalue_ptr = %p\n", hashtablevalue_ptr);
	
	dllitem_ptr = (struct DLLHASHTABLE_DLLITEM*)
		dll_insert(dll_ptr, hashitem_ptr);
	// printf("dllitem_ptr = %p\n", dllitem_ptr);

	hashtablevalue_ptr->dllitem_ptr = dllitem_ptr;
}
示例#4
0
文件: dl_lists.c 项目: OPENDAP/bes
DLL_NODE_PTR dll_add(DLL_NODE_PTR head_node)
{
	dll_rewind(&head_node);

	return(dll_insert(head_node));
/*
#ifdef DLL_CHK
	DLL_NODE_PTR new_node = dll_node_create(head_node);
#else
	DLL_NODE_PTR new_node = dll_node_create();
#endif
	
	FF_VALIDATE(head_node);
	
	if (new_node == NULL)
		return(NULL);

	dll_previous(new_node) = head_node;
	dll_next(new_node) = dll_next(head_node);

	dll_previous(dll_next(new_node)) = new_node;
	dll_next(head_node) = new_node;

	return(new_node);
*/
}
示例#5
0
文件: p12_8_3.c 项目: dielew/pts_on_c
int main( void ){
	
	int value;
	int flag;
	int init_val;
	Node *show;
	Node *previous;
	Node *next;
	
	Node *current = malloc(sizeof(Node));
	Node *head = current;

	current->bwd = NULL;
	for(init_val = 2; init_val < 21; init_val += 2 ){
		current->value = init_val;
		next = malloc(sizeof(Node));
		current->fwd = next;
		next->bwd = current;
		previous = malloc(sizeof(Node));
		previous = current;
		printf("Value of each original node in DLL is %d\n", previous->value);
		current = next;
	}
	previous->fwd = NULL;
	Node *tail = previous;

	printf("value of first node is: %d\n", head->value);
	printf("value of last  node is: %d\n", tail->value);
	

	printf("Enter insertation value: ");
	scanf("%d", &value);

	flag = dll_insert(&head, &tail, value);

	printf("flag: %d\n", flag);	
	if( !flag ){
		printf("Insertion value is already exists, invalid input, try agian...\n");
	}
	else{
		if( flag == -1 ){
			printf("mem allocation failed\n");
		}
		else{
			if( flag == 1 ){
				for( show = head;  show != NULL; show = show->fwd ){
					printf("Value of each node in inserted DLL is: %d\n", show->value);
				}
			}
			else{
				printf("unexpected branch. Wrong return value of the calling function.\n");
			}

		}

	}

	return 0;
}
示例#6
0
int dllist_test()
{

	struct mynode *mn[NUM_NODES];
	LPDL_NODE node;
	struct mynode *data;

	/* *insert */
	int i = 0;
	Debug_Message(LOG_FULL, "insert node from 1 to NUM_NODES(32): \n");
	for (; i < NUM_NODES; i++) {
		mn[i] = (struct mynode *)malloc(sizeof(struct mynode));
		mn[i]->string = (char *)malloc(sizeof(char) * 4);
		sprintf(mn[i]->string, "%d", i);
		dll_insert(&mytree, mn[i]);
	}
	
	/* *search */
	Debug_Message(LOG_FULL, "search all nodes: \n");
	for (node = dl_first(&mytree); node; node = dl_next(node)) {
		struct mynode *data;
		container_of(data, node, struct mynode, node);
		Debug_Message(LOG_TEST, "key = %s\n", data->string);
	}

	/* *delete */
	Debug_Message(LOG_FULL, "delete node 0: \n");
	data = dll_search(&mytree, "0");
	if (data) {
		dl_remove_node(&data->node, &mytree);
		dll_free(data);
	}

	/* *delete again*/
	Debug_Message(LOG_FULL, "delete node 10: \n");
	data = dll_search(&mytree, "10");
	if (data) {
		dl_remove_node(&data->node, &mytree);
		dll_free(data);
	}

	/* *delete once again*/
	Debug_Message(LOG_FULL, "delete node 31: \n");
	data = dll_search(&mytree, "31");
	if (data) {
		dl_remove_node(&data->node, &mytree);
		dll_free(data);
	}

	/* *search again*/
	Debug_Message(LOG_FULL, "search again:\n");
	for (node = dl_first(&mytree); node; node = dl_next(node)) {
		struct mynode *data;
		container_of(data, node, struct mynode, node);
		Debug_Message(LOG_TEST,"key = %s\n", data->string);
	}
	return 0;
}
示例#7
0
int main(void)
{

	dict_h lh ;
	dict_iter iter ;
	int i ;
	int *ip ;

	lh = dll_create( int_comp, int_kcomp, 0 ) ;

	for ( i = 0 ; i < N ; i++ )
	{
		nums[ i ] = 10-i ;
		if ( dll_insert( lh, &nums[ i ] ) != DICT_OK )
		{
			printf( "Failed at %d\n", i ) ;
			exit( 1 ) ;
		}
	}

	printf( "Successor test\n" ) ;
	for ( ip=INTP(dll_minimum( lh )) ; ip ; ip=INTP(dll_successor( lh, ip )) )
		printf( "%d\n", *ip ) ;
	printf( "Predecessor test\n" ) ;
	for ( ip=INTP(dll_maximum( lh )) ; ip ; ip=INTP(dll_predecessor( lh, ip )) )
		printf( "%d\n", *ip ) ;

	printf( "Search/delete test\n" ) ;
	i = 7 ;
	ip = INTP( dll_search( lh, &i ) ) ;
	if ( ip == NULL )
		printf( "Search failed\n" ) ;
	else
		if ( dll_delete( lh, ip ) != DICT_OK )
		{
			printf( "Delete failed\n" ) ;
			exit( 0 ) ;
		}

	printf( "Successor test 2\n" ) ;
	for ( ip=INTP(dll_minimum( lh )) ; ip ; ip=INTP(dll_successor( lh, ip )) )
		printf( "%d\n", *ip ) ;
	printf( "Predecessor test 2\n" ) ;
	for ( ip=INTP(dll_maximum( lh )) ; ip ; ip=INTP(dll_predecessor( lh, ip )) )
		printf( "%d\n", *ip ) ;

	printf( "Iteration test\n" ) ;
	iter = dll_iterate( lh, DICT_FROM_START ) ;
	while (( ip = INTP( dll_nextobj( lh, iter ) ) ))
		if ( *ip == 5 )
			(void) dll_delete( lh, ip ) ;
		else
			printf( "%d\n", *ip ) ;

	exit( 0 ) ;
}
示例#8
0
void wdbSysBpLibInit
    (
    BRKPT *	pBps,	/* pointer on breakpoint structure */
    int		bpCnt	/* number of breakpoints */
    )
    {
    static int	wdbBpInstalled = FALSE;

    if (!wdbBpInstalled)
	{
	wdbSvcAdd (WDB_CONTEXT_STEP, wdbStep, xdr_WDB_CTX_STEP_DESC, xdr_void);
	wdbSvcAdd (WDB_CONTEXT_CONT, wdbCont, xdr_WDB_CTX, xdr_void);

	wdbEventClassBp.evtptType = WDB_EVT_BP;
	wdbEventClassBp.evtptAdd = wdbBpAdd;
	wdbEventClassBp.evtptDel = wdbBpDelete;
	wdbEvtptClassConnect (&wdbEventClassBp);

#if	DBG_HARDWARE_BP
	wdbEventClassHwBp.evtptType = WDB_EVT_HW_BP;
	wdbEventClassHwBp.evtptAdd = wdbHwBpAdd;
	wdbEventClassHwBp.evtptDel = wdbBpDelete;
	wdbEvtptClassConnect (&wdbEventClassHwBp);
#endif	/* DBG_HARDWARE_BP */

#if	DBG_NO_SINGLE_STEP
	_func_trap = (FUNCPTR) wdbTrap;
#else   /* DBG_NO_SINGLE_STEP */
	_func_breakpoint = (FUNCPTR) wdbBreakpoint;
	_func_trace = (FUNCPTR) wdbTrace;
#endif  /* DBG_NO_SINGLE_STEP */

	_func_wdbIsNowExternal = (FUNCPTR) wdbIsNowExternal;

	wdbDbgBpListInit();

	while (bpCnt)
	    {
	    dll_insert (&pBps->bp_chain, &bpFreeList);
	    ++pBps;
	    --bpCnt;
	    }

	wdbDbgArchInit();

	wdbEventNodeInit (&eventSysBpNode, wdbSysBpEventGet, NULL, 
					(void *) &eventSysBpNode);

	wdbBpInstalled = TRUE;
	}
    }
示例#9
0
static void wdbExcHook
    (
    WDB_CTX	context,
    u_int	vec,
    char *	pESF,
    WDB_IU_REGS	* pRegs
    )
    {
    wdbExcInfoNode_t *	pExcInfoNode;
    int			lockKey;

    /* get a node off the queue */

    lockKey = intLock();
    pExcInfoNode = (wdbExcInfoNode_t *)dll_tail (&wdbExcEvtList);

    /* if event list if full and this is a task exception, just return */

    if ((pExcInfoNode->valid) && (context.contextType == WDB_CTX_TASK))
	{
	intUnlock (lockKey);
	return;
	}

    pExcInfoNode->valid     = TRUE;
    pExcInfoNode->context   = context;
    pExcInfoNode->excVector = vec;
    pExcInfoNode->pESF	    = pESF;

    dll_remove (&pExcInfoNode->node);
    dll_insert (&pExcInfoNode->node, &wdbExcEvtList);
    intUnlock (lockKey);

    /* exception in task context */

    if (wdbIsNowTasking())
	{
	wdbEventPost (&wdbExcEvtNode);
	return;
	}

    /* exception in system context - suspend system before posting event */

    wdbSuspendSystem (pRegs, wdbEventPost, (int)&wdbExcEvtNode);

    /* NOTREACHED */
    }
示例#10
0
int
main(int argc, char* argv[])
{
	struct NODE* head = NULL;
	struct NODE* tail = NULL;

	dll_insert(&head, &tail, 10);
	dll_insert(&head, &tail, 20);
	dll_insert(&head, &tail, 15);
	dll_insert(&head, &tail, 25);
	dll_insert(&head, &tail, 5);
	dll_insert(&head, &tail, 1);
	dll_insert(&head, &tail, 30);
	dll_show(head);

	return EXIT_SUCCESS;
}
示例#11
0
void wdbExcLibInit (void)
    {
    int ix;

    /* initialize our event node */

    wdbEventNodeInit (&wdbExcEvtNode, wdbExcGetEvent,
			wdbExcDeqEvent, NULL);

    /* initialize the linked list of exceptions */

    dll_init (&wdbExcEvtList);
    for (ix = 0; ix < MAX_EXC_EVENTS; ix++)
	dll_insert (&excInfoNode[ix].node, &wdbExcEvtList);

    /* add our exception hook to the run-time exception handler */

    (*pWdbRtIf->excHookAdd)(wdbExcHook);
    }
示例#12
0
void wdbExcGetEvent
    (
    void *	arg,
    WDB_EVT_DATA *	pEvtData
    )
    {
    wdbExcInfoNode_t *	pNode;
    wdbExcInfoNode_t *	pTmpNode;
    WDB_EXC_INFO *	pExcInfo;

    int lockKey;

    /* get a node from the exception queue */

    lockKey = intLock();
    pNode   = (wdbExcInfoNode_t *) dll_head (&wdbExcEvtList);
    dll_remove (&pNode->node);
    intUnlock (lockKey);

    /* give the node info to the host */

    pExcInfo = (WDB_EXC_INFO *)&pEvtData->eventInfo;
    pEvtData->evtType		= WDB_EVT_EXC;
    pExcInfo->numInts		= 4;
    pExcInfo->context		= pNode->context;
    pExcInfo->vec		= pNode->excVector;
    pExcInfo->pEsf		= (TGT_ADDR_T) pNode->pESF;

    /* mark the node invalid and put back in queue (after valid nodes) */

    pNode->valid = FALSE;
    lockKey = intLock();
    for (pTmpNode =  (wdbExcInfoNode_t *) dll_head (&wdbExcEvtList);
	 pTmpNode != (wdbExcInfoNode_t *) dll_end  (&wdbExcEvtList);
	 pTmpNode =  (wdbExcInfoNode_t *) dll_next (&pTmpNode->node))
	{
	if (pTmpNode->valid == FALSE)
	    break;
	}
    pTmpNode = (wdbExcInfoNode_t *) dll_prev (&pTmpNode->node);
    dll_insert (&pNode->node, &pTmpNode->node);
    intUnlock (lockKey);
    }
示例#13
0
STATUS wdbVioChannelRegister
    (
    WDB_VIO_NODE *	pVioNode
    )
    {
    WDB_VIO_NODE *	pThisNode;
    int lockKey;

    for (pThisNode =  (WDB_VIO_NODE *)dll_head (&wdbVioDevList);
	 pThisNode != (WDB_VIO_NODE *)dll_end  (&wdbVioDevList);
	 pThisNode =  (WDB_VIO_NODE *)dll_next (&pThisNode->node)
	)
	{
	if (pThisNode->channel == pVioNode->channel)
	    return (ERROR);
	}

    lockKey = intLock();
    dll_insert (&pVioNode->node, &wdbVioDevList);
    intUnlock (lockKey);

    return (OK);
    }
示例#14
0
static UINT32 wdbHwBpAdd
    (
    WDB_EVTPT_ADD_DESC *	pBreakPoint,	/* breakpoint to add */
    UINT32 *			pId		/* breakpoint ID */
    )
    {
    BRKPT *	pBp;
    dll_t *	pDll;
    int		status;
    DBG_REGS	dbgRegs;		/* debug registers */
    int		contextId;		/* context ID */
    UINT32	addr;			/* breakpoint address */
    UINT32	count = 0;		/* breakpoint count */
    int		type = DEFAULT_HW_BP;	/* hardware type */

    switch (pBreakPoint->numArgs)
	{
	default:
	case 3:
	    type = pBreakPoint->args[2];
	    /* FALL THROUGH */
	case 2:
	    count = pBreakPoint->args[1];
	    /* FALL THROUGH */
	case 1:
	    addr = pBreakPoint->args[0];
	    break;
	case 0:
	    return (WDB_ERR_INVALID_PARAMS);
	}

    /* check validity of hardware breakpoint address */

    if (wdbDbgHwAddrCheck (addr, type, (FUNCPTR) pWdbRtIf->memProbe) != OK)
        return (WDB_ERR_MEM_ACCES);

    /* check the agent mode */

    switch (pBreakPoint->context.contextType)
	{
	case WDB_CTX_SYSTEM:
	    if (!wdbIsNowExternal())
		return (WDB_ERR_AGENT_MODE);
	    break;

	default:
	    if (!wdbIsNowTasking())
		return (WDB_ERR_AGENT_MODE);
	}

    /* set the context ID */

    switch (pBreakPoint->context.contextType)
        {
        case WDB_CTX_SYSTEM:
            contextId = BP_SYS;
            break;
        case WDB_CTX_ANY_TASK:
            contextId = BP_ANY_TASK;
            break;
        case WDB_CTX_TASK:
        default:
            contextId = pBreakPoint->context.contextId;
        }

    /* clean dbgRegs structure */

    memset (&dbgRegs, 0, sizeof (DBG_REGS));

    /* fill dbgRegs structure with all hardware breakpoints */

    wdbTaskLock ();	/* disable task switching */
    for (pDll = dll_head(&bpList); pDll != dll_end(&bpList);
		pDll = dll_next(pDll))
	{
	pBp = BP_BASE(pDll);

	/* check if found breakpoint is applicable to new breakpoint context */

	if (((contextId == BP_SYS) && (pBp->bp_task == BP_SYS)) ||
		((contextId == BP_ANY_TASK) && (pBp->bp_task != BP_SYS)) ||
		((contextId != BP_SYS) && (pBp->bp_task == BP_ANY_TASK)))
	    {
	    if (pBp->bp_flags & BRK_HARDWARE)
		{
		if ((status = wdbDbgHwBpSet (&dbgRegs, 
				pBp->bp_flags & BRK_HARDMASK, 
				(UINT32) pBp->bp_addr)) != OK)
		    {
		    wdbTaskUnlock ();	/* re-enable task switching */
		    return (status);
		    }
		}
	    }
	}
    wdbTaskUnlock ();	/* re-enable task switching */

    if ((status = wdbDbgHwBpSet (&dbgRegs, type, addr)) != OK)
	return (status);

    if (dll_empty (&bpFreeList))
	return (WDB_ERR_EVENTPOINT_TABLE_FULL);

    wdbTaskLock ();		/* disable task switching */
    pBp = BP_BASE(dll_tail (&bpFreeList));
    dll_remove (&pBp->bp_chain);
    wdbTaskUnlock ();	/* re-enable task switching */

    pBp->bp_flags = BP_HOST | type | BRK_HARDWARE;
    pBp->bp_addr = (INSTR *)addr;
    pBp->bp_action = pBreakPoint->action.actionType;
    pBp->bp_count = count;
    pBp->bp_callRtn = (void (*)())pBreakPoint->action.callRtn;
    pBp->bp_callArg = pBreakPoint->action.callArg;
    pBp->bp_task = contextId;

    /* 
     * XXX - MS hack because host tools pass wrong info.
     * XXX - DBT This has been corrected in tornado 2.0 host tools but we
     * must keep this hack for backward compatibility.
     */

    if ((pBp->bp_action == 0) || (pBp->bp_action == WDB_ACTION_STOP))
	pBp->bp_action = WDB_ACTION_STOP | WDB_ACTION_NOTIFY;

    wdbTaskLock ();		/* disable task switching */
    dll_insert(&pBp->bp_chain, &bpList);
    wdbTaskUnlock ();		/* re-enable task switching */

    if (pBreakPoint->context.contextType != WDB_CTX_SYSTEM)
	if (_wdbTaskBpAdd != NULL)
	    _wdbTaskBpAdd (pBreakPoint);

    *pId = (UINT32)pBp;
    return (WDB_OK);
    }
示例#15
0
static UINT32 wdbBpAdd
    (
    WDB_EVTPT_ADD_DESC *	pBreakPoint,
    UINT32 *			pId
    )
    {
    INSTR	val;
    BRKPT *	pBp;
    INSTR *	addr;

    switch (pBreakPoint->numArgs)
	{
	default:
	case 1:
#if ((CPU_FAMILY == ARM) && ARM_THUMB)
	    addr = (INSTR *) ((UINT32)((pBreakPoint->args[0]) & ~1));
#else /* CPU_FAMILY == ARM */
	    addr = (INSTR *) pBreakPoint->args[0];
#endif /* CPU_FAMILY == ARM */
	    break;
	case 0:
	    return (WDB_ERR_INVALID_PARAMS);
	}

    /* check validity of breakpoint address */

    TEXT_UNLOCK(addr);

    if (((*pWdbRtIf->memProbe) ((char *)addr, VX_READ,
				sizeof(INSTR), (char *)&val) != OK) ||
        ((*pWdbRtIf->memProbe) ((char *)addr, VX_WRITE,
				sizeof(INSTR), (char *)&val) != OK))
	{
	TEXT_LOCK(addr);
        return (WDB_ERR_MEM_ACCES);
	}

    TEXT_LOCK(addr);

    /* check the agent mode */

    switch (pBreakPoint->context.contextType)
	{
	case WDB_CTX_SYSTEM:
	    if (!wdbIsNowExternal())
		return (WDB_ERR_AGENT_MODE);
	    break;
	default:
	    if (!wdbIsNowTasking())
		return (WDB_ERR_AGENT_MODE);
	}



    if (dll_empty (&bpFreeList))
	return (WDB_ERR_EVENTPOINT_TABLE_FULL);

    wdbTaskLock ();	/* disable task switching */
    pBp = BP_BASE(dll_tail (&bpFreeList));
    dll_remove (&pBp->bp_chain);
    wdbTaskUnlock ();	/* re-enable task switching */

    pBp->bp_flags = BP_HOST;
    pBp->bp_addr = addr;
    pBp->bp_action = pBreakPoint->action.actionType;
#if ((CPU_FAMILY == ARM) && ARM_THUMB)
    pBp->bp_callRtn = (void (*)())((UINT32)pBreakPoint->action.callRtn | 1);
#else /* CPU_FAMILY == ARM */
    pBp->bp_callRtn = (void (*)())pBreakPoint->action.callRtn;
#endif /* CPU_FAMILY == ARM */
    pBp->bp_callArg = pBreakPoint->action.callArg;
    pBp->bp_instr = *(INSTR *)addr;

    if (pBreakPoint->numArgs > 1)	/* second argument is count */
   	pBp->bp_count = pBreakPoint->args[1];
    else
   	pBp->bp_count = 0;

    /* XXX - hack because host tools pass wrong info */

    if ((pBp->bp_action == 0) || (pBp->bp_action == WDB_ACTION_STOP))
	pBp->bp_action = WDB_ACTION_STOP | WDB_ACTION_NOTIFY;

    /* set the context ID */

    switch (pBreakPoint->context.contextType)
        {
        case WDB_CTX_SYSTEM:
	    pBp->bp_task = BP_SYS;
            break;
        case WDB_CTX_ANY_TASK:
	    pBp->bp_task = BP_ANY_TASK;
            break;
        case WDB_CTX_TASK:
        default:
	    pBp->bp_task = pBreakPoint->context.contextId;
        }

    wdbTaskLock ();		/* disable task switching */
    dll_insert(&pBp->bp_chain, &bpList);
    wdbTaskUnlock ();		/* re-enable task switching */

    if (pBreakPoint->context.contextType != WDB_CTX_SYSTEM)
	if (_wdbTaskBpAdd != NULL)
	    _wdbTaskBpAdd (pBreakPoint);

    *pId = (UINT32)pBp;
    return (WDB_OK);
    }