📄 list.c
字号:
lhandle->beginptr = lhandle->currptr->next ;
lhandle->beginptr->prior = NULL;
free(lhandle->currptr) ; /* free the node */
lhandle->currptr = lhandle->beginptr ; /* current pointer stays at he beginning of the list */
lhandle->currno = 1L ; /* update current item's number */
}
else
{
tmpl1 = lhandle->currptr->prior ;
tmpl2 = lhandle->currptr->next ;
tmpl1->next = tmpl2 ;
tmpl2->prior = tmpl1 ;
free(lhandle->currptr) ; /* free the node */
lhandle->currptr = tmpl2 ;
/* Note! lhandle->currno does not change */
}
return( LIST_OK ) ;
}
}
/* ===================================
*
* ListReturn() - Return the actual data stored in the current entry
* This function can return one of the following error codes:
* LIST_ERR_BAD_POINTER
* LIST_ERR_NO_CURR
*
* ===================================*/
int ListReturn(HNDLIST *lhandle, void **buf, unsigned long *buflen)
{
*buf = NULL ;
*buflen = 0L ;
if (lhandle == NULL)
return( LIST_ERR_BAD_POINTER );
if(lhandle->currptr == NULL)
return( LIST_ERR_NO_CURR ) ;
*buf = lhandle->currptr->buf ;
*buflen = lhandle->currptr->buflen ;
return( LIST_OK ) ;
}
/* ===================================
*
* ListOverwrite() - Set the actual data stored in the current node.
* This function can return one of the following error codes:
* LIST_ERR_BAD_POINTER
* LIST_ERR_NO_CURR
*
* ===================================*/
int ListOverwrite(HNDLIST *lhandle, void *buf, long buflen)
{
void *tmpbuf ;
if (lhandle == NULL)
return( LIST_ERR_BAD_POINTER ) ;
if(lhandle->currptr == NULL)
return(LIST_ERR_NO_CURR) ;
if ((tmpbuf = calloc(1, (size_t) buflen)) != NULL) /* reserve memory for actual data */
{
memcpy(tmpbuf, buf, (size_t) buflen) ; /* store data in reserved memory block */
free(lhandle->currptr->buf) ; /* free old data in node */
lhandle->currptr->buf = tmpbuf ; /* set current node to point to the correct buffer */
lhandle->currptr->buflen = buflen ; /* set size of data */
}
else
return( LIST_ERR_MEMORY_ALLOCATION ) ;
}
/* ===================================
*
* ListFirst() - Set the current pointer to the first node.
* This function can return one of the following error codes:
* LIST_ERR_BAD_POINTER
*
* ===================================*/
int ListFirst(HNDLIST *lhandle)
{
if (lhandle == NULL)
return( LIST_ERR_BAD_POINTER ) ;
if( lhandle->itemscount == 0L)
return( LIST_ERR_END_LIST ) ;
lhandle->currptr = lhandle->beginptr ;
lhandle->currno = 1 ;
return(LIST_OK) ;
}
/* ===================================
*
* ListLast() - Set the current pointer to the last node.
* This function can return one of the following error codes:
* LIST_ERR_BAD_POINTER
*
* ===================================*/
int ListLast(HNDLIST *lhandle)
{
if (lhandle == NULL)
return( LIST_ERR_BAD_POINTER ) ;
if( lhandle->itemscount == 0L)
return( LIST_ERR_END_LIST ) ;
lhandle->currptr = lhandle->endptr ;
lhandle->currno = lhandle->itemscount ;
return(LIST_OK) ;
}
/* ===================================
*
* ListForward() - Set the current pointer forward node.
* This function can return one of the following error codes:
* LIST_ERR_BAD_POINTER
*
* ===================================*/
int ListForward(HNDLIST *lhandle, long forward)
{
long l ;
if (lhandle == NULL)
return( LIST_ERR_BAD_POINTER ) ;
if (lhandle->currptr == lhandle->endptr)
return( LIST_ERR_END_LIST ) ;
for (l = 0L; l < forward; l++)
{
if (lhandle->currptr == lhandle->endptr)
return( LIST_ERR_END_LIST ) ;
lhandle->currptr = lhandle->currptr->next ;
lhandle->currno ++;
/* Is this correct ??? */
if (lhandle->currptr == NULL)
return(LIST_ERR_BAD_POINTER) ;
}
return(LIST_OK) ;
}
/* ===================================
*
* ListNext() - Set the current pointer to next node.
* This function can return one of the following error codes:
* LIST_ERR_BAD_POINTER
*
* ===================================*/
int ListNext(HNDLIST *lhandle)
{
return( ListForward(lhandle, 1L) );
}
/* ===================================
*
* ListBackward() - Set the current pointer backward node.
* This function can return one of the following error codes:
* LIST_ERR_BAD_POINTER
* LIST_ERR_BEG_LIST, when at the beginning of the list
*
* ===================================*/
int ListBackward(HNDLIST *lhandle, long backward)
{
long l ;
if (lhandle == NULL)
return( LIST_ERR_BAD_POINTER ) ;
if (lhandle->currptr == lhandle->beginptr)
return( LIST_ERR_BEG_LIST ) ;
for (l = 0L; l < backward; l++)
{
if (lhandle->currptr == lhandle->beginptr)
return( LIST_ERR_BEG_LIST ) ;
lhandle->currptr = lhandle->currptr->prior ;
lhandle->currno -- ;
/* Is this correct ??? */
if (lhandle->currptr == NULL)
return(LIST_ERR_BAD_POINTER) ;
}
return(LIST_OK) ;
}
/* ===================================
*
* ListPrior() - Set the current pointer to the prior node.
* This function can return one of the following error codes:
* LIST_ERR_BAD_POINTER
* LIST_ERR_BEG_LIST, when at the beginning of the list
*
* =================================== */
int ListPrior(HNDLIST *lhandle)
{
return( ListBackward(lhandle, 1L) ) ;
}
/* ===================================
*
* ListGetPos() - returns pointer to the current item.
* This function can return one of the following error codes:
* LIST_ERR_BAD_POINTER
*
* ===================================*/
LIST_ENTRY *ListGetPos(HNDLIST * lhandle, int *actioncode, long *currno)
{
*actioncode = LIST_OK ;
*currno = 0L ;
if (lhandle == NULL)
{
*actioncode = LIST_ERR_BAD_POINTER ;
return( NULL ) ;
}
*currno = lhandle->currno ;
return(lhandle->currptr) ;
}
/* ===================================
*
* ListSetPos() - returns current item pointer to a value returned earlier
* ListGetPos().
* This function can return one of the following error codes:
* LIST_ERR_BAD_POINTER
*
* ===================================*/
int ListSetPos(HNDLIST * lhandle, LIST_ENTRY *newcurrptr, long newcurrno)
{
if (lhandle == NULL)
return( LIST_ERR_BAD_POINTER ) ;
lhandle->currptr = newcurrptr ;
lhandle->currno = newcurrno ;
return( LIST_OK ) ;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -