自主协议库编译通过

This commit is contained in:
lnk
2026-06-15 15:48:16 +08:00
parent d3579a2aa7
commit 7205cb5cb9
621 changed files with 224958 additions and 48 deletions

166
mmslib/slog/qmem.c Normal file
View File

@@ -0,0 +1,166 @@
/************************************************************************/
/* SISCO SOFTWARE MODULE HEADER *****************************************/
/************************************************************************/
/* (c) Copyright Systems Integration Specialists Company, Inc., */
/* 1993-2007, All Rights Reserved */
/* */
/* MODULE NAME : qmem.c */
/* PRODUCT(S) : Quick Memory Allocator */
/* */
/* MODULE DESCRIPTION : */
/* */
/* GLOBAL FUNCTIONS DEFINED IN THIS MODULE : */
/* */
/* MODIFICATION LOG : */
/* Date Who Rev Comments */
/* -------- --- ------ ------------------------------------------- */
/* 01/15/07 EJV 08 Chg S_LOCK_RESOURCES to S_LOCK_UTIL_RESOURCES*/
/* 03/11/04 GLB 07 Remove "thisFileName" */
/* 06/06/03 JRB 06 Use S_LOCK_RESOURCES (new util mutex). */
/* 04/14/03 JRB 05 Eliminate compiler warnings. */
/* 05/24/01 JRB 04 Chg chk_calloc to calloc. This always compiled*/
/* with !DEBUG_SISCO, screws up link. */
/* 09/24/99 JRB 03 added: #include "sysincs.h" */
/* 09/13/99 MDE 02 Added SD_CONST modifiers */
/* 04/14/99 MDE 01 Removed unnecessary include files */
/* 04/02/97 DTL 7.00 MMSEASE 7.0 release. See MODL70.DOC for */
/* history. */
/************************************************************************/
#include "glbtypes.h"
#include "sysincs.h"
#include "glbsem.h"
#include "mem_chk.h"
#include "qmem.h"
#if defined(MSDOS)
#define HUGE _huge
#else
#define HUGE
#define halloc(a,b) calloc(a,b)
#endif
ST_INT qMemElemSize; /* should be ((power of 2)-2) */
static ST_INT initialized;
static ST_CHAR HUGE *qMemBuf;
static ST_CHAR *qMemUsed;
static ST_INT16 qMemIndex;
static ST_INT qNumElem;
static ST_INT qShift;
/************************************************************************/
/* qMemInit */
/* Initialization function */
/************************************************************************/
ST_RET qMemInit (ST_INT NumElem)
{
ST_INT size;
ST_RET ret;
S_LOCK_UTIL_RESOURCES ();
if (!initialized)
{
if (qMemElemSize == 0)
qMemElemSize = 126;
qMemBuf = (ST_CHAR HUGE *) halloc ((ST_INT32) NumElem, qMemElemSize + 2);
qMemUsed = (ST_CHAR *) calloc (NumElem, 1);
qMemIndex = 0;
qNumElem = NumElem;
qShift = -1;
size = qMemElemSize + 2; /* 2 for the header! */
while (size) /* determine the size of the buffer (power of 2)*/
{
size >>= 1; /* size = (size/2) */
qShift++; /* Need to multiply buffer index by 2 later */
}
initialized = SD_TRUE;
}
if (!qMemBuf || !qMemUsed)
ret = SD_FAILURE;
else
ret = SD_SUCCESS;
S_UNLOCK_UTIL_RESOURCES ();
return (ret);
}
/************************************************************************/
/* qMemAlloc */
/* Allocation function */
/************************************************************************/
ST_VOID *qMemAlloc (ST_INT size)
{
ST_INT32 offset;
ST_CHAR HUGE *ptr;
register ST_INT i;
S_LOCK_UTIL_RESOURCES ();
if (!initialized)
qMemInit (qNumElem == 0 ? 1024 : qNumElem);
if (qMemIndex == -1 || size > qMemElemSize)
{
S_UNLOCK_UTIL_RESOURCES ();
return (NULL);
}
/* qMemIndex is the index into the array of buffers to the one that */
/* we will return this time */
offset = ((ST_INT32) qMemIndex) << qShift; /* multiply by buffer size */
ptr = qMemBuf + offset;
* (ST_INT16 *) ptr = qMemIndex; /* save index into used array */
qMemUsed[qMemIndex] = SD_TRUE; /* mark used */
/* Now get ready for next time */
qMemIndex++;
if (qMemIndex == qNumElem)
qMemIndex = 0;
for (i = 0; i < qNumElem; i++) /* find available buffer */
{
if (qMemUsed[qMemIndex] == SD_FALSE)
break;
else
{
qMemIndex++;
if (qMemIndex == qNumElem)
qMemIndex = 0;
}
}
if (i == qNumElem) /* no more buffers */
qMemIndex = -1;
S_UNLOCK_UTIL_RESOURCES ();
return ((ST_VOID *) (ptr + 2));
}
/************************************************************************/
/* qMemFree */
/* Free function */
/************************************************************************/
ST_VOID qMemFree (ST_VOID *vp)
{
ST_INT16 index;
ST_CHAR *ptr;
/* recover the index into the 'used' flag array & set SD_FALSE */
S_LOCK_UTIL_RESOURCES ();
ptr = (ST_CHAR *) vp;
ptr -= 2;
index = * (ST_INT16 *) ptr;
qMemUsed[index] = SD_FALSE;
qMemIndex = index;
S_UNLOCK_UTIL_RESOURCES ();
}

1004
mmslib/slog/slog.c Normal file

File diff suppressed because it is too large Load Diff

741
mmslib/slog/slogfil.c Normal file
View File

@@ -0,0 +1,741 @@
/************************************************************************/
/* SISCO SOFTWARE MODULE HEADER *****************************************/
/************************************************************************/
/* (c) Copyright Systems Integration Specialists Company, Inc., */
/* 1993-2008, All Rights Reserved */
/* */
/* MODULE NAME : slogfil.c */
/* PRODUCT(S) : SLOG */
/* */
/* MODULE DESCRIPTION : */
/* */
/* GLOBAL FUNCTIONS DEFINED IN THIS MODULE : */
/* */
/* MODIFICATION LOG : */
/* Date Who Rev Comments */
/* -------- --- ------ ------------------------------------------- */
/* 03/27/08 EJV 22 Elim warning from previous changes. */
/* 03/27/08 EJV 21 Use S_MAX_PATH instead of MAX_PATH. */
/* slog_get_index_file_name: added destLen param*/
/* and changed to return result. */
/* 10/08/07 EJV 20 Moved MAX_PATH define to sysincs.h */
/* 01/15/07 EJV 19 Chg S_LOCK_RESOURCES to S_LOCK_UTIL_RESOURCES*/
/* 02/13/06 DSF 18 Migrate to VS.NET 2005 */
/* 10/31/05 MDE 17 Tweaked index tile name creation */
/* 09/23/05 MDE 16 Tweaked size of idxFileName in */
/* 09/14/05 DSF 15 Increased size of idxFileName in */
/* 08/26/05 MDE 14 Fixed startup w/wo */
/* 08/10/05 MDE 13 Added index file, wrap cleanup, etc. */
/* 06/07/04 EJV 12 slogFil: chg state if reopen err (HARD_FLUSH)*/
/* 05/13/04 EJV 11 Moved log header formatting to slogSetHdr. */
/* 03/11/04 GLB 10 Remove "thisFileName" */
/* 02/20/03 JRB 09 Del PSOS code. */
/* 10/13/00 EJV 08 Moved glbsem.h below sysincs.h. */
/* 08/22/00 KCR 07 Added FIL_CTRL_NO_LOG_HDR */
/* 09/13/99 MDE 06 Added SD_CONST modifiers */
/* 04/14/99 MDE 05 Removed unnecessary include files */
/* 10/23/98 MDE 04 No blank line bet. logs if LOG_NO_HEADER_CR */
/* 10/16/98 DSF 03 Spelling */
/* 10/08/98 MDE 02 Migrated to updated SLOG interface */
/* 10/06/97 DSF 01 Added thisFileName */
/* 04/02/97 DTL 7.00 MMSEASE 7.0 release. See MODL70.DOC for */
/* history. */
/************************************************************************/
#if defined (_WIN32)
#pragma warning(disable : 4996)
#endif
#include "glbtypes.h"
#include "sysincs.h"
#include "glbsem.h"
#include <errno.h>
#if defined(_WIN32)
#include "io.h"
#endif
#include "slog.h"
/************************************************************************/
/* Do not change w/o testing */
#define OLDEST_STRING " OLDEST DATA STARTS BELOW"
/************************************************************************/
/* Local function prototypes */
/************************************************************************/
static ST_VOID printWipe (FILE *fh);
static ST_VOID printWrap (FILE *fh);
static ST_VOID printStart (FILE *fh);
static ST_VOID slogFileErrorPrint(ST_CHAR *text, ST_CHAR *fname);
static ST_LONG findOldestMessage(LOG_CTRL *lc, FILE *fh);
static ST_INT copy_named_files (LOG_CTRL *lc, SD_CONST ST_CHAR *SD_CONST dest,
SD_CONST ST_CHAR *SD_CONST src);
static ST_INT copy_named_files_ex (LOG_CTRL *lc, SD_CONST ST_CHAR *SD_CONST dest,
SD_CONST ST_CHAR *SD_CONST src);
static ST_VOID chk_slog_service (LOG_CTRL *lc);
/************************************************************************/
/* slogFile */
/************************************************************************/
ST_VOID slogFile (LOG_CTRL *lc, SD_CONST ST_INT logType,
SD_CONST ST_CHAR *SD_CONST logTypeStr,
SD_CONST ST_CHAR *SD_CONST sourceFile,
SD_CONST ST_INT lineNum,
SD_CONST ST_INT bufLen, SD_CONST ST_CHAR *buf)
{
FILE *fh;
struct stat fileStat;
ST_LONG seekPos;
ST_LONG currPos;
ST_ULONG fileSize;
ST_CHAR slogHdr[SLOG_MAX_HDR + 1];
/*ST_INT wrap; */
if (!(lc->fc.state & FIL_STATE_OPEN)) /* if not already opened */
{
/* Need to open the file */
if (lc->fc.ctrl & FIL_CTRL_NO_APPEND) /* If overwrite is requested */
fh = NULL;
else
lc->fc.fp = fh = fopen (lc->fc.fileName,"r+");
if (!fh) /* File must not exist, or overwrite requested */
{ /* try creating it */
lc->fc.fp = fh = fopen (lc->fc.fileName,"w+");
if (!fh)
{
slogFileErrorPrint ("OPEN",lc->fc.fileName);
return;
}
}
/* We have successfully opened the log file */
lc->fc.state = FIL_STATE_OPEN;
if (lc->fc.ctrl & FIL_CTRL_SETBUF_EN) /* If setbuf desired */
setbuf (fh,NULL); /* no buffering, please */
/* If appending, need to get to the start write position */
if ((lc->fc.ctrl & FIL_CTRL_NO_APPEND) == 0)
{
/* Check the current file size, see if we can just append */
if (fstat (fileno(fh), &fileStat))
{
slogFileErrorPrint ("SEEK",lc->fc.fileName);
return;
}
fileSize = fileStat.st_size;
if (fileSize < lc->fc.maxSize)
seekPos = (ST_LONG) fileSize;
else
{
seekPos = findOldestMessage (lc, fh);
lc->fc.state |= FIL_STATE_NEED_WIPE; /* flag to show we wrapped */
}
if (fseek (fh,seekPos,SEEK_SET))
{
slogFileErrorPrint ("SEEK",lc->fc.fileName);
return;
}
}
/* Print the 'started' message */
if (!(lc->fc.ctrl & FIL_CTRL_NO_LOG_HDR)) /* log file header */
printStart (fh);
}/* File not opened */
else
{ /* The file has already been opened for logging */
fh = lc->fc.fp;
if (lc->fc.ctrl & FIL_CTRL_WRAP_EN) /* if wrap allowed */
{
/* Check to see the position of the file to see if we need to wrap it */
currPos = ftell (fh);
if (currPos == -1L)
{
slogFileErrorPrint ("TELL",lc->fc.fileName);
return;
}
/* Check to see if we need to wrap - currPos is where we would write */
if (((ST_ULONG) currPos > lc->fc.maxSize))
{
/* Yep, need to wrap - cut off the rest of the file to avoid trailing */
#if defined(MSDOS) || defined(__OS2__) || defined(_WIN32)
if (chsize (fileno(fh), currPos))
{
slogFileErrorPrint ("CHSIZE",lc->fc.fileName);
}
#else
#ifndef __ECOS
if (ftruncate (fileno(fh), currPos))
{
slogFileErrorPrint ("FTRUNCATE",lc->fc.fileName);
}
#endif
#endif
/* Seek to start of file */
if (fseek (fh,0L,SEEK_SET))
{
slogFileErrorPrint ("SEEK",lc->fc.fileName);
return;
}
/* Print wrap message at top */
seekPos = 0;
printWrap (fh);
lc->fc.state |= FIL_STATE_NEED_WIPE; /* flag to show we wrapped */
} /* need to wrap */
} /* Wrap not disabled */
} /* File already opened */
/* Ok, the file is open and the pointer set to where we log the next */
/* message, any wrap has been printed - time to log the info */
/* Now print the message header */
slogSetHdr (lc, logType, logTypeStr, sourceFile, lineNum, slogHdr, "\n");
fprintf (fh,"%s", slogHdr);
/* Now print the message buffer */
fprintf (fh,"%s", buf);
/* Now print 'wipe bar', if file has wrapped some time in the past */
/* and if we are supposed to do the wipe */
if (lc->fc.state & FIL_STATE_NEED_WIPE &&
lc->fc.ctrl & FIL_CTRL_WIPE_EN)
{
currPos = ftell (fh);
if (currPos == -1L)
{
slogFileErrorPrint ("TELL",lc->fc.fileName);
return;
}
/* Print the wipe bar */
lc->fc.wipeFilePos = currPos;
printWipe (fh);
/* Seek to the current write position */
if (fseek (fh,currPos,SEEK_SET))
{
slogFileErrorPrint ("SEEK",lc->fc.fileName);
return;
}
} /* Need to print wipe bar */
/* Try to not lose log data */
fflush (fh);
/* Check for paranoid user - wants to close && reopen */
if (lc->fc.ctrl & FIL_CTRL_HARD_FLUSH)
{
currPos = ftell (fh);
if (currPos == -1L)
{
slogFileErrorPrint ("TELL",lc->fc.fileName);
return;
}
/* Close the file */
fclose (fh);
/* Re-open the file */
lc->fc.fp = fh = fopen (lc->fc.fileName,"r+");
if (!fh) /* better exist */
{
slogFileErrorPrint ("OPEN",lc->fc.fileName);
lc->fc.state &= ~FIL_STATE_OPEN;
return;
}
if (lc->fc.ctrl & FIL_CTRL_SETBUF_EN) /* If setbuf desired */
setbuf (fh,NULL); /* no buffering, please */
/* Seek to current write position */
if (fseek (fh,currPos,SEEK_SET))
{
slogFileErrorPrint ("SEEK",lc->fc.fileName);
return;
}
} /* if hard flush enabled */
}
/************************************************************************/
/* slogCloseFile */
/************************************************************************/
ST_VOID slogCloseFile (LOG_CTRL *lc)
{
S_GS_INIT ();
S_LOCK_UTIL_RESOURCES ();
if (lc->fc.state & FIL_STATE_OPEN)
{
if (fclose (lc->fc.fp))
{
fprintf (stderr,"\n *** LOG FILE CLOSE PROBLEM (%s) : ",
lc->fc.fileName);
return;
}
lc->fc.state &= ~FIL_STATE_OPEN;
}
S_UNLOCK_UTIL_RESOURCES ();
}
/************************************************************************/
/* slogCloneFile */
/************************************************************************/
ST_VOID slogCloneFile (LOG_CTRL *lc, SD_CONST ST_CHAR *newFile)
{
ST_LONG currPos;
FILE *fh;
S_GS_INIT ();
S_LOCK_UTIL_RESOURCES ();
fh = lc->fc.fp;
if (lc->fc.state & FIL_STATE_OPEN)
{
currPos = ftell (fh);
if (currPos == -1L)
{
slogFileErrorPrint ("TELL",lc->fc.fileName);
S_UNLOCK_UTIL_RESOURCES ();
return;
}
/* Close the file */
fclose (fh);
/* Copy the log file */
copy_named_files (lc, newFile, lc->fc.fileName);
/* Re-open the file at the old position */
lc->fc.fp = fh = fopen (lc->fc.fileName,"r+");
if (!fh) /* better exist */
{
slogFileErrorPrint ("OPEN",lc->fc.fileName);
S_UNLOCK_UTIL_RESOURCES ();
return;
}
if (lc->fc.ctrl & FIL_CTRL_SETBUF_EN) /* If setbuf desired */
setbuf (fh,NULL); /* no buffering, please */
/* Seek to current write position */
if (fseek (fh,currPos,SEEK_SET))
{
slogFileErrorPrint ("SEEK",lc->fc.fileName);
S_UNLOCK_UTIL_RESOURCES ();
return;
}
}
else /* log file not opened, just copy it */
copy_named_files (lc, newFile, lc->fc.fileName);
S_UNLOCK_UTIL_RESOURCES ();
}
/************************************************************************/
/* slogCloneFileEx */
/************************************************************************/
ST_VOID slogCloneFileEx (LOG_CTRL *lc, SD_CONST ST_CHAR *newFile)
{
ST_LONG currPos;
FILE *fh;
S_GS_INIT ();
S_LOCK_UTIL_RESOURCES ();
fh = lc->fc.fp;
if (lc->fc.state & FIL_STATE_OPEN)
{
currPos = ftell (fh);
if (currPos == -1L)
{
slogFileErrorPrint ("TELL",lc->fc.fileName);
S_UNLOCK_UTIL_RESOURCES ();
return;
}
/* Close the file */
fclose (fh);
/* Copy the log file */
copy_named_files_ex (lc, newFile, lc->fc.fileName);
/* Re-open the file at the old position */
lc->fc.fp = fh = fopen (lc->fc.fileName,"r+");
if (!fh) /* better exist */
{
slogFileErrorPrint ("OPEN",lc->fc.fileName);
S_UNLOCK_UTIL_RESOURCES ();
return;
}
if (lc->fc.ctrl & FIL_CTRL_SETBUF_EN) /* If setbuf desired */
setbuf (fh,NULL); /* no buffering, please */
/* Seek to current write position */
if (fseek (fh,currPos,SEEK_SET))
{
slogFileErrorPrint ("SEEK",lc->fc.fileName);
S_UNLOCK_UTIL_RESOURCES ();
return;
}
}
else /* log file not opened, just copy it */
copy_named_files_ex (lc, newFile, lc->fc.fileName);
S_UNLOCK_UTIL_RESOURCES ();
}
/************************************************************************/
/* slogDeleteFile */
/************************************************************************/
ST_VOID slogDeleteFile (LOG_CTRL *lc)
{
S_GS_INIT ();
S_LOCK_UTIL_RESOURCES ();
/* first close the log file */
slogCloseFile (lc);
/* Now delete it */
remove (lc->fc.fileName);
S_UNLOCK_UTIL_RESOURCES ();
}
/************************************************************************/
/* findOldestMessage */
/************************************************************************/
static ST_LONG findOldestMessage (LOG_CTRL *lc, FILE *fh)
{
ST_CHAR idxFileName[S_MAX_PATH];
FILE *idxFh;
ST_CHAR buf[200];
ST_LONG startPos;
ST_LONG currPos;
ST_INT count;
ST_INT cmpLen;
cmpLen = strlen(OLDEST_STRING);
/* Need to find the start position by looking for the 'OLDEST' message. */
/* See if we have an index file and seek position ... */
if (slog_get_index_file_name (lc, idxFileName, sizeof(idxFileName)) == SD_SUCCESS)
{
idxFh = fopen (idxFileName,"r");
if (idxFh)
{
count = fscanf (idxFh, "%ld", &startPos);
fclose (idxFh);
if (count == 1)
{
if (fseek (fh, startPos, SEEK_SET) == 0)
{
fgets (buf,200,fh);
fgets (buf,200,fh);
fgets (buf,200,fh);
if (fgets (buf,200,fh))
{
if (buf[10] == 'O' && !strncmp (buf,OLDEST_STRING, cmpLen))
return (startPos);
}
}
}
}
}
/* Darn, need to start at the top and find it */
fseek (fh, 0, SEEK_SET);
while (SD_TRUE)
{
currPos = ftell (fh);
if (!fgets (buf,200,fh))
break;
chk_slog_service (lc);
/* Is this the position with the marker string? */
if (buf[10] == 'O' && !strncmp (buf,OLDEST_STRING, cmpLen))
return (currPos);
}
/* No oldest found, go to the start of the file */
fseek (fh, 0, SEEK_END);
currPos = ftell (fh);
return (currPos);
}
/************************************************************************/
/* slog_get_index_file_name */
/************************************************************************/
ST_RET slog_get_index_file_name (LOG_CTRL *lc, ST_CHAR *dest, ST_INT destLen)
{
ST_CHAR *src;
ST_INT srcLen;
src = lc->fc.fileName;
srcLen = strlen(src);
if (!src || srcLen == 0)
return (SD_FAILURE);
if (!dest || destLen < (srcLen+4)) /* +4 for len of ".sli" */
return (SD_FAILURE);
while (SD_TRUE)
{
*dest = *src;
if (*dest == 0) /* End of string ... */
break;
if (*dest == '.')
*dest = '_';
++src;
++dest;
}
strcat (dest, ".sli");
return (SD_SUCCESS);
}
/************************************************************************/
/* printStart */
/************************************************************************/
static ST_VOID printStart (FILE *fh)
{
time_t t;
t = time(NULL);
fprintf (fh,"\n\n***********************************************************");
fprintf (fh,"\n LOGGING STARTED %s", ctime(&t));
fprintf (fh,"***********************************************************");
}
/************************************************************************/
/* printWrap */
/************************************************************************/
static ST_VOID printWrap (FILE *fh)
{
time_t t;
t = time(NULL);
fprintf (fh,"\n***********************************************************");
fprintf (fh,"\n FILE WRAPPED %s", ctime(&t));
fprintf (fh,"***********************************************************");
}
/************************************************************************/
/* printWipe */
/************************************************************************/
static ST_VOID printWipe (FILE *fh)
{
fprintf (fh,"\n\n***********************************************************");
fprintf (fh,"\n%s",OLDEST_STRING);;
fprintf (fh,"\n***********************************************************\n\n");
}
/************************************************************************/
/* slogFileErrorPrint */
/************************************************************************/
static ST_VOID slogFileErrorPrint (ST_CHAR *text, ST_CHAR *fname)
{
fprintf (stderr,"\n*** LOG FILE %s ERROR (%s) : ",text,fname);
fprintf (stderr,"%s",strerror(errno));
}
/************************************************************************/
/* copy_named_files */
/************************************************************************/
#define FILE_READ_SIZE 1000
static ST_INT copy_named_files (LOG_CTRL *lc,
SD_CONST ST_CHAR *SD_CONST dest, SD_CONST ST_CHAR *SD_CONST src)
{
FILE *dest_fp;
FILE *src_fp;
ST_INT ret;
ST_CHAR buf[FILE_READ_SIZE+1];
ST_INT bytes_read;
ST_INT bytes_written;
if (!(src_fp = fopen (src,"rb")))
return (SD_FAILURE);
if (!(dest_fp = fopen (dest,"wb")))
{
fclose (src_fp);
return (SD_FAILURE);
}
ret = SD_SUCCESS;
while (SD_TRUE)
{
if (!(bytes_read = fread (buf,1,FILE_READ_SIZE,src_fp)))
break;
bytes_written = fwrite (buf,1,bytes_read,dest_fp);
if (bytes_read != bytes_written)
{
ret = SD_FAILURE;
break;
}
chk_slog_service (lc);
}
if (fclose (src_fp))
ret = SD_FAILURE;
if (fclose (dest_fp))
ret = SD_FAILURE;
return (ret);
}
/************************************************************************/
/* copy_named_files_ex */
/************************************************************************/
static ST_INT copy_named_files_ex (LOG_CTRL *lc, SD_CONST ST_CHAR *SD_CONST dest,
SD_CONST ST_CHAR *SD_CONST src)
{
FILE *dest_fp;
FILE *src_fp;
ST_INT ret;
ST_CHAR buf[200+1];
ST_LONG currPos;
ST_LONG oldestPos;
if (!(src_fp = fopen (src,"rb")))
return (SD_FAILURE);
oldestPos = findOldestMessage (lc, src_fp);
if (fseek (src_fp, oldestPos, SEEK_SET))
{
slogFileErrorPrint ("SEEK",lc->fc.fileName);
fclose (src_fp);
return (SD_FAILURE);
}
if (!(dest_fp = fopen (dest,"wb")))
{
fclose (src_fp);
return (SD_FAILURE);
}
ret = SD_SUCCESS;
while (SD_TRUE)
{
if (!fgets (buf,200,src_fp))
break;
fputs (buf,dest_fp);
chk_slog_service (lc);
}
if (fclose (src_fp))
ret = SD_FAILURE;
if (ret == SD_SUCCESS)
{
if (oldestPos > 0)
{
if (!(src_fp = fopen (src,"rb")))
{
fclose (dest_fp);
return (SD_FAILURE);
}
currPos = 0;
while (currPos < oldestPos)
{
if (!fgets (buf,200,src_fp))
break;
fputs (buf,dest_fp);
currPos = ftell (src_fp);
if (currPos == -1L)
{
slogFileErrorPrint ("TELL",lc->fc.fileName);
fclose (src_fp);
fclose (dest_fp);
return (SD_FAILURE);
}
chk_slog_service (lc);
}
}
}
if (fclose (src_fp))
ret = SD_FAILURE;
if (fclose (dest_fp))
ret = SD_FAILURE;
return (ret);
}
/************************************************************************/
/* chk_slog_service */
/************************************************************************/
static ST_INT slog_service_count;
static ST_VOID chk_slog_service (LOG_CTRL *lc)
{
ST_UINT32 logCtrlSave;
/* Allow the application to do it's thing during a slow operation */
if (slog_service_fun)
{
if (++slog_service_count > 10)
{
slog_service_count = 0;
/* do not allow file logging during this operation */
logCtrlSave = lc->logCtrl;
lc->logCtrl &= ~LOG_FILE_EN;
(*slog_service_fun) ();
lc->logCtrl = logCtrlSave;
}
}
}

362
mmslib/slog/sloghex.c Normal file
View File

@@ -0,0 +1,362 @@
/************************************************************************/
/* SISCO SOFTWARE MODULE HEADER *****************************************/
/************************************************************************/
/* (c) Copyright Systems Integration Specialists Company, Inc., */
/* 1993-2007, All Rights Reserved */
/* */
/* MODULE NAME : sloghex.c */
/* PRODUCT(S) : SLOG */
/* */
/* MODULE DESCRIPTION : */
/* */
/* GLOBAL FUNCTIONS DEFINED IN THIS MODULE : */
/* */
/* MODIFICATION LOG : */
/* Date Who Rev Comments */
/* -------- --- ------ ------------------------------------------- */
/* 01/15/07 EJV 15 Chg S_LOCK_RESOURCES to S_LOCK_UTIL_RESOURCES*/
/* 08/18/06 JRB 14 Chk _slog_remote_fun along with other ptrs. */
/* 05/23/05 EJV 13 doSlog corr: replaced LOG_IPC_EN with */
/* LOG_IPC_LISTEN_EN || LOG_IPC_CALL_EN */
/* 11/05/04 EJV 12 Added check for LOG_IPC_EN. */
/* 05/18/04 MDE 11 Removed LOG_IPC_SUPPORT #ifdef's */
/* 03/11/04 GLB 10 Remove "thisFileName" */
/* 02/17/03 JRB 09 Del system includes (using sysincs.h). */
/* 03/27/01 MDE 08 Added _slogStr */
/* 09/13/99 MDE 07 Added SD_CONST modifiers */
/* 11/11/98 DSF 06 Minor changes to _slog_dyn_log_fun */
/* 10/09/98 MDE 05 Put back center space per JB request */
/* 10/08/98 MDE 04 Migrated to updated SLOG interface */
/* 04/07/98 MDE 03 Minor warning cleanup */
/* 10/06/97 DSF 02 Added thisFileName */
/* 05/28/97 DSF 01 Added IPC logging capability */
/* 04/02/97 DTL 7.00 MMSEASE 7.0 release. See MODL70.DOC for */
/* history. */
/************************************************************************/
#include "glbtypes.h"
#include "sysincs.h"
#include "glbsem.h"
#include "slog.h"
#define cvt_nibble(a) ((ST_UCHAR) ((a) > 9 ? (a) + 'A' - 10 : (a) + '0'))
#define DEBUG_BUF_LEN 100
#define CHAR_PER_LINE 75
/************************************************************************/
/* slogHex */
/* Main HEX logging function, typically called via macro */
/* Create the HEX strings && pass to memory & file logging */
/* functions if enabled */
/************************************************************************/
ST_VOID slogHex (LOG_CTRL *lc,
SD_CONST ST_INT logType,
SD_CONST ST_CHAR *SD_CONST fileName,
SD_CONST ST_INT lineNum,
SD_CONST ST_INT numBytes,
SD_CONST ST_VOID *hexData)
{
_slogHex (lc, numBytes, hexData);
}
ST_VOID _slogHex (LOG_CTRL *lc,
ST_INT numBytes,
SD_CONST ST_VOID *hexData)
{
ST_INT i;
ST_INT ascii_index;
ST_INT hex_index;
ST_CHAR debug_buf[DEBUG_BUF_LEN+1]; /* output buffer */
ST_INT curlen;
ST_UCHAR ch;
ST_UCHAR hex;
ST_LONG addr;
ST_UINT filCtrlSave;
ST_UINT memCtrlSave;
ST_UCHAR *buf;
S_GS_INIT ();
S_LOCK_UTIL_RESOURCES ();
addr = 0;
/* Make the compiler happy */
buf = (ST_UCHAR *) hexData;
/* Make sure the LOG_CTRL pointer is not NULL */
if (!lc)
{
S_UNLOCK_UTIL_RESOURCES ();
return;
}
/* Check to see if any logging is enabled AND dynamic user logging */
/* function pointer not set */
if (!(lc->logCtrl & (LOG_FILE_EN | LOG_MEM_EN | LOG_IPC_EN)) &&
!slog_dyn_log_fun && !_slog_dyn_log_fun &&
!slog_remote_fun && !_slog_remote_fun)
{
S_UNLOCK_UTIL_RESOURCES ();
return;
}
/* Remember the state of the wipe/wrap/header enable flags */
/* so that we can restore them later */
filCtrlSave = lc->fc.ctrl & (FIL_CTRL_WIPE_EN |
FIL_CTRL_WRAP_EN |
FIL_CTRL_MSG_HDR_EN);
memCtrlSave = lc->mc.ctrl & MEM_CTRL_MSG_HDR_EN;
/* No hdr or wipe during a hex dump (allow wrap for first line if req'd)*/
lc->fc.ctrl &= ~(FIL_CTRL_WIPE_EN | FIL_CTRL_MSG_HDR_EN);
lc->mc.ctrl &= ~MEM_CTRL_MSG_HDR_EN;
/* Also turn on HEX flag bit for memory logging */
lc->mc.ctrl |= MEM_CTRL_HEX_LOG;
/* OK, now start the dump, line by line */
while (numBytes)
{
curlen = min(numBytes,16); /* # char's in current line */
for (i = 0; i < DEBUG_BUF_LEN; ++i)
debug_buf[i] = ' ';
sprintf (debug_buf,"%05lX ",addr);/* data offset */
hex_index = 7; /* where to put hex data */
ascii_index = 57; /* where to put ascii conversion */
debug_buf[ascii_index++] = '*';
for (i = 0; i < curlen; i++) /* for each byte in this line */
{
ch = *buf++; /* get next character */
hex = (ch >> 4) & (ST_UCHAR) 0x0f;/* write HEX chars for the byte */
hex = cvt_nibble(hex);
debug_buf[hex_index++] = hex;
hex = ch & (ST_UCHAR) 0x0f;
hex = cvt_nibble(hex);
debug_buf[hex_index++] = hex;
++hex_index; /* space between bytes */
if (i == 7)
++hex_index;
if (isprint(ch)) /* print ASCII portion */
debug_buf[ascii_index] = ch;
else
debug_buf[ascii_index] = '.'; /* just put a '.' there */
ascii_index++;
}
debug_buf[ascii_index++] = '*';
debug_buf[ascii_index++] = 0;
addr += 16; /* prepare for next line */
numBytes -= curlen;
/* debug_buf now contains the hex/ascii line to be logged */
/* for the last line to be logged, turn wipe back on */
if (!numBytes)
{
lc->fc.ctrl |= (filCtrlSave & FIL_CTRL_WIPE_EN);
}
if (lc->logCtrl & LOG_FILE_EN) /* File Logging enabled */
{
slogFile (lc, SLOG_CONT, NULL, NULL, 0, strlen(debug_buf), debug_buf);
}
if (lc->logCtrl & LOG_MEM_EN) /* Memory Logging enabled */
{
slogMem (lc, SLOG_CONT, NULL, NULL, 0, strlen(debug_buf), debug_buf);
}
if ((lc->logCtrl & LOG_IPC_LISTEN_EN) || (lc->logCtrl & LOG_IPC_CALL_EN))
/* IPC Logging enabled (listen, calling, or both modes) */
{
slogIpc (lc, SLOG_CONT, NULL, NULL, 0, strlen(debug_buf), debug_buf);
}
/* If the user has set up a dynamic log display function, call it */
if (slog_dyn_log_fun)
{
(*slog_dyn_log_fun)(lc, SLOG_CONT, NULL, 0,
strlen(debug_buf), debug_buf);
}
if (_slog_dyn_log_fun)
{
(*_slog_dyn_log_fun)(lc, slogTimeText, SLOG_CONT, NULL, NULL, 0,
strlen(debug_buf), debug_buf);
}
/* If the user has set up a remote logging function, call it */
if (slog_remote_fun)
{
(*slog_remote_fun)(slogRemoteFlags, lc, SLOG_CONT,
NULL, 0,
strlen(debug_buf), debug_buf);
}
if (_slog_remote_fun)
{
(*_slog_remote_fun)(slogRemoteFlags, lc, SLOG_CONT, NULL,
NULL, 0,
strlen(debug_buf), debug_buf);
}
/* Don't want to wrap the file in the middle of a hex dump */
lc->fc.ctrl &= ~FIL_CTRL_WRAP_EN;
}
/* All done, restore the flag state bits */
lc->fc.ctrl |= filCtrlSave;
lc->mc.ctrl |= memCtrlSave;
lc->mc.ctrl &= ~MEM_CTRL_HEX_LOG;
S_UNLOCK_UTIL_RESOURCES ();
}
/************************************************************************/
/* slogStr */
/************************************************************************/
ST_VOID _slogStr (LOG_CTRL *lc, ST_CHAR *strData)
{
ST_INT i;
ST_INT ascii_index;
ST_CHAR debug_buf[DEBUG_BUF_LEN+1]; /* output buffer */
ST_INT curlen;
ST_UCHAR ch;
ST_UINT filCtrlSave;
ST_UINT memCtrlSave;
ST_INT numBytes;
S_GS_INIT ();
S_LOCK_UTIL_RESOURCES ();
/* Make sure the LOG_CTRL pointer is not NULL */
if (!lc)
{
S_UNLOCK_UTIL_RESOURCES ();
return;
}
/* Check to see if any logging is enabled AND dynamic user logging */
/* function pointer not set */
if (!(lc->logCtrl & (LOG_FILE_EN | LOG_MEM_EN | LOG_IPC_EN)) &&
!slog_dyn_log_fun && !_slog_dyn_log_fun &&
!slog_remote_fun && !_slog_remote_fun)
{
S_UNLOCK_UTIL_RESOURCES ();
return;
}
/* Remember the state of the wipe/wrap/header enable flags */
/* so that we can restore them later */
filCtrlSave = lc->fc.ctrl & (FIL_CTRL_WIPE_EN |
FIL_CTRL_WRAP_EN |
FIL_CTRL_MSG_HDR_EN);
memCtrlSave = lc->mc.ctrl & MEM_CTRL_MSG_HDR_EN;
/* No hdr or wipe during a hex dump (allow wrap for first line if req'd)*/
lc->fc.ctrl &= ~(FIL_CTRL_WIPE_EN | FIL_CTRL_MSG_HDR_EN);
lc->mc.ctrl &= ~MEM_CTRL_MSG_HDR_EN;
/* OK, now start the dump, line by line */
numBytes = strlen (strData);
while (numBytes)
{
curlen = min (numBytes,CHAR_PER_LINE); /* # char's in current line */
ascii_index = 0; /* where to put ascii conversion */
for (i = 0; i < curlen; i++) /* for each byte in this line */
{
ch = *strData++; /* get next character */
if (isprint(ch)) /* print ASCII portion */
debug_buf[ascii_index] = ch;
else if (ch == '\n')
{
debug_buf[ascii_index] = ch;
++i;
break;
} /* end of this line */
else if (ch == '\t')
debug_buf[ascii_index] = ch;
else
debug_buf[ascii_index] = '.'; /* just put a '.' there */
ascii_index++;
}
debug_buf[ascii_index++] = 0;
numBytes -= i;
/* debug_buf now contains the ascii line to be logged */
/* for the last line to be logged, turn wipe back on */
if (!numBytes)
{
lc->fc.ctrl |= (filCtrlSave & FIL_CTRL_WIPE_EN);
}
if (lc->logCtrl & LOG_FILE_EN) /* File Logging enabled */
{
slogFile (lc, SLOG_CONT, NULL, NULL, 0, strlen(debug_buf), debug_buf);
}
if (lc->logCtrl & LOG_MEM_EN) /* Memory Logging enabled */
{
slogMem (lc, SLOG_CONT, NULL, NULL, 0, strlen(debug_buf), debug_buf);
}
if ((lc->logCtrl & LOG_IPC_LISTEN_EN) || (lc->logCtrl & LOG_IPC_CALL_EN))
/* IPC Logging enabled (listen, calling, or both modes) */
{
slogIpc (lc, SLOG_CONT, NULL, NULL, 0, strlen(debug_buf), debug_buf);
}
/* If the user has set up a dynamic log display function, call it */
if (slog_dyn_log_fun)
{
(*slog_dyn_log_fun)(lc, SLOG_CONT, NULL, 0,
strlen(debug_buf), debug_buf);
}
if (_slog_dyn_log_fun)
{
(*_slog_dyn_log_fun)(lc, slogTimeText, SLOG_CONT, NULL, NULL, 0,
strlen(debug_buf), debug_buf);
}
/* If the user has set up a remote logging function, call it */
if (slog_remote_fun)
{
(*slog_remote_fun)(slogRemoteFlags, lc, SLOG_CONT,
NULL, 0,
strlen(debug_buf), debug_buf);
}
if (_slog_remote_fun)
{
(*_slog_remote_fun)(slogRemoteFlags, lc, SLOG_CONT, NULL,
NULL, 0,
strlen(debug_buf), debug_buf);
}
/* Don't want to wrap the file in the middle of a hex dump */
lc->fc.ctrl &= ~FIL_CTRL_WRAP_EN;
}
/* All done, restore the flag state bits */
lc->fc.ctrl |= filCtrlSave;
lc->mc.ctrl |= memCtrlSave;
lc->mc.ctrl &= ~MEM_CTRL_HEX_LOG;
S_UNLOCK_UTIL_RESOURCES ();
}

124
mmslib/slog/slogipcs.c Normal file
View File

@@ -0,0 +1,124 @@
/************************************************************************/
/* SISCO SOFTWARE MODULE HEADER *****************************************/
/************************************************************************/
/* (c) Copyright Systems Integration Specialists Company, Inc., */
/* 2004 - 2007, All Rights Reserved */
/* */
/* MODULE NAME : slogipcs.c */
/* PRODUCT(S) : SLOG */
/* */
/* MODULE DESCRIPTION : */
/* */
/* GLOBAL FUNCTIONS DEFINED IN THIS MODULE : */
/* */
/* MODIFICATION LOG : */
/* Date Who Rev Comments */
/* -------- --- ------ ------------------------------------------- */
/* 08/04/08 MDE 46 Added slogIpcEventEx */
/* 07/25/08 MDE 06 Moved slogIpcCtx into LOG_CTRL */
/* 05/30/08 JRB 05 Fix ..RawData args. */
/* 10/04/07 MDE 04 Added slogIpcCallingEnable */
/* 01/08/07 EJV 04 slogIpcStop: added lc param. */
/* 11/03/05 EJV 02 Added slogIpcEvent. */
/* 02/22/05 JRB 02 slogIpc: add SD_CONST to some args. */
/* 05/18/04 MDE 01 Initial Release */
/************************************************************************/
#include "glbtypes.h"
#include "sysincs.h"
#include "stime.h"
#include "slog.h"
#include "gensock2.h"
/************************************************************************/
SLOGIPC_CMD *slogIpcCmdList;
ST_INT slogIpcMaxCmdPend = 1;
/************************************************************************/
/* slogIpcInit */
/************************************************************************/
ST_RET slogIpcInit (LOG_CTRL *lc)
{
return (SD_SUCCESS);
}
/************************************************************************/
/* slogIpcCallingEnable */
/************************************************************************/
ST_VOID slogIpcCallingEnable (ST_BOOLEAN enable)
{
}
ST_VOID slogIpcCallingEnableEx (struct log_ctrl *lc, ST_BOOLEAN enable)
{
}
/************************************************************************/
/* slogIpcStop */
/************************************************************************/
ST_RET slogIpcStop (LOG_CTRL *lc)
{
return (SD_SUCCESS);
}
/************************************************************************/
/* slogIpcEvent */
/************************************************************************/
ST_RET slogIpcEvent (ST_VOID)
{
return (SD_SUCCESS);
}
ST_RET slogIpcEventEx (LOG_CTRL *lc)
{
return (SD_SUCCESS);
}
/************************************************************************/
/* slogIpc */
/************************************************************************/
ST_VOID slogIpc (LOG_CTRL *lc, ST_INT logType,
SD_CONST ST_CHAR *SD_CONST logTypeStr,
SD_CONST ST_CHAR *SD_CONST sourceFile,
ST_INT lineNum, ST_INT bufLen,
ST_CHAR *buf)
{
}
/************************************************************************/
/* slog_ipc_std_cmd_fun */
/************************************************************************/
ST_VOID slog_ipc_std_cmd_fun (GEN_SOCK *pSock, GEN_SOCK_DATA *sockData,
ST_UINT32 msgType, ST_UINT32 msgDataLen,
ST_CHAR *msgData)
{
}
/************************************************************************/
/* slogIpcSendData */
/************************************************************************/
ST_VOID slogIpcSendData (GEN_SOCK *pSock, ST_UINT32 msgType, ST_INT dataLen, ST_UCHAR *data)
{
}
/************************************************************************/
/* slogIpcSendRawData */
/************************************************************************/
ST_VOID slogIpcSendRawData (LOG_CTRL *lc, ST_INT bufLen, ST_CHAR *buf, ST_BOOLEAN sendAlways)
{
}

434
mmslib/slog/slogmem.c Normal file
View File

@@ -0,0 +1,434 @@
/************************************************************************/
/* SISCO SOFTWARE MODULE HEADER *****************************************/
/************************************************************************/
/* (c) Copyright Systems Integration Specialists Company, Inc., */
/* 1993-2007, All Rights Reserved */
/* */
/* MODULE NAME : slogmem.c */
/* PRODUCT(S) : SLOG */
/* */
/* MODULE DESCRIPTION : */
/* */
/* GLOBAL FUNCTIONS DEFINED IN THIS MODULE : */
/* */
/* MODIFICATION LOG : */
/* Date Who Rev Comments */
/* -------- --- ------ ------------------------------------------- */
/* 01/15/07 EJV 16 Chg S_LOCK_RESOURCES to S_LOCK_UTIL_RESOURCES*/
/* 07/13/05 JRB 15 slogGetMemMsg: skip timestamp on continuation*/
/* logs & indent 4 chars; indent hex logs. */
/* getMsgBuffer: make size based on max msg. */
/* 02/25/05 MDE 14 Added \n */
/* 01/10/05 MDE 13 Cleanup dump a bit */
/* 07/09/04 EJV 12 All systems: one time/date format in slog hdr*/
/* 03/12/04 GLB 11 Removed "thisFileName" */
/* 02/17/03 JRB 10 Del system includes (using sysincs.h). */
/* 05/24/01 JRB 09 Chg chk_calloc to calloc. This always compiled*/
/* with !DEBUG_SISCO, screws up link. */
/* 10/13/00 EJV 08 Moved glbsem.h below sysincs.h. */
/* 09/13/99 MDE 07 Added SD_CONST modifiers */
/* 02/09/99 DSF 06 Thread-safe slogMem () */
/* Remove extraneous newline in slogMemDump() */
/* 10/23/98 MDE 05 No blank line bet. logs if LOG_NO_HEADER_CR */
/* 10/16/98 DSF 04 Spelling */
/* 10/08/98 MDE 03 Migrated to updated SLOG interface */
/* 06/15/98 MDE 02 Changes to allow compile under C++ */
/* 09/18/97 DSF 01 In slogMemInit (), clear chk_debug_en before */
/* calling chk_calloc () and restore it after. */
/* 04/02/97 DTL 7.00 MMSEASE 7.0 release. See MODL70.DOC for */
/* history. */
/************************************************************************/
#include "glbtypes.h"
#include "sysincs.h"
#include "glbsem.h"
#include "mem_chk.h"
#include "slog.h"
#include "qmem.h"
/************************************************************************/
/* Some mysterious looking function pointers */
/************************************************************************/
ST_VOID *(*slogAllocBuf) (ST_INT size) = qMemAlloc;
ST_VOID (*slogFreeBuf) (ST_VOID *buf) = qMemFree;
/************************************************************************/
/* slogMem */
/************************************************************************/
ST_VOID slogMem (LOG_CTRL *lc,
SD_CONST ST_INT logType,
SD_CONST ST_CHAR *SD_CONST logTypeStr,
SD_CONST ST_CHAR *SD_CONST sourceFile,
SD_CONST ST_INT lineNum,
ST_INT bufLen, SD_CONST ST_CHAR *buf)
{
LOGMEM_ITEM *thisItem;
MEM_LOG_CTRL *mc;
S_GS_INIT ();
S_LOCK_UTIL_RESOURCES ();
/* get pointer to memory control structure */
mc = &lc->mc;
/* Check for initialization */
if (!(mc->state & MEM_STATE_INIT))
{
slogMemInit (lc);
}
/* Get pointer to the destination item and reset the 'next put' index */
thisItem = &mc->item[mc->nextPut];
mc->nextPut++;
if (mc->nextPut >= mc->maxItems) /* check for wraparound */
{
mc->nextPut = 0;
/* Check for autodump && clean */
if (mc->ctrl & MEM_CTRL_AUTODUMP_EN)
{
slogDumpMem (lc); /* Dump memory to log file */
slogResetMem (lc); /* Delete all contents */
}
}
/* Check to see if we need to free the string buffer */
if (thisItem->flags & LMF_USED)
{
(*slogFreeBuf) (thisItem->string);
}
/* Set flags for this item */
if (mc->ctrl & MEM_CTRL_MSG_HDR_EN)
{
thisItem->flags = LMF_HEADER | LMF_USED;
thisItem->sourceFile = sourceFile; /* save source information */
thisItem->lineNum = lineNum;
}
else
thisItem->flags = LMF_USED;
/* If this is a HEX log, remember that it is */
if (mc->ctrl & MEM_CTRL_HEX_LOG)
{
thisItem->flags |= LMF_HEX;
}
/* Save the log type information */
thisItem->logType = logType;
thisItem->logTypeStr = logTypeStr;
/* If time stamping is enabled, need to save the time */
if (lc->logCtrl & LOG_TIME_EN)
strcpy (thisItem->slogTimeText, slogTimeText);
/* Limit the string size (bufLen includes the null) */
if (bufLen > SLOG_MEM_BUF_SIZE)
{
bufLen = SLOG_MEM_BUF_SIZE;
thisItem->string = (ST_CHAR *) (*slogAllocBuf) (bufLen+1);
strncpy (thisItem->string, buf, SLOG_MEM_BUF_SIZE -1);
thisItem->string[SLOG_MEM_BUF_SIZE-1] = 0;
}
else /* no buffer size adjustments req'd */
{
thisItem->string = (ST_CHAR *) (*slogAllocBuf) (bufLen+1);
strcpy (thisItem->string, buf);
}
S_UNLOCK_UTIL_RESOURCES ();
}
/************************************************************************/
/* slogDumpMem */
/************************************************************************/
ST_VOID slogDumpMem (LOG_CTRL *lc)
{
LOGMEM_ITEM *item;
LOGMEM_ITEM *tooFar;
ST_INT count;
FILE *fh;
time_t t;
ST_CHAR fname[SLOG_MAX_FNAME + 1];
MEM_LOG_CTRL *mc;
ST_INT i;
S_GS_INIT ();
S_LOCK_UTIL_RESOURCES ();
/* get pointer to memory control structure */
mc = &lc->mc;
if (!(mc->state & MEM_STATE_INIT))
{
S_UNLOCK_UTIL_RESOURCES ();
return;
}
fh = fopen(mc->dumpFileName, "a+");
if (!fh)
fh = fopen(mc->dumpFileName, "w+");
if (fh)
{
/* Print the dump header */
t = time(NULL);
fprintf (fh,"\n\n***********************************************************");
fprintf (fh,"\n MEMORY LOG LIST %s", ctime(&t));
fprintf (fh,"***********************************************************");
count = mc->maxItems; /* just in case, for loop escape */
/* start at the last logged item, which would be 'next put' */
/* if the list has wrapped, otherwise somewhere down the list */
item = &mc->item[mc->nextPut]; /* Item to log */
tooFar = &mc->item[mc->maxItems]; /* 1 past end of array */
for (i = 0; i < count; ++i,++item) /* for each possible item */
{
if (item >= tooFar) /* check for wrap */
item = mc->item; /* go to top */
if (item->flags & LMF_USED) /* if used .. */
{
if (item->flags & LMF_HEADER)
{ /* header info is to be used */
if (!(lc->logCtrl & LOG_NO_HEADER_CR))
fprintf (fh,"\n");
if (item->logType != SLOG_CONT)
{
if (lc->logCtrl & LOG_TIME_EN) /* user wants time stamp */
fprintf (fh,"\n%s ", item->slogTimeText);
if (!(lc->logCtrl & LOG_LOGTYPE_SUPPRESS))
{
if (item->logTypeStr != NULL)
fprintf (fh,"%s ", item->logTypeStr);
else
fprintf (fh,"LogType:% 2d ", item->logType);
}
if (item->sourceFile && !(lc->logCtrl & LOG_FILENAME_SUPPRESS))
{
slogTrimFileName (fname,item->sourceFile);
fprintf (fh,"(%s %d) ", fname, item->lineNum);
}
if (!(lc->logCtrl & LOG_NO_HEADER_CR))
fprintf (fh,"\n ");
}
}
if (item->logType == SLOG_CONT)
fprintf (fh," ");
fprintf(fh,"%s",item->string);
} /* end if used */
} /* end for each possible item */
fclose(fh);
}
S_UNLOCK_UTIL_RESOURCES ();
}
/************************************************************************/
/* slogResetMem */
/************************************************************************/
ST_VOID slogResetMem (LOG_CTRL *lc)
{
LOGMEM_ITEM *item;
ST_INT i;
MEM_LOG_CTRL *mc;
S_GS_INIT ();
S_LOCK_UTIL_RESOURCES ();
/* get pointer to memory control structure */
mc = &lc->mc;
if (!(mc->state & MEM_STATE_INIT))
return;
/* just go through the list, clear the used flag && free the str buf */
item = mc->item;
for (i = 0; i < mc->maxItems; ++i, ++item)
{
if (item->flags & LMF_USED)
{
item->flags &= ~LMF_USED;
(*slogFreeBuf) (item->string);
}
}
mc->nextPut = 0;
S_UNLOCK_UTIL_RESOURCES ();
}
/************************************************************************/
/* slogMemInit */
/************************************************************************/
#define SLOG_MAX_ITEMS (0xFF00/sizeof(LOGMEM_ITEM))
ST_VOID slogMemInit (LOG_CTRL *lc)
{
MEM_LOG_CTRL *mc;
ST_UINT save_debug_en;
mc = &lc->mc;
if (!mc->maxItems)
{
fprintf (stderr,"\n Memory Logging Problem - 0 Items");
return;
}
if (mc->maxItems > SLOG_MAX_ITEMS)
{
fprintf (stderr,"\n Memory Logging Problem - Too Many Items");
mc->maxItems = SLOG_MAX_ITEMS;
}
if (qMemInit (mc->maxItems))
{
fprintf (stderr,"\n QMEM Initialization Problem");
mc->maxItems = 0;
lc->logCtrl &= ~LOG_MEM_EN;
}
else
{
/* Allocate a zero'd memory block for the item control list */
save_debug_en = chk_debug_en;
chk_debug_en = 0;
mc->item =
(LOGMEM_ITEM *) calloc (mc->maxItems, sizeof (LOGMEM_ITEM));
chk_debug_en = save_debug_en;
}
mc->state |= MEM_STATE_INIT;
}
/************************************************************************/
/* slogGetMemMsg */
/************************************************************************/
/* Need buffer big enough for max msg plus extra space for timestamp. */
/* 50 should leave plenty of safety margin. */
static ST_CHAR getMsgBuffer[SLOG_MEM_BUF_SIZE + 50];
ST_CHAR *slogGetMemMsg (LOG_CTRL *lc, SD_CONST ST_INT msgNum)
{
ST_INT i;
MEM_LOG_CTRL *mc;
ST_INT index;
S_GS_INIT ();
S_LOCK_UTIL_RESOURCES ();
/* get pointer to memory control structure */
mc = &lc->mc;
if (!(mc->state & MEM_STATE_INIT) || msgNum > mc->maxItems)
{
S_UNLOCK_UTIL_RESOURCES ();
return (NULL);
}
/* FInd the start index in the item array */
index = mc->nextPut; /* if wrapped, next put is oldest item */
if (!(mc->item[index].flags & LMF_USED)) /* but if not wrapped */
index = 0; /* oldest is item 0 */
/* Find the 'msgNum' item index (msgNum == 0 means oldest item) */
for (i = 0; i < msgNum; ++i)
{
++index;
if (index >= mc->maxItems) /* check for wraparound */
index = 0;
}
if ((mc->item[index].flags & LMF_USED)) /* if used ... */
{
/* too easy! return (mc->item[index].string); */
if (lc->logCtrl & LOG_TIME_EN)
{
if (mc->item[index].flags & LMF_HEADER)
{
if (mc->item[index].logType == SLOG_CONT)
sprintf (getMsgBuffer," %s", mc->item[index].string); /* indent 4 char*/
else
sprintf (getMsgBuffer,"%s: %s", &mc->item[index].slogTimeText[11],
mc->item[index].string);
}
else if (mc->item[index].flags & LMF_HEX)
sprintf (getMsgBuffer," %s", mc->item[index].string); /* indent 4 char*/
else
sprintf (getMsgBuffer," %s", mc->item[index].string);
}
else
{
if (mc->item[index].logType == SLOG_CONT)
sprintf (getMsgBuffer," %s", mc->item[index].string); /* indent 4 char*/
else
sprintf (getMsgBuffer,"%s", mc->item[index].string);
}
S_UNLOCK_UTIL_RESOURCES ();
return (getMsgBuffer);
}
S_UNLOCK_UTIL_RESOURCES ();
return (NULL);
}
/************************************************************************/
/* slogGetMemCount */
/************************************************************************/
ST_INT slogGetMemCount (LOG_CTRL *lc)
{
MEM_LOG_CTRL *mc;
S_GS_INIT ();
S_LOCK_UTIL_RESOURCES ();
/* get pointer to memory control structure */
mc = &lc->mc;
if (!(mc->state & MEM_STATE_INIT))
{
S_UNLOCK_UTIL_RESOURCES ();
return (0);
}
if (mc->item[mc->nextPut].flags & LMF_USED) /* if wrapped, */
{
S_UNLOCK_UTIL_RESOURCES ();
return (mc->maxItems);
}
else
{
S_UNLOCK_UTIL_RESOURCES ();
return (mc->nextPut);
}
}