📄 slog_bbuf.c
字号:
#include <stdio.h>#ifdef HAVE_SLOGCONF_H#include "slog_config.h"#endif#ifdef HAVE_SLOG_WINCONFIG_H#include "slog_winconfig.h"#endif#if defined( STDC_HEADERS ) || defined( HAVE_STDLIB_H )#include <stdlib.h>#endif#include "slog_bbuf.h" /*I "slog_bbuf.h" I*//* Move Intvl Rec from src_bbuf and Append it to dest_bbuf through the use of src_bbuf->lptr which points at the Intvl Rec Node to be moved. The routine does NOT advance the src_bbuf->lptr, so the calling routine should do the bookkeeping. After the call, the calling routine should NOT assume that src_bbuf->lptr still points at anything meaningful after the call. src_bbuf->lptr can be set by SLOG_Bbuf_SetPointerAt()*/int SLOG_Bbufs_MoveIntvlRec( SLOG_intvlrec_blist_t *src_bbuf, SLOG_intvlrec_blist_t *dest_bbuf ){ int ierr; if ( src_bbuf->lptr == NULL ) { fprintf( errfile, __FILE__":SLOG_Bbufs_MoveIntvlRec() - " "the src_bbuf->lptr is NULL\n" ); fflush( errfile ); return SLOG_FAIL; } ierr = SLOG_Bbuf_RemoveNodeLinks( src_bbuf ); if ( ierr != SLOG_SUCCESS ) { fprintf( errfile, __FILE__":SLOG_Bbufs_MoveIntvlRec() - " "SLOG_Bbuf_RemoveNodeLinks() fails\n" ); fflush( errfile ); return SLOG_FAIL; } ierr = SLOG_Bbuf_AddMovedIrecNode( dest_bbuf, src_bbuf->lptr ); if ( ierr != SLOG_SUCCESS ) { fprintf( errfile, __FILE__":SLOG_Bbufs_MoveIntvlRec() - " "SLOG_Bbuf_AddMovedIrecNode() fails\n" ); fflush( errfile ); return SLOG_FAIL; } return ierr;}/* Copy Intvl Rec from src_bbuf and Append it to dest_bbuf through the use of src_bbuf->lptr which points at the Intvl Rec to be copied. The routine does NOT advance the src_bbuf->lptr, so the calling routine should do the bookkeeping. src_bbuf->lptr can be set by SLOG_Bbuf_SetPointerAt()*/int SLOG_Bbufs_CopyIntvlRec( const SLOG_intvlrec_blist_t *src_bbuf, SLOG_intvlrec_blist_t *dest_bbuf ){ int ierr; if ( src_bbuf->lptr == NULL ) { fprintf( errfile, __FILE__":SLOG_Bbufs_CopyIntvlRec() - " "the src_bbuf->lptr is NULL\n" ); fflush( errfile ); return SLOG_FAIL; } if ( src_bbuf->lptr->irec == NULL ) { fprintf( errfile, __FILE__":SLOG_Bbufs_CopyIntvlRec() - " "the src_bbuf->lptr->irec is NULL\n" ); fflush( errfile ); return SLOG_FAIL; } ierr = SLOG_Bbuf_AddCopiedIntvlRec( dest_bbuf, src_bbuf->lptr->irec ); if ( ierr != SLOG_SUCCESS ) { fprintf( errfile, __FILE__":SLOG_Bbufs_CopyIntvlRec() - " "SLOG_Bbuf_AddCopiedIntvlRec() fails\n" ); fflush( errfile ); return SLOG_FAIL; } return ierr;}/* The routine modifies both the src_bbuf and dest_bbuf in order to achieve the process of concatenation of the 2 bbuf. The head of the concatenated bbuf will the the head of the dest_bbuf. Both the src_bbuf and dest_bbuf will be the same bbuf. There is no malloc() involved to create the concatenated bbuf. The concatenated bbuf is created from the merging the src_buff and dest_bbuf.*/int SLOG_Bbufs_Concatenate( SLOG_intvlrec_blist_t *src_bbuf, SLOG_intvlrec_blist_t *dest_bbuf ){ if ( src_bbuf == NULL ) { fprintf( errfile, __FILE__":SLOG_Bbufs_Concatenate() - " "the input src_bbuf is NULL\n" ); fflush( errfile ); return SLOG_FAIL; } if ( dest_bbuf == NULL ) { fprintf( errfile, __FILE__":SLOG_Bbufs_Concatenate() - " "the input dest_bbuf is NULL\n" ); fflush( errfile ); return SLOG_FAIL; } if ( ! SLOG_Bbuf_IsConsistent( src_bbuf ) ) { fprintf( errfile, __FILE__":SLOG_Bbufs_Concatenate() - " "the input src_bbuf is Inconsistent\n" ); fflush( errfile ); return SLOG_FAIL; } if ( ! SLOG_Bbuf_IsConsistent( dest_bbuf ) ) { fprintf( errfile, __FILE__":SLOG_Bbufs_Concatenate() - " "the input dest_bbuf is Inconsistent\n" ); fflush( errfile ); return SLOG_FAIL; } dest_bbuf->Nbytes_in_file += src_bbuf->Nbytes_in_file; dest_bbuf->count_irec += src_bbuf->count_irec; if ( dest_bbuf->ltail != NULL ) dest_bbuf->ltail->next = src_bbuf->lhead; else dest_bbuf->lhead = src_bbuf->lhead; if ( src_bbuf->lhead != NULL ) src_bbuf->lhead->prev = dest_bbuf->ltail; else src_bbuf->ltail = dest_bbuf->ltail; dest_bbuf->ltail = src_bbuf->ltail; src_bbuf->Nbytes_in_file = dest_bbuf->Nbytes_in_file; src_bbuf->count_irec = dest_bbuf->count_irec; src_bbuf->lhead = dest_bbuf->lhead; return SLOG_SUCCESS;}SLOG_time SLOG_Bbuf_EarliestStarttime( const SLOG_intvlrec_blist_t *slog_bbuf ){ const SLOG_intvlrec_lptr_t *lptr; SLOG_time irec_starttime; SLOG_time earliest; if ( slog_bbuf == NULL ) { fprintf( errfile, __FILE__":SLOG_Bbuf_EarliestStarttime() - " "Input slog_bbuf is NULL\n" ); fflush( errfile ); return SLOG_time_NULL; } if ( slog_bbuf->lhead == NULL ) { fprintf( errfile, __FILE__":SLOG_Bbuf_EarliestStarttime() - " "Input slog_bbuf contains No element\n" ); fflush( errfile ); return SLOG_time_NULL; } earliest = slog_bbuf->lhead->irec->starttime; for ( lptr = slog_bbuf->lhead; lptr != NULL; lptr = lptr->next ) { irec_starttime = lptr->irec->starttime; if ( irec_starttime < earliest ) earliest = irec_starttime; } return earliest;}SLOG_time SLOG_Bbuf_LatestEndtime( const SLOG_intvlrec_blist_t *slog_bbuf ){ const SLOG_intvlrec_lptr_t *lptr; SLOG_time irec_endtime; SLOG_time latest; if ( slog_bbuf == NULL ) { fprintf( errfile, __FILE__":SLOG_Bbuf_LatestEndtime() - " "Input slog_bbuf is NULL\n" ); fflush( errfile ); return SLOG_time_NULL; } if ( slog_bbuf->lhead == NULL ) { fprintf( errfile, __FILE__":SLOG_Bbuf_LatestEndtime() - " "Input slog_bbuf contains No element\n" ); fflush( errfile ); return SLOG_time_NULL; } latest = slog_bbuf->lhead->irec->starttime + slog_bbuf->lhead->irec->duration; for ( lptr = slog_bbuf->lhead; lptr != NULL; lptr = lptr->next ) { irec_endtime = lptr->irec->starttime + lptr->irec->duration; if ( irec_endtime > latest ) latest = irec_endtime; } return latest;}int SLOG_Bbuf_IsPointerAtNULL( const SLOG_intvlrec_blist_t *slog_bbuf ){ return ( slog_bbuf->lptr == NULL );}int SLOG_Bbuf_SetPointerAtHead( SLOG_intvlrec_blist_t *slog_bbuf ){ if ( slog_bbuf == NULL ) { fprintf( errfile, __FILE__":SLOG_Bbuf_SetPointerAtHead() - " "the input slog_bbuf is a NULL pointer\n" ); fflush( errfile ); return SLOG_FAIL; } slog_bbuf->lptr = slog_bbuf->lhead; return SLOG_SUCCESS;}int SLOG_Bbuf_SetPointerAtTail( SLOG_intvlrec_blist_t *slog_bbuf ){ if ( slog_bbuf == NULL ) { fprintf( errfile, __FILE__":SLOG_Bbuf_SetPointerAtTail() - " "the input slog_bbuf is a NULL pointer\n" ); fflush( errfile ); return SLOG_FAIL; } slog_bbuf->lptr = slog_bbuf->ltail; return SLOG_SUCCESS;}/* const SLOG_intvlrec_lptr_t *lptr*/int SLOG_Bbuf_SetPointerAt( SLOG_intvlrec_blist_t *slog_bbuf, SLOG_intvlrec_lptr_t *lptr ){ if ( slog_bbuf == NULL ) { fprintf( errfile, __FILE__":SLOG_Bbuf_SetPointerAt() - " "the input slog_bbuf is a NULL pointer\n" ); fflush( errfile ); return SLOG_FAIL; } slog_bbuf->lptr = lptr; return SLOG_SUCCESS;}SLOG_intvlrec_lptr_t *SLOG_Bbuf_GetPointerAtHead( const SLOG_intvlrec_blist_t *slog_bbuf ){ if ( slog_bbuf != NULL ) return slog_bbuf->lhead; else return NULL;}SLOG_intvlrec_lptr_t *SLOG_Bbuf_GetPointerAtTail( const SLOG_intvlrec_blist_t *slog_bbuf ){ if ( slog_bbuf != NULL ) return slog_bbuf->ltail; else return NULL;}SLOG_intvlrec_lptr_t *SLOG_Bbuf_GetPointerAt( const SLOG_intvlrec_blist_t *slog_bbuf ){ if ( slog_bbuf != NULL ) return slog_bbuf->lptr; else return NULL;}/* The routine returns a pointer to the interval record of the current node in the bi-directional linked list buffer given. The routine makes no attempt to create new node/irec. It just simply returns a pointer to the existing one in the bi-directional linked list. If one wants to modify the content of the interval record without modification of the specified bi-directional linked, one should use SLOG_Irec_Copy() to copy the returned record content to a new record. The routine also ADVANCES the internal pointer of the specified linked list buffer.*/const SLOG_intvlrec_t *SLOG_Bbuf_GetIntvlRec( SLOG_intvlrec_blist_t *slog_bbuf ){ SLOG_intvlrec_t *irec; if ( slog_bbuf == NULL ) { fprintf( errfile, __FILE__":SLOG_Bbuf_GetIntvlRec() - " "the input slog_bbuf is a NULL pointer\n" ); fflush( errfile ); return NULL; } if ( slog_bbuf->lptr == NULL ) return NULL; /* Extraction */ irec = slog_bbuf->lptr->irec; /* Move the internal pointer to the next one */ slog_bbuf->lptr = slog_bbuf->lptr->next; return irec;} SLOG_intvlrec_lptr_t *SLOG_Bbuf_LocateIntvlRec( SLOG_intvlrec_blist_t *slog_bbuf, const SLOG_intvlrec_t *irec ){ SLOG_intvlrec_lptr_t *lptr; for ( lptr = slog_bbuf->lhead; lptr != NULL; lptr = lptr->next ) { if ( SLOG_Irec_IsEqualTo( lptr->irec, irec ) ) return lptr; } return NULL;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -