From: Rolf K. <lab...@us...> - 2006-01-07 20:11:39
|
Update of /cvsroot/opengtoolkit/lvzip/c_source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8049/c_source Modified Files: macbin.c macbin.h Added Files: MacBinaryIII.c MacBinaryIII.h Log Message: Added c-code MacBinary implementation for Mac platform Index: macbin.c =================================================================== RCS file: /cvsroot/opengtoolkit/lvzip/c_source/macbin.c,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** macbin.c 8 Jun 2005 19:54:30 -0000 1.11 --- macbin.c 7 Jan 2006 20:11:30 -0000 1.12 *************** *** 6,9 **** --- 6,11 ---- */ + #include <stdio.h> + #include <string.h> #include "zlib.h" #include "ioapi.h" *************** *** 11,16 **** --- 13,20 ---- #if Mac + #include <CoreServices/CoreServices.h> // instead of #include <Resources.h> #include "Finder.h" #include "Files.h" + #include "MacBinaryIII.h" #define MacIsInvisible(cpb) ((cpb).hFileInfo.ioFlFndrInfo.fdFlags & kIsInvisible) *************** *** 20,24 **** #define kFileChanged (1L<<7) ! static OSErr MakeFSpec(PStr path, FSSpec *fss); static OSErr IfDirCloseIt(int16 vol); static MgErr OSErrToLVErr(OSErr err); --- 24,28 ---- #define kFileChanged (1L<<7) ! static OSErr MakeFSpec(ConstStr255 path, FSSpec *fss); static OSErr IfDirCloseIt(int16 vol); static MgErr OSErrToLVErr(OSErr err); *************** *** 38,41 **** --- 42,112 ---- #endif + extern void ZEXPORT DLLVersion(char* version) + { + sprintf(version, "lvzlib date: %s, time: %s",__DATE__,__TIME__); + } + + extern MgErr ZEXPORT HasResourceFork(ConstStr255 fileName, long *hasResFork){ + + #if Mac + OSErr err = noErr; + int theRefNum; + FSSpec theFSSpec; + + *hasResFork = 0; + + err = MakeFSpec(fileName, &theFSSpec); + id (!err) + { + theRefNum = FSpOpenResFile(&theFSSpec, fsRdWrPerm); + if (ResError() == noErr) //we've got a resource file + { + CloseResFile(theRefNum); + *hasResFork = 1; + } + } + return OSErrToLVErr(err); + #else + *hasResFork = 0; + return noErr; + #endif + } + + extern MgErr ZEXPORT LV_EncodeMacbinary(ConstStr255 srcFileName, ConstStr255 dstFileName){ + #if Mac + FSSpec srcFSSpec; + FSSpec dstFSSpec; + OSErr err = MakeFSpec(srcFileName, &srcFSSpec); + if (!err) + { + err = MakeFSpec(dstFileName, &dstFSSpec); + if (!err) + err = EncodeMacbinaryFiles(&srcFSSpec,&dstFSSpec); + } + return OSErrToLVErr(err); + #else + return mgNotSupported; + #endif + } + + extern MgErr ZEXPORT LV_DecodeMacbinary(ConstStr255 srcFileName, ConstStr255 dstFileName){ + #if Mac + FSSpec srcFSSpec; + FSSpec dstFSSpec; + OSErr err; + + err = MakeFSpec(srcFileName, &srcFSSpec); + if (!err) + { + err = MakeFSpec(dstFileName, &dstFSSpec); + if (err) + err = DecodeMacBinaryFiles(&srcFSSpec,&dstFSSpec); + } + return OSErrToLVErr(err); + #else + return mgNotSupported; + #endif + } + extern MgErr ZEXPORT OpenResFork(File *fdp, PStr path, *************** *** 223,238 **** { #if Win32 ! fill_win32_filefunc(pzlib_filefunc_def); #else ! fill_fopen_filefunc(pzlib_filefunc_def); #endif ! return noErr; } else ! return sizeof(zlib_filefunc_def); } #if Mac ! static OSErr MakeFSpec(PStr path, FSSpec *fss) { OSErr err; --- 294,309 ---- { #if Win32 ! fill_win32_filefunc(pzlib_filefunc_def); #else ! fill_fopen_filefunc(pzlib_filefunc_def); #endif ! return noErr; } else ! return sizeof(zlib_filefunc_def); } #if Mac ! static OSErr MakeFSpec(ConstStr255 path, FSSpec *fss) { OSErr err; *************** *** 248,252 **** /* fileName parameter. */ if ((err == noErr) && (fss->parID == 0)) { ! fss->parID = fsRtParID; } return noErr; --- 319,323 ---- /* fileName parameter. */ if ((err == noErr) && (fss->parID == 0)) { ! fss->parID = fsRtParID; } return noErr; *************** *** 307,311 **** delta = loc.u.gmtDelta & 0x00ffffff; /* get sec east of UTC */ if (delta & 0x800000) ! delta |= 0xff000000; /* sign extend */ return -delta; /* secs from UTC */ } --- 378,382 ---- delta = loc.u.gmtDelta & 0x00ffffff; /* get sec east of UTC */ if (delta & 0x800000) ! delta |= 0xff000000; /* sign extend */ return -delta; /* secs from UTC */ } *************** *** 315,319 **** if (time > 0.0) { ! *sTime = time - UTCShift(); } return; --- 386,390 ---- if (time > 0.0) { ! *sTime = time - UTCShift(); } return; Index: macbin.h =================================================================== RCS file: /cvsroot/opengtoolkit/lvzip/c_source/macbin.h,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** macbin.h 8 Jun 2005 19:54:30 -0000 1.6 --- macbin.h 7 Jan 2006 20:11:30 -0000 1.7 *************** *** 20,24 **** #endif ! #if defined(macintosh) || defined(__PPCC__) || defined(THINK_C) || defined(__SC__) || defined(__MWERKS__) #define Mac 1 #elif defined(__GNUC__) || defined(linux) --- 20,24 ---- #endif ! #if defined(macintosh) || defined(__PPCC__) || defined(THINK_C) || defined(__SC__) || defined(__MWERKS__) || defined(__APPLE_CC__) #define Mac 1 #elif defined(__GNUC__) || defined(linux) *************** *** 142,145 **** --- 142,147 ---- #define PStrSize(b) (PStrLen(b)+1) /* # of bytes including length */ + typedef const uChar ConstStr255[256]; + /* Typedefs */ typedef struct { *************** *** 160,163 **** --- 162,172 ---- enum { denyReadWrite, denyWriteOnly, denyNeither}; /* deny modes */ + extern void ZEXPORT DLLVersion(char* Version); + + extern MgErr ZEXPORT HasResourceFork(ConstStr255 fileName, long *hasResFork); + + extern MgErr LV_EncodeMacbinary(ConstStr255 srcFileName, ConstStr255 dstFileName); + extern MgErr LV_DecodeMacbinary(ConstStr255 srcFileName, ConstStr255 dstFileName); + extern MgErr ZEXPORT UtilFileInfo OF((PStr path, uInt8 write, --- NEW FILE: MacBinaryIII.h --- //MacBinaryIII.h // Ch, 28.02.2003, OSX port, see TARGET_API_MAC_CARBON macro // Ch. 19.07.2005, Xcode 1.5 port, from CW project #ifdef TARGET_API_MAC_CARBON // #include <Types.h> // not for OSX #endif //#include <Files.h> //#include <Script.h> #include <CoreServices/CoreServices.h> // instead of #include <Script.h> and /#include <Files.h> #include <String.h> #pragma once #pragma options align=mac68k /* 000 Byte old version number, must be kept at zero for compatibility 001 Byte Length of filename (must be in the range 1-31) 002 1 to 63 Bytes filename (only "length" bytes are significant). 065 Long Word file type (normally expressed as four characters) 069 Long Word file creator (normally expressed as four characters) 073 Byte original Finder flags Bit 7 - isAlias. Bit 6 - isInvisible. Bit 5 - hasBundle. Bit 4 - nameLocked. Bit 3 - isStationery. Bit 2 - hasCustomIcon. Bit 1 - reserved. Bit 0 - hasBeenInited. 074 Byte zero fill, must be zero for compatibility 075 Word file's vertical position within its window. 077 Word file's horizontal position within its window. 079 Word file's window or folder ID. 081 Byte "Protected" flag (in low order bit). 082 Byte zero fill, must be zero for compatibility 083 Long Word Data Fork length (bytes, zero if no Data Fork). 087 Long Word Resource Fork length (bytes, zero if no R.F.). 091 Long Word File's creation date 095 Long Word File's "last modified" date. 099 Word length of Get Info comment to be sent after the resource fork (if implemented, see below). 101 Byte Finder Flags, bits 0-7. (Bits 8-15 are already in byte 73) Bit 7 - hasNoInits Bit 6 - isShared Bit 5 - requiresSwitchLaunch Bit 4 - ColorReserved Bits 1-3 - color Bit 0 - isOnDesk *102 Long Word signature for indentification purposes ('mBIN') *106 Byte script of file name (from the fdScript field of an fxInfo record) *107 Byte extended Finder flags (from the fdXFlags field of an fxInfo record) 108-115 Unused (must be zeroed by creators, must be ignored by readers) 116 Long Word Length of total files when packed files are unpacked. As of the writing of this document, this field has never been used. 120 Word Length of a secondary header. If this is non-zero, skip this many bytes (rounded up to the next multiple of 128). This is for future expansion only, when sending files with MacBinary, this word should be zero. *122 Byte Version number of MacBinary III that the uploading program is written for (the version is 130 for MacBinary III) 123 Byte Minimum MacBinary version needed to read this file (set this value at 129 for backwards compatibility with MacBinary II) 124 Word CRC of previous 124 bytes */ typedef unsigned short Word; #define kOldVersionOffset 0 #define kFileNameLengthOffset 1 #define kFileNameOffset 2 #define kFileTypeOffset 65 #define kFileCreatorOffset 69 #define kFinderFlagsHiOffset 73 #define kVersionCheckZero 74 #define kFileVPositionOffset 75 #define kFileHPositionOffset 77 #define kFileFolderIDOffset 79 #define kProtectedFlagOffset 81 #define kVersionOneCheckZero 82 #define kDataForkLengthOffset 83 #define kResourceForkLengthOffset 87 #define kFileCreationDateOffset 91 #define kFileModificationDateOffset 95 #define kGetInfoCommentLengthOffset 99 #define kFinderFlagsLowOffset 101 #define kMacbinarySigOffset 102 #define kFilenameScriptOffset 106 #define kExtendedFinderFlagsOffset 107 #define kTotalFileLengthOffset 116 #define kSecondaryHeaderLengthOffset 120 #define kCurrentVersionOffset 122 #define kMinimumVersionOffset 123 #define kCRCOffset 124 #define LONG_AT_OFFSET(data, offset) *((long *)((unsigned char *)&data[offset])) #define WORD_AT_OFFSET(data, offset) *((Word *)((unsigned char *)&data[offset])) #define BYTE_AT_OFFSET(data, offset) *((Byte *)((unsigned char *)&data[offset])) #define PTR_AT_OFFSET(data, offset) ((Ptr)((unsigned char *)&data[offset])) #ifdef __cplusplus extern "C" { #endif Handle EncodeMacbinary(FSSpec *file); OSErr EncodeMacbinaryFile(FSSpec *file); OSErr EncodeMacbinaryFiles(FSSpec *file, FSSpec* outfile); OSErr DecodeMacBinary(Handle data, FSSpec *destination); OSErr DecodeMacBinaryFile(FSSpec *source); OSErr DecodeMacBinaryFiles(FSSpec* inputfile,FSSpec* outputfile); Boolean FSpIsMacBinary(FSSpec *file); #ifdef __cplusplus } #endif #pragma options align=reset --- NEW FILE: MacBinaryIII.c --- (This appears to be a binary file; contents omitted.) |