Headers and library sources from all versions of Lightspeed C and THINK C

Import Lightspeed C 2.01

jcs.org 616fc163

+14286
+182
headers/Appletalk.h
··· 1 + 2 + /* 3 + * Appletalk.h 4 + * 5 + * Copyright (c) 1986 THINK Technologies, Inc. 6 + * These interfaces are based on information published in 7 + * "Inside Macintosh" by Apple Computer, Addison-Wesley, 8 + * Reading (Mass.), 1985. 9 + * 10 + */ 11 + 12 + #ifndef _Appletalk_ 13 + #define _Appletalk_ 14 + 15 + #ifndef _MacTypes_ 16 + #include "MacTypes.h" 17 + #endif 18 + 19 + 20 + /* result codes */ 21 + enum { 22 + sktClosedErr = -3109, 23 + recNotFnd, 24 + atpBadRsp, 25 + atpLenErr, 26 + readQErr, 27 + extractErr, 28 + cksumErr, 29 + noMPPError, 30 + buf2SmallErr, 31 + reqAborted = -1105, 32 + noDataArea, 33 + noSendResp, 34 + cbNotFound, 35 + noRelErr, 36 + badBuffNum, 37 + badATPSkt, 38 + tooManySkts, 39 + tooManyReqs, 40 + reqFailed, 41 + nbpNISErr = -1029, 42 + nbpNotFound, 43 + nbpDuplicate, 44 + nbpConfDiff, 45 + nbpNoConfirm, 46 + nbpBuffOvr, 47 + portNotCf = -98, 48 + portInUse, 49 + excessCollsns = -95, 50 + lapProtErr, 51 + noBridgeErr, 52 + ddpLenErr, 53 + ddpSktErr 54 + }; 55 + 56 + 57 + typedef enum { 58 + tLAPRead, 59 + tLAPWrite, 60 + tDDPRead, 61 + tDDPWrite, 62 + tNBPLookup, 63 + tNBPConfirm, 64 + tNBPRegister, 65 + tATPSndRequest, 66 + tATPGetRequest, 67 + tATPSdRsp, 68 + tATPAddRsp, 69 + tATPRequest, 70 + tATPResponse 71 + } ABCallType; 72 + 73 + typedef Byte ABByte; 74 + 75 + typedef struct LAPAdrBlock { 76 + Byte dstNodeID; 77 + Byte srcNodeID; 78 + ABByte lapProtType; 79 + } LAPAdrBlock; 80 + 81 + typedef struct AddrBlock { 82 + int aNet; 83 + Byte aNode; 84 + Byte aSocket; 85 + } AddrBlock; 86 + 87 + typedef unsigned char Str32[34]; 88 + 89 + typedef struct EntityName { 90 + Str32 objStr; 91 + Str32 typeStr; 92 + Str32 zoneStr; 93 + } EntityName, *EntityPtr; 94 + 95 + typedef struct RetransType { 96 + Byte retransInterval; 97 + Byte retransCount; 98 + } RetransType; 99 + 100 + typedef struct BDSElement { 101 + int buffSize; 102 + Ptr buffPtr; 103 + int dataSize; 104 + long userBytes; 105 + } BDSElement, BDSType[8]; 106 + typedef BDSType *BDSPtr; 107 + 108 + typedef char BitMapType; 109 + 110 + typedef struct lapProto { 111 + ABCallType abOpcode; 112 + int abResult; 113 + long abUserReference; 114 + LAPAdrBlock lapAddress; 115 + int lapReqCount; 116 + int lapActCount; 117 + Ptr lapDataPtr; 118 + } lapProto, LAPProto; 119 + #define lapSize sizeof(lapProto) 120 + 121 + typedef struct ddpProto { 122 + ABCallType abOpcode; 123 + int abResult; 124 + long abUserReference; 125 + unsigned ddpType; 126 + unsigned ddpSocket; 127 + AddrBlock ddpAddress; 128 + int ddpReqCount; 129 + int ddpActCount; 130 + Ptr ddpDataPtr; 131 + unsigned ddpNodeID; 132 + } ddpProto, DDPProto; 133 + #define ddpSize sizeof(ddpProto) 134 + 135 + typedef struct nbpProto { 136 + ABCallType abOpcode; 137 + int abResult; 138 + long abUserReference; 139 + EntityPtr nbpEntityPtr; 140 + Ptr nbpBufPtr; 141 + int nbpBufSize; 142 + int nbpDataField; 143 + AddrBlock nbpAddress; 144 + RetransType nbpRetransmitInfo; 145 + } nbpProto, NBPProto; 146 + #define nbpSize sizeof(nbpProto) 147 + 148 + typedef struct atpProto { 149 + ABCallType abOpcode; 150 + int abResult; 151 + long abUserReference; 152 + unsigned atpSocket; 153 + AddrBlock atpAddress; 154 + int atpReqCount; 155 + Ptr atpDataPtr; 156 + BDSPtr atpRspBDSPtr; 157 + BitMapType atpBitMap; 158 + int atpTransID; 159 + int atpActCount; 160 + long atpUserData; 161 + Boolean atpXO; 162 + Boolean atpEOM; 163 + unsigned atpTimeOut; 164 + unsigned atpRetries; 165 + unsigned atpNumBufs; 166 + unsigned atpNumRsp; 167 + unsigned atpBDSSize; 168 + long atpRspUData; 169 + Ptr atpRspBuf; 170 + int atpRspSize; 171 + } atpProto, ATPProto; 172 + #define atpSize sizeof(atpProto) 173 + 174 + typedef union { 175 + lapProto lapProto; 176 + ddpProto ddpProto; 177 + nbpProto nbpProto; 178 + atpProto atpProto; 179 + } ABusRecord, *ABRecPtr, **ABRecHandle; 180 + 181 + 182 + #endif _Appletalk_
+87
headers/ControlMgr.h
··· 1 + 2 + /* 3 + * ControlMgr.h 4 + * 5 + * Copyright (c) 1986 THINK Technologies, Inc. 6 + * These interfaces are based on information published in 7 + * "Inside Macintosh" by Apple Computer, Addison-Wesley, 8 + * Reading (Mass.), 1985. 9 + * 10 + */ 11 + 12 + #ifndef _ControlMgr_ 13 + #define _ControlMgr_ 14 + 15 + #ifndef _MacTypes_ 16 + #include "MacTypes.h" /* needs Mactypes.h */ 17 + #endif 18 + 19 + #ifndef _WindowMgr_ 20 + #include "WindowMgr.h" /* needs WindowMgr.h */ 21 + #endif 22 + 23 + /* control messages */ 24 + enum { 25 + drawCntl, 26 + testCntl, 27 + calcCRgns, 28 + initCntl, 29 + dispCntl, 30 + posCntl, 31 + thumbCntl, 32 + dragCntl, 33 + autoTrack 34 + }; 35 + 36 + /* findcontrol result codes */ 37 + enum { 38 + inButton = 10, 39 + inCheckBox = 11, 40 + inUpButton = 20, 41 + inDownButton = 21, 42 + inPageUp = 22, 43 + inPageDown = 23, 44 + inThumb = 129 45 + }; 46 + 47 + /* control def proc id's */ 48 + enum { 49 + pushButProc, 50 + checkBoxProc, 51 + radioButProc, 52 + useWFont = 8, 53 + scrollBarProc = 16 54 + }; 55 + 56 + /* Axis constraints for drag control */ 57 + /* #define noConstraint 0 defined in WindowMgr.h */ 58 + /* #define hAxisOnly 1 defined in WindowMgr.h */ 59 + /* #define vAxisOnly 2 defined in WindowMgr.h */ 60 + 61 + 62 + typedef struct ControlRecord 63 + { 64 + struct ControlRecord ** nextControl ; 65 + WindowPtr contrlOwner ; 66 + Rect contrlRect ; 67 + char contrlVis ; 68 + char contrlHilite ; 69 + int contrlValue ; 70 + int contrlMin ; 71 + int contrlMax ; 72 + Handle contrlDefProc ; 73 + Handle contrlData ; 74 + ProcPtr contrlAction ; 75 + long contrlRfCon ; 76 + Str255 contrlTitle ; 77 + } ControlRecord ; 78 + typedef ControlRecord * ControlPtr ; 79 + typedef ControlPtr * ControlHandle ; 80 + 81 + 82 + /* functions returning non-integral values */ 83 + pascal ControlHandle NewControl(); 84 + pascal ControlHandle GetNewControl(); 85 + pascal ProcPtr GetCtlAction(); 86 + 87 + #endif
+23
headers/DeskMgr.h
··· 1 + 2 + /* 3 + * DeskMgr.h 4 + * 5 + * Copyright (c) 1986 THINK Technologies, Inc. 6 + * These interfaces are based on information published in 7 + * "Inside Macintosh" by Apple Computer, Addison-Wesley, 8 + * Reading (Mass.), 1985. 9 + * 10 + */ 11 + 12 + #ifndef _DeskMgr_ 13 + #define _DeskMgr_ 14 + 15 + enum { 16 + undoCmd, 17 + cutCmd = 2, 18 + copyCmd, 19 + pasteCmd, 20 + clearCmd 21 + }; 22 + 23 + #endif
+136
headers/DeviceMgr.h
··· 1 + 2 + /* 3 + * DeviceMgr.h 4 + * 5 + * Copyright (c) 1986 THINK Technologies, Inc. 6 + * These interfaces are based on information published in 7 + * "Inside Macintosh" by Apple Computer, Addison-Wesley, 8 + * Reading (Mass.), 1985-86. 9 + * 10 + */ 11 + 12 + #ifndef _DeviceMgr_ 13 + #define _DeviceMgr_ 14 + 15 + #ifndef _MacTypes_ 16 + #include "MacTypes.h" 17 + #endif 18 + 19 + #ifndef _OSUtil_ 20 + #include "OSUtil.h" 21 + #endif 22 + 23 + 24 + /* parameter block for Control/Status calls */ 25 + typedef struct 26 + { 27 + QElemPtr qLink; 28 + int qType; 29 + int ioTrap; 30 + Ptr ioCmdAddr; 31 + ProcPtr ioCompletion; 32 + OsErr ioResult; 33 + StringPtr ioNamePtr; 34 + int ioVRefNum; 35 + int ioRefNum; 36 + int csCode; 37 + int csParam[]; 38 + } cntrlParam; 39 + 40 + /* csCode */ 41 + enum { 42 + goodBye = -1, 43 + killCode = 1, 44 + accEvent = 64, 45 + accRun, 46 + accCursor, 47 + accMenu, 48 + accUndo, 49 + accCut = 70, 50 + accCopy, 51 + accPaste, 52 + accClear 53 + }; 54 + 55 + 56 + /* device control entry */ 57 + typedef struct DCtlEntry 58 + { 59 + Ptr dCtlDriver; 60 + int dCtlFlags; 61 + QHdr dCtlQHdr; 62 + long dCtlPosition; 63 + Handle dCtlStorage; 64 + int dCtlRefNum; 65 + long dCtlCurTicks; 66 + struct GrafPort *dCtlWindow; 67 + int dCtlDelay; 68 + int dCtlEMask; 69 + int dCtlMenu; 70 + } DCtlEntry ; 71 + typedef DCtlEntry * DCtlPtr; 72 + typedef DCtlPtr * DCtlHandle; 73 + 74 + /* dCtlFlags bits */ 75 + #define dNeedLock 0x4000 76 + #define dNeedTime 0x2000 77 + #define dNeedGoodBye 0x1000 78 + #define dStatEnable 0x0800 79 + #define dCtlEnable 0x0400 80 + #define dWritEnable 0x0200 81 + #define dReadEnable 0x0100 82 + #define drvrActive 0x0080 83 + #define dRAMBased 0x0040 84 + #define dOpened 0x0020 85 + 86 + /* traps */ 87 + #define aRdCmd 2 88 + #define aWrCmd 3 89 + #define asyncTrpBit 0x0400 90 + #define noQueueBit 0x0200 91 + 92 + /* result codes */ 93 + enum { 94 + notOpenErr = -28, 95 + abortErr, 96 + dInstErr, 97 + dRemovErr, 98 + closeErr, 99 + openErr, 100 + unitEmptyErr, 101 + badUnitErr, 102 + writErr, 103 + readErr, 104 + statusErr, 105 + controlErr 106 + }; 107 + 108 + /* chooser interface */ 109 + enum { 110 + chooserID, /* caller value for chooser */ 111 + newSelMsg = 12, /* message values */ 112 + fillListMsg, 113 + getSelMsg, 114 + selectMsg, 115 + deselectMsg, 116 + terminateMsg, 117 + buttonMsg = 19 118 + }; 119 + 120 + 121 + /* functions returning non-integral values */ 122 + pascal DCtlHandle GetDCtlEntry(); 123 + 124 + /* low-memory globals */ 125 + extern DCtlHandle *UTableBase : 0x11C; 126 + extern ProcPtr Lvl1DT[] : 0x192; 127 + extern ProcPtr Lvl2DT[] : 0x1B2; 128 + extern int UnitNtryCnt : 0x1D2; 129 + extern Ptr VIA : 0x1D4; 130 + extern Ptr SCCRd : 0x1D8; 131 + extern Ptr SCCWr : 0x1DC; 132 + extern Ptr IWM : 0x1E0; 133 + extern ProcPtr ExtStsDT[] : 0x2BE; 134 + 135 + 136 + #endif _DeviceMgr_
+117
headers/DialogMgr.h
··· 1 + 2 + /* 3 + * DialogMgr.h 4 + * 5 + * Copyright (c) 1986 THINK Technologies, Inc. 6 + * These interfaces are based on information published in 7 + * "Inside Macintosh" by Apple Computer, Addison-Wesley, 8 + * Reading (Mass.), 1985. 9 + * 10 + */ 11 + 12 + #ifndef _DialogMgr_ 13 + #define _DialogMgr_ 14 + 15 + #ifndef _MacTypes_ 16 + #include "MacTypes.h" 17 + #endif 18 + 19 + #ifndef _WindowMgr_ 20 + #include "WindowMgr.h" 21 + #endif 22 + 23 + #ifndef _TextEdit_ 24 + #include "TextEdit.h" 25 + #endif 26 + 27 + /* item types */ 28 + enum { 29 + userItem = 0, 30 + ctrlItem = 4, 31 + statText = 8, 32 + editText = 16, 33 + iconItem = 32, 34 + picItem = 64, 35 + itemDisable = 128 36 + }; 37 + 38 + /* control item types */ 39 + enum { 40 + btnCtrl, 41 + chkCtrl, 42 + radCtrl, 43 + resCtrl 44 + }; 45 + 46 + /* buttons */ 47 + enum { 48 + OK = 1, 49 + Cancel 50 + }; 51 + 52 + /* alert icons */ 53 + enum { 54 + stopIcon, 55 + noteIcon, 56 + cautionIcon 57 + }; 58 + #define ctnIcon cautionIcon 59 + 60 + 61 + typedef struct DialogRecord 62 + { 63 + WindowRecord window; 64 + Handle items ; 65 + TEHandle textH; 66 + int editField; 67 + int editOpen; 68 + int aDefItem; 69 + } DialogRecord ; 70 + typedef DialogRecord * DialogPeek; 71 + typedef WindowPtr DialogPtr ; 72 + 73 + typedef struct DialogTemplate 74 + { 75 + Rect boundsRect; 76 + int procID; 77 + char visible; 78 + char filler1; 79 + char goAwayFlag; 80 + char filler2; 81 + long refCon; 82 + int itemsID; 83 + Str255 title; 84 + } DialogTemplate; 85 + typedef DialogTemplate * DialogTPtr; 86 + typedef DialogTPtr * DialogTHndl; 87 + 88 + typedef struct AlertTemplate 89 + { 90 + Rect boundsRect; 91 + int itemsID; 92 + unsigned int boldItm4 : 1; /* this is StageList */ 93 + unsigned int boxDrwn4 : 1; 94 + unsigned int sound4 : 2; 95 + unsigned int boldItm3 : 1; 96 + unsigned int boxDrwn3 : 1; 97 + unsigned int sound3 : 2; 98 + unsigned int boldItm2 : 1; 99 + unsigned int boxDrwn2 : 1; 100 + unsigned int sound2 : 2; 101 + unsigned int boldItm1 : 1; 102 + unsigned int boxDrwn1 : 1; 103 + unsigned int sound1 : 2; 104 + } AlertTemplate; 105 + typedef AlertTemplate * AlertTPtr; 106 + typedef AlertTPtr * AlertTHndl; 107 + 108 + 109 + 110 + /* functions returning non-integral values */ 111 + pascal DialogPtr NewDialog(); 112 + pascal DialogPtr GetNewDialog(); 113 + 114 + /* low-memory globals */ 115 + extern ProcPtr ResumeProc : 0xA8C; 116 + 117 + #endif
+62
headers/DiskDvr.h
··· 1 + 2 + /* 3 + * DiskDvr.h 4 + * 5 + * Copyright (c) 1986 THINK Technologies, Inc. 6 + * These interfaces are based on information published in 7 + * "Inside Macintosh" by Apple Computer, Addison-Wesley, 8 + * Reading (Mass.), 1985. 9 + * 10 + */ 11 + 12 + #ifndef _DiskDvr_ 13 + #define _DiskDvr_ 14 + 15 + /* positioning */ 16 + #define currPos 0 /* fsAtMark */ 17 + #define absPos 1 /* fsFromStart */ 18 + #define relPos 3 /* fsFromMark */ 19 + 20 + typedef struct 21 + { 22 + int track; 23 + char writeProt; 24 + char diskInPlace; 25 + char installed; 26 + char sides; 27 + struct QElem *qLink; 28 + int qType; 29 + int dQDrive; 30 + int dQRefNum; 31 + int dQFSID; 32 + char twoSideFmt; 33 + char needsFlush; 34 + int diskErrs; 35 + } DrvSts; 36 + 37 + /* result codes */ 38 + #define firstDskErr (-84) 39 + enum { 40 + sectNFErr = -81, 41 + seekErr, 42 + spdAdjErr, 43 + twoSideErr, 44 + initIWMErr, 45 + tk0BadErr, 46 + cantStepErr, 47 + wrUnderrun, 48 + badDBtSlp, 49 + badDCksum, 50 + noDtaMkErr, 51 + badBtSlpErr, 52 + badCksmErr, 53 + dataVerErr, 54 + noAdrMkErr, 55 + noNybErr, 56 + offLinErr, 57 + noDriveErr 58 + }; 59 + #define lastDskErr (-64) 60 + 61 + 62 + #endif
+120
headers/EventMgr.h
··· 1 + 2 + /* 3 + * EventMgr.h 4 + * 5 + * Copyright (c) 1986 THINK Technologies, Inc. 6 + * These interfaces are based on information published in 7 + * "Inside Macintosh" by Apple Computer, Addison-Wesley, 8 + * Reading (Mass.), 1985. 9 + * 10 + */ 11 + 12 + #ifndef _EventMgr_ 13 + #define _EventMgr_ 14 + 15 + #ifndef _MacTypes_ 16 + #include "MacTypes.h" 17 + #endif 18 + 19 + /* event codes */ 20 + enum { 21 + nullEvent, 22 + mouseDown, 23 + mouseUp, 24 + keyDown, 25 + keyUp, 26 + autoKey, 27 + updateEvt, 28 + diskEvt, 29 + activateEvt, 30 + /* event 9 is no longer used */ 31 + networkEvt = 10, 32 + driverEvt, 33 + app1Evt, 34 + app2Evt, 35 + app3Evt, 36 + app4Evt 37 + }; 38 + 39 + /* masks for keyboard event message */ 40 + #define charCodeMask 0x000000FFL 41 + #define keyCodeMask 0x0000FF00L 42 + 43 + /* event masks */ 44 + #define mDownMask 0x2 45 + #define mUpMask 0x4 46 + #define keyDownMask 0x8 47 + #define keyUpMask 0x10 48 + #define autoKeyMask 0x20 49 + #define updateMask 0x40 50 + #define diskMask 0x80 51 + #define activMask 0x100 52 + /* event 9 is no longer used */ 53 + #define networkMask 0x400 54 + #define driverMask 0x800 55 + #define app1Mask 0x1000 56 + #define app2Mask 0x2000 57 + #define app3Mask 0x4000 58 + #define app4Mask 0x8000 59 + #define everyEvent 0xFFFF 60 + 61 + /* modifiers */ 62 + #define activeFlag 0x0001 63 + #define changeFlag 0x0002 64 + #define btnState 0x0080 65 + #define cmdKey 0x0100 66 + #define shiftKey 0x0200 67 + #define alphaLock 0x0400 68 + #define optionKey 0x0800 69 + 70 + 71 + /* results returned by PostEvent */ 72 + /* #define noErr 0 */ 73 + #define EvtNotEnb 1 74 + 75 + 76 + typedef struct EventRecord 77 + { 78 + int what; 79 + long message; 80 + long when; 81 + Point where; 82 + int modifiers; 83 + }EventRecord; 84 + 85 + typedef struct KeyMap 86 + { 87 + long Key[4]; 88 + }KeyMap; 89 + 90 + typedef struct EvQEl 91 + { 92 + struct QElem *qLink; 93 + int qType; 94 + int evtQWhat; 95 + long evtQMessage; 96 + long evtQWhen; 97 + Point evtQWhere; 98 + int evtQModifiers; 99 + } EvQEl, *EvQElPtr ; 100 + 101 + 102 + /* functions returning non-integral values */ 103 + pascal struct QHdr *GetEvQHdr(); 104 + 105 + /* low-memory globals */ 106 + extern int SysEvtMask : 0x144; 107 + extern struct QHdr EventQueue : 0x14A; 108 + extern char SEvtEnb : 0x15C; 109 + extern long Ticks : 0x16A; 110 + extern int KeyThresh : 0x18E; 111 + extern int KeyRepThresh : 0x190; 112 + extern ProcPtr JGNEFilter : 0x29A; 113 + extern ProcPtr Key1Trans : 0x29E; 114 + extern ProcPtr Key2Trans : 0x2A2; 115 + extern long DoubleTime : 0x2F0; 116 + extern long CaretTime : 0x2F4; 117 + extern char ScrDmpEnb : 0x2F8; 118 + 119 + 120 + #endif
+235
headers/FileMgr.h
··· 1 + 2 + /* 3 + * FileMgr.h 4 + * 5 + * Copyright (c) 1986 THINK Technologies, Inc. 6 + * These interfaces are based on information published in 7 + * "Inside Macintosh" by Apple Computer, Addison-Wesley, 8 + * Reading (Mass.), 1985-86. 9 + * 10 + */ 11 + 12 + #ifndef _FileMgr_ 13 + #define _FileMgr_ 14 + 15 + #ifndef _MacTypes_ 16 + #include "MacTypes.h" 17 + #endif 18 + 19 + 20 + /* finder constants */ 21 + #define fHasBundle 8192 22 + #define fInvisible 16384 23 + #define fTrash (-3) 24 + #define fDeskTop (-2) 25 + #define fDisk 0 26 + #define fOnDesk 1 27 + 28 + 29 + /* ioPosMode values */ 30 + enum { 31 + fsAtMark, 32 + fsFromStart, 33 + fsFromLEOF, 34 + fsFromMark 35 + }; 36 + #define rdVerify 64 37 + 38 + 39 + /* ioPermssn values */ 40 + enum { 41 + fsCurPerm, 42 + fsRdPerm, 43 + fsWrPerm, 44 + fsRdWrPerm, 45 + fsRdWrShPerm 46 + }; 47 + 48 + 49 + /* result codes */ 50 + enum { 51 + fsDSIntErr = -127, 52 + wrgVolTypErr = -123, 53 + badMovErr, 54 + tmwdoErr, 55 + dirNFErr, 56 + wrPermErr = -61, 57 + badMDBErr, 58 + fsRnErr, 59 + extFSErr, 60 + noMacDskErr, 61 + nsDrvErr, 62 + volOnLinErr, 63 + permErr, 64 + volOffLinErr, 65 + gfpErr, 66 + rfNumErr, 67 + paramErr, 68 + opWrErr, 69 + dupFNErr, 70 + fBsyErr, 71 + vLckdErr, 72 + fLckdErr, 73 + wPrErr, 74 + fnfErr, 75 + tmfoErr, 76 + mFulErr, 77 + posErr, 78 + eofErr, 79 + fnOpnErr, 80 + bdNamErr, 81 + ioErr, 82 + nsvErr, 83 + dskFulErr, 84 + dirFulErr 85 + }; 86 + 87 + 88 + /* standard header used in all PB records */ 89 + #define STANDARD_PBHEADER \ 90 + struct QElem * qLink; \ 91 + int qType; \ 92 + int ioTrap; \ 93 + Ptr ioCmdAddr; \ 94 + ProcPtr ioCompletion; \ 95 + OsErr ioResult; \ 96 + StringPtr ioNamePtr; \ 97 + int ioVRefNum; 98 + 99 + 100 + typedef struct 101 + { 102 + OsType fdType; 103 + OsType fdCreator; 104 + int fdFlags; 105 + Point fdLocation; 106 + int fdFldr; 107 + } FInfo ; 108 + 109 + 110 + typedef struct 111 + { 112 + STANDARD_PBHEADER 113 + int ioRefNum; 114 + SignedByte ioVersNum; 115 + SignedByte ioPermssn; 116 + Ptr ioMisc; 117 + Ptr ioBuffer; 118 + long ioReqCount; 119 + long ioActCount; 120 + int ioPosMode; 121 + long ioPosOffset; 122 + } ioParam, IOParam ; 123 + 124 + /* file parameter block */ 125 + typedef struct 126 + { 127 + STANDARD_PBHEADER 128 + int ioFRefNum; 129 + SignedByte ioFVersNum; 130 + SignedByte filler1; 131 + int ioFDirIndex; 132 + SignedByte ioFlAttrib; 133 + SignedByte ioFlVersNum; 134 + FInfo ioFlFndrInfo; 135 + long ioFlNum; 136 + int ioFlStBlk; 137 + long ioFlLgLen; 138 + long ioFlPyLen; 139 + int ioFlRStBlk; 140 + long ioFlRLgLen; 141 + long ioFlRPyLen; 142 + long ioFlCrDat; 143 + long ioFlMdDat; 144 + } fileParam, FileParam ; 145 + 146 + /* volume parameter block */ 147 + typedef struct 148 + { 149 + STANDARD_PBHEADER 150 + long filler2; 151 + int ioVolIndex; 152 + long ioVCrDate; 153 + long ioVLsBkUp; 154 + int ioVAtrb; 155 + int ioVNmFls; 156 + int ioVDirSt; 157 + int ioVBlLn; 158 + int ioVNmAlBlks; 159 + long ioVAlBlkSiz; 160 + long ioVClpSiz; 161 + int ioAlBlSt; 162 + long ioVNxtFNum; 163 + int ioVFrBlk; 164 + } volumeParam, VolumeParam ; 165 + 166 + 167 + typedef union { 168 + ioParam ioParam; 169 + fileParam fileParam; 170 + volumeParam volumeParam; 171 + } ParamBlockRec, *ParmBlkPtr; 172 + 173 + 174 + /* volume control block */ 175 + typedef struct 176 + { 177 + struct QElem *qLink; 178 + int qType; 179 + int vcbFlags; 180 + int vcbSigWord; 181 + long vcbCrDate; 182 + long vcbLsBkUp; 183 + int vcbAtrb; 184 + int vcbNmFls; 185 + int vcbDirSt; 186 + int vcbBlLn; 187 + int vcbNmBlks; 188 + long vcbAlBlkSiz; 189 + long vcbClpSiz; 190 + int vcbAlBlSt; 191 + long vcbNxtFNum; 192 + int vcbFreeBks; 193 + char vcbVN[28]; 194 + int vcbDrvNum; 195 + int vcbDRefNum; 196 + int vcbFSID; 197 + int vcbVRefNum; 198 + Ptr vcbMAdr; 199 + Ptr vcbBufAdr; 200 + int vcbMLen; 201 + int vcbDirIndex; 202 + int vcbDirBlk; 203 + } VCB ; 204 + 205 + 206 + /* drive queue element */ 207 + 208 + typedef struct 209 + { 210 + /* long flags; */ 211 + struct QElem *qLink; 212 + int qType; 213 + int dQDrive; 214 + int dQRefNum; 215 + int dQFSID; 216 + int dQDrvSize; 217 + } DrvQEl,*DrvQElPtr ; 218 + 219 + 220 + /* functions returning non-integral values */ 221 + pascal struct QHdr *GetFSQHdr(); 222 + pascal struct QHdr *GetDrvQHdr(); 223 + pascal struct QHdr *GetVCBQHdr(); 224 + 225 + /* low-memory globals */ 226 + extern int BootDrive : 0x210; 227 + extern struct QHdr DrvQHdr : 0x308; 228 + extern ProcPtr EjectNotify : 0x338; 229 + extern Ptr FCBSPtr : 0x34E; 230 + extern VCB *DefVCBPtr : 0x352; 231 + extern struct QHdr VCBQHdr : 0x356; 232 + extern struct QHdr FSQHdr : 0x360; 233 + 234 + 235 + #endif
+170
headers/FontMgr.h
··· 1 + 2 + /* 3 + * FontMgr.h 4 + * 5 + * Copyright (c) 1986 THINK Technologies, Inc. 6 + * These interfaces are based on information published in 7 + * "Inside Macintosh" by Apple Computer, Addison-Wesley, 8 + * Reading (Mass.), 1985-86. 9 + * 10 + */ 11 + 12 + #ifndef _FontMgr_ 13 + #define _FontMgr_ 14 + 15 + #ifndef _MacTypes_ 16 + #include "MacTypes.h" 17 + #endif 18 + 19 + /* font numbers */ 20 + enum { 21 + systemFont, 22 + applFont, 23 + newYork, 24 + geneva, 25 + monaco, 26 + venice, 27 + london, 28 + athens, 29 + sanFran, 30 + toronto, 31 + cairo = 11, 32 + losAngeles, 33 + times = 20, 34 + helvetica, 35 + courier, 36 + symbol, 37 + taliesin 38 + }; 39 + 40 + #define propFont 0x9000 41 + #define prpFntH 0x9001 42 + #define prpFntW 0x9002 43 + #define prpFntHW 0x9003 44 + #define fixedFont 0xB000 45 + #define fxdFntH 0xB001 46 + #define fxdFntW 0xB002 47 + #define fxdFntHW 0xB003 48 + #define fontWid 0xACB0 49 + 50 + #define fMgrCtl1 8 51 + 52 + 53 + typedef struct FMInput 54 + { 55 + int family ; 56 + int size ; 57 + char face ; 58 + char needBits ; 59 + int device ; 60 + Point numer ; 61 + Point denom ; 62 + } FMInput ; 63 + 64 + typedef struct FMOutput 65 + { 66 + int errNum ; 67 + Handle fontHandle ; 68 + char bold ; 69 + char italic ; 70 + char ulOffset ; 71 + char ulShadow ; 72 + char ulThick ; 73 + char shadow ; 74 + SignedByte extra ; 75 + char ascent ; 76 + char descent ; 77 + char widMax ; 78 + SignedByte leading ; 79 + char unused ; 80 + Point numer ; 81 + Point denom ; 82 + } FMOutput ; 83 + typedef FMOutput * FMOutPtr ; 84 + 85 + typedef struct FontRec 86 + { 87 + int fontType ; 88 + int firstChar ; 89 + int lastChar ; 90 + int widMax ; 91 + int kernMax ; 92 + int nDescent ; 93 + int fRectMax ; 94 + int chHeight ; 95 + int owTLoc ; 96 + int ascent ; 97 + int descent ; 98 + int leading ; 99 + int rowWords ; 100 + /* int bitImage[rowWords][chHeight]; */ 101 + /* int locTable[]; */ 102 + /* int owTable[]; */ 103 + } FontRec ; 104 + 105 + typedef struct FMetricRec { 106 + Fixed ascent; 107 + Fixed descent; 108 + Fixed leading; 109 + Fixed widMax; 110 + Handle wTabHandle; 111 + } FMetricRec; 112 + 113 + typedef struct FamRec { 114 + int ffFlags; 115 + int ffFamID; 116 + int ffFirstChar; 117 + int ffLastChar; 118 + int ffAscent; 119 + int ffDescent; 120 + int ffLeading; 121 + int ffWidMax; 122 + long ffWTabOff; 123 + long ffKernOff; 124 + long ffStylOff; 125 + int ffProperty[9]; 126 + int ffIntl[2]; 127 + int ffVersion; 128 + /* FontAssoc ffAssoc; */ 129 + /* WidTable ffWidthTab; */ 130 + /* StyleTable ffStyTab; */ 131 + /* KernTable ffKernTab; */ 132 + } FamRec; 133 + 134 + typedef struct WidthTable { 135 + Fixed tabData[256]; 136 + Handle tabFont; 137 + long sExtra; 138 + long style; 139 + int fID; 140 + int fSize; 141 + int face; 142 + int device; 143 + Point inNumer; 144 + Point inDenom; 145 + int aFID; 146 + Handle fHand; 147 + Boolean usedFam; 148 + Byte aFace; 149 + int vOutput; 150 + int hOutput; 151 + int vFactor; 152 + int hFactor; 153 + int aSize; 154 + int tabSize; 155 + } WidthTable; 156 + 157 + 158 + /* functions returning non-integral values */ 159 + pascal FMOutPtr SwapFont(); 160 + pascal FMOutPtr FMSwapFont(); 161 + 162 + /* low-memory globals */ 163 + extern int ApFontID : 0x984; 164 + extern char FScaleDisable : 0xA63; 165 + extern char FractEnable : 0xBF4; 166 + extern WidthTable **WidthTabHandle : 0xB2A; 167 + extern FamRec **LastFOND : 0xBC2; 168 + 169 + 170 + #endif
+268
headers/HFS.h
··· 1 + 2 + /* 3 + * HFS.h 4 + * 5 + * Copyright (c) 1986 THINK Technologies, Inc. 6 + * These interfaces are based on information published in 7 + * "Inside Macintosh" by Apple Computer, Addison-Wesley, 8 + * Reading (Mass.), 1986. 9 + * 10 + */ 11 + 12 + 13 + #ifndef _HFS_ 14 + #define _HFS_ 15 + 16 + #ifndef _FileMgr_ 17 + #include "FileMgr.h" 18 + #endif 19 + 20 + 21 + typedef struct { 22 + int fdIconID; 23 + int fdUnused[4]; 24 + int fdComment; 25 + long fdPutAway; 26 + } FXInfo; 27 + 28 + typedef struct { 29 + Rect frRect; 30 + int frFlags; 31 + Point frLocation; 32 + int frView; 33 + } DInfo; 34 + 35 + typedef struct { 36 + Point frScroll; 37 + long frOpenChain; 38 + int frUnused; 39 + int frComment; 40 + long fdPutAway; 41 + } DXInfo; 42 + 43 + 44 + typedef IOParam HIOParam; 45 + 46 + typedef struct { 47 + STANDARD_PBHEADER 48 + int ioFRefNum; 49 + SignedByte ioFVersNum; 50 + SignedByte filler1; 51 + int ioFDirIndex; 52 + SignedByte ioFlAttrib; 53 + SignedByte ioFlVersNum; 54 + FInfo ioFlFndrInfo; 55 + long ioDirID; 56 + int ioFlStBlk; 57 + long ioFlLgLen; 58 + long ioFlPyLen; 59 + int ioFlRStBlk; 60 + long ioFlRLgLen; 61 + long ioFlRPyLen; 62 + long ioFlCrDat; 63 + long ioFlMdDat; 64 + } HFileParam ; 65 + 66 + typedef struct { 67 + STANDARD_PBHEADER 68 + long filler2; 69 + int ioVolIndex; 70 + long ioVCrDate; 71 + long ioVLsMod; 72 + int ioVAtrb; 73 + int ioVNmFls; 74 + int ioVBitMap; 75 + int ioAllocPtr; 76 + int ioVNmAlBlks; 77 + long ioVAlBlkSiz; 78 + long ioVClpSiz; 79 + int ioAlBlSt; 80 + long ioVNxtCNID; 81 + int ioVFrBlk; 82 + int ioVSigWord; 83 + int ioVDrvInfo; 84 + int ioVDRefNum; 85 + int ioVFSID; 86 + long ioVBkUp; 87 + int ioVSeqNum; 88 + long ioVWrCnt; 89 + long ioVFilCnt; 90 + long ioVDirCnt; 91 + long ioVFndrInfo[8]; 92 + } HVolumeParam; 93 + 94 + typedef union { 95 + HIOParam ioParam; 96 + HFileParam fileParam; 97 + HVolumeParam volumeParam; 98 + } HParamBlockRec, *HParmBlkPtr; 99 + 100 + 101 + typedef struct { 102 + STANDARD_PBHEADER 103 + int ioFRefNum; 104 + SignedByte ioFVersNum; 105 + SignedByte filler1; 106 + int ioFDirIndex; 107 + SignedByte ioFlAttrib; 108 + SignedByte filler2; 109 + FInfo ioFlFndrInfo; 110 + long ioDirID; 111 + int ioFlStBlk; 112 + long ioFlLgLen; 113 + long ioFlPyLen; 114 + int ioFlRStBlk; 115 + long ioFlRLgLen; 116 + long ioFlRPyLen; 117 + long ioFlCrDat; 118 + long ioFlMdDat; 119 + long ioFlBkDat; 120 + FXInfo ioFlXFndrInfo; 121 + long ioFlParID; 122 + long ioFlClpSiz; 123 + } HFileInfo; 124 + 125 + typedef struct { 126 + STANDARD_PBHEADER 127 + int ioFRefNum; 128 + SignedByte ioFVersNum; 129 + SignedByte filler1; 130 + int ioFDirIndex; 131 + SignedByte ioFlAttrib; 132 + SignedByte filler2; 133 + DInfo ioDrUsrWds; 134 + long ioDrDirID; 135 + int ioDrNmFls; 136 + int filler3[9]; 137 + long ioDrCrDat; 138 + long ioDrMdDat; 139 + long ioDrBkDat; 140 + DXInfo ioDrFndrInfo; 141 + long ioDrParID; 142 + } DirInfo; 143 + 144 + typedef union { 145 + HFileInfo hFileInfo; 146 + DirInfo dirInfo; 147 + } CInfoPBRec, *CInfoPBPtr; 148 + 149 + 150 + typedef struct { 151 + STANDARD_PBHEADER 152 + long filler1; 153 + StringPtr ioNewName; 154 + long filler2; 155 + long ioNewDirID; 156 + long filler3[2]; 157 + long ioDirID; 158 + } CMovePBRec, *CMovePBPtr; 159 + 160 + 161 + typedef struct { 162 + STANDARD_PBHEADER 163 + int filler1; 164 + int ioWDIndex; 165 + long ioWDProcID; 166 + int ioWDVRefNum; 167 + int filler2[7]; 168 + long ioWDDirID; 169 + } WDPBRec, *WDPBPtr; 170 + 171 + 172 + typedef struct { 173 + STANDARD_PBHEADER 174 + int ioRefNum; 175 + int filler; 176 + int ioFCBIndx; 177 + int ioFCBFiller1; 178 + long ioFCBFlNm; 179 + int ioFCBFlags; 180 + int ioFCBStBlk; 181 + long ioFCBEOF; 182 + long ioFCBPLen; 183 + long ioFCBCrPs; 184 + int ioFCBVRefNum; 185 + long ioFCBClpSiz; 186 + long ioFCBParID; 187 + } FCBPBRec, *FCBPBPtr; 188 + 189 + 190 + typedef struct { 191 + struct QElem * qLink; 192 + int qtype; 193 + int vcbFlags; 194 + int vcbSigWord; 195 + long vcbCrDate; 196 + long vcbLsMod; 197 + int vcbAtrb; 198 + int vcbNmFls; 199 + int vcbVBMSt; 200 + int vcbAllocPtr; 201 + int vcbNmAlBlks; 202 + long vcbAlBlkSiz; 203 + long vcbClpSIz; 204 + int vcbAlBlSt; 205 + long vcbNxtCNID; 206 + int vcbFreeBks; 207 + char vcbVN[28]; 208 + int vcbDrvNum; 209 + int vcbDRefNum; 210 + int vcbFSID; 211 + int vcbVRefNum; 212 + Ptr vcbMAdr; 213 + Ptr vcbBufAdr; 214 + int vcbMLen; 215 + int vcbDirIndex; 216 + int vcbDirBlk; 217 + long vcbVolBkUp; 218 + int vcbVSeqNum; 219 + long vcbWrCnt; 220 + long vcbXTClpSiz; 221 + long vcbCTClpSiz; 222 + int vcbNmRtDirs; 223 + long vcbFilCnt; 224 + long vcbDirCnt; 225 + long vcbFndrInfo[8]; 226 + int vcbVCSize; 227 + int vcbVBMCSiz; 228 + int vcbCtlCSiz; 229 + int vcbXTAlBlks; 230 + int vcbCTAlBlks; 231 + int vcbXTRef; 232 + int vcbCTRef; 233 + Ptr vcbCtlBuf; 234 + long vcbDirIDM; 235 + int vcbOffsM; 236 + } HVCB; 237 + 238 + 239 + typedef struct { 240 + /* long flags; */ 241 + struct QElem * qLink; 242 + int qType; 243 + int dQDrive; 244 + int dQRefNum; 245 + int dQFSID; 246 + int dQDrvSz; 247 + int dQDrvSz2; 248 + } HDrvQEl, *HDrvQElPtr; 249 + 250 + 251 + typedef struct { 252 + char sigWord[2]; 253 + long abSize; 254 + long clpSize; 255 + long nxFreeFN; 256 + long btClpSize; 257 + int rsrv1; 258 + int rsrv2; 259 + int rsrv3; 260 + } HFSDefaults; 261 + 262 + 263 + /* low-memory globals */ 264 + extern int FSFCBLen : 0x3F6; 265 + extern HFSDefaults *FmtDefaults : 0x39E; 266 + 267 + 268 + #endif
+119
headers/IntlPkg.h
··· 1 + 2 + /* 3 + * IntlPkg.h 4 + * 5 + * Copyright (c) 1986 THINK Technologies, Inc. 6 + * These interfaces are based on information published in 7 + * "Inside Macintosh" by Apple Computer, Addison-Wesley, 8 + * Reading (Mass.), 1985. 9 + * 10 + */ 11 + 12 + 13 + #ifndef _IntlPkg_ 14 + #define _IntlPkg_ 15 + 16 + #ifndef _MacTypes_ 17 + #include "MacTypes.h" 18 + #endif 19 + 20 + #define currSymLead 16 21 + #define currNegSym 32 22 + #define currTrailingZ 64 23 + #define currLeadingZ 128 24 + 25 + enum { mdy, dmy, ymd }; 26 + 27 + #define century 128 28 + #define mntLdingZ 64 29 + #define dayLdingZ 32 30 + 31 + #define hrLeadingZ 128 32 + #define minLeadingZ 64 33 + #define secLeadingZ 32 34 + 35 + enum { 36 + verUS, 37 + verFrance, 38 + verBritain, 39 + verGermany, 40 + verItaly, 41 + verNetherlands, 42 + verBelgiumLux, 43 + verSweden, 44 + verSpain, 45 + verDenmark, 46 + verPortugal, 47 + verFrCanada, 48 + verNorway, 49 + verIsrael, 50 + verJapan, 51 + verAustralia, 52 + verArabia, 53 + verFinland, 54 + verFrSwiss, 55 + verGrSwiss, 56 + verGreece, 57 + verIceland, 58 + verMalta, 59 + verCyprus, 60 + verTurkey, 61 + verYugoslavia 62 + }; 63 + 64 + 65 + typedef struct Intl0Rec 66 + { 67 + char decimalPt; 68 + char thousSep; 69 + char listSep; 70 + char currSym1; 71 + char currSym2; 72 + char currSym3; 73 + char currFmt ; 74 + char dateOrder; 75 + char shortDateFmt; 76 + char dateSep ; 77 + char timeCycle; 78 + char timeFmt ; 79 + char mornStr[4]; 80 + char eveStr[4]; 81 + char timeSep; 82 + char time1Suff; 83 + char time2Suff; 84 + char time3Suff; 85 + char time4Suff; 86 + char time5Suff; 87 + char time6Suff; 88 + char time7Suff; 89 + char time8Suff; 90 + char metricSys; 91 + int Intl0Vers; 92 + } Intl0Rec,* Intl0Ptr,** Intl0Hndl ; 93 + 94 + typedef struct Intl1Rec 95 + { 96 + char days[7][16]; 97 + char months[12][16]; 98 + char suppressDay; 99 + char longDateFmt; 100 + char dayleading0; 101 + char abbrLen; 102 + char st0[4]; /* check to see if these should be long */ 103 + char st1[4]; 104 + char st2[4]; 105 + char st3[4]; 106 + char st4[4]; 107 + int intl1Vers; 108 + int localRtn; 109 + } Intl1Rec,* Intl1Ptr,** Intl1Hndl ; 110 + 111 + 112 + typedef enum { shortDate, longDate, abbrevDate } DateForm; 113 + 114 + 115 + /* functions returning non-integral values */ 116 + pascal Handle IUGetIntl(); 117 + 118 + 119 + #endif
+74
headers/ListMgr.h
··· 1 + 2 + /* 3 + * ListMgr.h 4 + * 5 + * Copyright (c) 1986 THINK Technologies, Inc. 6 + * These interfaces are based on information published in 7 + * "Inside Macintosh" by Apple Computer, Addison-Wesley, 8 + * Reading (Mass.), 1986. 9 + * 10 + */ 11 + 12 + #ifndef _ListMgr_ 13 + #define _ListMgr_ 14 + 15 + #ifndef _ControlMgr_ 16 + #include "ControlMgr.h" 17 + #endif 18 + 19 + 20 + /* masks for automatic scrolling */ 21 + #define lDoHAutoScroll 1 22 + #define lDoVAutoScroll 2 23 + 24 + /* masks for selection flags */ 25 + #define lNoNilHilite 2 26 + #define lUseSense 4 27 + #define lNoRect 8 28 + #define lNoExtend 16 29 + #define lNoDisjoint 32 30 + #define lExtendDrag 64 31 + #define lOnlyOne 128 32 + 33 + /* message to defproc */ 34 + enum { lInitMsg, lDrawMsg, lHiliteMsg, lCloseMsg }; 35 + 36 + 37 + typedef Point Cell; 38 + 39 + typedef char DataArray[32000]; 40 + typedef DataArray *DataPtr, **DataHandle; 41 + 42 + typedef struct ListRec { 43 + Rect rView; 44 + GrafPtr port; 45 + Point indent; 46 + Point cellSize; 47 + Rect visible; 48 + ControlHandle vScroll; 49 + ControlHandle hScroll; 50 + char selFlags; 51 + Boolean lActive; 52 + char lReserved; 53 + char listFlags; 54 + long clikTime; 55 + Point clikLoc; 56 + Point mouseLoc; 57 + Ptr lClikLoop; 58 + Cell lastClick; 59 + long refCon; 60 + Handle listDefProc; 61 + Handle userHandle; 62 + Rect dataBounds; 63 + DataHandle cells; 64 + int maxIndex; 65 + int cellArray[]; 66 + } ListRec, *ListPtr, **ListHandle; 67 + 68 + 69 + /* functions returning non-integral values */ 70 + pascal ListHandle LNew(); 71 + /*pascal Cell LLastClick(); -- actually returns a long */ 72 + 73 + 74 + #endif
+56
headers/MacTypes.h
··· 1 + 2 + /* 3 + * MacTypes.h 4 + * 5 + * Copyright (c) 1986 THINK Technologies, Inc. 6 + * These interfaces are based on information published in 7 + * "Inside Macintosh" by Apple Computer, Addison-Wesley, 8 + * Reading (Mass.), 1985. 9 + * 10 + */ 11 + 12 + #ifndef _MacTypes_ 13 + #define _MacTypes_ 14 + 15 + #define noErr 0 16 + 17 + typedef int OsErr, OSErr; 18 + typedef long OsType, OSType; 19 + typedef char SignedByte ; 20 + typedef unsigned char Byte ; 21 + typedef char * Ptr ; 22 + typedef char ** Handle ; 23 + typedef int (*ProcPtr)() ; 24 + typedef long Fixed, Fract; 25 + typedef long Size; 26 + typedef enum { false, true, FALSE = 0, TRUE } Boolean; 27 + typedef unsigned char Str255[256]; 28 + typedef unsigned char * StringPtr,** StringHandle ; 29 + typedef long ResType ; 30 + 31 + 32 + typedef struct 33 + { 34 + int v,h; 35 + } Point ; 36 + 37 + typedef struct 38 + { 39 + int top,left,bottom,right ; 40 + } Rect ; 41 + #define topLeft(r) (((Point *) &(r))[0]) 42 + #define botRight(r) (((Point *) &(r))[1]) 43 + 44 + 45 + /* functions returning non-integral values */ 46 + pascal Handle NewHandle(); 47 + pascal Ptr NewPtr(); 48 + pascal Handle GetResource(); 49 + pascal Handle GetIndResource(); 50 + pascal Handle GetNamedResource(); 51 + 52 + /* low-memory globals */ 53 + extern int ROM85 : 0x28E; 54 + 55 + 56 + #endif
+41
headers/MacinTalk.h
··· 1 + /* 2 + * MacinTalk.h 3 + * 4 + * Copyright (c) 1986 THINK Technologies, Inc. 5 + * These interfaces are based on information published by Apple Computer. 6 + * 7 + */ 8 + 9 + #ifndef _MacTypes_ 10 + #include "MacTypes.h" 11 + #endif 12 + 13 + typedef int SpeechErr; 14 + 15 + typedef char SpeechRecord[100]; 16 + 17 + typedef SpeechRecord *SpeechPointer, **SpeechHandle; 18 + 19 + typedef enum { Male, Female } Sex; 20 + 21 + typedef enum { Natural, Robotic, NoChange } FOMode; 22 + 23 + typedef enum { xEnglish, French, Spanish, German, Italian } Language; 24 + 25 + typedef struct { 26 + Sex theSex; 27 + Language theLanguage; 28 + int theRate; 29 + int thePitch; 30 + FOMode theMode; 31 + Str255 theName; 32 + long refCon; 33 + } VoiceRecord, *VoicePtr; 34 + 35 + pascal SpeechErr SpeechOn(); 36 + pascal void SpeechOff(); 37 + pascal void SpeechRate(); 38 + pascal void SpeechPitch(); 39 + pascal void SpeechSex(); 40 + pascal int Reader(); 41 + pascal int MacinTalk();
+84
headers/MemoryMgr.h
··· 1 + 2 + /* 3 + * MemoryMgr.h 4 + * 5 + * Copyright (c) 1986 THINK Technologies, Inc. 6 + * These interfaces are based on information published in 7 + * "Inside Macintosh" by Apple Computer, Addison-Wesley, 8 + * Reading (Mass.), 1985-86. 9 + * 10 + */ 11 + 12 + 13 + #ifndef _MemoryMgr_ 14 + #define _MemoryMgr_ 15 + 16 + #ifndef _MacTypes_ 17 + #include "MacTypes.h" 18 + #endif 19 + 20 + /* maximum block size */ 21 + #define maxSize 0x800000 22 + 23 + /* result codes */ 24 + enum { 25 + memLockedErr = -117, 26 + memPurErr = -112, 27 + memWZErr, 28 + nilHandleErr = -109, 29 + memFullErr, 30 + memROZErr = -99 31 + }; 32 + 33 + typedef struct 34 + { 35 + Ptr bkLim; 36 + Ptr purgePtr; 37 + Ptr hFstFree; 38 + long zcbFree; 39 + ProcPtr gzProc; 40 + int moreMast; 41 + int flags; 42 + int cntRel; 43 + int maxRel; 44 + int cntNRel; 45 + int maxNRel; 46 + int cntEmpty; 47 + int cntHandles; 48 + long minCBFree; 49 + ProcPtr purgeProc; 50 + Ptr sparePtr; 51 + Ptr allocPtr; 52 + int heapData; 53 + }Zone, * THz ; 54 + 55 + /* functions returning non-integral values */ 56 + pascal THz GetZone(); 57 + pascal THz SystemZone(); 58 + pascal THz ApplicZone(); 59 + pascal THz HandleZone(); 60 + pascal Handle RecoverHandle(); 61 + pascal THz PtrZone(); 62 + pascal Handle GZSaveHnd(); 63 + pascal Ptr TopMem(); 64 + pascal Ptr GetApplLimit(); 65 + pascal Handle NewEmptyHandle(); 66 + 67 + /* low-memory globals */ 68 + extern Ptr MemTop : 0x108; 69 + extern Ptr BufPtr : 0x10C; 70 + extern Ptr HeapEnd : 0x114; 71 + extern THz TheZone : 0x118; 72 + extern Ptr ApplLimit : 0x130; 73 + extern int MemErr : 0x220; 74 + extern THz SysZone : 0x2A6; 75 + extern THz ApplZone : 0x2AA; 76 + extern Ptr ROMBase : 0x2AE; 77 + extern Ptr RAMBase : 0x2B2; 78 + extern long Lo3Bytes : 0x31A; 79 + extern ProcPtr IAZNotify : 0x33C; 80 + extern Ptr CurrentA5 : 0x904; 81 + extern Ptr CurStackBase : 0x908; 82 + 83 + 84 + #endif
+63
headers/MenuMgr.h
··· 1 + 2 + /* 3 + * MenuMgr.h 4 + * 5 + * Copyright (c) 1986 THINK Technologies, Inc. 6 + * These interfaces are based on information published in 7 + * "Inside Macintosh" by Apple Computer, Addison-Wesley, 8 + * Reading (Mass.), 1985. 9 + * 10 + */ 11 + 12 + #ifndef _MenuMgr_ 13 + #define _MenuMgr_ 14 + 15 + #ifndef _MacTypes_ 16 + #include "MacTypes.h" 17 + #endif 18 + 19 + #define maxItem 31 20 + 21 + /* special chars */ 22 + enum { 23 + noMark, 24 + commandMark = 0x11, 25 + checkMark, 26 + diamondMark, 27 + appleMark 28 + }; 29 + 30 + /* menu defproc messages */ 31 + enum { mDrawMsg, mChooseMsg, mSizeMsg }; 32 + 33 + /* MDEF id */ 34 + #define textMenuProc 0 35 + 36 + typedef struct 37 + { 38 + int menuID; 39 + int menuWidth; 40 + int menuHeight; 41 + Handle menuProc; 42 + long enableFlags; 43 + Str255 menuData; 44 + } MenuInfo,* MenuPtr, ** MenuHandle; 45 + 46 + 47 + /* functions returning non-integral values */ 48 + pascal MenuHandle NewMenu(); 49 + pascal MenuHandle GetMenu(); 50 + pascal Handle GetNewMBar(); 51 + pascal Handle GetMenuBar(); 52 + pascal MenuHandle GetMHandle(); 53 + 54 + /* low-memory globals */ 55 + extern Handle MenuList : 0xA1C; 56 + extern int MBarEnable : 0xA20; 57 + extern int MenuFlash : 0xA24; 58 + extern int TheMenu : 0xA26; 59 + extern ProcPtr MBarHook : 0xA2C; 60 + extern ProcPtr MenuHook : 0xA30; 61 + 62 + 63 + #endif
+103
headers/OSUtil.h
··· 1 + 2 + /* 3 + * OSUtil.h 4 + * 5 + * Copyright (c) 1986 THINK Technologies, Inc. 6 + * These interfaces are based on information published in 7 + * "Inside Macintosh" by Apple Computer, Addison-Wesley, 8 + * Reading (Mass.), 1985-86. 9 + * 10 + */ 11 + 12 + #ifndef _OSUtil_ 13 + #define _OSUtil_ 14 + 15 + #ifndef _MacTypes_ 16 + #include "MacTypes.h" 17 + #endif 18 + 19 + /* result codes */ 20 + enum { 21 + prInitErr = -88, 22 + prWrErr, 23 + clkWrErr, 24 + clkRdErr, 25 + vTypErr = -2, 26 + qErr 27 + }; 28 + 29 + /* queue types */ 30 + enum { 31 + vType = 1, 32 + ioQType, 33 + drvType, 34 + evType, 35 + fsQType 36 + }; 37 + 38 + /* machine types */ 39 + enum { macXLMachine, macMachine }; 40 + 41 + /* trap types */ 42 + enum { OSTrap, ToolTrap }; 43 + 44 + /* serial port use */ 45 + enum { useFree, useATalk, useAsync }; 46 + 47 + typedef struct 48 + { 49 + char valid; 50 + char aTalkA; 51 + char aTalkB; 52 + char config; 53 + int portA; 54 + int portB; 55 + long alarm; 56 + int font; 57 + int kbdPrint; 58 + int volClik; 59 + int misc; 60 + } SysParmType,* SysPPtr ; 61 + 62 + typedef struct QElem 63 + { 64 + struct QElem *qLink; 65 + int qType; 66 + char qData[]; 67 + } QElem, *QElemPtr; 68 + 69 + typedef struct QHdr 70 + { 71 + int qFlags; 72 + QElemPtr qHead; 73 + QElemPtr qTail; 74 + } QHdr,* QHdrPtr ; 75 + 76 + typedef struct 77 + { 78 + int year; 79 + int month; 80 + int day; 81 + int hour; 82 + int minute; 83 + int second; 84 + int dayOfWeek; 85 + } DateTimeRec ; 86 + 87 + 88 + /* access A5 from interrupt level */ 89 + #define SetUpA5() asm { move.l a5,-(sp) \ 90 + move.l 0x904,a5 } 91 + #define RestoreA5() asm { move.l (sp)+,a5 } 92 + 93 + 94 + /* functions returning non-integral values */ 95 + pascal SysPPtr GetSysPPtr(); 96 + 97 + /* low-memory globals */ 98 + extern int SysVersion : 0x15A; 99 + extern SysParmType SysParam : 0x1F8; 100 + extern long Time : 0x20C; 101 + 102 + 103 + #endif
+36
headers/PackageMgr.h
··· 1 + 2 + /* 3 + * PackageMgr.h 4 + * 5 + * Copyright (c) 1986 THINK Technologies, Inc. 6 + * These interfaces are based on information published in 7 + * "Inside Macintosh" by Apple Computer, Addison-Wesley, 8 + * Reading (Mass.), 1985-86. 9 + * 10 + */ 11 + 12 + #ifndef _PackageMgr_ 13 + #define _PackageMgr_ 14 + 15 + #ifndef _MacTypes_ 16 + #include "MacTypes.h" 17 + #endif 18 + 19 + /* package IDs */ 20 + enum { 21 + listMgr, 22 + dskInit = 2, 23 + stdFile, 24 + flPoint, 25 + trFunc, 26 + intUtil, 27 + bdConv 28 + }; 29 + 30 + /* low-memory globals */ 31 + extern Handle AppPacks[] : 0xAB8; 32 + 33 + 34 + #endif 35 + 36 +
+182
headers/PrintMgr.h
··· 1 + 2 + /* 3 + * PrintMgr.h 4 + * 5 + * Copyright (c) 1986 THINK Technologies, Inc. 6 + * These interfaces are based on information published in 7 + * "Inside Macintosh" by Apple Computer, Addison-Wesley, 8 + * Reading (Mass.), 1985; and on the Public Toolbox Interface 9 + * Source Code, copyright (c) 1985 Apple Computer, licensed 10 + * to THINK Technologies by Apple Computer. 11 + * 12 + */ 13 + 14 + #ifndef _PrintMgr_ 15 + #define _PrintMgr_ 16 + 17 + #ifndef _DialogMgr_ 18 + #include "DialogMgr.h" 19 + #endif 20 + 21 + 22 + /* printing methods */ 23 + enum { bDraftLoop, bSpoolLoop, bUser1Loop, bUser2Loop }; 24 + 25 + /* printers */ 26 + enum { bDevCItoh = 1, bDevDaisy, bDevLaser }; 27 + #define iDevCItoh 0x0100 28 + #define iDevDaisy 0x0200 29 + #define iDevLaser 0x0300 30 + 31 + /* PrCtlCall parameters */ 32 + #define iPrBitsCtl 4 33 + #define lScreenBits 0x00000000 34 + #define lPaintBits 0x00000001 35 + #define lHiScreenBits 0x00000010 36 + #define lHiPaintBits 0x00000011 37 + #define iPrIOCtl 5 38 + #define iPrEvtCtl 6 39 + #define lPrEvtAll 0x0002FFFD 40 + #define lPrEvtTop 0x0001FFFD 41 + #define iPrDevCtl 7 42 + #define lPrReset 0x00010000 43 + #define lPrPageEnd 0x00020000 44 + #define lPrLineFeed 0x00030000 45 + #define lPrLFSixth 0x0003FFFF 46 + #define lPrLFEighth 0x0003FFFE 47 + #define iFMgrCtl 8 48 + 49 + /* result codes */ 50 + #define iPrSavPFil (-1) 51 + #define iIOAbort (-27) 52 + #define iMemFullErr (-108) 53 + #define iPrAbort 128 54 + 55 + /* other constants */ 56 + #define sPrDrvr "\p.Print" 57 + #define iPrDrvrRef (-3) 58 + #define iPrPgFract 120 59 + #define iPrPgFst 1 60 + #define iPrPgMax 9999 61 + #define iPrRelease 3 62 + #define iPfMaxPgs 128 63 + 64 + 65 + typedef struct TPrPort { 66 + GrafPort gPort; 67 + QDProcs gProcs; 68 + long lGParam1; 69 + long lGParam2; 70 + long lGParam3; 71 + long lGParam4; 72 + Boolean fOurPtr; 73 + Boolean fOurBits; 74 + } TPrPort, *TPPrPort; 75 + 76 + typedef struct TPrInfo { 77 + int iDev; 78 + int iVRes; 79 + int iHRes; 80 + Rect rPage; 81 + } TPrInfo, *TPPrInfo; 82 + 83 + typedef struct TPrJob { 84 + int iFstPage; 85 + int iLstPage; 86 + int iCopies; 87 + SignedByte bJDocLoop; 88 + Boolean fFromUsr; 89 + ProcPtr pIdleProc; 90 + StringPtr pFileName; 91 + int iFileVol; 92 + SignedByte bFileVers; 93 + SignedByte bJobX; 94 + } TPrJob, *TPPrJob; 95 + 96 + typedef enum { feedCut, feedFanfold, feedMechCut, feedOther} TFeed; 97 + 98 + typedef struct TPrStl { 99 + int wDev; 100 + int iPageV; 101 + int iPageH; 102 + SignedByte bPort; 103 + TFeed feed; 104 + } TPrStl, *TPPrStl; 105 + 106 + typedef enum { scanTB, scanBT, scanLR, scanRL} TScan; 107 + 108 + typedef struct TPrXInfo { 109 + int iRowBytes; 110 + int iBandV; 111 + int iBandH; 112 + int iDevBytes; 113 + int iBands; 114 + SignedByte bPatScale; 115 + SignedByte bULThick; 116 + SignedByte bULOffset; 117 + SignedByte bULShadow; 118 + TScan scan; 119 + SignedByte bXInfoX; 120 + } TPrXInfo, *TPPrXInfo; 121 + 122 + typedef Rect *TPRect; 123 + 124 + typedef struct TPrint { 125 + int iPrVersion; 126 + TPrInfo prInfo; 127 + Rect rPaper; 128 + TPrStl prStl; 129 + TPrInfo prInfoPT; 130 + TPrXInfo prXInfo; 131 + TPrJob prJob; 132 + int printX[19]; 133 + } TPrint, *TPPrint, **THPrint; 134 + 135 + typedef struct TPrStatus { 136 + int iTotPages; 137 + int iCurPage; 138 + int iTotCopies; 139 + int iCurCopy; 140 + int iTotBands; 141 + int iCurBand; 142 + Boolean fPgDirty; 143 + Boolean fImaging; 144 + THPrint hPrint; 145 + TPPrPort pPrPort; 146 + PicHandle hPic; 147 + } TPrStatus, *TPPrStatus; 148 + 149 + typedef struct TPfPgDir { 150 + int iPages; 151 + long lPgPos[iPfMaxPgs+1]; 152 + } TPfPgDir, *TPPfPgDir, **THPfPgDir; 153 + 154 + typedef struct TPfHeader { 155 + TPrint print; 156 + TPfPgDir pfPgDir; 157 + } TPfHeader, *TPPfHeader, **THPfHeader; 158 + 159 + typedef struct TPrDlg { 160 + DialogRecord dlg; 161 + ProcPtr pFltrProc; 162 + ProcPtr pItemProc; 163 + THPrint hPrintUsr; 164 + Boolean fDoIt; 165 + Boolean fDone; 166 + long lUser1; 167 + long lUser2; 168 + long lUser3; 169 + long lUser4; 170 + /* plus more stuff needed by the particular printing dialog */ 171 + } TPrDlg, *TPPrDlg; 172 + 173 + 174 + /* functions returning non-integral values */ 175 + pascal TPPrPort PrOpenDoc(); 176 + pascal Handle PrDrvrDCE(); 177 + 178 + /* low-memory globals */ 179 + extern int PrintErr : 0x944; 180 + 181 + 182 + #endif _PrintMgr_
+206
headers/Quickdraw.h
··· 1 + 2 + /* 3 + * Quickdraw.h 4 + * 5 + * Copyright (c) 1986 THINK Technologies, Inc. 6 + * These interfaces are based on information published in 7 + * "Inside Macintosh" by Apple Computer, Addison-Wesley, 8 + * Reading (Mass.), 1985. 9 + * 10 + */ 11 + 12 + #ifndef _Quickdraw_ 13 + #define _Quickdraw_ 14 + 15 + #ifndef _MacTypes_ 16 + #include "MacTypes.h" 17 + #endif 18 + 19 + 20 + /* transfer modes */ 21 + enum { 22 + srcCopy, 23 + srcOr, 24 + srcXor, 25 + srcBic, 26 + notSrcCopy, 27 + notSrcOr, 28 + notSrcXor, 29 + notSrcBic, 30 + patCopy, 31 + patOr, 32 + patXor, 33 + patBic, 34 + notPatCopy, 35 + notPatOr, 36 + notPatXor, 37 + notPatBic 38 + }; 39 + 40 + /* colors */ 41 + #define blackColor 33 42 + #define whiteColor 30 43 + #define redColor 205 44 + #define greenColor 341 45 + #define blueColor 409 46 + #define cyanColor 273 47 + #define magentaColor 137 48 + #define yellowColor 69 49 + 50 + /* standard picture comments */ 51 + enum { picLParen, picRParen }; 52 + 53 + /* color mapping */ 54 + enum { 55 + normalBit, 56 + inverseBit, 57 + blueBit, 58 + greenBit, 59 + redBit, 60 + blackBit, 61 + yellowBit, 62 + magentaBit, 63 + cyanBit 64 + }; 65 + 66 + typedef char QDByte, *QDPtr, **QDHandle; 67 + 68 + typedef enum { 69 + bold = 1, 70 + italic = 2, 71 + underline = 4, 72 + outline = 8, 73 + shadow = 16, 74 + condense = 32, 75 + extend = 64 76 + } Style; 77 + 78 + typedef enum { frame, paint, erase, invert, fill } GrafVerb; 79 + 80 + typedef unsigned char Pattern[8]; 81 + typedef Pattern *PatPtr, **PatHandle; 82 + 83 + typedef int Bits16[16]; 84 + 85 + typedef struct 86 + { 87 + int ascent; 88 + int descent; 89 + int widMax; 90 + int leading; 91 + } FontInfo; 92 + 93 + typedef struct 94 + { 95 + QDPtr baseAddr; 96 + int rowBytes; 97 + Rect bounds; 98 + } BitMap; 99 + 100 + typedef struct 101 + { 102 + Bits16 data; 103 + Bits16 mask; 104 + Point hotSpot; 105 + } Cursor, *CursPtr, **CursHandle; 106 + 107 + typedef struct 108 + { 109 + Point pnLoc; 110 + Point pnSize; 111 + int pnMode; 112 + Pattern pnPat; 113 + } PenState; 114 + 115 + typedef struct 116 + { 117 + int polySize; 118 + Rect polyBBox; 119 + Point polyPoints[]; 120 + } Polygon, *PolyPtr, **PolyHandle; 121 + 122 + typedef struct 123 + { 124 + int rgnSize; 125 + Rect rgnBBox; 126 + } Region,* RgnPtr,** RgnHandle; 127 + 128 + 129 + typedef struct 130 + { 131 + int picSize; 132 + Rect picFrame; 133 + } Picture, *PicPtr, **PicHandle; 134 + 135 + typedef struct 136 + { 137 + QDPtr textProc; 138 + QDPtr lineProc; 139 + QDPtr rectProc; 140 + QDPtr rRectProc; 141 + QDPtr ovalProc; 142 + QDPtr arcProc; 143 + QDPtr polyProc; 144 + QDPtr rgnProc; 145 + QDPtr bitsProc; 146 + QDPtr commentProc; 147 + QDPtr txMeasProc; 148 + QDPtr getPicProc; 149 + QDPtr putPicProc; 150 + } QDProcs,* QDProcsPtr; 151 + 152 + typedef struct GrafPort 153 + { 154 + int device; 155 + BitMap portBits; 156 + Rect portRect; 157 + RgnHandle visRgn; 158 + RgnHandle clipRgn; 159 + Pattern bkPat; 160 + Pattern fillPat; 161 + Point pnLoc; 162 + Point pnSize; 163 + int pnMode; 164 + Pattern pnPat; 165 + int pnVis; 166 + int txFont; 167 + Style txFace; 168 + int txMode; 169 + int txSize; 170 + long spExtra; 171 + long fgColor; 172 + long bkColor; 173 + int colrBit; 174 + int patStretch; 175 + QDHandle picSave; 176 + QDHandle rgnSave; 177 + QDHandle polySave; 178 + QDProcsPtr grafProcs; 179 + } GrafPort, * GrafPtr; 180 + 181 + /* Quickdraw global variables - defined in the MacTraps library */ 182 + extern GrafPtr thePort; 183 + extern Pattern white; 184 + extern Pattern black; 185 + extern Pattern gray; 186 + extern Pattern ltGray; 187 + extern Pattern dkGray; 188 + extern Cursor arrow; 189 + extern BitMap screenBits; 190 + extern long randSeed; 191 + 192 + /* functions returning non-integral values */ 193 + pascal RgnHandle NewRgn(); 194 + pascal PicHandle OpenPicture(); 195 + pascal PolyHandle OpenPoly(); 196 + 197 + /* low-memory globals */ 198 + extern int ScrVRes : 0x102; 199 + extern int ScrHRes : 0x104; 200 + extern int ScreenRow : 0x106; 201 + extern long RndSeed : 0x156; 202 + extern Ptr ScrnBase : 0x824; 203 + extern Rect CrsrPin : 0x834; 204 + 205 + 206 + #endif
+66
headers/ResourceMgr.h
··· 1 + 2 + /* 3 + * ResourceMgr.h 4 + * 5 + * Copyright (c) 1986 THINK Technologies, Inc. 6 + * These interfaces are based on information published in 7 + * "Inside Macintosh" by Apple Computer, Addison-Wesley, 8 + * Reading (Mass.), 1985-86. 9 + * 10 + */ 11 + 12 + #ifndef _ResourceMgr_ 13 + #define _ResourceMgr_ 14 + 15 + #ifndef _MacTypes_ 16 + #include "MacTypes.h" 17 + #endif 18 + 19 + /* resource attributes */ 20 + #define resSysRef 128 21 + #define resSysHeap 64 22 + #define resPurgeable 32 23 + #define resLocked 16 24 + #define resProtected 8 25 + #define resPreload 4 26 + #define resChanged 2 27 + 28 + /* result codes */ 29 + enum { 30 + mapReadErr = -199, 31 + resAttrErr, 32 + rmvRefFailed, 33 + rmvResFailed, 34 + addRefFailed, 35 + addResFailed, 36 + resFNotFound, 37 + resNotFound 38 + }; 39 + 40 + /* file attributes */ 41 + #define mapReadOnly 128 42 + #define mapCompact 64 43 + #define mapChanged 32 44 + 45 + /* RomMapInsert values */ 46 + #define mapTrue 0xFFFF 47 + #define mapFalse 0xFF00 48 + 49 + /* functions returning non-integral values */ 50 + pascal Handle Get1Resource(); 51 + pascal Handle Get1IndResource(); 52 + pascal Handle Get1NamedResource(); 53 + 54 + /* low-memory globals */ 55 + extern Handle TopMapHndl : 0xA50; 56 + extern Handle SysMapHndl : 0xA54; 57 + extern int SysMap : 0xA58; 58 + extern int CurMap : 0xA5A; 59 + extern Boolean ResLoad : 0xA5E; 60 + extern int ResErr : 0xA60; 61 + extern ProcPtr ResErrProc : 0xAF2; 62 + extern char SysResName[] : 0xAD8; 63 + extern int RomMapInsert : 0xB9E; 64 + 65 + 66 + #endif
+44
headers/SCSIMgr.h
··· 1 + 2 + /* 3 + * SCSIMgr.h 4 + * 5 + * Copyright (c) 1986 THINK Technologies, Inc. 6 + * These interfaces are based on information published in 7 + * "Inside Macintosh" by Apple Computer, Addison-Wesley, 8 + * Reading (Mass.), 1986. 9 + * 10 + */ 11 + 12 + #ifndef _SCSIMgr_ 13 + #define _SCSIMgr_ 14 + 15 + 16 + /* transfer instruction op codes */ 17 + enum { 18 + scInc = 1, 19 + scNoInc, 20 + scAdd, 21 + scMove, 22 + scLoop, 23 + scNop, 24 + scStop, 25 + scComp 26 + }; 27 + 28 + /* result codes */ 29 + enum { 30 + scCommErr = 2, 31 + scBadParmsErr = 4, 32 + scPhaseErr, 33 + scCompareErr 34 + }; 35 + 36 + 37 + typedef struct SCSIInstr { 38 + int scOpcode; 39 + long scParam1; 40 + long scParam2; 41 + } SCSIInstr; 42 + 43 + 44 + #endif
+40
headers/ScrapMgr.h
··· 1 + 2 + /* 3 + * ScrapMgr.h 4 + * 5 + * Copyright (c) 1986 THINK Technologies, Inc. 6 + * These interfaces are based on information published in 7 + * "Inside Macintosh" by Apple Computer, Addison-Wesley, 8 + * Reading (Mass.), 1985. 9 + * 10 + */ 11 + 12 + #ifndef _ScrapMgr_ 13 + #define _ScrapMgr_ 14 + 15 + #ifndef _MacTypes_ 16 + #include "MacTypes.h" 17 + #endif 18 + 19 + /* result codes */ 20 + enum { noTypeErr = -102, noScrapErr = -100 }; 21 + 22 + 23 + typedef struct ScrapStuff 24 + { 25 + long scrapSize; 26 + Handle scrapHandle; 27 + int scrapCount; 28 + int scrapState; 29 + StringPtr scrapName; 30 + } ScrapStuff,* PScrapStuff; 31 + 32 + 33 + /* functions returning non-integral values */ 34 + pascal PScrapStuff InfoScrap(); 35 + 36 + /* low-memory globals */ 37 + extern ScrapStuff ScrapInfo : 0x960; 38 + 39 + 40 + #endif
+38
headers/SegmentLdr.h
··· 1 + 2 + /* 3 + * SegmentLdr.h 4 + * 5 + * Copyright (c) 1986 THINK Technologies, Inc. 6 + * These interfaces are based on information published in 7 + * "Inside Macintosh" by Apple Computer, Addison-Wesley, 8 + * Reading (Mass.), 1985. 9 + * 10 + */ 11 + 12 + #ifndef _SegmentLdr_ 13 + #define _SegmentLdr_ 14 + 15 + #ifndef _MacTypes_ 16 + #include "MacTypes.h" 17 + #endif 18 + 19 + enum { appOpen, appPrint }; 20 + 21 + typedef struct 22 + { 23 + int vRefNum; 24 + OSType fType; 25 + int versNum; 26 + Str255 fName; 27 + } AppFile ; 28 + 29 + /* low-memory globals */ 30 + extern char FinderName[] : 0x2E0; 31 + extern int CurApRefNum : 0x900; 32 + extern char CurApName[] : 0x910; 33 + extern int CurJTOffset : 0x934; 34 + extern int CurPageOption : 0x936; 35 + extern Handle AppParmHandle : 0xAEC; 36 + 37 + 38 + #endif
+86
headers/SerialDvr.h
··· 1 + 2 + /* 3 + * SerialDvr.h 4 + * 5 + * Copyright (c) 1986 THINK Technologies, Inc. 6 + * These interfaces are based on information published in 7 + * "Inside Macintosh" by Apple Computer, Addison-Wesley, 8 + * Reading (Mass.), 1985-86. 9 + * 10 + */ 11 + 12 + #ifndef _SerialDvr_ 13 + #define _SerialDvr_ 14 + 15 + /* baud rate constants */ 16 + #define baud300 380 17 + #define baud600 189 18 + #define baud1200 94 19 + #define baud1800 62 20 + #define baud2400 46 21 + #define baud3600 30 22 + #define baud4800 22 23 + #define baud7200 14 24 + #define baud9600 10 25 + #define baud19200 4 26 + #define baud57600 0 27 + 28 + /* SCC channel config word */ 29 + #define stop10 16384 30 + #define stop15 ((int) -32768) 31 + #define stop20 (-16384) 32 + #define noParity 8192 33 + #define oddParity 4096 34 + #define evenParity 12288 35 + #define data5 0 36 + #define data6 2048 37 + #define data7 1024 38 + #define data8 3072 39 + 40 + /* serial driver error masks */ 41 + #define swOverrunErr 1 42 + #define parityErr 16 43 + #define hwOverrunErr 32 44 + #define framingErr 64 45 + 46 + #define xOffWasSent 0x80 47 + 48 + #define dtrNegated 0x40 49 + 50 + #define ctsEvent 32 51 + #define breakEvent 128 52 + 53 + typedef enum { sPortA, sPortB } SPortSel; 54 + 55 + /* refNums for the serial ports */ 56 + #define AinRefNum -6 57 + #define AoutRefNum -7 58 + #define BinRefNum -8 59 + #define BoutRefNum -9 60 + 61 + 62 + typedef struct 63 + { 64 + char fXOn; 65 + char fCTS; 66 + char xOn; 67 + char xOff; 68 + char errs; 69 + char evts; 70 + char fInX; 71 + char fDTR; 72 + } SerShk; 73 + 74 + 75 + typedef struct 76 + { 77 + char cumErrs; 78 + char xOffSent; 79 + char rdPend; 80 + char wrPend; 81 + char ctsHold; 82 + char xOffHold; 83 + } SerStaRec ; 84 + 85 + 86 + #endif
+74
headers/SoundDvr.h
··· 1 + 2 + /* 3 + * SoundDvr.h 4 + * 5 + * Copyright (c) 1986 THINK Technologies, Inc. 6 + * These interfaces are based on information published in 7 + * "Inside Macintosh" by Apple Computer, Addison-Wesley, 8 + * Reading (Mass.), 1985. 9 + * 10 + */ 11 + 12 + #ifndef _SoundDvr_ 13 + #define _SoundDvr_ 14 + 15 + /* synthesizer modes */ 16 + enum { swMode = -1, ffMode, ftMode }; 17 + 18 + typedef char FreeWave[1] ; /* array[0..30000] of byte; */ 19 + 20 + typedef struct FFSynthRec 21 + { 22 + int mode; 23 + long count; 24 + FreeWave waveBytes; 25 + } FFSynthRec, *FFSynthPtr ; 26 + 27 + 28 + typedef struct 29 + { 30 + int count; 31 + int amplitude; 32 + int duration; 33 + } Tone ; 34 + 35 + typedef Tone Tones[1]; /* array[0..5000] of Tone */ 36 + 37 + typedef struct 38 + { 39 + int mode; 40 + Tones triplets; 41 + } SWSynthRec, *SWSynthPtr ; 42 + 43 + typedef char Wave[256]; 44 + typedef Wave * WavePtr; 45 + 46 + typedef struct 47 + { 48 + int duration; 49 + long sound1Rate; 50 + long sound1Phase; 51 + long sound2Rate; 52 + long sound2Phase; 53 + long sound3Rate; 54 + long sound3Phase; 55 + long sound4Rate; 56 + long sound4Phase; 57 + WavePtr sound1Wave; 58 + WavePtr sound2Wave; 59 + WavePtr sound3Wave; 60 + WavePtr sound4Wave; 61 + } FTSoundRec, *FTSndRecPtr ; 62 + 63 + typedef struct 64 + { 65 + int mode; 66 + FTSndRecPtr sndRec; 67 + } FTSynthRec, * FTSynthPtr; 68 + 69 + 70 + /* low-memory globals */ 71 + extern char SdVolume : 0x260; 72 + 73 + 74 + #endif
+55
headers/StdFilePkg.h
··· 1 + 2 + /* 3 + * StdFilePkg.h 4 + * 5 + * Copyright (c) 1986 THINK Technologies, Inc. 6 + * These interfaces are based on information published in 7 + * "Inside Macintosh" by Apple Computer, Addison-Wesley, 8 + * Reading (Mass.), 1985-86. 9 + * 10 + */ 11 + 12 + #ifndef _StdFilePkg_ 13 + #define _StdFilePkg_ 14 + 15 + #define putDlgID -3999 16 + 17 + enum { 18 + putSave = 1, 19 + putCancel, 20 + putEject = 5, 21 + putDrive, 22 + putName 23 + }; 24 + 25 + #define getDlgID -4000 26 + 27 + enum { 28 + getOpen = 1, 29 + getCancel = 3, 30 + getEject = 5, 31 + getDrive, 32 + getNmList, 33 + getScroll 34 + }; 35 + 36 + 37 + typedef struct SFReply 38 + { 39 + char good; 40 + char copy; 41 + long fType; /* array[1..4] of char; */ 42 + int vRefNum; 43 + int version; 44 + unsigned char fName[64]; 45 + }SFReply; 46 + 47 + typedef long SFTypeList[4]; /* array[0..3] of OSType; */ 48 + 49 + 50 + /* low-memory globals */ 51 + extern int SFSaveDisk : 0x214; 52 + extern long CurDirStore : 0x398; 53 + 54 + 55 + #endif
+70
headers/TextEdit.h
··· 1 + 2 + /* 3 + * TextEdit.h 4 + * 5 + * Copyright (c) 1986 THINK Technologies, Inc. 6 + * These interfaces are based on information published in 7 + * "Inside Macintosh" by Apple Computer, Addison-Wesley, 8 + * Reading (Mass.), 1985. 9 + * 10 + */ 11 + 12 + #ifndef _TextEdit_ 13 + #define _TextEdit_ 14 + 15 + #ifndef _Quickdraw_ 16 + #include "Quickdraw.h" 17 + #endif 18 + 19 + /* justifications */ 20 + enum { teJustRight = -1, teJustLeft, teJustCenter }; 21 + 22 + typedef char Chars[1], *CharsPtr, **CharsHandle; 23 + 24 + typedef struct 25 + { 26 + Rect destRect ; 27 + Rect viewRect ; 28 + Rect selRect ; 29 + int lineHeight ; 30 + int fontAscent ; 31 + Point selPoint ; 32 + int selStart ; 33 + int selEnd ; 34 + int active ; 35 + ProcPtr wordBreak ; 36 + ProcPtr clikLoop ; 37 + long clickTime ; 38 + int clickLoc ; 39 + long caretTime ; 40 + int caretState ; 41 + int just ; 42 + int teLength ; 43 + Handle hText ; 44 + int recalBack ; 45 + int recalLines; 46 + int clikStuff ; 47 + int crOnly ; 48 + int txFont ; 49 + char txFace ; 50 + int txMode ; 51 + int txSize ; 52 + GrafPtr inPort ; 53 + ProcPtr highHook ; 54 + ProcPtr caretHook ; 55 + int nLines ; 56 + int lineStarts[]; 57 + } TERec, *TEPtr, **TEHandle ; 58 + 59 + 60 + /* functions returning non-integral values */ 61 + pascal TEHandle TENew(); 62 + pascal CharsHandle TEGetText(); 63 + pascal Handle TEScrapHandle(); 64 + 65 + /* low-memory globals */ 66 + extern int TEScrpLength : 0xAB0; 67 + extern Handle TEScrpHandle : 0xAB4; 68 + 69 + 70 + #endif
+28
headers/TimeMgr.h
··· 1 + 2 + /* 3 + * TimeMgr.h 4 + * 5 + * Copyright (c) 1986 THINK Technologies, Inc. 6 + * These interfaces are based on information published in 7 + * "Inside Macintosh" by Apple Computer, Addison-Wesley, 8 + * Reading (Mass.), 1986. 9 + * 10 + */ 11 + 12 + #ifndef _TimeMgr_ 13 + #define _TimeMgr_ 14 + 15 + #ifndef _MacTypes_ 16 + #include "MacTypes.h" 17 + #endif 18 + 19 + 20 + typedef struct TMTask { 21 + struct QElem *qLink; 22 + int qType; 23 + ProcPtr tmAddr; 24 + int tmCount; 25 + } TMTask; 26 + 27 + 28 + #endif
+46
headers/ToolboxUtil.h
··· 1 + 2 + /* 3 + * ToolboxUtil.h 4 + * 5 + * Copyright (c) 1986 THINK Technologies, Inc. 6 + * These interfaces are based on information published in 7 + * "Inside Macintosh" by Apple Computer, Addison-Wesley, 8 + * Reading (Mass.), 1985-86. 9 + * 10 + */ 11 + 12 + #ifndef _ToolboxUtil_ 13 + #define _ToolboxUtil_ 14 + 15 + #ifndef _Quickdraw_ 16 + #include "Quickdraw.h" 17 + #endif 18 + 19 + #define sysPatListID 0 20 + 21 + enum { 22 + iBeamCursor = 1, 23 + crossCursor, 24 + plusCursor, 25 + watchCursor 26 + }; 27 + 28 + typedef struct 29 + { 30 + long hiLong; 31 + long loLong; 32 + } Int64Bit ; 33 + 34 + 35 + /* functions returning non-integral values */ 36 + pascal StringHandle NewString(); 37 + pascal StringHandle GetString(); 38 + pascal Handle GetIcon(); 39 + pascal PatHandle GetPattern(); 40 + pascal CursHandle GetCursor(); 41 + pascal PicHandle GetPicture(); 42 + double Fix2X(Fixed); 43 + double Frac2X(Fract); 44 + 45 + 46 + #endif
+38
headers/VRetraceMgr.h
··· 1 + 2 + /* 3 + * VRetraceMgr.h 4 + * 5 + * Copyright (c) 1986 THINK Technologies, Inc. 6 + * These interfaces are based on information published in 7 + * "Inside Macintosh" by Apple Computer, Addison-Wesley, 8 + * Reading (Mass.), 1985. 9 + * 10 + */ 11 + 12 + #ifndef _VRetraceMgr_ 13 + #define _VRetraceMgr_ 14 + 15 + #ifndef _MacTypes_ 16 + #include "MacTypes.h" 17 + #endif 18 + 19 + typedef struct VBLTask 20 + { 21 + struct QElem * qLink; 22 + int qType; 23 + ProcPtr vblAddr; 24 + int vblCount; 25 + int vblPhase; 26 + } VBLTask , *VBLQElPtr; 27 + 28 + #define inVBL 0x40 29 + 30 + 31 + /* functions returning non-integral values */ 32 + pascal struct QHdr *GetVBLQHdr(); 33 + 34 + /* low-memory globals */ 35 + extern struct QHdr VBLQueue : 0x160; 36 + 37 + 38 + #endif
+125
headers/WindowMgr.h
··· 1 + 2 + /* 3 + * WindowMgr.h 4 + * 5 + * Copyright (c) 1986 THINK Technologies, Inc. 6 + * These interfaces are based on information published in 7 + * "Inside Macintosh" by Apple Computer, Addison-Wesley, 8 + * Reading (Mass.), 1985-86. 9 + * 10 + */ 11 + 12 + #ifndef _WindowMgr_ 13 + #define _WindowMgr_ 14 + 15 + #ifndef _Quickdraw_ 16 + #include "Quickdraw.h" 17 + #endif 18 + 19 + /* window def proc ID's */ 20 + enum { 21 + documentProc, 22 + dBoxProc, 23 + plainDBox, 24 + altDBoxProc, 25 + noGrowDocProc, 26 + rDocProc = 16 27 + }; 28 + 29 + /* types of windows */ 30 + #define dialogKind 2 31 + #define userKind 8 32 + 33 + /* FindWindow values */ 34 + enum { 35 + inDesk, 36 + inMenuBar, 37 + inSysWindow, 38 + inContent, 39 + inDrag, 40 + inGrow, 41 + inGoAway, 42 + inZoomIn, 43 + inZoomOut 44 + }; 45 + 46 + /* Axis constraints for DragGrayRgn */ 47 + enum { noConstraint, hAxisOnly, vAxisOnly }; 48 + 49 + /* window defproc messages */ 50 + enum { 51 + wDraw, 52 + wHit, 53 + wCalcRgns, 54 + wNew, 55 + wDispose, 56 + wGrow, 57 + wDrawGIcon 58 + }; 59 + 60 + /* hit test codes */ 61 + enum { 62 + wNoHit, 63 + wInContent, 64 + wInDrag, 65 + wInGrow, 66 + wInGoAway, 67 + wInZoomIn, 68 + wInZoomOut 69 + }; 70 + 71 + /* rsrc ID of desktop pattern */ 72 + #define deskPatID 16 73 + 74 + 75 + typedef struct WindowRecord 76 + { 77 + GrafPort port; 78 + int windowKind; 79 + char visible; 80 + char hilited; 81 + char goAwayFlag; 82 + char spareFlag; 83 + RgnHandle strucRgn; 84 + RgnHandle contRgn; 85 + RgnHandle updateRgn; 86 + Handle windowDefProc; 87 + Handle dataHandle; 88 + StringHandle titleHandle; 89 + int titleWidth; 90 + struct ControlRecord ** controlList; 91 + struct WindowRecord * nextWindow; 92 + PicHandle windowPic; 93 + long refCon; 94 + } WindowRecord, *WindowPeek ; 95 + 96 + typedef GrafPtr WindowPtr; 97 + 98 + typedef struct WStateData { 99 + Rect userState; 100 + Rect stdState; 101 + } WStateData; 102 + 103 + 104 + /* functions returning non-integral values */ 105 + pascal WindowPtr NewWindow(); 106 + pascal WindowPtr GetNewWindow(); 107 + pascal WindowPtr FrontWindow(); 108 + pascal PicHandle GetWindowPic(); 109 + 110 + /* low-memory globals */ 111 + extern WindowPeek WindowList : 0x9D6; 112 + extern int SaveUpdate : 0x9DA; 113 + extern int PaintWhite : 0x9DC; 114 + extern GrafPtr WMgrPort : 0x9DE; 115 + extern RgnHandle GrayRgn : 0x9EE; 116 + extern ProcPtr DragHook : 0x9F6; 117 + extern Pattern DragPattern : 0xA34; 118 + extern Pattern DeskPattern : 0xA3C; 119 + extern WindowPtr CurActivate : 0xA64; 120 + extern WindowPtr CurDeactive : 0xA68; 121 + extern ProcPtr DeskHook : 0xA6C; 122 + extern WindowPtr GhostWindow : 0xA84; 123 + 124 + 125 + #endif
+29
headers/asm.h
··· 1 + 2 + 3 + /* ----- asm.h: definitions useful with inline assembly ----- */ 4 + 5 + 6 + /* trap modifier flags, e.g. "NewHandle SYS+CLEAR" */ 7 + 8 + enum { 9 + /* Memory Manager traps */ 10 + SYS = 2, /* applies to system heap */ 11 + CLEAR = 1, /* zero allocated block */ 12 + /* File Manager and Device Manager traps */ 13 + ASYNC = 2, /* asynchronous I/O */ 14 + HFS = 1, /* HFS version of trap (File Manager) */ 15 + IMMED = 1, /* bypass driver queue (Device Manager) */ 16 + /* string operations */ 17 + MARKS = 1, /* ignore diacritical marks */ 18 + CASE = 2, /* don't ignore case */ 19 + /* GetTrapAddress, SetTrapAddress */ 20 + NEWOS = 1, /* new trap numbering, OS trap */ 21 + NEWTOOL = 3, /* new trap numbering, Toolbox trap */ 22 + /* Toolbox traps */ 23 + AUTOPOP = 2 /* return directly to caller's caller */ 24 + }; 25 + 26 + 27 + /* field offsets, e.g. "move.w d0,OFFSET(Rect,bottom)(a2)" */ 28 + 29 + #define OFFSET(type, field) ((int) &((type *) 0)->field)
+8
headers/pascal.h
··· 1 + 2 + pascal void CallPascal(); 3 + pascal char CallPascalB(); 4 + pascal int CallPascalW(); 5 + pascal long CallPascalL(); 6 + 7 + char *CtoPstr(); 8 + char *PtoCstr();
+153
sources/credits.c
··· 1 + #include "MacTypes.h" 2 + #include "WindowMgr.h" 3 + #include "FontMgr.h" 4 + 5 + #define size 20 6 + #define yoffset 10 7 + #define xoffset 10 8 + #define toupper(c) ((c>='a'&&c<='z')?(c-'a'+'A'):c) 9 + 10 + void Initalize(void); 11 + void Put_Up_Boxes(void); 12 + void Put_Up_Box(int x, int y); 13 + void Put_Up_Characters(char c); 14 + void Put_Up_Character(int x, int y, char c); 15 + main(void); 16 + 17 + char phrase[] = "Libraries by:@\ 18 + @ Robert Alpert\ 19 + @ Steve Adams\ 20 + @ Paul Garmon\ 21 + @\ 22 + @Tested By:@\ 23 + @ Clement Wang\ 24 + @ Rick Tompkins\ 25 + @\ 26 + @Special Thanks to:@\ 27 + @ Steve Stein\ 28 + @ Fleet Hill"; 29 + 30 + int line,row; 31 + 32 + main() 33 + { 34 + int i,j, k; 35 + int line,row = 1; 36 + 37 + Initalize(); 38 + 39 + for (i='a'; i<='z'; i++) 40 + { 41 + Put_Up_Characters(toupper(i)); 42 + 43 + for (k=40000; k; k--); 44 + } 45 + Put_Up_Characters(':'); 46 + 47 + MoveTo(165, 335); 48 + TextFont(systemFont); 49 + TextSize(12); 50 + DrawString("\pClick the mouse to exit"); 51 + while (!Button()); 52 + while (Button()); 53 + } 54 + 55 + 56 + void Initalize() 57 + { 58 + static GrafPort port; 59 + 60 + InitGraf(&thePort); 61 + InitFonts(); 62 + InitWindows(); 63 + InitDialogs(0L); 64 + TEInit(); 65 + 66 + OpenPort(&port); 67 + 68 + TextFont(monaco); 69 + TextSize(9); 70 + TextFace(0); 71 + TextMode(srcOr); 72 + 73 + HideCursor(); 74 + EraseRect(&port.portRect); 75 + 76 + Put_Up_Boxes(); 77 + 78 + } 79 + 80 + 81 + void Put_Up_Boxes() 82 + { 83 + int i; 84 + 85 + line = row = 1; 86 + for (i=0; phrase[i] != '\0'; i++) 87 + { 88 + switch(phrase[i]) 89 + { 90 + case ' ': row++; 91 + break; 92 + 93 + case '@': row = 1; 94 + line++; 95 + break; 96 + 97 + case '-': Put_Up_Box(row,line); 98 + Put_Up_Character(row++,line,'-'); 99 + break; 100 + 101 + default: Put_Up_Box(row++,line); 102 + break; 103 + } 104 + } 105 + } 106 + 107 + void Put_Up_Box(x,y) 108 + int x,y; 109 + { 110 + Rect rect; 111 + 112 + SetRect(&rect, x*size+x+xoffset,y*size+yoffset+1-size,x*size+x+xoffset+size,y*size+yoffset); 113 + FrameRect(&rect); 114 + } 115 + 116 + 117 + void Put_Up_Characters(c) 118 + char c; 119 + { 120 + int i; 121 + 122 + row = line = 1; 123 + for (i=0; phrase[i] != '\0'; i++) 124 + { 125 + switch(phrase[i]) 126 + { 127 + 128 + case '@': row = 1; 129 + line++; 130 + break; 131 + 132 + case ' ': 133 + case '-': row++; 134 + break; 135 + 136 + default: if (c == toupper(phrase[i])) 137 + Put_Up_Character(row++,line,c); 138 + else 139 + row++; 140 + break; 141 + } 142 + } 143 + } 144 + 145 + void Put_Up_Character(x,y,c) 146 + int x,y; 147 + char c; 148 + { 149 + MoveTo(x*size+x+xoffset+(size*2)/5, y*size+yoffset-(size*2)/5+2); 150 + DrawChar(c); 151 + } 152 + 153 +
+57
sources/ctype.h
··· 1 + /* 2 + Routines for LightspeedC� 3 + 4 + (C) Copyright 1986. THINK Technologies, Inc. All rights reserved. 5 + */ 6 + 7 + #ifndef _ctypeh_ 8 + #define _ctypeh_ 9 + 10 + /* NOTE: the ctype array lives in stddata_ctype.c */ 11 + 12 + extern char __ctype[]; 13 + 14 + #define _alpha_ 1 15 + #define _digit_ 2 16 + #define _hex_ 4 17 + #define _octal_ 8 18 + #define _ascii_ 16 19 + #define _cntrl_ 32 20 + #define _punct_ 64 21 + #define _space_ 128 22 + 23 + /* The c passed by the programmer should always be declared as an int or an 24 + unsigned char, not a char, otherwise these tests will behave 25 + unpredictably with values of c which are greater than 127 since chars 26 + are typically sign extended to ints so array bounds become negative */ 27 + 28 + 29 + #define isalnum(c) (__ctype[(c)+1]&(_alpha_|_digit_)) 30 + 31 + #define isalpha(c) (__ctype[(c)+1]&_alpha_) 32 + 33 + #define isascii(c) (__ctype[(c)+1]&_ascii_) 34 + 35 + #define iscntrl(c) (__ctype[(c)+1]&_cntrl_) 36 + 37 + #define iscsym(c) ((__ctype[(c)+1]&(_alpha_|_digit_))|| (c) == '_') 38 + 39 + #define iscsymf(c) ((__ctype[(c)+1]&_alpha_)|| (c) == '_') 40 + 41 + #define isdigit(c) (__ctype[(c)+1]&_digit_) 42 + 43 + #define isgraph(c) ((c) >= '!' && (c) <= '~') 44 + 45 + #define isodigit(c) (__ctype[(c)+1]&_octal_) 46 + 47 + #define isprint(c) (((c)>=32)&&((c)<=255)) 48 + 49 + #define ispunct(c) (__ctype[(c)+1]&_punct_) 50 + 51 + #define isspace(c) (__ctype[(c)+1]&_space_) 52 + 53 + #define isxdigit(c) (__ctype[(c)+1]&_hex_) 54 + 55 + #define toascii(c) (c&0x7F) 56 + 57 + #endif
+41
sources/errno.h
··· 1 + /* (C) Copyright 1986. THINK Technologies, Inc. All rights reserved. */ 2 + 3 + #define _errnoh_ 4 + 5 + typedef enum { 6 + EPERM=1, 7 + ENOENT=2, 8 + ESRCH=3, 9 + EINTR=4, 10 + EIO=5, 11 + ENXIO=6, 12 + E2BIG=7, 13 + ENOEXEC=8, 14 + EBADF=9, 15 + ECHILD=10, 16 + EAGAIN=11, 17 + ENOMEM=12, 18 + EACCES=13, 19 + EFAULT=14, 20 + ENOTBLK=15, 21 + EBUSY=16, 22 + EEXIST=17, 23 + EXDEV=18, 24 + ENODEV=19, 25 + ENOTDIR=20, 26 + EISDIR=21, 27 + EINVAL=22, 28 + ENFILE=23, 29 + EMFILE=24, 30 + ENOTTY=25, 31 + ETXTBSY=26, 32 + EFBIG=27, 33 + ENOSPC=28, 34 + ESPIPE=29, 35 + EROFS=30, 36 + EMLINK=31, 37 + EPIPE=32, 38 + /* EDOM=33, ERANGE=34, these are in math.h */ 39 + ENOMSG=35, 40 + EIDRM=36 41 + };
+141
sources/fopenw.h
··· 1 + /* (C) Copyright 1986. THINK Technologies, Inc. All rights reserved. */ 2 + 3 + /* 4 + This is the header file for the windowed output printf-2-w.c 5 + supplied with the new stdio. 6 + */ 7 + 8 + #ifndef _fopenwh_ 9 + #define _fopenwh_ 10 + 11 + #ifndef _stdioh_ 12 + #include "stdio.h" 13 + #endif 14 + 15 + #ifndef _WindowMgr_ 16 + #include "WindowMgr.h" 17 + #endif 18 + 19 + #ifndef _ControlMgr_ 20 + #include "ControlMgr.h" 21 + #endif 22 + 23 + #ifndef _EventMgr_ 24 + #include "EventMgr.h" 25 + #endif 26 + 27 + extern GrafPtr WMgrPort:0x9DE; 28 + 29 + /* This is the Standard Window Options structure (passed in to fopenw) */ 30 + 31 + /* Defaults are as follows (check printf-2-w.c for details) if you don't 32 + pass in an options record to fopenw() (also Console window): 33 + 34 + maxrow and maxcol are determined by screenbits.Bounds and the current 35 + font, so they will be something like 24 x 80 with Monaco 9 font on a 36 + standard Mac screen, larger on a Mac XL (Lisa), and even larger on 37 + something like a Radius. 38 + 39 + cursor_visible true 40 + echo_state true 41 + _tab_width 4 42 + no_pull_front false 43 + no_grow, false 44 + no_drag, false 45 + no_goaway, false 46 + no_scroll, false 47 + no_wrap; false 48 + */ 49 + 50 + typedef struct 51 + { 52 + int maxrow, /* number of rows in screen array */ 53 + maxcol; /* number of columns in screen array */ 54 + 55 + Boolean cursor_visible, /* cursor is visible */ 56 + echo_state, /* true if echo enabled */ 57 + _tab_width, /* width of tabs */ 58 + no_pull_front, /* don't pull window to front on keystrokes */ 59 + no_grow, /* no grow box */ 60 + no_drag, /* not draggable */ 61 + no_goaway, /* no goaway box */ 62 + no_scroll, /* vertical wrap instead of scrolling */ 63 + no_wrap; /* fall off end of line rather than horizontal wrap */ 64 + 65 + } StdWindowOptions; 66 + 67 + typedef struct 68 + { 69 + WindowRecord wrec; /* actual window record -- a pointer to this 70 + can be obtained by Get_WindowPtr(filevar) 71 + where filevar is returned from fopenw() */ 72 + long signature; /* can be used to determine if stdio window */ 73 + StdWindowOptions opt; /* our options record */ 74 + int visrow, /* # visible rows */ 75 + viscol, /* # visible columns */ 76 + row, /* current row */ 77 + col, /* current column */ 78 + toprow, /* row in array that is actual first row 79 + since scrolling only changes this and 80 + treats screen array as a wrapped queue */ 81 + charheight, /* character height in pixels */ 82 + charwidth; /* character width in pixels */ 83 + FontInfo sf; /* stuff for font management */ 84 + char screen[]; /* screen row buffer -- pointer to this can 85 + be obtained with Get_ScreenPtr(filevar) 86 + where filevar is returned from fopenw()*/ 87 + } StdWindowRec; 88 + 89 + typedef struct { /* expandable window refcon control structure */ 90 + int (*eventProc)(); 91 + ControlHandle vscroll; 92 + } eventinfo; 93 + 94 + typedef struct { 95 + EventRecord record; 96 + WindowPtr window; 97 + ControlHandle control; 98 + } XEventRecord; 99 + 100 + typedef struct { 101 + WindowPtr wp; 102 + FILE *fp; 103 + } StdwsaveRecord; 104 + 105 + enum {OFF, ON}; 106 + 107 + /* misc. defs */ 108 + 109 + #define _OURSIGNATURE 'LSWD' /* identifies our window records */ 110 + #define _CONTROLWIDTH 15 /* width of scroll bar */ 111 + #define _LEFTEDGE 4 /* margins */ 112 + #define _TOPEDGE 4 113 + 114 + extern int MBarHeight:0xBAA; 115 + #define _MBARHEIGHT (ROM85==-1?20:MBarHeight) 116 + 117 + #define _TITLEBARHEIGHT 20 118 + 119 + #define hiword(x) (((short *) &(x))[0]) 120 + #define loword(x) (((short *) &(x))[1]) 121 + #define screenHeight (screenBits.bounds.bottom) 122 + #define screenWidth (screenBits.bounds.right) 123 + 124 + typedef enum 125 + { 126 + menuEvent=16, /* our internal codes for events */ 127 + growEvent, 128 + dragEvent, 129 + cursorEvent, 130 + selectEvent, 131 + controlEvent, 132 + deactivateEvt, 133 + closeEvent, 134 + openEvent, 135 + appleEvent, 136 + dialogEvent, 137 + editEvent 138 + }; 139 + 140 + #endif 141 +
+27
sources/io.h
··· 1 + /* (C) Copyright 1986. THINK Technologies, Inc. All rights reserved. */ 2 + 3 + #define _ioh_ 4 + #define O_RDONLY 0x0000 5 + #define O_WRONLY 0x0001 6 + #define O_RDWR 0x0002 7 + #define O_APPEND 0x0008 8 + #define O_NDELAY 0x0000 /* ignored when ORed with one of the above */ 9 + 10 + #define O_CREAT 0x0100 11 + #define O_TRUNC 0x0200 12 + #define O_EXCL 0x0400 13 + 14 + #define O_TEXT 0x4000 15 + #define O_BINARY 0x8000 16 + 17 + /* Default for these functions are int so they don't need to be declared 18 + int fileno(); 19 + int open(); 20 + int close(); 21 + int read(); 22 + int write(); 23 + int rename(); 24 + int remove(); 25 + int unlink(); 26 + int creat(); 27 + */
+584
sources/math.c
··· 1 + /* 2 + 3 + Standard Unix math library for LightspeedC�. 4 + 5 + (C) Copyright 1986 THINK Technologies, Inc. All rights reserved. 6 + 7 + See Harbison & Steele's C:A Reference Manual chapter 11 for details 8 + 9 + */ 10 + 11 + 12 + #include "stdio.h" 13 + #include "math.h" 14 + #include "sane.h" 15 + 16 + #define C (0.00000000011641532183) 17 + 18 + /* The following value is the largest possible positive number that can be 19 + represented by the double format */ 20 + 21 + static union { 22 + unsigned int plusdoubleparts[5]; 23 + double plusdouble; 24 + } max = {0x7FFE, 0x7FFF, 0xFFFF, 0xFFFF, 0xFFFF}; 25 + 26 + /* The following value is positive infinity as represented by SANE */ 27 + 28 + static union { 29 + unsigned int plusdoubleparts[5]; 30 + double plusdouble; 31 + } inf = {0x7FFF, 0, 0, 0, 0}; 32 + 33 + /* The following value is the base 2 logarithm of 10.0 as represented 34 + by a double value returned by SANE */ 35 + 36 + static union { 37 + unsigned int tenparts[5]; 38 + double ten; 39 + } log2of = {0x4000, 0xD49A, 0x784B, 0xCD1B, 0x8AFE}; 40 + 41 + /* This is the data structure used with rand() and srand() to generate 42 + random numbers according to the ANSI C spec. 43 + pdg - 6/10/86 */ 44 + 45 + static union { 46 + unsigned long seed; 47 + struct { int sign : 1, v : 15; } hiword; 48 + } randval = 1; 49 + 50 + /* This is the structure of a double, so we can access the exponent 51 + and mantissa sign bits independently without using SANE */ 52 + 53 + typedef struct { 54 + short expsign:1, 55 + exp:15; 56 + long mansign:1, 57 + man:31; 58 + long moreman; 59 + } dbl; 60 + 61 + 62 + /* This is the structure of the SANE (Standard Apple Numeric Environment) 63 + environment flags word used in ceil(), floor(), etc. */ 64 + 65 + typedef struct { 66 + short unused:1, round:2, 67 + /*flags:5, */ inexact:1, divbyzero:1, overflow:1, underflow:1, invalid:1, 68 + lastround:1, precision:2, halts:5; 69 + } SANEenvword; 70 + 71 + /* Temporary save area for SANE global environment flags word */ 72 + 73 + static SANEenvword SANEstate; 74 + 75 + /* Define the location of the SANE environment word in Macintosh memory */ 76 + 77 + #define SANEglobalenv (*((SANEenvword*) 0x0A4A)) 78 + 79 + 80 + /* local function to truncate a double to an integer (works for both old 81 + and new versions of LightspeedC */ 82 + 83 + #define NEWLSC /* if uncommented, removes excess code for new version */ 84 + 85 + #ifndef NEWLSC 86 + 87 + static int trunc(x) 88 + double x; 89 + { 90 + int i; 91 + 92 + SANEstate = SANEglobalenv; 93 + 94 + SANEglobalenv.round = TOWARDZERO; 95 + 96 + i = x; 97 + 98 + SANEglobalenv = SANEstate; 99 + 100 + return (i); 101 + } 102 + #else 103 + #define trunc(x) x 104 + #endif NEWLSC 105 + 106 + 107 + /* Return the absolute value of the integer X */ 108 + #line 0 abs 109 + int abs(x) 110 + int x; 111 + { 112 + if (x<0) return (-x); 113 + return (x); 114 + } 115 + 116 + /* Return the arc cosine of the double value X */ 117 + #line 0 acos 118 + double acos(x) 119 + double x; 120 + { 121 + if ((x > 1.0)||(x < -1.0)) 122 + { 123 + errno = EDOM; 124 + return( 0.0 ); 125 + } 126 + 127 + if (x == -1.0) return ( PI ); 128 + 129 + x = (1.0 - x) / (1.0 + x); 130 + 131 + fp68k(&x, FOSQRT); 132 + 133 + x *= 2.0; 134 + 135 + return( x ); 136 + } 137 + 138 + /* Return the arc sine of the double value X */ 139 + #line 0 asin 140 + double asin(x) 141 + double x; 142 + { 143 + double y = fabs( x ); 144 + 145 + if ( y > 1.0 ) 146 + { 147 + errno = EDOM; 148 + return( 0.0 ); 149 + } 150 + 151 + if (y == 1.0) 152 + { 153 + y = PI2; 154 + 155 + /* copy sign of x into y */ 156 + 157 + (*(dbl*) (&y)).mansign = (*(dbl*) (&x)).mansign; 158 + 159 + return( y ); 160 + } 161 + 162 + if ( y >= 0.3 ) x /= sqrt( (1.0 - x) * (1.0 + x) ); 163 + else 164 + if ( y >= C ) x /= sqrt( 1.0 - x * x ); 165 + 166 + elems68k( &x, FOATANX ); 167 + 168 + return( x ); /* pdg - 6/10/86 - formerly returned y */ 169 + } 170 + 171 + 172 + /* Return the arc tangent of the double value X */ 173 + #line 0 atan 174 + double atan(x) 175 + double x; 176 + { 177 + elems68k( &x, FOATANX ); 178 + return( x ); 179 + } 180 + 181 + 182 + /* Return the arc tangent of the double value of Y divided by X */ 183 + #line 0 atan2 184 + double atan2(y,x) 185 + double y, x; 186 + { 187 + double z; 188 + 189 + if ( x == 0.0 ) 190 + { 191 + if ( y == 0.0 ) 192 + { 193 + errno = EDOM; 194 + return( 0.0 ); 195 + } 196 + 197 + z = PI2; 198 + } 199 + else 200 + { 201 + z = atan( fabs( y ) / fabs( x ) ); 202 + 203 + if (x <= 0.0) z = PI - z; 204 + } 205 + 206 + /* copy sign of y into z */ 207 + 208 + (*(dbl*) (&z)).mansign = (*(dbl*) (&y)).mansign; 209 + 210 + return (z); 211 + } 212 + 213 + 214 + /* Round towards positive infinity. 215 + pdg - 6/10/86 - complete revision using SANE call */ 216 + #line 0 ceil 217 + double ceil(x) 218 + double x; 219 + { 220 + /* save the state, do the round, restore the state, and return value */ 221 + 222 + SANEstate = SANEglobalenv; 223 + 224 + SANEglobalenv.round = UPWARD; 225 + 226 + fp68k( &x, FORTI ); 227 + 228 + SANEglobalenv = SANEstate; 229 + 230 + return (x); 231 + } 232 + 233 + 234 + /* Return the cosine of the double value X */ 235 + #line 0 cos 236 + double cos(x) 237 + double x; 238 + { 239 + elems68k( &x, FOCOSX ); 240 + return( x ); 241 + } 242 + 243 + 244 + /* Return the hyperbolic cosine of the double value X */ 245 + #line 0 cosh 246 + double cosh(x) 247 + double x; 248 + { 249 + double y = exp( fabs( x ) ); 250 + 251 + if (y == 0.0) 252 + { 253 + errno = ERANGE; 254 + return ( max.plusdouble ); 255 + } 256 + 257 + y *= 0.5; 258 + y += y * 0.25; 259 + 260 + return( y ); 261 + } 262 + 263 + /* Return the value of e raised to the X power */ 264 + #line 0 exp 265 + double exp(x) 266 + double x; 267 + { 268 + elems68k( &x, FOEXPX ); 269 + 270 + if (SANEglobalenv.overflow) 271 + { 272 + errno = ERANGE; 273 + return ( max.plusdouble ); 274 + } 275 + 276 + return( x ); 277 + } 278 + 279 + 280 + /* Return the absolute value of X */ 281 + #line 0 fabs 282 + double fabs(x) 283 + double x; 284 + { 285 + fp68k( &x, FOABS ); 286 + return( x ); 287 + } 288 + 289 + 290 + /* Round towards negative infinity. 291 + pdg - 6/10/86 - complete revision using SANE call vs. improper C hack */ 292 + #line 0 floor 293 + double floor(x) 294 + double x; 295 + { 296 + /* save the state, do the round, restore the state, and return value */ 297 + 298 + SANEstate = SANEglobalenv; 299 + 300 + SANEglobalenv.round = DOWNWARD; 301 + 302 + fp68k( &x, FORTI ); 303 + 304 + SANEglobalenv = SANEstate; 305 + 306 + return (x); 307 + } 308 + 309 + 310 + /* Return a number such F that k * Y + f == X 311 + Thanks to Robert J. Murphy of Data Tailor, Inc. for this revision */ 312 + #line 0 fmod 313 + double fmod(x,y) 314 + double x, y; 315 + { 316 + double rem = x; 317 + 318 + fp68k( &y, FOABS); 319 + fp68k( &y, &rem, FOREM); 320 + 321 + if ( (x > 0) && (rem < 0)) rem += y; 322 + else 323 + if ( (x < 0) && (rem > 0)) rem -= y; 324 + 325 + return (rem); 326 + } 327 + 328 + 329 + /* Return fraction and exponent of X */ 330 + #line 0 frexp 331 + double frexp(x,nptr) 332 + double x; 333 + register int *nptr; 334 + { 335 + double y = fabs( x ), z = 2.0; 336 + 337 + if (y == 0.0) 338 + { 339 + *nptr = 0; 340 + return( 0.0 ); 341 + } 342 + 343 + elems68k( &y, FOLOG2X ); 344 + 345 + y -= (*nptr = trunc(y)); 346 + 347 + elems68k( &y, &z, FOPWRY ); 348 + 349 + /* scale the result if not between .5 and 1.0 */ 350 + 351 + if (z >= 1.0) 352 + { 353 + (*nptr)++; 354 + z *= 0.5; 355 + } 356 + else 357 + if (z < 0.5) 358 + { 359 + (*nptr)--; 360 + z *= 2.0; 361 + } 362 + 363 + /* copy sign of x into z */ 364 + 365 + (*(dbl*) (&z)).mansign = (*(dbl*) (&x)).mansign; 366 + 367 + return( z ); 368 + } 369 + 370 + 371 + /* Return the absolute value of the long number X */ 372 + #line 0 labs 373 + long int labs(x) 374 + register long int x; 375 + { 376 + if ( x < 0 ) return (-x); 377 + 378 + return (x); 379 + } 380 + 381 + 382 + /* Return return the floating point number represented by (X * radix) ^ n */ 383 + #line 0 ldexp 384 + double ldexp(x,n) 385 + double x; 386 + int n; 387 + { 388 + fp68k( &n, &x, FOSCALB ); 389 + return( x ); 390 + } 391 + 392 + 393 + /* Return the natural log of the double value X */ 394 + #line 0 log 395 + double log(x) 396 + double x; 397 + { 398 + if (x <= 0.0) 399 + { 400 + errno = EDOM; 401 + return ( -max.plusdouble ); 402 + } 403 + 404 + elems68k( &x, FOLNX ); 405 + return( x ); 406 + } 407 + 408 + 409 + /* Return the log base 10 of the double value X */ 410 + #line 0 log10 411 + double log10(x) 412 + double x; 413 + { 414 + if (x <= 0.0) 415 + { 416 + errno = EDOM; 417 + return ( -max.plusdouble ); 418 + } 419 + 420 + elems68k(&x, FOLOG2X); /* LOG2 is much faster than LN */ 421 + 422 + x /= log2of.ten; 423 + 424 + return ( x ); 425 + } 426 + 427 + 428 + /* Split X into a fraction and integer such that |X| < 1 */ 429 + #line 0 modf 430 + double modf(x,nptr) 431 + double x; 432 + register int *nptr; 433 + { 434 + if (abs( (*nptr = trunc(x)) ) > fabs( x )) 435 + { 436 + if (*nptr > 0) (*nptr)--; 437 + else 438 + (*nptr)++; 439 + } 440 + 441 + x -= *nptr; 442 + 443 + return( x ); 444 + } 445 + 446 + /* Return X ^ Y */ 447 + #line 0 pow 448 + double pow(x,y) 449 + double x, y; 450 + { 451 + int dummyint; 452 + 453 + if ( (x < 0.0 && (modf(y, &dummyint) != 0)) || (x == 0.0 && y < 0.0) ) 454 + { 455 + errno = EDOM; 456 + x = -max.plusdouble; 457 + goto returnx; 458 + } 459 + 460 + elems68k( &y, &x, FOPWRY ); 461 + 462 + if (SANEglobalenv.overflow) 463 + { 464 + errno = ERANGE; 465 + x = max.plusdouble; 466 + } 467 + 468 + returnx: 469 + 470 + return( x ); 471 + } 472 + 473 + 474 + /* Return a random number in the range 0 .. max int */ 475 + #line 0 rand 476 + 477 + int rand() 478 + { 479 + /* pdg - 6/10/86 - ANSI random number generator */ 480 + 481 + randval.seed = randval.seed * 1103515245 + 12345; 482 + return randval.hiword.v; 483 + } 484 + 485 + /* Return the sine of the double value X */ 486 + #line 0 sin 487 + double sin(x) 488 + double x; 489 + { 490 + elems68k( &x, FOSINX ); 491 + return( x ); 492 + } 493 + 494 + /* Return the hyperbolic sine of the double value X */ 495 + #line 0 sinh 496 + double sinh(x) 497 + double x; 498 + { 499 + double y = fabs(x); 500 + 501 + if (y >= C) 502 + { 503 + elems68k( &y, FOEXP1X ); 504 + 505 + if (SANEglobalenv.overflow) 506 + { 507 + errno = ERANGE; 508 + y = max.plusdouble; 509 + } 510 + else 511 + { 512 + y += y / ( y + 1.0); 513 + 514 + y *= 0.5; 515 + } 516 + } 517 + 518 + /* copy sign of x into y */ 519 + 520 + (*(dbl*) (&y)).mansign = (*(dbl*) (&x)).mansign; 521 + 522 + return (y); 523 + } 524 + 525 + 526 + /* Return the square root of the double value X */ 527 + #line 0 sqrt 528 + double sqrt(x) 529 + double x; 530 + { 531 + if (x < 0.0) 532 + { 533 + errno = EDOM; 534 + return( 0.0 ); 535 + } 536 + 537 + fp68k(&x, FOSQRT); 538 + return(x); 539 + } 540 + 541 + 542 + /* Set the seed of the random number generator to SEED */ 543 + #line 0 srand 544 + void srand(seed) 545 + unsigned int seed; 546 + { 547 + randval.seed = seed; 548 + } 549 + 550 + /* Return the tangent of the double value X */ 551 + #line 0 tan 552 + double tan(x) 553 + double x; 554 + { 555 + elems68k( &x, FOTANX ); 556 + 557 + if ( SANEglobalenv.invalid || ( x == inf.plusdouble ) ) 558 + { 559 + errno = ERANGE; 560 + x = max.plusdouble; 561 + } 562 + 563 + return(x); 564 + } 565 + 566 + 567 + /* Return the hyperbolic tangent of the double value X */ 568 + #line 0 tanh 569 + double tanh(x) 570 + double x; 571 + { 572 + double y = fabs( x ); 573 + 574 + if (y >= C) 575 + { 576 + y *= -2.0; 577 + elems68k( &y, FOEXP1X ); 578 + y = -y / ( y + 2.0 ); 579 + } 580 + 581 + (*(dbl*) (&y)).mansign = (*(dbl*) (&x)).mansign; 582 + 583 + return (y); 584 + }
+49
sources/math.h
··· 1 + /**************************************************************************** 2 + 3 + Standard math library header for LightspeedC�. 4 + 5 + (C) Copyright 1986 THINK Technologies, Inc. All rights reserved. 6 + 7 + *****************************************************************************/ 8 + 9 + #ifndef _math_ 10 + 11 + #define _math_ /* show symbols defined */ 12 + double acos(); 13 + double asin(); 14 + double atan(); 15 + double atan2(); 16 + double ceil(); 17 + double cos(); 18 + double cosh(); 19 + double exp(); 20 + double fabs(); 21 + double floor(); 22 + double fmod(); 23 + double frexp(); 24 + long labs(); 25 + double ldexp(); 26 + double log(); 27 + double log10(); 28 + double modf(); 29 + double pow(); 30 + double sin(); 31 + double sinh(); 32 + double sqrt(); 33 + double tan(); 34 + double tanh(); 35 + 36 + #define PI (3.14159265358979323846) 37 + #define PI2 (1.57079632679489661923) 38 + #define PI4 (0.78539816339744830966) 39 + 40 + #define E (2.71828182845904523536) 41 + 42 + typedef enum{ 43 + EDOM=33, 44 + ERANGE=34 45 + }; 46 + 47 + extern int errno; /* actually defined in stdio */ 48 + 49 + #endif
+50
sources/onexit.c
··· 1 + /* 2 + Routines for LightspeedC� 3 + 4 + (C) Copyright 1985, 1986. THINK Technologies, Inc. All rights reserved. 5 + 6 + */ 7 + /* 8 + * onexit 9 + * 10 + * By calling "onexit", the programmer can arrange for up to NPROCS 11 + * routines to be called just before program exit. The routines are 12 + * called with no arguments and in the reverse order in which they 13 + * were supplied to "onexit". 14 + * 15 + * "Onexit" returns its argument, the address of the routine to be 16 + * called, or zero if it has already been called NPROCS times. 17 + * 18 + * "Onexit" is built on a lower-level mechanism, "_onexit", which 19 + * provides for a single routine to be called at termination. 20 + * 21 + */ 22 + 23 + 24 + typedef void (*Proc)(); /* address of a proc */ 25 + 26 + #define NPROCS 32 /* max # of procs in list */ 27 + static int nprocs = 0; /* actual # of procs in list */ 28 + static Proc proctable[NPROCS]; /* list of procs */ 29 + 30 + static long _onexit = 0x4EED006A; /* "jmp $6A(a5)" */ 31 + 32 + onexit_handler() 33 + { 34 + while (nprocs>0) 35 + if (proctable[--nprocs]) 36 + (*proctable[nprocs])(); 37 + } 38 + 39 + #line 0 onexit() 40 + Proc 41 + onexit(proc) 42 + Proc proc; 43 + { 44 + if (nprocs == 0) 45 + (* ((Proc) &_onexit))(onexit_handler); 46 + 47 + return(nprocs < NPROCS ? proctable[nprocs++] = proc : 0); 48 + } 49 + 50 +
+155
sources/printf-1.c
··· 1 + /* 2 + printf routines for LightspeedC� 3 + 4 + (C) Copyright 1985, 1986. THINK Technologies, Inc. All rights reserved. 5 + 6 + pdg - 6/11/86 - revised: split off sprintf to another module 7 + */ 8 + 9 + #include "fopenw.h" 10 + 11 + #ifndef _setjmph_ 12 + #include "setjmp.h" 13 + #endif 14 + 15 + 16 + extern FILE _console_; 17 + 18 + /*---------------------------------------------------------------------------- 19 + some global storage to prevent excessive parameter transfer 20 + ----------------------------------------------------------------------------*/ 21 + static FILE *globalwho=NULL; /* output destination specifier */ 22 + static StdwsaveRecord saverec; /* save record for window info */ 23 + extern jmp_buf env; /* global error return mechanism */ 24 + extern void (*_output)(); /* global pointer to function for output */ 25 + extern int _num_count; /* number of characters transmitted */ 26 + 27 + 28 + #line 0 to_file() 29 + static void to_file(character) 30 + char character; 31 + { 32 + /* context switch back to caller of _format in case of error */ 33 + 34 + if (fputc(character,globalwho) == EOF) 35 + longjmp(env, EOF); 36 + 37 + _num_count++; /* increment transmitted character count */ 38 + } 39 + 40 + 41 + #line 0 to_StdStream() 42 + static void to_StdStream(character) 43 + char character; 44 + { 45 + putch(character); /* putch can't fail */ 46 + 47 + _num_count++; /* increment transmitted character count */ 48 + } 49 + 50 + #line 0 to_DummyStream() 51 + static void to_DummyStream(character) 52 + char character; 53 + { 54 + _num_count++; /* increment transmitted character count */ 55 + } 56 + 57 + #line 0 finish_format() 58 + static int finish_format(who, count) 59 + FILE *who; 60 + int count; 61 + { 62 + /* restore window settings */ 63 + 64 + if (who->window) stdwrestore(who, &saverec); 65 + 66 + return (count); 67 + } 68 + 69 + #line 0 setup_format() 70 + static int setup_format(who) 71 + register FILE *who; 72 + { 73 + /* make sure that globalwho is valid */ 74 + 75 + if (!(globalwho=who)) return (EOF); 76 + 77 + /* assume output is to a file */ 78 + 79 + _output = to_file; 80 + 81 + /* if standard stream */ 82 + 83 + if (who->StdStream) 84 + { 85 + /* assume that we are going to the standard stream */ 86 + 87 + _output = to_StdStream; 88 + 89 + /* if, for some reason, we can't write, then fake it */ 90 + 91 + if (!who->wr) _output = to_DummyStream; 92 + else 93 + Init_stdio(); 94 + 95 + /* preserve existing window settings */ 96 + 97 + if (who->window) stdwsave(who, &saverec); 98 + 99 + } 100 + 101 + return (0); 102 + } 103 + 104 + int _format(); /* function to handle formatting */ 105 + 106 + #line 0 printf(); 107 + int printf(fmt) 108 + char *fmt; 109 + { 110 + if (setup_format(stdout)) return(EOF); 111 + return(finish_format(stdout, _format(&fmt,false))); 112 + } 113 + 114 + #line 0 vprintf(); 115 + int vprintf(fmt,arr) 116 + char *fmt,*arr; 117 + { 118 + if (setup_format(stdout)) return (EOF); 119 + return((finish_format(stdout, _format(&fmt,true)))); 120 + } 121 + 122 + 123 + #line 0 fprintf(); 124 + int fprintf(who,fmt) 125 + FILE *who; 126 + char *fmt; 127 + { 128 + if (setup_format(who)) return (EOF); 129 + return (finish_format(who, _format(&fmt,false))); 130 + } 131 + 132 + #line 0 vfprintf(); 133 + int vfprintf(who,fmt,arr) 134 + FILE *who; 135 + char *fmt,*arr; 136 + { 137 + if (setup_format(who)) return (EOF); 138 + return (finish_format(who, _format(&fmt,true))); 139 + } 140 + 141 + #line 0 cprintf(); 142 + int cprintf(fmt) 143 + char *fmt; 144 + { 145 + if (setup_format(_console)) return (EOF); 146 + return(finish_format(_console, _format(&fmt,false))); 147 + } 148 + 149 + #line 0 vcprintf(); 150 + int vcprintf(fmt,arr) 151 + char *fmt,*arr; 152 + { 153 + if (setup_format(_console)) return (EOF); 154 + return(finish_format(_console, _format(&fmt,true))); 155 + }
+58
sources/printf-1a.c
··· 1 + /* 2 + printf routines for LightspeedC� 3 + 4 + (C) Copyright 1985, 1986. THINK Technologies, Inc. All rights reserved. 5 + 6 + pdg - 6/11/86 - revised: sprintf, vsprintf module 7 + */ 8 + 9 + #ifndef _stdioh_ 10 + #include "stdio.h" 11 + #endif 12 + 13 + #ifndef _MacTypes_ 14 + #include "MacTypes.h" 15 + #endif 16 + 17 + 18 + extern void (*_output)(); /* global pointer to function for output */ 19 + static char *destination; /* pointer to destination buffer */ 20 + 21 + 22 + #line 0 to_memory() 23 + static void to_memory(character) 24 + char character; 25 + { 26 + *destination++ = character; 27 + } 28 + 29 + #line 0 xprintf() 30 + static int xprintf(dest, fmtp, var) 31 + char *dest; /* pointer to buffer space */ 32 + char **fmtp; /* pointer to address of format string pointer */ 33 + Boolean var; 34 + { 35 + _output = to_memory; 36 + destination = dest; 37 + if (_format(fmtp,var) == EOF) return (EOF); 38 + *destination = '\0'; 39 + return(destination-dest+1); 40 + } 41 + 42 + 43 + #line 0 sprintf(); 44 + int sprintf(dest, fmt) 45 + char *dest; /* pointer to buffer space */ 46 + char *fmt; /* pointer to format string */ 47 + { 48 + return xprintf(dest, &fmt,false); 49 + } 50 + 51 + 52 + #line 0 vsprintf(); 53 + int vsprintf(dest, fmt,arr) 54 + char *dest; /* pointer to buffer space */ 55 + char *fmt,*arr; /* pointer to format string */ 56 + { 57 + return xprintf(dest, &fmt,true); 58 + }
+1383
sources/printf-2-w.c
··· 1 + /* 2 + printf routines for LightspeedC� 3 + 4 + (C) Copyright 1986. THINK Technologies, Inc. All rights reserved. 5 + 6 + NOTE: Proportional fonts can be used, but lines will wrap as if they 7 + are monospaced. In this version, since each line is drawn with 8 + DrawChar or DrawText without repositioning, it will look better 9 + than the old monospaced repositioning version of putch. 10 + */ 11 + 12 + /* If you have a non-Mac screen like a Radius or E-Machines, etc. stdio 13 + may not operate correctly since it normally directly moves the graphics 14 + pen to achieve reasonable speeds in drawing characters. By defining 15 + _NonMacScreen_ you can convert all of the specialized code into the 16 + standard Macintosh Toolbox traps so it will work correctly */ 17 + 18 + /* #define _NonMacScreen_ */ 19 + 20 + #ifndef _stdioh_ 21 + #include "stdio.h" 22 + #endif 23 + 24 + #ifndef _QuickDraw_ 25 + #include "QuickDraw.h" 26 + #endif 27 + 28 + #ifndef _FontMgr_ 29 + #include "FontMgr.h" 30 + #endif 31 + 32 + #ifndef _MenuMgr_ 33 + #include "MenuMgr.h" 34 + #endif 35 + 36 + #ifndef _ToolboxUtil_ 37 + #include "ToolboxUtil.h" 38 + #endif 39 + 40 + #ifndef _fopenwh_ 41 + #include "fopenw.h" 42 + #endif 43 + 44 + char *CtoPstr(); 45 + char *PtoCstr(); 46 + char *std_ver(); 47 + void drawcursor(); 48 + void Std_updatewindow(); 49 + 50 + /* screen display globals */ 51 + 52 + static WindowPtr Currentswrp = 0; 53 + static FILE *CurrentWindow = 0; 54 + static WindowPtr _exit_wp = 0; /* for special exit window handling */ 55 + static WindowPtr _console_wp = 0; 56 + 57 + /* default font info */ 58 + 59 + static GrafPort dummyPort; 60 + static FontInfo _sf; /* holds the info about the font */ 61 + static int _font = monaco, 62 + _size = 9, 63 + _face = 0, 64 + _mode = srcOr; /* stuff for Stdio_Config */ 65 + 66 + static RgnHandle emptyrgn; /* used for scrolling */ 67 + static Rect bounds; 68 + 69 + Boolean _inited = false; /* whether Mac is inited yet */ 70 + static Boolean _screen = false; /* whether screen is inited */ 71 + static Boolean _click_on = true; /* wait at exit from program */ 72 + static Boolean _our_menus = false; /* flag to indicate if our menus */ 73 + static int deskacc_count = 0; /* # desk accessories open */ 74 + 75 + Boolean _echo = true; /* global Echo status for keyboard input */ 76 + extern void (*_echo_to_printer_)(); /* global Echo call variable for printer */ 77 + 78 + 79 + #define movecursor(swrp, x, y)\ 80 + MoveTo( _LEFTEDGE + (x) * swrp->charwidth,\ 81 + _TOPEDGE + swrp->sf.ascent + ((y)+swrp->visrow-swrp->opt.maxrow) * swrp->charheight) 82 + 83 + 84 + /* Determine if this is one of the stdio created windows or not */ 85 + 86 + static 87 + Boolean OurWindow(window) 88 + register StdWindowRec *window; 89 + { 90 + if (window) 91 + if ((window == (StdWindowRec *)_exit_wp) || (window->signature == _OURSIGNATURE)) 92 + return (true); 93 + 94 + return (false); 95 + } 96 + 97 + /* Dispatch via refcon field of window record for window events */ 98 + 99 + static 100 + Boolean WindowEvent(xevent) 101 + XEventRecord *xevent; 102 + { 103 + register WindowPeek wp; 104 + register eventinfo **refcon; 105 + register int (*proc)(); 106 + 107 + if (! OurWindow(wp = (WindowPeek) xevent->window)) return (false); 108 + 109 + if (wp->windowKind >= 8 && (refcon = (eventinfo**) wp->refCon) 110 + && (proc = (**refcon).eventProc)) 111 + return ((*proc)(xevent)); 112 + 113 + return (false); 114 + } 115 + 116 + /* If we set up the screen, we set up a simple menu as well 117 + for DAs and such */ 118 + 119 + static 120 + void setup_menus() 121 + { 122 + register MenuHandle menu; /* handle for our menus */ 123 + 124 + InitMenus(); 125 + menu = NewMenu(1, "\p\024"); /* apple menu */ 126 + AddResMenu(menu, 'DRVR'); 127 + InsertMenu(menu, 0); 128 + menu = NewMenu(2, "\pFile"); 129 + AppendMenu(menu, "\p(New;Open;Close;(Save;(-;Quit"); 130 + InsertMenu(menu, 0); 131 + menu = NewMenu(3, "\pEdit"); 132 + #ifdef _STD_PASTE_ 133 + AppendMenu(menu, "\p(Undo;(-;(Cut;(Copy;Paste;(Clear;(-"); 134 + #else 135 + AppendMenu(menu, "\p(Undo;(-;(Cut;(Copy;(Paste;(Clear;(-"); 136 + #endif _STD_PASTE_ 137 + 138 + AppendMenu(menu, CtoPstr(std_ver())); 139 + PtoCstr(std_ver()); 140 + InsertMenu(menu, 0); 141 + DrawMenuBar(); 142 + 143 + _our_menus = true; 144 + } 145 + 146 + static 147 + void do_exit() 148 + {Cursor watch; 149 + 150 + watch = **GetCursor(watchCursor); 151 + SetCursor(&watch); 152 + _click_on = false; 153 + onexit_handler(); /* make sure other onexit routines get called */ 154 + ExitToShell(); 155 + } 156 + 157 + static 158 + doMenu(event) 159 + register XEventRecord *event; 160 + { 161 + short item; 162 + 163 + if (event->record.what != menuEvent) 164 + return; 165 + 166 + item = event->record.message; 167 + switch (* (short *) &event->record.message) 168 + { 169 + case 1: 170 + event->record.what = appleEvent; 171 + HiliteMenu(0); 172 + break; 173 + case 2: 174 + switch (item) 175 + { 176 + case 2: /* Open entry on file menu */ 177 + event->record.what = openEvent; 178 + break; 179 + 180 + case 3: /* Close entry on file menu */ 181 + event->record.what = closeEvent; 182 + break; 183 + 184 + case 6: /* Quit entry on file menu */ 185 + do_exit(); 186 + break; 187 + } 188 + break; 189 + case 3: 190 + #ifdef _STD_PASTE_ 191 + if (item == 5) 192 + /* Paste entry on edit menu */ 193 + _std_setup_paste(); 194 + #endif _STD_PASTE_ 195 + 196 + HiliteMenu(0); 197 + event->record.what = editEvent; 198 + break; 199 + } 200 + } 201 + 202 + /* enable edit menu picks for undo, cut, copy, paste, etc. */ 203 + 204 + static 205 + void edit_enable() 206 + {register MenuHandle editmenu; 207 + 208 + if (_our_menus) 209 + { 210 + if (editmenu = GetMHandle(3)) 211 + {register int i; 212 + for (i=CountMItems(editmenu); i; i--) 213 + EnableItem(editmenu, i); 214 + DisableItem(editmenu, 2); /* gray line */ 215 + DisableItem(editmenu, 7); /* gray line */ 216 + DisableItem(editmenu, 8); /* Library version */ 217 + } 218 + } 219 + } 220 + 221 + static 222 + void edit_disable() 223 + {register MenuHandle editmenu; 224 + 225 + if (_our_menus) 226 + { 227 + if (editmenu = GetMHandle(3)) 228 + {register int i; 229 + for (i=CountMItems(editmenu); i; i--) 230 + DisableItem(editmenu, i); 231 + #ifdef _STD_PASTE_ 232 + EnableItem(editmenu, 5); /* Paste */ 233 + #endif _STD_PASTE_ 234 + EnableItem(editmenu, 8); /* Library version */ 235 + } 236 + } 237 + } 238 + 239 + /* 240 + * StdEvent - event handler 241 + * 242 + */ 243 + 244 + #line 0 StdEvent 245 + Boolean StdEvent(event) 246 + register EventRecord *event; 247 + { 248 + XEventRecord ev; 249 + register XEventRecord *xevent = &ev; 250 + register short item, refnum; 251 + Rect r; 252 + long size; 253 + int (*proc)(); 254 + static char accessory[256]; 255 + 256 + Init_stdio(); 257 + 258 + /* copy event to local data structure */ 259 + 260 + ev = *(XEventRecord*) event; 261 + 262 + /* reset event to point to this extended event record */ 263 + 264 + event = (EventRecord*) &ev; 265 + 266 + xevent->window = FrontWindow(); 267 + 268 + switch (event->what) 269 + { 270 + default: 271 + return (WindowEvent(event)); 272 + 273 + case nullEvent: 274 + if (! WindowEvent(event)) return (false); 275 + 276 + switch (FindWindow(event->where, &xevent->window)) 277 + { 278 + case inContent: 279 + if (xevent->window == FrontWindow()) 280 + { 281 + SetPort(xevent->window); 282 + GlobalToLocal(&event->where); 283 + event->what = cursorEvent; 284 + return (WindowEvent(event)); 285 + } 286 + default: 287 + SetCursor(&arrow); 288 + break; 289 + } 290 + break; 291 + 292 + case updateEvt: 293 + if (! OurWindow(xevent->window = (WindowPtr) event->message)) 294 + return (false); 295 + 296 + BeginUpdate(xevent->window); 297 + SetPort(xevent->window); 298 + WindowEvent(event); 299 + EndUpdate(xevent->window); 300 + break; 301 + 302 + case activateEvt: 303 + if (! OurWindow(xevent->window = (WindowPtr) event->message)) 304 + return (false); 305 + 306 + SetPort(xevent->window); 307 + if (!(event->modifiers & activeFlag)) 308 + event->what = deactivateEvt; 309 + WindowEvent(event); 310 + break; 311 + 312 + case mouseDown: 313 + switch (FindWindow(event->where, &xevent->window)) 314 + { 315 + default: 316 + return (false); 317 + 318 + case inMenuBar: 319 + if (! _our_menus) 320 + return (false); 321 + 322 + xevent->window = FrontWindow(); 323 + SetCursor(&arrow); 324 + doMenu(event); 325 + event->message = MenuSelect(event->where); 326 + 327 + if (hiword(event->message) == 0) break; 328 + 329 + event->what = menuEvent; 330 + doMenu(event); 331 + switch (event->what) 332 + { 333 + case editEvent: 334 + if (SystemEdit((short) event->message - 1)) 335 + break; 336 + WindowEvent(event); 337 + break; 338 + 339 + case closeEvent: 340 + if (xevent->window) 341 + { 342 + refnum = ((WindowPeek) xevent->window)->windowKind; 343 + if (refnum < 0) 344 + { 345 + CloseDeskAcc(refnum); 346 + } 347 + else 348 + WindowEvent(event); 349 + } 350 + break; 351 + 352 + case openEvent: 353 + if (_console->filebuf) 354 + { 355 + if (!((WindowPeek)_console->filebuf)->visible) 356 + { 357 + ShowWindow(_console->filebuf); 358 + Std_updatewindow(_console->filebuf); 359 + } 360 + } 361 + break; 362 + 363 + case appleEvent: 364 + GetItem(GetMHandle(hiword(event->message)), 365 + loword(event->message), 366 + accessory); 367 + OpenDeskAcc(accessory); 368 + edit_enable(); 369 + break; 370 + } 371 + break; 372 + 373 + case inSysWindow: 374 + SystemClick(event, xevent->window); 375 + break; 376 + 377 + case inContent: 378 + if (! OurWindow(xevent->window)) return (false); 379 + 380 + if (xevent->window != FrontWindow()) 381 + { 382 + event->what = selectEvent; 383 + WindowEvent(event); 384 + if (event->what != mouseDown) 385 + { 386 + SelectWindow(xevent->window); 387 + break; 388 + } 389 + } 390 + SetPort(xevent->window); 391 + GlobalToLocal(&event->where); 392 + if (event->message = FindControl(event->where, 393 + xevent->window, 394 + &xevent->control)) 395 + { 396 + proc = (int (*)()) (event->message > 128 ? 0L : -1L); 397 + if (TrackControl(xevent->control, event->where, proc) == 0) 398 + break; 399 + event->what = controlEvent; 400 + } 401 + WindowEvent(event); 402 + if (event->what != dragEvent) break; 403 + 404 + LocalToGlobal(&event->where); 405 + /* ... */ 406 + case inDrag: 407 + /* don't select window if command key is down */ 408 + 409 + if (!(event->modifiers & cmdKey)) 410 + if (xevent->window != FrontWindow()) 411 + { 412 + SelectWindow(xevent->window); 413 + break; 414 + } 415 + SetRect(&r, 4, _MBARHEIGHT + 4, screenWidth - 4, screenHeight - 4); 416 + SetCursor(&arrow); 417 + DragWindow(xevent->window, event->where, &r); 418 + break; 419 + 420 + case inGrow: 421 + if (! OurWindow(xevent->window)) return (false); 422 + 423 + {register StdWindowRec *swrp = (StdWindowRec*)xevent->window; 424 + 425 + SetRect(&r, 426 + swrp->charwidth + _LEFTEDGE + _CONTROLWIDTH + 3, 427 + swrp->charheight + _TOPEDGE + _CONTROLWIDTH + 8, 428 + swrp->charwidth * swrp->opt.maxcol + _LEFTEDGE + _CONTROLWIDTH + 3, 429 + swrp->charheight * swrp->opt.maxrow + _TOPEDGE + _CONTROLWIDTH + 8); 430 + } 431 + 432 + SetCursor(&arrow); 433 + if (size = GrowWindow(xevent->window, event->where, &r)) 434 + { 435 + SizeWindow(xevent->window, loword(size), hiword(size), 0); 436 + SetPort(xevent->window); 437 + InvalRect(&xevent->window->portRect); 438 + event->what = growEvent; 439 + WindowEvent(event); 440 + {StdWindowRec *swrp = ((StdWindowRec*)xevent->window); 441 + swrp->viscol = (loword(size)-_CONTROLWIDTH-1-swrp->charwidth+1)/swrp->charwidth; 442 + swrp->visrow = (hiword(size)-_CONTROLWIDTH-1-swrp->charheight+1)/swrp->charheight; 443 + 444 + /* make sure neither variable exceeds legal bounds */ 445 + 446 + if (swrp->viscol > swrp->opt.maxcol) swrp->viscol = swrp->opt.maxcol; 447 + if (swrp->visrow > swrp->opt.maxrow) swrp->visrow = swrp->opt.maxrow; 448 + } 449 + } 450 + break; 451 + 452 + case inGoAway: 453 + if (! OurWindow(xevent->window)) return (false); 454 + 455 + SetCursor(&arrow); 456 + if (TrackGoAway(xevent->window, event->where)) 457 + { 458 + event->what = closeEvent; 459 + WindowEvent(event); 460 + } 461 + break; 462 + } 463 + break; 464 + } 465 + return (true); 466 + } 467 + 468 + static 469 + void stdio_fontset(portp) 470 + GrafPtr portp; 471 + { 472 + /* set up a font */ 473 + 474 + SetPort(portp); 475 + TextFont(_font); 476 + TextSize(_size); 477 + TextFace(_face); 478 + TextMode(_mode); 479 + } 480 + 481 + static 482 + void drawcursor(swrp, flag) 483 + register StdWindowRec *swrp; 484 + Boolean flag; 485 + {register int x, y, savey; 486 + #ifdef _NonMacScreen_ 487 + Point savepoint; 488 + #endif 489 + 490 + if (swrp->opt.cursor_visible) 491 + {register int mode = notPatCopy; 492 + 493 + if (flag == ON) mode = patCopy; 494 + 495 + /* adjust and save pen position */ 496 + 497 + #ifdef _NonMacScreen_ 498 + GetPen(&savepoint); 499 + x = savepoint.h - 1; 500 + savey = savepoint.v; 501 + y = savey + swrp->sf.descent; 502 + MoveTo(x,y); 503 + #else 504 + x = ((WindowPtr)swrp)->pnLoc.h -= 1; 505 + savey = ((WindowPtr)swrp)->pnLoc.v; 506 + y = (((WindowPtr)swrp)->pnLoc.v += swrp->sf.descent); 507 + #endif 508 + /* cursor is simply a vertical line */ 509 + 510 + #ifdef _NonMacScreen_ 511 + PenMode(mode); 512 + #else 513 + ((WindowPtr)swrp)->pnMode = mode; /*improved speed on Mac screen */ 514 + #endif 515 + 516 + LineTo(x, y - swrp->charheight); 517 + 518 + #ifdef _NonMacScreen_ 519 + MoveTo(x+1, savey); 520 + #else 521 + ((WindowPtr)swrp)->pnLoc.h = x + 1; 522 + ((WindowPtr)swrp)->pnLoc.v = savey; 523 + #endif 524 + /* redraw character where cursor is if we turned it off */ 525 + 526 + if (flag == OFF) 527 + { 528 + DrawChar(swrp->screen[((swrp->toprow+swrp->row)%swrp->opt.maxrow)*swrp->opt.maxcol+swrp->col]); 529 + 530 + /* replaced with below to improve speed */ 531 + #ifdef _NonMacScreen_ 532 + MoveTo(x+1, savey); 533 + #else 534 + ((WindowPtr)swrp)->pnLoc.h = x + 1; 535 + ((WindowPtr)swrp)->pnLoc.v = savey; 536 + #endif 537 + } 538 + } 539 + } 540 + 541 + #line 0 Std_updatewindow 542 + void Std_updatewindow(swrp) 543 + register StdWindowRec *swrp; 544 + { 545 + register int i, thisrow; 546 + 547 + SetPort(swrp); 548 + 549 + EraseRect(&((WindowPtr)swrp)->portRect); 550 + 551 + /* redraw last n rows in the visible region */ 552 + 553 + for (i=0, 554 + thisrow = (swrp->toprow + (swrp->opt.maxrow-swrp->visrow)) % swrp->opt.maxrow; 555 + i<swrp->visrow; 556 + i++, thisrow = ++thisrow % swrp->opt.maxrow) 557 + { 558 + movecursor(swrp, 0, i+swrp->opt.maxrow-swrp->visrow); 559 + DrawText(&swrp->screen[thisrow*swrp->opt.maxcol], 0, swrp->viscol); 560 + } 561 + 562 + if (!swrp->opt.no_grow) 563 + {Rect r; 564 + /* invalidate the scroll bar regions of the window, so 565 + the scroll bars and grow box get drawn properly */ 566 + r = ((WindowPtr)swrp)->portRect; 567 + r.left = r.right-_CONTROLWIDTH-2; 568 + r.top = r.bottom-_CONTROLWIDTH-2; 569 + InvalRect(&r); 570 + 571 + DrawControls(swrp); 572 + DrawGrowIcon(swrp); 573 + } 574 + 575 + /* make sure there is no further update event on this window */ 576 + 577 + ValidRect(&((WindowPtr)swrp)->portRect); 578 + 579 + movecursor(swrp, swrp->col, swrp->row); 580 + drawcursor(swrp, ON); 581 + } 582 + 583 + static 584 + Stdwindow_doEvent(xevent) 585 + XEventRecord *xevent; 586 + { 587 + register WindowPtr wp = xevent->window; 588 + register int i; 589 + 590 + switch (((EventRecord*)xevent)->what) 591 + { 592 + case activateEvt: 593 + edit_disable(); 594 + break; 595 + 596 + case deactivateEvt: 597 + {StdWindowRec *srp; 598 + 599 + edit_disable(); 600 + 601 + if ((srp = (StdWindowRec*)FrontWindow())) 602 + if (! OurWindow(srp)) 603 + edit_enable(); 604 + break; 605 + } 606 + case updateEvt: 607 + Std_updatewindow(wp); 608 + break; 609 + 610 + case closeEvent: 611 + 612 + /* hide the window */ 613 + 614 + HideWindow(wp); 615 + 616 + /* THIS PATCHED OUT CODE ALLOWS CLOSING ALL WINDOWS WHICH SHARE 617 + THIS WINDOW POINTER AND RELEASING THEIR WINDOW RECORDS: 618 + for (i= _NFILE-1; i>=0 ; i--) 619 + if (_file[i].filebuf == (char*)wp) 620 + fclosew(&_file[i]); 621 + */ 622 + 623 + break; 624 + 625 + default: 626 + /* event was not handled by us */ 627 + 628 + return (false); 629 + } 630 + 631 + /* event was handled somewhere above */ 632 + 633 + return (true); 634 + } 635 + 636 + #line 0 fclosew 637 + int fclosew(who) 638 + register FILE *who; 639 + { 640 + if (!who->window) return (EOF); 641 + 642 + if (who != _console) 643 + { 644 + who->window = false; 645 + who->InUse = false; 646 + 647 + /* Now release the memory for the window record unless 648 + it's the console which we never should release */ 649 + 650 + if (OurWindow(who->filebuf) && ((WindowPtr)who->filebuf != _console_wp)) 651 + { 652 + ((StdWindowRec*)who->filebuf)->signature = 0; 653 + DisposHandle(((WindowPeek)who->filebuf)->refCon); 654 + DisposeWindow(who->filebuf); 655 + } 656 + 657 + who->filebuf = NULL; 658 + 659 + if (who == CurrentWindow) 660 + { 661 + CurrentWindow = _console; 662 + Currentswrp = _console_wp; 663 + } 664 + } 665 + 666 + return (0); 667 + } 668 + 669 + static 670 + void clearscreenmem(swrp) 671 + register StdWindowRec *swrp; 672 + { 673 + register char sp = ' '; 674 + register char *begp, *p; 675 + 676 + /* clear screen buffer to spaces working backwards through buffer */ 677 + 678 + p = (begp = swrp->screen) + swrp->opt.maxcol * swrp->opt.maxrow; 679 + 680 + while (--p >= begp) *p = sp; 681 + } 682 + 683 + 684 + static 685 + FILE *fopenwx(titlebar, upper_left, optionsptr, whichfilevar, ourwp) 686 + char *titlebar; 687 + Point upper_left; 688 + register StdWindowOptions *optionsptr; 689 + FILE *whichfilevar; 690 + WindowPtr ourwp; 691 + { 692 + register int maxrow = 0, maxcol = 0; 693 + register FILE *who; 694 + register StdWindowRec *swrp; 695 + register Boolean grow = true, goaway = true; 696 + eventinfo et; 697 + 698 + Init_stdio(); 699 + 700 + if (whichfilevar) 701 + { 702 + /* a specific file variable was specified */ 703 + who = whichfilevar; 704 + 705 + if ((!who->StdStream) || who->InUse) 706 + { 707 + /* don't allow this for other than standard streams */ 708 + errno = -47; /* file busy error */ 709 + return (NULL); 710 + } 711 + } 712 + else 713 + {register int free_slot = _NFILE; 714 + 715 + /* look thru FILE array for an open slot */ 716 + 717 + while ((--free_slot>=0) && _file[free_slot].InUse) 718 + ; 719 + 720 + if (free_slot < 0) 721 + { 722 + errno = -42; /* tmfoErr - too many files open */ 723 + return (NULL); 724 + } 725 + 726 + who = &_file[free_slot]; 727 + 728 + if (!ourwp && optionsptr) 729 + { 730 + /* override defaults */ 731 + 732 + maxcol = optionsptr->maxcol; 733 + maxrow = optionsptr->maxrow; 734 + 735 + grow = !optionsptr->no_grow; 736 + goaway = !optionsptr->no_goaway; 737 + } 738 + } 739 + 740 + /* if ourwp is nonzero, then the window is already set up and all 741 + we need to do is set up the file record */ 742 + 743 + if (ourwp) swrp = (StdWindowRec*) ourwp; 744 + else 745 + {{register int charheight; 746 + 747 + stdio_fontset(&dummyPort); 748 + GetFontInfo(&_sf); 749 + 750 + charheight = (_sf.ascent + _sf.descent + _sf.leading); 751 + 752 + /* set up default number of rows and columns depending on screen */ 753 + 754 + if (!maxrow) 755 + maxrow = (screenHeight - upper_left.v - _TOPEDGE - _CONTROLWIDTH - 1 - charheight + 1) / 756 + charheight; 757 + 758 + if (!maxcol) 759 + maxcol = (screenWidth - upper_left.h - _LEFTEDGE - _CONTROLWIDTH - 1 - _sf.widMax + 1) / 760 + _sf.widMax; 761 + 762 + /* create a pointer block big enough to accomodate the window record 763 + and all of our stuff */ 764 + 765 + if (!(swrp = (StdWindowRec*) (NewPtr(sizeof(StdWindowRec)+maxrow*maxcol)))) 766 + { 767 + errno = -108; /* MemFullErr - ran out of memory */ 768 + return (NULL); 769 + } 770 + 771 + swrp->sf = _sf; 772 + 773 + swrp->charheight = charheight; 774 + swrp->charwidth = _sf.widMax; 775 + 776 + } /* just provides scoping for charheight */ 777 + 778 + swrp->toprow = swrp->col = 0; 779 + swrp->row = maxrow - 1; /* start cursor at bottom of screen */ 780 + swrp->signature = _OURSIGNATURE; 781 + 782 + bounds.top = upper_left.v; 783 + bounds.left = upper_left.h; 784 + bounds.right = bounds.left + _LEFTEDGE + maxcol * swrp->charwidth + _CONTROLWIDTH + 1; 785 + bounds.bottom = bounds.top + _TOPEDGE + maxrow * swrp->charheight + _CONTROLWIDTH + 1 + 4; 786 + 787 + NewWindow(swrp, &bounds, CtoPstr(titlebar), true, 788 + (grow ? documentProc : noGrowDocProc), -1L, goaway, 0L); 789 + 790 + PtoCstr(titlebar); 791 + 792 + /* set up event processing hooks */ 793 + 794 + et.eventProc = Stdwindow_doEvent; 795 + et.vscroll = 0; 796 + PtrToHand(&et, &((WindowPeek)swrp)->refCon, sizeof et); 797 + 798 + stdio_fontset(swrp); 799 + 800 + if (grow) 801 + { 802 + InvalRect(&((WindowPtr)swrp)->portRect); 803 + DrawControls(swrp); 804 + DrawGrowIcon(swrp); 805 + } 806 + 807 + ValidRect(&((WindowPtr)swrp)->portRect); 808 + 809 + if (optionsptr) 810 + swrp->opt = *optionsptr; 811 + else 812 + { 813 + swrp->opt.maxrow = maxrow; 814 + swrp->viscol = swrp->opt.maxcol = maxcol; 815 + swrp->opt.cursor_visible = true; 816 + swrp->opt.echo_state = true; 817 + swrp->opt._tab_width = 4; 818 + swrp->opt.no_pull_front = false; 819 + swrp->opt.no_grow = !grow; 820 + swrp->opt.no_drag = false; 821 + swrp->opt.no_goaway = !goaway; 822 + swrp->opt.no_scroll = false; 823 + swrp->opt.no_wrap = false; 824 + } 825 + 826 + swrp->visrow = maxrow; 827 + swrp->viscol = maxcol; 828 + 829 + /* clear screen memory to spaces */ 830 + 831 + clearscreenmem(swrp); 832 + 833 + movecursor(swrp, swrp->col, swrp->row); 834 + drawcursor(swrp, ON); 835 + } 836 + 837 + /* set all relevant items in FILE record */ 838 + 839 + who->filebuf = (char *) swrp; 840 + who->StdStream = true; 841 + who->InUse = true; 842 + who->window = true; 843 + who->rd = false; 844 + who->wr = true; 845 + 846 + return (who); 847 + } 848 + 849 + #line 0 fopenw 850 + FILE *fopenw(titlebar, upper_left, optionsptr) 851 + char *titlebar; 852 + Point upper_left; 853 + StdWindowOptions *optionsptr; 854 + { 855 + fopenwx(titlebar, upper_left, optionsptr, NULL, NULL); 856 + } 857 + 858 + #line 0 setwindow 859 + int setwindow(windowfile) 860 + register FILE *windowfile; 861 + { 862 + register StdWindowRec *swrp; 863 + 864 + if (windowfile && 865 + windowfile->InUse && 866 + windowfile->window && 867 + (swrp = ((StdWindowRec*)windowfile->filebuf))->signature == _OURSIGNATURE) 868 + { 869 + CurrentWindow = windowfile; 870 + Currentswrp = (WindowPtr) swrp; 871 + _echo = swrp->opt.echo_state; 872 + } 873 + else 874 + return (EOF); 875 + 876 + return (0); 877 + } 878 + 879 + stdwsave(windowfile, env) 880 + FILE *windowfile; 881 + StdwsaveRecord *env; 882 + { 883 + 884 + Init_stdio(); 885 + env->fp = CurrentWindow; 886 + env->wp = Currentswrp; 887 + 888 + return (setwindow(windowfile)); 889 + } 890 + 891 + stdwrestore(windowfile, env) 892 + FILE *windowfile; 893 + StdwsaveRecord *env; 894 + { 895 + if (windowfile != CurrentWindow) return (EOF); 896 + 897 + CurrentWindow = env->fp; 898 + Currentswrp = env->wp; 899 + _echo = ((StdWindowRec*)Currentswrp)->opt.echo_state; 900 + return (0); 901 + } 902 + 903 + #line 0 Click_On() 904 + void Click_On(flag) 905 + { 906 + _click_on = flag; 907 + } 908 + 909 + static 910 + draw_exit_text(xevent) 911 + XEventRecord *xevent; 912 + { 913 + WindowPtr wp = xevent->window; 914 + 915 + switch (((EventRecord*)xevent)->what) 916 + { 917 + case updateEvt: 918 + SetPort(wp); 919 + MoveTo(4, 24+_sf.descent); 920 + DrawString("\p Click close box of this window or press Return to continue"); 921 + break; 922 + 923 + case closeEvent: 924 + do_exit(); 925 + 926 + default: 927 + /* event not handled by us */ 928 + 929 + return (false); 930 + } 931 + 932 + /* event was handled above */ 933 + 934 + return (true); 935 + } 936 + 937 + static 938 + void click_to_continue() 939 + { 940 + eventinfo et; 941 + 942 + /* make sure all exit routines have been called before we 943 + do anything */ 944 + 945 + onexit_handler(); 946 + 947 + /* if (emptyrgn) DisposeRgn(emptyrgn); - need not bother since the 948 + entire application heap should be vaporized shortly */ 949 + 950 + if (_click_on) 951 + { 952 + /* cancel any pending events */ 953 + 954 + FlushEvents(everyEvent, 0); 955 + 956 + bounds.left = bounds.top = 50; 957 + bounds.right = 456; 958 + bounds.bottom = 100; 959 + 960 + /* Put up a window and handle window events 961 + until goaway is clicked for this window */ 962 + 963 + _exit_wp = NewWindow(0L, &bounds, "\pExit Window", 964 + true, noGrowDocProc, 965 + -1L, true, 0L); 966 + 967 + et.eventProc = draw_exit_text; 968 + PtrToHand(&et, &((WindowPeek) _exit_wp)->refCon, sizeof et); 969 + 970 + _font = systemFont; 971 + _size = 12; 972 + stdio_fontset(_exit_wp); 973 + 974 + /* small event loop to process window events such as bringing 975 + to front, resizing, dragging, etc. */ 976 + 977 + for (;;) 978 + {EventRecord event; 979 + while (! GetNextEvent(everyEvent, &event)) 980 + { 981 + HiliteMenu(0); 982 + SystemTask(); 983 + } 984 + 985 + SetCursor(&arrow); 986 + 987 + if (event.what == keyDown && (char) event.message == '\r') 988 + break; 989 + 990 + StdEvent(&event); 991 + } 992 + 993 + do_exit(); 994 + } 995 + } 996 + 997 + #line 0 Stdio_Config() 998 + void Stdio_Config(font,size,face,mode) 999 + int font,size,face,mode; 1000 + { 1001 + /* modify defaults */ 1002 + 1003 + _font = font; 1004 + _size = size; 1005 + _face = face; 1006 + _mode = mode; 1007 + } 1008 + 1009 + #line 0 Stdio_config() /* lower case c since it was wrong in the manual! */ 1010 + void Stdio_config(font,size,face,mode) 1011 + int font,size,face,mode; 1012 + { 1013 + Stdio_Config(font, size, face, mode); 1014 + } 1015 + 1016 + void Init_stdio() 1017 + { 1018 + register StdWindowRec *swrp; 1019 + Point topleftcorner; 1020 + 1021 + if (_inited && _screen) return; 1022 + 1023 + if (!_inited) 1024 + { 1025 + _inited = true; 1026 + InitGraf(&thePort); 1027 + InitFonts(); 1028 + InitWindows(); 1029 + InitDialogs(0L); 1030 + setup_menus(); 1031 + TEInit(); 1032 + FlushEvents(everyEvent, 0); 1033 + HiliteMenu(0); 1034 + SystemTask(); 1035 + } 1036 + 1037 + if (!_screen) 1038 + { 1039 + _screen = true; 1040 + 1041 + OpenPort(&dummyPort); 1042 + 1043 + /* this font information must be set up for fopenw to know how 1044 + big to make the window */ 1045 + 1046 + topleftcorner.h = 4; 1047 + topleftcorner.v = _MBARHEIGHT + _TITLEBARHEIGHT + 4; 1048 + 1049 + setwindow(fopenwx("console", topleftcorner, NULL, _console, NULL)); 1050 + 1051 + _console_wp = Currentswrp; 1052 + 1053 + /* unlike other windows, console is multi-purpose and 1054 + so it is handled specially */ 1055 + 1056 + _console->rd = true; 1057 + 1058 + /* set up stdout and stderr to match */ 1059 + 1060 + if (stdout->StdStream) 1061 + fopenwx("", topleftcorner, NULL, stdout, _console_wp); 1062 + 1063 + if (stderr->StdStream) 1064 + fopenwx("", topleftcorner, NULL, stderr, _console_wp); 1065 + 1066 + /* set up exit procedure */ 1067 + 1068 + onexit(click_to_continue); 1069 + 1070 + SetCursor(&arrow); 1071 + } 1072 + 1073 + if (!emptyrgn) emptyrgn=NewRgn(); 1074 + } 1075 + 1076 + #line 0 Set_Echo() 1077 + void Set_Echo(state) 1078 + Boolean state; 1079 + { 1080 + _echo = state; 1081 + if (CurrentWindow) 1082 + ((StdWindowRec*)(Currentswrp))->opt.echo_state = state; 1083 + } 1084 + 1085 + /* pdg - 6/10/86 - Stdio_MacInit() allows coexistence of Mac windows and 1086 + stdio if called with flag set to true so stdio won't 1087 + reinitialize all of the Mac stuff. */ 1088 + 1089 + #line 0 Stdio_MacInit() 1090 + void Stdio_MacInit(flag) 1091 + Boolean flag; 1092 + { 1093 + _inited = flag; 1094 + } 1095 + 1096 + #line 0 Set_Tab 1097 + void Set_Tab(len) 1098 + int len; 1099 + { 1100 + Init_stdio(); 1101 + 1102 + ((StdWindowRec*) Currentswrp)->opt._tab_width = 1; 1103 + 1104 + if (len < 1) ((StdWindowRec*) Currentswrp)->opt._tab_width = len; 1105 + } 1106 + 1107 + #line 0 gotoxy 1108 + void gotoxy(x,y) 1109 + register int x,y; 1110 + { 1111 + register StdWindowRec *swrp; 1112 + 1113 + Init_stdio(); 1114 + 1115 + swrp = (StdWindowRec*) Currentswrp; 1116 + 1117 + if ((x < swrp->opt.maxcol) && (y < swrp->opt.maxrow)) 1118 + { 1119 + drawcursor(swrp, OFF); 1120 + swrp->col = x; 1121 + swrp->row = y; 1122 + movecursor(swrp, x,y); 1123 + drawcursor(swrp, ON); 1124 + } 1125 + } 1126 + 1127 + #line 0 getxpos 1128 + int getxpos() 1129 + { 1130 + Init_stdio(); 1131 + 1132 + return (((StdWindowRec*) Currentswrp)->col); 1133 + } 1134 + 1135 + #line 0 getypos 1136 + int getypos() 1137 + { 1138 + Init_stdio(); 1139 + 1140 + return (((StdWindowRec*) Currentswrp)->row); 1141 + } 1142 + 1143 + #line 0 Get_ScreenPtr 1144 + char *Get_ScreenPtr(who) 1145 + register FILE *who; 1146 + { 1147 + Init_stdio(); 1148 + 1149 + if (who->InUse && who->window) 1150 + return (((StdWindowRec*) who->filebuf)->screen); 1151 + 1152 + return (NULL); 1153 + } 1154 + 1155 + #line 0 Get_WindowPtr 1156 + void *Get_WindowPtr(who) /* actually returns a WindowPtr! */ 1157 + register FILE *who; 1158 + { 1159 + Init_stdio(); 1160 + 1161 + if (who->InUse && who->window) 1162 + return ((void*) who->filebuf); 1163 + 1164 + return (NULL); 1165 + } 1166 + 1167 + #line 0 putch 1168 + void putch(c) 1169 + register char c; 1170 + { 1171 + register StdWindowRec *swrp; 1172 + register char *screenp; 1173 + static inited=false; 1174 + 1175 + if (!inited) 1176 + { 1177 + inited = true; 1178 + Init_stdio(); 1179 + } 1180 + 1181 + if (! Currentswrp || ! CurrentWindow->InUse) return; 1182 + 1183 + if (_echo_to_printer_ && (Currentswrp == _console_wp)) 1184 + (*_echo_to_printer_)(c); 1185 + 1186 + SetPort(swrp = (StdWindowRec*) Currentswrp); 1187 + 1188 + if (swrp != (StdWindowRec *)FrontWindow()) 1189 + if (! swrp->opt.no_pull_front) 1190 + { 1191 + SelectWindow(swrp); 1192 + Std_updatewindow(swrp); 1193 + } 1194 + 1195 + /* wait here if mouse is down */ 1196 + 1197 + while (Button()); 1198 + 1199 + if (c<' ') 1200 + { 1201 + switch(c) 1202 + { 1203 + 1204 + case '\t': 1205 + {register int over; 1206 + Boolean newline = false; 1207 + 1208 + over = swrp->opt._tab_width - (swrp->col % swrp->opt._tab_width); 1209 + if ((swrp->col + over) > swrp->opt.maxcol) 1210 + { 1211 + newline = true; 1212 + c = '\n'; 1213 + 1214 + over = swrp->opt.maxcol - swrp->col; 1215 + } 1216 + 1217 + /* want to write spaces into those columns where tab is */ 1218 + 1219 + if (over > 0) 1220 + {Rect r; 1221 + 1222 + screenp = swrp->screen + 1223 + (((swrp->toprow+swrp->row)%swrp->opt.maxrow) * swrp->opt.maxcol) + swrp->col - 1; 1224 + 1225 + drawcursor(swrp, OFF); 1226 + 1227 + /* erase character positions on screen */ 1228 + 1229 + r.right = (r.left = ((WindowPtr)swrp)->pnLoc.h) + over * swrp->charwidth; 1230 + r.top = (r.bottom = ((WindowPtr)swrp)->pnLoc.v + swrp->sf.descent) - swrp->charheight; 1231 + 1232 + EraseRect(&r); 1233 + 1234 + swrp->col += over; 1235 + 1236 + while (--over>=0) *++screenp = ' '; 1237 + 1238 + movecursor(swrp, swrp->col, swrp->row); 1239 + 1240 + drawcursor(swrp, ON); 1241 + } 1242 + 1243 + if (newline) break; 1244 + 1245 + return; 1246 + } 1247 + 1248 + case '\r': /* simply return cursor to start of line */ 1249 + drawcursor(swrp, OFF); 1250 + swrp->col = 0; 1251 + movecursor(swrp, 0, swrp->row); 1252 + drawcursor(swrp, ON); 1253 + return; 1254 + 1255 + case '\b': /* simply reposition cursor back one column */ 1256 + { 1257 + /* This won't work for proportional fonts 1258 + since we don't have the true width handy 1259 + true, it could be looked up in the font...*/ 1260 + 1261 + drawcursor(swrp, OFF); 1262 + 1263 + if (swrp->col == 0) 1264 + { 1265 + if (((swrp->row == 0) && (!swrp->opt.no_scroll)) 1266 + || swrp->opt.no_wrap) 1267 + { 1268 + drawcursor(swrp, ON); 1269 + return; 1270 + } 1271 + 1272 + /* return to previous row */ 1273 + 1274 + if (swrp->row == 0) 1275 + swrp->row = swrp->opt.maxrow; 1276 + 1277 + swrp->row--; 1278 + swrp->col = swrp->opt.maxcol; 1279 + } 1280 + swrp->col--; 1281 + movecursor(swrp, swrp->col, swrp->row); 1282 + drawcursor(swrp, ON); 1283 + return; 1284 + } 1285 + 1286 + case '\f': 1287 + {Rect r; 1288 + 1289 + drawcursor(swrp, OFF); 1290 + 1291 + r = ((WindowPtr)swrp)->portRect; 1292 + r.right -= _CONTROLWIDTH+2; 1293 + r.bottom -= _CONTROLWIDTH+2; 1294 + EraseRect(&r); 1295 + 1296 + swrp->toprow = swrp->row = swrp->col = 0; 1297 + 1298 + clearscreenmem(swrp); 1299 + 1300 + movecursor(swrp, 0, 0); 1301 + drawcursor(swrp, ON); 1302 + return; 1303 + } 1304 + 1305 + case 7: SysBeep(2); /* Bell */ 1306 + return; 1307 + } 1308 + } 1309 + 1310 + drawcursor(swrp, OFF); 1311 + 1312 + if ((c != '\n') && (swrp->col < swrp->opt.maxcol)) 1313 + { 1314 + screenp = swrp->screen + ((swrp->toprow+swrp->row)%swrp->opt.maxrow)*swrp->opt.maxcol+swrp->col; 1315 + 1316 + /* dump character into the screen buffer and 1317 + possibly draw the character */ 1318 + 1319 + 1320 + 1321 + if (swrp->col < swrp->viscol) 1322 + { 1323 + if (*screenp != ' ') 1324 + {Rect r; 1325 + /* erase this character position on screen */ 1326 + 1327 + r.right = (r.left = ((WindowPtr)swrp)->pnLoc.h) + swrp->charwidth; 1328 + r.top = (r.bottom = ((WindowPtr)swrp)->pnLoc.v + swrp->sf.descent) - swrp->charheight; 1329 + 1330 + EraseRect(&r); 1331 + } 1332 + 1333 + DrawChar(*screenp = c); 1334 + } 1335 + else 1336 + *screenp = c; 1337 + } 1338 + 1339 + /* need to do a newline? */ 1340 + 1341 + if ((c=='\n') || ((++swrp->col >= swrp->opt.maxcol) && !swrp->opt.no_wrap)) 1342 + { 1343 + if (swrp->opt.no_scroll) 1344 + /* if we don't scroll, toprow doesn't move and the characters 1345 + wrap back to the first screen line */ 1346 + swrp->row = (swrp->row + 1) % swrp->opt.maxrow; 1347 + else 1348 + { 1349 + if (swrp->row >= swrp->opt.maxrow-1) 1350 + {Rect scrollrect; 1351 + register int i; 1352 + register char *p; 1353 + 1354 + scrollrect = ((WindowPtr)swrp)->portRect; 1355 + scrollrect.top += _TOPEDGE; 1356 + scrollrect.left += _LEFTEDGE; 1357 + scrollrect.right -= _CONTROLWIDTH+1; 1358 + scrollrect.bottom -= _CONTROLWIDTH+1; 1359 + 1360 + ScrollRect(&scrollrect,0,-swrp->charheight,emptyrgn); 1361 + 1362 + /* toprow points to the new first line */ 1363 + 1364 + swrp->toprow = (swrp->toprow + 1) % swrp->opt.maxrow; 1365 + 1366 + p = swrp->screen + ((swrp->toprow + swrp->opt.maxrow - 1) % swrp->opt.maxrow) * swrp->opt.maxcol - 1; 1367 + 1368 + /* clear the reallocated line in the buffer */ 1369 + 1370 + for (i=swrp->opt.maxcol; i; i--) 1371 + *++p = ' '; 1372 + } 1373 + else 1374 + ++swrp->row; 1375 + } 1376 + 1377 + swrp->col = 0; 1378 + 1379 + movecursor(swrp, 0, swrp->row); 1380 + } 1381 + 1382 + drawcursor(swrp, ON); 1383 + }
+346
sources/printf-2.c
··· 1 + /* 2 + printf routines for LightspeedC� 3 + 4 + (C) Copyright 1985, 1986. THINK Technologies, Inc. All rights reserved. 5 + */ 6 + 7 + #ifndef _stdioh_ 8 + #include "stdio.h" 9 + #endif 10 + 11 + #ifndef _ctypeh_ 12 + #include "ctype.h" 13 + #endif 14 + 15 + #ifndef _MacTypes_ 16 + #include "MacTypes.h" 17 + #endif 18 + 19 + #ifndef _WindowMgr_ 20 + #include "WindowMgr.h" 21 + #endif 22 + 23 + #ifndef _QuickDraw_ 24 + #include "QuickDraw.h" 25 + #endif 26 + 27 + #ifndef _EventMgr_ 28 + #include "EventMgr.h" 29 + #endif 30 + 31 + #ifndef _FontMgr_ 32 + #include "FontMgr.h" 33 + #endif 34 + 35 + extern void (*_echo_to_printer_)(); /* global Echo call variable for printer */ 36 + 37 + GrafPort stdioPort; 38 + static int _tab_width = 4; /* size between tab stops */ 39 + static FontInfo _sf; /* holds the info about the font */ 40 + static int _ch,_cw,_mh,_mw,_sz; /* various info for putch */ 41 + static int _font,_size,_face,_mode;/* stuff for Stdio_Config */ 42 + static RgnHandle emptyrgn; /* used for scrolling */ 43 + 44 + static Boolean _default = true; /* true for default font */ 45 + Boolean _inited = false; /* whether Mac is inited yet */ 46 + static Boolean _screen = false; /* whether screen is inited */ 47 + static Boolean _click_on = true; /* wait at exit from program */ 48 + Boolean _echo = true; /* Echo status for keyboard input */ 49 + 50 + static int row = 1; 51 + static int col = 1; 52 + 53 + 54 + #line 0 Click_On() 55 + void Click_On(flag) 56 + { 57 + _click_on = flag; 58 + } 59 + 60 + #line 0 click_to_continue() 61 + static void click_to_continue() 62 + { 63 + /* if (emptyrgn) DisposeRgn(emptyrgn); - gets blasted on exit anyway */ 64 + 65 + if (_click_on) 66 + { 67 + gotoxy(_mw/2-12,_mh); 68 + cputs("click mouse to continue."); 69 + 70 + while (!Button()); 71 + 72 + /* pdg- 6/10/86 - then wait for release of button */ 73 + 74 + while (Button()); 75 + } 76 + } 77 + 78 + #line 0 Init_stdio() 79 + void Init_stdio() 80 + { 81 + if (_inited && _screen) return; 82 + 83 + if (!_inited) 84 + { 85 + _inited = true; 86 + InitGraf(&thePort); 87 + InitFonts(); 88 + InitWindows(); 89 + InitDialogs(0L); 90 + TEInit(); 91 + } 92 + 93 + if (!_screen) 94 + { 95 + _screen = true; 96 + OpenPort(&stdioPort); 97 + HideCursor(); 98 + EraseRect(&stdioPort.portRect); 99 + 100 + if (_default) 101 + { 102 + _font = monaco; 103 + _size = 9; 104 + _face = 0; 105 + _mode = srcOr; 106 + } 107 + TextFont(_font); 108 + TextSize(_size); 109 + _sz = _size; /* should be the same as above */ 110 + TextFace(_face); 111 + TextMode(_mode); 112 + GetFontInfo(&_sf); 113 + _ch = _sf.ascent+_sf.descent+_sf.leading; 114 + _cw = _sf.widMax; 115 + _mw = (stdioPort.portRect.right)/_cw - 1; /* 13-Feb-86 */ 116 + _mh = (stdioPort.portRect.bottom - 11)/_ch - 1; 117 + 118 + /* set up exit procedure */ 119 + 120 + onexit(click_to_continue); 121 + } 122 + } 123 + 124 + #line 0 Stdio_Config() 125 + void Stdio_Config(font,size,face,mode) 126 + int font,size,face,mode; 127 + { 128 + _font = font; 129 + _size = size; 130 + _face = face; 131 + _mode = mode; 132 + _default = false; 133 + } 134 + 135 + 136 + #line 0 Set_Echo() 137 + void Set_Echo(state) 138 + Boolean state; 139 + { 140 + _echo = state; 141 + } 142 + 143 + /* pdg - 6/10/86 - Stdio_MacInit() allows coexistence of Mac windows and 144 + stdio if called with flag set to true so stdio won't 145 + reinitialize all of the Mac stuff. */ 146 + 147 + #line 0 Stdio_MacInit() 148 + void Stdio_MacInit(flag) 149 + Boolean flag; 150 + { 151 + _inited = flag; 152 + } 153 + 154 + #line 0 cursor_plot 155 + static void cursor_plot(erase_block) 156 + Boolean erase_block; 157 + { 158 + register int v; 159 + Rect rect; 160 + PenState ps; 161 + 162 + static Boolean Cursor_Inited = false; 163 + thePort->pnLoc.v = v = row * _ch - _sf.descent; 164 + 165 + thePort->pnLoc.h = rect.left = col * _cw; 166 + 167 + GetPenState(&ps); 168 + 169 + PenMode(patXor); 170 + 171 + rect.top = v - _sf.ascent; 172 + rect.right = rect.left + _cw; 173 + rect.bottom = v + _sf.descent; 174 + 175 + if (Cursor_Inited == false) 176 + Cursor_Inited = true; 177 + else 178 + if (erase_block) EraseRect(&rect); 179 + else PaintRect(&rect); 180 + 181 + SetPenState(&ps); 182 + } 183 + 184 + 185 + #line 0 Set_Tab 186 + void Set_Tab(len) 187 + int len; 188 + { 189 + _tab_width = 1; 190 + 191 + if (len < 1) _tab_width = len; 192 + } 193 + 194 + #line 0 gotoxy 195 + void gotoxy(x,y) 196 + int x,y; 197 + { 198 + Init_stdio(); 199 + 200 + if ((x<=_mw)&&(y<=_mh)) 201 + { 202 + cursor_plot(false); 203 + col = x+1; 204 + row = y+1; 205 + cursor_plot(false); 206 + } 207 + } 208 + 209 + #line 0 getxpos 210 + int getxpos() 211 + { 212 + return (col-1); 213 + } 214 + 215 + #line 0 getypos 216 + int getypos() 217 + { 218 + return (row-1); 219 + } 220 + 221 + #line 0 putch 222 + void putch(c) 223 + register char c; 224 + { 225 + 226 + Init_stdio(); /* initalize */ 227 + 228 + if (_echo_to_printer_) (*_echo_to_printer_)(c); 229 + 230 + /* wait here if mouse is down */ 231 + 232 + while (Button()); 233 + 234 + if (c<' ') 235 + { 236 + switch(c) 237 + { 238 + 239 + case '\n' : cursor_plot(false); 240 + break; 241 + 242 + case '\t' : cursor_plot(false); 243 + while (((col-1) % _tab_width) || (col-1 == 0)) 244 + { 245 + cursor_plot(true); 246 + col++; 247 + } 248 + break; 249 + 250 + case '\r' : cursor_plot(false); 251 + col = 1; 252 + cursor_plot(false); 253 + return; 254 + 255 + case '\b' : cursor_plot(false); 256 + if (col > 1) col--; 257 + cursor_plot(true); 258 + cursor_plot(false); 259 + return; 260 + 261 + case '\f' : EraseRect(&stdioPort.portRect); 262 + col = 1; 263 + row = 1; 264 + cursor_plot(false); 265 + return; 266 + 267 + case 7 : SysBeep(5); 268 + return; 269 + } 270 + } 271 + if (c != '\t') 272 + { 273 + if (c != '\n') 274 + { /* position and print char */ 275 + 276 + cursor_plot(true); 277 + 278 + DrawChar(c); 279 + } 280 + 281 + if ((++col > _mw) || (c=='\n')) /* need to do a newline? */ 282 + { 283 + if (row > _mh) 284 + { 285 + if (!emptyrgn) emptyrgn=NewRgn(); 286 + 287 + ScrollRect(&stdioPort.portRect,0,-_ch,emptyrgn); 288 + } 289 + else 290 + row++; 291 + 292 + col = 1; 293 + } 294 + } 295 + cursor_plot(false); 296 + } 297 + 298 + /* the following are for compatibility with windowed version: printf-2-w.c */ 299 + 300 + #line 0 StdEvent 301 + Boolean StdEvent(event) 302 + { 303 + return (false); 304 + } 305 + 306 + #line 0 stdwsave 307 + stdwsave() 308 + { 309 + return (0); 310 + } 311 + #line 0 stdwrestore 312 + stdwrestore() 313 + { 314 + return (0); 315 + } 316 + 317 + #line 0 setwindow 318 + setwindow() 319 + { 320 + return (0); 321 + } 322 + 323 + #line 0 fclosew 324 + fclosew() 325 + { 326 + return (0); 327 + } 328 + 329 + /* the following two are not implemented since there is nothing sensible 330 + that they could return in a non-windowed version of printf */ 331 + 332 + #ifdef _NOT_SENSIBLE_ 333 + 334 + #line 0 Get_ScreenPtr 335 + char *Get_ScreenPtr() 336 + { 337 + return (0); 338 + } 339 + 340 + #line 0 Get_WindowPtr 341 + WindowPtr Get_WindowPtr() 342 + { 343 + return (0); 344 + } 345 + 346 + #endif _NOT_SENSIBLE_
+830
sources/printf-3.c
··· 1 + /* 2 + printf formatter for LightspeedC� 3 + 4 + (C) Copyright 1985, 1986. THINK Technologies, Inc. All rights reserved. 5 + 6 + pdg - 6/11/86 - revised 7 + */ 8 + 9 + /* comment this out if you don't need floating point numeric support */ 10 + #define _FORMAT_FP_ 11 + 12 + #ifndef _stdioh_ 13 + #include "stdio.h" 14 + #endif 15 + 16 + #ifndef _MacTypes_ 17 + #include "MacTypes.h" 18 + #endif 19 + 20 + #ifndef _saneh_ 21 + #include "sane.h" 22 + #endif 23 + 24 + #ifndef _setjmph_ 25 + #include "setjmp.h" 26 + #endif 27 + 28 + /* it turns out that defining min, max, and isdigit as follows works pretty 29 + well and drags in less code from other modules */ 30 + #undef min 31 + #undef max 32 + #undef isdigit 33 + 34 + #define min(a,b) ( (a<b) ? (a) : (b) ) 35 + #define max(a,b) ( (a>b) ? (a) : (b) ) 36 + #define isdigit(c) ( (c<='9') && (c>='0') ) 37 + 38 + #define BLANKS 0 39 + 40 + void (*_output)(); /* global pointer to function for output */ 41 + int _num_count; /* number of characters transmitted */ 42 + jmp_buf env; /* global error return mechanism */ 43 + 44 + static char _hex_case; /* used for x X case */ 45 + static char fillchar; /* space or '0' depending on mode */ 46 + static int base; /* global to store base under conversion */ 47 + 48 + #line 0 check_for_three() 49 + static char *check_for_three(ptr,tptr) 50 + char *ptr,*tptr; 51 + { 52 + int l; 53 + 54 + /* if length of exponent is 3 or more then return */ 55 + 56 + if ((l =len_of_str(ptr))>2) return(tptr); 57 + 58 + /* This implementation normally makes the exponent 3 bytes wide */ 59 + 60 + *tptr++ = '0'; /* make default width = 2 */ 61 + 62 + /* if 2 byte default width is desired then comment out the 63 + following line of code */ 64 + 65 + if (l == 1) *tptr++ = '0'; /* make default width = 3 */ 66 + 67 + return(tptr); 68 + } 69 + 70 + #line 0 dumpbuffer() 71 + static void dumpbuffer(tbufptr) /* write buffer to output stream */ 72 + register char *tbufptr; 73 + { 74 + register void (*outputx)() = _output; 75 + 76 + if (*tbufptr == '@') tbufptr++; 77 + 78 + while (*tbufptr) 79 + (*outputx)(*tbufptr++); 80 + 81 + } 82 + 83 + #line 0 dopadding() 84 + static void dopadding(tempbuffer,left_justify,zero_fill,width) 85 + register char *tempbuffer; 86 + register Boolean left_justify,zero_fill; 87 + register int width; 88 + { 89 + register int length; 90 + register void (*outputx)() = _output; 91 + 92 + if ((length = len_of_str(tempbuffer))<width) 93 + { 94 + width -= length; 95 + if (left_justify == false) 96 + { 97 + if ((*tempbuffer == ' ')|| 98 + (((*tempbuffer == '+')||(*tempbuffer == '-'))&&zero_fill) ) 99 + { 100 + (*outputx)(*tempbuffer); 101 + 102 + *tempbuffer = '@'; 103 + } 104 + 105 + while (--width >= 0) 106 + (*outputx)(zero_fill?'0':' '); 107 + 108 + dumpbuffer(tempbuffer); 109 + } 110 + else 111 + { 112 + dumpbuffer(tempbuffer); 113 + 114 + while (--width >= 0) 115 + (*outputx)(' '); 116 + } 117 + } 118 + else /* pdg - 7/23/86 missing else! */ 119 + dumpbuffer(tempbuffer); 120 + } 121 + 122 + /* pdg - 6/10/86 - revise for efficiency */ 123 + 124 + #line 0 len_of_str() 125 + static int len_of_str(s) 126 + register char *s; 127 + { 128 + register char *s0 = s; 129 + 130 + while (*s) s++; 131 + 132 + return(s-s0); 133 + } 134 + 135 + #line 0 padd() 136 + static void padd(zero_fill,count) 137 + Boolean zero_fill; 138 + register int count; 139 + { 140 + while (--count >= 0) 141 + (*_output)(((zero_fill)?'0':' ')); 142 + } 143 + 144 + 145 + #line 0 output_number() 146 + static void output_number(value) 147 + unsigned long value; 148 + { 149 + unsigned long quotient; 150 + register int remainder; 151 + 152 + if ((quotient = value / base) != 0) output_number(quotient); 153 + 154 + remainder = (value % base); 155 + 156 + (*_output)(((remainder<10) ? remainder + '0' : 157 + remainder + _hex_case)); 158 + } 159 + 160 + #line 0 length of number() 161 + static int length_of_number(number) 162 + register unsigned long number; 163 + { 164 + register int places = 1; 165 + 166 + while (number /= base) places++; 167 + 168 + return (places); 169 + } 170 + 171 + #ifdef _FORMAT_FP_ 172 + 173 + char *PtoCstr(); /* need proper typing of return value */ 174 + 175 + #line 0 cvtf2string() 176 + static char *cvtf2string(doublep, style, digits, floatbufferp) 177 + double *doublep; 178 + char style; 179 + short digits; 180 + char *floatbufferp; 181 + { 182 + DecForm _decform_; /* information record for conversion */ 183 + Decimal _decimal_; /* intermediate record */ 184 + 185 + /* convert binary to decimal record */ 186 + 187 + _decform_.style = style; 188 + _decform_.digits = digits; 189 + 190 + fp68k(&_decform_, doublep, &_decimal_, FFEXT+FOB2D); 191 + 192 + /* decimal record to string */ 193 + 194 + _decform_.style= style; 195 + _decform_.digits = digits; 196 + 197 + Dec2Str(_decform_, &_decimal_, floatbufferp); 198 + 199 + /* convert to C string from Pascal string used by SANE */ 200 + 201 + return (PtoCstr(floatbufferp)); 202 + } 203 + 204 + #endif _FORMAT_FP_ 205 + 206 + 207 + #line 0 _format() 208 + /*---------------------------------------------------------------------------- 209 + "_format" is the internal routine to do the conversion process. This routine 210 + is passed a pointer to the pointer to the format string. By scanning the 211 + format string until a format code is encountered, information can be extrac- 212 + ted to determine the what argument was present on the stack and processing 213 + can be handled. Note that the following stack layout applies after the call 214 + to _format (standard C calling conventions): 215 + 216 + HI memory 217 + |---------------------| 218 + | last argument | last argument for format 219 + |---------------------| 220 + . 221 + . 222 + |---------------------| 223 + |--->---| first argument | points to format string 224 + | |---------------------| 225 + | | return address | 226 + | |---------------------| 227 + |---<---| argument to _format | points to pointer to format 228 + |---------------------| 229 + | return address | 230 + |---------------------| 231 + LO memory 232 + 233 + The _format routine sets "format" to point to the format string and scans 234 + over it. By incrementing the parameter "ptr" (passed to _format) the 235 + first argument for substitution in the format string can be accessed. 236 + How the arguments are interpreted is derived from the format string. 237 + A pointer to a function "*_output" is used to stuff processed characters 238 + to their destination. 239 + 240 + -----------------------------------------------------------------------------*/ 241 + int _format(fmt,var_stuff) 242 + char **fmt; /* pointer to pointer to format string */ 243 + Boolean var_stuff; 244 + { 245 + Boolean left_justify; /* flag to indicate left justiccation */ 246 + Boolean do_precision; /* flag limited precision */ 247 + Boolean its_a_long; /* flag to indicate long integer */ 248 + Boolean zero_fill; /* flag to indicate padding with zero */ 249 + Boolean sign_on; /* flag to indicate '+' */ 250 + Boolean space_on; /* flag to indicate ' ' */ 251 + Boolean pound_on; /* flag to indicate '#' */ 252 + Boolean neg; /* flag to indicate a negative number */ 253 + 254 + register char *format; /* pointer to format string */ 255 + register char *argument; /* pointer to arguments for fmt string */ 256 + 257 + #ifdef _FORMAT_FP 258 + #define outputx _output 259 + #else 260 + register void (*outputx)() = _output; 261 + #endif 262 + 263 + register char c; /* current character under inspection */ 264 + unsigned long value; /* for conversion of numerics */ 265 + register int length; /* length of argument to be inserted */ 266 + register int width; /* field width as specified by format */ 267 + register int numleft; /* # of characters left to print */ 268 + register int precision; /* precision of number to be converted */ 269 + 270 + #ifdef _FORMAT_FP_ 271 + 272 + /* floating point junk */ 273 + double tempdouble; 274 + char floatbuffer[256]; 275 + char tempbuffer[256]; 276 + register char *bufptr; 277 + register char *tbufptr; 278 + 279 + #endif _FORMAT_FP_ 280 + 281 + /* set up the direct error return to caller */ 282 + 283 + if (setjmp(env)) return (EOF); 284 + 285 + _num_count = 0; /* set # characters transmitted to zero */ 286 + 287 + format = *fmt++; /* set "format" to the format string */ 288 + /* "fmt" is left pointing to first argument */ 289 + argument = (char *) fmt; /* set "argument" to point to first argument */ 290 + 291 + /* if variable, indirect through first argument to find real arg list */ 292 + 293 + if (var_stuff) argument = (char *)(*(long *)argument); 294 + 295 + while (c = *format++) /* scan format string until NULL */ 296 + { 297 + if (c == '%') 298 + { 299 + left_justify = false; 300 + zero_fill = false; 301 + sign_on = false; 302 + space_on = false; 303 + pound_on = false; 304 + neg = false; 305 + flagloop: 306 + switch(c = *format++) 307 + { 308 + case '-': left_justify = true; 309 + zero_fill = false; 310 + goto flagloop; 311 + 312 + case '0': zero_fill = (!left_justify); 313 + goto flagloop; 314 + 315 + case '+': sign_on = true; 316 + space_on = false; 317 + goto flagloop; 318 + 319 + case ' ': space_on = (!sign_on); 320 + goto flagloop; 321 + 322 + case '#': pound_on = true; 323 + goto flagloop; 324 + 325 + case '*': numleft = width = *(int *)argument; 326 + argument += sizeof(int); 327 + goto getdot; 328 + 329 + default: format--; /* need to back up if unrecognized */ 330 + break; 331 + } 332 + 333 + 334 + /* compute total field width */ 335 + 336 + {char *tempformat = format; /* let format be register */ 337 + 338 + numleft = width = (isdigit(*format)) ? _std_decode(&tempformat) : 0; 339 + format = tempformat; 340 + } 341 + 342 + getdot: 343 + /* compute precision within total field width */ 344 + 345 + precision = 0; 346 + 347 + if (do_precision = (*format == '.')) 348 + { 349 + if (*++format == '*') 350 + { 351 + precision = *(int *)argument; 352 + argument += sizeof(int); 353 + format++; 354 + } 355 + else 356 + {char *tempformat = format; /* let format be register */ 357 + 358 + precision = _std_decode(&tempformat); 359 + format = tempformat; 360 + } 361 + } 362 + 363 + if (*format == '%') 364 + { 365 + if (left_justify) 366 + { 367 + (*outputx)('%'); 368 + padd(BLANKS,width-1); 369 + } 370 + else 371 + { 372 + padd(zero_fill,width-1); 373 + (*outputx)('%'); 374 + } 375 + format++; 376 + continue; 377 + } 378 + 379 + /* check if long integer is required */ 380 + 381 + if (its_a_long = ((c = (*format++)) == 'l')) 382 + c = *format++; 383 + 384 + /* check for short %h.. */ 385 + 386 + if (c == 'h') c = *format++; 387 + 388 + /* note that "format" is left ready for the next pass */ 389 + switch (c) 390 + { 391 + 392 + case 'd': 393 + {register long svaluel; /* for conversion of signed long */ 394 + register int svaluei; /* for conversion of signed int */ 395 + 396 + if (its_a_long) 397 + { 398 + svaluel = *(long *)argument; 399 + argument += sizeof(long); 400 + 401 + value = (unsigned long)svaluel; 402 + 403 + if (svaluel < 0) goto negate; 404 + } 405 + else 406 + { 407 + svaluei = *(int *)argument; 408 + argument += sizeof(int); 409 + 410 + value = (unsigned long)svaluei; 411 + 412 + if (svaluei < 0) 413 + { 414 + negate: neg = true; 415 + value = -value; 416 + } 417 + } 418 + 419 + /* fall into case 'u' */ 420 + } 421 + 422 + case 'u': 423 + base = 10; 424 + goto evaluate; 425 + 426 + case 'o': 427 + base = 8; 428 + goto evaluate; 429 + 430 + case 'x': _hex_case = 'a'-10; 431 + goto sethex; 432 + case 'X': 433 + _hex_case = 'A'-10; 434 + sethex: 435 + base = 16; 436 + evaluate: 437 + /* get the target value in a long, 438 + readjust the argument pointer */ 439 + 440 + if (c != 'd') 441 + { 442 + if (its_a_long) 443 + { 444 + value = *(unsigned long *)argument; 445 + argument += sizeof (unsigned long); 446 + } 447 + else 448 + { 449 + value = *(unsigned *)argument; 450 + argument += sizeof (unsigned); 451 + } 452 + } 453 + 454 + /* get the length of the output string */ 455 + 456 + length = length_of_number(value); 457 + 458 + /* now figure out the positioning */ 459 + 460 + if (zero_fill) 461 + { 462 + if (((neg)||(sign_on)|| 463 + (space_on)) && (c =='d')) 464 + { 465 + if (neg) 466 + { 467 + (*outputx)('-'); 468 + } 469 + else 470 + (*outputx)((sign_on ? '+' : ' ')); 471 + 472 + numleft--; /* room for sign */ 473 + } 474 + 475 + if (((c=='o')||(c == 'X')||(c == 'x'))&&(pound_on)) 476 + { 477 + (*outputx)('0'); 478 + numleft--; 479 + 480 + if (c == 'X') { (*outputx)('X');numleft--; } 481 + if (c == 'x') { (*outputx)('x');numleft--; } 482 + } 483 + 484 + padd(zero_fill, numleft - max(length,precision)); 485 + 486 + if (precision > length) 487 + padd(zero_fill,precision-length); 488 + 489 + output_number(value); 490 + 491 + } 492 + 493 + if (left_justify) 494 + { 495 + if (c =='d') 496 + { 497 + if (neg) 498 + { 499 + (*outputx)('-'); 500 + numleft--; 501 + } 502 + else 503 + if((sign_on)||(space_on)) 504 + { 505 + (*outputx)((sign_on ? '+' : ' ')); 506 + 507 + numleft--; 508 + } 509 + } 510 + 511 + if (((c=='o')||(c == 'X')||(c == 'x'))&&(pound_on)) 512 + { 513 + (*outputx)('0'); 514 + 515 + numleft--; 516 + 517 + if (c == 'X') { (*outputx)('X');numleft--; } 518 + if (c == 'x') { (*outputx)('x');numleft--; } 519 + } 520 + 521 + padd(true,precision-length); 522 + 523 + if(precision-length>0) numleft -= (precision-length); 524 + 525 + output_number(value); 526 + 527 + numleft -= length; 528 + 529 + padd(BLANKS, numleft); 530 + 531 + } 532 + 533 + if ((!zero_fill)&&(!left_justify)) 534 + { 535 + if (((neg)||(space_on)|| 536 + (sign_on)) && (c == 'd')) 537 + { 538 + padd(zero_fill, width - max(length,precision)-1); 539 + 540 + if (neg) 541 + { 542 + (*outputx)('-'); 543 + } 544 + else 545 + (*outputx)(((sign_on)?'+':' ')); 546 + 547 + padd(true,precision-length); 548 + 549 + output_number(value); 550 + 551 + } /* normal decimal output with sign */ 552 + else 553 + if ((pound_on)&&((c == 'o')||(c == 'X')||(c == 'x'))) 554 + { 555 + numleft = 2; 556 + if ( c == 'o') numleft = 1; 557 + padd(zero_fill, width - max(length,precision)-numleft); 558 + 559 + (*outputx)('0'); 560 + 561 + if (c == 'X') (*outputx)('X'); 562 + if (c == 'x') (*outputx)('x'); 563 + 564 + padd(true,precision-length); 565 + 566 + output_number(value); 567 + } 568 + else 569 + { 570 + padd(zero_fill, width - max(precision,length)); 571 + padd(!zero_fill,precision-length); 572 + output_number(value); 573 + } 574 + } /* ((!zero_fill)&&(!left_justify)) */ 575 + break; 576 + 577 + case 'c': 578 + /* get the character and readjust the pointer 579 + note that a char on the stack is expanded to int */ 580 + 581 + if (left_justify) 582 + { 583 + (*outputx)(*(int *) argument); 584 + padd(BLANKS, width - 1); 585 + } 586 + else 587 + { 588 + padd(zero_fill, width - 1); 589 + (*outputx)(*(int *) argument); 590 + } 591 + argument += sizeof (int); 592 + break; 593 + 594 + case 's': 595 + {register char *char_ptr; 596 + 597 + /* get the length of the string */ 598 + 599 + length = len_of_str(char_ptr = *((char **) argument)); 600 + argument += sizeof(char_ptr); 601 + 602 + /* check for truncation */ 603 + if (do_precision) 604 + if (length > precision) length = precision; 605 + 606 + /* set width to padding width */ 607 + if ((width -= length) < 0) width = 0; 608 + 609 + if (left_justify) 610 + { 611 + while (--length >= 0) 612 + (*outputx)(*char_ptr++); 613 + 614 + padd(BLANKS, width); 615 + } 616 + else 617 + { 618 + padd(zero_fill, width); 619 + while (--length >= 0) 620 + (*outputx)(*char_ptr++); 621 + } 622 + break; 623 + } 624 + 625 + #ifdef _FORMAT_FP_ 626 + 627 + case 'f': 628 + tempdouble = *((double *)argument); /* consume argument */ 629 + argument += sizeof(double); 630 + 631 + 632 + /* default precision is 6 */ 633 + if (do_precision == false) precision = 6; 634 + regf: 635 + bufptr = cvtf2string(&tempdouble, 1, precision, floatbuffer); 636 + nregf: 637 + tbufptr = tempbuffer; 638 + 639 + if ((tempdouble >= 0)&&((space_on)|| 640 + (sign_on))) 641 + *tbufptr++ = (sign_on ? '+' : ' '); 642 + 643 + while(c = *(bufptr++)) 644 + *tbufptr++ = c; 645 + 646 + if ((pound_on)&&(precision == 0)) 647 + *tbufptr++ = '.'; 648 + 649 + *tbufptr = '\0'; 650 + 651 + dopadding(tempbuffer,left_justify,zero_fill,width); 652 + 653 + break; 654 + 655 + case 'e': 656 + case 'E': 657 + tempdouble = *((double *)argument); /* consume argument */ 658 + argument += sizeof(double); 659 + 660 + /* default precision is 6 */ 661 + if (do_precision == false) precision = 6; 662 + 663 + bufptr = cvtf2string(&tempdouble, 0, precision+1, floatbuffer); 664 + 665 + rege: 666 + tbufptr = tempbuffer; 667 + 668 + if ((tempdouble >= 0)&&(sign_on)) /* if + then make prefix */ 669 + *bufptr = '+'; 670 + 671 + if ((space_on == false)&&(*bufptr == ' ')) 672 + bufptr++; /* if leading space and no flag fix it */ 673 + 674 + while(*(bufptr)) 675 + { 676 + if (*bufptr == 'e') /* is this the e char? */ 677 + { 678 + neg = true; 679 + *bufptr = c; /* convert if if necessary */ 680 + if ((pound_on)&&(precision == 0)) 681 + *tbufptr++ = '.'; 682 + } 683 + if ((*(bufptr-2) == c)&&(neg)) /* should we pad the exp */ 684 + tbufptr = check_for_three(bufptr,tbufptr); 685 + if (*bufptr != '@') 686 + *tbufptr++ = *bufptr++; 687 + } 688 + *tbufptr = '\0'; 689 + 690 + dopadding(tempbuffer,left_justify,zero_fill,width); 691 + 692 + break; 693 + 694 + case 'g': 695 + case 'G': 696 + tempdouble = *((double *)argument); /* consume argument */ 697 + argument += sizeof(double); 698 + 699 + if (precision < 1) precision = 1; 700 + 701 + if (do_precision == false) precision = 6; 702 + 703 + 704 + /* convert to e form */ 705 + 706 + bufptr = cvtf2string(&tempdouble, 0, precision, floatbuffer); 707 + 708 + /* look at char after 'e' */ 709 + 710 + while (*bufptr++ != 'e') 711 + ; 712 + neg = (*bufptr++ == '-'); /* is it a negative exponent */ 713 + tbufptr = bufptr; 714 + 715 + /* get size of exponent */ 716 + 717 + length = _std_decode(&tbufptr); 718 + if (neg) length *= -1; 719 + 720 + if (pound_on) /* if # flag is on and ... */ 721 + { 722 + if ((length<=precision)&&(length>=-4)) 723 + goto regf; /* do regular f routine */ 724 + else 725 + { 726 + /* this gives precision-1 digits after 727 + . instead of precision */ 728 + 729 + bufptr = (char *)floatbuffer; 730 + c -= 2; 731 + goto rege; /* do regular e routine */ 732 + } 733 + } 734 + 735 + 736 + if ((length<=precision)&&(length>=-4)) 737 + {register Boolean strip_it = false; 738 + 739 + /* convert to f format */ 740 + 741 + bufptr = cvtf2string(&tempdouble, 1, precision-length, floatbuffer); 742 + 743 + /* don't strip string unless therre is a . */ 744 + while (*bufptr) 745 + { 746 + strip_it = strip_it?true:(*bufptr == '.'); 747 + bufptr++; 748 + } 749 + bufptr -= 1; /* was 2 */ 750 + 751 + /* strip trailing zeros */ 752 + if (strip_it) 753 + { 754 + while (*bufptr == '0') bufptr--; 755 + if (*bufptr == '.') bufptr--; 756 + *(++bufptr) = '\0'; 757 + } 758 + 759 + bufptr = (char *)floatbuffer; 760 + 761 + /* now test for \0 or -\0 and adjust */ 762 + if ((*bufptr == '\0') || 763 + ((*bufptr=='-')&&(*(bufptr+1)=='\0'))) 764 + { 765 + *bufptr = '0'; 766 + *(bufptr+1) = '\0'; 767 + } 768 + 769 + goto nregf; 770 + 771 + break; 772 + } 773 + 774 + 775 + /* back up before the e and strip trailing zeros */ 776 + 777 + bufptr -= 3; 778 + 779 + while ((*bufptr == '0')||(*bufptr == '.')) 780 + *(bufptr--) = '@'; 781 + 782 + /* bufptr = (char *)floatbuffer; 783 + c -= 2; / convert form g to e, G to E / 784 + goto rege; 785 + */ 786 + 787 + if ((space_on == false)&&(floatbuffer[0] == ' ')) 788 + floatbuffer[0] = '@'; 789 + 790 + if ((tempdouble>=0) && (sign_on)) floatbuffer[0] = '+'; 791 + 792 + tbufptr = (char *)tempbuffer; 793 + bufptr = (char *)floatbuffer; 794 + 795 + while (*bufptr != 'e') 796 + if (*bufptr != '@') 797 + *tbufptr++ = *bufptr++; 798 + else 799 + bufptr++; 800 + 801 + *bufptr = c-2; /* convert G to E, g to e */ 802 + *tbufptr++ = *bufptr++; 803 + *tbufptr++ = *bufptr++; 804 + tbufptr = check_for_three(bufptr,tbufptr); 805 + while (*bufptr) 806 + *tbufptr++ = *bufptr++; 807 + *tbufptr = '\0'; 808 + dopadding(tempbuffer,left_justify,zero_fill,width); 809 + 810 + break; 811 + #endif _FORMAT_FP_ 812 + 813 + default: 814 + /* input garbled, bark: arf arf */ 815 + return (EOF); 816 + 817 + } /* end of switch */ 818 + } /* end of if */ 819 + else 820 + /* copy it directly to output */ 821 + 822 + (*outputx)(c); 823 + 824 + } /* end of while */ 825 + 826 + return(_num_count); 827 + 828 + (void) std_ver(); 829 + 830 + }
+77
sources/printf-4.c
··· 1 + /* 2 + printf routines for LightspeedC� 3 + 4 + (C) Copyright 1986. THINK Technologies, Inc. All rights reserved. 5 + 6 + allows echoing the output of console window to printer 7 + 8 + */ 9 + 10 + #ifndef _stdioh_ 11 + #include "stdio.h" 12 + #endif 13 + 14 + #ifndef _MacTypes_ 15 + #include "MacTypes.h" 16 + #endif 17 + 18 + 19 + /* some less than famous Mac globals */ 20 + 21 + #define SPPrint (*((char*) 0x207)) 22 + #define PortBUse (*((char*) 0x291)) 23 + 24 + void (*_echo_to_printer_)() = 0; /* global Echo call variable for printer */ 25 + 26 + static FILE *printfile; 27 + 28 + static void send_printer(c) 29 + char c; 30 + { 31 + fputc(c, printfile); 32 + } 33 + 34 + int Echo_to_Printer(wantecho) 35 + Boolean wantecho; 36 + { 37 + register char *p; 38 + 39 + /* printer mode may already be set up to be what they want */ 40 + 41 + if (_echo_to_printer_ && wantecho) return (0); 42 + 43 + if (wantecho) 44 + { 45 + /* activate printer copying from console */ 46 + 47 + /* if printer port number is non-zero, port A is implied */ 48 + 49 + if (SPPrint) p = ".AOut"; 50 + else 51 + /* well, check to see if port B is in use by AppleTalk, 52 + indicated by a greater than zero value */ 53 + 54 + if (PortBUse < 0) p = ".BOut"; 55 + else 56 + /* ran out of ports to check */ 57 + return (EOF); 58 + 59 + /* set to binary mode if we are opening a device driver, 60 + so output directed to a printer gets proper linefeeds */ 61 + 62 + if (!(printfile = fopen(p, "wb"))) return (EOF); 63 + 64 + _echo_to_printer_ = send_printer; 65 + } 66 + else 67 + { 68 + /* deactivate printer copying from console */ 69 + 70 + _echo_to_printer_ = 0; 71 + 72 + fclose(printfile); 73 + } 74 + 75 + return (0); 76 + } 77 +
+351
sources/profile.c
··· 1 + /* 2 + 3 + Profile and tracing package for LightspeedC�. 4 + 5 + (C) Copyright 1986 THINK Technologies, Inc. All rights reserved. 6 + 7 + */ 8 + 9 + 10 + #include "stdio.h" 11 + 12 + 13 + typedef unsigned char Bool; /* for size */ 14 + enum{false,true}; 15 + 16 + typedef void (*address)(); /* address type */ 17 + typedef unsigned char byte; 18 + typedef unsigned long time; 19 + 20 + typedef struct { 21 + char *name; /* function name */ 22 + time average; /* average time */ 23 + time maximum; /* largest time */ 24 + time minimum; /* smallest time */ 25 + time total; /* total time */ 26 + unsigned int entries; /* times entered */ 27 + } PROFILE; 28 + 29 + typedef struct { 30 + address user; /* user return address */ 31 + int function; /* index into profiles */ 32 + time correction; /* nested call time */ 33 + time start; /* entry time */ 34 + } STACK; 35 + 36 + #define LOCAL static /* local to profiler */ 37 + #define MAX_PROFILES 200 /* routines to follow */ 38 + #define MAX_STACK 200 /* max nested calls */ 39 + #define MAX_TIME 500000L /* max time */ 40 + 41 + 42 + /* 43 + 44 + Select execution/compilation options. 45 + 46 + SINGLE - each routine contains only its time 47 + TESTING - test profile package without LightspeedC PROFILE option 48 + 49 + */ 50 + 51 + #define SINGLE /* single routine only */ 52 + /* #define TESTING standalone testing */ 53 + 54 + 55 + #ifdef TESTING 56 + #undef LOCAL /* make items visible */ 57 + #define LOCAL 58 + #endif 59 + 60 + 61 + 62 + LOCAL int depth = -1; 63 + LOCAL PROFILE profiles[MAX_PROFILES]; 64 + LOCAL int profile_count = 0; 65 + LOCAL STACK stack[MAX_STACK]; 66 + LOCAL int stack_pointer = -1; 67 + LOCAL time start_time; 68 + 69 + int _profile = 1; 70 + int _trace = 0; 71 + 72 + void DumpProfile(); 73 + extern _profile_exit_(); 74 + extern char *CtoPstr(); 75 + extern char *PtoCstr(); 76 + 77 + #define _VIATIMER_ /* if this symbol is defined, the VIA timer now is used 78 + instead of TickCount -- it provides faster ticks, 79 + however there is a false precision to the numbers 80 + and there is a range of + or - 500 ticks since 81 + the VIAtimer is so fast that interrupts and such 82 + play a more significant time role. 83 + 84 + NOTE THAT THIS PROFILE OPTION CANNOT BE USED WITH 85 + ANY PROGRAM THAT MANIPULATES THE #1 VIA timer */ 86 + 87 + 88 + #ifdef _VIATIMER_ 89 + 90 + /* TickCount() - redefine TickCount trap to be a procedure for determining 91 + the timing according to the VIA timer */ 92 + 93 + #define VIAbase (*((unsigned char**)0x01D4)) 94 + #define VIAt1lo (*(VIAbase+512*4)) 95 + #define VIAt1hi (*(VIAbase+512*5)) 96 + #define VIAmaxtime ~0 97 + 98 + time TickCount() 99 + { 100 + static time timer=0; 101 + 102 + if (timer > 0) 103 + { 104 + /* Use VIA timer #1 (sound driver) and to implement a fine 105 + resolution counter */ 106 + 107 + /* Find delta of VIA #1 */ 108 + 109 + timer += VIAmaxtime - (((unsigned short)VIAt1hi<<8)+VIAt1lo); 110 + } 111 + else 112 + timer = 1; 113 + 114 + /* Reset VIA counter */ 115 + 116 + VIAt1hi = VIAmaxtime; 117 + VIAt1lo = VIAmaxtime; 118 + 119 + return (timer); 120 + } 121 + 122 + #endif _VIATIMER_ 123 + 124 + 125 + /* 126 + 127 + Compare two Pascal strings for equality. 128 + 129 + */ 130 + 131 + LOCAL Bool pstreq( s1, s2 ) 132 + register unsigned char *s1, *s2; 133 + { 134 + register int n = *s1; 135 + 136 + if ((n = *s1++) != *s2++) 137 + return( false ); 138 + while (n-- > 0) 139 + if (*s1++ != *s2++) 140 + return( false ); 141 + return( true ); 142 + } 143 + 144 + 145 + /* 146 + 147 + Return the time difference caused by the overhead of function entry and 148 + timer call. 149 + 150 + */ 151 + 152 + LOCAL time delta( original ) 153 + time original; 154 + { 155 + return( (time) TickCount() - original ); 156 + } 157 + 158 + 159 + /* 160 + 161 + Lookup a name in the active profile table. For this system, "names" are 162 + the address of the routine. If the name is found in the table, then the 163 + index to the table entry is returned. If the name is not found and the 164 + insert flag is on, then the item is inserted, and the new table index 165 + is returned (if insert is false, then -1 is returned). If the profile 166 + table is full, then -1 is returned. 167 + 168 + */ 169 + 170 + LOCAL int lookup( name, insert ) 171 + char *name; 172 + Bool insert; 173 + { 174 + register int i; 175 + 176 + for (i = 0; i < profile_count; i++) 177 + if (pstreq( profiles[i].name, name )) 178 + return( i ); 179 + if ( insert && profile_count < MAX_PROFILES) 180 + { /* place in table - i points to correct entry */ 181 + if (++profile_count == 1) 182 + { /* first time in */ 183 + start_time = (time) TickCount(); 184 + onexit( DumpProfile ); 185 + } 186 + profiles[i].name = name; 187 + profiles[i].minimum = MAX_TIME; 188 + profiles[i].maximum = 189 + profiles[i].total = NULL; 190 + profiles[i].entries = 0; 191 + return( i ); 192 + } 193 + return( -1 ); 194 + } 195 + 196 + 197 + /* 198 + 199 + Skip over to column 32 from position 'n'. 200 + 201 + */ 202 + 203 + LOCAL void Skip( n ) 204 + register int n; 205 + { 206 + for (; n < 32; n++) 207 + putchar( ' ' ); 208 + } 209 + 210 + 211 + /* 212 + 213 + Print the profile table on demand. Output is written to stdout and may 214 + be redirected with the Unix '>' mechanism to a file. The user should 215 + call this routine whenever a report is desired. Each time the routine is 216 + called, the program opens the map file which corresponds to the program 217 + running. The name of the map file is built by appending ".map" to the name 218 + of the running program. If the map file cannot be found then the routine 219 + returns. 220 + 221 + */ 222 + 223 + void DumpProfile() 224 + { 225 + int j, k; /* generic loop variables */ 226 + register int i; /* primary loop variable */ 227 + register time duration = 0L; /* time in test regions */ 228 + 229 + _profile = 0; /* turn off profiling here */ 230 + 231 + for (i = 0; i < profile_count; i++) 232 + duration += profiles[i].total; /* compute total time */ 233 + 234 + printf( "\n\n" ); 235 + printf( "\t\t\t\tRoutine Profiles\n\n" ); 236 + printf( "Routine Address" ); 237 + Skip( 15 ); 238 + printf( " Minimum Maximum Average %% Entries\n" ); 239 + 240 + if (duration <= 0.0) 241 + duration++; 242 + 243 + for (i = 0; i < profile_count; i++) 244 + { /* for all entries in the profile table */ 245 + if (profiles[i].minimum == MAX_TIME) 246 + continue; /* routine entry, no exit */ 247 + printf( "%s", PtoCstr( profiles[i].name ) ); 248 + CtoPstr( profiles[i].name ); 249 + Skip( profiles[i].name[0] ); 250 + printf( "%9lu %9lu %9lu %3.0f %7u\n", 251 + profiles[i].minimum, profiles[i].maximum, 252 + profiles[i].average, 253 + ((float) profiles[i].total * 100.0) / (float) duration + 0.05, 254 + profiles[i].entries ); 255 + } 256 + 257 + _profile = 1; /* re-enable profiling */ 258 + } 259 + 260 + 261 + /* 262 + 263 + Called by assembler exit routine. Compute usage statistics for routine on 264 + top of profiling stack. 265 + 266 + */ 267 + 268 + address __profile_exit() 269 + { 270 + int i; 271 + time exit_time = (time) TickCount(); 272 + 273 + depth--; 274 + /* end timing for a function */ 275 + 276 + i = stack[stack_pointer].function; 277 + #ifdef SINGLE 278 + exit_time = exit_time - delta( exit_time ) - 279 + stack[stack_pointer].start - stack[stack_pointer--].correction; 280 + if (exit_time > 0x7FFFFFFF) 281 + exit_time = 0L; /* handle clock rollover */ 282 + profiles[i].total += exit_time; 283 + if (stack_pointer >= 0) 284 + stack[stack_pointer].correction += exit_time + stack[stack_pointer + 1].correction; 285 + #else 286 + exit_time = exit_time - delta( exit_time ) - stack[stack_pointer--].start; 287 + if (exit_time > 0x7FFFFFFF) 288 + exit_time = 0L; /* handle clock rollover */ 289 + profiles[i].total += exit_time; 290 + #endif 291 + if (exit_time > profiles[i].maximum) 292 + profiles[i].maximum = exit_time; 293 + if (exit_time < profiles[i].minimum) 294 + profiles[i].minimum = exit_time; 295 + if (profiles[i].entries) 296 + profiles[i].average = profiles[i].total / profiles[i].entries; 297 + return( stack[stack_pointer + 1].user ); 298 + } 299 + 300 + 301 + /* 302 + 303 + Handle the routine entry profiling. Setup a stack frame and a profile 304 + table entry if needed. 305 + 306 + */ 307 + 308 + void __profile( unused, ret, name ) 309 + unsigned long *ret; 310 + address unused; 311 + char *name; 312 + { 313 + register int function, /* index of routine */ 314 + i; 315 + register time entry_time = (time) TickCount(); 316 + 317 + depth++; 318 + if (_trace) 319 + { 320 + _profile = 0; 321 + for (i = 0; i < depth; i++) 322 + putchar( ' ' ); 323 + printf( "%s\n", PtoCstr( name ) ); 324 + CtoPstr( name ); 325 + _profile = 1; 326 + } 327 + if (++stack_pointer < MAX_STACK) 328 + { /* setup for return to PROFILE_EXIT on user exit */ 329 + stack[stack_pointer].user = (address) *ret; 330 + *ret = (unsigned long) _profile_exit_; 331 + stack[stack_pointer].correction = NULL; 332 + } 333 + else 334 + { 335 + depth--; 336 + return; 337 + } 338 + 339 + if ((function = lookup( name, true )) >= 0) 340 + { /* process function entry */ 341 + profiles[function].entries++; 342 + stack[stack_pointer].function = function; 343 + entry_time = TickCount(); 344 + stack[stack_pointer].start = entry_time - delta( entry_time ); 345 + } 346 + else 347 + { /* remove entry from stack */ 348 + *ret = (unsigned long) stack[stack_pointer--].user; 349 + depth--; 350 + } 351 + }
+49
sources/profilehooks.c
··· 1 + /* 2 + 3 + Profile and tracing package for LightspeedC�. 4 + 5 + (C) Copyright 1986 THINK Technologies, Inc. All rights reserved. 6 + 7 + */ 8 + 9 + extern void __profile(); 10 + extern void __profile_exit(); 11 + 12 + /* 13 + ; 14 + ; Entry point for profiler. Add another parameter to the stack which is 15 + ; a pointer to the return address of the caller of this function. 16 + ; 17 + */ 18 + _profile_() 19 + { 20 + 21 + asm 22 + { 23 + move.l (a7)+,d0 ; get current return address 24 + pea 4(a6) ; push pointer to return address 25 + move.l d0,-(a7) ; push back the return address 26 + jsr __profile ; call the C profiler 27 + move.l (a7)+,d0 ; get return address 28 + move.l d0,(a7) ; write on top of stack and return 29 + } 30 + } 31 + 32 + /* 33 + ; 34 + ; Exit point for profiler. This calls the end of function timing routine 35 + ; and returns to the user. 36 + ; 37 + */ 38 + 39 + _profile_exit_() 40 + { 41 + asm 42 + { 43 + move.l d0, -(a7) ; save old function result 44 + jsr __profile_exit ; call end of routine timer 45 + move.l d0, a0 ; save return address in A0 46 + move.l (a7)+, d0 ; retrieve old function result 47 + jmp (a0) ; then return 48 + } 49 + }
+277
sources/proto.h
··· 1 + /* LightspeedC function prototype header file. 2 + 3 + Copyright (c)1986. THINK Technologies, Inc. All rights reserved. 4 + 5 + 6 + This file contains the function prototypes for all (hopefully) of the 7 + published LightspeedC library functions. It can be dissected into 8 + whatever pieces are desired or it can simply be included (at some extra 9 + cost in time to compile and symbol table overhead). 10 + 11 + Since the original header files have not been modified, they can still be 12 + included in conjunction with this prototype header, if desired. That 13 + means that you could still include "math.h" for its definition of PI and 14 + such and follow that with an include of this file. 15 + 16 + The prototypes are presented here in no particular order, however, they are 17 + grouped by originating library. 18 + 19 + */ 20 + 21 + #ifndef _fopenwh_ 22 + #include "fopenw.h" 23 + #endif 24 + 25 + #ifndef _EventMgr_ 26 + #include "EventMgr.h" 27 + #endif 28 + 29 + 30 + /* math.h */ 31 + 32 + int abs(int x); 33 + double acos(double x); 34 + double asin(double x); 35 + double atan(double x); 36 + double atan2(double y, double x); 37 + double ceil(double x); 38 + double cos(double x); 39 + double cosh(double x); 40 + double exp(double x); 41 + double fabs(double x); 42 + double floor(double x); 43 + double fmod(double x, double y); 44 + double frexp(double x, int *nptr); 45 + long int labs(long int x); 46 + double ldexp(double x, int n); 47 + double log(double x); 48 + double log10(double x); 49 + double modf(double x,int *nptr); 50 + double pow(double x, double y); 51 + int rand(void); 52 + double sin(double x); 53 + double sinh(double x); 54 + double sqrt(double x); 55 + void srand(unsigned int seed); 56 + double tan(double x); 57 + double tanh(double x); 58 + 59 + /* strings.h */ 60 + 61 + int stccpy(char *s1, char *s2, int n); 62 + int stcis(char *s, char *set); 63 + int stcisn(char *s1, char *set); 64 + int stclen(char *s); 65 + char *stpblk(char *p); 66 + char *stpbrk(char *s, char *set); 67 + char *stpchr(char *s, char c); 68 + char *stpcpy(char *s1, char *s2); 69 + char *strcat(char *s1, char *s2); 70 + char *strchr(char *s, char c); 71 + int strcmp(char *s1, char *s2); 72 + char *strcpy(char *s1, char *s2); 73 + int strcspn(char *s, char *set); 74 + int strlen(char *s); 75 + char *strncat(char *s1, char *s2, int n); 76 + int strncmp(char *s1, char *s2, int n); 77 + char *strncpy(char *s1, char *s2, int n); 78 + char *strpbrk(char *s, char *set); 79 + int strpos(char *s, char c); 80 + char *strrchr(char *s, char c); 81 + char *strrpbrk(char *s, char *set); 82 + int strrpos(char *s, char c); 83 + int strspn(char *s, char *set); 84 + int stscmp(char *s1, char *s2); 85 + 86 + /* unix_strings.h */ 87 + 88 + int stcarg(char *s, char *b); 89 + int stcpm(char *s, char *p, char **q); 90 + int stcpma(char *string, char *pattern); 91 + char *stpsym(char *s, char *sym, int symlen); 92 + char *stptok(char *s, char *tok, int toklen, char *brk); 93 + 94 + /* storage.h */ 95 + 96 + char *clalloc(unsigned long count,unsigned long size); 97 + char *calloc(unsigned int count, unsigned int size); 98 + int free(char *ptr); 99 + int cfree(char *ptr); 100 + char *mlalloc(unsigned long size); 101 + char *malloc(unsigned int size); 102 + char *relalloc(char *ptr,unsigned long newsize); 103 + char *realloc(char *ptr,unsigned newsize); 104 + 105 + /* storageu.h */ 106 + 107 + int allmem(void); 108 + int bldmem(int n); 109 + char *getmem(unsigned int nbytes); 110 + char *getml(unsigned long lnbytes); 111 + char *lsbrk(unsigned long lnbytes); 112 + int rlsmem(char *cp, unsigned int nbytes); 113 + int rlsml(char *cp,unsigned long lnbytes); 114 + void rstmem(void); 115 + void rbrk(void); 116 + char *sbrk(unsigned int nbytes); 117 + long sizmem(void); 118 + 119 + /* unix.h */ 120 + 121 + #ifndef _stdioh_ 122 + #include "stdio.h" 123 + #endif _stdioh_ 124 + 125 + char *locv(int hi,int lo); 126 + int getw(FILE *who); 127 + int putw(int word, FILE *who); 128 + void perror(char *s); 129 + 130 + void sleep(int secs); 131 + int ttyn(FILE *who); 132 + int stspfp(char *p,int *n); 133 + 134 + double atof(char *s); 135 + int atoi(char *s); 136 + long atol(char *s); 137 + 138 + int execl(char *path, ...); 139 + int execv(char *path, char *argv[]); 140 + int execle(char *path, ...); 141 + int execve(char *path, char *argv[], char *envp[]); 142 + 143 + void exit(...); 144 + void _exit(...); 145 + void abort(...); 146 + 147 + 148 + int fileno(FILE *who); 149 + int open(char *filename, int mode); 150 + int close(int fildes); 151 + int read(int fildes, char *buffer, unsigned nbytes); 152 + int write(int fildes, char *buffer, unsigned nbytes); 153 + long lseek(int fildes, long int offset, unsigned int offsetmode); 154 + long tell(int fildes); 155 + int rename(char *old, char *new); 156 + int remove(char *name); 157 + int unlink(char *name); 158 + int creat(char *filename, int mode); 159 + 160 + int getuid(void); 161 + int setuid(int uid); 162 + int getpid(void); 163 + int setpid(int pid); 164 + char *cgetpid(char *sptr); 165 + 166 + void setmem(char *p,unsigned n,char c); 167 + void repmem(char *s, char *v, int lv, int nv); 168 + void movmem(char *s, char *d, unsigned n); 169 + 170 + void eraseplot(void); 171 + void line(int x1, int y1, int x2, int y2); 172 + void move(int x, int y); 173 + void circle(int x, int y, int r); 174 + void cont(int x, int y); 175 + void point(int x, int y); 176 + void label(char *s); 177 + 178 + int setbuf(FILE *fp, char *buf); 179 + int setnbuf(FILE *fp); 180 + 181 + int (*signal(int sig, int (*func)()))(); 182 + int kill(int pid, int sig); 183 + 184 + int stci_d(char *out, int in, int outlen); 185 + int stcu_d(char *out, unsigned int in, int outlen); 186 + 187 + int stcd_i(char *s,int *r); 188 + int stch_i(char *s,int *r); 189 + 190 + unsigned long time(unsigned long *clock); 191 + char *ctime(unsigned long *clock); 192 + struct tm *localtime(unsigned long *clock); 193 + struct tm *gmtime(unsigned long *clock); 194 + char *asctime(struct tm *UnixTimeRecp); 195 + 196 + /* stdio */ 197 + 198 + int feof(FILE *who); 199 + int ferror(FILE *who); 200 + void clearerr(FILE *who); 201 + void clrerr(FILE *who); 202 + 203 + int fseek(FILE *who, long offset, int type); 204 + long ftell(FILE *who); 205 + int fflush(FILE *who); 206 + void rewind(FILE *who); 207 + 208 + int fwrite(char *ptr, unsigned size, int count, FILE *who); 209 + int fread(char *ptr, unsigned size, int count, FILE *who); 210 + 211 + int fgetc(FILE *who); 212 + char *fgets(char *s, int n, FILE *who); 213 + char *gets(char *s); 214 + int ungetc(char c, FILE *who); 215 + 216 + int ungetch(int c); 217 + int getch(void); 218 + int getche(void); 219 + char *cgets(char *s); 220 + 221 + int min(int v1, int v2); 222 + int max(int v1, int v2); 223 + 224 + int fclose(FILE *who); 225 + FILE *fopen(char *nameptr, char *type); 226 + FILE *freopen(char *nameptr, char *type, FILE *who); 227 + int _closeall(void); 228 + 229 + int fputc(unsigned char c, FILE *who); 230 + int fputs(char *s, FILE *who); 231 + int puts(char *s); 232 + 233 + void cputs(char *s); 234 + void wputs(char *s); 235 + int kbhit(void); 236 + 237 + int toint(char c); 238 + int toupper(char c); 239 + int tolower(char c); 240 + int _toupper(char c); 241 + int _tolower(char c); 242 + int isupper(char c); 243 + int islower(char c); 244 + 245 + char *std_ver(void); 246 + 247 + int printf(char *fmt, ...); 248 + int vprintf(char *fmt, char *arr, ...); 249 + int fprintf(FILE *who, char *fmt, ...); 250 + int vfprintf(FILE *who, char *fmt, char *arr, ...); 251 + int cprintf(char *fmt, ...); 252 + int vcprintf(char *fmt, char *arr, ...); 253 + 254 + int sprintf(char *dest, char *fmt, ...); 255 + int vsprintf(char *dest, char *fmt, char *arr, ...); 256 + 257 + int scanf(char *fmt, ...); 258 + int cscanf(char *fmt, ...); 259 + int fscanf(FILE *who, char *fmt, ...); 260 + int sscanf(unsigned char *dest, char *fmt, ...); 261 + 262 + Boolean StdEvent(EventRecord *event); 263 + FILE *fopenw(char *titlebar, Point upper_left, StdWindowOptions *opts); 264 + char *Get_ScreenPtr(void); 265 + setwindow(FILE *windowfile); 266 + void Click_On(int flag); 267 + void Stdio_Config(int font, int size, int face, int mode); 268 + void Stdio_config(int font, int size, int face, int mode); 269 + void Set_Echo(Boolean state); 270 + void Stdio_MacInit(Boolean flag); 271 + void Set_Tab(int len); 272 + void gotoxy(int x, int y); 273 + int getxpos(void); 274 + int getypos(void); 275 + void putch(char c); 276 + 277 +
+178
sources/qsort.c
··· 1 + /* 2 + (C) Copyright 1986. THINK Technologies, Inc. All rights reserved. 3 + 4 + 5 + The qsort and qksort functions provided with the LightspeedC compiler 6 + are contained in this module. 7 + 8 + */ 9 + 10 + #include "MemoryMgr.h" 11 + 12 + /* Based on the algorithm given in Knuth volume 3, p. 116 13 + 14 + 15 + qsort(base, nelms, size, compare) 16 + 17 + where: base pointer to start of data 18 + nelms number of elements (int) 19 + size size of each array element in bytes 20 + compare pointer to procedure described below 21 + 22 + compare(p1, p2) p1 & p2 are pointer to two elements in the array 23 + compare returns <0 if *p1 < *p2 24 + >0 if *p1 > *p2 25 + 0 if *p1 == *p2 26 + 27 + *************************************************************************** 28 + NOTE: qsort assumes that elements are aligned on word boundaries for 29 + sizes of 2 & 4 to provide an efficient implementation. 30 + *************************************************************************** 31 + 32 + 33 + Alternate calling sequence: 34 + 35 + qksort(nelms, compare, swap) 36 + 37 + where: nelms the number of elements to be sorted 38 + compare pointer to procedure described below 39 + swap pointer to procedure described below 40 + 41 + 42 + compare(i, j) i & j are short int args which are indices into 43 + the array that compareproc knows about. 44 + compare returns <0 if item[i] < item[j] 45 + >0 if item[i] > item[j] 46 + 0 if item[i] == item[j] 47 + 48 + swap(i, j) i & j are short int args which are indices into 49 + the array that swapproc knows about. 50 + swapproc swaps array items i & j. 51 + 52 + */ 53 + 54 + 55 + static int (*qkCompare)(), (*qkSwap)(); 56 + 57 + #line 0 qksort1 58 + /* sort elements "first" through "last"-1 */ 59 + static qksort1(first, last) 60 + { 61 + static short i; /* "static" to save stack space */ 62 + register short j; 63 + 64 + while (last - first > 1) { 65 + i = first; 66 + j = last; 67 + for (;;) { 68 + while (++i < last && (*qkCompare)(i, first) < 0) 69 + ; 70 + while (--j > first && (*qkCompare)(j, first) > 0) 71 + ; 72 + if (i >= j) 73 + break; 74 + (*qkSwap)(i, j); 75 + } 76 + (*qkSwap)(first, j); 77 + if (j - first < last - (j + 1)) { 78 + qksort1(first, j); 79 + first = j + 1; /* qsort1(j + 1, last); */ 80 + } 81 + else { 82 + qksort1(j + 1, last); 83 + last = j; /* qsort1(first, j); */ 84 + } 85 + } 86 + } 87 + 88 + #line 0 qksort 89 + /* sort "nelems" elements, using user's "compare" and "swap" routines */ 90 + qksort(nelems, compare, swap) 91 + int (*compare)(), (*swap)(); 92 + { 93 + qkCompare = compare; 94 + qkSwap = swap; 95 + qksort1(0, nelems); 96 + } 97 + 98 + 99 + /* qsort call support variables */ 100 + 101 + static int (*qCompare)(); 102 + static char *qbase, *qtemp; 103 + static unsigned long qsize; 104 + 105 + #line 0 qxcompare 106 + qxcompare(i, j) 107 + int i, j; 108 + { 109 + (*qCompare) (qbase + i * qsize, qbase + j * qsize); 110 + } 111 + 112 + #line 0 qxswap 113 + void qxswap(i, j) 114 + register int i, j; 115 + { 116 + register char c; /* save stack space and cut execution overhead */ 117 + register int k; 118 + register long l; 119 + register char *p1, *p2; 120 + 121 + switch (qsize) 122 + { 123 + case 1: c = qbase[i]; 124 + qbase[i] = qbase[j]; 125 + qbase[j] = c; 126 + break; 127 + 128 + case 2: k = ((int*)(qbase))[i]; 129 + ((int*)(qbase))[i] = ((int*)(qbase))[j]; 130 + ((int*)(qbase))[j] = k; 131 + break; 132 + 133 + case 4: l = ((long*)(qbase))[i]; 134 + ((long*)(qbase))[i] = ((long*)(qbase))[j]; 135 + ((long*)(qbase))[j] = l; 136 + break; 137 + 138 + 139 + default: p1 = qbase + i * qsize; 140 + p2 = qbase + j * qsize; 141 + BlockMove(p1, qtemp, qsize); 142 + BlockMove(p2, p1, qsize); 143 + BlockMove(qtemp, p2, qsize); 144 + break; 145 + } 146 + } 147 + 148 + 149 + #line 0 qsort 150 + qsort(base, nelms, size, compare) 151 + char *base; 152 + int nelms; 153 + register int size; 154 + int (*compare)(); 155 + { 156 + if (size <= 0) return (-1); 157 + 158 + /* allocate a buffer unless swapping char, int, or long */ 159 + 160 + qtemp = 0; 161 + 162 + if (size==3 || size>4) 163 + { 164 + qtemp=NewPtr(size); 165 + if (MemErr) return (-1); 166 + } 167 + 168 + qCompare = compare; 169 + qbase = base; 170 + qsize = size; 171 + 172 + qksort(nelms, &qxcompare, &qxswap); 173 + 174 + if (qtemp) DisposPtr(qtemp); 175 + 176 + return (0); 177 + } 178 +
+158
sources/sane.h
··· 1 + /*************************************************************************** 2 + 3 + Standard Apple Numeric Environment (SANE) interface for LightspeedC�. 4 + 5 + (C) Copyright 1986 THINK Technologies, Inc. All rights reserved. 6 + 7 + ****************************************************************************/ 8 + 9 + #ifndef _saneh_ 10 + #define _saneh_ 11 + 12 + 13 + typedef enum {TONEAREST, UPWARD, DOWNWARD, TOWARDZERO} rounddir; 14 + typedef enum {EXTPRECISION, DBLPRECISION, FLOATPRECISION} roundpre; 15 + typedef enum {GREATERTHAN, LESSTHAN, EQUALTO, UNORDERED} relop; 16 + typedef enum { INVALID =1, 17 + UNDERFLOW =2, 18 + OVERFLOW =4, 19 + DIVBYZERO =8, 20 + INEXACT =16 21 + } exception; 22 + typedef enum {SNAN, QNAN, INFINITE, ZERONUM, NORMALNUM, DENORMALNUM}numclass; 23 + typedef enum { FLOATDECIMAL = 0, 24 + FIXEDDECIMAL = 1, 25 + SIGDIGLEN = 20, 26 + DECSTROUTLEN = 80 } ; 27 + 28 + typedef struct 29 + { 30 + short sgn; /* char */ 31 + short exp; 32 + struct 33 + { 34 + unsigned char length; /* was char sig[22] */ 35 + char text[21]; 36 + }sig; 37 + } Decimal; 38 + 39 + typedef struct 40 + { 41 + char style; 42 + short digits; 43 + } DecForm; 44 + 45 + 46 + typedef int Environment ; 47 + 48 + typedef enum { /* Operation code masks */ 49 + FOADD = (int) 0x0000, /* add */ 50 + FOSUB = (int) 0x0002, /* subtract */ 51 + FOMUL = (int) 0x0004, /* multiply */ 52 + FODIV = (int) 0x0006, /* divide */ 53 + FOCMP = (int) 0x0008, /* compare no exception */ 54 + FOCPX = (int) 0x000A, /* compare, exception */ 55 + FOREM = (int) 0x000C, /* remainder */ 56 + FOZ2X = (int) 0x000E, /* convert to extended */ 57 + F0X2Z = (int) 0x0010, /* convrt from extended */ 58 + FOSQRT = (int) 0x0012, /* square root */ 59 + FORTI = (int) 0x0014, /* round to integral */ 60 + FOTTI = (int) 0x0016, /* truncate to integral */ 61 + FOSCALB = (int) 0x0018, /* binary scale */ 62 + FOLOGB = (int) 0x001A, /* binary log */ 63 + FOCLASS = (int) 0x001C, /* classify */ 64 + 65 + FOSETENV = (int) 0x0001, /* set environment */ 66 + FOGETENV = (int) 0x0003, /* get environment */ 67 + FOSETHV = (int) 0x0005, /* set halt vector */ 68 + FOGETHV = (int) 0x0007, /* get halt vector */ 69 + FOD2B = (int) 0x0009, /* cvt dec to bin */ 70 + FOB2D = (int) 0x000B, /* cvt bin to dec */ 71 + FONEG = (int) 0x000D, /* negate */ 72 + FOABS = (int) 0x000F, /* absolute */ 73 + FOCPYSGN = (int) 0x0011, /* copy sign */ 74 + FONEXT = (int) 0x0013, /* next-after */ 75 + FOSETXCP = (int) 0x0015, /* set exception */ 76 + FOPROCENTRY = (int) 0x0017, /* procedure entry */ 77 + FOPROCEXIT = (int) 0x0019, /* procedure exit */ 78 + FOTESTXCP = (int) 0x001B, /* test exception */ 79 + _UNUSED__ = (int) 0x0100 80 + } Operation_code_masks; 81 + 82 + typedef enum { /* Operand mask formats */ 83 + FFEXT = (int) 0x0000, /* extended 80 bit */ 84 + FFDBL = (int) 0x0800, /* double 64 bit */ 85 + FFSGL = (int) 0x1000, /* single 32 bit */ 86 + FFINT = (int) 0x2000, /* integer 16 bit */ 87 + FFLNG = (int) 0x2800, /* long int 32 bit */ 88 + FFCOMP = (int) 0x3000 /* comp 64 bit */ 89 + } Operand_format_masks; 90 + 91 + typedef enum { /* Precision code masks */ 92 + FCEXT = (int) 0x0000, /* extended */ 93 + FCDBL = (int) 0x4000, /* double */ 94 + FCSGL = (int) 0x8000 /* single */ 95 + } Precision_code_masks; 96 + 97 + typedef enum { /* Bit indexes */ 98 + FBINVALID = (int) 0x0000, /* invalid operation */ 99 + FBUFLOW = (int) 0x0001, /* underflow */ 100 + FBOFLOW = (int) 0x0002, /* overflow */ 101 + FBDIVZER = (int) 0x0003, /* division by zero */ 102 + FBINEXACT = (int) 0x0004, /* inexact */ 103 + FBRNDLO = (int) 0x0005, /* low bit rounding */ 104 + FBRNDHI = (int) 0x0006, /* high bit rounding */ 105 + FBLSTRND = (int) 0x0007, /* last round bit */ 106 + FBDBL = (int) 0x0005, /* dbl precision cntrl */ 107 + FBSGL = (int) 0x0006 /* sgl precision cntrl */ 108 + } Bit_indexes; 109 + 110 + typedef enum { /* Elementary masks */ 111 + FOLNX = (int) 0x0000, /* base-e log */ 112 + FOLOG2X = (int) 0x0002, /* base-2 log */ 113 + FOLN1X = (int) 0x0004, /* ln (1 + x ) */ 114 + FOLOG1X = (int) 0x0006, /* log2( 1 + x ) */ 115 + FOEXPX = (int) 0x0008, /* base-e exponential */ 116 + FOEXP2X = (int) 0x000A, /* base-2 exponential */ 117 + FOEXP1X = (int) 0x000C, /* exp( x ) - 1 */ 118 + FOEXP21X = (int) 0x000E, /* exp2( x ) - 1 */ 119 + FOPWRI = (int) 0x8010, /* integer exp */ 120 + FOPWRY = (int) 0x8012, /* general exp */ 121 + FOCOMPOUND = (int) 0xC014, /* compound */ 122 + FOANNUITY = (int) 0xC016, /* annuity */ 123 + FOSINX = (int) 0x0018, /* sine */ 124 + FOCOSX = (int) 0x001A, /* cosine */ 125 + FOTANX = (int) 0x001C, /* tangent */ 126 + FOATANX = (int) 0x001E, /* arctangent */ 127 + FORAND = (int) 0x0020 /* random number */ 128 + } Elementary_functions; 129 + 130 + typedef enum { /* NaN codes */ 131 + NANSQRT = (int) 0x0001, /* invalid sqrt */ 132 + NANADD = (int) 0x0002, /* invalid add */ 133 + NANDIV = (int) 0x0004, /* invalid division */ 134 + NANMUL = (int) 0x0008, /* invalid multiply */ 135 + NANREM = (int) 0x0009, /* invalid rem or mod */ 136 + NANASCBIN = (int) 0x0011, /* invalid ASCII string */ 137 + NANCOMP = (int) 0x0014, /* error in comp - flt */ 138 + NANZERO = (int) 0x0015, /* zero NaN */ 139 + NANTRIG = (int) 0x0021, /* invalid trig arg */ 140 + NANINVTRIG = (int) 0x0022, /* invalid inv trig arg */ 141 + NANLOG = (int) 0x0024, /* invalid log arg */ 142 + NANPOWER = (int) 0x0025, /* invalid power arg */ 143 + NANFINAN = (int) 0x0026, /* invalid finance arg */ 144 + NANINIT = (int) 0x00FF /* uninitialized var */ 145 + } NaN_codes; 146 + 147 + 148 + #define SetEnvironment(where) ( fp68k(where,FOSETENV) ) 149 + #define GetEnvironment(where) ( fp68k(where,FOGETENV) ) 150 + 151 + pascal void fp68k() = 0xA9EB; /* 68K arithemtic */ 152 + pascal void elems68k() = 0xA9EC; /* elementary functions */ 153 + pascal void Dec2Str(); 154 + pascal void Str2Dec(); 155 + pascal void CStr2Dec(); 156 + 157 + 158 + #endif
+77
sources/scanf1.c
··· 1 + /* 2 + scanf routines for LightspeedC� 3 + 4 + (C) Copyright 1986. THINK Technologies, Inc. All rights reserved. 5 + */ 6 + 7 + 8 + #ifndef _stdioh_ 9 + #include "stdio.h" 10 + #endif 11 + 12 + #ifndef _setjmph_ 13 + #include "setjmp.h" 14 + #endif 15 + 16 + extern int (*_scanf_input)(); /* global pointer to function for input */ 17 + extern int (*_scanf_putback)(); /* global pointer to function for putback */ 18 + extern int _scanf_scan(); /* function to handle formatting */ 19 + extern jmp_buf _scanf_env; /* for error exit context switch */ 20 + 21 + static FILE *globalwho; /* pointer to indicate stream for input */ 22 + 23 + static 24 + int from_stream() 25 + { 26 + return(fgetc(globalwho)); /* get chararacter from stream and return it */ 27 + } 28 + 29 + static 30 + put_back_into_stream(x) 31 + int x; 32 + { 33 + if ((ungetc(x,globalwho))!= x) longjmp(_scanf_env, EOF); 34 + } 35 + 36 + 37 + static 38 + int setup(who) 39 + register FILE *who; 40 + { 41 + globalwho = who; 42 + 43 + if ((!who)||(!who->InUse)||(!who->rd)) return(EOF); 44 + 45 + _scanf_input = from_stream; 46 + _scanf_putback = put_back_into_stream; 47 + 48 + return (0); 49 + } 50 + 51 + #line 0 scanf() 52 + int scanf(fmt) 53 + char *fmt; 54 + { 55 + if (setup(stdin)) return (EOF); 56 + return(_scanf_scan(&fmt)); 57 + } 58 + 59 + 60 + #line 0 cscanf() 61 + int cscanf(fmt) 62 + char *fmt; 63 + { 64 + if (setup(_console)) return (EOF); 65 + return(_scanf_scan(&fmt)); 66 + } 67 + 68 + 69 + #line 0 fscanf() 70 + int fscanf(who,fmt) 71 + FILE *who; 72 + char *fmt; 73 + { 74 + if (setup(who)) return (EOF); 75 + return(_scanf_scan(&fmt)); 76 + } 77 +
+564
sources/scanf2.c
··· 1 + /* 2 + scanf routines for LightspeedC� 3 + 4 + (C) Copyright 1986. THINK Technologies, Inc. All rights reserved. 5 + */ 6 + 7 + #ifndef _stdioh_ 8 + #include "stdio.h" 9 + #endif 10 + 11 + #ifndef _MacTypes_ 12 + #include "MacTypes.h" 13 + #endif 14 + 15 + #ifndef _ctypeh_ 16 + #include "ctype.h" 17 + #endif 18 + 19 + #ifndef _saneh_ 20 + #include "sane.h" 21 + #endif 22 + 23 + #ifndef _setjmph_ 24 + #include "setjmp.h" 25 + #endif 26 + 27 + /*---------------------------------------------------------------------------- 28 + some global storage to prevent excessive parameter transfer 29 + ----------------------------------------------------------------------------*/ 30 + 31 + int (*_scanf_input)(); /* global pointer to function for input */ 32 + int (*_scanf_putback)(); /* global pointer to function for putback */ 33 + _scanf_scan(); /* function to handle formatting */ 34 + jmp_buf _scanf_env; /* for error exit context switch */ 35 + 36 + static unsigned char *destination; /* pointer to indicate stream for output */ 37 + static char scratch[256]; /* used for [ command for byte validation */ 38 + 39 + static 40 + int from_memory() 41 + { 42 + return(*destination++); /* return next character in memory stream */ 43 + } 44 + 45 + static 46 + put_back_into_memory(x) 47 + char x; 48 + { 49 + destination--; 50 + } 51 + 52 + 53 + #line 0 sscanf 54 + int sscanf(dest, fmt) 55 + unsigned char *dest; /* pointer to buffer space */ 56 + char *fmt; /* pointer to format string */ 57 + { 58 + _scanf_input = from_memory; 59 + _scanf_putback = put_back_into_memory; 60 + 61 + destination = dest; 62 + return(_scanf_scan(&fmt)); 63 + } 64 + 65 + static 66 + Boolean okdigit(c, base, value_in_base_ptr) 67 + register char c; 68 + register int base; 69 + register int *value_in_base_ptr; 70 + { 71 + /* only works for bases 2 through 10 (inclusive) and 16! */ 72 + 73 + *value_in_base_ptr = 0; 74 + 75 + if (c >= '0') 76 + { 77 + if (c <= (((base<=10)?base:10)+'0'-1)) 78 + { 79 + *value_in_base_ptr = c-'0'; 80 + return (true); 81 + } 82 + 83 + if (base == 16) 84 + { 85 + /* if character is lower case, convert to upper case */ 86 + 87 + if ((c >= 'a') && (c <= 'f')) c -= 'a'-'A'; 88 + 89 + if ((c >= 'A') && (c <= 'F')) 90 + { 91 + *value_in_base_ptr = c - 'A' + 10; 92 + return (true); 93 + } 94 + } 95 + } 96 + 97 + return (false); 98 + } 99 + 100 + 101 + static 102 + long read_num(num,err,at_least_one, base) 103 + register unsigned num; 104 + register Boolean *err; 105 + register Boolean *at_least_one; 106 + register int base; 107 + { 108 + register long number = 0; 109 + register int c; 110 + register Boolean oneX=false; 111 + int value_in_base; 112 + 113 + *at_least_one = false; 114 + *err = false; 115 + if (num == 0) num--; 116 + 117 + /* if first char is EOF, then it's not a number */ 118 + 119 + if ((c = (*_scanf_input)()) == EOF) 120 + { 121 + *err = true; 122 + return(EOF); 123 + } 124 + 125 + /* loop collecting digits while num is not zero */ 126 + 127 + while (okdigit(c, base, &value_in_base) && num--) 128 + { 129 + number = number * base + value_in_base; 130 + *at_least_one = true; 131 + 132 + /* no need to put back EOF if we hit it */ 133 + 134 + if ((c = (*_scanf_input)()) == EOF) return (number); 135 + 136 + /* the form 0xNNNN is allowed for hex numbers, just swallow the 137 + X and continue from there, but only do it once! */ 138 + 139 + if ((base == 16) && ((c == 'x') || (c == 'X'))) 140 + { 141 + if ((number > 0) || oneX) break; 142 + 143 + /* pick up next digit -- error if nothing follows X */ 144 + 145 + if ((c = (*_scanf_input)()) == EOF) return (EOF); 146 + } 147 + 148 + /* only allow hex form after first zero, otherwise it is an error */ 149 + 150 + oneX = true; 151 + } 152 + 153 + (*_scanf_putback)(c); 154 + 155 + return(number); 156 + } 157 + 158 + static 159 + int skip_white() 160 + { 161 + register int c; 162 + 163 + do 164 + { 165 + if ((c = (*_scanf_input)()) == EOF) longjmp(_scanf_env, EOF); 166 + } 167 + while (c && isspace(c)); 168 + 169 + return(c); /* returns character after white space */ 170 + } 171 + 172 + 173 + int _scanf_scan(fmt) 174 + char **fmt; /* pointer to pointer to format string */ 175 + { 176 + char c; /* current character under inspection */ 177 + char *format; /* pointer to format string */ 178 + Boolean its_a_long; /* flag to indicate long integer */ 179 + Boolean its_a_short; /* flag to indicate short integer */ 180 + Boolean neg; /* flag for negative # */ 181 + register Boolean assign; /* flag for suppression flag */ 182 + Boolean read_err; /* Used as error flag for read_ routines */ 183 + Boolean valid; /* valid digit? */ 184 + register long value; /* for conversion of numerics */ 185 + register char *argument; /* pointer to arguments for fmt string */ 186 + register unsigned width; /* field width as specified by format */ 187 + register int curr_char; /* last character read */ 188 + register char **loc; /* used to run thru argument */ 189 + int i; /* counter */ 190 + register count; /* counter */ 191 + register int (*_scanf_putbackx)() = _scanf_putback; 192 + 193 + if (count=setjmp(_scanf_env)) return (count); /* set up error handler */ 194 + 195 + format = *fmt++; /* set "format" to the format string */ 196 + /* "fmt" is left pointing to first argument */ 197 + argument = (char *) fmt; /* set "argument" to point to first argument */ 198 + count = 0; /* set count to zero */ 199 + 200 + while (c = *format++) /* scan format string until NULL */ 201 + { 202 + if (c == '%') 203 + { 204 + neg = false; 205 + assign = true; 206 + 207 + if ((c = *format) == '*') /* suppress mode? */ 208 + { 209 + assign = false; /* set flag if so */ 210 + format++; /* point to next char */ 211 + } 212 + 213 + /* compute total field width, zero allows arbitrary width */ 214 + 215 + width = (isdigit(*format)) ? _std_decode(&format) : 0; 216 + 217 + /* check if long integer is required */ 218 + 219 + if (its_a_long = ((*format) == 'l')) format++; 220 + 221 + /* check if short integer is required */ 222 + 223 + if (its_a_short = ((*format) == 'h')) format++; 224 + 225 + c = *format++; 226 + 227 + /* note that "format" is left ready for the next pass */ 228 + 229 + switch (c) 230 + { 231 + case 'd': switch (curr_char = skip_white()) 232 + { 233 + case '+': /* swallow a + */ 234 + break; 235 + 236 + case '-': /* remember a -, swallow char */ 237 + neg = true; 238 + break; 239 + 240 + default: /* oops, put it back! */ 241 + (*_scanf_putbackx)(curr_char); 242 + break; 243 + } 244 + 245 + value = read_num(width,&read_err,&valid, 10); 246 + 247 + if (read_err) return(EOF); 248 + 249 + if (valid == false) return(count); 250 + 251 + if (neg) value = -value; 252 + 253 + if (assign) 254 + { 255 + if(its_a_long) 256 + **(long **)argument = value; 257 + else 258 + **(int **)argument = value; 259 + 260 + argument += sizeof(long); 261 + count++; 262 + } 263 + break; 264 + 265 + case 'u': 266 + (*_scanf_putbackx)(skip_white()); 267 + 268 + value = read_num(width,&read_err,&valid, 10); 269 + 270 + if (read_err) return(EOF); 271 + 272 + if (valid == false) return(count); 273 + 274 + if (assign) 275 + { 276 + if(its_a_long) 277 + **(unsigned long **)argument = value; 278 + else 279 + **(unsigned int **)argument = value; 280 + 281 + argument += sizeof(long); 282 + count++; 283 + } 284 + break; 285 + 286 + case 'x': 287 + case 'X': 288 + (*_scanf_putbackx)(skip_white()); 289 + 290 + value = read_num(width,&read_err,&valid, 16); 291 + 292 + if (read_err) return(EOF); 293 + 294 + if (valid == false) return(count); 295 + 296 + if (assign) 297 + { 298 + if(its_a_long) 299 + **(unsigned long **)argument = value; 300 + else 301 + **(unsigned int **)argument = value; 302 + 303 + argument += sizeof(long); 304 + count++; 305 + } 306 + break; 307 + case 'o': 308 + case 'O': 309 + (*_scanf_putbackx)(skip_white()); 310 + 311 + value = read_num(width,&read_err,&valid, 8); 312 + 313 + if (read_err) return(EOF); 314 + 315 + if (valid == false) return(count); 316 + 317 + if (assign) 318 + { 319 + if(its_a_long) 320 + **(unsigned long **)argument = value; 321 + else 322 + **(unsigned int **)argument = value; 323 + 324 + argument += sizeof(long); 325 + count++; 326 + } 327 + break; 328 + 329 + case 'c': if (width<=0) width = 1; 330 + 331 + loc = (char **)argument; 332 + 333 + do 334 + { 335 + if ((curr_char = (*_scanf_input)()) == EOF) 336 + return(EOF); 337 + 338 + if (assign) 339 + { 340 + **(char **)loc = curr_char; 341 + (*loc)++; 342 + } 343 + width--; 344 + } 345 + while (width); 346 + 347 + if (assign) 348 + { 349 + argument += sizeof(long); 350 + count++; 351 + } 352 + 353 + break; 354 + 355 + case 's': 356 + /* first char cannot be EOF after skip_white */ 357 + 358 + (*_scanf_putbackx)(skip_white()); 359 + 360 + loc = (char **)argument; 361 + 362 + do 363 + { 364 + if ((curr_char = (*_scanf_input)()) == EOF) 365 + { 366 + if (assign) **(char**) loc = '\0'; 367 + return (count); 368 + } 369 + 370 + if (assign) 371 + { 372 + if (!isspace(curr_char)) 373 + **(char **)loc = curr_char; 374 + else 375 + **(char **)loc = '\0'; 376 + (*loc)++; 377 + } 378 + width--; 379 + } 380 + while ((curr_char)&&(width)&&(!isspace(curr_char))); 381 + if (!curr_char || isspace(curr_char)) 382 + (*_scanf_putbackx)(curr_char); 383 + else 384 + if (assign) 385 + **(char **)loc = '\0'; 386 + 387 + if (assign) 388 + { 389 + argument += sizeof(long); 390 + count++; 391 + } 392 + break; 393 + 394 + case '[': neg = false; 395 + 396 + if (*format == '^') /* check for negate */ 397 + { 398 + neg = true; /* set if necessary */ 399 + format++; 400 + } 401 + 402 + loc = (char **)argument; /* point to destination */ 403 + 404 + /* initialize lookup table */ 405 + 406 + for (i=255; i>=0; i--) 407 + scratch[i] = neg; 408 + 409 + /* pointing after [ or ^ */ 410 + 411 + while ((curr_char = *format++) != ']') 412 + scratch[curr_char] = (!neg); 413 + 414 + do 415 + { 416 + if ((curr_char = (*_scanf_input)()) == EOF) 417 + return(EOF); 418 + 419 + if (assign) 420 + { 421 + if (scratch[curr_char]) 422 + **(char **)loc = curr_char; 423 + else 424 + **(char **)loc = '\0'; 425 + (*loc)++; 426 + } 427 + width--; 428 + } 429 + while ((width) && (scratch[curr_char])); 430 + 431 + if (!scratch[curr_char]) 432 + (*_scanf_putbackx)(curr_char); 433 + else 434 + if (assign) 435 + **(char **)loc = '\0'; 436 + 437 + if (assign) 438 + { 439 + argument += sizeof(long); 440 + count++; 441 + } 442 + break; 443 + 444 + 445 + 446 + case '%': if ((curr_char = (*_scanf_input)()) == EOF) 447 + return(EOF); 448 + if (curr_char != '%') 449 + return (count); 450 + break; 451 + 452 + case 'f': 453 + case 'e': 454 + case 'E': 455 + case 'g': 456 + case 'G': 457 + 458 + {Decimal _decimal_; 459 + int fblen = 0; 460 + 461 + scratch[0] = '\0'; 462 + curr_char = skip_white(); 463 + 464 + valid = false; 465 + do 466 + {int index = 0; 467 + 468 + scratch[fblen++] = curr_char; 469 + scratch[fblen] = '\0'; 470 + read_err = false; 471 + 472 + if (scratch[fblen-1]) 473 + { 474 + CStr2Dec(&scratch,&index,&_decimal_,&read_err); 475 + 476 + /* read_err is true if NO READ ERROR! */ 477 + 478 + if (read_err) 479 + { 480 + valid = true; 481 + 482 + /* read next character */ 483 + 484 + if ((curr_char = (*_scanf_input)()) == EOF) 485 + read_err = false; 486 + 487 + if (isspace(curr_char)) 488 + { 489 + read_err = false; 490 + (*_scanf_putbackx)(curr_char); 491 + } 492 + } 493 + else 494 + (*_scanf_putbackx)(scratch[fblen-1]); 495 + } 496 + 497 + } while ((read_err)&&(--width)); 498 + 499 + if (!valid) return(count); 500 + 501 + if (assign) 502 + { 503 + if (its_a_long) 504 + fp68k(&_decimal_,*(double**)argument,FFEXT|FOD2B); 505 + else 506 + if (its_a_short) 507 + fp68k(&_decimal_,*(short double**)argument,FFDBL|FOD2B); 508 + else 509 + fp68k(&_decimal_,*(float**)argument,FFSGL|FOD2B); 510 + 511 + count++; 512 + } 513 + 514 + argument += sizeof(long); 515 + break; 516 + } 517 + } /* end switch */ 518 + } /* end '%' */ 519 + else 520 + { 521 + if (!c || isspace(c)) 522 + { 523 + /* expecting zero or more spaces 524 + pdg - 6/20/86 - used to require at least 1 space! */ 525 + 526 + while (isspace(curr_char = (*_scanf_input)())) 527 + ; 528 + 529 + /* prevent trailing white space from incurring EOF exit */ 530 + 531 + if (curr_char == EOF) 532 + { 533 + if (count > 0) return (count); 534 + return (EOF); 535 + } 536 + 537 + (*_scanf_putbackx)(curr_char); 538 + 539 + /* skip all contiguous spaces in format string */ 540 + 541 + while (isspace(*format)) format++; 542 + } 543 + else 544 + { 545 + if ((curr_char = (*_scanf_input)()) == EOF) return(EOF); 546 + 547 + /* character must match exactly! */ 548 + 549 + if (curr_char != c) 550 + { 551 + (*_scanf_putbackx)(curr_char); 552 + return(count); 553 + } 554 + } 555 + } /* else % */ 556 + 557 + } /* end while (*format) */ 558 + 559 + /* return number of successful assignments */ 560 + 561 + return(count); 562 + 563 + } 564 +
+8
sources/setjmp.h
··· 1 + /* (C) Copyright 1986. THINK Technologies, Inc. All rights reserved. */ 2 + 3 + #ifndef _setjmph_ 4 + #define _setjmph_ 5 + 6 + typedef long jmp_buf[11]; /* D3-D7,PC,A2-A4,A6,SP */ 7 + 8 + #endif
+39
sources/signal.h
··· 1 + /* 2 + * signal.h 3 + * 4 + * defines the values for signal() in the unix emulation library 5 + * 6 + * (C) Copyright 1985, 1986. THINK Technologies Inc. All rights reserved. 7 + */ 8 + 9 + #ifndef _signalh_ 10 + #define _signalh_ 11 + 12 + #define SIGHUP 1 13 + #define SIGINT 2 /* signal on ^c or ^. from keyboard when using stdio */ 14 + #define SIGQUIT 3 15 + #define SIGILL 4 16 + #define SIGTRAP 5 17 + #define SIGIOT 6 18 + #define SIGEMT 7 19 + #define SIGFPE 8 20 + #define SIGKILL 9 /* send signal to a task (only one in this case) */ 21 + #define SIGBUS 10 22 + #define SIGSEGV 11 23 + #define SIGSYS 12 24 + #define SIGPIPE 13 25 + #define SIGALRM 14 26 + #define SIGTERM 15 /* signal on exit, equivalent to onexit() function */ 27 + #define SIGUSR1 16 28 + #define SIGUSR2 17 29 + #define SIGCLD 18 30 + #define SIGPWR 19 31 + 32 + #define _SIGMAX 19 /* 19 possible signals in this implementation */ 33 + 34 + #define SIG_DFL 1L 35 + #define SIG_IGN 2L 36 + 37 + int (*signal())(); 38 + 39 + #endif
+26
sources/std_decode.c
··· 1 + /* 2 + _std_decode - numeric string decoder 3 + 4 + (C) Copyright 1986. THINK Technologies, Inc. All rights reserved. 5 + 6 + */ 7 + 8 + #define isdigit(x) (((x)<='9') && ((x)>='0')) 9 + 10 + int _std_decode(string) 11 + register char **string; /* variable argument will be adjusted */ 12 + { 13 + register int number = 0; 14 + register char *fast_ptr = *string; /* dereference ptr & cache it */ 15 + 16 + while (isdigit(*fast_ptr)) 17 + { 18 + number = 10 * number + *fast_ptr - '0'; 19 + fast_ptr++; 20 + } 21 + 22 + *string = fast_ptr; /* store back the resulting ptr */ 23 + 24 + return(number); 25 + } 26 +
+152
sources/stddata_ctype.c
··· 1 + /* 2 + Routines for LightspeedC� 3 + 4 + (C) Copyright 1985, 1986. THINK Technologies, Inc. All rights reserved. 5 + */ 6 + 7 + #ifndef _ctypeh_ 8 + #include "ctype.h" 9 + #endif 10 + 11 + char __ctype[257] = 12 + { 13 + 0, 14 + _cntrl_|_ascii_, 15 + _cntrl_|_ascii_, 16 + _cntrl_|_ascii_, 17 + _cntrl_|_ascii_|_space_, 18 + _cntrl_|_ascii_, 19 + _cntrl_|_ascii_, /* 5 */ 20 + _cntrl_|_ascii_, 21 + _cntrl_|_ascii_, 22 + _cntrl_|_ascii_, 23 + _cntrl_|_ascii_|_space_, 24 + _cntrl_|_ascii_|_space_,/* 10 */ 25 + _cntrl_|_ascii_|_space_, 26 + _cntrl_|_ascii_|_space_, 27 + _cntrl_|_ascii_|_space_, 28 + _cntrl_|_ascii_, 29 + _cntrl_|_ascii_, /* 15 */ 30 + _cntrl_|_ascii_, 31 + _cntrl_|_ascii_, 32 + _cntrl_|_ascii_, 33 + _cntrl_|_ascii_, 34 + _cntrl_|_ascii_, /* 20 */ 35 + _cntrl_|_ascii_, 36 + _cntrl_|_ascii_, 37 + _cntrl_|_ascii_, 38 + _cntrl_|_ascii_, 39 + _cntrl_|_ascii_, /* 25 */ 40 + _cntrl_|_ascii_, 41 + _cntrl_|_ascii_, 42 + _cntrl_|_ascii_, 43 + _cntrl_|_ascii_, 44 + _cntrl_|_ascii_, /* 30 */ 45 + _cntrl_|_ascii_, 46 + _space_|_ascii_, /* 32 */ 47 + _ascii_|_punct_, 48 + _ascii_|_punct_, 49 + _ascii_|_punct_, /* 35 */ 50 + _ascii_|_punct_, 51 + _ascii_|_punct_, 52 + _ascii_|_punct_, 53 + _ascii_|_punct_, 54 + _ascii_|_punct_, /* 40 */ 55 + _ascii_|_punct_, 56 + _ascii_|_punct_, 57 + _ascii_|_punct_, 58 + _ascii_|_punct_, 59 + _ascii_|_punct_, /* 45 */ 60 + _ascii_|_punct_, 61 + _ascii_|_punct_, 62 + _digit_|_hex_|_octal_|_ascii_, /* 48 '0' */ 63 + _digit_|_hex_|_octal_|_ascii_, 64 + _digit_|_hex_|_octal_|_ascii_, /* 50 */ 65 + _digit_|_hex_|_octal_|_ascii_, 66 + _digit_|_hex_|_octal_|_ascii_, 67 + _digit_|_hex_|_octal_|_ascii_, 68 + _digit_|_hex_|_octal_|_ascii_, 69 + _digit_|_hex_|_octal_|_ascii_, /* 55 '7' */ 70 + _digit_|_hex_|_ascii_, 71 + _digit_|_hex_|_ascii_, /* 57 '9' */ 72 + _ascii_|_punct_, 73 + _ascii_|_punct_, 74 + _ascii_|_punct_, /* 60 */ 75 + _ascii_|_punct_, 76 + _ascii_|_punct_, 77 + _ascii_|_punct_, 78 + _ascii_|_punct_, 79 + _alpha_|_hex_|_ascii_, /* 65 'A' */ 80 + _alpha_|_hex_|_ascii_, 81 + _alpha_|_hex_|_ascii_, 82 + _alpha_|_hex_|_ascii_, 83 + _alpha_|_hex_|_ascii_, 84 + _alpha_|_hex_|_ascii_, /* 70 'F' */ 85 + _alpha_|_ascii_, 86 + _alpha_|_ascii_, 87 + _alpha_|_ascii_, 88 + _alpha_|_ascii_, 89 + _alpha_|_ascii_, /* 75 */ 90 + _alpha_|_ascii_, 91 + _alpha_|_ascii_, 92 + _alpha_|_ascii_, 93 + _alpha_|_ascii_, 94 + _alpha_|_ascii_, /* 80 */ 95 + _alpha_|_ascii_, 96 + _alpha_|_ascii_, 97 + _alpha_|_ascii_, 98 + _alpha_|_ascii_, 99 + _alpha_|_ascii_, /* 85 */ 100 + _alpha_|_ascii_, 101 + _alpha_|_ascii_, 102 + _alpha_|_ascii_, 103 + _alpha_|_ascii_, 104 + _alpha_|_ascii_, /* 90 'Z' */ 105 + _ascii_|_punct_, /* '[' */ 106 + _ascii_|_punct_, /* '\' */ 107 + _ascii_|_punct_, /* ']' */ 108 + _ascii_|_punct_, /* '^' */ 109 + _ascii_|_punct_, /* 95 '_' */ 110 + _ascii_|_punct_, 111 + _alpha_|_ascii_|_hex_, /* 97 'a' */ 112 + _alpha_|_ascii_|_hex_, 113 + _alpha_|_ascii_|_hex_, 114 + _alpha_|_ascii_|_hex_, /* 100 */ 115 + _alpha_|_ascii_|_hex_, 116 + _alpha_|_ascii_|_hex_, /* 102 'f' */ 117 + _alpha_|_ascii_, 118 + _alpha_|_ascii_, 119 + _alpha_|_ascii_, /* 105 */ 120 + _alpha_|_ascii_, 121 + _alpha_|_ascii_, 122 + _alpha_|_ascii_, 123 + _alpha_|_ascii_, 124 + _alpha_|_ascii_, /* 110 */ 125 + _alpha_|_ascii_, 126 + _alpha_|_ascii_, 127 + _alpha_|_ascii_, 128 + _alpha_|_ascii_, 129 + _alpha_|_ascii_, /* 115 */ 130 + _alpha_|_ascii_, 131 + _alpha_|_ascii_, 132 + _alpha_|_ascii_, 133 + _alpha_|_ascii_, 134 + _alpha_|_ascii_, /* 120 */ 135 + _alpha_|_ascii_, 136 + _alpha_|_ascii_, /* 122 'z' */ 137 + _ascii_|_punct_, 138 + _ascii_|_punct_, 139 + _ascii_|_punct_, /* 125 */ 140 + _ascii_|_punct_, 141 + _cntrl_|_ascii_, /* 127 */ 142 + 0, /* _ascii_, 10-Jun-86 */ /* 128 */ 143 + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 144 */ 144 + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 160 */ 145 + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 176 */ 146 + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 192 */ 147 + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 208 */ 148 + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 224 */ 149 + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 240 */ 150 + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 /* 255 */ 151 + }; 152 +
+55
sources/stddata_file.c
··· 1 + /* 2 + Routines for LightspeedC� 3 + 4 + (C) Copyright 1985, 1986. THINK Technologies, Inc. All rights reserved. 5 + */ 6 + 7 + 8 + 9 + #ifndef _stdioh_ 10 + #include "stdio.h" 11 + #endif 12 + 13 + FILE _file[_NFILE] = 14 + { /* set up _NFILE records of type FILE */ 15 + 0,0,0 ,0,1,1,1,0,0,0,0,0,0,NULL,0,0, /* stdin */ 16 + 0,0,1 ,0,0,1,0,1,0,0,0,0,0,NULL,0,0, /* stdout */ 17 + 0,0,2 ,0,0,1,0,1,0,0,0,0,0,NULL,0,0, /* stderr */ 18 + 0,0,3 ,0,0,0,0,0,0,0,0,0,0,NULL,0,0, 19 + 0,0,4 ,0,0,0,0,0,0,0,0,0,0,NULL,0,0, 20 + 0,0,5 ,0,0,0,0,0,0,0,0,0,0,NULL,0,0, 21 + 0,0,6 ,0,0,0,0,0,0,0,0,0,0,NULL,0,0, 22 + 0,0,7 ,0,0,0,0,0,0,0,0,0,0,NULL,0,0, 23 + 0,0,8 ,0,0,0,0,0,0,0,0,0,0,NULL,0,0, 24 + 0,0,9 ,0,0,0,0,0,0,0,0,0,0,NULL,0,0, 25 + 0,0,10,0,0,0,0,0,0,0,0,0,0,NULL,0,0, 26 + 0,0,11,0,0,0,0,0,0,0,0,0,0,NULL,0,0, 27 + 0,0,12,0,0,0,0,0,0,0,0,0,0,NULL,0,0, 28 + 0,0,13,0,0,0,0,0,0,0,0,0,0,NULL,0,0, 29 + 0,0,14,0,0,0,0,0,0,0,0,0,0,NULL,0,0, 30 + 0,0,15,0,0,0,0,0,0,0,0,0,0,NULL,0,0, 31 + 0,0,16,0,0,0,0,0,0,0,0,0,0,NULL,0,0, 32 + 0,0,17,0,0,0,0,0,0,0,0,0,0,NULL,0,0, 33 + 0,0,18,0,0,0,0,0,0,0,0,0,0,NULL,0,0, 34 + 0,0,19,0,0,0,0,0,0,0,0,0,0,NULL,0,0, 35 + 0,0,20,0,0,0,0,0,0,0,0,0,0,NULL,0,0, 36 + 0,0,21,0,0,0,0,0,0,0,0,0,0,NULL,0,0, 37 + 0,0,22,0,0,0,0,0,0,0,0,0,0,NULL,0,0, 38 + 0,0,23,0,0,0,0,0,0,0,0,0,0,NULL,0,0, 39 + 0,0,24,0,0,0,0,0,0,0,0,0,0,NULL,0,0, 40 + 0,0,25,0,0,0,0,0,0,0,0,0,0,NULL,0,0, 41 + 0,0,26,0,0,0,0,0,0,0,0,0,0,NULL,0,0, 42 + 0,0,27,0,0,0,0,0,0,0,0,0,0,NULL,0,0, 43 + 0,0,28,0,0,0,0,0,0,0,0,0,0,NULL,0,0, 44 + 0,0,29,0,0,0,0,0,0,0,0,0,0,NULL,0,0 45 + }; 46 + 47 + 48 + FILE _console_ = 49 + { 50 + 0,0,_NFILE,0,0,1,1,1,0,0,0,0,0,NULL,0,0 /* keyboard and screen */ 51 + }; 52 + 53 + 54 + int errno; /* error storage place */ 55 +
+46
sources/stdfile_error.c
··· 1 + /* 2 + Routines for LightspeedC� 3 + 4 + (C) Copyright 1985, 1986. THINK Technologies, Inc. All rights reserved. 5 + */ 6 + 7 + #ifndef _stdioh_ 8 + #include "stdio.h" 9 + #endif 10 + 11 + #ifndef _FileMgr_ 12 + #include "FileMgr.h" 13 + #endif 14 + 15 + 16 + 17 + #line 0 feof() 18 + int feof(who) 19 + FILE *who; 20 + { 21 + return(who->last_error == eofErr); 22 + } 23 + 24 + 25 + #line 0 ferror() 26 + int ferror(who) 27 + FILE *who; 28 + { 29 + return(who->last_error); 30 + } 31 + 32 + #line 0 clearerr() 33 + void clearerr(who) 34 + FILE *who; 35 + { 36 + who->last_error = noErr; 37 + } 38 + 39 + 40 + #line 0 clrerr() 41 + void clrerr(who) 42 + FILE *who; 43 + { 44 + who->last_error = noErr; 45 + } 46 +
+163
sources/stdfile_pos.c
··· 1 + /* 2 + Routines for LightspeedC� 3 + 4 + (C) Copyright 1985, 1986. THINK Technologies, Inc. All rights reserved. 5 + */ 6 + 7 + #ifndef _stdioh_ 8 + #include "stdio.h" 9 + #endif 10 + 11 + #ifndef _FileMgr_ 12 + #include "FileMgr.h" 13 + #endif 14 + 15 + /* 16 + * This file contains fseek, ftell, fflush, rewind. 17 + */ 18 + 19 + #line 0 fseek() 20 + int fseek(who,offset,type) 21 + register FILE *who; 22 + register long offset; 23 + int type; 24 + { 25 + ioParam pb; /* my parameter block for PB's */ 26 + register long eofile; /* save EOF */ 27 + register long posfile; /* save current position in file */ 28 + register int err, mactype; 29 + 30 + if (who->StdStream) 31 + return(errno = EOF); 32 + 33 + if (who->mod) 34 + if (write_to_buffer(who)) 35 + return(EOF); 36 + 37 + /* always get EOF */ 38 + 39 + pb.ioRefNum = who->refnum; 40 + 41 + if (err = who->last_error = PBGetEOF(&pb,false)) 42 + { 43 + errno = err; 44 + return(EOF); 45 + } 46 + 47 + eofile = (long) pb.ioMisc; 48 + 49 + switch(type) 50 + { 51 + case 0: /* offset from beginning of file */ 52 + break; 53 + 54 + case 1: /* offset from current file position */ 55 + if ((posfile = ftell(who)) == -1L) 56 + return (EOF); 57 + 58 + offset += posfile; 59 + break; 60 + 61 + case 2: /* offset from logical end of file */ 62 + offset += eofile; 63 + break; 64 + 65 + default: /* parameter error */ 66 + errno = who->last_error = paramErr; 67 + return(EOF); 68 + } 69 + 70 + who->look_full = false; /* set look_ahead buffer to empty */ 71 + who->fpos = BUFSIZ+10; /* force look to disk for block */ 72 + who->inbuf = 0; 73 + 74 + /* attempt to extend file requires write access */ 75 + 76 + if (offset > eofile) 77 + { 78 + if (! who->wr) 79 + { 80 + who->last_error = errno = wrPermErr; 81 + return(EOF); 82 + } 83 + 84 + /* just do a seteof to extend -- characters between the existing 85 + eof and the new file position are garbage characters */ 86 + 87 + pb.ioMisc = (char *) offset; 88 + if (err = who->last_error = PBSetEOF(&pb, false)) 89 + errno = err; 90 + 91 + return(err); 92 + } 93 + 94 + pb.ioPosMode = fsFromStart; 95 + pb.ioPosOffset = offset; 96 + if (err = who->last_error = PBSetFPos(&pb,false)) 97 + errno = err; 98 + 99 + return(err); 100 + } 101 + 102 + 103 + #line 0 ftell() 104 + long ftell(who) 105 + register FILE *who; 106 + { 107 + ioParam pb; /* my parameter block for PB's */ 108 + register int err; 109 + 110 + if (who->StdStream) 111 + return(errno = EOF); 112 + 113 + pb.ioRefNum = who->refnum; 114 + 115 + if(who->last_error = (err = (PBGetFPos(&pb,false)))) 116 + { 117 + errno = err; 118 + return(-1L); 119 + } 120 + 121 + return((who->fpos>BUFSIZ)?pb.ioPosOffset:pb.ioPosOffset+who->fpos); 122 + } 123 + 124 + 125 + #line 0 fflush() 126 + int fflush(who) 127 + register FILE *who; 128 + { 129 + ioParam pb; /* my parameter block for PB's */ 130 + int vrefnum; 131 + register int err; 132 + 133 + pb.ioRefNum = who->refnum; 134 + 135 + if (who->mod) 136 + if (write_to_buffer(who)) 137 + return(EOF); 138 + 139 + 140 + if (err=(GetVRefNum(who->refnum,&vrefnum))) /* get VRefNum*/ 141 + { 142 + errno = err; 143 + return(EOF); 144 + } 145 + pb.ioVRefNum = vrefnum; 146 + pb.ioNamePtr = 0L; 147 + if (err = (PBFlshVol(&pb,false))) /* flush vol */ 148 + { 149 + errno = err; 150 + return(EOF); 151 + } 152 + return(0); 153 + } 154 + 155 + 156 + #line 0 rewind() 157 + void rewind(who) 158 + FILE *who; 159 + { 160 + ioParam pb; /* my parameter block for PB's */ 161 + 162 + fseek(who,0L,0); 163 + }
+145
sources/stdfilebuf.c
··· 1 + /* 2 + Routines for LightspeedC� 3 + 4 + (C) Copyright 1985, 1986. THINK Technologies, Inc. All rights reserved. 5 + */ 6 + 7 + #ifndef _stdioh_ 8 + #include "stdio.h" 9 + #endif 10 + 11 + #ifndef _FileMgr_ 12 + #include "FileMgr.h" 13 + #endif 14 + 15 + 16 + #line 0 Get_file_pos() 17 + long Get_file_pos(who) 18 + register FILE *who; 19 + { 20 + ioParam pb; /* my parameter block for PB's */ 21 + 22 + pb.ioRefNum = who->refnum; 23 + 24 + if(who->last_error = (PBGetFPos(&pb,false))) 25 + { 26 + errno = who->last_error; 27 + return(EOF); 28 + } 29 + return(pb.ioPosOffset); 30 + } 31 + 32 + 33 + #line 0 Set_File_pos() 34 + int Set_File_pos(who,offset) 35 + register FILE *who; 36 + long offset; 37 + { 38 + ioParam pb; /* my parameter block for PB's */ 39 + register int err; 40 + 41 + pb.ioRefNum = who->refnum; 42 + pb.ioPosMode = fsFromStart; 43 + pb.ioPosOffset = offset; 44 + 45 + if (err = who->last_error = PBSetFPos(&pb,false)); 46 + errno = err; 47 + return(err); 48 + } 49 + 50 + 51 + #line 0 read_into_buffer() 52 + int read_into_buffer(who) 53 + register FILE *who; 54 + { 55 + register long x; 56 + ioParam pb; /* my parameter block for PB's */ 57 + register int err; 58 + 59 + pb.ioRefNum = who->refnum; /* get refnum */ 60 + pb.ioBuffer = who->filebuf; /* data buffer*/ 61 + 62 + x = Get_file_pos(who)+who->inbuf; 63 + if (err = Set_File_pos(who,x)) 64 + { 65 + who->inbuf = 0; 66 + who->fpos = BUFSIZ+10; 67 + who->mod = false; 68 + if (who->last_error = err) 69 + errno = err; 70 + return(err); 71 + } 72 + pb.ioReqCount = BUFSIZ; /* 512 bytes */ 73 + pb.ioPosMode = fsAtMark; /* start from current file mark */ 74 + 75 + if (err = (PBRead(&pb,false))) 76 + if(err != eofErr) 77 + { 78 + errno = who->last_error = err; 79 + return(err); 80 + } 81 + if (err = Set_File_pos(who,x)) 82 + { 83 + who->last_error = errno = err; 84 + return(err); 85 + } 86 + who->inbuf = pb.ioActCount; 87 + who->fpos = 0; 88 + who->mod = false; 89 + 90 + return(0); 91 + } 92 + 93 + 94 + 95 + #line 0 write_to_buffer() 96 + int write_to_buffer(who) 97 + register FILE *who; 98 + 99 + { 100 + register long x; 101 + ioParam pb; /* my parameter block for PB's */ 102 + register int err; 103 + 104 + pb.ioRefNum = who->refnum; /* get refnum */ 105 + pb.ioBuffer = who->filebuf; /* data buffer*/ 106 + pb.ioPosMode = fsAtMark; /* start from current file mark */ 107 + 108 + if (who->mod) 109 + { 110 + pb.ioReqCount = who->fpos; /* # bytes */ 111 + 112 + if (err = who->last_error = PBWrite(&pb,false)) 113 + { 114 + errno = err; 115 + return(errno); 116 + } 117 + } 118 + who->mod = false; 119 + 120 + if (who->rd) 121 + { 122 + x = Get_file_pos(who); 123 + 124 + pb.ioReqCount = BUFSIZE; /* 512 bytes */ 125 + pb.ioPosMode = fsAtMark; /* start from current file mark */ 126 + 127 + if (err = (PBRead(&pb,false))) 128 + if(err != eofErr) 129 + goto err6_exit; 130 + 131 + if (err = Set_File_pos(who,x)) 132 + if (err != eofErr) 133 + { 134 + err6_exit: who->last_error = errno = err; 135 + return(err); 136 + } 137 + who->inbuf = pb.ioActCount; 138 + } 139 + else 140 + who->inbuf = 0; 141 + 142 + who->fpos = 0; 143 + return(0); 144 + } 145 +
+179
sources/stdfwrite.c
··· 1 + /* 2 + Routines for LightspeedC� 3 + 4 + This file contains fwrite and fread. 5 + 6 + (C) Copyright 1985, 1986. THINK Technologies, Inc. All rights reserved. 7 + 8 + pdg - 6/20/86 - add capability for unix file i/o transfers >32K bytes 9 + add support for .AOut, .BOut device drivers 10 + */ 11 + 12 + #ifndef _stdioh_ 13 + #include "stdio.h" 14 + #endif 15 + 16 + #ifndef _FileMgr_ 17 + #include "FileMgr.h" 18 + #endif 19 + 20 + #ifndef _SerialDvr_ 21 + #include "SerialDvr.h" 22 + #endif 23 + 24 + int write_to_buffer(); 25 + int read_into_buffer(); 26 + 27 + long actcount_; /* used to return actual # bytes read using open() */ 28 + 29 + 30 + Boolean _unsignedbytes = false; /* added to allow unsigned read() and 31 + write() from unix library to use 32 + stdio and still function correctly */ 33 + 34 + #line 0 fwrite() 35 + int fwrite(ptr,size,count,who) 36 + register char *ptr; 37 + register unsigned size; 38 + register int count; 39 + register FILE *who; 40 + { 41 + register long n, m; 42 + 43 + actcount_ = 0; 44 + 45 + 46 + if (_unsignedbytes) 47 + { _unsignedbytes = false; /* reset */ 48 + m = n = (long)size * (long)((unsigned)count); 49 + } 50 + else 51 + { 52 + if (count < 0) 53 + return(0); 54 + 55 + m = n = (long)size*count; 56 + } 57 + 58 + if (who->wr == false) /* error if no write permission */ 59 + { 60 + errno = who->last_error = wrPermErr; 61 + return(0); 62 + } 63 + 64 + if((!who)||(!who->InUse)) /* error if file not open */ 65 + { 66 + errno = fnOpnErr; /* errno = file not open */ 67 + return(0); 68 + } 69 + 70 + if (who->StdStream) 71 + { 72 + while (--n>=0 && ((fputc(*ptr,who)) == *ptr++)); /* keep going till EOF or */ 73 + actcount_ = (int)n; 74 + return((int)(m/size)); 75 + } 76 + 77 + for (n=0; n<m; ++n) 78 + { 79 + if (who->fpos>(BUFSIZ-1)) 80 + if (write_to_buffer(who)) 81 + { 82 + actcount_ = (int)n; 83 + return(0); 84 + } 85 + 86 + *(who->filebuf + who->fpos++) = ((!who->binary) && (*ptr == '\n'))?'\r':*ptr; 87 + ptr++; 88 + who->mod = true; 89 + } 90 + 91 + actcount_ = (int)n; 92 + 93 + /* if .AOut or .Bout serial drivers, then flush now */ 94 + 95 + if ((who->refnum == AoutRefNum) || (who->refnum == BoutRefNum)) 96 + if (write_to_buffer(who)) 97 + return(0); 98 + 99 + return((int)(n/size)); /* ..otherwise return # bytes written */ 100 + } 101 + 102 + 103 + 104 + 105 + #line 0 fread() 106 + int fread(ptr,size,count,who) 107 + 108 + register char *ptr; 109 + register unsigned size; 110 + register int count; 111 + register FILE *who; 112 + 113 + { 114 + register long n; 115 + register int c; 116 + register long m; 117 + 118 + actcount_ = 0; 119 + 120 + if (_unsignedbytes) 121 + { _unsignedbytes = false; /* reset */ 122 + n = (long)size * (long)((unsigned)count); 123 + } 124 + else 125 + { 126 + if (count<0) 127 + return(0); 128 + 129 + n = (long)size*count; 130 + } 131 + 132 + if((!who)||(!who->InUse)) /* error if file not open */ 133 + { 134 + errno = fnOpnErr; /* errno = file not open */ 135 + return(0); 136 + } 137 + 138 + if(!who->rd) /* check for read permission */ 139 + { 140 + errno = who->last_error = permErr; 141 + return(0); 142 + } 143 + 144 + if (who->StdStream) 145 + { 146 + while (--n>=0 && (c=fgetc(who))!= EOF) /* keep going till EOF or */ 147 + *ptr++ = c; /* placing character into buffer */ 148 + actcount_ = count * size; 149 + return(count); 150 + } 151 + 152 + for (m=0; m<n; m++) 153 + { 154 + if (who->fpos>=who->inbuf) 155 + { 156 + if (c = read_into_buffer(who)) 157 + if (c != eofErr) 158 + { 159 + actcount_ = (int)m; 160 + errno = who->last_error = c; 161 + return(0); 162 + } 163 + if(who->inbuf == 0) /* if the buffer is empty then ... */ 164 + { 165 + errno = who->last_error = (c?c:eofErr); 166 + actcount_ = (int)m; 167 + return((int)(m/size)); /* 27-Feb-86 */ 168 + } 169 + } 170 + c = *(who->filebuf + who->fpos++); 171 + if ((!who->binary)&&(c == '\r')) 172 + c = '\n'; 173 + *ptr++ = c; 174 + } 175 + 176 + actcount_ = (int)m; 177 + return(count); 178 + } 179 +
+340
sources/stdget_console.c
··· 1 + /* 2 + Routines for LightspeedC� 3 + 4 + (C) Copyright 1985, 1986. THINK Technologies, Inc. All rights reserved. 5 + 6 + This file contains: 7 + 8 + ungetch, getch, getche. 9 + */ 10 + 11 + #ifndef _stdioh_ 12 + #include "stdio.h" 13 + #endif 14 + 15 + #ifndef _EventMgr_ 16 + #include "EventMgr.h" 17 + #endif 18 + 19 + #ifndef _signalh_ 20 + #include "signal.h" 21 + #endif 22 + 23 + #ifndef _Quickdraw_ 24 + #include "QuickDraw.h" 25 + #endif 26 + 27 + extern Boolean _inited; 28 + extern Boolean _echo; 29 + 30 + /* signal handling hooks */ 31 + 32 + int (*_key_int_sig_func_)() = 0; 33 + 34 + #define AutoInt7 (*(long*) 0x7C) 35 + #define ROMBase (*(long*) 0x2AE) 36 + #define MaskPtr (*(long*) 0x31A) 37 + 38 + /* pdg - 6/18/86 - completely revised command character handling of the 39 + following function to allow control characters to be 40 + easily generated from the keyboard */ 41 + 42 + #ifdef _STD_PASTE_ 43 + 44 + /* If _STD_PASTE is defined in stdio.h, then characters from the clipboard 45 + can be pasted into the input stream, unlike TE which pastes into a 46 + window. This allows all of the standard i/o functions to be passed the 47 + contents of the paste on a character by character basis. While the 48 + paste is occurring, the keyboard is constantly monitored for a 49 + Command-. which will abort the paste. */ 50 + 51 + static 52 + AbortEvent() 53 + { 54 + EventRecord event; 55 + 56 + /* swallow key events looking for Command-. */ 57 + 58 + while (GetNextEvent(keyDownMask, &event)) 59 + if ((char) event.message == '.' && (event.modifiers & cmdKey)) 60 + return(1); 61 + 62 + return(0); 63 + } 64 + 65 + static long paste_offset = 0; 66 + static int paste_length = 0; 67 + static Handle scrap_handle = 0; 68 + 69 + void _std_setup_paste() 70 + { 71 + long scrap_offset; 72 + 73 + if (scrap_handle) 74 + DisposHandle(scrap_handle); 75 + 76 + scrap_handle = NewHandle(0); 77 + 78 + paste_length = GetScrap(scrap_handle, 'TEXT', &scrap_offset); 79 + paste_offset = 0; 80 + } 81 + 82 + #endif _STD_PASTE_ 83 + 84 + 85 + #line 0 _get_char_from_keyboard() 86 + int _get_char_from_keyboard() 87 + { 88 + register int c; 89 + EventRecord the_Event; /* holds the event record */ 90 + 91 + Init_stdio(); 92 + 93 + #ifdef _STD_PASTE_ 94 + 95 + /* allow getting keystrokes from the clipboard (scrap) if a paste 96 + operation has been done */ 97 + 98 + dopaste: 99 + 100 + if (paste_length > 0) 101 + { 102 + /* a paste operation is in progress, check for keyboard aborts */ 103 + 104 + if (AbortEvent()) 105 + paste_length = 0; 106 + else 107 + { 108 + c = * (*scrap_handle + paste_offset); 109 + paste_length--; 110 + paste_offset++; 111 + 112 + /* change Mac return to a new line */ 113 + 114 + if (c == '\r') c = '\n'; 115 + 116 + return (c); 117 + } 118 + } 119 + #endif _STD_PASTE_ 120 + 121 + nextevent: 122 + 123 + while(true) 124 + { 125 + while (! GetNextEvent(everyEvent, &the_Event)) 126 + { 127 + HiliteMenu(0); 128 + SystemTask(); 129 + 130 + #ifdef _STD_PASTE_ 131 + if (paste_length > 0) goto dopaste; 132 + #endif _STD_PASTE_ 133 + 134 + } 135 + 136 + #ifdef _STD_PASTE_ 137 + if (paste_length > 0) goto dopaste; 138 + #endif _STD_PASTE_ 139 + 140 + SetCursor(&arrow); 141 + 142 + if (the_Event.what == keyDown || the_Event.what == autoKey) 143 + break; 144 + 145 + StdEvent(&the_Event); 146 + } 147 + 148 + /* pick up the character */ 149 + 150 + c = (unsigned char) the_Event.message; 151 + 152 + if (the_Event.modifiers & cmdKey) 153 + { 154 + 155 + /* if signal logic is enabled, then call interrupt procedure */ 156 + 157 + if (_key_int_sig_func_) 158 + {register int (*_temp_key_int_sig_func_)() = _key_int_sig_func_; 159 + 160 + switch (c) 161 + { 162 + case 'c': 163 + case 'C': 164 + case '.': 165 + if ((long)_key_int_sig_func_ == SIG_DFL) 166 + { 167 + /* call debugger if loaded, then 168 + (or otherwise) depart */ 169 + 170 + if ((AutoInt7 & MaskPtr) < ROMBase) 171 + DebugStr("\pSIGDFL reset!"); 172 + 173 + ExitToShell(); 174 + } 175 + 176 + _key_int_sig_func_ = (void*) SIG_DFL; 177 + (*_temp_key_int_sig_func_)(SIGINT); 178 + goto nextevent; 179 + 180 + default: break; 181 + } 182 + } 183 + 184 + switch (c) 185 + { 186 + /* command(fan) D and command Z are considered EOF chars */ 187 + 188 + case 'd': 189 + case 'D': 190 + case 'z': 191 + case 'Z': 192 + return (EOF); 193 + 194 + /* the key may therefore be some other control key, convert it 195 + if it is, otherwise ignore the command modifier */ 196 + 197 + /* NULL is command space, as is command 2 (shift doesn't work 198 + on for @ since event manager traps command shift combos */ 199 + 200 + case ' ': 201 + case '2': 202 + c = 0; 203 + break; 204 + 205 + /* map command 6 into control-^ */ 206 + 207 + case '6': 208 + c = 30; 209 + break; 210 + 211 + /* map command ` into control-~ */ 212 + 213 + case '`': 214 + c = 31; 215 + break; 216 + 217 + /* map command backspace into DEL */ 218 + 219 + case 8: 220 + c = 0x7F; 221 + break; 222 + 223 + default: 224 + /* check for standard control chars */ 225 + 226 + if ((c >= 'A') && (c <= '_')) c-= ('A' - 1); 227 + else 228 + if ((c >= 'a') && (c <= '~')) c-= ('a' - 1); 229 + 230 + break; 231 + } 232 + } 233 + else 234 + /* translate any input return to a newline, but not control M! */ 235 + if (c == '\r') c = '\n'; 236 + 237 + return(c); 238 + } 239 + 240 + 241 + #line 0 ungetch() 242 + int ungetch(c) 243 + int c; 244 + { 245 + if (_console->look_full) 246 + return(EOF); 247 + 248 + _console->look_full = true; 249 + _console->look_ahead = c; 250 + return(c); 251 + } 252 + 253 + 254 + 255 + #line 0 getch_common() 256 + static int getch_common() 257 + { 258 + if (_console->look_full) 259 + { 260 + _console->look_full = false; 261 + return((int)_console->look_ahead); 262 + } 263 + return( _get_char_from_keyboard() ); 264 + } 265 + 266 + 267 + 268 + #line 0 getch() 269 + int getch() 270 + { 271 + return( getch_common() ); 272 + } 273 + 274 + 275 + 276 + #line 0 getche() 277 + int getche() 278 + { 279 + register int c; 280 + 281 + c = getch_common(); 282 + if (c != EOF) 283 + putch(c); 284 + return(c); 285 + } 286 + 287 + 288 + 289 + #line 0 cgets() 290 + char *cgets(s) 291 + register char *s; 292 + { 293 + register int c; 294 + register char *scopy = s; 295 + register Boolean orig_echo = _echo; 296 + 297 + /* handle our own echoing */ 298 + 299 + Init_stdio(); 300 + 301 + /*loop until EOF or \n */ 302 + 303 + while ((c=getch_common())!= EOF) 304 + { 305 + if (c == '\b') 306 + { 307 + if (scopy != s) 308 + { 309 + if (_echo) 310 + { 311 + putch('\b'); 312 + putch(' '); 313 + putch('\b'); 314 + } 315 + 316 + *--scopy = ' '; 317 + } 318 + } 319 + else 320 + { 321 + if (_echo) putch(c); 322 + 323 + if ((*scopy++ = c) == '\n') 324 + { 325 + scopy--; 326 + break; 327 + } 328 + } 329 + } 330 + 331 + if ((scopy != s) || (c == '\n')) 332 + { 333 + *scopy = '\0'; 334 + } 335 + else 336 + s = NULL; 337 + 338 + return(s); 339 + } 340 +
+219
sources/stdgets.c
··· 1 + /* 2 + Routines for LightspeedC� 3 + 4 + (C) Copyright 1985, 1986. THINK Technologies, Inc. All rights reserved. 5 + 6 + This file contains: 7 + 8 + fgetc, fgets, gets, ungetc. 9 + */ 10 + 11 + #ifndef _stdioh_ 12 + #include "stdio.h" 13 + #endif 14 + 15 + #ifndef _FileMgr_ 16 + #include "FileMgr.h" 17 + #endif 18 + 19 + extern Boolean _echo; 20 + extern int _get_char_from_keyboard(); 21 + 22 + static int maxchars = 0; /* allow unlimited length gets if zero */ 23 + 24 + #line 0 fgetc() 25 + int fgetc(who) 26 + register FILE *who; 27 + { 28 + register unsigned int c; 29 + register int err; 30 + 31 + if((!who)||(!who->InUse)) /* error if file not open */ 32 + { 33 + errno = fnOpnErr; 34 + return(EOF); 35 + } 36 + 37 + if(!who->rd) /* check for read permission */ 38 + { 39 + errno = who->last_error = permErr; 40 + return(EOF); 41 + } 42 + 43 + if (who->StdStream) /* if from keyboard */ 44 + { 45 + if(who->look_full) /* is look_ahead buffer full */ 46 + { /* if buffer is full... */ 47 + who->look_full = false; /* set to empty */ 48 + return((int)who->look_ahead); /* return then character */ 49 + } 50 + c = _get_char_from_keyboard(); 51 + 52 + if ((_echo) && (c != EOF)) 53 + putch(c); 54 + return(c); 55 + } 56 + 57 + if (who->fpos >= who->inbuf) 58 + { 59 + if (err = read_into_buffer(who)) 60 + if (err != eofErr) 61 + return(EOF); 62 + 63 + if(!who->inbuf) 64 + { 65 + errno = who->last_error = eofErr; 66 + return(EOF); 67 + } 68 + } 69 + c = (unsigned char)*(who->filebuf + who->fpos++); 70 + if ((!who->binary)&&(c == '\r')) 71 + c = '\n'; 72 + return(c); 73 + } 74 + 75 + #line 0 fgets() 76 + char *fgets(s,n,who) 77 + register char *s; 78 + register int n; 79 + register FILE *who; 80 + { 81 + register int c; 82 + register char *scopy = s; 83 + 84 + if (n ==0) return (NULL); 85 + 86 + if (who == stdin && who->StdStream) 87 + { 88 + maxchars = n; 89 + return (gets(s)); 90 + } 91 + 92 + /* loop until EOF or \n */ 93 + 94 + while (--n>=0 && (c=fgetc(who))!= EOF) 95 + { 96 + if (c == '\b') 97 + { 98 + if (scopy != s) 99 + { 100 + n += 2; 101 + scopy--; 102 + } 103 + else 104 + n++; 105 + } 106 + else 107 + if ((*scopy++ = c) == '\n') /* placing character into user */ 108 + break; /* defined buffer. */ 109 + } 110 + 111 + if (s != scopy) /* if buffer is modified.. */ 112 + *scopy = '\0'; /* Insert null in buffer */ 113 + 114 + return((scopy == s) ? NULL : s); /* Return pointer to buffer */ 115 + } 116 + 117 + 118 + #line 0 gets() 119 + char *gets(s) 120 + register char *s; 121 + { 122 + register int c; 123 + register char *scopy = s; 124 + register Boolean orig_echo = _echo, checkchars = (maxchars > 0); 125 + 126 + /* checkchars will be true if invoked by fgets for stdin */ 127 + 128 + /* handle our own echoing */ 129 + 130 + if (stdin->StdStream && _echo) Init_stdio(); 131 + 132 + Set_Echo(false); 133 + 134 + /*loop until EOF or \n */ 135 + 136 + while ((c=fgetc(stdin))!= EOF) 137 + { 138 + if (c == '\b') 139 + { 140 + if (scopy != s) 141 + { 142 + if (stdin->StdStream && orig_echo) 143 + { 144 + putch('\b'); 145 + putch(' '); 146 + putch('\b'); 147 + } 148 + 149 + *--scopy = ' '; 150 + } 151 + } 152 + else 153 + { 154 + if (stdin->StdStream && orig_echo) 155 + putch(c); 156 + 157 + if ((*scopy++ = c) == '\n') 158 + { 159 + if (!checkchars) scopy--; 160 + break; 161 + } 162 + 163 + if (checkchars) 164 + if (--maxchars == 0) break; 165 + } 166 + 167 + } 168 + 169 + if ((scopy != s) || (c == '\n')) 170 + { 171 + *scopy = '\0'; 172 + } 173 + else 174 + s = NULL; 175 + 176 + Set_Echo(orig_echo); 177 + 178 + maxchars = 0; /* gets always resets to zero */ 179 + 180 + return(s); 181 + } 182 + 183 + 184 + #line 0 ungetc() 185 + int ungetc(c,who) 186 + register int c; 187 + register FILE *who; 188 + 189 + { 190 + if ((!who)||(!who->InUse)) /* If file not open */ 191 + { 192 + errno = fnOpnErr; 193 + return(EOF); 194 + } 195 + 196 + if ((int)c==EOF) /* ignore EOF characters*/ 197 + return(EOF); 198 + 199 + 200 + if((who->StdStream)&&(who->rd)) 201 + { 202 + if (who->look_full) /* if buffer is full */ 203 + return(EOF); /* return EOF */ 204 + 205 + who->look_full = true; /* set buffer to full */ 206 + who->look_ahead = c; /* put char in buffer */ 207 + return((int)c); /* return character */ 208 + } 209 + 210 + if ((who->fpos>BUFSIZ)||(who->fpos==0)) 211 + return(EOF); 212 + 213 + 214 + who->fpos -= 1; 215 + *(who->filebuf+who->fpos) = c; 216 + 217 + return(c); /* return the character */ 218 + } 219 +
+126
sources/stdio.h
··· 1 + /* 2 + * stdio.h 3 + * 4 + * defines the structure used by the LightSpeedC I/O ("standard I/O") 5 + * routines and some of the associated values and macros. 6 + * 7 + * (C) Copyright 1985, 1986. THINK Technologies Inc. All rights reserved. 8 + */ 9 + 10 + #ifndef _stdioh_ 11 + #define _stdioh_ 12 + 13 + /* By uncommenting the next #define you are allowed to use the paste 14 + menu item in the stdio menus. It allows the contents of the clipboard 15 + to be pasted into the input stream. (see stdget_console.c for info) 16 + HOWEVER, IT ADDS OVER 200 BYTES TO THE SIZE OF STDIO! */ 17 + 18 + /* #define _STD_PASTE_ */ 19 + 20 + #define BUFSIZ 512 21 + #define BUFSIZE 512 22 + #define NULL 0L 23 + #define _NFILE 30 /* increased from 15 */ 24 + #define EOF (-1) 25 + 26 + #define STDERRNO 2 27 + #define stdin (&_file[0]) 28 + #define stdout (&_file[1]) 29 + #define stderr (&_file[STDERRNO]) 30 + #define _console (&_console_) 31 + 32 + typedef struct { 33 + int refnum; /* OS Reference number */ 34 + int last_error; /* holds last error on file */ 35 + int fileno; /* fnum for level 1 I/O */ 36 + unsigned user_buf:1, /* 1 if user defined buffer */ 37 + InUse:1, /* 0 if free */ 38 + StdStream:1, /* 0 = file, 1 = stdio */ 39 + rd:1,wr:1, /* flag for read and write */ 40 + look_full:1, /* flag for look_ahead */ 41 + mod:1, /* file modified flag */ 42 + binary:1, /* flag for binary file */ 43 + window:1; /* this is a window */ 44 + unsigned char look_ahead;/* char for look_ahead */ 45 + char *filebuf; /* Pointer to buffer */ 46 + int fpos; /* pos of file in buffer */ 47 + int inbuf; /* # of chars in buffer */ 48 + } FILE; 49 + 50 + 51 + void clearerr(); /* clear last error that occured */ 52 + void clrerr(); /* clear last error that occured */ 53 + void cputs(); /* puts a string to the console (screen) */ 54 + void gotoxy(); /* goto x,y on screen */ 55 + void Init_stdio(); /* initalize stdio (automatically done */ 56 + void putch(); /* print a character to the console */ 57 + void rewind(); /* set pointer to beginning of a file */ 58 + void Set_Echo(); /* set I/O to echo or not (true=echo) */ 59 + void Set_Tab(); /* set the width of the tab stop */ 60 + void Click_On(); /* Sets the click_to_continue option of or off */ 61 + void Stdio_config(); /* font,size,face,mode */ 62 + char *cgets(); /* gets a string from the console (keyboard) */ 63 + char *fgets(); /* gets a string from an input stream */ 64 + char *gets(); /* gets a string from stdin */ 65 + FILE *fopen(); /* open a file */ 66 + FILE *fopenw(); /* open a file */ 67 + FILE *freopen(); /* open a file using the given stream */ 68 + extern FILE _file[_NFILE]; /* file descriptor array (internal) */ 69 + extern FILE _console_; /* device name for the console */ 70 + long ftell(); /* get position withen file */ 71 + 72 + /* new for windowed printf-2-w.c */ 73 + 74 + char *Get_ScreenPtr(); 75 + void *Get_WindowPtr(); /* actually a WindowPtr -- this saves bringing in 76 + the include for WindowMgr.h */ 77 + 78 + int _closeall(); /* close all open files */ 79 + extern int errno; 80 + 81 + /* Default for these functions are int so they don't need to be declared 82 + Boolean StdEvent(); -- this is fine since Booleans become ints 83 + cprintf(); 84 + cscanf(); 85 + fclose(); 86 + feof(); 87 + ferror(); 88 + fflush(); 89 + fgetc(); 90 + fileno(); 91 + fprintf(); 92 + fputc(); 93 + fputs(); 94 + fread(); 95 + fseek(); 96 + fwrite(); 97 + getch(); 98 + getche(); 99 + getxpos(); 100 + getypos(); 101 + isupper(); 102 + islower(); 103 + kbhit(); 104 + max(); 105 + min(); 106 + puts(); 107 + printf(); 108 + sprintf(); 109 + toint(); 110 + tolower(); 111 + toupper(); 112 + ungetc(); 113 + vcprintf(); 114 + vfprintf(); 115 + vprintf(); 116 + vsprintf(); 117 + _tolower(); 118 + _toupper(); 119 + onexit(); 120 + */ 121 + #define getc(stream) (fgetc(stream)) 122 + #define getchar() (fgetc(stdin)) 123 + #define putc(c,stream) (fputc(c,stream)) 124 + #define putchar(c) (fputc(c,stdout)) 125 + 126 + #endif
+23
sources/stdmax_min.c
··· 1 + /* 2 + max and min routines for LightspeedC� 3 + 4 + (C) Copyright 1985, 1986. THINK Technologies, Inc. All rights reserved. 5 + */ 6 + 7 + #line 0 min 8 + int min(v1,v2) 9 + int v1,v2; 10 + { 11 + if (v1 < v2) return (v1); 12 + 13 + return (v2); 14 + } 15 + 16 + #line 0 max 17 + int max(v1,v2) 18 + int v1,v2; 19 + { 20 + if (v1 > v2) return (v1); 21 + 22 + return (v2); 23 + }
+372
sources/stdopen.c
··· 1 + /* 2 + Routines for LightspeedC� 3 + 4 + (C) Copyright 1985, 1986. THINK Technologies, Inc. All rights reserved. 5 + */ 6 + 7 + #ifndef _stdioh_ 8 + #include "stdio.h" 9 + #endif 10 + 11 + #ifndef _FileMgr_ 12 + #include "FileMgr.h" 13 + #endif 14 + 15 + #ifndef _SerialDvr_ 16 + #include "SerialDvr.h" 17 + #endif 18 + 19 + static Boolean _exiting_closeall_flag = false; 20 + void _exit_closeall(); 21 + 22 + /* This file contains the code for fopen, fclose, _closeall, freopen. */ 23 + 24 + #line 0 xfopen 25 + static FILE *xfopen(nameptr,type,who) 26 + char *nameptr; 27 + register char *type; 28 + register FILE *who; 29 + 30 + { 31 + register int new; 32 + static Boolean _init_onexit = false; /* flag to signal onexit was initalized */ 33 + 34 + ioParam pb; /* my parameter block for PB's */ 35 + fileParam pb2; 36 + register int err; 37 + int refnum; 38 + Boolean create; 39 + Boolean add; 40 + register Boolean delete; 41 + register Boolean bin_file; 42 + register Ptr p; 43 + 44 + if(!who) 45 + { 46 + register int free_slot; 47 + /* look thru FILE array for an open slot */ 48 + for (free_slot=STDERRNO+1; 49 + ((free_slot<_NFILE)&&(_file[free_slot].InUse)); 50 + free_slot++) 51 + ; 52 + 53 + if (free_slot >= _NFILE) { 54 + errno = tmfoErr; /* too many files open */ 55 + return (NULL); 56 + } 57 + 58 + who = &_file[free_slot]; 59 + } 60 + 61 + { 62 + register int permission; 63 + 64 + permission = fsWrPerm; /* default = write */ 65 + create = delete = true; /* default is true */ 66 + bin_file = add = false; 67 + refnum = 0; 68 + 69 + if (type[1]=='\0') 70 + { 71 + if (type[0] == 'r') permission = fsRdPerm; 72 + } 73 + else 74 + if (type[1] == '+') 75 + { 76 + permission = fsRdWrPerm; 77 + if (type[2] == 'b') bin_file = true; 78 + } 79 + else 80 + { 81 + if (type[1] == 'b') bin_file = true; 82 + 83 + if (type[0] == 'r') permission = fsRdPerm; 84 + 85 + } 86 + 87 + switch (type[0]) 88 + { 89 + case 'r': 90 + create = false; 91 + break; 92 + case 'w': 93 + delete = true; 94 + break; 95 + case 'a': 96 + add = true; 97 + break; 98 + default: 99 + return(NULL); 100 + } 101 + 102 + 103 + CtoPstr(nameptr); 104 + 105 + p = NewPtr((long)BUFSIZ); 106 + 107 + do { 108 + 109 + /* pdg 7/29/86 - look only via default path */ 110 + 111 + pb.ioNamePtr = 0; 112 + if (PBGetVol(&pb, false)) pb.ioVRefNum = 0; 113 + 114 + 115 + pb.ioNamePtr = (StringPtr)nameptr; 116 + pb.ioVersNum = 0; 117 + pb.ioPermssn = permission; 118 + pb.ioMisc = 0L; 119 + 120 + new = PBOpen(&pb,false); 121 + 122 + if ((new == fnfErr) && (create)) 123 + { 124 + if (err = (PBCreate(&pb,false))) goto err_exit; 125 + 126 + pb2.ioFDirIndex = 0; 127 + pb2.ioNamePtr = pb.ioNamePtr; 128 + pb2.ioVRefNum = pb.ioVRefNum; 129 + pb2.ioFVersNum = pb.ioVersNum; 130 + if (err = (PBGetFInfo(&pb2,false))) goto err_exit; 131 + 132 + pb2.ioFlFndrInfo.fdType = 'TEXT'; 133 + pb2.ioFlFndrInfo.fdCreator = '????'; 134 + if (err = (PBSetFInfo(&pb2,false))) goto err_exit; 135 + 136 + delete = false; /* don't delete this file */ 137 + } 138 + 139 + if (!new) 140 + { /* no errors on open */ 141 + if (pb.ioRefNum > 0) 142 + { /* don't do this stuff if a device driver */ 143 + 144 + if (type[0]=='a') 145 + { 146 + if(err = (PBGetEOF(&pb,false))) goto err_exit; 147 + 148 + pb.ioPosOffset = (long)pb.ioMisc; 149 + pb.ioPosMode = fsFromStart; 150 + err = PBSetFPos(&pb,false); 151 + if ((err!=noErr) && (err!=eofErr)) goto err_exit; 152 + } 153 + 154 + if ((type[0]=='w') && (delete)) 155 + { 156 + pb2.ioFDirIndex = 0; 157 + pb2.ioNamePtr = pb.ioNamePtr; 158 + pb2.ioVRefNum = pb.ioVRefNum; 159 + pb2.ioFVersNum = pb.ioVersNum; 160 + if (err = (PBGetFInfo(&pb2,false))) goto err_exit; 161 + 162 + if (err = (PBClose(&pb,false))) goto err_exit; 163 + 164 + if (err = (PBDelete(&pb,false))) goto err_exit; 165 + 166 + if (err = (PBCreate(&pb,false))) goto err_exit; 167 + 168 + if (err = (PBSetFInfo(&pb2,false))) goto err_exit; 169 + 170 + new = PBOpen(&pb,false); 171 + create = false; 172 + } 173 + } 174 + 175 + if (!new) 176 + { 177 + refnum = pb.ioRefNum; 178 + who->refnum = refnum; 179 + who->last_error = noErr; 180 + who->user_buf = false; 181 + who->StdStream = false; 182 + who->filebuf = p; 183 + who->InUse = true; 184 + who->mod = false; 185 + who->look_full = false; 186 + who->rd = false; 187 + who->wr = false; 188 + who->window = false; 189 + if((permission==fsRdWrPerm)||(permission==fsRdPerm)) 190 + who->rd = true; 191 + if((permission==fsRdWrPerm)||(permission==fsWrPerm)) 192 + who->wr = true; 193 + who->binary = bin_file; 194 + who->fpos = BUFSIZ+10; /* force fread/fwrite to go to disk */ 195 + who->inbuf = 0; 196 + PtoCstr(nameptr); 197 + if (_init_onexit == false) 198 + { 199 + _init_onexit = true; 200 + onexit(_exit_closeall); 201 + } 202 + 203 + if ((who->rd)&&(who->wr)) 204 + { 205 + if(err = read_into_buffer(who)) 206 + if (err != eofErr) 207 + { 208 + who->last_error = errno = err; 209 + return(who); 210 + } 211 + } 212 + return(who); 213 + } 214 + } 215 + } 216 + while ((new == fnfErr) && (create)); 217 + 218 + if (new) errno = new; 219 + 220 + goto exit_noset; 221 + 222 + err_exit: 223 + errno = err; 224 + 225 + exit_noset: 226 + 227 + DisposPtr(p); 228 + PtoCstr(nameptr); 229 + return(NULL); 230 + } /* end of scope of permission */ 231 + 232 + } 233 + 234 + 235 + #line 0 fclose 236 + int fclose(who) 237 + register FILE *who; 238 + { 239 + ioParam pb; /* my parameter block for PB's */ 240 + int vrefnum; /* vrefnum storage */ 241 + register int refnum; 242 + register int err; 243 + 244 + if (who) /* error if file not open */ 245 + { 246 + if(who->StdStream) /* Is it a standard device */ 247 + { 248 + if (who->window) 249 + { 250 + /* leave windows alone if in exit code */ 251 + if (_exiting_closeall_flag) 252 + return (0); 253 + 254 + return (fclosew(who)); 255 + } 256 + 257 + who->InUse = false; /* Close stream if so */ 258 + who->StdStream = false; 259 + return(0); /* OK */ 260 + } 261 + 262 + if (!who->InUse) goto file_not_in_use; 263 + 264 + switch (refnum = who->refnum) 265 + { 266 + default: 267 + 268 + if (refnum > 0) 269 + if (err=(GetVRefNum(refnum,&vrefnum))) /* get VRefNum*/ 270 + goto err2_exit; 271 + 272 + pb.ioRefNum = refnum; 273 + 274 + if (who->mod) 275 + { 276 + pb.ioBuffer = who->filebuf; 277 + pb.ioReqCount = (long)who->fpos; 278 + pb.ioPosMode = fsAtMark; 279 + pb.ioPosOffset = 0L; 280 + 281 + if (err = who->last_error = PBWrite(&pb,false)) 282 + errno = err; 283 + } 284 + 285 + who->InUse = false; 286 + if (err = (PBClose(&pb,false))) /* close file */ 287 + goto err2_exit; 288 + 289 + if (refnum > 0) 290 + { 291 + pb.ioVRefNum = vrefnum; 292 + pb.ioNamePtr = 0L; 293 + if (err = (PBFlshVol(&pb,false))) /* flush vol */ 294 + goto err2_exit; 295 + } 296 + 297 + break; 298 + 299 + /* in the case of the standard serial drivers, flush the buffer, 300 + but never close the driver (mouse will die, etc.) */ 301 + 302 + case AinRefNum: 303 + case BinRefNum: 304 + case AoutRefNum: 305 + case BoutRefNum: 306 + 307 + if (who->mod) 308 + write_to_buffer(who); 309 + break; 310 + } 311 + 312 + if (!who->user_buf) 313 + DisposPtr(who->filebuf); /* dispose mem*/ 314 + 315 + return(0); 316 + } 317 + 318 + file_not_in_use: 319 + 320 + err = fnOpnErr; /* file not open error */ 321 + 322 + err2_exit: 323 + 324 + errno = err; 325 + return(EOF); 326 + } 327 + 328 + 329 + 330 + 331 + #line 0 fopen 332 + FILE *fopen(nameptr,type) 333 + char *nameptr,*type; 334 + { 335 + return(xfopen(nameptr,type,NULL)); 336 + 337 + (void) std_ver(); 338 + 339 + } 340 + 341 + 342 + 343 + #line 0 freopen 344 + FILE *freopen(nameptr,type,who) 345 + char *nameptr,*type; 346 + FILE *who; 347 + 348 + { 349 + if(fclose(who)) return(NULL); 350 + return(xfopen(nameptr,type,who)); 351 + } 352 + 353 + 354 + #line 0 _closeall 355 + int _closeall() 356 + { 357 + register int counter, bad_ones = 0; 358 + 359 + for (counter = 0; counter < _NFILE; counter++) 360 + if (fclose(&_file[counter])) 361 + bad_ones++; 362 + 363 + return(bad_ones); 364 + 365 + } 366 + 367 + static 368 + void _exit_closeall() 369 + { 370 + _exiting_closeall_flag = true; 371 + _closeall(); 372 + }
+43
sources/stdput_console.c
··· 1 + /* 2 + Routines for LightspeedC� 3 + 4 + (C) Copyright 1985, 1986. THINK Technologies, Inc. All rights reserved. 5 + 6 + The name of this file is purely historical and does not really 7 + reflect the two functions defined here. 8 + */ 9 + 10 + #ifndef _Quickdraw_ 11 + #include "Quickdraw.h" 12 + #endif 13 + 14 + #ifndef _EventMgr_ 15 + #include "EventMgr.h" 16 + #endif 17 + 18 + extern Boolean _inited; 19 + 20 + #line 0 wputs() 21 + void wputs(s) 22 + register char *s; 23 + { 24 + Init_stdio(); 25 + 26 + while (*s) 27 + { 28 + putch(*s); 29 + s++; 30 + } 31 + } 32 + 33 + #line 0 kbhit() 34 + int kbhit() 35 + { 36 + EventRecord the_Event; /* holds the event record */ 37 + 38 + if (! _inited) InitGraf(&thePort); 39 + 40 + EventAvail(keyDownMask+autoKeyMask,&the_Event); /* get event */ 41 + 42 + return(the_Event.what); 43 + }
+142
sources/stdputs.c
··· 1 + /* 2 + Routines for LightspeedC� 3 + 4 + (C) Copyright 1985, 1986. THINK Technologies, Inc. All rights reserved. 5 + 6 + This file contains: 7 + 8 + fputc, fputs, puts 9 + */ 10 + 11 + #include "fopenw.h" 12 + 13 + #ifndef _FileMgr_ 14 + #include "FileMgr.h" 15 + #endif 16 + 17 + extern Boolean _echo; 18 + 19 + /* 20 + This file contains fputc, fputs, puts, cputs 21 + */ 22 + 23 + static StdwsaveRecord saverec; 24 + 25 + 26 + #line 0 cputs() 27 + void cputs(s) 28 + register char *s; 29 + { 30 + stdwsave(stdout, &saverec); 31 + 32 + while (*s) 33 + { 34 + putch(*s); 35 + s++; 36 + } 37 + 38 + stdwrestore(stdout, &saverec); 39 + } 40 + 41 + 42 + #line 0 fputc() 43 + int fputc(c,who) 44 + 45 + register unsigned char c; 46 + register FILE *who; 47 + 48 + { 49 + ioParam pb; /* my parameter block for PB's */ 50 + 51 + if ((!who)||(!who->InUse)||(!who->wr)) /* error if file not open */ 52 + { 53 + if (!who->wr) 54 + errno = who->last_error = wrPermErr; /* write perm error */ 55 + else 56 + errno = fnOpnErr; /* file not open */ 57 + return(EOF); 58 + } 59 + 60 + 61 + if (who->StdStream) 62 + { 63 + stdwsave(who, &saverec); 64 + putch(c); /* put char directly to the screen */ 65 + stdwrestore(who, &saverec); 66 + return(c); /* never an error on fputc(stdout). */ 67 + } 68 + 69 + if (who->fpos>(BUFSIZ-1)) 70 + if (write_to_buffer(who)) 71 + return(EOF); 72 + *(who->filebuf + who->fpos++) =(unsigned char) ((!who->binary) && (c == '\n'))?'\r':c; 73 + who->mod = true; 74 + return(c); 75 + } 76 + 77 + 78 + 79 + #line 0 fputs 80 + int fputs(s,who) 81 + 82 + register char *s; 83 + register FILE *who; 84 + 85 + { 86 + register int c; 87 + 88 + if ((!who)||(!who->InUse)||(!who->wr)) /* error if file not open */ 89 + { 90 + if (!who->wr) 91 + errno = who->last_error = wrPermErr; /* write perm error */ 92 + else 93 + errno = fnOpnErr; /* file not open */ 94 + return(EOF); 95 + } 96 + 97 + if (who->StdStream) 98 + { 99 + cputs(s); 100 + return(0); 101 + } 102 + 103 + 104 + while (c = *s++) 105 + if (fputc(c,who) != c) 106 + return(EOF); 107 + 108 + return(0); /* Its ok */ 109 + 110 + } 111 + 112 + 113 + #line 0 puts 114 + int puts(s) 115 + register char *s; 116 + { 117 + if (stdout->StdStream) 118 + { 119 + if (stdout->wr == false) 120 + { 121 + errno = stdout->last_error = wrPermErr; 122 + return(EOF); 123 + } 124 + 125 + cputs(s); 126 + cputs("\n"); 127 + return(0); 128 + } 129 + 130 + 131 + if(fputs(s,stdout) == EOF) 132 + return(EOF); 133 + 134 + if(fputc('\n',stdout) != '\n') 135 + return(EOF); 136 + 137 + return(0); 138 + } 139 + 140 + 141 + 142 +
+74
sources/stdto..x.c
··· 1 + /* 2 + Routines for LightspeedC� 3 + 4 + (C) Copyright 1985, 1986. THINK Technologies, Inc. All rights reserved. 5 + */ 6 + 7 + 8 + #ifndef _stdioh_ 9 + #include "stdio.h" 10 + #endif 11 + 12 + #ifndef _ctypeh_ 13 + #include "ctype.h" 14 + #endif 15 + 16 + 17 + #line 0 toint() 18 + int toint(c) 19 + char c; 20 + { 21 + if (! isxdigit(c)) 22 + return(-1); 23 + 24 + if (isxdigit(c)) 25 + return(c-30); 26 + else 27 + return(toupper(c)-55); 28 + } 29 + 30 + #line 0 toupper() 31 + int toupper(c) 32 + char c; 33 + { 34 + return( (c>='a')&&(c<='z') ? (c-('a'-'A')) : c ); 35 + } 36 + 37 + #line 0 tolower() 38 + int tolower(c) 39 + char c; 40 + { 41 + return( (c>='A')&&(c<='Z') ? (c+('a'-'A')) : c ); 42 + } 43 + 44 + 45 + #line 0 _toupper() 46 + int _toupper(c) 47 + char c; 48 + { 49 + return(c-('a'-'A')); 50 + } 51 + 52 + #line 0 _tolower() 53 + int _tolower(c) 54 + char c; 55 + { 56 + return(c+('a'-'A')); 57 + } 58 + 59 + #line 0 isupper() 60 + int isupper(c) 61 + char c; 62 + { 63 + return( (c>='A')&&(c<='Z') ); 64 + } 65 + 66 + 67 + #line 0 islower() 68 + int islower(c) 69 + char c; 70 + { 71 + return( (c>='a')&&(c<='z') ); 72 + } 73 + 74 +
+24
sources/stdver.c
··· 1 + /* 2 + Routines for LightspeedC� 3 + 4 + (C) Copyright 1986. THINK Technologies, Inc. All rights reserved. 5 + 6 + */ 7 + 8 + /* This module is purely for identification of the standard i/o release, 9 + however, for those diehards who wanted it, it does contain a 10 + perfectly usable function that returns a pointer to a string that 11 + contains the version of standard i/o */ 12 + 13 + #define STDIO_VERSION "LightspeedC� Libraries 1.57" 14 + 15 + /* return the library version number of stdio */ 16 + 17 + 18 + #line 0 std_ver() 19 + char *std_ver() 20 + { 21 + return (STDIO_VERSION); 22 + 23 + "(C) Copyright 1986 THINK Technologies,Inc. All rights reserved"; 24 + }
+115
sources/storage.c
··· 1 + /************************************************************************/ 2 + /* */ 3 + /* Copyright (C) 1986 THINK Technologies, Inc. All rights reserved. */ 4 + /* */ 5 + /************************************************************************/ 6 + 7 + /* 8 + Storage function library. All of the basic storage allocation and 9 + disposition routines provided with the LightspeedC compiler are contained 10 + in this module. The header "storage.h" contains definitions for the routines 11 + contained herein. Each of the routines are described below. 12 + 13 + 14 + Standard C Library storage procedures 15 + 16 + calloc(count,size) - allocate a cleared block of size*count bytes 17 + clalloc(count,size) - allocate a cleared block of size*count bytes 18 + cfree(ptr) - release block from calloc, clalloc, malloc, mlalloc 19 + free(ptr) - release block from calloc, clalloc, malloc, mlalloc 20 + malloc(size) - allocate a block of size bytes 21 + mlalloc(size) - allocate a block of size bytes 22 + realloc(ptr,newsize) - resize a block to newsize bytes 23 + relalloc(ptr,newsize) - resize a block to newsize bytes 24 + */ 25 + 26 + #include "Storage.h" 27 + 28 + #ifndef _MemoryMgr_ 29 + #include "MemoryMgr.h" 30 + #endif 31 + 32 + #undef NULL 33 + #define NULL 0L 34 + #define CLEAR 1 35 + 36 + #line 0 clalloc 37 + char *clalloc(count,size) 38 + unsigned long count; 39 + unsigned long size; 40 + { 41 + size *= count; 42 + 43 + asm 44 + { 45 + move.l size,d0 46 + NewPtr CLEAR 47 + move.w d0,MemErr 48 + move.l a0,d0 49 + } 50 + } 51 + 52 + #line 0 calloc 53 + char *calloc(count, size) 54 + unsigned int count; 55 + unsigned int size; 56 + { 57 + 58 + return (clalloc((long)count, (long)size)); 59 + } 60 + 61 + 62 + #line 0 free 63 + int free(ptr) 64 + char *ptr; 65 + { 66 + /* Get the handle back from the pointer */ 67 + 68 + DisposPtr(ptr); 69 + 70 + return (MemErr ? -1 : 0); 71 + } 72 + 73 + #line 0 cfree 74 + int cfree(ptr) 75 + char *ptr; 76 + { 77 + free(ptr); 78 + } 79 + 80 + #line 0 mlalloc 81 + char *mlalloc(size) 82 + unsigned long size; 83 + { 84 + return NewPtr(size); 85 + } 86 + 87 + #line 0 malloc 88 + char *malloc(size) 89 + unsigned int size; 90 + { 91 + return NewPtr(size); 92 + } 93 + 94 + #line 0 relalloc 95 + char *relalloc(ptr,newsize) 96 + char *ptr; 97 + unsigned long newsize; 98 + { 99 + SetPtrSize(ptr, newsize); 100 + 101 + /* return new pointer */ 102 + 103 + return (MemErr ? NULL : ptr); 104 + } 105 + 106 + 107 + #line 0 realloc 108 + char *realloc(ptr,newsize) 109 + char *ptr; 110 + unsigned newsize; 111 + { 112 + return (relalloc(ptr, (long)newsize)); 113 + } 114 + 115 +
+23
sources/storage.h
··· 1 + /************************************************************************* 2 + 3 + Storage function library 4 + 5 + Standard C storage procedures 6 + 7 + (C) Copyright 1986. THINK Technologies, Inc. All rights reserved. 8 + 9 + ************************************************************************/ 10 + 11 + #ifndef _storagech_ 12 + #define _storagech_ 13 + 14 + char *calloc(); 15 + char *clalloc(); 16 + /* int cfree(); Default for these functions are int so they don't need to be declared*/ 17 + /* int free(); */ 18 + char *malloc(); 19 + char *mlalloc(); 20 + char *realloc(); 21 + char *relalloc(); 22 + 23 + #endif
+513
sources/storageu.c
··· 1 + /************************************************************************/ 2 + /* */ 3 + /* Copyright (C) 1986 THINK Technologies, Inc. All rights reserved. */ 4 + /* */ 5 + /************************************************************************/ 6 + 7 + /* 8 + Storage function library. All of the UNIX storage allocation and 9 + disposition routines provided with the LightspeedC compiler are contained 10 + in this module. The header "storageu.h" contains definitions for the routines 11 + contained herein. 12 + 13 + 14 + UNIX compatibility storage procedures for level 1 and level 2 memory mgmt. 15 + 16 + allmem(nkbytes) 17 + bldmem(nkbytes) 18 + getmem(nbytes) 19 + getml(nbytes) 20 + lsbrk(nbytes) 21 + rbrk() 22 + rlsmem(cp,nbytes) 23 + rlsml(cp,nbytes) 24 + rstmem() 25 + sbrk(nbytes) 26 + sizmem() 27 + */ 28 + 29 + #include "Storageu.h" 30 + 31 + #ifndef _MemoryMgr_ 32 + #include "MemoryMgr.h" 33 + #endif 34 + 35 + #define NULL 0L 36 + #define ERROR -1 37 + 38 + /********************************************************/ 39 + /* */ 40 + /* UNIX level 1 & level 2 storage allocation */ 41 + /* */ 42 + /********************************************************/ 43 + 44 + /* need some variables to manage memory pools */ 45 + 46 + static unsigned long poolsize=0; /* Size of pool in bytes */ 47 + static Handle poolhandle=NULL; /* Handle to memory pool */ 48 + static char *bldbrk=NULL; /* beginning of level 2 memory pool */ 49 + static char *getbrk=NULL; /* end of actively allocated level 2 */ 50 + static char *endbrk=NULL; /* end address of pool */ 51 + static char allmemflag=0; /* allmem has been called flag */ 52 + 53 + #define L2POOLSIZE 30*1024 /* size of automatic level 2 memory pool */ 54 + 55 + /* forward references */ 56 + 57 + char *getbytes(); 58 + void initfreepool(); 59 + 60 + 61 + #line 0 allmem 62 + int allmem() 63 + { 64 + int status; 65 + 66 + if (allmemflag) return (ERROR); 67 + 68 + status = bldmem(0); 69 + 70 + allmemflag = 1; 71 + 72 + return (status); 73 + } 74 + 75 + #line 0 bldmem 76 + int bldmem(n) 77 + int n; 78 + { 79 + unsigned long m = n; 80 + 81 + if (allmemflag) return (ERROR); 82 + 83 + /* set up the level 2 memory pool to be n K bytes if n!=0 */ 84 + 85 + if ((getbrk = bldbrk = lsbrk(m=(m?(m<<10):L2POOLSIZE)))==NULL) 86 + return (ERROR); 87 + 88 + /* remember end position so we know when allocation area runs out */ 89 + 90 + endbrk = bldbrk + m; 91 + return (0); 92 + } 93 + 94 + 95 + #line 0 getmem 96 + char *getmem(nbytes) 97 + unsigned int nbytes; 98 + { 99 + return (getml((long)nbytes)); 100 + } 101 + 102 + 103 + #line 0 getml 104 + char *getml(lnbytes) 105 + unsigned long lnbytes; 106 + { 107 + if (getbrk) return (getbytes(lnbytes)); 108 + return (lsbrk(lnbytes)); 109 + } 110 + 111 + #line 0 lsbrk 112 + char *lsbrk(lnbytes) 113 + register unsigned long lnbytes; 114 + { 115 + register char *p; 116 + 117 + /* odd sizes are illegal for lsbrk and are rounded upwards */ 118 + 119 + if (lnbytes & 1) lnbytes++; 120 + 121 + if (poolhandle) 122 + { 123 + /* pool aready exists, create pointer to current end */ 124 + 125 + p = *poolhandle + poolsize; 126 + 127 + /* grow it in place since we aren't allowed to move it */ 128 + 129 + SetHandleSize(poolhandle, poolsize+lnbytes); 130 + 131 + if (MemErr) return (NULL); 132 + 133 + poolsize += lnbytes; 134 + 135 + return (p); 136 + } 137 + 138 + /* Create new pool */ 139 + 140 + if (poolhandle = NewHandle(lnbytes)) 141 + { 142 + poolsize = lnbytes; 143 + HLock(poolhandle); 144 + return (*poolhandle); 145 + } 146 + 147 + return (NULL); 148 + 149 + } 150 + 151 + #line 0 rlsmem 152 + int rlsmem(cp,nbytes) 153 + char *cp; 154 + unsigned int nbytes; 155 + { 156 + return (rlsml(cp, (long)nbytes)); 157 + } 158 + 159 + #line 0 rlsml 160 + int rlsml(cp,lnbytes) 161 + register char *cp; 162 + unsigned long lnbytes; 163 + { 164 + /* Make sure pointer is within the pool */ 165 + 166 + if (cp < *poolhandle) return (ERROR); 167 + 168 + /* memory allocated from primary pool before calling allmem() 169 + or bldmem() cannot be reclaimed if released */ 170 + 171 + if (getbrk == NULL) 172 + return (0); 173 + 174 + if ((cp+lnbytes) > getbrk) return (ERROR); 175 + 176 + /* OK, it's in the pool, now put it onto the free list, 177 + note that if cp is odd, block is marked as unusable (third param) */ 178 + 179 + return (putfreepool(cp, lnbytes, !((int)cp&1))); 180 + } 181 + 182 + #line 0 rstmem 183 + void rstmem() 184 + { 185 + /* reinitialize level 2 memory pool */ 186 + 187 + initfreepool(); 188 + 189 + /* reset allocation point */ 190 + 191 + getbrk = bldbrk; 192 + 193 + /* pretend that allmem() was never called */ 194 + 195 + allmemflag = 0; 196 + } 197 + 198 + #line 0 rbrk 199 + void rbrk() 200 + { 201 + if (poolhandle) 202 + { 203 + /* release all level 2 free pool memory */ 204 + 205 + rstmem(); 206 + 207 + /* now release level 1 pool memory */ 208 + 209 + HUnlock(poolhandle); 210 + DisposHandle(poolhandle); 211 + poolhandle = NULL; 212 + bldbrk = endbrk = getbrk = NULL; 213 + 214 + /* our memory pool is now restored to its initial state */ 215 + } 216 + } 217 + 218 + #line 0 sbrk 219 + char *sbrk(nbytes) 220 + unsigned int nbytes; 221 + { 222 + char *p; 223 + 224 + if ((p = lsbrk((long)nbytes)) == NULL) return ((char*)ERROR); 225 + 226 + return (p); 227 + } 228 + 229 + 230 + #line 0 sizmem 231 + long sizmem() 232 + { 233 + /* return unallocated memory pool size, note that this does 234 + not include any memory given back to the free pool */ 235 + 236 + return (endbrk - getbrk); 237 + } 238 + 239 + 240 + 241 + /********************************************************/ 242 + /* */ 243 + /* Internal support procedures, etc. */ 244 + /* */ 245 + /********************************************************/ 246 + 247 + typedef struct { 248 + char *offset; 249 + unsigned long size; 250 + int usable; 251 + } freeliststruct; 252 + 253 + #define FREELISTUNIT (10*sizeof(freeliststruct)) 254 + 255 + #define delentry(freep, freecount, index)\ 256 + BlockMove(freep+1, freep, (--freecount-index)*sizeof(*freep)) 257 + 258 + #define addentry(freep, freecount, index)\ 259 + BlockMove(freep, freep+1, (freecount++-index)*sizeof(*freep)) 260 + 261 + 262 + static freeliststruct **freehandle=NULL; 263 + static int freecount=0; 264 + static unsigned long freemax=0; 265 + char *getfreepool(); 266 + 267 + 268 + #line 0 getbytes 269 + static char *getbytes(lnbytes) 270 + register unsigned long lnbytes; 271 + { 272 + register unsigned long size; 273 + register char *p; 274 + 275 + /* if there isn't a memory pool created, it's an error */ 276 + 277 + if (poolhandle == NULL) return (NULL); 278 + 279 + /* See if we can get something from already deallocated memory */ 280 + 281 + if (p=getfreepool(lnbytes)) return (p); 282 + 283 + if ( getbrk+lnbytes > endbrk) 284 + { 285 + /* Not enough free pool memory, try to get more, rounded to 1K */ 286 + 287 + size = (lnbytes+1023) & ~1023; 288 + 289 + /* This may fail if lots of memory has been allocated */ 290 + 291 + if (lsbrk(size) == NULL) return (NULL); 292 + 293 + endbrk += size; 294 + } 295 + 296 + /* Allocate from the pool */ 297 + 298 + p = getbrk; 299 + 300 + /* can't allow allocation of space on odd byte addresses, so 301 + round to the next byte */ 302 + 303 + if (lnbytes & 1) 304 + { 305 + if (putfreepool(p + lnbytes, 1L, false)) return (NULL); 306 + lnbytes++; 307 + } 308 + 309 + getbrk += lnbytes; 310 + return (p); 311 + } 312 + 313 + #line 0 initfreepool 314 + static void initfreepool() 315 + { 316 + if (freehandle) DisposHandle(freehandle); 317 + 318 + freehandle = NULL; 319 + freecount = 0; 320 + freemax = 0; 321 + } 322 + 323 + #line 0 putfreepool 324 + static int putfreepool(cp, lnbytes, usable) 325 + register char *cp; 326 + register unsigned long lnbytes; 327 + int usable; 328 + { 329 + register freeliststruct *freep; 330 + register int i, done=false; 331 + 332 + if (freehandle == NULL) 333 + { 334 + /* Create a free list */ 335 + 336 + if ((freehandle = (freeliststruct**) 337 + NewHandle(freemax = FREELISTUNIT)) == NULL) 338 + return (ERROR); 339 + 340 + freecount = 0; 341 + } 342 + 343 + HLock(freehandle); 344 + 345 + /* Determine insertion point in free list */ 346 + 347 + for (i=0, freep = *freehandle; (i<freecount)&&(freep->offset<cp); 348 + freep++, i++); 349 + 350 + if (i>0) 351 + { 352 + /* check if this item overlaps previous entry */ 353 + 354 + if (((freep-1)->offset + (freep-1)->size) > cp) 355 + { 356 + /* yes, it's an error */ 357 + 358 + HUnlock(freehandle); 359 + return (ERROR); 360 + } 361 + 362 + /* see if we can combine the item with the previous entry */ 363 + 364 + if (((freep-1)->offset + (freep-1)->size) == cp) 365 + { 366 + /* yes, combine it */ 367 + (freep-1)->size += lnbytes; 368 + done = true; 369 + } 370 + } 371 + 372 + if (!done && (i<freecount)) 373 + { 374 + /* check if this item overlaps the next entry */ 375 + 376 + if ((cp+lnbytes) > freep->offset) 377 + { 378 + /* yes, error */ 379 + 380 + HUnlock(freehandle); 381 + return (ERROR); 382 + } 383 + 384 + /* see if we can combine the item with the next entry */ 385 + 386 + if ((cp+lnbytes) == freep->offset) 387 + { 388 + /* yes, combine it */ 389 + freep->size += lnbytes; 390 + freep->offset = cp; 391 + freep->usable = (!((int)cp&1)); 392 + done = true; 393 + } 394 + } 395 + 396 + if (done) 397 + { 398 + /* now see if we have to combine the two entries */ 399 + 400 + if ((i>0) && (i<freecount)) 401 + { 402 + /* both entries exist, so try to combine them */ 403 + 404 + if (((freep-1)->offset + (freep-1)->size) == freep->offset) 405 + { 406 + /* yes, combine them both into the previous entry */ 407 + 408 + (freep-1)->size += freep->size; 409 + 410 + /* now delete the second entry */ 411 + 412 + delentry(freep, freecount, i); 413 + } 414 + } 415 + } 416 + else 417 + { 418 + if (freecount==freemax) 419 + { 420 + /* Need to grow the free list, first make freep relative */ 421 + 422 + freep -= (unsigned long) *freehandle; 423 + 424 + /* Allow free list to roam about */ 425 + 426 + HUnlock(freehandle); 427 + 428 + /* resize it */ 429 + 430 + SetHandleSize(freehandle, freemax+=FREELISTUNIT); 431 + 432 + if (MemErr) return (ERROR); 433 + 434 + HLock(freehandle); 435 + 436 + /* now make freep absolute again */ 437 + 438 + freep += (unsigned long) *freehandle; 439 + } 440 + 441 + /* Need to slide down entries to make room for new one */ 442 + 443 + addentry(freep, freecount, i); 444 + 445 + freep->offset = cp; 446 + freep->size = lnbytes; 447 + 448 + freep->usable = usable; 449 + } 450 + 451 + HUnlock(freehandle); 452 + 453 + if (freecount == 0) initfreepool(); 454 + 455 + return (0); 456 + } 457 + 458 + #line 0 getfreepool 459 + static char *getfreepool(lnbytes) 460 + register unsigned long lnbytes; 461 + { 462 + register freeliststruct *freep; 463 + register char *oddptr, *cp = NULL; 464 + register int i; 465 + 466 + 467 + /* There may not be a free list */ 468 + if (freehandle == NULL) return (NULL); 469 + 470 + /* guess we have to scan through... */ 471 + HLock(freehandle); 472 + 473 + for (i=0, freep=*freehandle; ((i<freecount)&&(freep->size<lnbytes)) 474 + &&(!freep->usable); 475 + freep++, i++); 476 + 477 + if (i == freecount) 478 + { 479 + /* got to end of list without finding sufficient space */ 480 + 481 + HUnlock(freehandle); 482 + return (NULL); 483 + } 484 + 485 + /* decrease free pool allocated amount by lnbytes (or so) */ 486 + 487 + cp = freep->offset; 488 + 489 + /* can't allow allocation of space on odd byte addresses, so 490 + round to the next byte */ 491 + 492 + if ((lnbytes & 1) && (freep->size != lnbytes)) 493 + { 494 + oddptr = cp + lnbytes; 495 + lnbytes++; 496 + } 497 + 498 + freep->offset += lnbytes; 499 + 500 + if ((freep->size -= lnbytes) == 0) 501 + delentry(freep, freecount, i); 502 + 503 + HUnlock(freehandle); 504 + 505 + /* if we allocated an odd number of bytes, put the odd byte on the 506 + free list, but make it unavailable for allocation */ 507 + 508 + if (oddptr) 509 + if (putfreepool(oddptr, 1L, false)) return ((char*)ERROR); 510 + 511 + return (cp); 512 + } 513 +
+26
sources/storageu.h
··· 1 + /************************************************************************* 2 + 3 + Storage function library 4 + 5 + UNIX compatibility storage procedures for level 1 and level 2 memory mgmt. 6 + 7 + (C) Copyright 1986. THINK Technologies, Inc. All rights reserved. 8 + 9 + ************************************************************************/ 10 + 11 + #ifndef _storageuh_ 12 + #define _storageuh_ 13 + 14 + /* int allmem(); */ 15 + /* int bldmem(); */ 16 + char *getmem(); 17 + char *getml(); 18 + char *lsbrk(); 19 + void rbrk(); 20 + /* int rlsmem(); Default for these functions are int so they don't need to be declared*/ 21 + /* int rlsml(); */ 22 + void rstmem(); 23 + char *sbrk(); 24 + long sizmem(); 25 + 26 + #endif
+387
sources/strings.c
··· 1 + /* 2 + 3 + (C) Copyright THINK Technologies, Inc. 1986. All rights reserved. 4 + 5 + 6 + String function library. All of the string routines provided with the 7 + LightSpeed C compiler are contained in this module. The header 8 + "strings.h" contains all of the definitions for the routines contained 9 + herein. Each of the routines are described below. This table, and 10 + the functions in the file are arranged in alphabetical order. 11 + 12 + stccpy( s1, s2, n ) - copy n character from s2 into s1 13 + stcis( s, set ) - find first position in s not in set 14 + stcisn( s1, set ) - find first position in s and in set 15 + stclen( s ) - length of s 16 + stpblk( p ) - return pointer to first non-blank in p 17 + stpbrk( s, set ) - return pointer to first of set in s 18 + stpchr( s, c ) - return pointer to c in s 19 + stpcpy( s1, s2 ) - copy s2 into s1 20 + strcat( s1, s2 ) - append s2 to s1 21 + strchr( s, c ) - return pointer to c in s 22 + strcmp( s1, s2 ) - return <0 if s1 < s2, =0 if s1 == s2, >0 if s1 > s2 23 + strcpy( s1, s2 ) - copy s2 into s1 24 + strcspn( s, set ) - find first position in s and in set 25 + strlen( s ) - length of s 26 + strncat( s1, s2, n ) - append up to n chars from t into s 27 + strncmp( s1, s2, n ) - for n chars of s1, 28 + return <0 if s1 < s2, =0 if s1 == s2, >0 if s1 > s2 29 + strncpy( s1, s2, n ) - copy up to n chars from s2 to s1 30 + strpbrk( s, set ) - return pointer to first of set in s 31 + strpos( s, c ) - find first position of c in s 32 + strrchr( s, c ) - return pointer to last occurance of c in s 33 + strrpbrk( s, set ) - return pointer last char in s and in set 34 + strrpos( s, c ) - find position of last occurance of c in s 35 + strspn( s, set ) - find first occurance in s not in set 36 + stscmp( s1, s2 ) - return <0 if s1 < s2, =0 if s1 == s2, >0 if s1 > s2 37 + 38 + In order to minimize the size of the library, some functions are used 39 + as aliases for others. The list below defines the mapping used. 40 + Routines not in this list are explicitly coded. 41 + 42 + stcis -> strspn 43 + stcisn -> strcspn 44 + stclen -> strlen 45 + stpbrk -> strpbrk 46 + stpchr -> strchr 47 + stpcpy -> strcpy 48 + strcmp -> strncmp 49 + stscmp -> strncmp 50 + */ 51 + 52 + #include "stdio.h" 53 + #include "ctype.h" 54 + #include "strings.h" 55 + 56 + #line 0 stccpy 57 + 58 + stccpy(s1, s2, n) 59 + register char *s1, *s2; 60 + register int n; 61 + { 62 + register char *s0 = s1; 63 + 64 + if (n <= 0) return (0); 65 + 66 + while (n-- && (*s1++ = *s2++)); 67 + 68 + if (n && *(s1-1)) *s1 = '\0'; 69 + 70 + return (s1-s0-1); 71 + } 72 + 73 + 74 + #line 0 stcis 75 + 76 + stcis(s, set) 77 + char *s, *set; 78 + { 79 + return (strspn(s, set)); 80 + } 81 + 82 + 83 + #line 0 stcisn 84 + 85 + stcisn(s1, set) 86 + char *s1, *set; 87 + 88 + { 89 + return (strcspn(s1, set)); 90 + } 91 + 92 + 93 + #line 0 stclen 94 + 95 + stclen(s) 96 + char *s; 97 + { 98 + return (strlen(s)); 99 + } 100 + 101 + 102 + #line 0 stpblk 103 + 104 + char *stpblk(p) 105 + register char *p; 106 + { 107 + while (!(isspace(*p))) p++; 108 + 109 + return (p); 110 + } 111 + 112 + #line 0 stpbrk 113 + 114 + char *stpbrk(s, set) 115 + char *s, *set; 116 + 117 + { 118 + return (strpbrk(s, set)); 119 + } 120 + 121 + #line 0 stpchr 122 + 123 + char *stpchr( s, c ) 124 + char *s, c; 125 + { 126 + return (strchr(s, c)); 127 + } 128 + 129 + #line 0 stpcpy 130 + 131 + char *stpcpy(s1, s2) 132 + char *s1, *s2; 133 + { 134 + return (strcpy(s1, s2)); 135 + } 136 + 137 + #line 0 strcat 138 + 139 + char *strcat( s1, s2 ) 140 + char *s1, *s2; 141 + { 142 + strcpy(s1+strlen(s1), s2); 143 + 144 + return (s1); 145 + } 146 + 147 + 148 + #line 0 strchr 149 + 150 + char *strchr(s, c) 151 + register char *s,c; 152 + { 153 + 154 + while ((*s != c) && *s) s++; 155 + 156 + return ( *s == c ? s : NULL ); 157 + } 158 + 159 + 160 + #line 0 strcmp 161 + 162 + strcmp(s1, s2) 163 + char *s1, *s2; 164 + { 165 + for (; *s1 == *s2 ; s1++, s2++) if (!*s1) break; 166 + 167 + return (*s1 - *s2); 168 + 169 + } 170 + 171 + 172 + #line 0 strcpy 173 + 174 + char *strcpy(s1,s2) 175 + register char *s1, *s2; 176 + { 177 + char *s = s1; 178 + 179 + while (*s1++=*s2++); 180 + 181 + return (s); 182 + } 183 + 184 + 185 + #line 0 strcspn 186 + 187 + strcspn(s, set) 188 + register char *s; 189 + char *set; 190 + 191 + { 192 + register char *t; 193 + register int count = 0; 194 + 195 + while (*s) 196 + { 197 + t = set; 198 + while (*t && (*s != *t)) t++; 199 + if (!*t) 200 + { 201 + s++; 202 + count++; 203 + } 204 + else 205 + break; 206 + } 207 + 208 + return (count); 209 + } 210 + 211 + 212 + #line 0 strlen 213 + 214 + strlen(s) 215 + register char *s; 216 + { 217 + char *s0 = s; 218 + 219 + while (*s++); 220 + return (s-s0-1); 221 + } 222 + 223 + 224 + #line 0 strncat 225 + 226 + char *strncat(s1, s2, n) 227 + register char *s1, *s2; 228 + register int n; 229 + { 230 + char *s0 = s1; 231 + 232 + if (n <= 0) return ( s1 ); 233 + 234 + while (*s1) s1++; 235 + 236 + while ((*s1++ = *s2++) && (--n)); 237 + 238 + if (*(s1 - 1)) *s1 = '\0'; 239 + 240 + return (s0); 241 + } 242 + 243 + 244 + #line 0 strncmp 245 + 246 + strncmp(s1, s2, n) 247 + register char *s1, *s2; 248 + register int n; 249 + { 250 + if (n <= 0) return ( 0 ); 251 + for (; --n && (*s1 == *s2); s1++, s2++) 252 + if (!*s1) break; 253 + 254 + return (*s1 - *s2); 255 + } 256 + 257 + 258 + #line 0 strncpy 259 + 260 + char *strncpy(s1, s2, n) 261 + register char *s1, *s2; 262 + register int n; 263 + { 264 + char *s0 = s1; 265 + 266 + if (n > 0) 267 + { 268 + while (n-- && (*s1++ = *s2++)); 269 + 270 + while (n>0) 271 + { /* pad out to n chars -- H&S specs it this way... */ 272 + 273 + *s1++ = '\0'; 274 + n--; 275 + } 276 + } 277 + 278 + return (s0); 279 + } 280 + 281 + 282 + #line 0 strpbrk 283 + 284 + char *strpbrk(s, set) 285 + register char *s; 286 + char *set; 287 + 288 + { 289 + register char *t; 290 + 291 + for (; *s ; s++) 292 + { 293 + for (t = set; *t && (*s != *t); t++); 294 + 295 + if (*t) return (s); 296 + } 297 + 298 + return (NULL); 299 + } 300 + 301 + 302 + #line 0 strpos 303 + 304 + strpos(s, c) 305 + register char *s, c; 306 + { 307 + char *s0 = s; 308 + 309 + while ((*s != c) && *s) s++; 310 + 311 + return ( *s == c ? s-s0 : -1 ); 312 + } 313 + 314 + 315 + #line 0 strrchr 316 + 317 + char *strrchr( s, c ) 318 + register char *s, c; 319 + { 320 + register char *p; 321 + 322 + for (p=s+strlen(s); p>=s; p--) if (*p==c) return (p); 323 + 324 + return (NULL); 325 + } 326 + 327 + 328 + #line 0 strrpbrk 329 + 330 + char *strrpbrk(s, set) 331 + char *s; 332 + char *set; 333 + { 334 + register char *t, *p; 335 + register long xs = (long) s; 336 + 337 + for (p=s+strlen(s); p>= (char*)xs ; p--) 338 + { 339 + for (t=set; *t; t++) 340 + if (*p == *t) return (p); 341 + } 342 + 343 + return (NULL); 344 + } 345 + 346 + 347 + #line 0 strrpos 348 + 349 + strrpos(s, c) 350 + register char *s, c; 351 + { 352 + register char *p; 353 + register long xs = (long) s; 354 + 355 + for (p=s+strlen(s); p>=(char*)xs; p--) 356 + if (*p == c) return (p-s); 357 + 358 + return (-1); 359 + } 360 + 361 + #line 0 strspn 362 + 363 + strspn(s, set) 364 + register char *s; 365 + char *set; 366 + { 367 + char *s0 = s; 368 + register char *t; 369 + 370 + for (; *s ; s++) 371 + { 372 + for (t = set; *t ; t++) if (*s == *t) break; 373 + 374 + if (!*t) break; 375 + } 376 + 377 + return (s-s0); 378 + } 379 + 380 + 381 + #line 0 stscmp 382 + 383 + stscmp(s1,s2) 384 + char *s1, *s2; 385 + { 386 + return (strcmp(s1, s2)); 387 + }
+54
sources/strings.h
··· 1 + /************************************************************************** 2 + 3 + Header file for routines contained in "strings.c" 4 + and "Unix_Strings.c". Refer to those files 5 + for information on string function and implementation. 6 + 7 + (C) Copyright 1985, 1986. THINK Technologies, Inc. All rights reserved. 8 + 9 + **************************************************************************/ 10 + 11 + 12 + #ifndef _stringh_ 13 + #define _stringh_ 14 + 15 + /* Routines in string.lib */ 16 + char *stpblk(); 17 + char *stpbrk(); 18 + char *stpchr(); 19 + char *stpcpy(); 20 + char *strcat(); 21 + char *strchr(); 22 + char *strcpy(); 23 + char *strncat(); 24 + char *strncpy(); 25 + char *strpbrk(); 26 + char *strrchr(); 27 + char *strrpbrk(); 28 + 29 + /* Default for these functions are int so they don't need to be declared 30 + int stccpy(); 31 + int stcis(); 32 + int stclen(); 33 + int strcmp(); 34 + int strcspn(); 35 + int strlen(); 36 + int strncmp(); 37 + int strpos(); 38 + int strrpos(); 39 + int strspn(); 40 + int stscmp(); 41 + */ 42 + 43 + 44 + /* parsing functions - in unix string.lib */ 45 + char *stpsym(); 46 + char *stptok(); 47 + 48 + /* 49 + int stcarg(); 50 + int stcpm(); 51 + int stcpma(); 52 + */ 53 + 54 + #endif
+492
sources/stringsasm.c
··· 1 + /* 2 + ; (C) Copyright THINK Technologies, Inc. 1986. All rights reserved. 3 + ; 4 + ; 5 + ; Assembly language string procedures. This module comprises the string 6 + ; library. Certain functions are more efficient done this way than in 7 + ; straight C since LightspeedC is not optimized for the kind of 8 + ; specialized string handling done here. 9 + ; 10 + */ 11 + 12 + /*************************************************************************/ 13 + 14 + stccpy() 15 + { 16 + asm 17 + { 18 + movem.l 4(a7),a0-a1 19 + move.l a0,d1 20 + move.w 12(a7),d0 21 + subq #1,d0 22 + bge.s @stccpy1 23 + stccpyx: 24 + move.l a0,d0 25 + sub.l d1,d0 26 + return 27 + stccpy1: 28 + move.b (a1)+,(a0)+ 29 + dbeq d0,@stccpy1 ; if flags were 0 or count == -1, exit loop 30 + tst.b -(a0) 31 + beq.s @stccpyx 32 + tst.w d0 ; did count go to zero? 33 + blt.s @stccpyx ; yes, don't add zero on end 34 + addq.l #1,a0 ; point to new end of string 35 + clr.b (a0) ; zero it out 36 + bra.s @stccpyx 37 + return 38 + } 39 + } 40 + 41 + /*************************************************************************/ 42 + 43 + stpblk() /* space codes are hard-wired, taken from stddata_ctype.c */ 44 + { 45 + asm 46 + { 47 + move.l 4(a7),a0 48 + stpblk1: 49 + cmp.b #32,(a0) ; is it a space? 50 + beq.s @stpblkx 51 + cmp.b #3,(a0) ; is it ^C (ETX)? 52 + beq.s @stpblkx 53 + cmp.b #9,(a0) ; is it less than 9? 54 + blt.s @stpblk2 ; yes, no white space chars there 55 + cmp.b #13,(a0) ; is it less than or equal to 13? 56 + ble.s @stpblkx ; if so, 9-13 are all white space chars 57 + stpblk2: 58 + addq.l #1,a0 ; look at next character in memory 59 + bra.s @stpblk1 60 + stpblkx: 61 + move.l a0,d0 62 + return 63 + } 64 + } 65 + 66 + /*************************************************************************/ 67 + 68 + strcat() 69 + { 70 + asm 71 + { 72 + movem.l 4(a7),a0-a1 73 + move.l a0,d0 74 + strcat1: 75 + tst.b (a0)+ ; find end of string1 (zero byte) 76 + bne.s @strcat1 ; using tight loop 77 + subq.l #1,a0 ; back up one 78 + strcat2: 79 + move.b (a1)+,(a0)+ ; now copy string2 onto end of string1 80 + bne.s @strcat2 ; again using tight loop 81 + return 82 + } 83 + } 84 + 85 + /*************************************************************************/ 86 + 87 + strchr() 88 + { 89 + asm 90 + { 91 + move.l 4(a7),a0 92 + move.b 9(a7),d2 93 + moveq #0,d0 94 + strchr1: 95 + move.b (a0)+,d1 96 + bne.s @strchr2 97 + tst.b d2 ; special case if searching for 0 98 + beq.s @strchr3 99 + return 100 + strchr2: 101 + cmp.b d2,d1 102 + bne.s @strchr1 103 + strchr3: 104 + move.l a0,d0 105 + subq.l #1,d0 106 + return 107 + } 108 + } 109 + 110 + stpchr() /* synonym for strchr */ 111 + { 112 + asm 113 + { 114 + jmp strchr 115 + } 116 + } 117 + 118 + /*************************************************************************/ 119 + 120 + strcmp() 121 + { 122 + asm 123 + { 124 + movem.l 4(a7),a0-a1 125 + strcmp1: 126 + cmpm.b (a1)+,(a0)+ 127 + bne.s @strcmpx 128 + strcmp2: 129 + tst.b -1(a0) ; did string1 end? 130 + bne.s @strcmp1 131 + strcmpx: 132 + move.b -(a0),d0 ; return (*s1 - *s2) 133 + sub.b -(a1),d0 134 + ext.w d0 135 + return 136 + } 137 + } 138 + 139 + stscmp() /* synonym for strcmp */ 140 + { 141 + asm 142 + { 143 + jmp strcmp 144 + } 145 + } 146 + 147 + 148 + /*************************************************************************/ 149 + 150 + strcpy() 151 + { 152 + asm 153 + { 154 + movem.l 4(a7),a0-a1 155 + move.l a0,d0 ; return ptr to start of destination string 156 + strcpy1: 157 + move.b (a1)+,(a0)+ ; copy until we pass a 158 + bne.s @strcpy1 ; zero byte 159 + return 160 + } 161 + } 162 + 163 + stpcpy() /* synonym for strcpy */ 164 + { 165 + asm 166 + { 167 + jmp strcpy 168 + } 169 + } 170 + 171 + /*************************************************************************/ 172 + 173 + strcspn() /* a0 = s, d1 = set, a1 = t */ 174 + { 175 + asm 176 + { 177 + move.l 4(a7),a0 178 + move.l 8(a7),d1 179 + strcspn1: 180 + tst.b (a0) ; is *s zero? 181 + beq.s @strcspnx ; yes, exit 182 + move.l d1,a1 ; t = set 183 + strcspn2: 184 + tst.b (a1) ; is *t zero? 185 + beq.s @strcspn3 ; yes, try next *s 186 + cmpm.b (a0)+,(a1)+ ; is char in set? 187 + subq.l #1,a0 ; no such inst as cmpm (a0),(a1)+ 188 + beq.s @strcspnx ; yes, exit 189 + bra.s @strcspn2 190 + strcspn3: 191 + addq.l #1,a0 ; yes, loop through for next char in s 192 + bra.s @strcspn1 193 + strcspnx: 194 + move.l a0,d0 ; subtract current pos from orig 195 + sub.l 4(a7),d0 ; to get count 196 + return 197 + } 198 + } 199 + 200 + stcisn() /* synonym for strcspn */ 201 + { 202 + asm 203 + { 204 + jmp strcspn 205 + } 206 + } 207 + 208 + /*************************************************************************/ 209 + 210 + strlen() 211 + { 212 + asm 213 + { 214 + move.l 4(a7),a0 215 + strlen1: 216 + tst.b (a0)+ 217 + bne.s @strlen1 218 + move.l a0,d0 219 + sub.l 4(a7),d0 220 + subq.l #1,d0 221 + return 222 + } 223 + } 224 + 225 + stclen() /* synonym for strlen */ 226 + { 227 + asm 228 + { 229 + jmp strlen 230 + } 231 + } 232 + 233 + /*************************************************************************/ 234 + 235 + strncat() 236 + { 237 + asm 238 + { 239 + movem.l 4(a7),a0-a1 240 + move.l a0,d0 241 + move.w 12(a7),d1 242 + ble.s @strncat3 243 + strncat1: 244 + tst.b (a0)+ 245 + bne.s @strncat1 ; find end of string1 246 + subq.l #1,a0 247 + subq.w #1,d1 ; offset by 1 for dbeq 248 + strncat2: 249 + move.b (a1)+,(a0)+ ; copy string2 onto end of string1 250 + dbeq d1,@strncat2 251 + tst.b -1(a0) ; did we copy a zero? 252 + beq.s @strncat3 ; yes 253 + clr.b (a0) ; no, add a zero on end 254 + strncat3: 255 + return 256 + } 257 + } 258 + 259 + /*************************************************************************/ 260 + 261 + strncmp() 262 + { 263 + asm 264 + { 265 + movem.l 4(a7),a0-a1 266 + clr.w d0 267 + move.w 12(a7),d1 268 + ble.s @strncmp2 269 + strncmp1: 270 + cmpm.b (a0)+,(a1)+ 271 + beq.s @strncmp3 272 + strncmpx: 273 + move.b -(a0),d0 274 + sub.b -(a1),d0 275 + ext.w d0 276 + strncmp2: 277 + return 278 + strncmp3: 279 + subq.w #1,d1 280 + beq.s @strncmpx 281 + tst.b -1(a0) 282 + beq.s @strncmpx 283 + bra.s @strncmp1 284 + return 285 + } 286 + } 287 + 288 + /*************************************************************************/ 289 + 290 + strncpy() 291 + { 292 + asm 293 + { 294 + movem.l 4(a7),a0-a1 295 + move.l a0,d0 296 + move.w 12(a7),d1 297 + bgt.s @strncpy1 298 + strncpyx: 299 + return 300 + strncpy1: 301 + move.b (a1)+,(a0)+ 302 + beq.s @strncpy2 ; if zero byte, see if we need to fill 303 + subq.w #1,d1 304 + bgt.s @strncpy1 ; is count exhausted? 305 + beq.s @strncpyx ; yes, quit now 306 + strncpy2: 307 + subq.w #1,d1 308 + beq.s @strncpyx 309 + clr.b (a0)+ ; zero end of string until count runs out 310 + bra.s @strncpy2 311 + } 312 + } 313 + 314 + /*************************************************************************/ 315 + 316 + strpbrk() 317 + { 318 + asm 319 + { 320 + move.l 4(a7),a0 ; a0 = s 321 + move.l 8(a7),d1 ; d1 = set 322 + moveq #0,d0 323 + strpbrk1: 324 + tst.b (a0) ; *s zero? 325 + beq.s @strpbrkx 326 + move.l d1,a1 ; t = set 327 + strpbrk2: 328 + move.b (a1)+,d2 329 + bne.s @strpbrk3 330 + addq.l #1,a0 ; reached end of set 331 + bra.s @strpbrk1 ; try next char in s 332 + strpbrk3: 333 + cmp.b (a0),d2 ; *s == *t ? 334 + bne.s @strpbrk2 ; if not, try next *t 335 + move.l a0,d0 ; yes, return s 336 + strpbrkx: 337 + return 338 + } 339 + } 340 + 341 + stpbrk() /* synonym for strpbrk */ 342 + { 343 + asm 344 + { 345 + jmp strpbrk 346 + } 347 + } 348 + 349 + /*************************************************************************/ 350 + 351 + strpos() 352 + { 353 + asm 354 + { 355 + move.l 4(a7),a0 356 + move.b 9(a7),d0 357 + strpos1: 358 + move.b (a0)+,d1 359 + bne.s @strpos2 360 + tst.b d0 ; special case searching for 0 361 + beq.s @strpos3 362 + moveq #-1,d0 ; return -1 if not found 363 + return 364 + strpos2: 365 + cmp.b d0,d1 366 + bne.s @strpos1 ; no match, try again 367 + strpos3: 368 + move.l a0,d0 ; matched, return index into string 369 + sub.l 4(a7),d0 370 + subq.w #1,d0 371 + return 372 + } 373 + } 374 + 375 + /*************************************************************************/ 376 + 377 + strrchr() /* return ptr to last occurrence of char */ 378 + { 379 + asm 380 + { 381 + move.l 4(a7),a0 ; in the string 382 + move.b 9(a7),d1 383 + moveq #1,d0 384 + strrchr1: 385 + move.b (a0)+,d2 386 + beq.s @strrchr3 387 + cmp.b d1,d2 388 + bne.s @strrchr1 389 + move.l a0,d0 ; remember last occurrence + 1 390 + bra.s @strrchr1 391 + strrchr3: 392 + tst.b d1 ; special case searching for 0 393 + bne.s @strrchr4 394 + move.l a0,d0 395 + strrchr4: 396 + subq.l #1,d0 397 + return 398 + } 399 + } 400 + 401 + /*************************************************************************/ 402 + 403 + strrpbrk() 404 + { 405 + asm 406 + { 407 + move.l 4(a7),a0 408 + move.l 8(a7),d1 409 + moveq #0,d0 410 + strrpbrk1: 411 + tst.b (a0) 412 + beq.s @strrpbrkx 413 + move.l d1,a1 414 + strrpbrk2: 415 + move.b (a1)+,d2 416 + beq.s @strrpbrk3 417 + cmp.b (a0),d2 418 + bne.s @strrpbrk2 419 + move.l a0,d0 420 + strrpbrk3: 421 + addq.l #1,a0 422 + bra.s @strrpbrk1 423 + strrpbrkx: 424 + return 425 + } 426 + } 427 + 428 + /*************************************************************************/ 429 + 430 + strrpos() 431 + { 432 + asm 433 + { 434 + move.l 4(a7),a0 435 + move.l a0,a1 436 + move.b 9(a7),d1 437 + move.l a0,d0 438 + strrpos1: 439 + move.b (a0)+,d2 440 + beq.s @strrpos3 441 + cmp.b d1,d2 442 + bne.s @strrpos1 443 + move.l a0,d0 444 + bra.s @strrpos1 445 + strrpos3: 446 + tst.b d1 447 + bne.s @strrpos4 448 + move.l a0,d0 449 + strrpos4: 450 + sub.l a1,d0 451 + subq.w #1,d0 452 + return 453 + } 454 + } 455 + 456 + /*************************************************************************/ 457 + 458 + strspn() /* a0 = s, d1 = set, a1 = t */ 459 + { 460 + asm 461 + { 462 + move.l 4(a7),a0 463 + move.l 8(a7),d1 464 + strspn1: 465 + tst.b (a0) ; is *s zero? 466 + beq.s @strspnx ; yes, exit 467 + move.l d1,a1 ; t = set 468 + strspn2: 469 + tst.b (a1) ; is *t zero? 470 + beq.s @strspnx ; yes, exit since char must not be in set 471 + cmpm.b (a0)+,(a1)+ ; is char in set? 472 + subq.l #1,a0 ; no such inst as cmpm (a0),(a1)+ 473 + bne.s @strspn2 ; loop through contents of set 474 + strspn3: 475 + addq.l #1,a0 ; yes, loop through for next char in s 476 + bra.s @strspn1 477 + strspnx: 478 + move.l a0,d0 ; subtract current pos from orig 479 + sub.l 4(a7),d0 ; to get count 480 + return 481 + } 482 + } 483 + 484 + stcis() /* synonym for strspn */ 485 + { 486 + asm 487 + { 488 + jmp strspn 489 + } 490 + } 491 + 492 +
+25
sources/time.h
··· 1 + /* (C) Copyright 1986. THINK Technologies, Inc. All rights reserved. */ 2 + 3 + #ifndef _timeh_ 4 + #define _timeh_ 5 + 6 + typedef struct tm { 7 + int tm_sec; 8 + int tm_min; 9 + int tm_hour; 10 + int tm_mday; 11 + int tm_mon; 12 + int tm_year; 13 + int tm_wday; 14 + int tm_yday; 15 + int tm_isdst; 16 + } tm; 17 + 18 + struct tm *gmtime(); 19 + struct tm *localtime(); 20 + char *ctime(); 21 + char *asctime(); 22 + unsigned long time(); 23 + extern char *tzname[]; 24 + 25 + #endif
+15
sources/types.h
··· 1 + /* (C) Copyright 1986. THINK Technologies, Inc. All rights reserved. */ 2 + 3 + 4 + typedef long time_t; 5 + typedef long daddr_t; 6 + typedef char *caddr_t; 7 + typedef unsigned int uint; 8 + typedef unsigned short ushort; 9 + typedef ushort ino_t; 10 + typedef short cnt_t; 11 + typedef short dev_t; 12 + typedef long off_t; 13 + typedef long paddr_t; 14 + typedef long key_t; 15 + typedef int label_t[10];
+133
sources/unix main.c
··· 1 + /************************************************************************* 2 + * * 3 + * Module: unix main.c * 4 + * Programmer: Steve Adams * 5 + * * 6 + * (C) Copyright 1985, THINK Technologies, Inc. All rights reserved. * 7 + * * 8 + * Alternate main program to handle Unix command lines under Lightspeed * 9 + * C. The user is prompted for the command line on program entry. The * 10 + * line is disected and placed in an "argv" array up to a maximum of * 11 + * MAX_ARGS entries. I/O redirection is also supported, as follows: * 12 + * * 13 + * > redirects stdout to following file name * 14 + * < redirects stdin to following file name * 15 + * >> redirects stderr to following file name * 16 + * * 17 + * File names following a redirection may be immediately after the * 18 + * redirector, or at what appears to be the next argument. If a file * 19 + * open error occurs, then the program calls "SysBeep" and exits to the * 20 + * shell. * 21 + * * 22 + * TO USE: change the "main" function in you application to "_main" and * 23 + * include this file in your project. * 24 + * * 25 + *************************************************************************/ 26 + 27 + 28 + #include <stdio.h> 29 + #include <ctype.h> 30 + 31 + #define MAX_ARGS 50 32 + 33 + #ifndef true 34 + #define true 1 35 + #define false 0 36 + #endif 37 + 38 + static int argc = 1; /* final argument count */ 39 + static char *argv[MAX_ARGS] = { "" }; /* array of pointers */ 40 + static char command[256]; /* input line buffer */ 41 + static int filename = false; /* TRUE iff file name */ 42 + 43 + 44 + /************************************************************************* 45 + * * 46 + * Local routine to make a "beep" and exit to the shell. * 47 + * * 48 + *************************************************************************/ 49 + 50 + static void punt() 51 + { 52 + SysBeep( 5L ); 53 + ExitToShell(); 54 + } 55 + 56 + 57 + /************************************************************************* 58 + * * 59 + * Local routine to open a file in argv[--argc] after closing it's * 60 + * previous existance. * 61 + * * 62 + *************************************************************************/ 63 + 64 + 65 + static void openfile( file, mode ) 66 + char *mode; /* mode for file open */ 67 + FILE *file; /* file pointer to use */ 68 + { 69 + 70 + if ( (file = freopen( argv[--argc], mode, file ) ) <= (FILE *) NULL) 71 + punt(); 72 + filename = false; 73 + } 74 + 75 + 76 + /************************************************************************* 77 + * * 78 + * New main routine. Prompts for command line then calls user's main * 79 + * now called "_main" with the argument list and redirected I/O. * 80 + * * 81 + *************************************************************************/ 82 + 83 + 84 + void main() 85 + { 86 + char c; /* temp for EOLN check */ 87 + register char *cp; /* index in command line */ 88 + char *mode; /* local file mode */ 89 + FILE *file; /* file to change */ 90 + int i; 91 + 92 + printf( "Enter Unix command line:\n" ); 93 + gets( &command ); /* allow user to edit */ 94 + cp = &command[0]; /* start of buffer */ 95 + argv[0] = ""; /* program name is NULL */ 96 + while (argc < MAX_ARGS) 97 + { /* up to MAX_ARGS entries */ 98 + while (isspace( *cp++ )); 99 + if ( !*--cp ) 100 + break; 101 + else if ( *cp == '<' ) 102 + { /* redirect stdin */ 103 + cp++; 104 + file = stdin; 105 + mode = "r"; 106 + filename = true; 107 + } 108 + else if ( *cp == '>' ) 109 + { 110 + mode = "w"; 111 + filename = true; 112 + if (*++cp == '>') 113 + { 114 + file = stderr; 115 + cp++; 116 + } 117 + else 118 + file = stdout; 119 + } 120 + else 121 + { /* either an argument or a filename */ 122 + argv[argc++] = cp; 123 + while ( *++cp && !isspace( *cp ) ); 124 + c = *cp; 125 + *cp++ = '\0'; 126 + if (filename) 127 + openfile( file, mode ); 128 + if (!c) 129 + break; 130 + } 131 + } 132 + _main( argc, argv ); 133 + }
+62
sources/unix.h
··· 1 + /* (C) Copyright 1986. THINK Technologies, Inc. All rights reserved. */ 2 + 3 + #ifndef _unixh_ 4 + #define _unixh_ 5 + 6 + #ifndef _timeh_ 7 + #include "time.h" 8 + #endif _timeh_ 9 + 10 + #ifndef _errnoh_ 11 + #include "errno.h" 12 + #endif _errnoh_ 13 + 14 + #ifndef _ioh_ 15 + #include "io.h" 16 + #endif _ioh_ 17 + 18 + #ifndef _signalh_ 19 + #include "signal.h" 20 + #endif _signalh_ 21 + 22 + double atof(); 23 + long atol(); 24 + long lseek(); 25 + long tell(); 26 + 27 + void exit(); 28 + void _exit(); 29 + void abort(); 30 + void setmem(); 31 + void repmem(); 32 + void movmem(); 33 + void perror(); 34 + void eraseplot(); 35 + void line(); 36 + void circle(); 37 + void move(); 38 + void cont(); 39 + void point(); 40 + void label(); 41 + void sleep(); 42 + char *cgetpid(); 43 + char *locv(); 44 + 45 + /* Default for these functions are int so they don't need to be declared 46 + int atoi(); 47 + int getuid(); 48 + int setuid(); 49 + int getpid(); 50 + int setpid(); 51 + int stcu_d(); 52 + int stci_d(); 53 + int stch_i(); 54 + int stcd_i(); 55 + int getw(); 56 + int putw(); 57 + int ttyn(); 58 + int stspfp(); 59 + int setbuf(); 60 + int setnbuf(); 61 + */ 62 + #endif
+59
sources/unix2.c
··· 1 + /* (C) Copyright 1986. THINK Technologies, Inc. All rights reserved. */ 2 + 3 + #ifndef _stdioh_ 4 + #include "stdio.h" 5 + #endif 6 + 7 + #ifndef _ctypeh_ 8 + #include "ctype.h" 9 + #endif 10 + 11 + #line 0 locv 12 + 13 + char *locv(hi,lo) 14 + int hi,lo; 15 + { 16 + static char buf[15]; 17 + sprintf(buf,"%ld",((long)hi<<16) || lo ); 18 + return(buf); 19 + } 20 + 21 + 22 + #line 0 getw 23 + 24 + int getw(who) 25 + FILE *who; 26 + { 27 + register int chi,clo; 28 + 29 + if ((chi = fgetc(who)) == EOF) 30 + return(EOF); 31 + 32 + if ((clo = fgetc(who)) == EOF) 33 + return(EOF); 34 + 35 + return((chi & 0xFF) << 8 | (clo & 0xFF)); 36 + } 37 + 38 + #line 0 putw 39 + 40 + int putw(word,who) 41 + int word; 42 + FILE *who; 43 + { 44 + if (fputc(((word>>8)&0xFF),who) == EOF) 45 + return(EOF); 46 + 47 + if (fputc((word &0xFF),who) == EOF) 48 + return(EOF); 49 + 50 + return(word); 51 + } 52 + 53 + #line 0 perror 54 + 55 + void perror(s) 56 + char *s; 57 + { 58 + printf("%s : Error number %d\n",s,errno); 59 + }
+56
sources/unix3.c
··· 1 + /* (C) Copyright 1986. THINK Technologies, Inc. All rights reserved. */ 2 + 3 + #ifndef _stdioh_ 4 + #include "stdio.h" 5 + #endif 6 + 7 + 8 + #define MacTicker (*(long*)0x16A) 9 + 10 + #line 0 sleep 11 + 12 + void sleep(secs) 13 + int secs; 14 + { 15 + 16 + register long beginticks,endticks; 17 + 18 + beginticks = MacTicker; 19 + endticks = beginticks + secs * 60; 20 + while (MacTicker < endticks) 21 + ; 22 + } 23 + 24 + #line 0 ttyn 25 + 26 + int ttyn(who) 27 + FILE *who; 28 + { 29 + if (who->StdStream) 30 + return(1); 31 + return(0); 32 + } 33 + 34 + #line 0 stspfp 35 + 36 + int stspfp(p,n) 37 + register char *p; 38 + register int *n; 39 + { 40 + register int i=0, c=1; 41 + 42 + while (*p) 43 + { 44 + if (*p++ == ':') 45 + { 46 + if (i>14) 47 + return(-1); 48 + *n++ = c; 49 + i++; 50 + *(p-1) = '\0'; 51 + } 52 + c++; 53 + } 54 + *n = -1; 55 + return(0); 56 + }
+248
sources/unix_strings.c
··· 1 + /* 2 + Unix/Lattice string parsing functions for Lightspeed. 3 + 4 + This library implements the string based parsing routines. 5 + 6 + Routines defined in this module: 7 + stcarg - get an argument 8 + stpcm - unanchored pattern match 9 + stpcma - anchored pattern match 10 + stpsym - get a symbol from a string 11 + stptok - get a token from a string 12 + 13 + 14 + (C) Copyright 1986 THINK Technologies, Inc. All rights reserved. 15 + */ 16 + 17 + #include "strings.h" 18 + 19 + 20 + /* 21 + Scan string S until a character in B is found. If none is found, then a 22 + zero is returned, otherwise the number of characters before the break 23 + character is returned. Quoted strings and literals are skipped. Also, 24 + the backslash is recognized as an escape character. 25 + 26 + Clarification: if no match in B is found, the value returned is the 27 + length of the string. If the first character matches, then the value 28 + returned would be zero. The value returned can be used as an index 29 + into the string (starting from 0) which points to the break character, 30 + or is equal to the length of the string if there is no break character. 31 + */ 32 + #line 0 stcarg 33 + int stcarg( s, b ) 34 + char *b; /* break char set */ 35 + register char *s; /* source string */ 36 + { 37 + register char c; /* string terminator */ 38 + register char *t; /* break set temporary */ 39 + register char *s0 = s; /* original value of s */ 40 + 41 + while ( *s ) 42 + if ( *s == '"' || *s == '\'') 43 + { 44 + for (c = *s++; (*s) && (*s != c); s++) 45 + ; 46 + s++; 47 + } 48 + else 49 + if ( *s == '\\' ) s++; 50 + else 51 + { 52 + for (t = b; (*t) && (*s != *t); t++ ) 53 + ; 54 + 55 + if ( *t ) break; 56 + 57 + s++; 58 + } 59 + 60 + return( s-s0 ); 61 + } 62 + 63 + 64 + /* Scan string S for first substring that matches the pattern in P. If a 65 + pattern is found, then *Q is set to point to the start of the substring, 66 + and it's length is returned. If the string is not found, then the length 67 + returned is zero, and Q is unchanged. 68 + 69 + */ 70 + #line 0 stcmp 71 + int stcpm( s, p, q ) 72 + char *p; /* pattern string */ 73 + char **q; /* points to matched string */ 74 + register char *s; /* source string */ 75 + { 76 + register int i; 77 + 78 + while ( *s ) 79 + if ( (i = stcpma( s, p )) ) 80 + { 81 + *q = s; 82 + return( i ); 83 + } 84 + else 85 + s++; 86 + return( 0 ); 87 + } 88 + 89 + 90 + /* Determine if string S starts with the pattern indicated in P. If it does, 91 + it indicates the number of characters matched from the pattern. If not, 92 + it returns zero. 93 + */ 94 + #line 0 stcpma 95 + int stcpma( string, pattern ) 96 + register char *pattern; /* pattern to match */ 97 + register char *string; /* character to match */ 98 + { 99 + register char c; /* current pattern char */ 100 + char *start = string; /* start of input string */ 101 + 102 + 103 + while ( *pattern ) 104 + if ( *pattern == '?' ) 105 + { 106 + string++; 107 + pattern++; 108 + } 109 + else 110 + { 111 + c = *pattern++; 112 + if ( c == '\\' ) 113 + { 114 + switch (*pattern) 115 + { 116 + case '*': 117 + case '+': 118 + case '?': 119 + c = *pattern++; 120 + break; 121 + default: 122 + continue; 123 + } 124 + } 125 + 126 + if ( *pattern == '*' ) 127 + { /* matches 0 .. n of C */ 128 + pattern++; 129 + while ( *string == c ) 130 + string++; 131 + } 132 + else if ( *pattern == '+' ) 133 + { /* matches 1 .. n of C */ 134 + pattern++; 135 + if ( *string == c ) 136 + while ( *string == c ) 137 + string++; 138 + else 139 + break; 140 + } 141 + else if ( c == *string ) 142 + string++; 143 + else 144 + break; 145 + } 146 + return( string - start ); 147 + } 148 + 149 + 150 + /* 151 + Return pointer to next symbol in input string. A valid symbol starts 152 + with a letter and is alphanumeric after that. Leading white space is not 153 + skipped. If no symbol is found, S is returned, and SYM has a NULL as the 154 + first byte. SYM is always NULL terminated. 155 + */ 156 + #line 0 stpsym 157 + char *stpsym( s, sym, symlen ) 158 + register char *s; /* pointer to input string */ 159 + register char *sym; /* pointer to output string */ 160 + register int symlen; /* sizeof( sym ) */ 161 + { 162 + if ( (*s >= 'a' && *s <= 'z') || (*s >= 'A' && *s <= 'Z') ) 163 + while ( (*s >= 'a' && *s <= 'z') || (*s >= 'A' && *s <= 'Z') || 164 + (*s >= '0' && *s <= '9' ) ) 165 + { 166 + if (symlen > 1) 167 + { 168 + symlen--; 169 + *sym++ = *s; 170 + } 171 + s++; 172 + } 173 + *sym = '\0'; 174 + return( s ); 175 + } 176 + 177 + /* duplicated here from strings.c for self-containment of unix strings */ 178 + 179 + static int strcspn() /* a0 = s, a1 = set, a2 = t */ 180 + { 181 + asm 182 + { 183 + movem.l 4(a7),a0-a1 184 + strcspn1: 185 + tst.b (a0) ; is *s zero? 186 + beq.s @strcspnx ; yes, exit 187 + move.l a1,a2 ; t = set 188 + strcspn2: 189 + tst.b (a2) ; is *t zero? 190 + beq.s @strcspn3 ; yes, try next *s 191 + cmpm.b (a0)+,(a2)+ ; is char in set? 192 + subq.l #1,a0 ; no such inst as cmpm (a0),(a2)+ 193 + beq.s @strcspnx ; yes, exit 194 + bra.s @strcspn2 195 + strcspn3: 196 + addq.l #1,a0 ; yes, loop through for next char in s 197 + bra.s @strcspn1 198 + strcspnx: 199 + move.l a0,d0 ; subtract current pos from orig 200 + sub.l 4(a7),d0 ; to get count 201 + return 202 + } 203 + } 204 + 205 + static char *strncpy() 206 + { 207 + asm 208 + { 209 + movem.l 4(a7),a0-a1 210 + move.l a0,d0 211 + move.w 12(a7),d1 212 + bgt.s @strncpy1 213 + strncpyx: 214 + return 215 + strncpy1: 216 + move.b (a1)+,(a0)+ 217 + beq.s @strncpy2 ; if zero byte, see if we need to fill 218 + subq.w #1,d1 219 + bgt.s @strncpy1 ; is count exhausted? 220 + beq.s @strncpyx ; yes, quit now 221 + strncpy2: 222 + subq.w #1,d1 223 + beq.s @strncpyx 224 + clr.b (a0)+ ; zero end of string until count runs out 225 + bra.s @strncpy2 226 + } 227 + } 228 + 229 + 230 + /* 231 + Return the next token from S in TOK. The break characters for the ending 232 + of token are in BRK. Leading whitespace is not skipped. If no token is 233 + found, then S is returned. TOK is always NULL terminated. 234 + */ 235 + #line 0 stptok 236 + char *stptok( s, tok, toklen, brk ) 237 + char *brk; /* pointer to break string */ 238 + char *s; /* pointer to input string */ 239 + char *tok; /* pointer to output string */ 240 + int toklen; /* sizeof( tok ) */ 241 + { 242 + register int i; 243 + 244 + i = strcspn( s, brk ); 245 + strncpy( tok, s, i = i < toklen ? i : toklen - 1 ); 246 + tok[i] = '\0'; 247 + return( s + i ); 248 + }
+21
sources/unixatof.c
··· 1 + /* (C) Copyright 1986. THINK Technologies, Inc. All rights reserved. */ 2 + 3 + #include "unix.h" 4 + #include "sane.h" 5 + #include "MacTypes.h" 6 + 7 + double atof(s) 8 + char *s; 9 + 10 + { 11 + 12 + Decimal _decimal_; 13 + int index=0; 14 + Boolean read_error; 15 + double x; 16 + 17 + 18 + CStr2Dec(s,&index,&_decimal_,&read_error); 19 + fp68k(&_decimal_,&x,FFEXT|FOD2B); 20 + return(x); 21 + }
+55
sources/unixatox.c
··· 1 + /* (C) Copyright 1986. THINK Technologies, Inc. All rights reserved. */ 2 + 3 + 4 + #ifndef _ctypeh_ 5 + #include "ctype.h" 6 + #endif 7 + 8 + #line 0 atoi 9 + 10 + int atoi(s) 11 + register char *s; 12 + { 13 + register char signflag = 0; 14 + register int r=0; 15 + 16 + while (isspace(*s)) s++; 17 + 18 + if (*s=='-') 19 + { 20 + signflag = 1; 21 + s++; 22 + } 23 + else 24 + if (*s=='+') s++; 25 + 26 + while (isdigit(*s)) 27 + r = r * 10 + (*s++ - '0'); 28 + 29 + return (signflag?-r:r); 30 + } 31 + 32 + 33 + #line 0 atol 34 + 35 + long atol( s ) 36 + register char *s; 37 + { 38 + register char signflag = 0; 39 + register long r=0; 40 + 41 + while (isspace(*s)) s++; 42 + 43 + if (*s=='-') 44 + { 45 + signflag = 1; 46 + s++; 47 + } 48 + else 49 + if (*s=='+') s++; 50 + 51 + while (isdigit(*s)) 52 + r = r * 10 + (*s++ - '0'); 53 + 54 + return (signflag?-r:r); 55 + }
+46
sources/unixexec.c
··· 1 + /* (C) Copyright 1986. THINK Technologies, Inc. All rights reserved. */ 2 + 3 + /* This module implements abbreviated versions of execl, execv, execle, 4 + and execve. It seems that the args should do something, however 5 + nothing is done with them here. These are implemented purely as a 6 + starting point for those applications which need to do transfers to 7 + other applications. */ 8 + 9 + char *CtoPstr(); 10 + 11 + 12 + #line 0 execl 13 + 14 + execl(path, arg) 15 + char *path, *arg; 16 + { /* designed for launching application with arg0, arg1, ..., argn */ 17 + 18 + Launch(0, CtoPstr(path)); 19 + } 20 + 21 + #line 0 execv 22 + 23 + execv(path, argv) 24 + char *path, *argv[]; 25 + { 26 + Launch(0, CtoPstr(path)); 27 + } 28 + 29 + #line 0 execle 30 + 31 + execle(path, arg) 32 + char *path, *arg; 33 + { 34 + /* launch application with arg0, arg1, ..., argn, 0, env */ 35 + 36 + Launch(0, CtoPstr(path)); 37 + } 38 + 39 + #line 0 execve 40 + 41 + execve(path, argv, envp) 42 + char *path, *argv[], *envp[]; 43 + { 44 + Launch(0, CtoPstr(path)); 45 + } 46 +
+42
sources/unixexit.c
··· 1 + /* (C) Copyright 1986. THINK Technologies, Inc. All rights reserved. */ 2 + 3 + #ifndef _stdioh_ 4 + #include "stdio.h" 5 + #endif 6 + 7 + #ifndef _ctypeh_ 8 + #include "ctype.h" 9 + #endif 10 + 11 + #ifndef _unixh_ 12 + #include "unix.h" 13 + #endif 14 + 15 + #line 0 exit 16 + 17 + void exit() 18 + { 19 + ExitToShell(); 20 + } 21 + 22 + #line 0 _exit 23 + 24 + void _exit() 25 + { 26 + ExitToShell(); 27 + } 28 + 29 + #define AutoInt7 (*(long*) 0x7C) 30 + #define ROMBase (*(long*) 0x2AE) 31 + #define MaskPtr (*(long*) 0x31A) 32 + 33 + #line 0 abort 34 + 35 + void abort() 36 + { 37 + 38 + if ((AutoInt7 & MaskPtr) < ROMBase) 39 + DebugStr("\pAbort"); 40 + 41 + ExitToShell(); 42 + }
+362
sources/unixfileio.c
··· 1 + /* (C) Copyright 1986. THINK Technologies, Inc. All rights reserved. */ 2 + 3 + /* This module translates UNIX I/O style calls to STDIO calls */ 4 + 5 + #ifndef _stdioh_ 6 + #include "stdio.h" 7 + #endif 8 + 9 + #ifndef _ctypeh_ 10 + #include "ctype.h" 11 + #endif 12 + 13 + #ifndef _unixh_ 14 + #include "unix.h" 15 + #endif 16 + 17 + #ifndef _FileMgr_ 18 + #include "FileMgr.h" 19 + #endif 20 + 21 + Boolean _unix_file_exists(filename) 22 + char *filename; 23 + { 24 + FILE *who; 25 + fileParam pb2; 26 + 27 + CtoPstr(filename); 28 + 29 + pb2.ioFDirIndex = 0; 30 + pb2.ioNamePtr = (StringPtr)filename; 31 + pb2.ioVRefNum = 0; 32 + pb2.ioFVersNum = 0; 33 + 34 + if (PBGetFInfo(&pb2,false) == fnfErr) 35 + { 36 + PtoCstr(filename); 37 + return(false); 38 + } 39 + PtoCstr(filename); 40 + return(true); 41 + } 42 + 43 + 44 + static char *cvtmode(mode,filename) 45 + register int mode; 46 + char *filename; 47 + { 48 + register int i=0; 49 + static char stdmode[5]; 50 + 51 + if ((mode & O_EXCL) && (mode & O_CREAT)) 52 + if (_unix_file_exists(filename)) 53 + { 54 + errno = EEXIST; 55 + return(NULL); 56 + } 57 + 58 + switch (mode & (O_RDONLY | O_WRONLY | O_RDWR)) 59 + { 60 + case O_RDONLY: 61 + if (mode & O_APPEND) 62 + { 63 + errno = EINVAL; 64 + return (NULL); 65 + } 66 + 67 + if ((mode & O_CREAT)||(mode & O_TRUNC)) 68 + { 69 + stdmode[i++] = 'w'; 70 + stdmode[i++] = '+'; 71 + } 72 + else 73 + stdmode[i++] = 'r'; 74 + break; 75 + 76 + case O_WRONLY: 77 + if (mode & O_APPEND) 78 + { 79 + if (mode & O_TRUNC) 80 + stdmode[i++] = 'w'; 81 + else 82 + stdmode[i++] = 'a'; 83 + } 84 + else 85 + stdmode[i++] = 'w'; 86 + break; 87 + 88 + case O_RDWR: 89 + nonstdmode: 90 + if ((mode & O_CREAT) || (mode & O_TRUNC)) 91 + stdmode[i++] = 'w'; 92 + else 93 + if (mode & O_APPEND) 94 + stdmode[i++] = 'a'; 95 + else 96 + stdmode[i++] = 'r'; 97 + 98 + stdmode[i++] = '+'; 99 + break; 100 + 101 + default: 102 + /* if no mode was selected, append is a legal mode in this 103 + implementation and is treated as RDWR append */ 104 + 105 + if (mode & O_APPEND) goto nonstdmode; 106 + 107 + errno = EINVAL; 108 + return (NULL); 109 + } 110 + 111 + if (mode & O_BINARY) 112 + stdmode[i++] = 'b'; 113 + 114 + stdmode[i++] = '\0'; 115 + 116 + return (stdmode); 117 + } 118 + 119 + static int invalidfildes(fildes) 120 + register int fildes; 121 + { 122 + if ((fildes >= _NFILE) || (!_file[fildes].InUse)) 123 + { 124 + errno = EBADF; 125 + return (1); 126 + } 127 + 128 + return (0); 129 + } 130 + 131 + /* searches thru the file descriptors for a free file 132 + and returns the file position of a free file. */ 133 + 134 + static int findfreefileref() 135 + { 136 + register int i; 137 + 138 + for (i=0; i<_NFILE; i++) 139 + if (! _file[i].InUse) 140 + return i; 141 + 142 + return (-1); 143 + } 144 + 145 + int fread(); 146 + int fwrite(); 147 + 148 + static unsigned int fileop(fildes, buffer, nbytes, op) 149 + register int fildes; 150 + char *buffer; 151 + unsigned nbytes; 152 + unsigned int (*op)(); 153 + { 154 + unsigned int actcount; 155 + extern Boolean _unsignedbytes; 156 + 157 + if (invalidfildes(fildes)) 158 + return (-1); 159 + 160 + _unsignedbytes = true; /* one-shot flag for unsigned nbytes */ 161 + 162 + if (actcount = (*op)(buffer, sizeof(*buffer), nbytes, &_file[fildes])) 163 + return (actcount); 164 + 165 + /* pdg - 6/10/86 - supposed to return zero on eof, not error! */ 166 + 167 + if (_file[fildes].last_error == eofErr) 168 + return (0); 169 + 170 + errno = EIO; 171 + return (-1); 172 + } 173 + 174 + #line 0 fileno 175 + 176 + int fileno(who) 177 + register FILE *who; 178 + { 179 + if ((!who)||(!who->InUse)) 180 + return(-1); 181 + 182 + return(who->fileno); 183 + } 184 + 185 + #line 0 open 186 + 187 + int open(filename, mode) 188 + char *filename; 189 + int mode; 190 + { 191 + int fildes; 192 + char *type; 193 + 194 + if (findfreefileref() == -1) 195 + { 196 + errno = EMFILE; 197 + return(-1); 198 + } 199 + 200 + if ((type = cvtmode(mode,filename)) == NULL) 201 + return(-1); 202 + 203 + if (fildes = fopen(filename, type)->fileno) 204 + return (fildes); 205 + 206 + errno = EACCES; 207 + return (-1); 208 + } 209 + 210 + #line 0 close 211 + 212 + int close(fildes) 213 + register int fildes; 214 + { 215 + if (invalidfildes(fildes)) 216 + return (-1); 217 + 218 + return (fclose(&_file[fildes])); 219 + } 220 + 221 + 222 + #line 0 read 223 + 224 + int read(fildes, buffer, nbytes) 225 + int fildes; 226 + char *buffer; 227 + unsigned nbytes; 228 + { 229 + return (fileop(fildes, buffer, nbytes, fread)); 230 + } 231 + 232 + #line 0 write 233 + 234 + int write(fildes, buffer, nbytes) 235 + int fildes; 236 + char *buffer; 237 + unsigned nbytes; 238 + { 239 + return (fileop(fildes, buffer, nbytes, fwrite)); 240 + } 241 + 242 + #line 0 lseek 243 + 244 + long lseek(fildes, offset, offsetmode) 245 + register int fildes; 246 + long int offset; 247 + register unsigned int offsetmode; 248 + { 249 + if (invalidfildes(fildes)) 250 + return (-1L); 251 + 252 + if (offsetmode>2) 253 + { 254 + errno = EINVAL; 255 + return(-1L); 256 + } 257 + 258 + if (fseek(&_file[fildes], offset, offsetmode)) 259 + { 260 + errno = EIO; 261 + return (-1L); 262 + } 263 + 264 + return (ftell(&_file[fildes])); 265 + } 266 + 267 + /* 268 + This is an old Unix seek which returns an int instead of a long and 269 + is commented out unless you really want to bother uncommenting it! 270 + 271 + #line 0 seek 272 + 273 + int seek(fildes, offset, origin) 274 + int fildes; 275 + register int offset; 276 + int origin; 277 + { 278 + long longoffset; 279 + int neworigin; 280 + 281 + longoffset = ((neworigin = origin % 3) == origin) ? offset : (long)offset*512; 282 + 283 + return ((int) lseek(fildes, longoffset, neworigin)); 284 + } 285 + */ 286 + 287 + #line 0 tell 288 + 289 + long tell(fildes) 290 + int fildes; 291 + { 292 + return (ftell(&_file[fildes])); 293 + } 294 + 295 + #line 0 rename 296 + 297 + int rename(old,new) 298 + char *old,*new; 299 + { 300 + ioParam pb; 301 + 302 + CtoPstr(old); 303 + CtoPstr(new); 304 + pb.ioNamePtr = (StringPtr)old; 305 + pb.ioVRefNum = 0; 306 + pb.ioVersNum = 0; 307 + pb.ioMisc = new; 308 + 309 + if (PBRename(&pb,false)) 310 + { 311 + errno = EIO; 312 + PtoCstr(old); 313 + PtoCstr(new); 314 + return(-1); 315 + } 316 + 317 + PtoCstr(old); 318 + PtoCstr(new); 319 + 320 + return(0); 321 + } 322 + 323 + #line 0 remove 324 + 325 + int remove(name) 326 + char *name; 327 + { 328 + ioParam pb; 329 + 330 + CtoPstr(name); 331 + pb.ioNamePtr = (StringPtr)name; 332 + pb.ioVRefNum = 0; 333 + pb.ioVersNum = 0; 334 + 335 + if (PBDelete(&pb,false)) 336 + { 337 + errno = EIO; 338 + PtoCstr(name); 339 + return(-1); 340 + } 341 + PtoCstr(name); 342 + return(0); 343 + } 344 + 345 + #line 0 unlink 346 + 347 + int unlink(name) 348 + char *name; 349 + { 350 + return(remove(name)); 351 + } 352 + 353 + #line 0 creat 354 + 355 + int creat(filename, mode) 356 + char *filename; 357 + int mode; 358 + { 359 + return (open(filename, mode | O_CREAT)); 360 + } 361 + 362 +
+59
sources/unixid.c
··· 1 + /* (C) Copyright 1986. THINK Technologies, Inc. All rights reserved. */ 2 + 3 + #ifndef _stdioh_ 4 + #include "stdio.h" 5 + #endif 6 + 7 + #ifndef _ctypeh_ 8 + #include "ctype.h" 9 + #endif 10 + 11 + #ifndef _unixh_ 12 + #include "unix.h" 13 + #endif 14 + 15 + 16 + static int ouruid = 1; 17 + static int ourpid = 1; 18 + 19 + #line 0 getuid 20 + 21 + int getuid() 22 + { 23 + return(ouruid); 24 + } 25 + 26 + #line 0 setuid 27 + 28 + int setuid(uid) 29 + int uid; 30 + { 31 + ouruid = uid; 32 + return(0); 33 + } 34 + 35 + #line 0 getpid 36 + 37 + int getpid() 38 + { 39 + return(ourpid); 40 + } 41 + 42 + #line 0 setpid 43 + 44 + int setpid(pid) 45 + int pid; 46 + { 47 + ourpid = pid; 48 + return(0); 49 + } 50 + 51 + #line 0 cgetpid 52 + 53 + char *cgetpid(sptr) 54 + char *sptr; 55 + { 56 + sprintf(sptr,"%s%05d",sptr,ourpid); 57 + return(sptr); 58 + } 59 +
+40
sources/unixmem.c
··· 1 + /* (C) Copyright 1986. THINK Technologies, Inc. All rights reserved. */ 2 + 3 + #ifndef _unixh_ 4 + #include "unix.h" 5 + #endif 6 + 7 + #line 0 setmem 8 + 9 + void setmem(p,n,c) 10 + register char *p; 11 + register unsigned n; 12 + register char c; 13 + { 14 + while (n--) 15 + *p++ = c; 16 + } 17 + 18 + #line 0 repmem 19 + 20 + void repmem(s,v,lv,nv) 21 + register char *s, *v; 22 + register int lv,nv; 23 + { 24 + register char *p; 25 + register int i; 26 + 27 + while (nv--) 28 + for (p=v, i=lv; i; i--) 29 + *s++ = *p++; 30 + } 31 + 32 + #line 0 movmem 33 + 34 + void movmem(s,d,n) 35 + char *s,*d; 36 + unsigned n; 37 + { 38 + BlockMove(s,d,n); 39 + } 40 +
+84
sources/unixplot.c
··· 1 + /* (C) Copyright 1986. THINK Technologies, Inc. All rights reserved. */ 2 + 3 + #ifndef _unixh_ 4 + #include "unix.h" 5 + #endif 6 + 7 + #ifndef _QuickDraw_ 8 + #include "QuickDraw.h" 9 + #endif 10 + 11 + extern GrafPort stdioPort; 12 + 13 + #line 0 eraseplot 14 + 15 + void eraseplot() 16 + { 17 + Init_stdio(); 18 + putch('\f'); 19 + } 20 + 21 + #line 0 line 22 + 23 + void line(x1,y1,x2,y2) 24 + int x1,y1,x2,y2; 25 + { 26 + Init_stdio(); 27 + MoveTo(x1,y1); 28 + LineTo(x2,y2); 29 + } 30 + 31 + #line 0 move 32 + 33 + void move(x,y) 34 + int x,y; 35 + { 36 + Init_stdio(); 37 + MoveTo(x,y); 38 + } 39 + 40 + #line 0 circle 41 + 42 + void circle(x,y,r) 43 + int x,y,r; 44 + { 45 + Rect rect; 46 + Pattern p; 47 + 48 + Init_stdio(); 49 + SetRect(&rect,x-r/2,y-r/2,x+r/2,y+r/2); 50 + PaintArc(&rect,0,360); 51 + } 52 + 53 + #line 0 cont 54 + 55 + void cont(x,y) 56 + int x,y; 57 + { 58 + Init_stdio(); 59 + LineTo(x,y); 60 + } 61 + 62 + #line 0 point 63 + 64 + void point(x,y) 65 + int x,y; 66 + { 67 + Rect rect; 68 + 69 + Init_stdio(); 70 + SetRect(&rect,x,y,x+1,y+1); 71 + PaintRect(&rect); 72 + } 73 + 74 + #line 0 label 75 + 76 + void label(s) 77 + char *s; 78 + { 79 + Init_stdio(); 80 + CtoPstr(s); 81 + DrawString(s); 82 + PtoCstr(s); 83 + } 84 +
+49
sources/unixsetbuf.c
··· 1 + /* (C) Copyright 1986. THINK Technologies, Inc. All rights reserved. */ 2 + 3 + #ifndef _stdioh_ 4 + #include "stdio.h" 5 + #endif 6 + 7 + #ifndef _MacTypes_ 8 + #include "MacTypes.h" 9 + #endif 10 + 11 + #line 0 setbuf 12 + 13 + int setbuf(fp,buf) 14 + register FILE *fp; 15 + char *buf; 16 + { 17 + if (buf == NULL) 18 + return(setnbuf(fp)); 19 + 20 + if (! fp->user_buf) 21 + { 22 + DisposPtr(fp->filebuf); 23 + fp->user_buf = true; 24 + } 25 + 26 + fp->filebuf = buf; 27 + fp->fpos = 555; 28 + fp->inbuf = 0; 29 + return(0); 30 + } 31 + 32 + #line 0 setnbuf 33 + 34 + int setnbuf(fp) 35 + register FILE *fp; 36 + { 37 + Ptr p; 38 + 39 + if (! fp->user_buf) 40 + return(0); 41 + 42 + p = NewPtr(BUFSIZ+10); 43 + fp->user_buf = false; 44 + fp->filebuf = p; 45 + fp->fpos = 555; 46 + fp->inbuf = 0; 47 + 48 + return(0); 49 + }
+143
sources/unixsignal.c
··· 1 + /* (C) Copyright 1986. THINK Technologies, Inc. All rights reserved. */ 2 + 3 + /* This module implements an abbreviated version of signal() and its 4 + related functions */ 5 + 6 + #ifndef _unixh_ 7 + #include "unix.h" 8 + #endif 9 + 10 + extern int errno; 11 + extern int (*_key_int_sig_func_)(); 12 + 13 + static void *sigptr[_SIGMAX+1]; /* array of signal pointers, initially 0 */ 14 + static char _initsigterm = 0; /* flag for special SIGTERM set up */ 15 + 16 + #define AutoInt7 (*(long*) 0x7C) 17 + #define ROMBase (*(long*) 0x2AE) 18 + #define MaskPtr (*(long*) 0x31A) 19 + 20 + #line 0 bugout 21 + 22 + static void bugout() 23 + { 24 + /* call debugger if loaded, then (or otherwise) depart */ 25 + 26 + if ((AutoInt7 & MaskPtr) < ROMBase) 27 + DebugStr("\pSIGDFL exit!"); 28 + 29 + ExitToShell(); 30 + } 31 + 32 + #line 0 dosigterm 33 + 34 + static void dosigterm() 35 + {register void (*calledfunc)() = sigptr[SIGTERM]; 36 + 37 + /* if non-zero, call this procedure on exit from application */ 38 + 39 + if (calledfunc) 40 + (*calledfunc)(SIGTERM); 41 + } 42 + 43 + 44 + #line 0 signal 45 + 46 + int (*signal(sig, func))() 47 + int sig; 48 + int (*func)(); 49 + { 50 + int (*_last_sig_func_)(); 51 + 52 + /* SIGINT is presently supported as a special case for trapping ^c 53 + and ^. (where ^ means the command (fan) key. ^c and ^. are 54 + therefore invisible to the application and are swallowed when the 55 + interrupt procedure is called. This was done so lots of unix 56 + code would not get dragged in for those just using stdio. */ 57 + 58 + switch (sig) 59 + { 60 + case SIGINT: 61 + 62 + _last_sig_func_= _key_int_sig_func_; 63 + 64 + /* see if user wants to cause an exit on SIGINT */ 65 + 66 + if ((long)func == SIG_DFL) 67 + _key_int_sig_func_ = (void*) bugout; 68 + else 69 + if ((long)func == SIG_IGN) 70 + _key_int_sig_func_ = 0; /* eliminate any set function */ 71 + else 72 + _key_int_sig_func_ = func; /* set up "catch" function */ 73 + 74 + return (_last_sig_func_); /* return last catch function */ 75 + 76 + case SIGTERM: 77 + 78 + /* enable sending a last signal on application termination */ 79 + 80 + if (!_initsigterm) 81 + { 82 + _initsigterm = 1; 83 + onexit(dosigterm); 84 + } 85 + default: 86 + if ((sig > 0) && (sig <= _SIGMAX)) 87 + { 88 + _last_sig_func_ = sigptr[sig]; 89 + 90 + /* see if user wants to cause an exit on signal */ 91 + 92 + if ((long)func == SIG_DFL) 93 + sigptr[sig] = (void*) bugout; 94 + else 95 + if ((long)func == SIG_IGN) 96 + sigptr[sig] = 0; /* eliminate any set function */ 97 + else 98 + sigptr[sig] = func; /* set up "catch" function */ 99 + 100 + return (_last_sig_func_); /* return last catch function */ 101 + } 102 + 103 + if (sig == 0) return (0); 104 + 105 + /* signal value out of range */ 106 + 107 + errno = EINVAL; 108 + return ((void*)-1); 109 + } 110 + } 111 + 112 + #line 0 kill 113 + 114 + kill(pid, sig) 115 + int pid, sig; 116 + { 117 + if ((sig > _SIGMAX) || (sig < 0)) 118 + { 119 + /* signal value out of range */ 120 + errno = EINVAL; 121 + return (-1); 122 + } 123 + 124 + if ((pid == getpid()) || (pid <= 0)) 125 + {register void (*calledfunc)() = sigptr[sig]; 126 + 127 + if (sig) 128 + { 129 + /* send a signal to ourself! */ 130 + 131 + sigptr[sig] = (void*) SIG_DFL; 132 + 133 + if (calledfunc) 134 + (*calledfunc)(sig); 135 + } 136 + 137 + return (0); 138 + } 139 + 140 + errno = ESRCH; /* no such process */ 141 + return (-1); 142 + } 143 +
+58
sources/unixst2d.c
··· 1 + /* (C) Copyright 1986. THINK Technologies, Inc. All rights reserved. */ 2 + 3 + 4 + static stc_d(out, in, outlen, signflag) 5 + register char *out; 6 + register unsigned int in; 7 + register int outlen; 8 + int signflag; 9 + { 10 + char revnum [8]; 11 + register int i=0; 12 + register char *out0 = out; 13 + 14 + if (outlen<=0) return (0); 15 + 16 + if (in == 0) revnum[i++]=0; 17 + else 18 + while (in) 19 + { 20 + revnum[i++] = in - (in/10)*10; 21 + in /= 10; 22 + } 23 + 24 + if (signflag) 25 + { 26 + *out++ = '-'; 27 + outlen--; 28 + } 29 + 30 + for (; i && outlen; i--, outlen--) 31 + *out++ = revnum[i-1] + '0'; 32 + 33 + *out = '\0'; 34 + 35 + return (out-out0); 36 + 37 + } 38 + 39 + #line 0 stci_d 40 + 41 + stci_d(out, in, outlen) 42 + char *out; 43 + int in; 44 + int outlen; 45 + { 46 + return (stc_d(out, (in>=0?in:-in), outlen, in<0)); 47 + } 48 + 49 + #line 0 stcu_d 50 + 51 + stcu_d(out, in, outlen) 52 + char *out; 53 + unsigned int in; 54 + int outlen; 55 + { 56 + return (stc_d(out, in, outlen, 0)); 57 + } 58 +
+68
sources/unixst2i.c
··· 1 + /* (C) Copyright 1986. THINK Technologies, Inc. All rights reserved. */ 2 + 3 + #ifndef _ctypeh_ 4 + #include "ctype.h" 5 + #endif 6 + 7 + #line 0 stcd_i 8 + 9 + int stcd_i(s,r) 10 + register char *s; 11 + register int *r; 12 + { 13 + register char *s0=s; 14 + register char signflag = 0; 15 + 16 + *r = 0; 17 + 18 + while (isspace(*s)) s++; 19 + 20 + if (*s=='-') 21 + { 22 + signflag = 1; 23 + s++; 24 + } 25 + else 26 + if (*s=='+') s++; 27 + 28 + while (isdigit(*s)) 29 + *r = *r * 10 + (*s++ - '0'); 30 + 31 + if (signflag) *r = -*r; 32 + 33 + return (s-s0); 34 + } 35 + 36 + #line 0 stch_i 37 + 38 + int stch_i(s,r) 39 + register char *s; 40 + register int *r; 41 + { 42 + register char *s0=s; 43 + register char signflag = 0; 44 + 45 + *r = 0; 46 + 47 + while (isspace(*s)) s++; 48 + 49 + if (*s=='-') 50 + { 51 + signflag = 1; 52 + s++; 53 + } 54 + else 55 + if (*s=='+') s++; 56 + 57 + while (isxdigit(*s)) 58 + { 59 + *r = (*r << 4) + (isdigit(*s) ? (*s-'0'):toupper(*s)-'A'+10); 60 + s++; 61 + } 62 + 63 + if (signflag) *r = -*r; 64 + 65 + return (s-s0); 66 + 67 + } 68 +
+159
sources/unixtime.c
··· 1 + /* (C) Copyright 1986. THINK Technologies, Inc. All rights reserved. */ 2 + 3 + #include "stdio.h" 4 + #include "time.h" 5 + 6 + #ifndef _ctypeh_ 7 + #include "ctype.h" 8 + #endif 9 + 10 + #ifndef _OSUtil_ 11 + #include "OSUtil.h" 12 + #endif 13 + 14 + #ifndef _IntlPkg_ 15 + #include "IntlPkg.h" 16 + #endif 17 + 18 + /* The Macintosh keeps a raw seconds count that begins at 19 + 00:00:00 January 1, 1904 local time, 20 + UNIX uses 00:00:00 January 1, 1970 GMT */ 21 + 22 + /* seconds difference between EST & GMT time zones */ 23 + #define GMTzonedif (5*60*60) 24 + 25 + #define TMacbaseyr 1904 26 + #define TUNIXbaseyr 1970 27 + 28 + /* number of leap days between the two years -- Mac base was a leap year! */ 29 + #define TLpD ((TUNIXbaseyr-TMacbaseyr-1)/4) 30 + 31 + /* TimeBaseDif is the number of seconds between Mac and UNIX time (GMT) */ 32 + #define TimeBaseDif ((((TUNIXbaseyr-TMacbaseyr)*365)+TLpD)*24*60*60) 33 + 34 + /* global variables for time computations */ 35 + 36 + long timezone = GMTzonedif; /* difference between GMT & local time */ 37 + 38 + int daylight = 0; /* daylight savings time flag */ 39 + 40 + char *tzname[2] = {"EST", "EDT"}; /* names of time zones */ 41 + 42 + #line 0 time 43 + 44 + /* This routine returns the time since Jan 1, 1970 00:00:00 GMT */ 45 + 46 + unsigned long time(clock) 47 + unsigned long *clock; 48 + { 49 + unsigned long GMTtimenow = Time-TimeBaseDif+timezone; 50 + 51 + if (clock) 52 + *clock = GMTtimenow; 53 + 54 + return (GMTtimenow); 55 + } 56 + 57 + #line 0 ctime 58 + 59 + char *ctime(clock) 60 + register unsigned long *clock; 61 + { 62 + static char timebuffer[26]; 63 + register char *tp; 64 + DateTimeRec MacTimeRec; 65 + register Intl1Hndl myHndl; 66 + register int i; 67 + 68 + Secs2Date((clock?(*clock+TimeBaseDif):(Time+timezone)),&MacTimeRec); 69 + 70 + myHndl = (Intl1Hndl)IUGetIntl(1); 71 + tp = timebuffer; 72 + 73 + for (i=1; i<4; i++) 74 + *tp++ = (*myHndl)->days[MacTimeRec.dayOfWeek-1][i]; /* make day of week */ 75 + *tp++ = ' '; 76 + 77 + for (i=1; i<4; i++) 78 + *tp++ = (*myHndl)->months[MacTimeRec.month-1][i]; /* make month */ 79 + *tp++ = ' '; 80 + 81 + sprintf(tp,"%02d ",MacTimeRec.day); /* now put in day of month */ 82 + tp += 3; 83 + 84 + sprintf(tp,"%02d:%02d:%02d %d\n",MacTimeRec.hour,MacTimeRec.minute,MacTimeRec.second,MacTimeRec.year); 85 + 86 + return(timebuffer); 87 + } 88 + 89 + #line 0 localtime 90 + 91 + struct tm *localtime(clock) 92 + register unsigned long *clock; 93 + { 94 + DateTimeRec MacTimeRec; 95 + static struct tm UnixTimeRec; 96 + register int dayofyear=0, i; 97 + 98 + Secs2Date(clock?(*clock+TimeBaseDif-timezone):Time,&MacTimeRec); 99 + 100 + UnixTimeRec.tm_sec = (MacTimeRec.second); 101 + UnixTimeRec.tm_min = (MacTimeRec.minute); 102 + UnixTimeRec.tm_hour = (MacTimeRec.hour); 103 + UnixTimeRec.tm_mday = (MacTimeRec.day); 104 + UnixTimeRec.tm_mon = (MacTimeRec.month-1); /* UNIX uses 0-11 not 1-12 */ 105 + UnixTimeRec.tm_year = (MacTimeRec.year-1900); 106 + UnixTimeRec.tm_wday = (MacTimeRec.dayOfWeek-1); /* UNIX uses 0-6 not 1-7 */ 107 + 108 + for(i=0; i<UnixTimeRec.tm_mon; i++) 109 + { 110 + static char monthdays[11] = {31,28,31,30,31,30,31,31,30,31,30}; 111 + 112 + /* check for leap year in Feb */ 113 + if ((i==1) && !(MacTimeRec.year % 4) && !(MacTimeRec.year % 100)) 114 + dayofyear++; 115 + 116 + dayofyear += monthdays[i]; 117 + } 118 + 119 + UnixTimeRec.tm_yday = (dayofyear + MacTimeRec.day-1); 120 + 121 + UnixTimeRec.tm_isdst = daylight; 122 + 123 + return(&UnixTimeRec); 124 + 125 + } 126 + 127 + #line 0 gmtime 128 + 129 + struct tm *gmtime(clock) 130 + unsigned long *clock; 131 + { 132 + unsigned long temp = (clock?(*clock+timezone):(Time-TimeBaseDif+timezone)); 133 + 134 + return (localtime(&temp)); 135 + } 136 + 137 + #line 0 asctime 138 + 139 + char *asctime(UnixTimeRecp) 140 + register struct tm *UnixTimeRecp; 141 + { 142 + unsigned long clock; 143 + DateTimeRec MacTimeRec; 144 + 145 + MacTimeRec.second=UnixTimeRecp->tm_sec; 146 + MacTimeRec.minute = UnixTimeRecp->tm_min; 147 + MacTimeRec.hour = UnixTimeRecp->tm_hour; 148 + MacTimeRec.day = UnixTimeRecp->tm_mday; 149 + MacTimeRec.month = UnixTimeRecp->tm_mon+1; /* UNIX uses 0-11 not 1-12 */ 150 + MacTimeRec.year = UnixTimeRecp->tm_year+1900; 151 + MacTimeRec.dayOfWeek = UnixTimeRecp->tm_wday+1; /* UNIX uses 0-6 not 1-7 */ 152 + 153 + Date2Secs(&MacTimeRec, &clock); 154 + 155 + clock -= TimeBaseDif; /* convert to UNIX GMT time */ 156 + 157 + return (ctime(&clock)); 158 + 159 + }