eudora-mac/hexbin.c

1 line
22 KiB
C
Raw Normal View History

2018-05-23 09:59:15 +00:00
/* Copyright (c) 2017, Computer History Museum All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted (subject to the limitations in the disclaimer below) provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Computer History Museum nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "hexbin.h" #define FILE_NUM 17 /* Copyright (c) 1990-1992 by the University of Illinois Board of Trustees */ /************************************************************************ * functions to convert files to binhex and back again * much of this code is patterned after xbin by Dave Johnson, Brown University * Some is lifted straight from xbin. Our thanks to Dave & Brown. ************************************************************************/ #pragma segment HexBin /************************************************************************ * Declarations for private routines ************************************************************************/ void HexBinInputChar(Byte c,long estMessageSize); void HexBinDataChar(short d,long estMessageSize); int FoundHexBin(void); int HexBinDecode(Byte c,long estMessageSize); void AbortHexBin(Boolean error); void OpenDataFork(void); int ForkRoll(void); int FlushBuffer(void); void ResetHexBin(void); void comp_q_crc(unsigned short c); void CrcError(void); void SaveHexBin(UPtr text,long size,long estMessageSize); void ForceAttachFolder(PStr volName, long *dirId); /************************************************************************ * Private globals ************************************************************************/ typedef struct { long type; long author; short flags; long dataLength; long rzLength; unsigned short hCrc; } HexBinHead; typedef struct HexBinGlobals_ HexBinGlobals, *HBGPtr, **HBGHandle; struct HexBinGlobals_ { short state; long oSpot; UHandle buffer; long bSize; long bSpot; short refN; FSSpec spec; Byte lastData; Byte state68; Byte b8; Byte runCount; Boolean run; HeaderDHandle hdh; // enclosing header long count; long size; Str63 binHexIntro; long origOffset; Boolean gotOne; short mailboxRefN; union { HexBinHead bxHead; Byte bxhBytes[sizeof(HexBinHead)]; } BHHUnion; unsigned long calcCrc; unsigned long crc; }; #define Hdh (*HBG)->hdh #define State (*HBG)->state #define OSpot (*HBG)->oSpot #define Buffer (*HBG)->buffer #define BSize (*HBG)->bSize #define BSpot (*HBG)->bSpot #define RefN (*HBG)->refN #define Spec (*HBG)->spec #define Name (*HBG)->spec.name #define Type (*HBG)->BHHUnion.bxHead.type #define Author (*HBG)->BHHUnion.bxHead.author #define Flags (*HBG)->BHHUnion.bxHead.flags #define RzLength (*HBG)->BHHUnion.bxHead.rzLength #define DataLength (*HBG)->