/*-------------------------------------------------------------------- * 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); }
/*-------------------------------------------------------------------- * 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; }
/*-------------------------------------------------------------------- * 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; }
/* 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); }