コード例 #1
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;
}
コード例 #2
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;
}
コード例 #3
0
ファイル: kcpmgr.c プロジェクト: fatman2021/myforthprocessor
/* 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);
		}
	}
}
コード例 #4
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;
	} else {
		if (!CloseHandle (MapFileCtl->hMapObject)) {
			Status = KCMS_IO_ERROR;
		} else {
			Status = KpFileClose((KpFileId)MapFileCtl->hFile);
		}
	}
	return Status;
}
コード例 #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);
}
コード例 #6
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;
}
コード例 #7
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;

}
コード例 #8
0
ファイル: kcms_io.c プロジェクト: fatman2021/myforthprocessor
/*----------------------------------------------------------------------*/
KpInt32_t Kp_close (
			KpFd_t	FAR *fd)
{
	KpInt32_t		Status;

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

	Status = KCMS_IO_SUCCESS;
	switch (fd->type) {
	case KCMS_IO_NULLFILE:
		break;

	case KCMS_IO_SYSFILE:
		if (1 != KpFileClose (fd->fd.sys))
			Status = KCMS_IO_ERROR;

		break;

	case KCMS_IO_MEMFILE:
		/* force a bus error if fd is used after it's freed */
		fd->fd.mem.buf = (char FAR *) -1L;
		fd->fd.mem.size = 0;
		fd->fd.mem.pos = 0;	/* set offset to point to start of buffer */
		break;
		
#if !defined KCMS_NO_CRC
	case KCMS_IO_CALCCRC:
		fd->fd.crc32 = 0;
		break;
#endif

	default:
		Status = KCMS_IO_ERROR;
		break;
	}

	fd->type = KCMS_IO_NULLFILE;
	return Status;
}
コード例 #9
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;

}
コード例 #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);
}
コード例 #11
0
ファイル: filemap.c プロジェクト: fatman2021/myforthprocessor
/*--------------------------------------------------------------------
 * 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) );
}