예제 #1
0
/* write a string to the diagnostic log file */
void
	kcpDiagLog (	KpChar_p	string)
{
initializedGlobals_p	iGP;
KpChar_t				diagName[256];
KpFileId				fd;
KpFileProps_t			fileProps;

	iGP = getInitializedGlobals ();
	if (iGP != NULL) {
		SetKCPDataDirProps (&fileProps);

#if defined (KPMAC) || defined (KPMSMAC)
		strcpy (fileProps.fileType, "TEXT");
		strcpy (diagName, iGP->KCPDataDir);	/* make the full name */
		strcat (diagName, "kcpdiag.log");
#else
		strcpy (diagName, "kcpdiag.log");
#endif

		if (KpFileOpen (diagName, "a", &fileProps, &fd)) {
			KpFileWrite (fd, string, strlen (string));
			(void) KpFileClose (fd);
		}
	}
}
예제 #2
0
/*----------------------------------------------------------------------*/
KpInt32_t Kp_write (
			KpFd_t			FAR *fd,
			KpLargeBuffer_t	buf,
			KpInt32_t		nbytes)
{
	void KPHUGE *memPtr;

	if (KpFdCheck (fd) != KCMS_IO_SUCCESS)
		return KCMS_IO_ERROR;

	/* validate destination */
	if (buf == NULL)
		return KCMS_IO_ERROR;

	switch (fd->type) {

	/* regular file, write it */
	case KCMS_IO_SYSFILE:
		if (1 != KpFileWrite (fd->fd.sys, buf, nbytes))
			return KCMS_IO_ERROR;

		break;

	/* memory file, copy to memory */
	case KCMS_IO_MEMFILE:
		if (fd->fd.mem.pos + nbytes > fd->fd.mem.size)
			return KCMS_IO_ERROR;

		/* validate destination */
		if (fd->fd.mem.buf == NULL)
			return KCMS_IO_ERROR;

		memPtr = (char KPHUGE *) fd->fd.mem.buf + fd->fd.mem.pos;

		KpMemCpy (memPtr, buf, nbytes);

		fd->fd.mem.pos += nbytes;
		break;

#if !defined KCMS_NO_CRC
	/* calculate CRC */
	case KCMS_IO_CALCCRC:
		fd->fd.crc32 = Kp_Crc32 (fd->fd.crc32, nbytes, (KpChar_p) buf);
		break;
#endif

	default:
		return KCMS_IO_ERROR;
	}

	return KCMS_IO_SUCCESS;
}
예제 #3
0
/*--------------------------------------------------------------------
 * DESCRIPTION
 *	Unmap an entire file.
 *
 * AUTHOR
 * 	lsh
 *
 * DATE CREATED
 *	November 9, 1993
 *------------------------------------------------------------------*/
KpInt32_t KpUnMapFile (KpMapFile_t FAR *MapFileCtl)
{
	KpInt32_t Status;

	Status = KCMS_IO_SUCCESS;
    if ('w' == MapFileCtl->Mode) {
		if (KpFilePosition (MapFileCtl->Fd, FROM_START, 0)) {
			if (!KpFileWrite (MapFileCtl->Fd, MapFileCtl->Ptr,
												MapFileCtl->NumBytes))
				Status = KCMS_IO_ERROR;
		}
		else
			Status = KCMS_IO_ERROR;
		KpFileClose (MapFileCtl->Fd);
	}

	freeBufferPtr (MapFileCtl->Ptr);
	return Status;
}
예제 #4
0
static void MemLogFunc (void FAR *Ptr, long Size, MemLogType_t Type)
{
	char		MsgText [82];
	static KpFileId	fid;
	int32		MsgSize, i;
	char		*sLogName;
	
	if (NULL == Ptr)
		return;

/* check for first time */
	if (lLogSeqNum == 0) {
		fLogFileError = KPFALSE;
		lLogUseCount = 0;

		sLogName = getenv("KPMEMTRACEFILE");
		if (sLogName == NULL){
			fLogFileError = KPTRUE;
			return;
		}

		/* create the log file */
		if (KpFileOpen(sLogName, "w", &KCPDataDirProps, &fid) == 0) {
			fLogFileError = KPTRUE;
			return;
		}
	}
	if (fLogFileError == KPTRUE)
		return;

	++lLogSeqNum;

	for (i = 0; i < 80; i++) {
		MsgText[i] = 32;	/* SP */
	}
	MsgText[i++] = '\n';
	MsgText[i++] = 0;
	
/* create proper log message */
	switch (Type) {
	case MemLogAlloc:
		lLogUseCount++;
		KpLtos((int32)Ptr, MsgText);
		strcpy (&MsgText[10], "Allocate");
		KpItoa(lLogSeqNum, &MsgText[20]);
		KpItoa(lLogUseCount, &MsgText[30]);
		KpItoa(Size, &MsgText[40]);
		break;

	case MemLogFree:
		lLogUseCount--;
		KpLtos((int32)Ptr, MsgText);
		strcpy (&MsgText[10], "Free");
		KpItoa(lLogSeqNum, &MsgText[20]);
		KpItoa(lLogUseCount, &MsgText[30]);
		break;

	default:
		strcpy (MsgText, "Unknown memory log type\n");
		break;
	}

	for (i = 0; i < 80; i++) {
		if (MsgText[i] == 0) {
			MsgText[i] = 32;	/* SP */
		}
	}
	
/* write the message */
	MsgSize = strlen (MsgText);
	if  (KpFileWrite(fid, &MsgText, MsgSize) == 0){
		fLogFileError = KPTRUE;
		return;
	}

/* check for user requested break */
	if (lLogSeqNum == KpSeqNumStopAt) {
		KpMemLogBreak ();
	}
}
예제 #5
0
/* Used only by pt2pf to specify that fixed conversion PT files are being used */
void displayWarning(KpChar_p message)
{

char			prefFile[256];
char			logFileName[256];
char			*charPtr;
DWORD			numChars;
KpChar_p		LOG_SECTION = "Log";
KpChar_p		 LOG_ENTRY = "ConsoleLogFile";
BOOL			doLog;
char			eol[2];
KpFileProps_t	fileProps;
KpFileId		logFile;
int				kpStatus;

	/* Locate Module Preference File */
    numChars=GetModuleFileName(NULL,prefFile,(DWORD)(sizeof(prefFile)-1));
    prefFile[numChars-4]='\0';
    lstrcat(prefFile,".ini");

	/* get the value of "Write LogFile" */
	doLog = (KpBool_t)GetPrivateProfileString(LOG_SECTION, LOG_ENTRY, NULL, 
												logFileName, 256, prefFile);
	if (!doLog)
		return;
	/* Check if there is a '\' in the file name.  If so, assume
		   full path and file name is specified.  If not, assume
		   file name only and get path for .exe file */
	charPtr = strchr( logFileName, '\\' );
	if (charPtr != 0) {
		strcpy (prefFile, logFileName);
	}
	else {
	/* Generate the full name for the log file by reading
		   the file name from the .ini file and then getting the
		   path to the .exe file and making a new path to the .log
		   file.  */
		charPtr = strrchr( prefFile, '\\' );
		numChars = charPtr - prefFile + 1;
		prefFile[numChars] = '\0';
		strcat(prefFile, logFileName);
	}

   	eol[0] = 0x0d;
	eol[1] = 0x0a;

/* open the logging file */
	kpStatus =  KpFileOpen (prefFile, "w", &fileProps, &logFile);
	if (kpStatus != KCMS_IO_SUCCESS) return;

/* position to end of file */
	if (KpFilePosition(logFile, FROM_END, 0L) == 0) {
		return;
	}

	/* write buffer to log file */
	KpFileWrite (logFile, message, strlen(message)-1);
	KpFileWrite (logFile, eol, 2);

/* close the log file */
	KpFileClose (logFile);
}