Exemple #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);
		}
	}
}
Exemple #2
0
/*--------------------------------------------------------------------
 * DESCRIPTION
 *	Map an entire file. (WIN32 Version)
 *
 * AUTHOR
 * 	lsh
 *
 * DATE CREATED
 *	November 9, 1993
 *------------------------------------------------------------------*/
void FAR *KpMapFileEx (
				KpChar_p		FileName,
				KpFileProps_t	FAR *FileProps,
				KpChar_p		Mode,
				KpMapFile_t	FAR *MapFileCtl)
{
	KpInt32_t	status;
	DWORD		fdwProtect;
	DWORD		fdwAccess;

/* validate mode */
	switch (*Mode) {
	case 'R':
	case 'r':
		fdwProtect = PAGE_READONLY;
		fdwAccess = FILE_MAP_READ;
		break;
	
#if 0
	case 'w':
		fdwProtect = PAGE_READWRITE;
		fdwAccess = FILE_MAP_WRITE;
		break;
#endif
	
	default:
		return NULL;
	}

/* get the size of the file */
	if (!KpFileSize (FileName, FileProps, &MapFileCtl->NumBytes))
		return NULL;
	
/* open the file */
	status = KpFileOpen (FileName, Mode, FileProps, (KpFileId *)&MapFileCtl->hFile);

	if (KCMS_IO_SUCCESS != status)
		return NULL;

/* create the mapping object */
	MapFileCtl->hMapObject = CreateFileMapping ((HANDLE)MapFileCtl->hFile,
												NULL, fdwProtect, 0, 0, NULL);
	if (!MapFileCtl->hMapObject) {
		KpFileClose((KpFileId)MapFileCtl->hFile);
		return NULL;
	} 

/* create a view of the file */
	MapFileCtl->Ptr = MapViewOfFile (MapFileCtl->hMapObject,
										fdwAccess, 0, 0, 0);
	if (NULL == MapFileCtl->Ptr) {
		CloseHandle (MapFileCtl->hMapObject);
		KpFileClose((KpFileId)MapFileCtl->hFile);
		return NULL;
	}

/* return the address of the memory mapped file */
	return MapFileCtl->Ptr;
}
/*----------------------------------------------------------------------*/
KpInt32_t KpOpen (
			KpChar_p		filename,
			KpChar_p		mode,
			KpFd_t			FAR *fd,
			KpFileProps_t	FAR *fileProps,
			...)
{
	if (fd == NULL)
	  return KCMS_IO_ERROR;
	
	switch (*mode) {
	case 'r':
	case 'w':
	case 'e':
		if (1 != KpFileOpen (filename, mode, fileProps, &fd->fd.sys)) {
			fd->type = KCMS_IO_NULLFILE;
			return KCMS_IO_ERROR;
		}

		fd->type = KCMS_IO_SYSFILE;
		break;

	case 'm': {
		va_list		ap;				/* arg pointer */
		char		KPHUGE *buf;			/* used only if mode = "m" */
		KpInt32_t	size;			/* used only if mode = "m" */

		va_start (ap, fileProps);
		buf = va_arg (ap, char KPHUGE *);
		size = va_arg (ap, KpInt32_t);
		va_end (ap);

		fd->fd.mem.buf = buf;
		fd->fd.mem.size = size;
		if ((NULL == fd->fd.mem.buf) || (fd->fd.mem.size <= 0))
		  return KCMS_IO_ERROR;

		fd->fd.mem.pos = 0;
		fd->type = KCMS_IO_MEMFILE;
		break;
	}

#if !defined KCMS_NO_CRC
	case 'c':
		fd->fd.crc32 = 0xFFFFFFFFL;	/* initial value for crc routine */
		fd->type = KCMS_IO_CALCCRC;
		break;
#endif

	default:
		fd->type = KCMS_IO_NULLFILE;
		return KCMS_IO_ERROR;
	}

	return KCMS_IO_SUCCESS;
}
Exemple #4
0
/*--------------------------------------------------------------------
 * DESCRIPTION
 *	Map an entire file.
 *
 * AUTHOR
 * 	lsh
 *
 * DATE CREATED
 *	November 9, 1993
 *------------------------------------------------------------------*/
void FAR *KpMapFileEx (
				KpChar_p		FileName,
				KpFileProps_t	FAR *FileProps,
				KpChar_p		Mode,
				KpMapFile_t	FAR *MapFileCtl)
{
/* validate mode */
	switch (*Mode) {
	case 'R':
	case 'r':
#if 0
	case 'w':
#endif
		break;
	
	default:
		return NULL;
	}

/* get the size of the file */
	if (!KpFileSize (FileName, FileProps, &MapFileCtl->NumBytes))
		return NULL;

/* allocate buffer to hold file */
	MapFileCtl->Ptr = allocBufferPtr (MapFileCtl->NumBytes);
	if (NULL == MapFileCtl->Ptr)
		return NULL;

/* open the file */
	if (!KpFileOpen (FileName, Mode, FileProps, &MapFileCtl->Fd)) {
		freeBufferPtr (MapFileCtl->Ptr);
		return NULL;
	}

/* read file into the buffer */
	if (!KpFileRead (MapFileCtl->Fd, MapFileCtl->Ptr, &MapFileCtl->NumBytes)) {
		freeBufferPtr (MapFileCtl->Ptr);
		KpFileClose (MapFileCtl->Fd);
		return NULL;
	}

/* done with file, close it */
	if ('r' == *Mode) {
		KpFileClose (MapFileCtl->Fd);
		MapFileCtl->Fd = -1;
	}
	MapFileCtl->Mode = *Mode;

	return MapFileCtl->Ptr;
}
Exemple #5
0
/*--------------------------------------------------------------------
 * DESCRIPTION
 *	Returns KPTRUE if seems to be ICC Formatted Profile
 *      private function
 * AUTHOR
 * 	doro
 *
 * DATE CREATED
 *	August 9, 1996
 *------------------------------------------------------------------*/
KpBool_t KSPAPI SpIsICCProfile(	char                    *Filename,
                                SpFileProps_t		*Props)
{
    KpUInt32_t     ProfileSize;
    KpUInt32_t     ProfileCode = 0;
    SpStatus_t     Status = SpStatBadProfile;
    KpFileId       FD;
    char          *name;
    KpUInt32_t     Read_Size_OK, Read_Code_OK = 0;
    KpInt32_t      Read_Amount = 4;
    KpFileProps_t  fileProps;
    KpBool_t       IsICC = KPFALSE;
    char           ReadBufferArray[8];
    char           *ReadBuffer;

    name = Filename;



#if defined (KPMAC)
    SpCvrtSpFileProps(Props, &fileProps);
#endif
    if (KpFileOpen(name, "r", &fileProps, &FD)) /* 0 = not opened */
    {
        /* Read HEADER_SIZE into Buffer */
        ReadBuffer = ReadBufferArray;
        Read_Size_OK =  KpFileRead(FD, ReadBuffer, &Read_Amount);
        ProfileSize = SpGetUInt32(&ReadBuffer);

        if (KpFilePosition(FD, FROM_START, 36))
        {
            ReadBuffer = ReadBufferArray;
            Read_Code_OK = KpFileRead(FD, ReadBuffer, &Read_Amount);
            ProfileCode = SpGetUInt32(&ReadBuffer);
        }

        /* Close File */
        KpFileClose(FD);

        if ((Read_Size_OK) && (ProfileSize > HEADER_SIZE))
        {
            if ((Read_Code_OK) && (ProfileCode == (0x61637370)))
                IsICC = KPTRUE;
        }
    }
    return (IsICC);
}
Exemple #6
0
/*--------------------------------------------------------------------
 * DESCRIPTION
 *	Return the header for the profile.
 *
 * AUTHOR
 * 	doro
 *
 * DATE CREATED
 *	October 23, 1995
 *------------------------------------------------------------------*/
SpStatus_t KSPAPI SpProfileLoadHeader(
    char                    *Filename,
    SpFileProps_t		*Props,
    SpHeader_t              FAR *Header)
{
    SpHugeBuffer_t BufferAddress;
    SpStatus_t     Status = SpStatBadProfile;
    KpFileId       FD;
    char          *name;
    KpUInt32_t     Read_OK;
    KpInt32_t     Read_Amount = HEADER_SIZE;
    KpFileProps_t  fileProps;

    if (!SpIsICCProfile(Filename, Props))
        return (SpStatBadProfile);

    name = Filename;

    BufferAddress = allocBufferPtr(HEADER_SIZE);
    if (BufferAddress == NULL)
        return (SpStatMemory);

#if defined (KPMAC)
    SpCvrtSpFileProps(Props, &fileProps);
#endif
    if (KpFileOpen(name, "r", &fileProps, &FD)) /* 0 = not opened */
    {
        /* Read HEADER_SIZE into Buffer */
        Read_OK =  KpFileRead(FD, BufferAddress, &Read_Amount);

        /* Close File */
        if (!KpFileClose(FD))
            Status = SpStatBadProfile;

        if (Read_OK)
        {
            Status = SpHeaderToPublic(BufferAddress, HEADER_SIZE, Header);
        }
    }
    freeBufferPtr(BufferAddress);
    return Status;

}
/*----------------------------------------------------------------------*/
KpInt32_t Kp_open (
			KpChar_p	filename,
			KpChar_p	mode,
			KpFd_t		FAR *fd,
			ioFileChar	FAR *fileProps,
			...)
{
KpFileProps_t	kpfileProps;

	/* Convert ioFileChar to KpFileProps_t */
#if defined (KPMAC)
	if (fileProps != NULL) {
		kpfileProps.vRefNum = fileProps->vRefNum;
		kpfileProps.dirID = 0;
		strncpy (kpfileProps.fileType, fileProps->fileType, 5);
		strncpy (kpfileProps.creatorType, fileProps->creatorType, 5);
	} 
	else {
		kpfileProps.vRefNum = 0;
		kpfileProps.dirID = 0;
		strncpy (kpfileProps.fileType, "    ", 5);
		strncpy (kpfileProps.creatorType, "    ", 5);
	}
#endif

	if (fd == NULL)
	  return KCMS_IO_ERROR;
	
	switch (*mode) {
	case 'r':
	case 'w':
	case 'e':
		if (1 != KpFileOpen (filename, mode, &kpfileProps, &fd->fd.sys)) {
			fd->type = KCMS_IO_NULLFILE;
			return KCMS_IO_ERROR;
		}

		fd->type = KCMS_IO_SYSFILE;
		break;

	case 'm': {
		va_list		ap;				/* arg pointer */
		char		KPHUGE *buf;			/* used only if mode = "m" */
		KpInt32_t	size;			/* used only if mode = "m" */

		va_start (ap, fileProps);
		buf = va_arg (ap, char KPHUGE *);
		size = va_arg (ap, KpInt32_t);
		va_end (ap);

		fd->fd.mem.buf = buf;
		fd->fd.mem.size = size;
		if ((NULL == fd->fd.mem.buf) || (fd->fd.mem.size <= 0))
		  return KCMS_IO_ERROR;

		fd->fd.mem.pos = 0;
		fd->type = KCMS_IO_MEMFILE;
		break;
	}

#if !defined KCMS_NO_CRC
	case 'c':
		fd->fd.crc32 = 0xFFFFFFFFL;	/* initial value for crc routine */
		fd->type = KCMS_IO_CALCCRC;
		break;
#endif

	default:
		fd->type = KCMS_IO_NULLFILE;
		return KCMS_IO_ERROR;
	}

	return KCMS_IO_SUCCESS;
}
Exemple #8
0
/*--------------------------------------------------------------------
 * DESCRIPTION
 *	Return the Tag from the profile.
 *
 * AUTHOR
 * 	doro
 *
 * DATE CREATED
 *	March 12, 2002
 *------------------------------------------------------------------*/
SpStatus_t KSPAPI SpProfileLoadTagEx(
    char                   *Filename,
    SpFileProps_t          *Props,
    SpTagId_t               TagId,
    SpTagValue_t            FAR *Value)
{
    SpHeader_t       Header;
    SpHeader_t       *HeaderPtr;
    SpHugeBuffer_t   BufferAddress, TagAddress;
    SpStatus_t       Status = SpStatSuccess;
    KpFileId         FD;
    KpFileProps_t    fileProps;
    char             name[MAX_PATH];
    KpUInt32_t       FilePosition = HEADER_SIZE;
    KpInt32_t       Read_Amount  = sizeof(KpInt32_t);
    KpInt32_t       i, TagArraySize, TagBufferSize;
    SpTagRecord_t   *TagArray;

    if (!SpIsICCProfile(Filename, Props))
        return (SpStatBadProfile);

    strcpy (name, Filename);

    /* Need Header in case we are requesting a Named Color */
    HeaderPtr = (SpHeader_t *)NULL;
    if (TagId == SpTagNamedColor)
    {
        HeaderPtr = &Header;
        Status = SpProfileLoadHeader(name, Props, HeaderPtr);
    }
    if (Status == SpStatSuccess)
    {
        /* Set up for failure - yes I know I'm negative */
        Status = SpStatFileNotFound;

#if defined (KPMAC)
        SpCvrtSpFileProps(Props, &fileProps);
#endif
        if (KpFileOpen(Filename, "r", &fileProps, &FD)) /* 0 = not opened */
        {
            if (KpFilePosition(FD, FROM_START, FilePosition))
            {

                Status = SpStatFileReadError;
                /* Read TagArraySize into Buffer  */
                if (KpFileRead(FD, &TagArraySize, &Read_Amount))
                {
#if defined (KPLSBFIRST)
                    /* If we are on a little endian machine we need to do byte swap	*/
                    Kp_swab32 (&TagArraySize, 1);
#endif
                    TagBufferSize = TagArraySize * 3 * 4;  /* each entry is 3*4 bytes */
                    BufferAddress = allocBufferPtr(TagBufferSize);
                    if (BufferAddress != NULL)
                    {
                        if (KpFileRead(FD, BufferAddress, &TagBufferSize))
                        {
#if defined (KPLSBFIRST)
                            /* If we are on a little endian machine we need to do byte swap	*/
                            Kp_swab32 (BufferAddress, TagBufferSize / sizeof (KpInt32_t));
#endif
                            TagArray = BufferAddress;
                            Status = SpStatTagNotFound;
                            for (i = 0; i < TagArraySize; i++)
                            {
                                if (TagId == (SpTagId_t)TagArray[i].Id)
                                {
                                    Status = SpStatMemory;
                                    TagAddress = allocBufferPtr(TagArray[i].Size);
                                    if (TagAddress != NULL)
                                    {
                                        if (KpFilePosition(FD, FROM_START, TagArray[i].Offset))
                                        {
                                            Read_Amount = TagArray[i].Size;
                                            if (KpFileRead(FD, TagAddress, &Read_Amount))
                                            {
                                                Status = SpTagToPublic(HeaderPtr,   TagId,
                                                                       TagArray[i].Size,
                                                                       TagAddress,  Value);
                                            }
                                        }
                                        freeBufferPtr(TagAddress);
                                    } else
                                    {
                                        Status = SpStatMemory;
                                        break;
                                    }
                                }
                            }
                        }
                        freeBufferPtr(BufferAddress);
                    } else /* Buffer Address != 0 */
                        Status = SpStatMemory;
                }
            }
            /* Close File */
            KpFileClose(FD);
        }
    }
    return Status;

}
Exemple #9
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 ();
	}
}
Exemple #10
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);
}
Exemple #11
0
/*--------------------------------------------------------------------
 * DESCRIPTION
 *	Unmap an entire file. (WIN32 Version)
 *
 * AUTHOR
 * 	lsh
 *
 * DATE CREATED
 *	November 9, 1993
 *------------------------------------------------------------------*/
KpInt32_t KpUnMapFile (KpMapFile_t FAR *MapFileCtl)
{
	int	Status;

	Status = KCMS_IO_SUCCESS;
	if (!UnmapViewOfFile (MapFileCtl->Ptr))
		Status = KCMS_IO_ERROR;

	if (!CloseHandle (MapFileCtl->hMapObject))
		Status = KCMS_IO_ERROR;

#if defined(_M_IA64)
	if (!CloseHandle (MapFileCtl->hFile)) {
#else /* non-64-bit case */
	if (_lclose (MapFileCtl->hFile)) {
#endif /* defined(_M_IA64) */
		Status = KCMS_IO_ERROR;
	}

	return Status;
}

#else


/*--------------------------------------------------------------------
 * DESCRIPTION
 *	Map an entire file.
 *
 * AUTHOR
 * 	lsh
 *
 * DATE CREATED
 *	November 9, 1993
 *------------------------------------------------------------------*/
void FAR *KpMapFileEx (
				KpChar_p		FileName,
				KpFileProps_t	FAR *FileProps,
				KpChar_p		Mode,
				KpMapFile_t	FAR *MapFileCtl)
{
/* validate mode */
	switch (*Mode) {
	case 'R':
	case 'r':
#if 0
	case 'w':
#endif
		break;
	
	default:
		return NULL;
	}

/* get the size of the file */
	if (!KpFileSize (FileName, FileProps, &MapFileCtl->NumBytes))
		return NULL;

/* allocate buffer to hold file */
	MapFileCtl->Ptr = allocBufferPtr (MapFileCtl->NumBytes);
	if (NULL == MapFileCtl->Ptr)
		return NULL;

/* open the file */
	if (!KpFileOpen (FileName, Mode, FileProps, &MapFileCtl->Fd)) {
		freeBufferPtr (MapFileCtl->Ptr);
		return NULL;
	}

/* read file into the buffer */
	if (!KpFileRead (MapFileCtl->Fd, MapFileCtl->Ptr, &MapFileCtl->NumBytes)) {
		freeBufferPtr (MapFileCtl->Ptr);
		KpFileClose (MapFileCtl->Fd);
		return NULL;
	}

/* done with file, close it */
	if ('r' == *Mode) {
		KpFileClose (MapFileCtl->Fd);
		MapFileCtl->Fd = -1;
	}
	MapFileCtl->Mode = *Mode;

	return MapFileCtl->Ptr;
}


/*--------------------------------------------------------------------
 * DESCRIPTION
 *	Map an entire file. (non-win32 version)
 *
 * AUTHOR
 * 	lsh
 *
 * DATE CREATED
 *	November 9, 1993
 *------------------------------------------------------------------*/
void FAR *KpMapFile (
				KpChar_p		FileName,
				ioFileChar	FAR *FileProps,
				KpChar_p		Mode,
				KpMapFile_t	FAR *MapFileCtl)
{
KpFileProps_t	kpFileProps, *kpFilePropsPtr;

	/* convert FileProps to KpFileProps_t and call
	   KpMapFileEx */
#if defined (KPMAC) || defined (KPMSMAC)
	if (FileProps != NULL) {
		kpFileProps.vRefNum = FileProps->vRefNum;
		kpFileProps.dirID= 0;
		strncpy(kpFileProps.fileType, FileProps->fileType, 5);
		strncpy(kpFileProps.creatorType, FileProps->creatorType, 5);
	}
	else {
		kpFileProps.vRefNum = 0;
		kpFileProps.dirID= 0;
		strncpy(kpFileProps.fileType, "    ", 5);
		strncpy(kpFileProps.creatorType, "    ", 5);
	}
	kpFilePropsPtr = &kpFileProps;
#else
	kpFilePropsPtr = FileProps;
#endif
	return (KpMapFileEx (FileName, kpFilePropsPtr, Mode, MapFileCtl) );
}