···11+22+/*
33+ * DialogMgr.h
44+ *
55+ * Copyright (c) 1986 THINK Technologies, Inc.
66+ * These interfaces are based on information published in
77+ * "Inside Macintosh" by Apple Computer, Addison-Wesley,
88+ * Reading (Mass.), 1985.
99+ *
1010+ */
1111+1212+#ifndef _DialogMgr_
1313+#define _DialogMgr_
1414+1515+#ifndef _MacTypes_
1616+#include "MacTypes.h"
1717+#endif
1818+1919+#ifndef _WindowMgr_
2020+#include "WindowMgr.h"
2121+#endif
2222+2323+#ifndef _TextEdit_
2424+#include "TextEdit.h"
2525+#endif
2626+2727+/* item types */
2828+enum {
2929+ userItem = 0,
3030+ ctrlItem = 4,
3131+ statText = 8,
3232+ editText = 16,
3333+ iconItem = 32,
3434+ picItem = 64,
3535+ itemDisable = 128
3636+};
3737+3838+/* control item types */
3939+enum {
4040+ btnCtrl,
4141+ chkCtrl,
4242+ radCtrl,
4343+ resCtrl
4444+};
4545+4646+/* buttons */
4747+enum {
4848+ OK = 1,
4949+ Cancel
5050+};
5151+5252+/* alert icons */
5353+enum {
5454+ stopIcon,
5555+ noteIcon,
5656+ cautionIcon
5757+};
5858+#define ctnIcon cautionIcon
5959+6060+6161+typedef struct DialogRecord
6262+ {
6363+ WindowRecord window;
6464+ Handle items ;
6565+ TEHandle textH;
6666+ int editField;
6767+ int editOpen;
6868+ int aDefItem;
6969+ } DialogRecord ;
7070+typedef DialogRecord * DialogPeek;
7171+typedef WindowPtr DialogPtr ;
7272+7373+typedef struct DialogTemplate
7474+ {
7575+ Rect boundsRect;
7676+ int procID;
7777+ char visible;
7878+ char filler1;
7979+ char goAwayFlag;
8080+ char filler2;
8181+ long refCon;
8282+ int itemsID;
8383+ Str255 title;
8484+ } DialogTemplate;
8585+typedef DialogTemplate * DialogTPtr;
8686+typedef DialogTPtr * DialogTHndl;
8787+8888+typedef struct AlertTemplate
8989+ {
9090+ Rect boundsRect;
9191+ int itemsID;
9292+ unsigned int boldItm4 : 1; /* this is StageList */
9393+ unsigned int boxDrwn4 : 1;
9494+ unsigned int sound4 : 2;
9595+ unsigned int boldItm3 : 1;
9696+ unsigned int boxDrwn3 : 1;
9797+ unsigned int sound3 : 2;
9898+ unsigned int boldItm2 : 1;
9999+ unsigned int boxDrwn2 : 1;
100100+ unsigned int sound2 : 2;
101101+ unsigned int boldItm1 : 1;
102102+ unsigned int boxDrwn1 : 1;
103103+ unsigned int sound1 : 2;
104104+ } AlertTemplate;
105105+typedef AlertTemplate * AlertTPtr;
106106+typedef AlertTPtr * AlertTHndl;
107107+108108+109109+110110+/* functions returning non-integral values */
111111+pascal DialogPtr NewDialog();
112112+pascal DialogPtr GetNewDialog();
113113+114114+/* low-memory globals */
115115+extern ProcPtr ResumeProc : 0xA8C;
116116+117117+#endif
+62
headers/DiskDvr.h
···11+22+/*
33+ * DiskDvr.h
44+ *
55+ * Copyright (c) 1986 THINK Technologies, Inc.
66+ * These interfaces are based on information published in
77+ * "Inside Macintosh" by Apple Computer, Addison-Wesley,
88+ * Reading (Mass.), 1985.
99+ *
1010+ */
1111+1212+#ifndef _DiskDvr_
1313+#define _DiskDvr_
1414+1515+/* positioning */
1616+#define currPos 0 /* fsAtMark */
1717+#define absPos 1 /* fsFromStart */
1818+#define relPos 3 /* fsFromMark */
1919+2020+typedef struct
2121+ {
2222+ int track;
2323+ char writeProt;
2424+ char diskInPlace;
2525+ char installed;
2626+ char sides;
2727+ struct QElem *qLink;
2828+ int qType;
2929+ int dQDrive;
3030+ int dQRefNum;
3131+ int dQFSID;
3232+ char twoSideFmt;
3333+ char needsFlush;
3434+ int diskErrs;
3535+ } DrvSts;
3636+3737+/* result codes */
3838+#define firstDskErr (-84)
3939+enum {
4040+ sectNFErr = -81,
4141+ seekErr,
4242+ spdAdjErr,
4343+ twoSideErr,
4444+ initIWMErr,
4545+ tk0BadErr,
4646+ cantStepErr,
4747+ wrUnderrun,
4848+ badDBtSlp,
4949+ badDCksum,
5050+ noDtaMkErr,
5151+ badBtSlpErr,
5252+ badCksmErr,
5353+ dataVerErr,
5454+ noAdrMkErr,
5555+ noNybErr,
5656+ offLinErr,
5757+ noDriveErr
5858+};
5959+#define lastDskErr (-64)
6060+6161+6262+#endif
+120
headers/EventMgr.h
···11+22+/*
33+ * EventMgr.h
44+ *
55+ * Copyright (c) 1986 THINK Technologies, Inc.
66+ * These interfaces are based on information published in
77+ * "Inside Macintosh" by Apple Computer, Addison-Wesley,
88+ * Reading (Mass.), 1985.
99+ *
1010+ */
1111+1212+#ifndef _EventMgr_
1313+#define _EventMgr_
1414+1515+#ifndef _MacTypes_
1616+#include "MacTypes.h"
1717+#endif
1818+1919+/* event codes */
2020+enum {
2121+ nullEvent,
2222+ mouseDown,
2323+ mouseUp,
2424+ keyDown,
2525+ keyUp,
2626+ autoKey,
2727+ updateEvt,
2828+ diskEvt,
2929+ activateEvt,
3030+ /* event 9 is no longer used */
3131+ networkEvt = 10,
3232+ driverEvt,
3333+ app1Evt,
3434+ app2Evt,
3535+ app3Evt,
3636+ app4Evt
3737+};
3838+3939+/* masks for keyboard event message */
4040+#define charCodeMask 0x000000FFL
4141+#define keyCodeMask 0x0000FF00L
4242+4343+/* event masks */
4444+#define mDownMask 0x2
4545+#define mUpMask 0x4
4646+#define keyDownMask 0x8
4747+#define keyUpMask 0x10
4848+#define autoKeyMask 0x20
4949+#define updateMask 0x40
5050+#define diskMask 0x80
5151+#define activMask 0x100
5252+/* event 9 is no longer used */
5353+#define networkMask 0x400
5454+#define driverMask 0x800
5555+#define app1Mask 0x1000
5656+#define app2Mask 0x2000
5757+#define app3Mask 0x4000
5858+#define app4Mask 0x8000
5959+#define everyEvent 0xFFFF
6060+6161+/* modifiers */
6262+#define activeFlag 0x0001
6363+#define changeFlag 0x0002
6464+#define btnState 0x0080
6565+#define cmdKey 0x0100
6666+#define shiftKey 0x0200
6767+#define alphaLock 0x0400
6868+#define optionKey 0x0800
6969+7070+7171+/* results returned by PostEvent */
7272+/* #define noErr 0 */
7373+#define EvtNotEnb 1
7474+7575+7676+typedef struct EventRecord
7777+ {
7878+ int what;
7979+ long message;
8080+ long when;
8181+ Point where;
8282+ int modifiers;
8383+ }EventRecord;
8484+8585+typedef struct KeyMap
8686+ {
8787+ long Key[4];
8888+ }KeyMap;
8989+9090+typedef struct EvQEl
9191+ {
9292+ struct QElem *qLink;
9393+ int qType;
9494+ int evtQWhat;
9595+ long evtQMessage;
9696+ long evtQWhen;
9797+ Point evtQWhere;
9898+ int evtQModifiers;
9999+ } EvQEl, *EvQElPtr ;
100100+101101+102102+/* functions returning non-integral values */
103103+pascal struct QHdr *GetEvQHdr();
104104+105105+/* low-memory globals */
106106+extern int SysEvtMask : 0x144;
107107+extern struct QHdr EventQueue : 0x14A;
108108+extern char SEvtEnb : 0x15C;
109109+extern long Ticks : 0x16A;
110110+extern int KeyThresh : 0x18E;
111111+extern int KeyRepThresh : 0x190;
112112+extern ProcPtr JGNEFilter : 0x29A;
113113+extern ProcPtr Key1Trans : 0x29E;
114114+extern ProcPtr Key2Trans : 0x2A2;
115115+extern long DoubleTime : 0x2F0;
116116+extern long CaretTime : 0x2F4;
117117+extern char ScrDmpEnb : 0x2F8;
118118+119119+120120+#endif
+235
headers/FileMgr.h
···11+22+/*
33+ * FileMgr.h
44+ *
55+ * Copyright (c) 1986 THINK Technologies, Inc.
66+ * These interfaces are based on information published in
77+ * "Inside Macintosh" by Apple Computer, Addison-Wesley,
88+ * Reading (Mass.), 1985-86.
99+ *
1010+ */
1111+1212+#ifndef _FileMgr_
1313+#define _FileMgr_
1414+1515+#ifndef _MacTypes_
1616+#include "MacTypes.h"
1717+#endif
1818+1919+2020+/* finder constants */
2121+#define fHasBundle 8192
2222+#define fInvisible 16384
2323+#define fTrash (-3)
2424+#define fDeskTop (-2)
2525+#define fDisk 0
2626+#define fOnDesk 1
2727+2828+2929+/* ioPosMode values */
3030+enum {
3131+ fsAtMark,
3232+ fsFromStart,
3333+ fsFromLEOF,
3434+ fsFromMark
3535+};
3636+#define rdVerify 64
3737+3838+3939+/* ioPermssn values */
4040+enum {
4141+ fsCurPerm,
4242+ fsRdPerm,
4343+ fsWrPerm,
4444+ fsRdWrPerm,
4545+ fsRdWrShPerm
4646+};
4747+4848+4949+/* result codes */
5050+enum {
5151+ fsDSIntErr = -127,
5252+ wrgVolTypErr = -123,
5353+ badMovErr,
5454+ tmwdoErr,
5555+ dirNFErr,
5656+ wrPermErr = -61,
5757+ badMDBErr,
5858+ fsRnErr,
5959+ extFSErr,
6060+ noMacDskErr,
6161+ nsDrvErr,
6262+ volOnLinErr,
6363+ permErr,
6464+ volOffLinErr,
6565+ gfpErr,
6666+ rfNumErr,
6767+ paramErr,
6868+ opWrErr,
6969+ dupFNErr,
7070+ fBsyErr,
7171+ vLckdErr,
7272+ fLckdErr,
7373+ wPrErr,
7474+ fnfErr,
7575+ tmfoErr,
7676+ mFulErr,
7777+ posErr,
7878+ eofErr,
7979+ fnOpnErr,
8080+ bdNamErr,
8181+ ioErr,
8282+ nsvErr,
8383+ dskFulErr,
8484+ dirFulErr
8585+};
8686+8787+8888+/* standard header used in all PB records */
8989+#define STANDARD_PBHEADER \
9090+ struct QElem * qLink; \
9191+ int qType; \
9292+ int ioTrap; \
9393+ Ptr ioCmdAddr; \
9494+ ProcPtr ioCompletion; \
9595+ OsErr ioResult; \
9696+ StringPtr ioNamePtr; \
9797+ int ioVRefNum;
9898+9999+100100+typedef struct
101101+ {
102102+ OsType fdType;
103103+ OsType fdCreator;
104104+ int fdFlags;
105105+ Point fdLocation;
106106+ int fdFldr;
107107+ } FInfo ;
108108+109109+110110+typedef struct
111111+ {
112112+ STANDARD_PBHEADER
113113+ int ioRefNum;
114114+ SignedByte ioVersNum;
115115+ SignedByte ioPermssn;
116116+ Ptr ioMisc;
117117+ Ptr ioBuffer;
118118+ long ioReqCount;
119119+ long ioActCount;
120120+ int ioPosMode;
121121+ long ioPosOffset;
122122+ } ioParam, IOParam ;
123123+124124+/* file parameter block */
125125+typedef struct
126126+ {
127127+ STANDARD_PBHEADER
128128+ int ioFRefNum;
129129+ SignedByte ioFVersNum;
130130+ SignedByte filler1;
131131+ int ioFDirIndex;
132132+ SignedByte ioFlAttrib;
133133+ SignedByte ioFlVersNum;
134134+ FInfo ioFlFndrInfo;
135135+ long ioFlNum;
136136+ int ioFlStBlk;
137137+ long ioFlLgLen;
138138+ long ioFlPyLen;
139139+ int ioFlRStBlk;
140140+ long ioFlRLgLen;
141141+ long ioFlRPyLen;
142142+ long ioFlCrDat;
143143+ long ioFlMdDat;
144144+ } fileParam, FileParam ;
145145+146146+/* volume parameter block */
147147+typedef struct
148148+ {
149149+ STANDARD_PBHEADER
150150+ long filler2;
151151+ int ioVolIndex;
152152+ long ioVCrDate;
153153+ long ioVLsBkUp;
154154+ int ioVAtrb;
155155+ int ioVNmFls;
156156+ int ioVDirSt;
157157+ int ioVBlLn;
158158+ int ioVNmAlBlks;
159159+ long ioVAlBlkSiz;
160160+ long ioVClpSiz;
161161+ int ioAlBlSt;
162162+ long ioVNxtFNum;
163163+ int ioVFrBlk;
164164+ } volumeParam, VolumeParam ;
165165+166166+167167+typedef union {
168168+ ioParam ioParam;
169169+ fileParam fileParam;
170170+ volumeParam volumeParam;
171171+} ParamBlockRec, *ParmBlkPtr;
172172+173173+174174+/* volume control block */
175175+typedef struct
176176+ {
177177+ struct QElem *qLink;
178178+ int qType;
179179+ int vcbFlags;
180180+ int vcbSigWord;
181181+ long vcbCrDate;
182182+ long vcbLsBkUp;
183183+ int vcbAtrb;
184184+ int vcbNmFls;
185185+ int vcbDirSt;
186186+ int vcbBlLn;
187187+ int vcbNmBlks;
188188+ long vcbAlBlkSiz;
189189+ long vcbClpSiz;
190190+ int vcbAlBlSt;
191191+ long vcbNxtFNum;
192192+ int vcbFreeBks;
193193+ char vcbVN[28];
194194+ int vcbDrvNum;
195195+ int vcbDRefNum;
196196+ int vcbFSID;
197197+ int vcbVRefNum;
198198+ Ptr vcbMAdr;
199199+ Ptr vcbBufAdr;
200200+ int vcbMLen;
201201+ int vcbDirIndex;
202202+ int vcbDirBlk;
203203+ } VCB ;
204204+205205+206206+/* drive queue element */
207207+208208+typedef struct
209209+ {
210210+/* long flags; */
211211+ struct QElem *qLink;
212212+ int qType;
213213+ int dQDrive;
214214+ int dQRefNum;
215215+ int dQFSID;
216216+ int dQDrvSize;
217217+ } DrvQEl,*DrvQElPtr ;
218218+219219+220220+/* functions returning non-integral values */
221221+pascal struct QHdr *GetFSQHdr();
222222+pascal struct QHdr *GetDrvQHdr();
223223+pascal struct QHdr *GetVCBQHdr();
224224+225225+/* low-memory globals */
226226+extern int BootDrive : 0x210;
227227+extern struct QHdr DrvQHdr : 0x308;
228228+extern ProcPtr EjectNotify : 0x338;
229229+extern Ptr FCBSPtr : 0x34E;
230230+extern VCB *DefVCBPtr : 0x352;
231231+extern struct QHdr VCBQHdr : 0x356;
232232+extern struct QHdr FSQHdr : 0x360;
233233+234234+235235+#endif
+170
headers/FontMgr.h
···11+22+/*
33+ * FontMgr.h
44+ *
55+ * Copyright (c) 1986 THINK Technologies, Inc.
66+ * These interfaces are based on information published in
77+ * "Inside Macintosh" by Apple Computer, Addison-Wesley,
88+ * Reading (Mass.), 1985-86.
99+ *
1010+ */
1111+1212+#ifndef _FontMgr_
1313+#define _FontMgr_
1414+1515+#ifndef _MacTypes_
1616+#include "MacTypes.h"
1717+#endif
1818+1919+/* font numbers */
2020+enum {
2121+ systemFont,
2222+ applFont,
2323+ newYork,
2424+ geneva,
2525+ monaco,
2626+ venice,
2727+ london,
2828+ athens,
2929+ sanFran,
3030+ toronto,
3131+ cairo = 11,
3232+ losAngeles,
3333+ times = 20,
3434+ helvetica,
3535+ courier,
3636+ symbol,
3737+ taliesin
3838+};
3939+4040+#define propFont 0x9000
4141+#define prpFntH 0x9001
4242+#define prpFntW 0x9002
4343+#define prpFntHW 0x9003
4444+#define fixedFont 0xB000
4545+#define fxdFntH 0xB001
4646+#define fxdFntW 0xB002
4747+#define fxdFntHW 0xB003
4848+#define fontWid 0xACB0
4949+5050+#define fMgrCtl1 8
5151+5252+5353+typedef struct FMInput
5454+ {
5555+ int family ;
5656+ int size ;
5757+ char face ;
5858+ char needBits ;
5959+ int device ;
6060+ Point numer ;
6161+ Point denom ;
6262+ } FMInput ;
6363+6464+typedef struct FMOutput
6565+ {
6666+ int errNum ;
6767+ Handle fontHandle ;
6868+ char bold ;
6969+ char italic ;
7070+ char ulOffset ;
7171+ char ulShadow ;
7272+ char ulThick ;
7373+ char shadow ;
7474+ SignedByte extra ;
7575+ char ascent ;
7676+ char descent ;
7777+ char widMax ;
7878+ SignedByte leading ;
7979+ char unused ;
8080+ Point numer ;
8181+ Point denom ;
8282+ } FMOutput ;
8383+typedef FMOutput * FMOutPtr ;
8484+8585+typedef struct FontRec
8686+ {
8787+ int fontType ;
8888+ int firstChar ;
8989+ int lastChar ;
9090+ int widMax ;
9191+ int kernMax ;
9292+ int nDescent ;
9393+ int fRectMax ;
9494+ int chHeight ;
9595+ int owTLoc ;
9696+ int ascent ;
9797+ int descent ;
9898+ int leading ;
9999+ int rowWords ;
100100+/* int bitImage[rowWords][chHeight]; */
101101+/* int locTable[]; */
102102+/* int owTable[]; */
103103+ } FontRec ;
104104+105105+typedef struct FMetricRec {
106106+ Fixed ascent;
107107+ Fixed descent;
108108+ Fixed leading;
109109+ Fixed widMax;
110110+ Handle wTabHandle;
111111+} FMetricRec;
112112+113113+typedef struct FamRec {
114114+ int ffFlags;
115115+ int ffFamID;
116116+ int ffFirstChar;
117117+ int ffLastChar;
118118+ int ffAscent;
119119+ int ffDescent;
120120+ int ffLeading;
121121+ int ffWidMax;
122122+ long ffWTabOff;
123123+ long ffKernOff;
124124+ long ffStylOff;
125125+ int ffProperty[9];
126126+ int ffIntl[2];
127127+ int ffVersion;
128128+/* FontAssoc ffAssoc; */
129129+/* WidTable ffWidthTab; */
130130+/* StyleTable ffStyTab; */
131131+/* KernTable ffKernTab; */
132132+} FamRec;
133133+134134+typedef struct WidthTable {
135135+ Fixed tabData[256];
136136+ Handle tabFont;
137137+ long sExtra;
138138+ long style;
139139+ int fID;
140140+ int fSize;
141141+ int face;
142142+ int device;
143143+ Point inNumer;
144144+ Point inDenom;
145145+ int aFID;
146146+ Handle fHand;
147147+ Boolean usedFam;
148148+ Byte aFace;
149149+ int vOutput;
150150+ int hOutput;
151151+ int vFactor;
152152+ int hFactor;
153153+ int aSize;
154154+ int tabSize;
155155+} WidthTable;
156156+157157+158158+/* functions returning non-integral values */
159159+pascal FMOutPtr SwapFont();
160160+pascal FMOutPtr FMSwapFont();
161161+162162+/* low-memory globals */
163163+extern int ApFontID : 0x984;
164164+extern char FScaleDisable : 0xA63;
165165+extern char FractEnable : 0xBF4;
166166+extern WidthTable **WidthTabHandle : 0xB2A;
167167+extern FamRec **LastFOND : 0xBC2;
168168+169169+170170+#endif
+268
headers/HFS.h
···11+22+/*
33+ * HFS.h
44+ *
55+ * Copyright (c) 1986 THINK Technologies, Inc.
66+ * These interfaces are based on information published in
77+ * "Inside Macintosh" by Apple Computer, Addison-Wesley,
88+ * Reading (Mass.), 1986.
99+ *
1010+ */
1111+1212+1313+#ifndef _HFS_
1414+#define _HFS_
1515+1616+#ifndef _FileMgr_
1717+#include "FileMgr.h"
1818+#endif
1919+2020+2121+typedef struct {
2222+ int fdIconID;
2323+ int fdUnused[4];
2424+ int fdComment;
2525+ long fdPutAway;
2626+} FXInfo;
2727+2828+typedef struct {
2929+ Rect frRect;
3030+ int frFlags;
3131+ Point frLocation;
3232+ int frView;
3333+} DInfo;
3434+3535+typedef struct {
3636+ Point frScroll;
3737+ long frOpenChain;
3838+ int frUnused;
3939+ int frComment;
4040+ long fdPutAway;
4141+} DXInfo;
4242+4343+4444+typedef IOParam HIOParam;
4545+4646+typedef struct {
4747+ STANDARD_PBHEADER
4848+ int ioFRefNum;
4949+ SignedByte ioFVersNum;
5050+ SignedByte filler1;
5151+ int ioFDirIndex;
5252+ SignedByte ioFlAttrib;
5353+ SignedByte ioFlVersNum;
5454+ FInfo ioFlFndrInfo;
5555+ long ioDirID;
5656+ int ioFlStBlk;
5757+ long ioFlLgLen;
5858+ long ioFlPyLen;
5959+ int ioFlRStBlk;
6060+ long ioFlRLgLen;
6161+ long ioFlRPyLen;
6262+ long ioFlCrDat;
6363+ long ioFlMdDat;
6464+} HFileParam ;
6565+6666+typedef struct {
6767+ STANDARD_PBHEADER
6868+ long filler2;
6969+ int ioVolIndex;
7070+ long ioVCrDate;
7171+ long ioVLsMod;
7272+ int ioVAtrb;
7373+ int ioVNmFls;
7474+ int ioVBitMap;
7575+ int ioAllocPtr;
7676+ int ioVNmAlBlks;
7777+ long ioVAlBlkSiz;
7878+ long ioVClpSiz;
7979+ int ioAlBlSt;
8080+ long ioVNxtCNID;
8181+ int ioVFrBlk;
8282+ int ioVSigWord;
8383+ int ioVDrvInfo;
8484+ int ioVDRefNum;
8585+ int ioVFSID;
8686+ long ioVBkUp;
8787+ int ioVSeqNum;
8888+ long ioVWrCnt;
8989+ long ioVFilCnt;
9090+ long ioVDirCnt;
9191+ long ioVFndrInfo[8];
9292+} HVolumeParam;
9393+9494+typedef union {
9595+ HIOParam ioParam;
9696+ HFileParam fileParam;
9797+ HVolumeParam volumeParam;
9898+} HParamBlockRec, *HParmBlkPtr;
9999+100100+101101+typedef struct {
102102+ STANDARD_PBHEADER
103103+ int ioFRefNum;
104104+ SignedByte ioFVersNum;
105105+ SignedByte filler1;
106106+ int ioFDirIndex;
107107+ SignedByte ioFlAttrib;
108108+ SignedByte filler2;
109109+ FInfo ioFlFndrInfo;
110110+ long ioDirID;
111111+ int ioFlStBlk;
112112+ long ioFlLgLen;
113113+ long ioFlPyLen;
114114+ int ioFlRStBlk;
115115+ long ioFlRLgLen;
116116+ long ioFlRPyLen;
117117+ long ioFlCrDat;
118118+ long ioFlMdDat;
119119+ long ioFlBkDat;
120120+ FXInfo ioFlXFndrInfo;
121121+ long ioFlParID;
122122+ long ioFlClpSiz;
123123+} HFileInfo;
124124+125125+typedef struct {
126126+ STANDARD_PBHEADER
127127+ int ioFRefNum;
128128+ SignedByte ioFVersNum;
129129+ SignedByte filler1;
130130+ int ioFDirIndex;
131131+ SignedByte ioFlAttrib;
132132+ SignedByte filler2;
133133+ DInfo ioDrUsrWds;
134134+ long ioDrDirID;
135135+ int ioDrNmFls;
136136+ int filler3[9];
137137+ long ioDrCrDat;
138138+ long ioDrMdDat;
139139+ long ioDrBkDat;
140140+ DXInfo ioDrFndrInfo;
141141+ long ioDrParID;
142142+} DirInfo;
143143+144144+typedef union {
145145+ HFileInfo hFileInfo;
146146+ DirInfo dirInfo;
147147+} CInfoPBRec, *CInfoPBPtr;
148148+149149+150150+typedef struct {
151151+ STANDARD_PBHEADER
152152+ long filler1;
153153+ StringPtr ioNewName;
154154+ long filler2;
155155+ long ioNewDirID;
156156+ long filler3[2];
157157+ long ioDirID;
158158+} CMovePBRec, *CMovePBPtr;
159159+160160+161161+typedef struct {
162162+ STANDARD_PBHEADER
163163+ int filler1;
164164+ int ioWDIndex;
165165+ long ioWDProcID;
166166+ int ioWDVRefNum;
167167+ int filler2[7];
168168+ long ioWDDirID;
169169+} WDPBRec, *WDPBPtr;
170170+171171+172172+typedef struct {
173173+ STANDARD_PBHEADER
174174+ int ioRefNum;
175175+ int filler;
176176+ int ioFCBIndx;
177177+ int ioFCBFiller1;
178178+ long ioFCBFlNm;
179179+ int ioFCBFlags;
180180+ int ioFCBStBlk;
181181+ long ioFCBEOF;
182182+ long ioFCBPLen;
183183+ long ioFCBCrPs;
184184+ int ioFCBVRefNum;
185185+ long ioFCBClpSiz;
186186+ long ioFCBParID;
187187+} FCBPBRec, *FCBPBPtr;
188188+189189+190190+typedef struct {
191191+ struct QElem * qLink;
192192+ int qtype;
193193+ int vcbFlags;
194194+ int vcbSigWord;
195195+ long vcbCrDate;
196196+ long vcbLsMod;
197197+ int vcbAtrb;
198198+ int vcbNmFls;
199199+ int vcbVBMSt;
200200+ int vcbAllocPtr;
201201+ int vcbNmAlBlks;
202202+ long vcbAlBlkSiz;
203203+ long vcbClpSIz;
204204+ int vcbAlBlSt;
205205+ long vcbNxtCNID;
206206+ int vcbFreeBks;
207207+ char vcbVN[28];
208208+ int vcbDrvNum;
209209+ int vcbDRefNum;
210210+ int vcbFSID;
211211+ int vcbVRefNum;
212212+ Ptr vcbMAdr;
213213+ Ptr vcbBufAdr;
214214+ int vcbMLen;
215215+ int vcbDirIndex;
216216+ int vcbDirBlk;
217217+ long vcbVolBkUp;
218218+ int vcbVSeqNum;
219219+ long vcbWrCnt;
220220+ long vcbXTClpSiz;
221221+ long vcbCTClpSiz;
222222+ int vcbNmRtDirs;
223223+ long vcbFilCnt;
224224+ long vcbDirCnt;
225225+ long vcbFndrInfo[8];
226226+ int vcbVCSize;
227227+ int vcbVBMCSiz;
228228+ int vcbCtlCSiz;
229229+ int vcbXTAlBlks;
230230+ int vcbCTAlBlks;
231231+ int vcbXTRef;
232232+ int vcbCTRef;
233233+ Ptr vcbCtlBuf;
234234+ long vcbDirIDM;
235235+ int vcbOffsM;
236236+} HVCB;
237237+238238+239239+typedef struct {
240240+/* long flags; */
241241+ struct QElem * qLink;
242242+ int qType;
243243+ int dQDrive;
244244+ int dQRefNum;
245245+ int dQFSID;
246246+ int dQDrvSz;
247247+ int dQDrvSz2;
248248+} HDrvQEl, *HDrvQElPtr;
249249+250250+251251+typedef struct {
252252+ char sigWord[2];
253253+ long abSize;
254254+ long clpSize;
255255+ long nxFreeFN;
256256+ long btClpSize;
257257+ int rsrv1;
258258+ int rsrv2;
259259+ int rsrv3;
260260+} HFSDefaults;
261261+262262+263263+/* low-memory globals */
264264+extern int FSFCBLen : 0x3F6;
265265+extern HFSDefaults *FmtDefaults : 0x39E;
266266+267267+268268+#endif
···11+/*
22+ Routines for LightspeedC�
33+44+ (C) Copyright 1986. THINK Technologies, Inc. All rights reserved.
55+*/
66+77+#ifndef _ctypeh_
88+#define _ctypeh_
99+1010+/* NOTE: the ctype array lives in stddata_ctype.c */
1111+1212+extern char __ctype[];
1313+1414+#define _alpha_ 1
1515+#define _digit_ 2
1616+#define _hex_ 4
1717+#define _octal_ 8
1818+#define _ascii_ 16
1919+#define _cntrl_ 32
2020+#define _punct_ 64
2121+#define _space_ 128
2222+2323+/* The c passed by the programmer should always be declared as an int or an
2424+ unsigned char, not a char, otherwise these tests will behave
2525+ unpredictably with values of c which are greater than 127 since chars
2626+ are typically sign extended to ints so array bounds become negative */
2727+2828+2929+#define isalnum(c) (__ctype[(c)+1]&(_alpha_|_digit_))
3030+3131+#define isalpha(c) (__ctype[(c)+1]&_alpha_)
3232+3333+#define isascii(c) (__ctype[(c)+1]&_ascii_)
3434+3535+#define iscntrl(c) (__ctype[(c)+1]&_cntrl_)
3636+3737+#define iscsym(c) ((__ctype[(c)+1]&(_alpha_|_digit_))|| (c) == '_')
3838+3939+#define iscsymf(c) ((__ctype[(c)+1]&_alpha_)|| (c) == '_')
4040+4141+#define isdigit(c) (__ctype[(c)+1]&_digit_)
4242+4343+#define isgraph(c) ((c) >= '!' && (c) <= '~')
4444+4545+#define isodigit(c) (__ctype[(c)+1]&_octal_)
4646+4747+#define isprint(c) (((c)>=32)&&((c)<=255))
4848+4949+#define ispunct(c) (__ctype[(c)+1]&_punct_)
5050+5151+#define isspace(c) (__ctype[(c)+1]&_space_)
5252+5353+#define isxdigit(c) (__ctype[(c)+1]&_hex_)
5454+5555+#define toascii(c) (c&0x7F)
5656+5757+#endif
···11+/* (C) Copyright 1986. THINK Technologies, Inc. All rights reserved. */
22+33+/*
44+ This is the header file for the windowed output printf-2-w.c
55+ supplied with the new stdio.
66+*/
77+88+#ifndef _fopenwh_
99+#define _fopenwh_
1010+1111+#ifndef _stdioh_
1212+#include "stdio.h"
1313+#endif
1414+1515+#ifndef _WindowMgr_
1616+#include "WindowMgr.h"
1717+#endif
1818+1919+#ifndef _ControlMgr_
2020+#include "ControlMgr.h"
2121+#endif
2222+2323+#ifndef _EventMgr_
2424+#include "EventMgr.h"
2525+#endif
2626+2727+extern GrafPtr WMgrPort:0x9DE;
2828+2929+/* This is the Standard Window Options structure (passed in to fopenw) */
3030+3131+/* Defaults are as follows (check printf-2-w.c for details) if you don't
3232+ pass in an options record to fopenw() (also Console window):
3333+3434+ maxrow and maxcol are determined by screenbits.Bounds and the current
3535+ font, so they will be something like 24 x 80 with Monaco 9 font on a
3636+ standard Mac screen, larger on a Mac XL (Lisa), and even larger on
3737+ something like a Radius.
3838+3939+ cursor_visible true
4040+ echo_state true
4141+ _tab_width 4
4242+ no_pull_front false
4343+ no_grow, false
4444+ no_drag, false
4545+ no_goaway, false
4646+ no_scroll, false
4747+ no_wrap; false
4848+*/
4949+5050+typedef struct
5151+{
5252+int maxrow, /* number of rows in screen array */
5353+ maxcol; /* number of columns in screen array */
5454+5555+Boolean cursor_visible, /* cursor is visible */
5656+ echo_state, /* true if echo enabled */
5757+ _tab_width, /* width of tabs */
5858+ no_pull_front, /* don't pull window to front on keystrokes */
5959+ no_grow, /* no grow box */
6060+ no_drag, /* not draggable */
6161+ no_goaway, /* no goaway box */
6262+ no_scroll, /* vertical wrap instead of scrolling */
6363+ no_wrap; /* fall off end of line rather than horizontal wrap */
6464+6565+} StdWindowOptions;
6666+6767+typedef struct
6868+{
6969+WindowRecord wrec; /* actual window record -- a pointer to this
7070+ can be obtained by Get_WindowPtr(filevar)
7171+ where filevar is returned from fopenw() */
7272+long signature; /* can be used to determine if stdio window */
7373+StdWindowOptions opt; /* our options record */
7474+int visrow, /* # visible rows */
7575+ viscol, /* # visible columns */
7676+ row, /* current row */
7777+ col, /* current column */
7878+ toprow, /* row in array that is actual first row
7979+ since scrolling only changes this and
8080+ treats screen array as a wrapped queue */
8181+ charheight, /* character height in pixels */
8282+ charwidth; /* character width in pixels */
8383+FontInfo sf; /* stuff for font management */
8484+char screen[]; /* screen row buffer -- pointer to this can
8585+ be obtained with Get_ScreenPtr(filevar)
8686+ where filevar is returned from fopenw()*/
8787+} StdWindowRec;
8888+8989+typedef struct { /* expandable window refcon control structure */
9090+ int (*eventProc)();
9191+ ControlHandle vscroll;
9292+} eventinfo;
9393+9494+typedef struct {
9595+EventRecord record;
9696+WindowPtr window;
9797+ControlHandle control;
9898+} XEventRecord;
9999+100100+typedef struct {
101101+WindowPtr wp;
102102+FILE *fp;
103103+} StdwsaveRecord;
104104+105105+enum {OFF, ON};
106106+107107+/* misc. defs */
108108+109109+#define _OURSIGNATURE 'LSWD' /* identifies our window records */
110110+#define _CONTROLWIDTH 15 /* width of scroll bar */
111111+#define _LEFTEDGE 4 /* margins */
112112+#define _TOPEDGE 4
113113+114114+extern int MBarHeight:0xBAA;
115115+#define _MBARHEIGHT (ROM85==-1?20:MBarHeight)
116116+117117+#define _TITLEBARHEIGHT 20
118118+119119+#define hiword(x) (((short *) &(x))[0])
120120+#define loword(x) (((short *) &(x))[1])
121121+#define screenHeight (screenBits.bounds.bottom)
122122+#define screenWidth (screenBits.bounds.right)
123123+124124+typedef enum
125125+{
126126+menuEvent=16, /* our internal codes for events */
127127+growEvent,
128128+dragEvent,
129129+cursorEvent,
130130+selectEvent,
131131+controlEvent,
132132+deactivateEvt,
133133+closeEvent,
134134+openEvent,
135135+appleEvent,
136136+dialogEvent,
137137+editEvent
138138+};
139139+140140+#endif
141141+
+27
sources/io.h
···11+/* (C) Copyright 1986. THINK Technologies, Inc. All rights reserved. */
22+33+#define _ioh_
44+#define O_RDONLY 0x0000
55+#define O_WRONLY 0x0001
66+#define O_RDWR 0x0002
77+#define O_APPEND 0x0008
88+#define O_NDELAY 0x0000 /* ignored when ORed with one of the above */
99+1010+#define O_CREAT 0x0100
1111+#define O_TRUNC 0x0200
1212+#define O_EXCL 0x0400
1313+1414+#define O_TEXT 0x4000
1515+#define O_BINARY 0x8000
1616+1717+/* Default for these functions are int so they don't need to be declared
1818+int fileno();
1919+int open();
2020+int close();
2121+int read();
2222+int write();
2323+int rename();
2424+int remove();
2525+int unlink();
2626+int creat();
2727+*/
+584
sources/math.c
···11+/*
22+33+ Standard Unix math library for LightspeedC�.
44+55+ (C) Copyright 1986 THINK Technologies, Inc. All rights reserved.
66+77+ See Harbison & Steele's C:A Reference Manual chapter 11 for details
88+99+*/
1010+1111+1212+#include "stdio.h"
1313+#include "math.h"
1414+#include "sane.h"
1515+1616+#define C (0.00000000011641532183)
1717+1818+/* The following value is the largest possible positive number that can be
1919+ represented by the double format */
2020+2121+static union {
2222+unsigned int plusdoubleparts[5];
2323+double plusdouble;
2424+} max = {0x7FFE, 0x7FFF, 0xFFFF, 0xFFFF, 0xFFFF};
2525+2626+/* The following value is positive infinity as represented by SANE */
2727+2828+static union {
2929+unsigned int plusdoubleparts[5];
3030+double plusdouble;
3131+} inf = {0x7FFF, 0, 0, 0, 0};
3232+3333+/* The following value is the base 2 logarithm of 10.0 as represented
3434+ by a double value returned by SANE */
3535+3636+static union {
3737+unsigned int tenparts[5];
3838+double ten;
3939+} log2of = {0x4000, 0xD49A, 0x784B, 0xCD1B, 0x8AFE};
4040+4141+/* This is the data structure used with rand() and srand() to generate
4242+ random numbers according to the ANSI C spec.
4343+ pdg - 6/10/86 */
4444+4545+static union {
4646+unsigned long seed;
4747+struct { int sign : 1, v : 15; } hiword;
4848+} randval = 1;
4949+5050+/* This is the structure of a double, so we can access the exponent
5151+ and mantissa sign bits independently without using SANE */
5252+5353+typedef struct {
5454+short expsign:1,
5555+ exp:15;
5656+long mansign:1,
5757+ man:31;
5858+long moreman;
5959+} dbl;
6060+6161+6262+/* This is the structure of the SANE (Standard Apple Numeric Environment)
6363+ environment flags word used in ceil(), floor(), etc. */
6464+6565+typedef struct {
6666+short unused:1, round:2,
6767+/*flags:5, */ inexact:1, divbyzero:1, overflow:1, underflow:1, invalid:1,
6868+lastround:1, precision:2, halts:5;
6969+} SANEenvword;
7070+7171+/* Temporary save area for SANE global environment flags word */
7272+7373+static SANEenvword SANEstate;
7474+7575+/* Define the location of the SANE environment word in Macintosh memory */
7676+7777+#define SANEglobalenv (*((SANEenvword*) 0x0A4A))
7878+7979+8080+/* local function to truncate a double to an integer (works for both old
8181+ and new versions of LightspeedC */
8282+8383+#define NEWLSC /* if uncommented, removes excess code for new version */
8484+8585+#ifndef NEWLSC
8686+8787+static int trunc(x)
8888+double x;
8989+{
9090+int i;
9191+9292+ SANEstate = SANEglobalenv;
9393+9494+ SANEglobalenv.round = TOWARDZERO;
9595+9696+ i = x;
9797+9898+ SANEglobalenv = SANEstate;
9999+100100+ return (i);
101101+}
102102+#else
103103+#define trunc(x) x
104104+#endif NEWLSC
105105+106106+107107+/* Return the absolute value of the integer X */
108108+#line 0 abs
109109+int abs(x)
110110+int x;
111111+{
112112+ if (x<0) return (-x);
113113+ return (x);
114114+}
115115+116116+/* Return the arc cosine of the double value X */
117117+#line 0 acos
118118+double acos(x)
119119+double x;
120120+{
121121+ if ((x > 1.0)||(x < -1.0))
122122+ {
123123+ errno = EDOM;
124124+ return( 0.0 );
125125+ }
126126+127127+ if (x == -1.0) return ( PI );
128128+129129+ x = (1.0 - x) / (1.0 + x);
130130+131131+ fp68k(&x, FOSQRT);
132132+133133+ x *= 2.0;
134134+135135+ return( x );
136136+}
137137+138138+/* Return the arc sine of the double value X */
139139+#line 0 asin
140140+double asin(x)
141141+double x;
142142+{
143143+double y = fabs( x );
144144+145145+ if ( y > 1.0 )
146146+ {
147147+ errno = EDOM;
148148+ return( 0.0 );
149149+ }
150150+151151+ if (y == 1.0)
152152+ {
153153+ y = PI2;
154154+155155+ /* copy sign of x into y */
156156+157157+ (*(dbl*) (&y)).mansign = (*(dbl*) (&x)).mansign;
158158+159159+ return( y );
160160+ }
161161+162162+ if ( y >= 0.3 ) x /= sqrt( (1.0 - x) * (1.0 + x) );
163163+ else
164164+ if ( y >= C ) x /= sqrt( 1.0 - x * x );
165165+166166+ elems68k( &x, FOATANX );
167167+168168+ return( x ); /* pdg - 6/10/86 - formerly returned y */
169169+}
170170+171171+172172+/* Return the arc tangent of the double value X */
173173+#line 0 atan
174174+double atan(x)
175175+double x;
176176+{
177177+ elems68k( &x, FOATANX );
178178+ return( x );
179179+}
180180+181181+182182+/* Return the arc tangent of the double value of Y divided by X */
183183+#line 0 atan2
184184+double atan2(y,x)
185185+double y, x;
186186+{
187187+double z;
188188+189189+ if ( x == 0.0 )
190190+ {
191191+ if ( y == 0.0 )
192192+ {
193193+ errno = EDOM;
194194+ return( 0.0 );
195195+ }
196196+197197+ z = PI2;
198198+ }
199199+ else
200200+ {
201201+ z = atan( fabs( y ) / fabs( x ) );
202202+203203+ if (x <= 0.0) z = PI - z;
204204+ }
205205+206206+ /* copy sign of y into z */
207207+208208+ (*(dbl*) (&z)).mansign = (*(dbl*) (&y)).mansign;
209209+210210+ return (z);
211211+}
212212+213213+214214+/* Round towards positive infinity.
215215+ pdg - 6/10/86 - complete revision using SANE call */
216216+#line 0 ceil
217217+double ceil(x)
218218+double x;
219219+{
220220+ /* save the state, do the round, restore the state, and return value */
221221+222222+ SANEstate = SANEglobalenv;
223223+224224+ SANEglobalenv.round = UPWARD;
225225+226226+ fp68k( &x, FORTI );
227227+228228+ SANEglobalenv = SANEstate;
229229+230230+ return (x);
231231+}
232232+233233+234234+/* Return the cosine of the double value X */
235235+#line 0 cos
236236+double cos(x)
237237+double x;
238238+{
239239+ elems68k( &x, FOCOSX );
240240+ return( x );
241241+}
242242+243243+244244+/* Return the hyperbolic cosine of the double value X */
245245+#line 0 cosh
246246+double cosh(x)
247247+double x;
248248+{
249249+double y = exp( fabs( x ) );
250250+251251+ if (y == 0.0)
252252+ {
253253+ errno = ERANGE;
254254+ return ( max.plusdouble );
255255+ }
256256+257257+ y *= 0.5;
258258+ y += y * 0.25;
259259+260260+ return( y );
261261+}
262262+263263+/* Return the value of e raised to the X power */
264264+#line 0 exp
265265+double exp(x)
266266+double x;
267267+{
268268+ elems68k( &x, FOEXPX );
269269+270270+ if (SANEglobalenv.overflow)
271271+ {
272272+ errno = ERANGE;
273273+ return ( max.plusdouble );
274274+ }
275275+276276+ return( x );
277277+}
278278+279279+280280+/* Return the absolute value of X */
281281+#line 0 fabs
282282+double fabs(x)
283283+double x;
284284+{
285285+ fp68k( &x, FOABS );
286286+ return( x );
287287+}
288288+289289+290290+/* Round towards negative infinity.
291291+ pdg - 6/10/86 - complete revision using SANE call vs. improper C hack */
292292+#line 0 floor
293293+double floor(x)
294294+double x;
295295+{
296296+ /* save the state, do the round, restore the state, and return value */
297297+298298+ SANEstate = SANEglobalenv;
299299+300300+ SANEglobalenv.round = DOWNWARD;
301301+302302+ fp68k( &x, FORTI );
303303+304304+ SANEglobalenv = SANEstate;
305305+306306+ return (x);
307307+}
308308+309309+310310+/* Return a number such F that k * Y + f == X
311311+ Thanks to Robert J. Murphy of Data Tailor, Inc. for this revision */
312312+#line 0 fmod
313313+double fmod(x,y)
314314+double x, y;
315315+{
316316+double rem = x;
317317+318318+ fp68k( &y, FOABS);
319319+ fp68k( &y, &rem, FOREM);
320320+321321+ if ( (x > 0) && (rem < 0)) rem += y;
322322+ else
323323+ if ( (x < 0) && (rem > 0)) rem -= y;
324324+325325+ return (rem);
326326+}
327327+328328+329329+/* Return fraction and exponent of X */
330330+#line 0 frexp
331331+double frexp(x,nptr)
332332+double x;
333333+register int *nptr;
334334+{
335335+double y = fabs( x ), z = 2.0;
336336+337337+ if (y == 0.0)
338338+ {
339339+ *nptr = 0;
340340+ return( 0.0 );
341341+ }
342342+343343+ elems68k( &y, FOLOG2X );
344344+345345+ y -= (*nptr = trunc(y));
346346+347347+ elems68k( &y, &z, FOPWRY );
348348+349349+ /* scale the result if not between .5 and 1.0 */
350350+351351+ if (z >= 1.0)
352352+ {
353353+ (*nptr)++;
354354+ z *= 0.5;
355355+ }
356356+ else
357357+ if (z < 0.5)
358358+ {
359359+ (*nptr)--;
360360+ z *= 2.0;
361361+ }
362362+363363+ /* copy sign of x into z */
364364+365365+ (*(dbl*) (&z)).mansign = (*(dbl*) (&x)).mansign;
366366+367367+ return( z );
368368+}
369369+370370+371371+/* Return the absolute value of the long number X */
372372+#line 0 labs
373373+long int labs(x)
374374+register long int x;
375375+{
376376+ if ( x < 0 ) return (-x);
377377+378378+ return (x);
379379+}
380380+381381+382382+/* Return return the floating point number represented by (X * radix) ^ n */
383383+#line 0 ldexp
384384+double ldexp(x,n)
385385+double x;
386386+int n;
387387+{
388388+ fp68k( &n, &x, FOSCALB );
389389+ return( x );
390390+}
391391+392392+393393+/* Return the natural log of the double value X */
394394+#line 0 log
395395+double log(x)
396396+double x;
397397+{
398398+ if (x <= 0.0)
399399+ {
400400+ errno = EDOM;
401401+ return ( -max.plusdouble );
402402+ }
403403+404404+ elems68k( &x, FOLNX );
405405+ return( x );
406406+}
407407+408408+409409+/* Return the log base 10 of the double value X */
410410+#line 0 log10
411411+double log10(x)
412412+double x;
413413+{
414414+ if (x <= 0.0)
415415+ {
416416+ errno = EDOM;
417417+ return ( -max.plusdouble );
418418+ }
419419+420420+ elems68k(&x, FOLOG2X); /* LOG2 is much faster than LN */
421421+422422+ x /= log2of.ten;
423423+424424+ return ( x );
425425+}
426426+427427+428428+/* Split X into a fraction and integer such that |X| < 1 */
429429+#line 0 modf
430430+double modf(x,nptr)
431431+double x;
432432+register int *nptr;
433433+{
434434+ if (abs( (*nptr = trunc(x)) ) > fabs( x ))
435435+ {
436436+ if (*nptr > 0) (*nptr)--;
437437+ else
438438+ (*nptr)++;
439439+ }
440440+441441+ x -= *nptr;
442442+443443+ return( x );
444444+}
445445+446446+/* Return X ^ Y */
447447+#line 0 pow
448448+double pow(x,y)
449449+double x, y;
450450+{
451451+int dummyint;
452452+453453+ if ( (x < 0.0 && (modf(y, &dummyint) != 0)) || (x == 0.0 && y < 0.0) )
454454+ {
455455+ errno = EDOM;
456456+ x = -max.plusdouble;
457457+ goto returnx;
458458+ }
459459+460460+ elems68k( &y, &x, FOPWRY );
461461+462462+ if (SANEglobalenv.overflow)
463463+ {
464464+ errno = ERANGE;
465465+ x = max.plusdouble;
466466+ }
467467+468468+returnx:
469469+470470+ return( x );
471471+}
472472+473473+474474+/* Return a random number in the range 0 .. max int */
475475+#line 0 rand
476476+477477+int rand()
478478+{
479479+ /* pdg - 6/10/86 - ANSI random number generator */
480480+481481+ randval.seed = randval.seed * 1103515245 + 12345;
482482+ return randval.hiword.v;
483483+}
484484+485485+/* Return the sine of the double value X */
486486+#line 0 sin
487487+double sin(x)
488488+double x;
489489+{
490490+ elems68k( &x, FOSINX );
491491+ return( x );
492492+}
493493+494494+/* Return the hyperbolic sine of the double value X */
495495+#line 0 sinh
496496+double sinh(x)
497497+double x;
498498+{
499499+double y = fabs(x);
500500+501501+ if (y >= C)
502502+ {
503503+ elems68k( &y, FOEXP1X );
504504+505505+ if (SANEglobalenv.overflow)
506506+ {
507507+ errno = ERANGE;
508508+ y = max.plusdouble;
509509+ }
510510+ else
511511+ {
512512+ y += y / ( y + 1.0);
513513+514514+ y *= 0.5;
515515+ }
516516+ }
517517+518518+ /* copy sign of x into y */
519519+520520+ (*(dbl*) (&y)).mansign = (*(dbl*) (&x)).mansign;
521521+522522+ return (y);
523523+}
524524+525525+526526+/* Return the square root of the double value X */
527527+#line 0 sqrt
528528+double sqrt(x)
529529+double x;
530530+{
531531+ if (x < 0.0)
532532+ {
533533+ errno = EDOM;
534534+ return( 0.0 );
535535+ }
536536+537537+ fp68k(&x, FOSQRT);
538538+ return(x);
539539+}
540540+541541+542542+/* Set the seed of the random number generator to SEED */
543543+#line 0 srand
544544+void srand(seed)
545545+unsigned int seed;
546546+{
547547+ randval.seed = seed;
548548+}
549549+550550+/* Return the tangent of the double value X */
551551+#line 0 tan
552552+double tan(x)
553553+double x;
554554+{
555555+ elems68k( &x, FOTANX );
556556+557557+ if ( SANEglobalenv.invalid || ( x == inf.plusdouble ) )
558558+ {
559559+ errno = ERANGE;
560560+ x = max.plusdouble;
561561+ }
562562+563563+ return(x);
564564+}
565565+566566+567567+/* Return the hyperbolic tangent of the double value X */
568568+#line 0 tanh
569569+double tanh(x)
570570+double x;
571571+{
572572+double y = fabs( x );
573573+574574+ if (y >= C)
575575+ {
576576+ y *= -2.0;
577577+ elems68k( &y, FOEXP1X );
578578+ y = -y / ( y + 2.0 );
579579+ }
580580+581581+ (*(dbl*) (&y)).mansign = (*(dbl*) (&x)).mansign;
582582+583583+ return (y);
584584+}
+49
sources/math.h
···11+/****************************************************************************
22+33+ Standard math library header for LightspeedC�.
44+55+ (C) Copyright 1986 THINK Technologies, Inc. All rights reserved.
66+77+*****************************************************************************/
88+99+#ifndef _math_
1010+1111+ #define _math_ /* show symbols defined */
1212+ double acos();
1313+ double asin();
1414+ double atan();
1515+ double atan2();
1616+ double ceil();
1717+ double cos();
1818+ double cosh();
1919+ double exp();
2020+ double fabs();
2121+ double floor();
2222+ double fmod();
2323+ double frexp();
2424+ long labs();
2525+ double ldexp();
2626+ double log();
2727+ double log10();
2828+ double modf();
2929+ double pow();
3030+ double sin();
3131+ double sinh();
3232+ double sqrt();
3333+ double tan();
3434+ double tanh();
3535+3636+ #define PI (3.14159265358979323846)
3737+ #define PI2 (1.57079632679489661923)
3838+ #define PI4 (0.78539816339744830966)
3939+4040+ #define E (2.71828182845904523536)
4141+4242+ typedef enum{
4343+ EDOM=33,
4444+ ERANGE=34
4545+ };
4646+4747+extern int errno; /* actually defined in stdio */
4848+4949+#endif
+50
sources/onexit.c
···11+/*
22+ Routines for LightspeedC�
33+44+ (C) Copyright 1985, 1986. THINK Technologies, Inc. All rights reserved.
55+66+*/
77+/*
88+ * onexit
99+ *
1010+ * By calling "onexit", the programmer can arrange for up to NPROCS
1111+ * routines to be called just before program exit. The routines are
1212+ * called with no arguments and in the reverse order in which they
1313+ * were supplied to "onexit".
1414+ *
1515+ * "Onexit" returns its argument, the address of the routine to be
1616+ * called, or zero if it has already been called NPROCS times.
1717+ *
1818+ * "Onexit" is built on a lower-level mechanism, "_onexit", which
1919+ * provides for a single routine to be called at termination.
2020+ *
2121+ */
2222+2323+2424+typedef void (*Proc)(); /* address of a proc */
2525+2626+#define NPROCS 32 /* max # of procs in list */
2727+static int nprocs = 0; /* actual # of procs in list */
2828+static Proc proctable[NPROCS]; /* list of procs */
2929+3030+static long _onexit = 0x4EED006A; /* "jmp $6A(a5)" */
3131+3232+onexit_handler()
3333+{
3434+ while (nprocs>0)
3535+ if (proctable[--nprocs])
3636+ (*proctable[nprocs])();
3737+}
3838+3939+#line 0 onexit()
4040+Proc
4141+onexit(proc)
4242+Proc proc;
4343+{
4444+ if (nprocs == 0)
4545+ (* ((Proc) &_onexit))(onexit_handler);
4646+4747+ return(nprocs < NPROCS ? proctable[nprocs++] = proc : 0);
4848+}
4949+5050+
+155
sources/printf-1.c
···11+/*
22+ printf routines for LightspeedC�
33+44+ (C) Copyright 1985, 1986. THINK Technologies, Inc. All rights reserved.
55+66+ pdg - 6/11/86 - revised: split off sprintf to another module
77+*/
88+99+#include "fopenw.h"
1010+1111+#ifndef _setjmph_
1212+#include "setjmp.h"
1313+#endif
1414+1515+1616+extern FILE _console_;
1717+1818+/*----------------------------------------------------------------------------
1919+ some global storage to prevent excessive parameter transfer
2020+----------------------------------------------------------------------------*/
2121+static FILE *globalwho=NULL; /* output destination specifier */
2222+static StdwsaveRecord saverec; /* save record for window info */
2323+extern jmp_buf env; /* global error return mechanism */
2424+extern void (*_output)(); /* global pointer to function for output */
2525+extern int _num_count; /* number of characters transmitted */
2626+2727+2828+#line 0 to_file()
2929+static void to_file(character)
3030+char character;
3131+{
3232+ /* context switch back to caller of _format in case of error */
3333+3434+ if (fputc(character,globalwho) == EOF)
3535+ longjmp(env, EOF);
3636+3737+ _num_count++; /* increment transmitted character count */
3838+}
3939+4040+4141+#line 0 to_StdStream()
4242+static void to_StdStream(character)
4343+char character;
4444+{
4545+ putch(character); /* putch can't fail */
4646+4747+ _num_count++; /* increment transmitted character count */
4848+}
4949+5050+#line 0 to_DummyStream()
5151+static void to_DummyStream(character)
5252+char character;
5353+{
5454+ _num_count++; /* increment transmitted character count */
5555+}
5656+5757+#line 0 finish_format()
5858+static int finish_format(who, count)
5959+FILE *who;
6060+int count;
6161+{
6262+ /* restore window settings */
6363+6464+ if (who->window) stdwrestore(who, &saverec);
6565+6666+ return (count);
6767+}
6868+6969+#line 0 setup_format()
7070+static int setup_format(who)
7171+register FILE *who;
7272+{
7373+ /* make sure that globalwho is valid */
7474+7575+ if (!(globalwho=who)) return (EOF);
7676+7777+ /* assume output is to a file */
7878+7979+ _output = to_file;
8080+8181+ /* if standard stream */
8282+8383+ if (who->StdStream)
8484+ {
8585+ /* assume that we are going to the standard stream */
8686+8787+ _output = to_StdStream;
8888+8989+ /* if, for some reason, we can't write, then fake it */
9090+9191+ if (!who->wr) _output = to_DummyStream;
9292+ else
9393+ Init_stdio();
9494+9595+ /* preserve existing window settings */
9696+9797+ if (who->window) stdwsave(who, &saverec);
9898+9999+ }
100100+101101+ return (0);
102102+}
103103+104104+int _format(); /* function to handle formatting */
105105+106106+#line 0 printf();
107107+int printf(fmt)
108108+char *fmt;
109109+{
110110+ if (setup_format(stdout)) return(EOF);
111111+ return(finish_format(stdout, _format(&fmt,false)));
112112+}
113113+114114+#line 0 vprintf();
115115+int vprintf(fmt,arr)
116116+char *fmt,*arr;
117117+{
118118+ if (setup_format(stdout)) return (EOF);
119119+ return((finish_format(stdout, _format(&fmt,true))));
120120+}
121121+122122+123123+#line 0 fprintf();
124124+int fprintf(who,fmt)
125125+FILE *who;
126126+char *fmt;
127127+{
128128+ if (setup_format(who)) return (EOF);
129129+ return (finish_format(who, _format(&fmt,false)));
130130+}
131131+132132+#line 0 vfprintf();
133133+int vfprintf(who,fmt,arr)
134134+FILE *who;
135135+char *fmt,*arr;
136136+{
137137+ if (setup_format(who)) return (EOF);
138138+ return (finish_format(who, _format(&fmt,true)));
139139+}
140140+141141+#line 0 cprintf();
142142+int cprintf(fmt)
143143+char *fmt;
144144+{
145145+ if (setup_format(_console)) return (EOF);
146146+ return(finish_format(_console, _format(&fmt,false)));
147147+}
148148+149149+#line 0 vcprintf();
150150+int vcprintf(fmt,arr)
151151+char *fmt,*arr;
152152+{
153153+ if (setup_format(_console)) return (EOF);
154154+ return(finish_format(_console, _format(&fmt,true)));
155155+}
+58
sources/printf-1a.c
···11+/*
22+ printf routines for LightspeedC�
33+44+ (C) Copyright 1985, 1986. THINK Technologies, Inc. All rights reserved.
55+66+ pdg - 6/11/86 - revised: sprintf, vsprintf module
77+*/
88+99+#ifndef _stdioh_
1010+#include "stdio.h"
1111+#endif
1212+1313+#ifndef _MacTypes_
1414+#include "MacTypes.h"
1515+#endif
1616+1717+1818+extern void (*_output)(); /* global pointer to function for output */
1919+static char *destination; /* pointer to destination buffer */
2020+2121+2222+#line 0 to_memory()
2323+static void to_memory(character)
2424+char character;
2525+{
2626+ *destination++ = character;
2727+}
2828+2929+#line 0 xprintf()
3030+static int xprintf(dest, fmtp, var)
3131+char *dest; /* pointer to buffer space */
3232+char **fmtp; /* pointer to address of format string pointer */
3333+Boolean var;
3434+{
3535+ _output = to_memory;
3636+ destination = dest;
3737+ if (_format(fmtp,var) == EOF) return (EOF);
3838+ *destination = '\0';
3939+ return(destination-dest+1);
4040+}
4141+4242+4343+#line 0 sprintf();
4444+int sprintf(dest, fmt)
4545+char *dest; /* pointer to buffer space */
4646+char *fmt; /* pointer to format string */
4747+{
4848+ return xprintf(dest, &fmt,false);
4949+}
5050+5151+5252+#line 0 vsprintf();
5353+int vsprintf(dest, fmt,arr)
5454+char *dest; /* pointer to buffer space */
5555+char *fmt,*arr; /* pointer to format string */
5656+{
5757+ return xprintf(dest, &fmt,true);
5858+}
+1383
sources/printf-2-w.c
···11+/*
22+ printf routines for LightspeedC�
33+44+ (C) Copyright 1986. THINK Technologies, Inc. All rights reserved.
55+66+ NOTE: Proportional fonts can be used, but lines will wrap as if they
77+ are monospaced. In this version, since each line is drawn with
88+ DrawChar or DrawText without repositioning, it will look better
99+ than the old monospaced repositioning version of putch.
1010+*/
1111+1212+/* If you have a non-Mac screen like a Radius or E-Machines, etc. stdio
1313+ may not operate correctly since it normally directly moves the graphics
1414+ pen to achieve reasonable speeds in drawing characters. By defining
1515+ _NonMacScreen_ you can convert all of the specialized code into the
1616+ standard Macintosh Toolbox traps so it will work correctly */
1717+1818+/* #define _NonMacScreen_ */
1919+2020+#ifndef _stdioh_
2121+#include "stdio.h"
2222+#endif
2323+2424+#ifndef _QuickDraw_
2525+#include "QuickDraw.h"
2626+#endif
2727+2828+#ifndef _FontMgr_
2929+#include "FontMgr.h"
3030+#endif
3131+3232+#ifndef _MenuMgr_
3333+#include "MenuMgr.h"
3434+#endif
3535+3636+#ifndef _ToolboxUtil_
3737+#include "ToolboxUtil.h"
3838+#endif
3939+4040+#ifndef _fopenwh_
4141+#include "fopenw.h"
4242+#endif
4343+4444+char *CtoPstr();
4545+char *PtoCstr();
4646+char *std_ver();
4747+void drawcursor();
4848+void Std_updatewindow();
4949+5050+/* screen display globals */
5151+5252+static WindowPtr Currentswrp = 0;
5353+static FILE *CurrentWindow = 0;
5454+static WindowPtr _exit_wp = 0; /* for special exit window handling */
5555+static WindowPtr _console_wp = 0;
5656+5757+/* default font info */
5858+5959+static GrafPort dummyPort;
6060+static FontInfo _sf; /* holds the info about the font */
6161+static int _font = monaco,
6262+ _size = 9,
6363+ _face = 0,
6464+ _mode = srcOr; /* stuff for Stdio_Config */
6565+6666+static RgnHandle emptyrgn; /* used for scrolling */
6767+static Rect bounds;
6868+6969+Boolean _inited = false; /* whether Mac is inited yet */
7070+static Boolean _screen = false; /* whether screen is inited */
7171+static Boolean _click_on = true; /* wait at exit from program */
7272+static Boolean _our_menus = false; /* flag to indicate if our menus */
7373+static int deskacc_count = 0; /* # desk accessories open */
7474+7575+Boolean _echo = true; /* global Echo status for keyboard input */
7676+extern void (*_echo_to_printer_)(); /* global Echo call variable for printer */
7777+7878+7979+#define movecursor(swrp, x, y)\
8080+MoveTo( _LEFTEDGE + (x) * swrp->charwidth,\
8181+ _TOPEDGE + swrp->sf.ascent + ((y)+swrp->visrow-swrp->opt.maxrow) * swrp->charheight)
8282+8383+8484+/* Determine if this is one of the stdio created windows or not */
8585+8686+static
8787+Boolean OurWindow(window)
8888+register StdWindowRec *window;
8989+{
9090+ if (window)
9191+ if ((window == (StdWindowRec *)_exit_wp) || (window->signature == _OURSIGNATURE))
9292+ return (true);
9393+9494+ return (false);
9595+}
9696+9797+/* Dispatch via refcon field of window record for window events */
9898+9999+static
100100+Boolean WindowEvent(xevent)
101101+XEventRecord *xevent;
102102+{
103103+register WindowPeek wp;
104104+register eventinfo **refcon;
105105+register int (*proc)();
106106+107107+ if (! OurWindow(wp = (WindowPeek) xevent->window)) return (false);
108108+109109+ if (wp->windowKind >= 8 && (refcon = (eventinfo**) wp->refCon)
110110+ && (proc = (**refcon).eventProc))
111111+ return ((*proc)(xevent));
112112+113113+ return (false);
114114+}
115115+116116+/* If we set up the screen, we set up a simple menu as well
117117+ for DAs and such */
118118+119119+static
120120+void setup_menus()
121121+{
122122+register MenuHandle menu; /* handle for our menus */
123123+124124+ InitMenus();
125125+ menu = NewMenu(1, "\p\024"); /* apple menu */
126126+ AddResMenu(menu, 'DRVR');
127127+ InsertMenu(menu, 0);
128128+ menu = NewMenu(2, "\pFile");
129129+ AppendMenu(menu, "\p(New;Open;Close;(Save;(-;Quit");
130130+ InsertMenu(menu, 0);
131131+ menu = NewMenu(3, "\pEdit");
132132+#ifdef _STD_PASTE_
133133+ AppendMenu(menu, "\p(Undo;(-;(Cut;(Copy;Paste;(Clear;(-");
134134+#else
135135+ AppendMenu(menu, "\p(Undo;(-;(Cut;(Copy;(Paste;(Clear;(-");
136136+#endif _STD_PASTE_
137137+138138+ AppendMenu(menu, CtoPstr(std_ver()));
139139+ PtoCstr(std_ver());
140140+ InsertMenu(menu, 0);
141141+ DrawMenuBar();
142142+143143+ _our_menus = true;
144144+}
145145+146146+static
147147+void do_exit()
148148+{Cursor watch;
149149+150150+ watch = **GetCursor(watchCursor);
151151+ SetCursor(&watch);
152152+ _click_on = false;
153153+ onexit_handler(); /* make sure other onexit routines get called */
154154+ ExitToShell();
155155+}
156156+157157+static
158158+doMenu(event)
159159+register XEventRecord *event;
160160+{
161161+short item;
162162+163163+ if (event->record.what != menuEvent)
164164+ return;
165165+166166+ item = event->record.message;
167167+ switch (* (short *) &event->record.message)
168168+ {
169169+ case 1:
170170+ event->record.what = appleEvent;
171171+ HiliteMenu(0);
172172+ break;
173173+ case 2:
174174+ switch (item)
175175+ {
176176+ case 2: /* Open entry on file menu */
177177+ event->record.what = openEvent;
178178+ break;
179179+180180+ case 3: /* Close entry on file menu */
181181+ event->record.what = closeEvent;
182182+ break;
183183+184184+ case 6: /* Quit entry on file menu */
185185+ do_exit();
186186+ break;
187187+ }
188188+ break;
189189+ case 3:
190190+#ifdef _STD_PASTE_
191191+ if (item == 5)
192192+ /* Paste entry on edit menu */
193193+ _std_setup_paste();
194194+#endif _STD_PASTE_
195195+196196+ HiliteMenu(0);
197197+ event->record.what = editEvent;
198198+ break;
199199+ }
200200+}
201201+202202+/* enable edit menu picks for undo, cut, copy, paste, etc. */
203203+204204+static
205205+void edit_enable()
206206+{register MenuHandle editmenu;
207207+208208+ if (_our_menus)
209209+ {
210210+ if (editmenu = GetMHandle(3))
211211+ {register int i;
212212+ for (i=CountMItems(editmenu); i; i--)
213213+ EnableItem(editmenu, i);
214214+ DisableItem(editmenu, 2); /* gray line */
215215+ DisableItem(editmenu, 7); /* gray line */
216216+ DisableItem(editmenu, 8); /* Library version */
217217+ }
218218+ }
219219+}
220220+221221+static
222222+void edit_disable()
223223+{register MenuHandle editmenu;
224224+225225+ if (_our_menus)
226226+ {
227227+ if (editmenu = GetMHandle(3))
228228+ {register int i;
229229+ for (i=CountMItems(editmenu); i; i--)
230230+ DisableItem(editmenu, i);
231231+#ifdef _STD_PASTE_
232232+ EnableItem(editmenu, 5); /* Paste */
233233+#endif _STD_PASTE_
234234+ EnableItem(editmenu, 8); /* Library version */
235235+ }
236236+ }
237237+}
238238+239239+/*
240240+ * StdEvent - event handler
241241+ *
242242+ */
243243+244244+#line 0 StdEvent
245245+Boolean StdEvent(event)
246246+register EventRecord *event;
247247+{
248248+XEventRecord ev;
249249+register XEventRecord *xevent = &ev;
250250+register short item, refnum;
251251+Rect r;
252252+long size;
253253+int (*proc)();
254254+static char accessory[256];
255255+256256+ Init_stdio();
257257+258258+ /* copy event to local data structure */
259259+260260+ ev = *(XEventRecord*) event;
261261+262262+ /* reset event to point to this extended event record */
263263+264264+ event = (EventRecord*) &ev;
265265+266266+ xevent->window = FrontWindow();
267267+268268+ switch (event->what)
269269+ {
270270+ default:
271271+ return (WindowEvent(event));
272272+273273+ case nullEvent:
274274+ if (! WindowEvent(event)) return (false);
275275+276276+ switch (FindWindow(event->where, &xevent->window))
277277+ {
278278+ case inContent:
279279+ if (xevent->window == FrontWindow())
280280+ {
281281+ SetPort(xevent->window);
282282+ GlobalToLocal(&event->where);
283283+ event->what = cursorEvent;
284284+ return (WindowEvent(event));
285285+ }
286286+ default:
287287+ SetCursor(&arrow);
288288+ break;
289289+ }
290290+ break;
291291+292292+ case updateEvt:
293293+ if (! OurWindow(xevent->window = (WindowPtr) event->message))
294294+ return (false);
295295+296296+ BeginUpdate(xevent->window);
297297+ SetPort(xevent->window);
298298+ WindowEvent(event);
299299+ EndUpdate(xevent->window);
300300+ break;
301301+302302+ case activateEvt:
303303+ if (! OurWindow(xevent->window = (WindowPtr) event->message))
304304+ return (false);
305305+306306+ SetPort(xevent->window);
307307+ if (!(event->modifiers & activeFlag))
308308+ event->what = deactivateEvt;
309309+ WindowEvent(event);
310310+ break;
311311+312312+ case mouseDown:
313313+ switch (FindWindow(event->where, &xevent->window))
314314+ {
315315+ default:
316316+ return (false);
317317+318318+ case inMenuBar:
319319+ if (! _our_menus)
320320+ return (false);
321321+322322+ xevent->window = FrontWindow();
323323+ SetCursor(&arrow);
324324+ doMenu(event);
325325+ event->message = MenuSelect(event->where);
326326+327327+ if (hiword(event->message) == 0) break;
328328+329329+ event->what = menuEvent;
330330+ doMenu(event);
331331+ switch (event->what)
332332+ {
333333+ case editEvent:
334334+ if (SystemEdit((short) event->message - 1))
335335+ break;
336336+ WindowEvent(event);
337337+ break;
338338+339339+ case closeEvent:
340340+ if (xevent->window)
341341+ {
342342+ refnum = ((WindowPeek) xevent->window)->windowKind;
343343+ if (refnum < 0)
344344+ {
345345+ CloseDeskAcc(refnum);
346346+ }
347347+ else
348348+ WindowEvent(event);
349349+ }
350350+ break;
351351+352352+ case openEvent:
353353+ if (_console->filebuf)
354354+ {
355355+ if (!((WindowPeek)_console->filebuf)->visible)
356356+ {
357357+ ShowWindow(_console->filebuf);
358358+ Std_updatewindow(_console->filebuf);
359359+ }
360360+ }
361361+ break;
362362+363363+ case appleEvent:
364364+ GetItem(GetMHandle(hiword(event->message)),
365365+ loword(event->message),
366366+ accessory);
367367+ OpenDeskAcc(accessory);
368368+ edit_enable();
369369+ break;
370370+ }
371371+ break;
372372+373373+ case inSysWindow:
374374+ SystemClick(event, xevent->window);
375375+ break;
376376+377377+ case inContent:
378378+ if (! OurWindow(xevent->window)) return (false);
379379+380380+ if (xevent->window != FrontWindow())
381381+ {
382382+ event->what = selectEvent;
383383+ WindowEvent(event);
384384+ if (event->what != mouseDown)
385385+ {
386386+ SelectWindow(xevent->window);
387387+ break;
388388+ }
389389+ }
390390+ SetPort(xevent->window);
391391+ GlobalToLocal(&event->where);
392392+ if (event->message = FindControl(event->where,
393393+ xevent->window,
394394+ &xevent->control))
395395+ {
396396+ proc = (int (*)()) (event->message > 128 ? 0L : -1L);
397397+ if (TrackControl(xevent->control, event->where, proc) == 0)
398398+ break;
399399+ event->what = controlEvent;
400400+ }
401401+ WindowEvent(event);
402402+ if (event->what != dragEvent) break;
403403+404404+ LocalToGlobal(&event->where);
405405+ /* ... */
406406+ case inDrag:
407407+ /* don't select window if command key is down */
408408+409409+ if (!(event->modifiers & cmdKey))
410410+ if (xevent->window != FrontWindow())
411411+ {
412412+ SelectWindow(xevent->window);
413413+ break;
414414+ }
415415+ SetRect(&r, 4, _MBARHEIGHT + 4, screenWidth - 4, screenHeight - 4);
416416+ SetCursor(&arrow);
417417+ DragWindow(xevent->window, event->where, &r);
418418+ break;
419419+420420+ case inGrow:
421421+ if (! OurWindow(xevent->window)) return (false);
422422+423423+ {register StdWindowRec *swrp = (StdWindowRec*)xevent->window;
424424+425425+ SetRect(&r,
426426+ swrp->charwidth + _LEFTEDGE + _CONTROLWIDTH + 3,
427427+ swrp->charheight + _TOPEDGE + _CONTROLWIDTH + 8,
428428+ swrp->charwidth * swrp->opt.maxcol + _LEFTEDGE + _CONTROLWIDTH + 3,
429429+ swrp->charheight * swrp->opt.maxrow + _TOPEDGE + _CONTROLWIDTH + 8);
430430+ }
431431+432432+ SetCursor(&arrow);
433433+ if (size = GrowWindow(xevent->window, event->where, &r))
434434+ {
435435+ SizeWindow(xevent->window, loword(size), hiword(size), 0);
436436+ SetPort(xevent->window);
437437+ InvalRect(&xevent->window->portRect);
438438+ event->what = growEvent;
439439+ WindowEvent(event);
440440+ {StdWindowRec *swrp = ((StdWindowRec*)xevent->window);
441441+ swrp->viscol = (loword(size)-_CONTROLWIDTH-1-swrp->charwidth+1)/swrp->charwidth;
442442+ swrp->visrow = (hiword(size)-_CONTROLWIDTH-1-swrp->charheight+1)/swrp->charheight;
443443+444444+ /* make sure neither variable exceeds legal bounds */
445445+446446+ if (swrp->viscol > swrp->opt.maxcol) swrp->viscol = swrp->opt.maxcol;
447447+ if (swrp->visrow > swrp->opt.maxrow) swrp->visrow = swrp->opt.maxrow;
448448+ }
449449+ }
450450+ break;
451451+452452+ case inGoAway:
453453+ if (! OurWindow(xevent->window)) return (false);
454454+455455+ SetCursor(&arrow);
456456+ if (TrackGoAway(xevent->window, event->where))
457457+ {
458458+ event->what = closeEvent;
459459+ WindowEvent(event);
460460+ }
461461+ break;
462462+ }
463463+ break;
464464+ }
465465+ return (true);
466466+}
467467+468468+static
469469+void stdio_fontset(portp)
470470+GrafPtr portp;
471471+{
472472+ /* set up a font */
473473+474474+ SetPort(portp);
475475+ TextFont(_font);
476476+ TextSize(_size);
477477+ TextFace(_face);
478478+ TextMode(_mode);
479479+}
480480+481481+static
482482+void drawcursor(swrp, flag)
483483+register StdWindowRec *swrp;
484484+Boolean flag;
485485+{register int x, y, savey;
486486+#ifdef _NonMacScreen_
487487+Point savepoint;
488488+#endif
489489+490490+ if (swrp->opt.cursor_visible)
491491+ {register int mode = notPatCopy;
492492+493493+ if (flag == ON) mode = patCopy;
494494+495495+ /* adjust and save pen position */
496496+497497+#ifdef _NonMacScreen_
498498+ GetPen(&savepoint);
499499+ x = savepoint.h - 1;
500500+ savey = savepoint.v;
501501+ y = savey + swrp->sf.descent;
502502+ MoveTo(x,y);
503503+#else
504504+ x = ((WindowPtr)swrp)->pnLoc.h -= 1;
505505+ savey = ((WindowPtr)swrp)->pnLoc.v;
506506+ y = (((WindowPtr)swrp)->pnLoc.v += swrp->sf.descent);
507507+#endif
508508+ /* cursor is simply a vertical line */
509509+510510+#ifdef _NonMacScreen_
511511+ PenMode(mode);
512512+#else
513513+ ((WindowPtr)swrp)->pnMode = mode; /*improved speed on Mac screen */
514514+#endif
515515+516516+ LineTo(x, y - swrp->charheight);
517517+518518+#ifdef _NonMacScreen_
519519+ MoveTo(x+1, savey);
520520+#else
521521+ ((WindowPtr)swrp)->pnLoc.h = x + 1;
522522+ ((WindowPtr)swrp)->pnLoc.v = savey;
523523+#endif
524524+ /* redraw character where cursor is if we turned it off */
525525+526526+ if (flag == OFF)
527527+ {
528528+ DrawChar(swrp->screen[((swrp->toprow+swrp->row)%swrp->opt.maxrow)*swrp->opt.maxcol+swrp->col]);
529529+530530+ /* replaced with below to improve speed */
531531+#ifdef _NonMacScreen_
532532+ MoveTo(x+1, savey);
533533+#else
534534+ ((WindowPtr)swrp)->pnLoc.h = x + 1;
535535+ ((WindowPtr)swrp)->pnLoc.v = savey;
536536+#endif
537537+ }
538538+ }
539539+}
540540+541541+#line 0 Std_updatewindow
542542+void Std_updatewindow(swrp)
543543+register StdWindowRec *swrp;
544544+{
545545+register int i, thisrow;
546546+547547+ SetPort(swrp);
548548+549549+ EraseRect(&((WindowPtr)swrp)->portRect);
550550+551551+ /* redraw last n rows in the visible region */
552552+553553+ for (i=0,
554554+ thisrow = (swrp->toprow + (swrp->opt.maxrow-swrp->visrow)) % swrp->opt.maxrow;
555555+ i<swrp->visrow;
556556+ i++, thisrow = ++thisrow % swrp->opt.maxrow)
557557+ {
558558+ movecursor(swrp, 0, i+swrp->opt.maxrow-swrp->visrow);
559559+ DrawText(&swrp->screen[thisrow*swrp->opt.maxcol], 0, swrp->viscol);
560560+ }
561561+562562+ if (!swrp->opt.no_grow)
563563+ {Rect r;
564564+ /* invalidate the scroll bar regions of the window, so
565565+ the scroll bars and grow box get drawn properly */
566566+ r = ((WindowPtr)swrp)->portRect;
567567+ r.left = r.right-_CONTROLWIDTH-2;
568568+ r.top = r.bottom-_CONTROLWIDTH-2;
569569+ InvalRect(&r);
570570+571571+ DrawControls(swrp);
572572+ DrawGrowIcon(swrp);
573573+ }
574574+575575+ /* make sure there is no further update event on this window */
576576+577577+ ValidRect(&((WindowPtr)swrp)->portRect);
578578+579579+ movecursor(swrp, swrp->col, swrp->row);
580580+ drawcursor(swrp, ON);
581581+}
582582+583583+static
584584+Stdwindow_doEvent(xevent)
585585+XEventRecord *xevent;
586586+{
587587+register WindowPtr wp = xevent->window;
588588+register int i;
589589+590590+ switch (((EventRecord*)xevent)->what)
591591+ {
592592+ case activateEvt:
593593+ edit_disable();
594594+ break;
595595+596596+ case deactivateEvt:
597597+ {StdWindowRec *srp;
598598+599599+ edit_disable();
600600+601601+ if ((srp = (StdWindowRec*)FrontWindow()))
602602+ if (! OurWindow(srp))
603603+ edit_enable();
604604+ break;
605605+ }
606606+ case updateEvt:
607607+ Std_updatewindow(wp);
608608+ break;
609609+610610+ case closeEvent:
611611+612612+ /* hide the window */
613613+614614+ HideWindow(wp);
615615+616616+ /* THIS PATCHED OUT CODE ALLOWS CLOSING ALL WINDOWS WHICH SHARE
617617+ THIS WINDOW POINTER AND RELEASING THEIR WINDOW RECORDS:
618618+ for (i= _NFILE-1; i>=0 ; i--)
619619+ if (_file[i].filebuf == (char*)wp)
620620+ fclosew(&_file[i]);
621621+ */
622622+623623+ break;
624624+625625+ default:
626626+ /* event was not handled by us */
627627+628628+ return (false);
629629+ }
630630+631631+ /* event was handled somewhere above */
632632+633633+ return (true);
634634+}
635635+636636+#line 0 fclosew
637637+int fclosew(who)
638638+register FILE *who;
639639+{
640640+ if (!who->window) return (EOF);
641641+642642+ if (who != _console)
643643+ {
644644+ who->window = false;
645645+ who->InUse = false;
646646+647647+ /* Now release the memory for the window record unless
648648+ it's the console which we never should release */
649649+650650+ if (OurWindow(who->filebuf) && ((WindowPtr)who->filebuf != _console_wp))
651651+ {
652652+ ((StdWindowRec*)who->filebuf)->signature = 0;
653653+ DisposHandle(((WindowPeek)who->filebuf)->refCon);
654654+ DisposeWindow(who->filebuf);
655655+ }
656656+657657+ who->filebuf = NULL;
658658+659659+ if (who == CurrentWindow)
660660+ {
661661+ CurrentWindow = _console;
662662+ Currentswrp = _console_wp;
663663+ }
664664+ }
665665+666666+ return (0);
667667+}
668668+669669+static
670670+void clearscreenmem(swrp)
671671+register StdWindowRec *swrp;
672672+{
673673+register char sp = ' ';
674674+register char *begp, *p;
675675+676676+ /* clear screen buffer to spaces working backwards through buffer */
677677+678678+ p = (begp = swrp->screen) + swrp->opt.maxcol * swrp->opt.maxrow;
679679+680680+ while (--p >= begp) *p = sp;
681681+}
682682+683683+684684+static
685685+FILE *fopenwx(titlebar, upper_left, optionsptr, whichfilevar, ourwp)
686686+char *titlebar;
687687+Point upper_left;
688688+register StdWindowOptions *optionsptr;
689689+FILE *whichfilevar;
690690+WindowPtr ourwp;
691691+{
692692+register int maxrow = 0, maxcol = 0;
693693+register FILE *who;
694694+register StdWindowRec *swrp;
695695+register Boolean grow = true, goaway = true;
696696+eventinfo et;
697697+698698+ Init_stdio();
699699+700700+ if (whichfilevar)
701701+ {
702702+ /* a specific file variable was specified */
703703+ who = whichfilevar;
704704+705705+ if ((!who->StdStream) || who->InUse)
706706+ {
707707+ /* don't allow this for other than standard streams */
708708+ errno = -47; /* file busy error */
709709+ return (NULL);
710710+ }
711711+ }
712712+ else
713713+ {register int free_slot = _NFILE;
714714+715715+ /* look thru FILE array for an open slot */
716716+717717+ while ((--free_slot>=0) && _file[free_slot].InUse)
718718+ ;
719719+720720+ if (free_slot < 0)
721721+ {
722722+ errno = -42; /* tmfoErr - too many files open */
723723+ return (NULL);
724724+ }
725725+726726+ who = &_file[free_slot];
727727+728728+ if (!ourwp && optionsptr)
729729+ {
730730+ /* override defaults */
731731+732732+ maxcol = optionsptr->maxcol;
733733+ maxrow = optionsptr->maxrow;
734734+735735+ grow = !optionsptr->no_grow;
736736+ goaway = !optionsptr->no_goaway;
737737+ }
738738+ }
739739+740740+ /* if ourwp is nonzero, then the window is already set up and all
741741+ we need to do is set up the file record */
742742+743743+ if (ourwp) swrp = (StdWindowRec*) ourwp;
744744+ else
745745+ {{register int charheight;
746746+747747+ stdio_fontset(&dummyPort);
748748+ GetFontInfo(&_sf);
749749+750750+ charheight = (_sf.ascent + _sf.descent + _sf.leading);
751751+752752+ /* set up default number of rows and columns depending on screen */
753753+754754+ if (!maxrow)
755755+ maxrow = (screenHeight - upper_left.v - _TOPEDGE - _CONTROLWIDTH - 1 - charheight + 1) /
756756+ charheight;
757757+758758+ if (!maxcol)
759759+ maxcol = (screenWidth - upper_left.h - _LEFTEDGE - _CONTROLWIDTH - 1 - _sf.widMax + 1) /
760760+ _sf.widMax;
761761+762762+ /* create a pointer block big enough to accomodate the window record
763763+ and all of our stuff */
764764+765765+ if (!(swrp = (StdWindowRec*) (NewPtr(sizeof(StdWindowRec)+maxrow*maxcol))))
766766+ {
767767+ errno = -108; /* MemFullErr - ran out of memory */
768768+ return (NULL);
769769+ }
770770+771771+ swrp->sf = _sf;
772772+773773+ swrp->charheight = charheight;
774774+ swrp->charwidth = _sf.widMax;
775775+776776+ } /* just provides scoping for charheight */
777777+778778+ swrp->toprow = swrp->col = 0;
779779+ swrp->row = maxrow - 1; /* start cursor at bottom of screen */
780780+ swrp->signature = _OURSIGNATURE;
781781+782782+ bounds.top = upper_left.v;
783783+ bounds.left = upper_left.h;
784784+ bounds.right = bounds.left + _LEFTEDGE + maxcol * swrp->charwidth + _CONTROLWIDTH + 1;
785785+ bounds.bottom = bounds.top + _TOPEDGE + maxrow * swrp->charheight + _CONTROLWIDTH + 1 + 4;
786786+787787+ NewWindow(swrp, &bounds, CtoPstr(titlebar), true,
788788+ (grow ? documentProc : noGrowDocProc), -1L, goaway, 0L);
789789+790790+ PtoCstr(titlebar);
791791+792792+ /* set up event processing hooks */
793793+794794+ et.eventProc = Stdwindow_doEvent;
795795+ et.vscroll = 0;
796796+ PtrToHand(&et, &((WindowPeek)swrp)->refCon, sizeof et);
797797+798798+ stdio_fontset(swrp);
799799+800800+ if (grow)
801801+ {
802802+ InvalRect(&((WindowPtr)swrp)->portRect);
803803+ DrawControls(swrp);
804804+ DrawGrowIcon(swrp);
805805+ }
806806+807807+ ValidRect(&((WindowPtr)swrp)->portRect);
808808+809809+ if (optionsptr)
810810+ swrp->opt = *optionsptr;
811811+ else
812812+ {
813813+ swrp->opt.maxrow = maxrow;
814814+ swrp->viscol = swrp->opt.maxcol = maxcol;
815815+ swrp->opt.cursor_visible = true;
816816+ swrp->opt.echo_state = true;
817817+ swrp->opt._tab_width = 4;
818818+ swrp->opt.no_pull_front = false;
819819+ swrp->opt.no_grow = !grow;
820820+ swrp->opt.no_drag = false;
821821+ swrp->opt.no_goaway = !goaway;
822822+ swrp->opt.no_scroll = false;
823823+ swrp->opt.no_wrap = false;
824824+ }
825825+826826+ swrp->visrow = maxrow;
827827+ swrp->viscol = maxcol;
828828+829829+ /* clear screen memory to spaces */
830830+831831+ clearscreenmem(swrp);
832832+833833+ movecursor(swrp, swrp->col, swrp->row);
834834+ drawcursor(swrp, ON);
835835+ }
836836+837837+ /* set all relevant items in FILE record */
838838+839839+ who->filebuf = (char *) swrp;
840840+ who->StdStream = true;
841841+ who->InUse = true;
842842+ who->window = true;
843843+ who->rd = false;
844844+ who->wr = true;
845845+846846+ return (who);
847847+}
848848+849849+#line 0 fopenw
850850+FILE *fopenw(titlebar, upper_left, optionsptr)
851851+char *titlebar;
852852+Point upper_left;
853853+StdWindowOptions *optionsptr;
854854+{
855855+ fopenwx(titlebar, upper_left, optionsptr, NULL, NULL);
856856+}
857857+858858+#line 0 setwindow
859859+int setwindow(windowfile)
860860+register FILE *windowfile;
861861+{
862862+register StdWindowRec *swrp;
863863+864864+ if (windowfile &&
865865+ windowfile->InUse &&
866866+ windowfile->window &&
867867+ (swrp = ((StdWindowRec*)windowfile->filebuf))->signature == _OURSIGNATURE)
868868+ {
869869+ CurrentWindow = windowfile;
870870+ Currentswrp = (WindowPtr) swrp;
871871+ _echo = swrp->opt.echo_state;
872872+ }
873873+ else
874874+ return (EOF);
875875+876876+ return (0);
877877+}
878878+879879+stdwsave(windowfile, env)
880880+FILE *windowfile;
881881+StdwsaveRecord *env;
882882+{
883883+884884+ Init_stdio();
885885+ env->fp = CurrentWindow;
886886+ env->wp = Currentswrp;
887887+888888+ return (setwindow(windowfile));
889889+}
890890+891891+stdwrestore(windowfile, env)
892892+FILE *windowfile;
893893+StdwsaveRecord *env;
894894+{
895895+ if (windowfile != CurrentWindow) return (EOF);
896896+897897+ CurrentWindow = env->fp;
898898+ Currentswrp = env->wp;
899899+ _echo = ((StdWindowRec*)Currentswrp)->opt.echo_state;
900900+ return (0);
901901+}
902902+903903+#line 0 Click_On()
904904+void Click_On(flag)
905905+{
906906+ _click_on = flag;
907907+}
908908+909909+static
910910+draw_exit_text(xevent)
911911+XEventRecord *xevent;
912912+{
913913+WindowPtr wp = xevent->window;
914914+915915+ switch (((EventRecord*)xevent)->what)
916916+ {
917917+ case updateEvt:
918918+ SetPort(wp);
919919+ MoveTo(4, 24+_sf.descent);
920920+ DrawString("\p Click close box of this window or press Return to continue");
921921+ break;
922922+923923+ case closeEvent:
924924+ do_exit();
925925+926926+ default:
927927+ /* event not handled by us */
928928+929929+ return (false);
930930+ }
931931+932932+ /* event was handled above */
933933+934934+ return (true);
935935+}
936936+937937+static
938938+void click_to_continue()
939939+{
940940+eventinfo et;
941941+942942+ /* make sure all exit routines have been called before we
943943+ do anything */
944944+945945+ onexit_handler();
946946+947947+ /* if (emptyrgn) DisposeRgn(emptyrgn); - need not bother since the
948948+ entire application heap should be vaporized shortly */
949949+950950+ if (_click_on)
951951+ {
952952+ /* cancel any pending events */
953953+954954+ FlushEvents(everyEvent, 0);
955955+956956+ bounds.left = bounds.top = 50;
957957+ bounds.right = 456;
958958+ bounds.bottom = 100;
959959+960960+ /* Put up a window and handle window events
961961+ until goaway is clicked for this window */
962962+963963+ _exit_wp = NewWindow(0L, &bounds, "\pExit Window",
964964+ true, noGrowDocProc,
965965+ -1L, true, 0L);
966966+967967+ et.eventProc = draw_exit_text;
968968+ PtrToHand(&et, &((WindowPeek) _exit_wp)->refCon, sizeof et);
969969+970970+ _font = systemFont;
971971+ _size = 12;
972972+ stdio_fontset(_exit_wp);
973973+974974+ /* small event loop to process window events such as bringing
975975+ to front, resizing, dragging, etc. */
976976+977977+ for (;;)
978978+ {EventRecord event;
979979+ while (! GetNextEvent(everyEvent, &event))
980980+ {
981981+ HiliteMenu(0);
982982+ SystemTask();
983983+ }
984984+985985+ SetCursor(&arrow);
986986+987987+ if (event.what == keyDown && (char) event.message == '\r')
988988+ break;
989989+990990+ StdEvent(&event);
991991+ }
992992+993993+ do_exit();
994994+ }
995995+}
996996+997997+#line 0 Stdio_Config()
998998+void Stdio_Config(font,size,face,mode)
999999+int font,size,face,mode;
10001000+{
10011001+ /* modify defaults */
10021002+10031003+ _font = font;
10041004+ _size = size;
10051005+ _face = face;
10061006+ _mode = mode;
10071007+}
10081008+10091009+#line 0 Stdio_config() /* lower case c since it was wrong in the manual! */
10101010+void Stdio_config(font,size,face,mode)
10111011+int font,size,face,mode;
10121012+{
10131013+ Stdio_Config(font, size, face, mode);
10141014+}
10151015+10161016+void Init_stdio()
10171017+{
10181018+register StdWindowRec *swrp;
10191019+Point topleftcorner;
10201020+10211021+ if (_inited && _screen) return;
10221022+10231023+ if (!_inited)
10241024+ {
10251025+ _inited = true;
10261026+ InitGraf(&thePort);
10271027+ InitFonts();
10281028+ InitWindows();
10291029+ InitDialogs(0L);
10301030+ setup_menus();
10311031+ TEInit();
10321032+ FlushEvents(everyEvent, 0);
10331033+ HiliteMenu(0);
10341034+ SystemTask();
10351035+ }
10361036+10371037+ if (!_screen)
10381038+ {
10391039+ _screen = true;
10401040+10411041+ OpenPort(&dummyPort);
10421042+10431043+ /* this font information must be set up for fopenw to know how
10441044+ big to make the window */
10451045+10461046+ topleftcorner.h = 4;
10471047+ topleftcorner.v = _MBARHEIGHT + _TITLEBARHEIGHT + 4;
10481048+10491049+ setwindow(fopenwx("console", topleftcorner, NULL, _console, NULL));
10501050+10511051+ _console_wp = Currentswrp;
10521052+10531053+ /* unlike other windows, console is multi-purpose and
10541054+ so it is handled specially */
10551055+10561056+ _console->rd = true;
10571057+10581058+ /* set up stdout and stderr to match */
10591059+10601060+ if (stdout->StdStream)
10611061+ fopenwx("", topleftcorner, NULL, stdout, _console_wp);
10621062+10631063+ if (stderr->StdStream)
10641064+ fopenwx("", topleftcorner, NULL, stderr, _console_wp);
10651065+10661066+ /* set up exit procedure */
10671067+10681068+ onexit(click_to_continue);
10691069+10701070+ SetCursor(&arrow);
10711071+ }
10721072+10731073+ if (!emptyrgn) emptyrgn=NewRgn();
10741074+}
10751075+10761076+#line 0 Set_Echo()
10771077+void Set_Echo(state)
10781078+Boolean state;
10791079+{
10801080+ _echo = state;
10811081+ if (CurrentWindow)
10821082+ ((StdWindowRec*)(Currentswrp))->opt.echo_state = state;
10831083+}
10841084+10851085+/* pdg - 6/10/86 - Stdio_MacInit() allows coexistence of Mac windows and
10861086+ stdio if called with flag set to true so stdio won't
10871087+ reinitialize all of the Mac stuff. */
10881088+10891089+#line 0 Stdio_MacInit()
10901090+void Stdio_MacInit(flag)
10911091+Boolean flag;
10921092+{
10931093+ _inited = flag;
10941094+}
10951095+10961096+#line 0 Set_Tab
10971097+void Set_Tab(len)
10981098+int len;
10991099+{
11001100+ Init_stdio();
11011101+11021102+ ((StdWindowRec*) Currentswrp)->opt._tab_width = 1;
11031103+11041104+ if (len < 1) ((StdWindowRec*) Currentswrp)->opt._tab_width = len;
11051105+}
11061106+11071107+#line 0 gotoxy
11081108+void gotoxy(x,y)
11091109+register int x,y;
11101110+{
11111111+register StdWindowRec *swrp;
11121112+11131113+ Init_stdio();
11141114+11151115+ swrp = (StdWindowRec*) Currentswrp;
11161116+11171117+ if ((x < swrp->opt.maxcol) && (y < swrp->opt.maxrow))
11181118+ {
11191119+ drawcursor(swrp, OFF);
11201120+ swrp->col = x;
11211121+ swrp->row = y;
11221122+ movecursor(swrp, x,y);
11231123+ drawcursor(swrp, ON);
11241124+ }
11251125+}
11261126+11271127+#line 0 getxpos
11281128+int getxpos()
11291129+{
11301130+ Init_stdio();
11311131+11321132+ return (((StdWindowRec*) Currentswrp)->col);
11331133+}
11341134+11351135+#line 0 getypos
11361136+int getypos()
11371137+{
11381138+ Init_stdio();
11391139+11401140+ return (((StdWindowRec*) Currentswrp)->row);
11411141+}
11421142+11431143+#line 0 Get_ScreenPtr
11441144+char *Get_ScreenPtr(who)
11451145+register FILE *who;
11461146+{
11471147+ Init_stdio();
11481148+11491149+ if (who->InUse && who->window)
11501150+ return (((StdWindowRec*) who->filebuf)->screen);
11511151+11521152+ return (NULL);
11531153+}
11541154+11551155+#line 0 Get_WindowPtr
11561156+void *Get_WindowPtr(who) /* actually returns a WindowPtr! */
11571157+register FILE *who;
11581158+{
11591159+ Init_stdio();
11601160+11611161+ if (who->InUse && who->window)
11621162+ return ((void*) who->filebuf);
11631163+11641164+ return (NULL);
11651165+}
11661166+11671167+#line 0 putch
11681168+void putch(c)
11691169+register char c;
11701170+{
11711171+register StdWindowRec *swrp;
11721172+register char *screenp;
11731173+static inited=false;
11741174+11751175+ if (!inited)
11761176+ {
11771177+ inited = true;
11781178+ Init_stdio();
11791179+ }
11801180+11811181+ if (! Currentswrp || ! CurrentWindow->InUse) return;
11821182+11831183+ if (_echo_to_printer_ && (Currentswrp == _console_wp))
11841184+ (*_echo_to_printer_)(c);
11851185+11861186+ SetPort(swrp = (StdWindowRec*) Currentswrp);
11871187+11881188+ if (swrp != (StdWindowRec *)FrontWindow())
11891189+ if (! swrp->opt.no_pull_front)
11901190+ {
11911191+ SelectWindow(swrp);
11921192+ Std_updatewindow(swrp);
11931193+ }
11941194+11951195+ /* wait here if mouse is down */
11961196+11971197+ while (Button());
11981198+11991199+ if (c<' ')
12001200+ {
12011201+ switch(c)
12021202+ {
12031203+12041204+ case '\t':
12051205+ {register int over;
12061206+ Boolean newline = false;
12071207+12081208+ over = swrp->opt._tab_width - (swrp->col % swrp->opt._tab_width);
12091209+ if ((swrp->col + over) > swrp->opt.maxcol)
12101210+ {
12111211+ newline = true;
12121212+ c = '\n';
12131213+12141214+ over = swrp->opt.maxcol - swrp->col;
12151215+ }
12161216+12171217+ /* want to write spaces into those columns where tab is */
12181218+12191219+ if (over > 0)
12201220+ {Rect r;
12211221+12221222+ screenp = swrp->screen +
12231223+ (((swrp->toprow+swrp->row)%swrp->opt.maxrow) * swrp->opt.maxcol) + swrp->col - 1;
12241224+12251225+ drawcursor(swrp, OFF);
12261226+12271227+ /* erase character positions on screen */
12281228+12291229+ r.right = (r.left = ((WindowPtr)swrp)->pnLoc.h) + over * swrp->charwidth;
12301230+ r.top = (r.bottom = ((WindowPtr)swrp)->pnLoc.v + swrp->sf.descent) - swrp->charheight;
12311231+12321232+ EraseRect(&r);
12331233+12341234+ swrp->col += over;
12351235+12361236+ while (--over>=0) *++screenp = ' ';
12371237+12381238+ movecursor(swrp, swrp->col, swrp->row);
12391239+12401240+ drawcursor(swrp, ON);
12411241+ }
12421242+12431243+ if (newline) break;
12441244+12451245+ return;
12461246+ }
12471247+12481248+ case '\r': /* simply return cursor to start of line */
12491249+ drawcursor(swrp, OFF);
12501250+ swrp->col = 0;
12511251+ movecursor(swrp, 0, swrp->row);
12521252+ drawcursor(swrp, ON);
12531253+ return;
12541254+12551255+ case '\b': /* simply reposition cursor back one column */
12561256+ {
12571257+ /* This won't work for proportional fonts
12581258+ since we don't have the true width handy
12591259+ true, it could be looked up in the font...*/
12601260+12611261+ drawcursor(swrp, OFF);
12621262+12631263+ if (swrp->col == 0)
12641264+ {
12651265+ if (((swrp->row == 0) && (!swrp->opt.no_scroll))
12661266+ || swrp->opt.no_wrap)
12671267+ {
12681268+ drawcursor(swrp, ON);
12691269+ return;
12701270+ }
12711271+12721272+ /* return to previous row */
12731273+12741274+ if (swrp->row == 0)
12751275+ swrp->row = swrp->opt.maxrow;
12761276+12771277+ swrp->row--;
12781278+ swrp->col = swrp->opt.maxcol;
12791279+ }
12801280+ swrp->col--;
12811281+ movecursor(swrp, swrp->col, swrp->row);
12821282+ drawcursor(swrp, ON);
12831283+ return;
12841284+ }
12851285+12861286+ case '\f':
12871287+ {Rect r;
12881288+12891289+ drawcursor(swrp, OFF);
12901290+12911291+ r = ((WindowPtr)swrp)->portRect;
12921292+ r.right -= _CONTROLWIDTH+2;
12931293+ r.bottom -= _CONTROLWIDTH+2;
12941294+ EraseRect(&r);
12951295+12961296+ swrp->toprow = swrp->row = swrp->col = 0;
12971297+12981298+ clearscreenmem(swrp);
12991299+13001300+ movecursor(swrp, 0, 0);
13011301+ drawcursor(swrp, ON);
13021302+ return;
13031303+ }
13041304+13051305+ case 7: SysBeep(2); /* Bell */
13061306+ return;
13071307+ }
13081308+ }
13091309+13101310+ drawcursor(swrp, OFF);
13111311+13121312+ if ((c != '\n') && (swrp->col < swrp->opt.maxcol))
13131313+ {
13141314+ screenp = swrp->screen + ((swrp->toprow+swrp->row)%swrp->opt.maxrow)*swrp->opt.maxcol+swrp->col;
13151315+13161316+ /* dump character into the screen buffer and
13171317+ possibly draw the character */
13181318+13191319+13201320+13211321+ if (swrp->col < swrp->viscol)
13221322+ {
13231323+ if (*screenp != ' ')
13241324+ {Rect r;
13251325+ /* erase this character position on screen */
13261326+13271327+ r.right = (r.left = ((WindowPtr)swrp)->pnLoc.h) + swrp->charwidth;
13281328+ r.top = (r.bottom = ((WindowPtr)swrp)->pnLoc.v + swrp->sf.descent) - swrp->charheight;
13291329+13301330+ EraseRect(&r);
13311331+ }
13321332+13331333+ DrawChar(*screenp = c);
13341334+ }
13351335+ else
13361336+ *screenp = c;
13371337+ }
13381338+13391339+ /* need to do a newline? */
13401340+13411341+ if ((c=='\n') || ((++swrp->col >= swrp->opt.maxcol) && !swrp->opt.no_wrap))
13421342+ {
13431343+ if (swrp->opt.no_scroll)
13441344+ /* if we don't scroll, toprow doesn't move and the characters
13451345+ wrap back to the first screen line */
13461346+ swrp->row = (swrp->row + 1) % swrp->opt.maxrow;
13471347+ else
13481348+ {
13491349+ if (swrp->row >= swrp->opt.maxrow-1)
13501350+ {Rect scrollrect;
13511351+ register int i;
13521352+ register char *p;
13531353+13541354+ scrollrect = ((WindowPtr)swrp)->portRect;
13551355+ scrollrect.top += _TOPEDGE;
13561356+ scrollrect.left += _LEFTEDGE;
13571357+ scrollrect.right -= _CONTROLWIDTH+1;
13581358+ scrollrect.bottom -= _CONTROLWIDTH+1;
13591359+13601360+ ScrollRect(&scrollrect,0,-swrp->charheight,emptyrgn);
13611361+13621362+ /* toprow points to the new first line */
13631363+13641364+ swrp->toprow = (swrp->toprow + 1) % swrp->opt.maxrow;
13651365+13661366+ p = swrp->screen + ((swrp->toprow + swrp->opt.maxrow - 1) % swrp->opt.maxrow) * swrp->opt.maxcol - 1;
13671367+13681368+ /* clear the reallocated line in the buffer */
13691369+13701370+ for (i=swrp->opt.maxcol; i; i--)
13711371+ *++p = ' ';
13721372+ }
13731373+ else
13741374+ ++swrp->row;
13751375+ }
13761376+13771377+ swrp->col = 0;
13781378+13791379+ movecursor(swrp, 0, swrp->row);
13801380+ }
13811381+13821382+ drawcursor(swrp, ON);
13831383+}
+346
sources/printf-2.c
···11+/*
22+ printf routines for LightspeedC�
33+44+ (C) Copyright 1985, 1986. THINK Technologies, Inc. All rights reserved.
55+*/
66+77+#ifndef _stdioh_
88+#include "stdio.h"
99+#endif
1010+1111+#ifndef _ctypeh_
1212+#include "ctype.h"
1313+#endif
1414+1515+#ifndef _MacTypes_
1616+#include "MacTypes.h"
1717+#endif
1818+1919+#ifndef _WindowMgr_
2020+#include "WindowMgr.h"
2121+#endif
2222+2323+#ifndef _QuickDraw_
2424+#include "QuickDraw.h"
2525+#endif
2626+2727+#ifndef _EventMgr_
2828+#include "EventMgr.h"
2929+#endif
3030+3131+#ifndef _FontMgr_
3232+#include "FontMgr.h"
3333+#endif
3434+3535+extern void (*_echo_to_printer_)(); /* global Echo call variable for printer */
3636+3737+GrafPort stdioPort;
3838+static int _tab_width = 4; /* size between tab stops */
3939+static FontInfo _sf; /* holds the info about the font */
4040+static int _ch,_cw,_mh,_mw,_sz; /* various info for putch */
4141+static int _font,_size,_face,_mode;/* stuff for Stdio_Config */
4242+static RgnHandle emptyrgn; /* used for scrolling */
4343+4444+static Boolean _default = true; /* true for default font */
4545+Boolean _inited = false; /* whether Mac is inited yet */
4646+static Boolean _screen = false; /* whether screen is inited */
4747+static Boolean _click_on = true; /* wait at exit from program */
4848+Boolean _echo = true; /* Echo status for keyboard input */
4949+5050+static int row = 1;
5151+static int col = 1;
5252+5353+5454+#line 0 Click_On()
5555+void Click_On(flag)
5656+{
5757+ _click_on = flag;
5858+}
5959+6060+#line 0 click_to_continue()
6161+static void click_to_continue()
6262+{
6363+ /* if (emptyrgn) DisposeRgn(emptyrgn); - gets blasted on exit anyway */
6464+6565+ if (_click_on)
6666+ {
6767+ gotoxy(_mw/2-12,_mh);
6868+ cputs("click mouse to continue.");
6969+7070+ while (!Button());
7171+7272+ /* pdg- 6/10/86 - then wait for release of button */
7373+7474+ while (Button());
7575+ }
7676+}
7777+7878+#line 0 Init_stdio()
7979+void Init_stdio()
8080+{
8181+ if (_inited && _screen) return;
8282+8383+ if (!_inited)
8484+ {
8585+ _inited = true;
8686+ InitGraf(&thePort);
8787+ InitFonts();
8888+ InitWindows();
8989+ InitDialogs(0L);
9090+ TEInit();
9191+ }
9292+9393+ if (!_screen)
9494+ {
9595+ _screen = true;
9696+ OpenPort(&stdioPort);
9797+ HideCursor();
9898+ EraseRect(&stdioPort.portRect);
9999+100100+ if (_default)
101101+ {
102102+ _font = monaco;
103103+ _size = 9;
104104+ _face = 0;
105105+ _mode = srcOr;
106106+ }
107107+ TextFont(_font);
108108+ TextSize(_size);
109109+ _sz = _size; /* should be the same as above */
110110+ TextFace(_face);
111111+ TextMode(_mode);
112112+ GetFontInfo(&_sf);
113113+ _ch = _sf.ascent+_sf.descent+_sf.leading;
114114+ _cw = _sf.widMax;
115115+ _mw = (stdioPort.portRect.right)/_cw - 1; /* 13-Feb-86 */
116116+ _mh = (stdioPort.portRect.bottom - 11)/_ch - 1;
117117+118118+ /* set up exit procedure */
119119+120120+ onexit(click_to_continue);
121121+ }
122122+}
123123+124124+#line 0 Stdio_Config()
125125+void Stdio_Config(font,size,face,mode)
126126+int font,size,face,mode;
127127+{
128128+ _font = font;
129129+ _size = size;
130130+ _face = face;
131131+ _mode = mode;
132132+ _default = false;
133133+}
134134+135135+136136+#line 0 Set_Echo()
137137+void Set_Echo(state)
138138+Boolean state;
139139+{
140140+ _echo = state;
141141+}
142142+143143+/* pdg - 6/10/86 - Stdio_MacInit() allows coexistence of Mac windows and
144144+ stdio if called with flag set to true so stdio won't
145145+ reinitialize all of the Mac stuff. */
146146+147147+#line 0 Stdio_MacInit()
148148+void Stdio_MacInit(flag)
149149+Boolean flag;
150150+{
151151+ _inited = flag;
152152+}
153153+154154+#line 0 cursor_plot
155155+static void cursor_plot(erase_block)
156156+Boolean erase_block;
157157+{
158158+register int v;
159159+Rect rect;
160160+PenState ps;
161161+162162+static Boolean Cursor_Inited = false;
163163+ thePort->pnLoc.v = v = row * _ch - _sf.descent;
164164+165165+ thePort->pnLoc.h = rect.left = col * _cw;
166166+167167+ GetPenState(&ps);
168168+169169+ PenMode(patXor);
170170+171171+ rect.top = v - _sf.ascent;
172172+ rect.right = rect.left + _cw;
173173+ rect.bottom = v + _sf.descent;
174174+175175+ if (Cursor_Inited == false)
176176+ Cursor_Inited = true;
177177+ else
178178+ if (erase_block) EraseRect(&rect);
179179+ else PaintRect(&rect);
180180+181181+ SetPenState(&ps);
182182+}
183183+184184+185185+#line 0 Set_Tab
186186+void Set_Tab(len)
187187+int len;
188188+{
189189+ _tab_width = 1;
190190+191191+ if (len < 1) _tab_width = len;
192192+}
193193+194194+#line 0 gotoxy
195195+void gotoxy(x,y)
196196+int x,y;
197197+{
198198+ Init_stdio();
199199+200200+ if ((x<=_mw)&&(y<=_mh))
201201+ {
202202+ cursor_plot(false);
203203+ col = x+1;
204204+ row = y+1;
205205+ cursor_plot(false);
206206+ }
207207+}
208208+209209+#line 0 getxpos
210210+int getxpos()
211211+{
212212+ return (col-1);
213213+}
214214+215215+#line 0 getypos
216216+int getypos()
217217+{
218218+ return (row-1);
219219+}
220220+221221+#line 0 putch
222222+void putch(c)
223223+register char c;
224224+{
225225+226226+ Init_stdio(); /* initalize */
227227+228228+ if (_echo_to_printer_) (*_echo_to_printer_)(c);
229229+230230+ /* wait here if mouse is down */
231231+232232+ while (Button());
233233+234234+ if (c<' ')
235235+ {
236236+ switch(c)
237237+ {
238238+239239+ case '\n' : cursor_plot(false);
240240+ break;
241241+242242+ case '\t' : cursor_plot(false);
243243+ while (((col-1) % _tab_width) || (col-1 == 0))
244244+ {
245245+ cursor_plot(true);
246246+ col++;
247247+ }
248248+ break;
249249+250250+ case '\r' : cursor_plot(false);
251251+ col = 1;
252252+ cursor_plot(false);
253253+ return;
254254+255255+ case '\b' : cursor_plot(false);
256256+ if (col > 1) col--;
257257+ cursor_plot(true);
258258+ cursor_plot(false);
259259+ return;
260260+261261+ case '\f' : EraseRect(&stdioPort.portRect);
262262+ col = 1;
263263+ row = 1;
264264+ cursor_plot(false);
265265+ return;
266266+267267+ case 7 : SysBeep(5);
268268+ return;
269269+ }
270270+ }
271271+ if (c != '\t')
272272+ {
273273+ if (c != '\n')
274274+ { /* position and print char */
275275+276276+ cursor_plot(true);
277277+278278+ DrawChar(c);
279279+ }
280280+281281+ if ((++col > _mw) || (c=='\n')) /* need to do a newline? */
282282+ {
283283+ if (row > _mh)
284284+ {
285285+ if (!emptyrgn) emptyrgn=NewRgn();
286286+287287+ ScrollRect(&stdioPort.portRect,0,-_ch,emptyrgn);
288288+ }
289289+ else
290290+ row++;
291291+292292+ col = 1;
293293+ }
294294+ }
295295+ cursor_plot(false);
296296+}
297297+298298+/* the following are for compatibility with windowed version: printf-2-w.c */
299299+300300+#line 0 StdEvent
301301+Boolean StdEvent(event)
302302+{
303303+ return (false);
304304+}
305305+306306+#line 0 stdwsave
307307+stdwsave()
308308+{
309309+ return (0);
310310+}
311311+#line 0 stdwrestore
312312+stdwrestore()
313313+{
314314+ return (0);
315315+}
316316+317317+#line 0 setwindow
318318+setwindow()
319319+{
320320+ return (0);
321321+}
322322+323323+#line 0 fclosew
324324+fclosew()
325325+{
326326+ return (0);
327327+}
328328+329329+/* the following two are not implemented since there is nothing sensible
330330+ that they could return in a non-windowed version of printf */
331331+332332+#ifdef _NOT_SENSIBLE_
333333+334334+#line 0 Get_ScreenPtr
335335+char *Get_ScreenPtr()
336336+{
337337+ return (0);
338338+}
339339+340340+#line 0 Get_WindowPtr
341341+WindowPtr Get_WindowPtr()
342342+{
343343+ return (0);
344344+}
345345+346346+#endif _NOT_SENSIBLE_
+830
sources/printf-3.c
···11+/*
22+ printf formatter for LightspeedC�
33+44+ (C) Copyright 1985, 1986. THINK Technologies, Inc. All rights reserved.
55+66+ pdg - 6/11/86 - revised
77+*/
88+99+/* comment this out if you don't need floating point numeric support */
1010+#define _FORMAT_FP_
1111+1212+#ifndef _stdioh_
1313+#include "stdio.h"
1414+#endif
1515+1616+#ifndef _MacTypes_
1717+#include "MacTypes.h"
1818+#endif
1919+2020+#ifndef _saneh_
2121+#include "sane.h"
2222+#endif
2323+2424+#ifndef _setjmph_
2525+#include "setjmp.h"
2626+#endif
2727+2828+/* it turns out that defining min, max, and isdigit as follows works pretty
2929+ well and drags in less code from other modules */
3030+#undef min
3131+#undef max
3232+#undef isdigit
3333+3434+#define min(a,b) ( (a<b) ? (a) : (b) )
3535+#define max(a,b) ( (a>b) ? (a) : (b) )
3636+#define isdigit(c) ( (c<='9') && (c>='0') )
3737+3838+#define BLANKS 0
3939+4040+void (*_output)(); /* global pointer to function for output */
4141+int _num_count; /* number of characters transmitted */
4242+jmp_buf env; /* global error return mechanism */
4343+4444+static char _hex_case; /* used for x X case */
4545+static char fillchar; /* space or '0' depending on mode */
4646+static int base; /* global to store base under conversion */
4747+4848+#line 0 check_for_three()
4949+static char *check_for_three(ptr,tptr)
5050+char *ptr,*tptr;
5151+{
5252+int l;
5353+5454+ /* if length of exponent is 3 or more then return */
5555+5656+ if ((l =len_of_str(ptr))>2) return(tptr);
5757+5858+ /* This implementation normally makes the exponent 3 bytes wide */
5959+6060+ *tptr++ = '0'; /* make default width = 2 */
6161+6262+ /* if 2 byte default width is desired then comment out the
6363+ following line of code */
6464+6565+ if (l == 1) *tptr++ = '0'; /* make default width = 3 */
6666+6767+ return(tptr);
6868+}
6969+7070+#line 0 dumpbuffer()
7171+static void dumpbuffer(tbufptr) /* write buffer to output stream */
7272+register char *tbufptr;
7373+{
7474+register void (*outputx)() = _output;
7575+7676+ if (*tbufptr == '@') tbufptr++;
7777+7878+ while (*tbufptr)
7979+ (*outputx)(*tbufptr++);
8080+8181+}
8282+8383+#line 0 dopadding()
8484+static void dopadding(tempbuffer,left_justify,zero_fill,width)
8585+register char *tempbuffer;
8686+register Boolean left_justify,zero_fill;
8787+register int width;
8888+{
8989+register int length;
9090+register void (*outputx)() = _output;
9191+9292+ if ((length = len_of_str(tempbuffer))<width)
9393+ {
9494+ width -= length;
9595+ if (left_justify == false)
9696+ {
9797+ if ((*tempbuffer == ' ')||
9898+ (((*tempbuffer == '+')||(*tempbuffer == '-'))&&zero_fill) )
9999+ {
100100+ (*outputx)(*tempbuffer);
101101+102102+ *tempbuffer = '@';
103103+ }
104104+105105+ while (--width >= 0)
106106+ (*outputx)(zero_fill?'0':' ');
107107+108108+ dumpbuffer(tempbuffer);
109109+ }
110110+ else
111111+ {
112112+ dumpbuffer(tempbuffer);
113113+114114+ while (--width >= 0)
115115+ (*outputx)(' ');
116116+ }
117117+ }
118118+ else /* pdg - 7/23/86 missing else! */
119119+ dumpbuffer(tempbuffer);
120120+}
121121+122122+/* pdg - 6/10/86 - revise for efficiency */
123123+124124+#line 0 len_of_str()
125125+static int len_of_str(s)
126126+register char *s;
127127+{
128128+register char *s0 = s;
129129+130130+ while (*s) s++;
131131+132132+ return(s-s0);
133133+}
134134+135135+#line 0 padd()
136136+static void padd(zero_fill,count)
137137+Boolean zero_fill;
138138+register int count;
139139+{
140140+ while (--count >= 0)
141141+ (*_output)(((zero_fill)?'0':' '));
142142+}
143143+144144+145145+#line 0 output_number()
146146+static void output_number(value)
147147+unsigned long value;
148148+{
149149+unsigned long quotient;
150150+register int remainder;
151151+152152+ if ((quotient = value / base) != 0) output_number(quotient);
153153+154154+ remainder = (value % base);
155155+156156+ (*_output)(((remainder<10) ? remainder + '0' :
157157+ remainder + _hex_case));
158158+}
159159+160160+#line 0 length of number()
161161+static int length_of_number(number)
162162+register unsigned long number;
163163+{
164164+register int places = 1;
165165+166166+ while (number /= base) places++;
167167+168168+ return (places);
169169+}
170170+171171+#ifdef _FORMAT_FP_
172172+173173+char *PtoCstr(); /* need proper typing of return value */
174174+175175+#line 0 cvtf2string()
176176+static char *cvtf2string(doublep, style, digits, floatbufferp)
177177+double *doublep;
178178+char style;
179179+short digits;
180180+char *floatbufferp;
181181+{
182182+DecForm _decform_; /* information record for conversion */
183183+Decimal _decimal_; /* intermediate record */
184184+185185+ /* convert binary to decimal record */
186186+187187+ _decform_.style = style;
188188+ _decform_.digits = digits;
189189+190190+ fp68k(&_decform_, doublep, &_decimal_, FFEXT+FOB2D);
191191+192192+ /* decimal record to string */
193193+194194+ _decform_.style= style;
195195+ _decform_.digits = digits;
196196+197197+ Dec2Str(_decform_, &_decimal_, floatbufferp);
198198+199199+ /* convert to C string from Pascal string used by SANE */
200200+201201+ return (PtoCstr(floatbufferp));
202202+}
203203+204204+#endif _FORMAT_FP_
205205+206206+207207+#line 0 _format()
208208+/*----------------------------------------------------------------------------
209209+ "_format" is the internal routine to do the conversion process. This routine
210210+ is passed a pointer to the pointer to the format string. By scanning the
211211+ format string until a format code is encountered, information can be extrac-
212212+ ted to determine the what argument was present on the stack and processing
213213+ can be handled. Note that the following stack layout applies after the call
214214+ to _format (standard C calling conventions):
215215+216216+ HI memory
217217+ |---------------------|
218218+ | last argument | last argument for format
219219+ |---------------------|
220220+ .
221221+ .
222222+ |---------------------|
223223+ |--->---| first argument | points to format string
224224+ | |---------------------|
225225+ | | return address |
226226+ | |---------------------|
227227+ |---<---| argument to _format | points to pointer to format
228228+ |---------------------|
229229+ | return address |
230230+ |---------------------|
231231+ LO memory
232232+233233+ The _format routine sets "format" to point to the format string and scans
234234+ over it. By incrementing the parameter "ptr" (passed to _format) the
235235+ first argument for substitution in the format string can be accessed.
236236+ How the arguments are interpreted is derived from the format string.
237237+ A pointer to a function "*_output" is used to stuff processed characters
238238+ to their destination.
239239+240240+-----------------------------------------------------------------------------*/
241241+int _format(fmt,var_stuff)
242242+char **fmt; /* pointer to pointer to format string */
243243+Boolean var_stuff;
244244+{
245245+Boolean left_justify; /* flag to indicate left justiccation */
246246+Boolean do_precision; /* flag limited precision */
247247+Boolean its_a_long; /* flag to indicate long integer */
248248+Boolean zero_fill; /* flag to indicate padding with zero */
249249+Boolean sign_on; /* flag to indicate '+' */
250250+Boolean space_on; /* flag to indicate ' ' */
251251+Boolean pound_on; /* flag to indicate '#' */
252252+Boolean neg; /* flag to indicate a negative number */
253253+254254+register char *format; /* pointer to format string */
255255+register char *argument; /* pointer to arguments for fmt string */
256256+257257+#ifdef _FORMAT_FP
258258+#define outputx _output
259259+#else
260260+register void (*outputx)() = _output;
261261+#endif
262262+263263+register char c; /* current character under inspection */
264264+unsigned long value; /* for conversion of numerics */
265265+register int length; /* length of argument to be inserted */
266266+register int width; /* field width as specified by format */
267267+register int numleft; /* # of characters left to print */
268268+register int precision; /* precision of number to be converted */
269269+270270+#ifdef _FORMAT_FP_
271271+272272+/* floating point junk */
273273+double tempdouble;
274274+char floatbuffer[256];
275275+char tempbuffer[256];
276276+register char *bufptr;
277277+register char *tbufptr;
278278+279279+#endif _FORMAT_FP_
280280+281281+ /* set up the direct error return to caller */
282282+283283+ if (setjmp(env)) return (EOF);
284284+285285+ _num_count = 0; /* set # characters transmitted to zero */
286286+287287+ format = *fmt++; /* set "format" to the format string */
288288+ /* "fmt" is left pointing to first argument */
289289+ argument = (char *) fmt; /* set "argument" to point to first argument */
290290+291291+ /* if variable, indirect through first argument to find real arg list */
292292+293293+ if (var_stuff) argument = (char *)(*(long *)argument);
294294+295295+ while (c = *format++) /* scan format string until NULL */
296296+ {
297297+ if (c == '%')
298298+ {
299299+ left_justify = false;
300300+ zero_fill = false;
301301+ sign_on = false;
302302+ space_on = false;
303303+ pound_on = false;
304304+ neg = false;
305305+flagloop:
306306+ switch(c = *format++)
307307+ {
308308+ case '-': left_justify = true;
309309+ zero_fill = false;
310310+ goto flagloop;
311311+312312+ case '0': zero_fill = (!left_justify);
313313+ goto flagloop;
314314+315315+ case '+': sign_on = true;
316316+ space_on = false;
317317+ goto flagloop;
318318+319319+ case ' ': space_on = (!sign_on);
320320+ goto flagloop;
321321+322322+ case '#': pound_on = true;
323323+ goto flagloop;
324324+325325+ case '*': numleft = width = *(int *)argument;
326326+ argument += sizeof(int);
327327+ goto getdot;
328328+329329+ default: format--; /* need to back up if unrecognized */
330330+ break;
331331+ }
332332+333333+334334+ /* compute total field width */
335335+336336+ {char *tempformat = format; /* let format be register */
337337+338338+ numleft = width = (isdigit(*format)) ? _std_decode(&tempformat) : 0;
339339+ format = tempformat;
340340+ }
341341+342342+getdot:
343343+ /* compute precision within total field width */
344344+345345+ precision = 0;
346346+347347+ if (do_precision = (*format == '.'))
348348+ {
349349+ if (*++format == '*')
350350+ {
351351+ precision = *(int *)argument;
352352+ argument += sizeof(int);
353353+ format++;
354354+ }
355355+ else
356356+ {char *tempformat = format; /* let format be register */
357357+358358+ precision = _std_decode(&tempformat);
359359+ format = tempformat;
360360+ }
361361+ }
362362+363363+ if (*format == '%')
364364+ {
365365+ if (left_justify)
366366+ {
367367+ (*outputx)('%');
368368+ padd(BLANKS,width-1);
369369+ }
370370+ else
371371+ {
372372+ padd(zero_fill,width-1);
373373+ (*outputx)('%');
374374+ }
375375+ format++;
376376+ continue;
377377+ }
378378+379379+ /* check if long integer is required */
380380+381381+ if (its_a_long = ((c = (*format++)) == 'l'))
382382+ c = *format++;
383383+384384+ /* check for short %h.. */
385385+386386+ if (c == 'h') c = *format++;
387387+388388+ /* note that "format" is left ready for the next pass */
389389+ switch (c)
390390+ {
391391+392392+ case 'd':
393393+ {register long svaluel; /* for conversion of signed long */
394394+ register int svaluei; /* for conversion of signed int */
395395+396396+ if (its_a_long)
397397+ {
398398+ svaluel = *(long *)argument;
399399+ argument += sizeof(long);
400400+401401+ value = (unsigned long)svaluel;
402402+403403+ if (svaluel < 0) goto negate;
404404+ }
405405+ else
406406+ {
407407+ svaluei = *(int *)argument;
408408+ argument += sizeof(int);
409409+410410+ value = (unsigned long)svaluei;
411411+412412+ if (svaluei < 0)
413413+ {
414414+negate: neg = true;
415415+ value = -value;
416416+ }
417417+ }
418418+419419+ /* fall into case 'u' */
420420+ }
421421+422422+ case 'u':
423423+ base = 10;
424424+ goto evaluate;
425425+426426+ case 'o':
427427+ base = 8;
428428+ goto evaluate;
429429+430430+ case 'x': _hex_case = 'a'-10;
431431+ goto sethex;
432432+ case 'X':
433433+ _hex_case = 'A'-10;
434434+sethex:
435435+ base = 16;
436436+evaluate:
437437+ /* get the target value in a long,
438438+ readjust the argument pointer */
439439+440440+ if (c != 'd')
441441+ {
442442+ if (its_a_long)
443443+ {
444444+ value = *(unsigned long *)argument;
445445+ argument += sizeof (unsigned long);
446446+ }
447447+ else
448448+ {
449449+ value = *(unsigned *)argument;
450450+ argument += sizeof (unsigned);
451451+ }
452452+ }
453453+454454+ /* get the length of the output string */
455455+456456+ length = length_of_number(value);
457457+458458+ /* now figure out the positioning */
459459+460460+ if (zero_fill)
461461+ {
462462+ if (((neg)||(sign_on)||
463463+ (space_on)) && (c =='d'))
464464+ {
465465+ if (neg)
466466+ {
467467+ (*outputx)('-');
468468+ }
469469+ else
470470+ (*outputx)((sign_on ? '+' : ' '));
471471+472472+ numleft--; /* room for sign */
473473+ }
474474+475475+ if (((c=='o')||(c == 'X')||(c == 'x'))&&(pound_on))
476476+ {
477477+ (*outputx)('0');
478478+ numleft--;
479479+480480+ if (c == 'X') { (*outputx)('X');numleft--; }
481481+ if (c == 'x') { (*outputx)('x');numleft--; }
482482+ }
483483+484484+ padd(zero_fill, numleft - max(length,precision));
485485+486486+ if (precision > length)
487487+ padd(zero_fill,precision-length);
488488+489489+ output_number(value);
490490+491491+ }
492492+493493+ if (left_justify)
494494+ {
495495+ if (c =='d')
496496+ {
497497+ if (neg)
498498+ {
499499+ (*outputx)('-');
500500+ numleft--;
501501+ }
502502+ else
503503+ if((sign_on)||(space_on))
504504+ {
505505+ (*outputx)((sign_on ? '+' : ' '));
506506+507507+ numleft--;
508508+ }
509509+ }
510510+511511+ if (((c=='o')||(c == 'X')||(c == 'x'))&&(pound_on))
512512+ {
513513+ (*outputx)('0');
514514+515515+ numleft--;
516516+517517+ if (c == 'X') { (*outputx)('X');numleft--; }
518518+ if (c == 'x') { (*outputx)('x');numleft--; }
519519+ }
520520+521521+ padd(true,precision-length);
522522+523523+ if(precision-length>0) numleft -= (precision-length);
524524+525525+ output_number(value);
526526+527527+ numleft -= length;
528528+529529+ padd(BLANKS, numleft);
530530+531531+ }
532532+533533+ if ((!zero_fill)&&(!left_justify))
534534+ {
535535+ if (((neg)||(space_on)||
536536+ (sign_on)) && (c == 'd'))
537537+ {
538538+ padd(zero_fill, width - max(length,precision)-1);
539539+540540+ if (neg)
541541+ {
542542+ (*outputx)('-');
543543+ }
544544+ else
545545+ (*outputx)(((sign_on)?'+':' '));
546546+547547+ padd(true,precision-length);
548548+549549+ output_number(value);
550550+551551+ } /* normal decimal output with sign */
552552+ else
553553+ if ((pound_on)&&((c == 'o')||(c == 'X')||(c == 'x')))
554554+ {
555555+ numleft = 2;
556556+ if ( c == 'o') numleft = 1;
557557+ padd(zero_fill, width - max(length,precision)-numleft);
558558+559559+ (*outputx)('0');
560560+561561+ if (c == 'X') (*outputx)('X');
562562+ if (c == 'x') (*outputx)('x');
563563+564564+ padd(true,precision-length);
565565+566566+ output_number(value);
567567+ }
568568+ else
569569+ {
570570+ padd(zero_fill, width - max(precision,length));
571571+ padd(!zero_fill,precision-length);
572572+ output_number(value);
573573+ }
574574+ } /* ((!zero_fill)&&(!left_justify)) */
575575+ break;
576576+577577+ case 'c':
578578+ /* get the character and readjust the pointer
579579+ note that a char on the stack is expanded to int */
580580+581581+ if (left_justify)
582582+ {
583583+ (*outputx)(*(int *) argument);
584584+ padd(BLANKS, width - 1);
585585+ }
586586+ else
587587+ {
588588+ padd(zero_fill, width - 1);
589589+ (*outputx)(*(int *) argument);
590590+ }
591591+ argument += sizeof (int);
592592+ break;
593593+594594+ case 's':
595595+ {register char *char_ptr;
596596+597597+ /* get the length of the string */
598598+599599+ length = len_of_str(char_ptr = *((char **) argument));
600600+ argument += sizeof(char_ptr);
601601+602602+ /* check for truncation */
603603+ if (do_precision)
604604+ if (length > precision) length = precision;
605605+606606+ /* set width to padding width */
607607+ if ((width -= length) < 0) width = 0;
608608+609609+ if (left_justify)
610610+ {
611611+ while (--length >= 0)
612612+ (*outputx)(*char_ptr++);
613613+614614+ padd(BLANKS, width);
615615+ }
616616+ else
617617+ {
618618+ padd(zero_fill, width);
619619+ while (--length >= 0)
620620+ (*outputx)(*char_ptr++);
621621+ }
622622+ break;
623623+ }
624624+625625+#ifdef _FORMAT_FP_
626626+627627+ case 'f':
628628+ tempdouble = *((double *)argument); /* consume argument */
629629+ argument += sizeof(double);
630630+631631+632632+ /* default precision is 6 */
633633+ if (do_precision == false) precision = 6;
634634+regf:
635635+ bufptr = cvtf2string(&tempdouble, 1, precision, floatbuffer);
636636+nregf:
637637+ tbufptr = tempbuffer;
638638+639639+ if ((tempdouble >= 0)&&((space_on)||
640640+ (sign_on)))
641641+ *tbufptr++ = (sign_on ? '+' : ' ');
642642+643643+ while(c = *(bufptr++))
644644+ *tbufptr++ = c;
645645+646646+ if ((pound_on)&&(precision == 0))
647647+ *tbufptr++ = '.';
648648+649649+ *tbufptr = '\0';
650650+651651+ dopadding(tempbuffer,left_justify,zero_fill,width);
652652+653653+ break;
654654+655655+ case 'e':
656656+ case 'E':
657657+ tempdouble = *((double *)argument); /* consume argument */
658658+ argument += sizeof(double);
659659+660660+ /* default precision is 6 */
661661+ if (do_precision == false) precision = 6;
662662+663663+ bufptr = cvtf2string(&tempdouble, 0, precision+1, floatbuffer);
664664+665665+rege:
666666+ tbufptr = tempbuffer;
667667+668668+ if ((tempdouble >= 0)&&(sign_on)) /* if + then make prefix */
669669+ *bufptr = '+';
670670+671671+ if ((space_on == false)&&(*bufptr == ' '))
672672+ bufptr++; /* if leading space and no flag fix it */
673673+674674+ while(*(bufptr))
675675+ {
676676+ if (*bufptr == 'e') /* is this the e char? */
677677+ {
678678+ neg = true;
679679+ *bufptr = c; /* convert if if necessary */
680680+ if ((pound_on)&&(precision == 0))
681681+ *tbufptr++ = '.';
682682+ }
683683+ if ((*(bufptr-2) == c)&&(neg)) /* should we pad the exp */
684684+ tbufptr = check_for_three(bufptr,tbufptr);
685685+ if (*bufptr != '@')
686686+ *tbufptr++ = *bufptr++;
687687+ }
688688+ *tbufptr = '\0';
689689+690690+ dopadding(tempbuffer,left_justify,zero_fill,width);
691691+692692+ break;
693693+694694+ case 'g':
695695+ case 'G':
696696+ tempdouble = *((double *)argument); /* consume argument */
697697+ argument += sizeof(double);
698698+699699+ if (precision < 1) precision = 1;
700700+701701+ if (do_precision == false) precision = 6;
702702+703703+704704+ /* convert to e form */
705705+706706+ bufptr = cvtf2string(&tempdouble, 0, precision, floatbuffer);
707707+708708+ /* look at char after 'e' */
709709+710710+ while (*bufptr++ != 'e')
711711+ ;
712712+ neg = (*bufptr++ == '-'); /* is it a negative exponent */
713713+ tbufptr = bufptr;
714714+715715+ /* get size of exponent */
716716+717717+ length = _std_decode(&tbufptr);
718718+ if (neg) length *= -1;
719719+720720+ if (pound_on) /* if # flag is on and ... */
721721+ {
722722+ if ((length<=precision)&&(length>=-4))
723723+ goto regf; /* do regular f routine */
724724+ else
725725+ {
726726+ /* this gives precision-1 digits after
727727+ . instead of precision */
728728+729729+ bufptr = (char *)floatbuffer;
730730+ c -= 2;
731731+ goto rege; /* do regular e routine */
732732+ }
733733+ }
734734+735735+736736+ if ((length<=precision)&&(length>=-4))
737737+ {register Boolean strip_it = false;
738738+739739+ /* convert to f format */
740740+741741+ bufptr = cvtf2string(&tempdouble, 1, precision-length, floatbuffer);
742742+743743+ /* don't strip string unless therre is a . */
744744+ while (*bufptr)
745745+ {
746746+ strip_it = strip_it?true:(*bufptr == '.');
747747+ bufptr++;
748748+ }
749749+ bufptr -= 1; /* was 2 */
750750+751751+ /* strip trailing zeros */
752752+ if (strip_it)
753753+ {
754754+ while (*bufptr == '0') bufptr--;
755755+ if (*bufptr == '.') bufptr--;
756756+ *(++bufptr) = '\0';
757757+ }
758758+759759+ bufptr = (char *)floatbuffer;
760760+761761+ /* now test for \0 or -\0 and adjust */
762762+ if ((*bufptr == '\0') ||
763763+ ((*bufptr=='-')&&(*(bufptr+1)=='\0')))
764764+ {
765765+ *bufptr = '0';
766766+ *(bufptr+1) = '\0';
767767+ }
768768+769769+ goto nregf;
770770+771771+ break;
772772+ }
773773+774774+775775+ /* back up before the e and strip trailing zeros */
776776+777777+ bufptr -= 3;
778778+779779+ while ((*bufptr == '0')||(*bufptr == '.'))
780780+ *(bufptr--) = '@';
781781+782782+ /* bufptr = (char *)floatbuffer;
783783+ c -= 2; / convert form g to e, G to E /
784784+ goto rege;
785785+ */
786786+787787+ if ((space_on == false)&&(floatbuffer[0] == ' '))
788788+ floatbuffer[0] = '@';
789789+790790+ if ((tempdouble>=0) && (sign_on)) floatbuffer[0] = '+';
791791+792792+ tbufptr = (char *)tempbuffer;
793793+ bufptr = (char *)floatbuffer;
794794+795795+ while (*bufptr != 'e')
796796+ if (*bufptr != '@')
797797+ *tbufptr++ = *bufptr++;
798798+ else
799799+ bufptr++;
800800+801801+ *bufptr = c-2; /* convert G to E, g to e */
802802+ *tbufptr++ = *bufptr++;
803803+ *tbufptr++ = *bufptr++;
804804+ tbufptr = check_for_three(bufptr,tbufptr);
805805+ while (*bufptr)
806806+ *tbufptr++ = *bufptr++;
807807+ *tbufptr = '\0';
808808+ dopadding(tempbuffer,left_justify,zero_fill,width);
809809+810810+ break;
811811+#endif _FORMAT_FP_
812812+813813+ default:
814814+ /* input garbled, bark: arf arf */
815815+ return (EOF);
816816+817817+ } /* end of switch */
818818+ } /* end of if */
819819+ else
820820+ /* copy it directly to output */
821821+822822+ (*outputx)(c);
823823+824824+ } /* end of while */
825825+826826+ return(_num_count);
827827+828828+ (void) std_ver();
829829+830830+}
+77
sources/printf-4.c
···11+/*
22+ printf routines for LightspeedC�
33+44+ (C) Copyright 1986. THINK Technologies, Inc. All rights reserved.
55+66+ allows echoing the output of console window to printer
77+88+*/
99+1010+#ifndef _stdioh_
1111+#include "stdio.h"
1212+#endif
1313+1414+#ifndef _MacTypes_
1515+#include "MacTypes.h"
1616+#endif
1717+1818+1919+/* some less than famous Mac globals */
2020+2121+#define SPPrint (*((char*) 0x207))
2222+#define PortBUse (*((char*) 0x291))
2323+2424+void (*_echo_to_printer_)() = 0; /* global Echo call variable for printer */
2525+2626+static FILE *printfile;
2727+2828+static void send_printer(c)
2929+char c;
3030+{
3131+ fputc(c, printfile);
3232+}
3333+3434+int Echo_to_Printer(wantecho)
3535+Boolean wantecho;
3636+{
3737+register char *p;
3838+3939+ /* printer mode may already be set up to be what they want */
4040+4141+ if (_echo_to_printer_ && wantecho) return (0);
4242+4343+ if (wantecho)
4444+ {
4545+ /* activate printer copying from console */
4646+4747+ /* if printer port number is non-zero, port A is implied */
4848+4949+ if (SPPrint) p = ".AOut";
5050+ else
5151+ /* well, check to see if port B is in use by AppleTalk,
5252+ indicated by a greater than zero value */
5353+5454+ if (PortBUse < 0) p = ".BOut";
5555+ else
5656+ /* ran out of ports to check */
5757+ return (EOF);
5858+5959+ /* set to binary mode if we are opening a device driver,
6060+ so output directed to a printer gets proper linefeeds */
6161+6262+ if (!(printfile = fopen(p, "wb"))) return (EOF);
6363+6464+ _echo_to_printer_ = send_printer;
6565+ }
6666+ else
6767+ {
6868+ /* deactivate printer copying from console */
6969+7070+ _echo_to_printer_ = 0;
7171+7272+ fclose(printfile);
7373+ }
7474+7575+ return (0);
7676+}
7777+
+351
sources/profile.c
···11+/*
22+33+ Profile and tracing package for LightspeedC�.
44+55+ (C) Copyright 1986 THINK Technologies, Inc. All rights reserved.
66+77+ */
88+99+1010+#include "stdio.h"
1111+1212+1313+typedef unsigned char Bool; /* for size */
1414+enum{false,true};
1515+1616+typedef void (*address)(); /* address type */
1717+typedef unsigned char byte;
1818+typedef unsigned long time;
1919+2020+typedef struct {
2121+ char *name; /* function name */
2222+ time average; /* average time */
2323+ time maximum; /* largest time */
2424+ time minimum; /* smallest time */
2525+ time total; /* total time */
2626+ unsigned int entries; /* times entered */
2727+ } PROFILE;
2828+2929+typedef struct {
3030+ address user; /* user return address */
3131+ int function; /* index into profiles */
3232+ time correction; /* nested call time */
3333+ time start; /* entry time */
3434+ } STACK;
3535+3636+#define LOCAL static /* local to profiler */
3737+#define MAX_PROFILES 200 /* routines to follow */
3838+#define MAX_STACK 200 /* max nested calls */
3939+#define MAX_TIME 500000L /* max time */
4040+4141+4242+/*
4343+4444+ Select execution/compilation options.
4545+4646+ SINGLE - each routine contains only its time
4747+ TESTING - test profile package without LightspeedC PROFILE option
4848+4949+ */
5050+5151+#define SINGLE /* single routine only */
5252+/* #define TESTING standalone testing */
5353+5454+5555+#ifdef TESTING
5656+#undef LOCAL /* make items visible */
5757+#define LOCAL
5858+#endif
5959+6060+6161+6262+LOCAL int depth = -1;
6363+LOCAL PROFILE profiles[MAX_PROFILES];
6464+LOCAL int profile_count = 0;
6565+LOCAL STACK stack[MAX_STACK];
6666+LOCAL int stack_pointer = -1;
6767+LOCAL time start_time;
6868+6969+int _profile = 1;
7070+int _trace = 0;
7171+7272+void DumpProfile();
7373+extern _profile_exit_();
7474+extern char *CtoPstr();
7575+extern char *PtoCstr();
7676+7777+#define _VIATIMER_ /* if this symbol is defined, the VIA timer now is used
7878+ instead of TickCount -- it provides faster ticks,
7979+ however there is a false precision to the numbers
8080+ and there is a range of + or - 500 ticks since
8181+ the VIAtimer is so fast that interrupts and such
8282+ play a more significant time role.
8383+8484+ NOTE THAT THIS PROFILE OPTION CANNOT BE USED WITH
8585+ ANY PROGRAM THAT MANIPULATES THE #1 VIA timer */
8686+8787+8888+#ifdef _VIATIMER_
8989+9090+/* TickCount() - redefine TickCount trap to be a procedure for determining
9191+ the timing according to the VIA timer */
9292+9393+#define VIAbase (*((unsigned char**)0x01D4))
9494+#define VIAt1lo (*(VIAbase+512*4))
9595+#define VIAt1hi (*(VIAbase+512*5))
9696+#define VIAmaxtime ~0
9797+9898+time TickCount()
9999+{
100100+static time timer=0;
101101+102102+ if (timer > 0)
103103+ {
104104+ /* Use VIA timer #1 (sound driver) and to implement a fine
105105+ resolution counter */
106106+107107+ /* Find delta of VIA #1 */
108108+109109+ timer += VIAmaxtime - (((unsigned short)VIAt1hi<<8)+VIAt1lo);
110110+ }
111111+ else
112112+ timer = 1;
113113+114114+ /* Reset VIA counter */
115115+116116+ VIAt1hi = VIAmaxtime;
117117+ VIAt1lo = VIAmaxtime;
118118+119119+ return (timer);
120120+}
121121+122122+#endif _VIATIMER_
123123+124124+125125+/*
126126+127127+ Compare two Pascal strings for equality.
128128+129129+ */
130130+131131+LOCAL Bool pstreq( s1, s2 )
132132+register unsigned char *s1, *s2;
133133+{
134134+ register int n = *s1;
135135+136136+ if ((n = *s1++) != *s2++)
137137+ return( false );
138138+ while (n-- > 0)
139139+ if (*s1++ != *s2++)
140140+ return( false );
141141+ return( true );
142142+}
143143+144144+145145+/*
146146+147147+ Return the time difference caused by the overhead of function entry and
148148+ timer call.
149149+150150+ */
151151+152152+LOCAL time delta( original )
153153+time original;
154154+{
155155+ return( (time) TickCount() - original );
156156+}
157157+158158+159159+/*
160160+161161+ Lookup a name in the active profile table. For this system, "names" are
162162+ the address of the routine. If the name is found in the table, then the
163163+ index to the table entry is returned. If the name is not found and the
164164+ insert flag is on, then the item is inserted, and the new table index
165165+ is returned (if insert is false, then -1 is returned). If the profile
166166+ table is full, then -1 is returned.
167167+168168+ */
169169+170170+LOCAL int lookup( name, insert )
171171+char *name;
172172+Bool insert;
173173+{
174174+ register int i;
175175+176176+ for (i = 0; i < profile_count; i++)
177177+ if (pstreq( profiles[i].name, name ))
178178+ return( i );
179179+ if ( insert && profile_count < MAX_PROFILES)
180180+ { /* place in table - i points to correct entry */
181181+ if (++profile_count == 1)
182182+ { /* first time in */
183183+ start_time = (time) TickCount();
184184+ onexit( DumpProfile );
185185+ }
186186+ profiles[i].name = name;
187187+ profiles[i].minimum = MAX_TIME;
188188+ profiles[i].maximum =
189189+ profiles[i].total = NULL;
190190+ profiles[i].entries = 0;
191191+ return( i );
192192+ }
193193+ return( -1 );
194194+}
195195+196196+197197+/*
198198+199199+ Skip over to column 32 from position 'n'.
200200+201201+ */
202202+203203+LOCAL void Skip( n )
204204+register int n;
205205+{
206206+ for (; n < 32; n++)
207207+ putchar( ' ' );
208208+}
209209+210210+211211+/*
212212+213213+ Print the profile table on demand. Output is written to stdout and may
214214+ be redirected with the Unix '>' mechanism to a file. The user should
215215+ call this routine whenever a report is desired. Each time the routine is
216216+ called, the program opens the map file which corresponds to the program
217217+ running. The name of the map file is built by appending ".map" to the name
218218+ of the running program. If the map file cannot be found then the routine
219219+ returns.
220220+221221+ */
222222+223223+void DumpProfile()
224224+{
225225+ int j, k; /* generic loop variables */
226226+ register int i; /* primary loop variable */
227227+ register time duration = 0L; /* time in test regions */
228228+229229+ _profile = 0; /* turn off profiling here */
230230+231231+ for (i = 0; i < profile_count; i++)
232232+ duration += profiles[i].total; /* compute total time */
233233+234234+ printf( "\n\n" );
235235+ printf( "\t\t\t\tRoutine Profiles\n\n" );
236236+ printf( "Routine Address" );
237237+ Skip( 15 );
238238+ printf( " Minimum Maximum Average %% Entries\n" );
239239+240240+ if (duration <= 0.0)
241241+ duration++;
242242+243243+ for (i = 0; i < profile_count; i++)
244244+ { /* for all entries in the profile table */
245245+ if (profiles[i].minimum == MAX_TIME)
246246+ continue; /* routine entry, no exit */
247247+ printf( "%s", PtoCstr( profiles[i].name ) );
248248+ CtoPstr( profiles[i].name );
249249+ Skip( profiles[i].name[0] );
250250+ printf( "%9lu %9lu %9lu %3.0f %7u\n",
251251+ profiles[i].minimum, profiles[i].maximum,
252252+ profiles[i].average,
253253+ ((float) profiles[i].total * 100.0) / (float) duration + 0.05,
254254+ profiles[i].entries );
255255+ }
256256+257257+ _profile = 1; /* re-enable profiling */
258258+}
259259+260260+261261+/*
262262+263263+ Called by assembler exit routine. Compute usage statistics for routine on
264264+ top of profiling stack.
265265+266266+ */
267267+268268+address __profile_exit()
269269+{
270270+ int i;
271271+ time exit_time = (time) TickCount();
272272+273273+ depth--;
274274+ /* end timing for a function */
275275+276276+ i = stack[stack_pointer].function;
277277+#ifdef SINGLE
278278+ exit_time = exit_time - delta( exit_time ) -
279279+ stack[stack_pointer].start - stack[stack_pointer--].correction;
280280+ if (exit_time > 0x7FFFFFFF)
281281+ exit_time = 0L; /* handle clock rollover */
282282+ profiles[i].total += exit_time;
283283+ if (stack_pointer >= 0)
284284+ stack[stack_pointer].correction += exit_time + stack[stack_pointer + 1].correction;
285285+#else
286286+ exit_time = exit_time - delta( exit_time ) - stack[stack_pointer--].start;
287287+ if (exit_time > 0x7FFFFFFF)
288288+ exit_time = 0L; /* handle clock rollover */
289289+ profiles[i].total += exit_time;
290290+#endif
291291+ if (exit_time > profiles[i].maximum)
292292+ profiles[i].maximum = exit_time;
293293+ if (exit_time < profiles[i].minimum)
294294+ profiles[i].minimum = exit_time;
295295+ if (profiles[i].entries)
296296+ profiles[i].average = profiles[i].total / profiles[i].entries;
297297+ return( stack[stack_pointer + 1].user );
298298+}
299299+300300+301301+/*
302302+303303+ Handle the routine entry profiling. Setup a stack frame and a profile
304304+ table entry if needed.
305305+306306+ */
307307+308308+void __profile( unused, ret, name )
309309+unsigned long *ret;
310310+address unused;
311311+char *name;
312312+{
313313+ register int function, /* index of routine */
314314+ i;
315315+ register time entry_time = (time) TickCount();
316316+317317+ depth++;
318318+ if (_trace)
319319+ {
320320+ _profile = 0;
321321+ for (i = 0; i < depth; i++)
322322+ putchar( ' ' );
323323+ printf( "%s\n", PtoCstr( name ) );
324324+ CtoPstr( name );
325325+ _profile = 1;
326326+ }
327327+ if (++stack_pointer < MAX_STACK)
328328+ { /* setup for return to PROFILE_EXIT on user exit */
329329+ stack[stack_pointer].user = (address) *ret;
330330+ *ret = (unsigned long) _profile_exit_;
331331+ stack[stack_pointer].correction = NULL;
332332+ }
333333+ else
334334+ {
335335+ depth--;
336336+ return;
337337+ }
338338+339339+ if ((function = lookup( name, true )) >= 0)
340340+ { /* process function entry */
341341+ profiles[function].entries++;
342342+ stack[stack_pointer].function = function;
343343+ entry_time = TickCount();
344344+ stack[stack_pointer].start = entry_time - delta( entry_time );
345345+ }
346346+ else
347347+ { /* remove entry from stack */
348348+ *ret = (unsigned long) stack[stack_pointer--].user;
349349+ depth--;
350350+ }
351351+}
+49
sources/profilehooks.c
···11+/*
22+33+ Profile and tracing package for LightspeedC�.
44+55+ (C) Copyright 1986 THINK Technologies, Inc. All rights reserved.
66+77+*/
88+99+extern void __profile();
1010+extern void __profile_exit();
1111+1212+/*
1313+;
1414+; Entry point for profiler. Add another parameter to the stack which is
1515+; a pointer to the return address of the caller of this function.
1616+;
1717+*/
1818+_profile_()
1919+{
2020+2121+ asm
2222+ {
2323+ move.l (a7)+,d0 ; get current return address
2424+ pea 4(a6) ; push pointer to return address
2525+ move.l d0,-(a7) ; push back the return address
2626+ jsr __profile ; call the C profiler
2727+ move.l (a7)+,d0 ; get return address
2828+ move.l d0,(a7) ; write on top of stack and return
2929+ }
3030+}
3131+3232+/*
3333+;
3434+; Exit point for profiler. This calls the end of function timing routine
3535+; and returns to the user.
3636+;
3737+*/
3838+3939+_profile_exit_()
4040+{
4141+ asm
4242+ {
4343+ move.l d0, -(a7) ; save old function result
4444+ jsr __profile_exit ; call end of routine timer
4545+ move.l d0, a0 ; save return address in A0
4646+ move.l (a7)+, d0 ; retrieve old function result
4747+ jmp (a0) ; then return
4848+ }
4949+}
+277
sources/proto.h
···11+/* LightspeedC function prototype header file.
22+33+Copyright (c)1986. THINK Technologies, Inc. All rights reserved.
44+55+66+This file contains the function prototypes for all (hopefully) of the
77+published LightspeedC library functions. It can be dissected into
88+whatever pieces are desired or it can simply be included (at some extra
99+cost in time to compile and symbol table overhead).
1010+1111+Since the original header files have not been modified, they can still be
1212+included in conjunction with this prototype header, if desired. That
1313+means that you could still include "math.h" for its definition of PI and
1414+such and follow that with an include of this file.
1515+1616+The prototypes are presented here in no particular order, however, they are
1717+grouped by originating library.
1818+1919+*/
2020+2121+#ifndef _fopenwh_
2222+#include "fopenw.h"
2323+#endif
2424+2525+#ifndef _EventMgr_
2626+#include "EventMgr.h"
2727+#endif
2828+2929+3030+/* math.h */
3131+3232+int abs(int x);
3333+double acos(double x);
3434+double asin(double x);
3535+double atan(double x);
3636+double atan2(double y, double x);
3737+double ceil(double x);
3838+double cos(double x);
3939+double cosh(double x);
4040+double exp(double x);
4141+double fabs(double x);
4242+double floor(double x);
4343+double fmod(double x, double y);
4444+double frexp(double x, int *nptr);
4545+long int labs(long int x);
4646+double ldexp(double x, int n);
4747+double log(double x);
4848+double log10(double x);
4949+double modf(double x,int *nptr);
5050+double pow(double x, double y);
5151+int rand(void);
5252+double sin(double x);
5353+double sinh(double x);
5454+double sqrt(double x);
5555+void srand(unsigned int seed);
5656+double tan(double x);
5757+double tanh(double x);
5858+5959+/* strings.h */
6060+6161+int stccpy(char *s1, char *s2, int n);
6262+int stcis(char *s, char *set);
6363+int stcisn(char *s1, char *set);
6464+int stclen(char *s);
6565+char *stpblk(char *p);
6666+char *stpbrk(char *s, char *set);
6767+char *stpchr(char *s, char c);
6868+char *stpcpy(char *s1, char *s2);
6969+char *strcat(char *s1, char *s2);
7070+char *strchr(char *s, char c);
7171+int strcmp(char *s1, char *s2);
7272+char *strcpy(char *s1, char *s2);
7373+int strcspn(char *s, char *set);
7474+int strlen(char *s);
7575+char *strncat(char *s1, char *s2, int n);
7676+int strncmp(char *s1, char *s2, int n);
7777+char *strncpy(char *s1, char *s2, int n);
7878+char *strpbrk(char *s, char *set);
7979+int strpos(char *s, char c);
8080+char *strrchr(char *s, char c);
8181+char *strrpbrk(char *s, char *set);
8282+int strrpos(char *s, char c);
8383+int strspn(char *s, char *set);
8484+int stscmp(char *s1, char *s2);
8585+8686+/* unix_strings.h */
8787+8888+int stcarg(char *s, char *b);
8989+int stcpm(char *s, char *p, char **q);
9090+int stcpma(char *string, char *pattern);
9191+char *stpsym(char *s, char *sym, int symlen);
9292+char *stptok(char *s, char *tok, int toklen, char *brk);
9393+9494+/* storage.h */
9595+9696+char *clalloc(unsigned long count,unsigned long size);
9797+char *calloc(unsigned int count, unsigned int size);
9898+int free(char *ptr);
9999+int cfree(char *ptr);
100100+char *mlalloc(unsigned long size);
101101+char *malloc(unsigned int size);
102102+char *relalloc(char *ptr,unsigned long newsize);
103103+char *realloc(char *ptr,unsigned newsize);
104104+105105+/* storageu.h */
106106+107107+int allmem(void);
108108+int bldmem(int n);
109109+char *getmem(unsigned int nbytes);
110110+char *getml(unsigned long lnbytes);
111111+char *lsbrk(unsigned long lnbytes);
112112+int rlsmem(char *cp, unsigned int nbytes);
113113+int rlsml(char *cp,unsigned long lnbytes);
114114+void rstmem(void);
115115+void rbrk(void);
116116+char *sbrk(unsigned int nbytes);
117117+long sizmem(void);
118118+119119+/* unix.h */
120120+121121+#ifndef _stdioh_
122122+#include "stdio.h"
123123+#endif _stdioh_
124124+125125+char *locv(int hi,int lo);
126126+int getw(FILE *who);
127127+int putw(int word, FILE *who);
128128+void perror(char *s);
129129+130130+void sleep(int secs);
131131+int ttyn(FILE *who);
132132+int stspfp(char *p,int *n);
133133+134134+double atof(char *s);
135135+int atoi(char *s);
136136+long atol(char *s);
137137+138138+int execl(char *path, ...);
139139+int execv(char *path, char *argv[]);
140140+int execle(char *path, ...);
141141+int execve(char *path, char *argv[], char *envp[]);
142142+143143+void exit(...);
144144+void _exit(...);
145145+void abort(...);
146146+147147+148148+int fileno(FILE *who);
149149+int open(char *filename, int mode);
150150+int close(int fildes);
151151+int read(int fildes, char *buffer, unsigned nbytes);
152152+int write(int fildes, char *buffer, unsigned nbytes);
153153+long lseek(int fildes, long int offset, unsigned int offsetmode);
154154+long tell(int fildes);
155155+int rename(char *old, char *new);
156156+int remove(char *name);
157157+int unlink(char *name);
158158+int creat(char *filename, int mode);
159159+160160+int getuid(void);
161161+int setuid(int uid);
162162+int getpid(void);
163163+int setpid(int pid);
164164+char *cgetpid(char *sptr);
165165+166166+void setmem(char *p,unsigned n,char c);
167167+void repmem(char *s, char *v, int lv, int nv);
168168+void movmem(char *s, char *d, unsigned n);
169169+170170+void eraseplot(void);
171171+void line(int x1, int y1, int x2, int y2);
172172+void move(int x, int y);
173173+void circle(int x, int y, int r);
174174+void cont(int x, int y);
175175+void point(int x, int y);
176176+void label(char *s);
177177+178178+int setbuf(FILE *fp, char *buf);
179179+int setnbuf(FILE *fp);
180180+181181+int (*signal(int sig, int (*func)()))();
182182+int kill(int pid, int sig);
183183+184184+int stci_d(char *out, int in, int outlen);
185185+int stcu_d(char *out, unsigned int in, int outlen);
186186+187187+int stcd_i(char *s,int *r);
188188+int stch_i(char *s,int *r);
189189+190190+unsigned long time(unsigned long *clock);
191191+char *ctime(unsigned long *clock);
192192+struct tm *localtime(unsigned long *clock);
193193+struct tm *gmtime(unsigned long *clock);
194194+char *asctime(struct tm *UnixTimeRecp);
195195+196196+/* stdio */
197197+198198+int feof(FILE *who);
199199+int ferror(FILE *who);
200200+void clearerr(FILE *who);
201201+void clrerr(FILE *who);
202202+203203+int fseek(FILE *who, long offset, int type);
204204+long ftell(FILE *who);
205205+int fflush(FILE *who);
206206+void rewind(FILE *who);
207207+208208+int fwrite(char *ptr, unsigned size, int count, FILE *who);
209209+int fread(char *ptr, unsigned size, int count, FILE *who);
210210+211211+int fgetc(FILE *who);
212212+char *fgets(char *s, int n, FILE *who);
213213+char *gets(char *s);
214214+int ungetc(char c, FILE *who);
215215+216216+int ungetch(int c);
217217+int getch(void);
218218+int getche(void);
219219+char *cgets(char *s);
220220+221221+int min(int v1, int v2);
222222+int max(int v1, int v2);
223223+224224+int fclose(FILE *who);
225225+FILE *fopen(char *nameptr, char *type);
226226+FILE *freopen(char *nameptr, char *type, FILE *who);
227227+int _closeall(void);
228228+229229+int fputc(unsigned char c, FILE *who);
230230+int fputs(char *s, FILE *who);
231231+int puts(char *s);
232232+233233+void cputs(char *s);
234234+void wputs(char *s);
235235+int kbhit(void);
236236+237237+int toint(char c);
238238+int toupper(char c);
239239+int tolower(char c);
240240+int _toupper(char c);
241241+int _tolower(char c);
242242+int isupper(char c);
243243+int islower(char c);
244244+245245+char *std_ver(void);
246246+247247+int printf(char *fmt, ...);
248248+int vprintf(char *fmt, char *arr, ...);
249249+int fprintf(FILE *who, char *fmt, ...);
250250+int vfprintf(FILE *who, char *fmt, char *arr, ...);
251251+int cprintf(char *fmt, ...);
252252+int vcprintf(char *fmt, char *arr, ...);
253253+254254+int sprintf(char *dest, char *fmt, ...);
255255+int vsprintf(char *dest, char *fmt, char *arr, ...);
256256+257257+int scanf(char *fmt, ...);
258258+int cscanf(char *fmt, ...);
259259+int fscanf(FILE *who, char *fmt, ...);
260260+int sscanf(unsigned char *dest, char *fmt, ...);
261261+262262+Boolean StdEvent(EventRecord *event);
263263+FILE *fopenw(char *titlebar, Point upper_left, StdWindowOptions *opts);
264264+char *Get_ScreenPtr(void);
265265+setwindow(FILE *windowfile);
266266+void Click_On(int flag);
267267+void Stdio_Config(int font, int size, int face, int mode);
268268+void Stdio_config(int font, int size, int face, int mode);
269269+void Set_Echo(Boolean state);
270270+void Stdio_MacInit(Boolean flag);
271271+void Set_Tab(int len);
272272+void gotoxy(int x, int y);
273273+int getxpos(void);
274274+int getypos(void);
275275+void putch(char c);
276276+277277+
+178
sources/qsort.c
···11+/*
22+ (C) Copyright 1986. THINK Technologies, Inc. All rights reserved.
33+44+55+ The qsort and qksort functions provided with the LightspeedC compiler
66+ are contained in this module.
77+88+*/
99+1010+#include "MemoryMgr.h"
1111+1212+/* Based on the algorithm given in Knuth volume 3, p. 116
1313+1414+1515+ qsort(base, nelms, size, compare)
1616+1717+ where: base pointer to start of data
1818+ nelms number of elements (int)
1919+ size size of each array element in bytes
2020+ compare pointer to procedure described below
2121+2222+ compare(p1, p2) p1 & p2 are pointer to two elements in the array
2323+ compare returns <0 if *p1 < *p2
2424+ >0 if *p1 > *p2
2525+ 0 if *p1 == *p2
2626+2727+***************************************************************************
2828+NOTE: qsort assumes that elements are aligned on word boundaries for
2929+ sizes of 2 & 4 to provide an efficient implementation.
3030+***************************************************************************
3131+3232+3333+Alternate calling sequence:
3434+3535+ qksort(nelms, compare, swap)
3636+3737+ where: nelms the number of elements to be sorted
3838+ compare pointer to procedure described below
3939+ swap pointer to procedure described below
4040+4141+4242+ compare(i, j) i & j are short int args which are indices into
4343+ the array that compareproc knows about.
4444+ compare returns <0 if item[i] < item[j]
4545+ >0 if item[i] > item[j]
4646+ 0 if item[i] == item[j]
4747+4848+ swap(i, j) i & j are short int args which are indices into
4949+ the array that swapproc knows about.
5050+ swapproc swaps array items i & j.
5151+5252+*/
5353+5454+5555+static int (*qkCompare)(), (*qkSwap)();
5656+5757+#line 0 qksort1
5858+/* sort elements "first" through "last"-1 */
5959+static qksort1(first, last)
6060+{
6161+ static short i; /* "static" to save stack space */
6262+ register short j;
6363+6464+ while (last - first > 1) {
6565+ i = first;
6666+ j = last;
6767+ for (;;) {
6868+ while (++i < last && (*qkCompare)(i, first) < 0)
6969+ ;
7070+ while (--j > first && (*qkCompare)(j, first) > 0)
7171+ ;
7272+ if (i >= j)
7373+ break;
7474+ (*qkSwap)(i, j);
7575+ }
7676+ (*qkSwap)(first, j);
7777+ if (j - first < last - (j + 1)) {
7878+ qksort1(first, j);
7979+ first = j + 1; /* qsort1(j + 1, last); */
8080+ }
8181+ else {
8282+ qksort1(j + 1, last);
8383+ last = j; /* qsort1(first, j); */
8484+ }
8585+ }
8686+}
8787+8888+#line 0 qksort
8989+/* sort "nelems" elements, using user's "compare" and "swap" routines */
9090+qksort(nelems, compare, swap)
9191+int (*compare)(), (*swap)();
9292+{
9393+ qkCompare = compare;
9494+ qkSwap = swap;
9595+ qksort1(0, nelems);
9696+}
9797+9898+9999+/* qsort call support variables */
100100+101101+static int (*qCompare)();
102102+static char *qbase, *qtemp;
103103+static unsigned long qsize;
104104+105105+#line 0 qxcompare
106106+qxcompare(i, j)
107107+int i, j;
108108+{
109109+ (*qCompare) (qbase + i * qsize, qbase + j * qsize);
110110+}
111111+112112+#line 0 qxswap
113113+void qxswap(i, j)
114114+register int i, j;
115115+{
116116+register char c; /* save stack space and cut execution overhead */
117117+register int k;
118118+register long l;
119119+register char *p1, *p2;
120120+121121+ switch (qsize)
122122+ {
123123+ case 1: c = qbase[i];
124124+ qbase[i] = qbase[j];
125125+ qbase[j] = c;
126126+ break;
127127+128128+ case 2: k = ((int*)(qbase))[i];
129129+ ((int*)(qbase))[i] = ((int*)(qbase))[j];
130130+ ((int*)(qbase))[j] = k;
131131+ break;
132132+133133+ case 4: l = ((long*)(qbase))[i];
134134+ ((long*)(qbase))[i] = ((long*)(qbase))[j];
135135+ ((long*)(qbase))[j] = l;
136136+ break;
137137+138138+139139+ default: p1 = qbase + i * qsize;
140140+ p2 = qbase + j * qsize;
141141+ BlockMove(p1, qtemp, qsize);
142142+ BlockMove(p2, p1, qsize);
143143+ BlockMove(qtemp, p2, qsize);
144144+ break;
145145+ }
146146+}
147147+148148+149149+#line 0 qsort
150150+qsort(base, nelms, size, compare)
151151+char *base;
152152+int nelms;
153153+register int size;
154154+int (*compare)();
155155+{
156156+ if (size <= 0) return (-1);
157157+158158+ /* allocate a buffer unless swapping char, int, or long */
159159+160160+ qtemp = 0;
161161+162162+ if (size==3 || size>4)
163163+ {
164164+ qtemp=NewPtr(size);
165165+ if (MemErr) return (-1);
166166+ }
167167+168168+ qCompare = compare;
169169+ qbase = base;
170170+ qsize = size;
171171+172172+ qksort(nelms, &qxcompare, &qxswap);
173173+174174+ if (qtemp) DisposPtr(qtemp);
175175+176176+ return (0);
177177+}
178178+
···11+/*
22+ Routines for LightspeedC�
33+44+ This file contains fwrite and fread.
55+66+ (C) Copyright 1985, 1986. THINK Technologies, Inc. All rights reserved.
77+88+ pdg - 6/20/86 - add capability for unix file i/o transfers >32K bytes
99+ add support for .AOut, .BOut device drivers
1010+*/
1111+1212+#ifndef _stdioh_
1313+#include "stdio.h"
1414+#endif
1515+1616+#ifndef _FileMgr_
1717+#include "FileMgr.h"
1818+#endif
1919+2020+#ifndef _SerialDvr_
2121+#include "SerialDvr.h"
2222+#endif
2323+2424+int write_to_buffer();
2525+int read_into_buffer();
2626+2727+long actcount_; /* used to return actual # bytes read using open() */
2828+2929+3030+Boolean _unsignedbytes = false; /* added to allow unsigned read() and
3131+ write() from unix library to use
3232+ stdio and still function correctly */
3333+3434+#line 0 fwrite()
3535+int fwrite(ptr,size,count,who)
3636+ register char *ptr;
3737+ register unsigned size;
3838+ register int count;
3939+ register FILE *who;
4040+{
4141+ register long n, m;
4242+4343+ actcount_ = 0;
4444+4545+4646+ if (_unsignedbytes)
4747+ { _unsignedbytes = false; /* reset */
4848+ m = n = (long)size * (long)((unsigned)count);
4949+ }
5050+ else
5151+ {
5252+ if (count < 0)
5353+ return(0);
5454+5555+ m = n = (long)size*count;
5656+ }
5757+5858+ if (who->wr == false) /* error if no write permission */
5959+ {
6060+ errno = who->last_error = wrPermErr;
6161+ return(0);
6262+ }
6363+6464+ if((!who)||(!who->InUse)) /* error if file not open */
6565+ {
6666+ errno = fnOpnErr; /* errno = file not open */
6767+ return(0);
6868+ }
6969+7070+ if (who->StdStream)
7171+ {
7272+ while (--n>=0 && ((fputc(*ptr,who)) == *ptr++)); /* keep going till EOF or */
7373+ actcount_ = (int)n;
7474+ return((int)(m/size));
7575+ }
7676+7777+ for (n=0; n<m; ++n)
7878+ {
7979+ if (who->fpos>(BUFSIZ-1))
8080+ if (write_to_buffer(who))
8181+ {
8282+ actcount_ = (int)n;
8383+ return(0);
8484+ }
8585+8686+ *(who->filebuf + who->fpos++) = ((!who->binary) && (*ptr == '\n'))?'\r':*ptr;
8787+ ptr++;
8888+ who->mod = true;
8989+ }
9090+9191+ actcount_ = (int)n;
9292+9393+ /* if .AOut or .Bout serial drivers, then flush now */
9494+9595+ if ((who->refnum == AoutRefNum) || (who->refnum == BoutRefNum))
9696+ if (write_to_buffer(who))
9797+ return(0);
9898+9999+ return((int)(n/size)); /* ..otherwise return # bytes written */
100100+}
101101+102102+103103+104104+105105+#line 0 fread()
106106+int fread(ptr,size,count,who)
107107+108108+ register char *ptr;
109109+ register unsigned size;
110110+ register int count;
111111+ register FILE *who;
112112+113113+{
114114+ register long n;
115115+ register int c;
116116+ register long m;
117117+118118+ actcount_ = 0;
119119+120120+ if (_unsignedbytes)
121121+ { _unsignedbytes = false; /* reset */
122122+ n = (long)size * (long)((unsigned)count);
123123+ }
124124+ else
125125+ {
126126+ if (count<0)
127127+ return(0);
128128+129129+ n = (long)size*count;
130130+ }
131131+132132+ if((!who)||(!who->InUse)) /* error if file not open */
133133+ {
134134+ errno = fnOpnErr; /* errno = file not open */
135135+ return(0);
136136+ }
137137+138138+ if(!who->rd) /* check for read permission */
139139+ {
140140+ errno = who->last_error = permErr;
141141+ return(0);
142142+ }
143143+144144+ if (who->StdStream)
145145+ {
146146+ while (--n>=0 && (c=fgetc(who))!= EOF) /* keep going till EOF or */
147147+ *ptr++ = c; /* placing character into buffer */
148148+ actcount_ = count * size;
149149+ return(count);
150150+ }
151151+152152+ for (m=0; m<n; m++)
153153+ {
154154+ if (who->fpos>=who->inbuf)
155155+ {
156156+ if (c = read_into_buffer(who))
157157+ if (c != eofErr)
158158+ {
159159+ actcount_ = (int)m;
160160+ errno = who->last_error = c;
161161+ return(0);
162162+ }
163163+ if(who->inbuf == 0) /* if the buffer is empty then ... */
164164+ {
165165+ errno = who->last_error = (c?c:eofErr);
166166+ actcount_ = (int)m;
167167+ return((int)(m/size)); /* 27-Feb-86 */
168168+ }
169169+ }
170170+ c = *(who->filebuf + who->fpos++);
171171+ if ((!who->binary)&&(c == '\r'))
172172+ c = '\n';
173173+ *ptr++ = c;
174174+ }
175175+176176+ actcount_ = (int)m;
177177+ return(count);
178178+}
179179+
+340
sources/stdget_console.c
···11+/*
22+ Routines for LightspeedC�
33+44+ (C) Copyright 1985, 1986. THINK Technologies, Inc. All rights reserved.
55+66+ This file contains:
77+88+ ungetch, getch, getche.
99+*/
1010+1111+#ifndef _stdioh_
1212+#include "stdio.h"
1313+#endif
1414+1515+#ifndef _EventMgr_
1616+#include "EventMgr.h"
1717+#endif
1818+1919+#ifndef _signalh_
2020+#include "signal.h"
2121+#endif
2222+2323+#ifndef _Quickdraw_
2424+#include "QuickDraw.h"
2525+#endif
2626+2727+extern Boolean _inited;
2828+extern Boolean _echo;
2929+3030+/* signal handling hooks */
3131+3232+int (*_key_int_sig_func_)() = 0;
3333+3434+#define AutoInt7 (*(long*) 0x7C)
3535+#define ROMBase (*(long*) 0x2AE)
3636+#define MaskPtr (*(long*) 0x31A)
3737+3838+/* pdg - 6/18/86 - completely revised command character handling of the
3939+ following function to allow control characters to be
4040+ easily generated from the keyboard */
4141+4242+#ifdef _STD_PASTE_
4343+4444+/* If _STD_PASTE is defined in stdio.h, then characters from the clipboard
4545+ can be pasted into the input stream, unlike TE which pastes into a
4646+ window. This allows all of the standard i/o functions to be passed the
4747+ contents of the paste on a character by character basis. While the
4848+ paste is occurring, the keyboard is constantly monitored for a
4949+ Command-. which will abort the paste. */
5050+5151+static
5252+AbortEvent()
5353+{
5454+EventRecord event;
5555+5656+ /* swallow key events looking for Command-. */
5757+5858+ while (GetNextEvent(keyDownMask, &event))
5959+ if ((char) event.message == '.' && (event.modifiers & cmdKey))
6060+ return(1);
6161+6262+ return(0);
6363+}
6464+6565+static long paste_offset = 0;
6666+static int paste_length = 0;
6767+static Handle scrap_handle = 0;
6868+6969+void _std_setup_paste()
7070+{
7171+long scrap_offset;
7272+7373+ if (scrap_handle)
7474+ DisposHandle(scrap_handle);
7575+7676+ scrap_handle = NewHandle(0);
7777+7878+ paste_length = GetScrap(scrap_handle, 'TEXT', &scrap_offset);
7979+ paste_offset = 0;
8080+}
8181+8282+#endif _STD_PASTE_
8383+8484+8585+#line 0 _get_char_from_keyboard()
8686+int _get_char_from_keyboard()
8787+{
8888+register int c;
8989+EventRecord the_Event; /* holds the event record */
9090+9191+ Init_stdio();
9292+9393+#ifdef _STD_PASTE_
9494+9595+ /* allow getting keystrokes from the clipboard (scrap) if a paste
9696+ operation has been done */
9797+9898+dopaste:
9999+100100+ if (paste_length > 0)
101101+ {
102102+ /* a paste operation is in progress, check for keyboard aborts */
103103+104104+ if (AbortEvent())
105105+ paste_length = 0;
106106+ else
107107+ {
108108+ c = * (*scrap_handle + paste_offset);
109109+ paste_length--;
110110+ paste_offset++;
111111+112112+ /* change Mac return to a new line */
113113+114114+ if (c == '\r') c = '\n';
115115+116116+ return (c);
117117+ }
118118+ }
119119+#endif _STD_PASTE_
120120+121121+nextevent:
122122+123123+ while(true)
124124+ {
125125+ while (! GetNextEvent(everyEvent, &the_Event))
126126+ {
127127+ HiliteMenu(0);
128128+ SystemTask();
129129+130130+#ifdef _STD_PASTE_
131131+ if (paste_length > 0) goto dopaste;
132132+#endif _STD_PASTE_
133133+134134+ }
135135+136136+#ifdef _STD_PASTE_
137137+ if (paste_length > 0) goto dopaste;
138138+#endif _STD_PASTE_
139139+140140+ SetCursor(&arrow);
141141+142142+ if (the_Event.what == keyDown || the_Event.what == autoKey)
143143+ break;
144144+145145+ StdEvent(&the_Event);
146146+ }
147147+148148+ /* pick up the character */
149149+150150+ c = (unsigned char) the_Event.message;
151151+152152+ if (the_Event.modifiers & cmdKey)
153153+ {
154154+155155+ /* if signal logic is enabled, then call interrupt procedure */
156156+157157+ if (_key_int_sig_func_)
158158+ {register int (*_temp_key_int_sig_func_)() = _key_int_sig_func_;
159159+160160+ switch (c)
161161+ {
162162+ case 'c':
163163+ case 'C':
164164+ case '.':
165165+ if ((long)_key_int_sig_func_ == SIG_DFL)
166166+ {
167167+ /* call debugger if loaded, then
168168+ (or otherwise) depart */
169169+170170+ if ((AutoInt7 & MaskPtr) < ROMBase)
171171+ DebugStr("\pSIGDFL reset!");
172172+173173+ ExitToShell();
174174+ }
175175+176176+ _key_int_sig_func_ = (void*) SIG_DFL;
177177+ (*_temp_key_int_sig_func_)(SIGINT);
178178+ goto nextevent;
179179+180180+ default: break;
181181+ }
182182+ }
183183+184184+ switch (c)
185185+ {
186186+ /* command(fan) D and command Z are considered EOF chars */
187187+188188+ case 'd':
189189+ case 'D':
190190+ case 'z':
191191+ case 'Z':
192192+ return (EOF);
193193+194194+ /* the key may therefore be some other control key, convert it
195195+ if it is, otherwise ignore the command modifier */
196196+197197+ /* NULL is command space, as is command 2 (shift doesn't work
198198+ on for @ since event manager traps command shift combos */
199199+200200+ case ' ':
201201+ case '2':
202202+ c = 0;
203203+ break;
204204+205205+ /* map command 6 into control-^ */
206206+207207+ case '6':
208208+ c = 30;
209209+ break;
210210+211211+ /* map command ` into control-~ */
212212+213213+ case '`':
214214+ c = 31;
215215+ break;
216216+217217+ /* map command backspace into DEL */
218218+219219+ case 8:
220220+ c = 0x7F;
221221+ break;
222222+223223+ default:
224224+ /* check for standard control chars */
225225+226226+ if ((c >= 'A') && (c <= '_')) c-= ('A' - 1);
227227+ else
228228+ if ((c >= 'a') && (c <= '~')) c-= ('a' - 1);
229229+230230+ break;
231231+ }
232232+ }
233233+ else
234234+ /* translate any input return to a newline, but not control M! */
235235+ if (c == '\r') c = '\n';
236236+237237+ return(c);
238238+}
239239+240240+241241+#line 0 ungetch()
242242+int ungetch(c)
243243+int c;
244244+{
245245+ if (_console->look_full)
246246+ return(EOF);
247247+248248+ _console->look_full = true;
249249+ _console->look_ahead = c;
250250+ return(c);
251251+}
252252+253253+254254+255255+#line 0 getch_common()
256256+static int getch_common()
257257+{
258258+ if (_console->look_full)
259259+ {
260260+ _console->look_full = false;
261261+ return((int)_console->look_ahead);
262262+ }
263263+ return( _get_char_from_keyboard() );
264264+}
265265+266266+267267+268268+#line 0 getch()
269269+int getch()
270270+{
271271+ return( getch_common() );
272272+}
273273+274274+275275+276276+#line 0 getche()
277277+int getche()
278278+{
279279+ register int c;
280280+281281+ c = getch_common();
282282+ if (c != EOF)
283283+ putch(c);
284284+ return(c);
285285+}
286286+287287+288288+289289+#line 0 cgets()
290290+char *cgets(s)
291291+register char *s;
292292+{
293293+register int c;
294294+register char *scopy = s;
295295+register Boolean orig_echo = _echo;
296296+297297+ /* handle our own echoing */
298298+299299+ Init_stdio();
300300+301301+ /*loop until EOF or \n */
302302+303303+ while ((c=getch_common())!= EOF)
304304+ {
305305+ if (c == '\b')
306306+ {
307307+ if (scopy != s)
308308+ {
309309+ if (_echo)
310310+ {
311311+ putch('\b');
312312+ putch(' ');
313313+ putch('\b');
314314+ }
315315+316316+ *--scopy = ' ';
317317+ }
318318+ }
319319+ else
320320+ {
321321+ if (_echo) putch(c);
322322+323323+ if ((*scopy++ = c) == '\n')
324324+ {
325325+ scopy--;
326326+ break;
327327+ }
328328+ }
329329+ }
330330+331331+ if ((scopy != s) || (c == '\n'))
332332+ {
333333+ *scopy = '\0';
334334+ }
335335+ else
336336+ s = NULL;
337337+338338+ return(s);
339339+}
340340+
+219
sources/stdgets.c
···11+/*
22+ Routines for LightspeedC�
33+44+ (C) Copyright 1985, 1986. THINK Technologies, Inc. All rights reserved.
55+66+ This file contains:
77+88+ fgetc, fgets, gets, ungetc.
99+*/
1010+1111+#ifndef _stdioh_
1212+#include "stdio.h"
1313+#endif
1414+1515+#ifndef _FileMgr_
1616+#include "FileMgr.h"
1717+#endif
1818+1919+extern Boolean _echo;
2020+extern int _get_char_from_keyboard();
2121+2222+static int maxchars = 0; /* allow unlimited length gets if zero */
2323+2424+#line 0 fgetc()
2525+int fgetc(who)
2626+register FILE *who;
2727+{
2828+register unsigned int c;
2929+register int err;
3030+3131+ if((!who)||(!who->InUse)) /* error if file not open */
3232+ {
3333+ errno = fnOpnErr;
3434+ return(EOF);
3535+ }
3636+3737+ if(!who->rd) /* check for read permission */
3838+ {
3939+ errno = who->last_error = permErr;
4040+ return(EOF);
4141+ }
4242+4343+ if (who->StdStream) /* if from keyboard */
4444+ {
4545+ if(who->look_full) /* is look_ahead buffer full */
4646+ { /* if buffer is full... */
4747+ who->look_full = false; /* set to empty */
4848+ return((int)who->look_ahead); /* return then character */
4949+ }
5050+ c = _get_char_from_keyboard();
5151+5252+ if ((_echo) && (c != EOF))
5353+ putch(c);
5454+ return(c);
5555+ }
5656+5757+ if (who->fpos >= who->inbuf)
5858+ {
5959+ if (err = read_into_buffer(who))
6060+ if (err != eofErr)
6161+ return(EOF);
6262+6363+ if(!who->inbuf)
6464+ {
6565+ errno = who->last_error = eofErr;
6666+ return(EOF);
6767+ }
6868+ }
6969+ c = (unsigned char)*(who->filebuf + who->fpos++);
7070+ if ((!who->binary)&&(c == '\r'))
7171+ c = '\n';
7272+ return(c);
7373+}
7474+7575+#line 0 fgets()
7676+char *fgets(s,n,who)
7777+register char *s;
7878+register int n;
7979+register FILE *who;
8080+{
8181+register int c;
8282+register char *scopy = s;
8383+8484+ if (n ==0) return (NULL);
8585+8686+ if (who == stdin && who->StdStream)
8787+ {
8888+ maxchars = n;
8989+ return (gets(s));
9090+ }
9191+9292+ /* loop until EOF or \n */
9393+9494+ while (--n>=0 && (c=fgetc(who))!= EOF)
9595+ {
9696+ if (c == '\b')
9797+ {
9898+ if (scopy != s)
9999+ {
100100+ n += 2;
101101+ scopy--;
102102+ }
103103+ else
104104+ n++;
105105+ }
106106+ else
107107+ if ((*scopy++ = c) == '\n') /* placing character into user */
108108+ break; /* defined buffer. */
109109+ }
110110+111111+ if (s != scopy) /* if buffer is modified.. */
112112+ *scopy = '\0'; /* Insert null in buffer */
113113+114114+ return((scopy == s) ? NULL : s); /* Return pointer to buffer */
115115+}
116116+117117+118118+#line 0 gets()
119119+char *gets(s)
120120+register char *s;
121121+{
122122+register int c;
123123+register char *scopy = s;
124124+register Boolean orig_echo = _echo, checkchars = (maxchars > 0);
125125+126126+ /* checkchars will be true if invoked by fgets for stdin */
127127+128128+ /* handle our own echoing */
129129+130130+ if (stdin->StdStream && _echo) Init_stdio();
131131+132132+ Set_Echo(false);
133133+134134+ /*loop until EOF or \n */
135135+136136+ while ((c=fgetc(stdin))!= EOF)
137137+ {
138138+ if (c == '\b')
139139+ {
140140+ if (scopy != s)
141141+ {
142142+ if (stdin->StdStream && orig_echo)
143143+ {
144144+ putch('\b');
145145+ putch(' ');
146146+ putch('\b');
147147+ }
148148+149149+ *--scopy = ' ';
150150+ }
151151+ }
152152+ else
153153+ {
154154+ if (stdin->StdStream && orig_echo)
155155+ putch(c);
156156+157157+ if ((*scopy++ = c) == '\n')
158158+ {
159159+ if (!checkchars) scopy--;
160160+ break;
161161+ }
162162+163163+ if (checkchars)
164164+ if (--maxchars == 0) break;
165165+ }
166166+167167+ }
168168+169169+ if ((scopy != s) || (c == '\n'))
170170+ {
171171+ *scopy = '\0';
172172+ }
173173+ else
174174+ s = NULL;
175175+176176+ Set_Echo(orig_echo);
177177+178178+ maxchars = 0; /* gets always resets to zero */
179179+180180+ return(s);
181181+}
182182+183183+184184+#line 0 ungetc()
185185+int ungetc(c,who)
186186+ register int c;
187187+ register FILE *who;
188188+189189+{
190190+ if ((!who)||(!who->InUse)) /* If file not open */
191191+ {
192192+ errno = fnOpnErr;
193193+ return(EOF);
194194+ }
195195+196196+ if ((int)c==EOF) /* ignore EOF characters*/
197197+ return(EOF);
198198+199199+200200+ if((who->StdStream)&&(who->rd))
201201+ {
202202+ if (who->look_full) /* if buffer is full */
203203+ return(EOF); /* return EOF */
204204+205205+ who->look_full = true; /* set buffer to full */
206206+ who->look_ahead = c; /* put char in buffer */
207207+ return((int)c); /* return character */
208208+ }
209209+210210+ if ((who->fpos>BUFSIZ)||(who->fpos==0))
211211+ return(EOF);
212212+213213+214214+ who->fpos -= 1;
215215+ *(who->filebuf+who->fpos) = c;
216216+217217+ return(c); /* return the character */
218218+}
219219+
+126
sources/stdio.h
···11+/*
22+ * stdio.h
33+ *
44+ * defines the structure used by the LightSpeedC I/O ("standard I/O")
55+ * routines and some of the associated values and macros.
66+ *
77+ * (C) Copyright 1985, 1986. THINK Technologies Inc. All rights reserved.
88+ */
99+1010+#ifndef _stdioh_
1111+#define _stdioh_
1212+1313+/* By uncommenting the next #define you are allowed to use the paste
1414+ menu item in the stdio menus. It allows the contents of the clipboard
1515+ to be pasted into the input stream. (see stdget_console.c for info)
1616+ HOWEVER, IT ADDS OVER 200 BYTES TO THE SIZE OF STDIO! */
1717+1818+/* #define _STD_PASTE_ */
1919+2020+#define BUFSIZ 512
2121+#define BUFSIZE 512
2222+#define NULL 0L
2323+#define _NFILE 30 /* increased from 15 */
2424+#define EOF (-1)
2525+2626+#define STDERRNO 2
2727+#define stdin (&_file[0])
2828+#define stdout (&_file[1])
2929+#define stderr (&_file[STDERRNO])
3030+#define _console (&_console_)
3131+3232+typedef struct {
3333+ int refnum; /* OS Reference number */
3434+ int last_error; /* holds last error on file */
3535+ int fileno; /* fnum for level 1 I/O */
3636+ unsigned user_buf:1, /* 1 if user defined buffer */
3737+ InUse:1, /* 0 if free */
3838+ StdStream:1, /* 0 = file, 1 = stdio */
3939+ rd:1,wr:1, /* flag for read and write */
4040+ look_full:1, /* flag for look_ahead */
4141+ mod:1, /* file modified flag */
4242+ binary:1, /* flag for binary file */
4343+ window:1; /* this is a window */
4444+ unsigned char look_ahead;/* char for look_ahead */
4545+ char *filebuf; /* Pointer to buffer */
4646+ int fpos; /* pos of file in buffer */
4747+ int inbuf; /* # of chars in buffer */
4848+ } FILE;
4949+5050+5151+void clearerr(); /* clear last error that occured */
5252+void clrerr(); /* clear last error that occured */
5353+void cputs(); /* puts a string to the console (screen) */
5454+void gotoxy(); /* goto x,y on screen */
5555+void Init_stdio(); /* initalize stdio (automatically done */
5656+void putch(); /* print a character to the console */
5757+void rewind(); /* set pointer to beginning of a file */
5858+void Set_Echo(); /* set I/O to echo or not (true=echo) */
5959+void Set_Tab(); /* set the width of the tab stop */
6060+void Click_On(); /* Sets the click_to_continue option of or off */
6161+void Stdio_config(); /* font,size,face,mode */
6262+char *cgets(); /* gets a string from the console (keyboard) */
6363+char *fgets(); /* gets a string from an input stream */
6464+char *gets(); /* gets a string from stdin */
6565+FILE *fopen(); /* open a file */
6666+FILE *fopenw(); /* open a file */
6767+FILE *freopen(); /* open a file using the given stream */
6868+extern FILE _file[_NFILE]; /* file descriptor array (internal) */
6969+extern FILE _console_; /* device name for the console */
7070+long ftell(); /* get position withen file */
7171+7272+/* new for windowed printf-2-w.c */
7373+7474+char *Get_ScreenPtr();
7575+void *Get_WindowPtr(); /* actually a WindowPtr -- this saves bringing in
7676+ the include for WindowMgr.h */
7777+7878+int _closeall(); /* close all open files */
7979+extern int errno;
8080+8181+/* Default for these functions are int so they don't need to be declared
8282+Boolean StdEvent(); -- this is fine since Booleans become ints
8383+cprintf();
8484+cscanf();
8585+fclose();
8686+feof();
8787+ferror();
8888+fflush();
8989+fgetc();
9090+fileno();
9191+fprintf();
9292+fputc();
9393+fputs();
9494+fread();
9595+fseek();
9696+fwrite();
9797+getch();
9898+getche();
9999+getxpos();
100100+getypos();
101101+isupper();
102102+islower();
103103+kbhit();
104104+max();
105105+min();
106106+puts();
107107+printf();
108108+sprintf();
109109+toint();
110110+tolower();
111111+toupper();
112112+ungetc();
113113+vcprintf();
114114+vfprintf();
115115+vprintf();
116116+vsprintf();
117117+_tolower();
118118+_toupper();
119119+onexit();
120120+*/
121121+#define getc(stream) (fgetc(stream))
122122+#define getchar() (fgetc(stdin))
123123+#define putc(c,stream) (fputc(c,stream))
124124+#define putchar(c) (fputc(c,stdout))
125125+126126+#endif
+23
sources/stdmax_min.c
···11+/*
22+ max and min routines for LightspeedC�
33+44+ (C) Copyright 1985, 1986. THINK Technologies, Inc. All rights reserved.
55+*/
66+77+#line 0 min
88+int min(v1,v2)
99+int v1,v2;
1010+{
1111+ if (v1 < v2) return (v1);
1212+1313+ return (v2);
1414+}
1515+1616+#line 0 max
1717+int max(v1,v2)
1818+int v1,v2;
1919+{
2020+ if (v1 > v2) return (v1);
2121+2222+ return (v2);
2323+}
+372
sources/stdopen.c
···11+/*
22+ Routines for LightspeedC�
33+44+ (C) Copyright 1985, 1986. THINK Technologies, Inc. All rights reserved.
55+*/
66+77+#ifndef _stdioh_
88+#include "stdio.h"
99+#endif
1010+1111+#ifndef _FileMgr_
1212+#include "FileMgr.h"
1313+#endif
1414+1515+#ifndef _SerialDvr_
1616+#include "SerialDvr.h"
1717+#endif
1818+1919+static Boolean _exiting_closeall_flag = false;
2020+void _exit_closeall();
2121+2222+/* This file contains the code for fopen, fclose, _closeall, freopen. */
2323+2424+#line 0 xfopen
2525+static FILE *xfopen(nameptr,type,who)
2626+char *nameptr;
2727+register char *type;
2828+register FILE *who;
2929+3030+{
3131+register int new;
3232+static Boolean _init_onexit = false; /* flag to signal onexit was initalized */
3333+3434+ ioParam pb; /* my parameter block for PB's */
3535+ fileParam pb2;
3636+ register int err;
3737+ int refnum;
3838+ Boolean create;
3939+ Boolean add;
4040+ register Boolean delete;
4141+ register Boolean bin_file;
4242+ register Ptr p;
4343+4444+ if(!who)
4545+ {
4646+ register int free_slot;
4747+ /* look thru FILE array for an open slot */
4848+ for (free_slot=STDERRNO+1;
4949+ ((free_slot<_NFILE)&&(_file[free_slot].InUse));
5050+ free_slot++)
5151+ ;
5252+5353+ if (free_slot >= _NFILE) {
5454+ errno = tmfoErr; /* too many files open */
5555+ return (NULL);
5656+ }
5757+5858+ who = &_file[free_slot];
5959+ }
6060+6161+{
6262+ register int permission;
6363+6464+ permission = fsWrPerm; /* default = write */
6565+ create = delete = true; /* default is true */
6666+ bin_file = add = false;
6767+ refnum = 0;
6868+6969+ if (type[1]=='\0')
7070+ {
7171+ if (type[0] == 'r') permission = fsRdPerm;
7272+ }
7373+ else
7474+ if (type[1] == '+')
7575+ {
7676+ permission = fsRdWrPerm;
7777+ if (type[2] == 'b') bin_file = true;
7878+ }
7979+ else
8080+ {
8181+ if (type[1] == 'b') bin_file = true;
8282+8383+ if (type[0] == 'r') permission = fsRdPerm;
8484+8585+ }
8686+8787+ switch (type[0])
8888+ {
8989+ case 'r':
9090+ create = false;
9191+ break;
9292+ case 'w':
9393+ delete = true;
9494+ break;
9595+ case 'a':
9696+ add = true;
9797+ break;
9898+ default:
9999+ return(NULL);
100100+ }
101101+102102+103103+ CtoPstr(nameptr);
104104+105105+ p = NewPtr((long)BUFSIZ);
106106+107107+ do {
108108+109109+ /* pdg 7/29/86 - look only via default path */
110110+111111+ pb.ioNamePtr = 0;
112112+ if (PBGetVol(&pb, false)) pb.ioVRefNum = 0;
113113+114114+115115+ pb.ioNamePtr = (StringPtr)nameptr;
116116+ pb.ioVersNum = 0;
117117+ pb.ioPermssn = permission;
118118+ pb.ioMisc = 0L;
119119+120120+ new = PBOpen(&pb,false);
121121+122122+ if ((new == fnfErr) && (create))
123123+ {
124124+ if (err = (PBCreate(&pb,false))) goto err_exit;
125125+126126+ pb2.ioFDirIndex = 0;
127127+ pb2.ioNamePtr = pb.ioNamePtr;
128128+ pb2.ioVRefNum = pb.ioVRefNum;
129129+ pb2.ioFVersNum = pb.ioVersNum;
130130+ if (err = (PBGetFInfo(&pb2,false))) goto err_exit;
131131+132132+ pb2.ioFlFndrInfo.fdType = 'TEXT';
133133+ pb2.ioFlFndrInfo.fdCreator = '????';
134134+ if (err = (PBSetFInfo(&pb2,false))) goto err_exit;
135135+136136+ delete = false; /* don't delete this file */
137137+ }
138138+139139+ if (!new)
140140+ { /* no errors on open */
141141+ if (pb.ioRefNum > 0)
142142+ { /* don't do this stuff if a device driver */
143143+144144+ if (type[0]=='a')
145145+ {
146146+ if(err = (PBGetEOF(&pb,false))) goto err_exit;
147147+148148+ pb.ioPosOffset = (long)pb.ioMisc;
149149+ pb.ioPosMode = fsFromStart;
150150+ err = PBSetFPos(&pb,false);
151151+ if ((err!=noErr) && (err!=eofErr)) goto err_exit;
152152+ }
153153+154154+ if ((type[0]=='w') && (delete))
155155+ {
156156+ pb2.ioFDirIndex = 0;
157157+ pb2.ioNamePtr = pb.ioNamePtr;
158158+ pb2.ioVRefNum = pb.ioVRefNum;
159159+ pb2.ioFVersNum = pb.ioVersNum;
160160+ if (err = (PBGetFInfo(&pb2,false))) goto err_exit;
161161+162162+ if (err = (PBClose(&pb,false))) goto err_exit;
163163+164164+ if (err = (PBDelete(&pb,false))) goto err_exit;
165165+166166+ if (err = (PBCreate(&pb,false))) goto err_exit;
167167+168168+ if (err = (PBSetFInfo(&pb2,false))) goto err_exit;
169169+170170+ new = PBOpen(&pb,false);
171171+ create = false;
172172+ }
173173+ }
174174+175175+ if (!new)
176176+ {
177177+ refnum = pb.ioRefNum;
178178+ who->refnum = refnum;
179179+ who->last_error = noErr;
180180+ who->user_buf = false;
181181+ who->StdStream = false;
182182+ who->filebuf = p;
183183+ who->InUse = true;
184184+ who->mod = false;
185185+ who->look_full = false;
186186+ who->rd = false;
187187+ who->wr = false;
188188+ who->window = false;
189189+ if((permission==fsRdWrPerm)||(permission==fsRdPerm))
190190+ who->rd = true;
191191+ if((permission==fsRdWrPerm)||(permission==fsWrPerm))
192192+ who->wr = true;
193193+ who->binary = bin_file;
194194+ who->fpos = BUFSIZ+10; /* force fread/fwrite to go to disk */
195195+ who->inbuf = 0;
196196+ PtoCstr(nameptr);
197197+ if (_init_onexit == false)
198198+ {
199199+ _init_onexit = true;
200200+ onexit(_exit_closeall);
201201+ }
202202+203203+ if ((who->rd)&&(who->wr))
204204+ {
205205+ if(err = read_into_buffer(who))
206206+ if (err != eofErr)
207207+ {
208208+ who->last_error = errno = err;
209209+ return(who);
210210+ }
211211+ }
212212+ return(who);
213213+ }
214214+ }
215215+ }
216216+ while ((new == fnfErr) && (create));
217217+218218+ if (new) errno = new;
219219+220220+ goto exit_noset;
221221+222222+err_exit:
223223+ errno = err;
224224+225225+exit_noset:
226226+227227+ DisposPtr(p);
228228+ PtoCstr(nameptr);
229229+ return(NULL);
230230+} /* end of scope of permission */
231231+232232+}
233233+234234+235235+#line 0 fclose
236236+int fclose(who)
237237+register FILE *who;
238238+{
239239+ ioParam pb; /* my parameter block for PB's */
240240+ int vrefnum; /* vrefnum storage */
241241+ register int refnum;
242242+ register int err;
243243+244244+ if (who) /* error if file not open */
245245+ {
246246+ if(who->StdStream) /* Is it a standard device */
247247+ {
248248+ if (who->window)
249249+ {
250250+ /* leave windows alone if in exit code */
251251+ if (_exiting_closeall_flag)
252252+ return (0);
253253+254254+ return (fclosew(who));
255255+ }
256256+257257+ who->InUse = false; /* Close stream if so */
258258+ who->StdStream = false;
259259+ return(0); /* OK */
260260+ }
261261+262262+ if (!who->InUse) goto file_not_in_use;
263263+264264+ switch (refnum = who->refnum)
265265+ {
266266+ default:
267267+268268+ if (refnum > 0)
269269+ if (err=(GetVRefNum(refnum,&vrefnum))) /* get VRefNum*/
270270+ goto err2_exit;
271271+272272+ pb.ioRefNum = refnum;
273273+274274+ if (who->mod)
275275+ {
276276+ pb.ioBuffer = who->filebuf;
277277+ pb.ioReqCount = (long)who->fpos;
278278+ pb.ioPosMode = fsAtMark;
279279+ pb.ioPosOffset = 0L;
280280+281281+ if (err = who->last_error = PBWrite(&pb,false))
282282+ errno = err;
283283+ }
284284+285285+ who->InUse = false;
286286+ if (err = (PBClose(&pb,false))) /* close file */
287287+ goto err2_exit;
288288+289289+ if (refnum > 0)
290290+ {
291291+ pb.ioVRefNum = vrefnum;
292292+ pb.ioNamePtr = 0L;
293293+ if (err = (PBFlshVol(&pb,false))) /* flush vol */
294294+ goto err2_exit;
295295+ }
296296+297297+ break;
298298+299299+ /* in the case of the standard serial drivers, flush the buffer,
300300+ but never close the driver (mouse will die, etc.) */
301301+302302+ case AinRefNum:
303303+ case BinRefNum:
304304+ case AoutRefNum:
305305+ case BoutRefNum:
306306+307307+ if (who->mod)
308308+ write_to_buffer(who);
309309+ break;
310310+ }
311311+312312+ if (!who->user_buf)
313313+ DisposPtr(who->filebuf); /* dispose mem*/
314314+315315+ return(0);
316316+ }
317317+318318+file_not_in_use:
319319+320320+ err = fnOpnErr; /* file not open error */
321321+322322+err2_exit:
323323+324324+ errno = err;
325325+ return(EOF);
326326+}
327327+328328+329329+330330+331331+#line 0 fopen
332332+FILE *fopen(nameptr,type)
333333+ char *nameptr,*type;
334334+{
335335+ return(xfopen(nameptr,type,NULL));
336336+337337+ (void) std_ver();
338338+339339+}
340340+341341+342342+343343+#line 0 freopen
344344+FILE *freopen(nameptr,type,who)
345345+ char *nameptr,*type;
346346+ FILE *who;
347347+348348+{
349349+ if(fclose(who)) return(NULL);
350350+ return(xfopen(nameptr,type,who));
351351+}
352352+353353+354354+#line 0 _closeall
355355+int _closeall()
356356+{
357357+ register int counter, bad_ones = 0;
358358+359359+ for (counter = 0; counter < _NFILE; counter++)
360360+ if (fclose(&_file[counter]))
361361+ bad_ones++;
362362+363363+ return(bad_ones);
364364+365365+}
366366+367367+static
368368+void _exit_closeall()
369369+{
370370+ _exiting_closeall_flag = true;
371371+ _closeall();
372372+}
+43
sources/stdput_console.c
···11+/*
22+ Routines for LightspeedC�
33+44+ (C) Copyright 1985, 1986. THINK Technologies, Inc. All rights reserved.
55+66+ The name of this file is purely historical and does not really
77+ reflect the two functions defined here.
88+*/
99+1010+#ifndef _Quickdraw_
1111+#include "Quickdraw.h"
1212+#endif
1313+1414+#ifndef _EventMgr_
1515+#include "EventMgr.h"
1616+#endif
1717+1818+extern Boolean _inited;
1919+2020+#line 0 wputs()
2121+void wputs(s)
2222+register char *s;
2323+{
2424+ Init_stdio();
2525+2626+ while (*s)
2727+ {
2828+ putch(*s);
2929+ s++;
3030+ }
3131+}
3232+3333+#line 0 kbhit()
3434+int kbhit()
3535+{
3636+EventRecord the_Event; /* holds the event record */
3737+3838+ if (! _inited) InitGraf(&thePort);
3939+4040+ EventAvail(keyDownMask+autoKeyMask,&the_Event); /* get event */
4141+4242+ return(the_Event.what);
4343+}
+142
sources/stdputs.c
···11+/*
22+ Routines for LightspeedC�
33+44+ (C) Copyright 1985, 1986. THINK Technologies, Inc. All rights reserved.
55+66+ This file contains:
77+88+ fputc, fputs, puts
99+*/
1010+1111+#include "fopenw.h"
1212+1313+#ifndef _FileMgr_
1414+#include "FileMgr.h"
1515+#endif
1616+1717+extern Boolean _echo;
1818+1919+/*
2020+ This file contains fputc, fputs, puts, cputs
2121+*/
2222+2323+static StdwsaveRecord saverec;
2424+2525+2626+#line 0 cputs()
2727+void cputs(s)
2828+register char *s;
2929+{
3030+ stdwsave(stdout, &saverec);
3131+3232+ while (*s)
3333+ {
3434+ putch(*s);
3535+ s++;
3636+ }
3737+3838+ stdwrestore(stdout, &saverec);
3939+}
4040+4141+4242+#line 0 fputc()
4343+int fputc(c,who)
4444+4545+ register unsigned char c;
4646+ register FILE *who;
4747+4848+{
4949+ ioParam pb; /* my parameter block for PB's */
5050+5151+ if ((!who)||(!who->InUse)||(!who->wr)) /* error if file not open */
5252+ {
5353+ if (!who->wr)
5454+ errno = who->last_error = wrPermErr; /* write perm error */
5555+ else
5656+ errno = fnOpnErr; /* file not open */
5757+ return(EOF);
5858+ }
5959+6060+6161+ if (who->StdStream)
6262+ {
6363+ stdwsave(who, &saverec);
6464+ putch(c); /* put char directly to the screen */
6565+ stdwrestore(who, &saverec);
6666+ return(c); /* never an error on fputc(stdout). */
6767+ }
6868+6969+ if (who->fpos>(BUFSIZ-1))
7070+ if (write_to_buffer(who))
7171+ return(EOF);
7272+ *(who->filebuf + who->fpos++) =(unsigned char) ((!who->binary) && (c == '\n'))?'\r':c;
7373+ who->mod = true;
7474+return(c);
7575+}
7676+7777+7878+7979+#line 0 fputs
8080+int fputs(s,who)
8181+8282+ register char *s;
8383+ register FILE *who;
8484+8585+{
8686+ register int c;
8787+8888+ if ((!who)||(!who->InUse)||(!who->wr)) /* error if file not open */
8989+ {
9090+ if (!who->wr)
9191+ errno = who->last_error = wrPermErr; /* write perm error */
9292+ else
9393+ errno = fnOpnErr; /* file not open */
9494+ return(EOF);
9595+ }
9696+9797+ if (who->StdStream)
9898+ {
9999+ cputs(s);
100100+ return(0);
101101+ }
102102+103103+104104+ while (c = *s++)
105105+ if (fputc(c,who) != c)
106106+ return(EOF);
107107+108108+ return(0); /* Its ok */
109109+110110+}
111111+112112+113113+#line 0 puts
114114+int puts(s)
115115+ register char *s;
116116+{
117117+ if (stdout->StdStream)
118118+ {
119119+ if (stdout->wr == false)
120120+ {
121121+ errno = stdout->last_error = wrPermErr;
122122+ return(EOF);
123123+ }
124124+125125+ cputs(s);
126126+ cputs("\n");
127127+ return(0);
128128+ }
129129+130130+131131+ if(fputs(s,stdout) == EOF)
132132+ return(EOF);
133133+134134+ if(fputc('\n',stdout) != '\n')
135135+ return(EOF);
136136+137137+ return(0);
138138+}
139139+140140+141141+142142+
···11+/*
22+ Routines for LightspeedC�
33+44+ (C) Copyright 1986. THINK Technologies, Inc. All rights reserved.
55+66+*/
77+88+/* This module is purely for identification of the standard i/o release,
99+ however, for those diehards who wanted it, it does contain a
1010+ perfectly usable function that returns a pointer to a string that
1111+ contains the version of standard i/o */
1212+1313+#define STDIO_VERSION "LightspeedC� Libraries 1.57"
1414+1515+/* return the library version number of stdio */
1616+1717+1818+#line 0 std_ver()
1919+char *std_ver()
2020+{
2121+ return (STDIO_VERSION);
2222+2323+ "(C) Copyright 1986 THINK Technologies,Inc. All rights reserved";
2424+}
+115
sources/storage.c
···11+/************************************************************************/
22+/* */
33+/* Copyright (C) 1986 THINK Technologies, Inc. All rights reserved. */
44+/* */
55+/************************************************************************/
66+77+/*
88+ Storage function library. All of the basic storage allocation and
99+ disposition routines provided with the LightspeedC compiler are contained
1010+ in this module. The header "storage.h" contains definitions for the routines
1111+ contained herein. Each of the routines are described below.
1212+1313+1414+Standard C Library storage procedures
1515+1616+calloc(count,size) - allocate a cleared block of size*count bytes
1717+clalloc(count,size) - allocate a cleared block of size*count bytes
1818+cfree(ptr) - release block from calloc, clalloc, malloc, mlalloc
1919+free(ptr) - release block from calloc, clalloc, malloc, mlalloc
2020+malloc(size) - allocate a block of size bytes
2121+mlalloc(size) - allocate a block of size bytes
2222+realloc(ptr,newsize) - resize a block to newsize bytes
2323+relalloc(ptr,newsize) - resize a block to newsize bytes
2424+*/
2525+2626+#include "Storage.h"
2727+2828+#ifndef _MemoryMgr_
2929+#include "MemoryMgr.h"
3030+#endif
3131+3232+#undef NULL
3333+#define NULL 0L
3434+#define CLEAR 1
3535+3636+#line 0 clalloc
3737+char *clalloc(count,size)
3838+unsigned long count;
3939+unsigned long size;
4040+{
4141+ size *= count;
4242+4343+ asm
4444+ {
4545+ move.l size,d0
4646+ NewPtr CLEAR
4747+ move.w d0,MemErr
4848+ move.l a0,d0
4949+ }
5050+}
5151+5252+#line 0 calloc
5353+char *calloc(count, size)
5454+unsigned int count;
5555+unsigned int size;
5656+{
5757+5858+ return (clalloc((long)count, (long)size));
5959+}
6060+6161+6262+#line 0 free
6363+int free(ptr)
6464+char *ptr;
6565+{
6666+ /* Get the handle back from the pointer */
6767+6868+ DisposPtr(ptr);
6969+7070+ return (MemErr ? -1 : 0);
7171+}
7272+7373+#line 0 cfree
7474+int cfree(ptr)
7575+char *ptr;
7676+{
7777+ free(ptr);
7878+}
7979+8080+#line 0 mlalloc
8181+char *mlalloc(size)
8282+unsigned long size;
8383+{
8484+ return NewPtr(size);
8585+}
8686+8787+#line 0 malloc
8888+char *malloc(size)
8989+unsigned int size;
9090+{
9191+ return NewPtr(size);
9292+}
9393+9494+#line 0 relalloc
9595+char *relalloc(ptr,newsize)
9696+char *ptr;
9797+unsigned long newsize;
9898+{
9999+ SetPtrSize(ptr, newsize);
100100+101101+ /* return new pointer */
102102+103103+ return (MemErr ? NULL : ptr);
104104+}
105105+106106+107107+#line 0 realloc
108108+char *realloc(ptr,newsize)
109109+char *ptr;
110110+unsigned newsize;
111111+{
112112+ return (relalloc(ptr, (long)newsize));
113113+}
114114+115115+
+23
sources/storage.h
···11+/*************************************************************************
22+33+ Storage function library
44+55+Standard C storage procedures
66+77+ (C) Copyright 1986. THINK Technologies, Inc. All rights reserved.
88+99+************************************************************************/
1010+1111+#ifndef _storagech_
1212+#define _storagech_
1313+1414+ char *calloc();
1515+ char *clalloc();
1616+/* int cfree(); Default for these functions are int so they don't need to be declared*/
1717+/* int free(); */
1818+ char *malloc();
1919+ char *mlalloc();
2020+ char *realloc();
2121+ char *relalloc();
2222+2323+#endif
+513
sources/storageu.c
···11+/************************************************************************/
22+/* */
33+/* Copyright (C) 1986 THINK Technologies, Inc. All rights reserved. */
44+/* */
55+/************************************************************************/
66+77+/*
88+ Storage function library. All of the UNIX storage allocation and
99+ disposition routines provided with the LightspeedC compiler are contained
1010+ in this module. The header "storageu.h" contains definitions for the routines
1111+ contained herein.
1212+1313+1414+UNIX compatibility storage procedures for level 1 and level 2 memory mgmt.
1515+1616+allmem(nkbytes)
1717+bldmem(nkbytes)
1818+getmem(nbytes)
1919+getml(nbytes)
2020+lsbrk(nbytes)
2121+rbrk()
2222+rlsmem(cp,nbytes)
2323+rlsml(cp,nbytes)
2424+rstmem()
2525+sbrk(nbytes)
2626+sizmem()
2727+*/
2828+2929+#include "Storageu.h"
3030+3131+#ifndef _MemoryMgr_
3232+#include "MemoryMgr.h"
3333+#endif
3434+3535+#define NULL 0L
3636+#define ERROR -1
3737+3838+/********************************************************/
3939+/* */
4040+/* UNIX level 1 & level 2 storage allocation */
4141+/* */
4242+/********************************************************/
4343+4444+/* need some variables to manage memory pools */
4545+4646+static unsigned long poolsize=0; /* Size of pool in bytes */
4747+static Handle poolhandle=NULL; /* Handle to memory pool */
4848+static char *bldbrk=NULL; /* beginning of level 2 memory pool */
4949+static char *getbrk=NULL; /* end of actively allocated level 2 */
5050+static char *endbrk=NULL; /* end address of pool */
5151+static char allmemflag=0; /* allmem has been called flag */
5252+5353+#define L2POOLSIZE 30*1024 /* size of automatic level 2 memory pool */
5454+5555+/* forward references */
5656+5757+char *getbytes();
5858+void initfreepool();
5959+6060+6161+#line 0 allmem
6262+int allmem()
6363+{
6464+int status;
6565+6666+ if (allmemflag) return (ERROR);
6767+6868+ status = bldmem(0);
6969+7070+ allmemflag = 1;
7171+7272+ return (status);
7373+}
7474+7575+#line 0 bldmem
7676+int bldmem(n)
7777+int n;
7878+{
7979+unsigned long m = n;
8080+8181+ if (allmemflag) return (ERROR);
8282+8383+ /* set up the level 2 memory pool to be n K bytes if n!=0 */
8484+8585+ if ((getbrk = bldbrk = lsbrk(m=(m?(m<<10):L2POOLSIZE)))==NULL)
8686+ return (ERROR);
8787+8888+ /* remember end position so we know when allocation area runs out */
8989+9090+ endbrk = bldbrk + m;
9191+ return (0);
9292+}
9393+9494+9595+#line 0 getmem
9696+char *getmem(nbytes)
9797+unsigned int nbytes;
9898+{
9999+ return (getml((long)nbytes));
100100+}
101101+102102+103103+#line 0 getml
104104+char *getml(lnbytes)
105105+unsigned long lnbytes;
106106+{
107107+ if (getbrk) return (getbytes(lnbytes));
108108+ return (lsbrk(lnbytes));
109109+}
110110+111111+#line 0 lsbrk
112112+char *lsbrk(lnbytes)
113113+register unsigned long lnbytes;
114114+{
115115+register char *p;
116116+117117+ /* odd sizes are illegal for lsbrk and are rounded upwards */
118118+119119+ if (lnbytes & 1) lnbytes++;
120120+121121+ if (poolhandle)
122122+ {
123123+ /* pool aready exists, create pointer to current end */
124124+125125+ p = *poolhandle + poolsize;
126126+127127+ /* grow it in place since we aren't allowed to move it */
128128+129129+ SetHandleSize(poolhandle, poolsize+lnbytes);
130130+131131+ if (MemErr) return (NULL);
132132+133133+ poolsize += lnbytes;
134134+135135+ return (p);
136136+ }
137137+138138+ /* Create new pool */
139139+140140+ if (poolhandle = NewHandle(lnbytes))
141141+ {
142142+ poolsize = lnbytes;
143143+ HLock(poolhandle);
144144+ return (*poolhandle);
145145+ }
146146+147147+ return (NULL);
148148+149149+}
150150+151151+#line 0 rlsmem
152152+int rlsmem(cp,nbytes)
153153+char *cp;
154154+unsigned int nbytes;
155155+{
156156+ return (rlsml(cp, (long)nbytes));
157157+}
158158+159159+#line 0 rlsml
160160+int rlsml(cp,lnbytes)
161161+register char *cp;
162162+unsigned long lnbytes;
163163+{
164164+ /* Make sure pointer is within the pool */
165165+166166+ if (cp < *poolhandle) return (ERROR);
167167+168168+ /* memory allocated from primary pool before calling allmem()
169169+ or bldmem() cannot be reclaimed if released */
170170+171171+ if (getbrk == NULL)
172172+ return (0);
173173+174174+ if ((cp+lnbytes) > getbrk) return (ERROR);
175175+176176+ /* OK, it's in the pool, now put it onto the free list,
177177+ note that if cp is odd, block is marked as unusable (third param) */
178178+179179+ return (putfreepool(cp, lnbytes, !((int)cp&1)));
180180+}
181181+182182+#line 0 rstmem
183183+void rstmem()
184184+{
185185+ /* reinitialize level 2 memory pool */
186186+187187+ initfreepool();
188188+189189+ /* reset allocation point */
190190+191191+ getbrk = bldbrk;
192192+193193+ /* pretend that allmem() was never called */
194194+195195+ allmemflag = 0;
196196+}
197197+198198+#line 0 rbrk
199199+void rbrk()
200200+{
201201+ if (poolhandle)
202202+ {
203203+ /* release all level 2 free pool memory */
204204+205205+ rstmem();
206206+207207+ /* now release level 1 pool memory */
208208+209209+ HUnlock(poolhandle);
210210+ DisposHandle(poolhandle);
211211+ poolhandle = NULL;
212212+ bldbrk = endbrk = getbrk = NULL;
213213+214214+ /* our memory pool is now restored to its initial state */
215215+ }
216216+}
217217+218218+#line 0 sbrk
219219+char *sbrk(nbytes)
220220+unsigned int nbytes;
221221+{
222222+char *p;
223223+224224+ if ((p = lsbrk((long)nbytes)) == NULL) return ((char*)ERROR);
225225+226226+ return (p);
227227+}
228228+229229+230230+#line 0 sizmem
231231+long sizmem()
232232+{
233233+ /* return unallocated memory pool size, note that this does
234234+ not include any memory given back to the free pool */
235235+236236+ return (endbrk - getbrk);
237237+}
238238+239239+240240+241241+/********************************************************/
242242+/* */
243243+/* Internal support procedures, etc. */
244244+/* */
245245+/********************************************************/
246246+247247+typedef struct {
248248+char *offset;
249249+unsigned long size;
250250+int usable;
251251+} freeliststruct;
252252+253253+#define FREELISTUNIT (10*sizeof(freeliststruct))
254254+255255+#define delentry(freep, freecount, index)\
256256+ BlockMove(freep+1, freep, (--freecount-index)*sizeof(*freep))
257257+258258+#define addentry(freep, freecount, index)\
259259+ BlockMove(freep, freep+1, (freecount++-index)*sizeof(*freep))
260260+261261+262262+static freeliststruct **freehandle=NULL;
263263+static int freecount=0;
264264+static unsigned long freemax=0;
265265+char *getfreepool();
266266+267267+268268+#line 0 getbytes
269269+static char *getbytes(lnbytes)
270270+register unsigned long lnbytes;
271271+{
272272+register unsigned long size;
273273+register char *p;
274274+275275+ /* if there isn't a memory pool created, it's an error */
276276+277277+ if (poolhandle == NULL) return (NULL);
278278+279279+ /* See if we can get something from already deallocated memory */
280280+281281+ if (p=getfreepool(lnbytes)) return (p);
282282+283283+ if ( getbrk+lnbytes > endbrk)
284284+ {
285285+ /* Not enough free pool memory, try to get more, rounded to 1K */
286286+287287+ size = (lnbytes+1023) & ~1023;
288288+289289+ /* This may fail if lots of memory has been allocated */
290290+291291+ if (lsbrk(size) == NULL) return (NULL);
292292+293293+ endbrk += size;
294294+ }
295295+296296+ /* Allocate from the pool */
297297+298298+ p = getbrk;
299299+300300+ /* can't allow allocation of space on odd byte addresses, so
301301+ round to the next byte */
302302+303303+ if (lnbytes & 1)
304304+ {
305305+ if (putfreepool(p + lnbytes, 1L, false)) return (NULL);
306306+ lnbytes++;
307307+ }
308308+309309+ getbrk += lnbytes;
310310+ return (p);
311311+}
312312+313313+#line 0 initfreepool
314314+static void initfreepool()
315315+{
316316+ if (freehandle) DisposHandle(freehandle);
317317+318318+ freehandle = NULL;
319319+ freecount = 0;
320320+ freemax = 0;
321321+}
322322+323323+#line 0 putfreepool
324324+static int putfreepool(cp, lnbytes, usable)
325325+register char *cp;
326326+register unsigned long lnbytes;
327327+int usable;
328328+{
329329+register freeliststruct *freep;
330330+register int i, done=false;
331331+332332+ if (freehandle == NULL)
333333+ {
334334+ /* Create a free list */
335335+336336+ if ((freehandle = (freeliststruct**)
337337+ NewHandle(freemax = FREELISTUNIT)) == NULL)
338338+ return (ERROR);
339339+340340+ freecount = 0;
341341+ }
342342+343343+ HLock(freehandle);
344344+345345+ /* Determine insertion point in free list */
346346+347347+ for (i=0, freep = *freehandle; (i<freecount)&&(freep->offset<cp);
348348+ freep++, i++);
349349+350350+ if (i>0)
351351+ {
352352+ /* check if this item overlaps previous entry */
353353+354354+ if (((freep-1)->offset + (freep-1)->size) > cp)
355355+ {
356356+ /* yes, it's an error */
357357+358358+ HUnlock(freehandle);
359359+ return (ERROR);
360360+ }
361361+362362+ /* see if we can combine the item with the previous entry */
363363+364364+ if (((freep-1)->offset + (freep-1)->size) == cp)
365365+ {
366366+ /* yes, combine it */
367367+ (freep-1)->size += lnbytes;
368368+ done = true;
369369+ }
370370+ }
371371+372372+ if (!done && (i<freecount))
373373+ {
374374+ /* check if this item overlaps the next entry */
375375+376376+ if ((cp+lnbytes) > freep->offset)
377377+ {
378378+ /* yes, error */
379379+380380+ HUnlock(freehandle);
381381+ return (ERROR);
382382+ }
383383+384384+ /* see if we can combine the item with the next entry */
385385+386386+ if ((cp+lnbytes) == freep->offset)
387387+ {
388388+ /* yes, combine it */
389389+ freep->size += lnbytes;
390390+ freep->offset = cp;
391391+ freep->usable = (!((int)cp&1));
392392+ done = true;
393393+ }
394394+ }
395395+396396+ if (done)
397397+ {
398398+ /* now see if we have to combine the two entries */
399399+400400+ if ((i>0) && (i<freecount))
401401+ {
402402+ /* both entries exist, so try to combine them */
403403+404404+ if (((freep-1)->offset + (freep-1)->size) == freep->offset)
405405+ {
406406+ /* yes, combine them both into the previous entry */
407407+408408+ (freep-1)->size += freep->size;
409409+410410+ /* now delete the second entry */
411411+412412+ delentry(freep, freecount, i);
413413+ }
414414+ }
415415+ }
416416+ else
417417+ {
418418+ if (freecount==freemax)
419419+ {
420420+ /* Need to grow the free list, first make freep relative */
421421+422422+ freep -= (unsigned long) *freehandle;
423423+424424+ /* Allow free list to roam about */
425425+426426+ HUnlock(freehandle);
427427+428428+ /* resize it */
429429+430430+ SetHandleSize(freehandle, freemax+=FREELISTUNIT);
431431+432432+ if (MemErr) return (ERROR);
433433+434434+ HLock(freehandle);
435435+436436+ /* now make freep absolute again */
437437+438438+ freep += (unsigned long) *freehandle;
439439+ }
440440+441441+ /* Need to slide down entries to make room for new one */
442442+443443+ addentry(freep, freecount, i);
444444+445445+ freep->offset = cp;
446446+ freep->size = lnbytes;
447447+448448+ freep->usable = usable;
449449+ }
450450+451451+ HUnlock(freehandle);
452452+453453+ if (freecount == 0) initfreepool();
454454+455455+ return (0);
456456+}
457457+458458+#line 0 getfreepool
459459+static char *getfreepool(lnbytes)
460460+register unsigned long lnbytes;
461461+{
462462+register freeliststruct *freep;
463463+register char *oddptr, *cp = NULL;
464464+register int i;
465465+466466+467467+ /* There may not be a free list */
468468+ if (freehandle == NULL) return (NULL);
469469+470470+ /* guess we have to scan through... */
471471+ HLock(freehandle);
472472+473473+ for (i=0, freep=*freehandle; ((i<freecount)&&(freep->size<lnbytes))
474474+ &&(!freep->usable);
475475+ freep++, i++);
476476+477477+ if (i == freecount)
478478+ {
479479+ /* got to end of list without finding sufficient space */
480480+481481+ HUnlock(freehandle);
482482+ return (NULL);
483483+ }
484484+485485+ /* decrease free pool allocated amount by lnbytes (or so) */
486486+487487+ cp = freep->offset;
488488+489489+ /* can't allow allocation of space on odd byte addresses, so
490490+ round to the next byte */
491491+492492+ if ((lnbytes & 1) && (freep->size != lnbytes))
493493+ {
494494+ oddptr = cp + lnbytes;
495495+ lnbytes++;
496496+ }
497497+498498+ freep->offset += lnbytes;
499499+500500+ if ((freep->size -= lnbytes) == 0)
501501+ delentry(freep, freecount, i);
502502+503503+ HUnlock(freehandle);
504504+505505+ /* if we allocated an odd number of bytes, put the odd byte on the
506506+ free list, but make it unavailable for allocation */
507507+508508+ if (oddptr)
509509+ if (putfreepool(oddptr, 1L, false)) return ((char*)ERROR);
510510+511511+ return (cp);
512512+}
513513+
+26
sources/storageu.h
···11+/*************************************************************************
22+33+ Storage function library
44+55+UNIX compatibility storage procedures for level 1 and level 2 memory mgmt.
66+77+ (C) Copyright 1986. THINK Technologies, Inc. All rights reserved.
88+99+************************************************************************/
1010+1111+#ifndef _storageuh_
1212+#define _storageuh_
1313+1414+/* int allmem(); */
1515+/* int bldmem(); */
1616+ char *getmem();
1717+ char *getml();
1818+ char *lsbrk();
1919+ void rbrk();
2020+/* int rlsmem(); Default for these functions are int so they don't need to be declared*/
2121+/* int rlsml(); */
2222+ void rstmem();
2323+ char *sbrk();
2424+ long sizmem();
2525+2626+#endif
+387
sources/strings.c
···11+/*
22+33+ (C) Copyright THINK Technologies, Inc. 1986. All rights reserved.
44+55+66+ String function library. All of the string routines provided with the
77+ LightSpeed C compiler are contained in this module. The header
88+ "strings.h" contains all of the definitions for the routines contained
99+ herein. Each of the routines are described below. This table, and
1010+ the functions in the file are arranged in alphabetical order.
1111+1212+ stccpy( s1, s2, n ) - copy n character from s2 into s1
1313+ stcis( s, set ) - find first position in s not in set
1414+ stcisn( s1, set ) - find first position in s and in set
1515+ stclen( s ) - length of s
1616+ stpblk( p ) - return pointer to first non-blank in p
1717+ stpbrk( s, set ) - return pointer to first of set in s
1818+ stpchr( s, c ) - return pointer to c in s
1919+ stpcpy( s1, s2 ) - copy s2 into s1
2020+ strcat( s1, s2 ) - append s2 to s1
2121+ strchr( s, c ) - return pointer to c in s
2222+ strcmp( s1, s2 ) - return <0 if s1 < s2, =0 if s1 == s2, >0 if s1 > s2
2323+ strcpy( s1, s2 ) - copy s2 into s1
2424+ strcspn( s, set ) - find first position in s and in set
2525+ strlen( s ) - length of s
2626+ strncat( s1, s2, n ) - append up to n chars from t into s
2727+ strncmp( s1, s2, n ) - for n chars of s1,
2828+ return <0 if s1 < s2, =0 if s1 == s2, >0 if s1 > s2
2929+ strncpy( s1, s2, n ) - copy up to n chars from s2 to s1
3030+ strpbrk( s, set ) - return pointer to first of set in s
3131+ strpos( s, c ) - find first position of c in s
3232+ strrchr( s, c ) - return pointer to last occurance of c in s
3333+ strrpbrk( s, set ) - return pointer last char in s and in set
3434+ strrpos( s, c ) - find position of last occurance of c in s
3535+ strspn( s, set ) - find first occurance in s not in set
3636+ stscmp( s1, s2 ) - return <0 if s1 < s2, =0 if s1 == s2, >0 if s1 > s2
3737+3838+ In order to minimize the size of the library, some functions are used
3939+ as aliases for others. The list below defines the mapping used.
4040+ Routines not in this list are explicitly coded.
4141+4242+ stcis -> strspn
4343+ stcisn -> strcspn
4444+ stclen -> strlen
4545+ stpbrk -> strpbrk
4646+ stpchr -> strchr
4747+ stpcpy -> strcpy
4848+ strcmp -> strncmp
4949+ stscmp -> strncmp
5050+*/
5151+5252+#include "stdio.h"
5353+#include "ctype.h"
5454+#include "strings.h"
5555+5656+#line 0 stccpy
5757+5858+stccpy(s1, s2, n)
5959+register char *s1, *s2;
6060+register int n;
6161+{
6262+register char *s0 = s1;
6363+6464+ if (n <= 0) return (0);
6565+6666+ while (n-- && (*s1++ = *s2++));
6767+6868+ if (n && *(s1-1)) *s1 = '\0';
6969+7070+ return (s1-s0-1);
7171+}
7272+7373+7474+#line 0 stcis
7575+7676+stcis(s, set)
7777+char *s, *set;
7878+{
7979+ return (strspn(s, set));
8080+}
8181+8282+8383+#line 0 stcisn
8484+8585+stcisn(s1, set)
8686+char *s1, *set;
8787+8888+{
8989+ return (strcspn(s1, set));
9090+}
9191+9292+9393+#line 0 stclen
9494+9595+stclen(s)
9696+char *s;
9797+{
9898+ return (strlen(s));
9999+}
100100+101101+102102+#line 0 stpblk
103103+104104+char *stpblk(p)
105105+register char *p;
106106+{
107107+ while (!(isspace(*p))) p++;
108108+109109+ return (p);
110110+}
111111+112112+#line 0 stpbrk
113113+114114+char *stpbrk(s, set)
115115+char *s, *set;
116116+117117+{
118118+ return (strpbrk(s, set));
119119+}
120120+121121+#line 0 stpchr
122122+123123+char *stpchr( s, c )
124124+char *s, c;
125125+{
126126+ return (strchr(s, c));
127127+}
128128+129129+#line 0 stpcpy
130130+131131+char *stpcpy(s1, s2)
132132+char *s1, *s2;
133133+{
134134+ return (strcpy(s1, s2));
135135+}
136136+137137+#line 0 strcat
138138+139139+char *strcat( s1, s2 )
140140+char *s1, *s2;
141141+{
142142+ strcpy(s1+strlen(s1), s2);
143143+144144+ return (s1);
145145+}
146146+147147+148148+#line 0 strchr
149149+150150+char *strchr(s, c)
151151+register char *s,c;
152152+{
153153+154154+ while ((*s != c) && *s) s++;
155155+156156+ return ( *s == c ? s : NULL );
157157+}
158158+159159+160160+#line 0 strcmp
161161+162162+strcmp(s1, s2)
163163+char *s1, *s2;
164164+{
165165+ for (; *s1 == *s2 ; s1++, s2++) if (!*s1) break;
166166+167167+ return (*s1 - *s2);
168168+169169+}
170170+171171+172172+#line 0 strcpy
173173+174174+char *strcpy(s1,s2)
175175+register char *s1, *s2;
176176+{
177177+char *s = s1;
178178+179179+ while (*s1++=*s2++);
180180+181181+ return (s);
182182+}
183183+184184+185185+#line 0 strcspn
186186+187187+strcspn(s, set)
188188+register char *s;
189189+char *set;
190190+191191+{
192192+register char *t;
193193+register int count = 0;
194194+195195+ while (*s)
196196+ {
197197+ t = set;
198198+ while (*t && (*s != *t)) t++;
199199+ if (!*t)
200200+ {
201201+ s++;
202202+ count++;
203203+ }
204204+ else
205205+ break;
206206+ }
207207+208208+ return (count);
209209+}
210210+211211+212212+#line 0 strlen
213213+214214+strlen(s)
215215+register char *s;
216216+{
217217+char *s0 = s;
218218+219219+ while (*s++);
220220+ return (s-s0-1);
221221+}
222222+223223+224224+#line 0 strncat
225225+226226+char *strncat(s1, s2, n)
227227+register char *s1, *s2;
228228+register int n;
229229+{
230230+char *s0 = s1;
231231+232232+ if (n <= 0) return ( s1 );
233233+234234+ while (*s1) s1++;
235235+236236+ while ((*s1++ = *s2++) && (--n));
237237+238238+ if (*(s1 - 1)) *s1 = '\0';
239239+240240+ return (s0);
241241+}
242242+243243+244244+#line 0 strncmp
245245+246246+strncmp(s1, s2, n)
247247+register char *s1, *s2;
248248+register int n;
249249+{
250250+ if (n <= 0) return ( 0 );
251251+ for (; --n && (*s1 == *s2); s1++, s2++)
252252+ if (!*s1) break;
253253+254254+ return (*s1 - *s2);
255255+}
256256+257257+258258+#line 0 strncpy
259259+260260+char *strncpy(s1, s2, n)
261261+register char *s1, *s2;
262262+register int n;
263263+{
264264+char *s0 = s1;
265265+266266+ if (n > 0)
267267+ {
268268+ while (n-- && (*s1++ = *s2++));
269269+270270+ while (n>0)
271271+ { /* pad out to n chars -- H&S specs it this way... */
272272+273273+ *s1++ = '\0';
274274+ n--;
275275+ }
276276+ }
277277+278278+ return (s0);
279279+}
280280+281281+282282+#line 0 strpbrk
283283+284284+char *strpbrk(s, set)
285285+register char *s;
286286+char *set;
287287+288288+{
289289+register char *t;
290290+291291+ for (; *s ; s++)
292292+ {
293293+ for (t = set; *t && (*s != *t); t++);
294294+295295+ if (*t) return (s);
296296+ }
297297+298298+ return (NULL);
299299+}
300300+301301+302302+#line 0 strpos
303303+304304+strpos(s, c)
305305+register char *s, c;
306306+{
307307+char *s0 = s;
308308+309309+ while ((*s != c) && *s) s++;
310310+311311+ return ( *s == c ? s-s0 : -1 );
312312+}
313313+314314+315315+#line 0 strrchr
316316+317317+char *strrchr( s, c )
318318+register char *s, c;
319319+{
320320+register char *p;
321321+322322+ for (p=s+strlen(s); p>=s; p--) if (*p==c) return (p);
323323+324324+ return (NULL);
325325+}
326326+327327+328328+#line 0 strrpbrk
329329+330330+char *strrpbrk(s, set)
331331+char *s;
332332+char *set;
333333+{
334334+register char *t, *p;
335335+register long xs = (long) s;
336336+337337+ for (p=s+strlen(s); p>= (char*)xs ; p--)
338338+ {
339339+ for (t=set; *t; t++)
340340+ if (*p == *t) return (p);
341341+ }
342342+343343+ return (NULL);
344344+}
345345+346346+347347+#line 0 strrpos
348348+349349+strrpos(s, c)
350350+register char *s, c;
351351+{
352352+register char *p;
353353+register long xs = (long) s;
354354+355355+ for (p=s+strlen(s); p>=(char*)xs; p--)
356356+ if (*p == c) return (p-s);
357357+358358+ return (-1);
359359+}
360360+361361+#line 0 strspn
362362+363363+strspn(s, set)
364364+register char *s;
365365+char *set;
366366+{
367367+char *s0 = s;
368368+register char *t;
369369+370370+ for (; *s ; s++)
371371+ {
372372+ for (t = set; *t ; t++) if (*s == *t) break;
373373+374374+ if (!*t) break;
375375+ }
376376+377377+ return (s-s0);
378378+}
379379+380380+381381+#line 0 stscmp
382382+383383+stscmp(s1,s2)
384384+char *s1, *s2;
385385+{
386386+ return (strcmp(s1, s2));
387387+}
+54
sources/strings.h
···11+/**************************************************************************
22+33+ Header file for routines contained in "strings.c"
44+ and "Unix_Strings.c". Refer to those files
55+ for information on string function and implementation.
66+77+ (C) Copyright 1985, 1986. THINK Technologies, Inc. All rights reserved.
88+99+**************************************************************************/
1010+1111+1212+#ifndef _stringh_
1313+#define _stringh_
1414+1515+/* Routines in string.lib */
1616+ char *stpblk();
1717+ char *stpbrk();
1818+ char *stpchr();
1919+ char *stpcpy();
2020+ char *strcat();
2121+ char *strchr();
2222+ char *strcpy();
2323+ char *strncat();
2424+ char *strncpy();
2525+ char *strpbrk();
2626+ char *strrchr();
2727+ char *strrpbrk();
2828+2929+/* Default for these functions are int so they don't need to be declared
3030+ int stccpy();
3131+ int stcis();
3232+ int stclen();
3333+ int strcmp();
3434+ int strcspn();
3535+ int strlen();
3636+ int strncmp();
3737+ int strpos();
3838+ int strrpos();
3939+ int strspn();
4040+ int stscmp();
4141+*/
4242+4343+4444+/* parsing functions - in unix string.lib */
4545+ char *stpsym();
4646+ char *stptok();
4747+4848+/*
4949+ int stcarg();
5050+ int stcpm();
5151+ int stcpma();
5252+*/
5353+5454+#endif
+492
sources/stringsasm.c
···11+/*
22+; (C) Copyright THINK Technologies, Inc. 1986. All rights reserved.
33+;
44+;
55+; Assembly language string procedures. This module comprises the string
66+; library. Certain functions are more efficient done this way than in
77+; straight C since LightspeedC is not optimized for the kind of
88+; specialized string handling done here.
99+;
1010+*/
1111+1212+/*************************************************************************/
1313+1414+stccpy()
1515+{
1616+ asm
1717+ {
1818+ movem.l 4(a7),a0-a1
1919+ move.l a0,d1
2020+ move.w 12(a7),d0
2121+ subq #1,d0
2222+ bge.s @stccpy1
2323+stccpyx:
2424+ move.l a0,d0
2525+ sub.l d1,d0
2626+ return
2727+stccpy1:
2828+ move.b (a1)+,(a0)+
2929+ dbeq d0,@stccpy1 ; if flags were 0 or count == -1, exit loop
3030+ tst.b -(a0)
3131+ beq.s @stccpyx
3232+ tst.w d0 ; did count go to zero?
3333+ blt.s @stccpyx ; yes, don't add zero on end
3434+ addq.l #1,a0 ; point to new end of string
3535+ clr.b (a0) ; zero it out
3636+ bra.s @stccpyx
3737+ return
3838+ }
3939+}
4040+4141+/*************************************************************************/
4242+4343+stpblk() /* space codes are hard-wired, taken from stddata_ctype.c */
4444+{
4545+ asm
4646+ {
4747+ move.l 4(a7),a0
4848+stpblk1:
4949+ cmp.b #32,(a0) ; is it a space?
5050+ beq.s @stpblkx
5151+ cmp.b #3,(a0) ; is it ^C (ETX)?
5252+ beq.s @stpblkx
5353+ cmp.b #9,(a0) ; is it less than 9?
5454+ blt.s @stpblk2 ; yes, no white space chars there
5555+ cmp.b #13,(a0) ; is it less than or equal to 13?
5656+ ble.s @stpblkx ; if so, 9-13 are all white space chars
5757+stpblk2:
5858+ addq.l #1,a0 ; look at next character in memory
5959+ bra.s @stpblk1
6060+stpblkx:
6161+ move.l a0,d0
6262+ return
6363+ }
6464+}
6565+6666+/*************************************************************************/
6767+6868+strcat()
6969+{
7070+ asm
7171+ {
7272+ movem.l 4(a7),a0-a1
7373+ move.l a0,d0
7474+strcat1:
7575+ tst.b (a0)+ ; find end of string1 (zero byte)
7676+ bne.s @strcat1 ; using tight loop
7777+ subq.l #1,a0 ; back up one
7878+strcat2:
7979+ move.b (a1)+,(a0)+ ; now copy string2 onto end of string1
8080+ bne.s @strcat2 ; again using tight loop
8181+ return
8282+ }
8383+}
8484+8585+/*************************************************************************/
8686+8787+strchr()
8888+{
8989+ asm
9090+ {
9191+ move.l 4(a7),a0
9292+ move.b 9(a7),d2
9393+ moveq #0,d0
9494+strchr1:
9595+ move.b (a0)+,d1
9696+ bne.s @strchr2
9797+ tst.b d2 ; special case if searching for 0
9898+ beq.s @strchr3
9999+ return
100100+strchr2:
101101+ cmp.b d2,d1
102102+ bne.s @strchr1
103103+strchr3:
104104+ move.l a0,d0
105105+ subq.l #1,d0
106106+ return
107107+ }
108108+}
109109+110110+stpchr() /* synonym for strchr */
111111+{
112112+ asm
113113+ {
114114+ jmp strchr
115115+ }
116116+}
117117+118118+/*************************************************************************/
119119+120120+strcmp()
121121+{
122122+ asm
123123+ {
124124+ movem.l 4(a7),a0-a1
125125+strcmp1:
126126+ cmpm.b (a1)+,(a0)+
127127+ bne.s @strcmpx
128128+strcmp2:
129129+ tst.b -1(a0) ; did string1 end?
130130+ bne.s @strcmp1
131131+strcmpx:
132132+ move.b -(a0),d0 ; return (*s1 - *s2)
133133+ sub.b -(a1),d0
134134+ ext.w d0
135135+ return
136136+ }
137137+}
138138+139139+stscmp() /* synonym for strcmp */
140140+{
141141+ asm
142142+ {
143143+ jmp strcmp
144144+ }
145145+}
146146+147147+148148+/*************************************************************************/
149149+150150+strcpy()
151151+{
152152+ asm
153153+ {
154154+ movem.l 4(a7),a0-a1
155155+ move.l a0,d0 ; return ptr to start of destination string
156156+strcpy1:
157157+ move.b (a1)+,(a0)+ ; copy until we pass a
158158+ bne.s @strcpy1 ; zero byte
159159+ return
160160+ }
161161+}
162162+163163+stpcpy() /* synonym for strcpy */
164164+{
165165+ asm
166166+ {
167167+ jmp strcpy
168168+ }
169169+}
170170+171171+/*************************************************************************/
172172+173173+strcspn() /* a0 = s, d1 = set, a1 = t */
174174+{
175175+ asm
176176+ {
177177+ move.l 4(a7),a0
178178+ move.l 8(a7),d1
179179+strcspn1:
180180+ tst.b (a0) ; is *s zero?
181181+ beq.s @strcspnx ; yes, exit
182182+ move.l d1,a1 ; t = set
183183+strcspn2:
184184+ tst.b (a1) ; is *t zero?
185185+ beq.s @strcspn3 ; yes, try next *s
186186+ cmpm.b (a0)+,(a1)+ ; is char in set?
187187+ subq.l #1,a0 ; no such inst as cmpm (a0),(a1)+
188188+ beq.s @strcspnx ; yes, exit
189189+ bra.s @strcspn2
190190+strcspn3:
191191+ addq.l #1,a0 ; yes, loop through for next char in s
192192+ bra.s @strcspn1
193193+strcspnx:
194194+ move.l a0,d0 ; subtract current pos from orig
195195+ sub.l 4(a7),d0 ; to get count
196196+ return
197197+ }
198198+}
199199+200200+stcisn() /* synonym for strcspn */
201201+{
202202+ asm
203203+ {
204204+ jmp strcspn
205205+ }
206206+}
207207+208208+/*************************************************************************/
209209+210210+strlen()
211211+{
212212+ asm
213213+ {
214214+ move.l 4(a7),a0
215215+strlen1:
216216+ tst.b (a0)+
217217+ bne.s @strlen1
218218+ move.l a0,d0
219219+ sub.l 4(a7),d0
220220+ subq.l #1,d0
221221+ return
222222+ }
223223+}
224224+225225+stclen() /* synonym for strlen */
226226+{
227227+ asm
228228+ {
229229+ jmp strlen
230230+ }
231231+}
232232+233233+/*************************************************************************/
234234+235235+strncat()
236236+{
237237+ asm
238238+ {
239239+ movem.l 4(a7),a0-a1
240240+ move.l a0,d0
241241+ move.w 12(a7),d1
242242+ ble.s @strncat3
243243+strncat1:
244244+ tst.b (a0)+
245245+ bne.s @strncat1 ; find end of string1
246246+ subq.l #1,a0
247247+ subq.w #1,d1 ; offset by 1 for dbeq
248248+strncat2:
249249+ move.b (a1)+,(a0)+ ; copy string2 onto end of string1
250250+ dbeq d1,@strncat2
251251+ tst.b -1(a0) ; did we copy a zero?
252252+ beq.s @strncat3 ; yes
253253+ clr.b (a0) ; no, add a zero on end
254254+strncat3:
255255+ return
256256+ }
257257+}
258258+259259+/*************************************************************************/
260260+261261+strncmp()
262262+{
263263+ asm
264264+ {
265265+ movem.l 4(a7),a0-a1
266266+ clr.w d0
267267+ move.w 12(a7),d1
268268+ ble.s @strncmp2
269269+strncmp1:
270270+ cmpm.b (a0)+,(a1)+
271271+ beq.s @strncmp3
272272+strncmpx:
273273+ move.b -(a0),d0
274274+ sub.b -(a1),d0
275275+ ext.w d0
276276+strncmp2:
277277+ return
278278+strncmp3:
279279+ subq.w #1,d1
280280+ beq.s @strncmpx
281281+ tst.b -1(a0)
282282+ beq.s @strncmpx
283283+ bra.s @strncmp1
284284+ return
285285+ }
286286+}
287287+288288+/*************************************************************************/
289289+290290+strncpy()
291291+{
292292+ asm
293293+ {
294294+ movem.l 4(a7),a0-a1
295295+ move.l a0,d0
296296+ move.w 12(a7),d1
297297+ bgt.s @strncpy1
298298+strncpyx:
299299+ return
300300+strncpy1:
301301+ move.b (a1)+,(a0)+
302302+ beq.s @strncpy2 ; if zero byte, see if we need to fill
303303+ subq.w #1,d1
304304+ bgt.s @strncpy1 ; is count exhausted?
305305+ beq.s @strncpyx ; yes, quit now
306306+strncpy2:
307307+ subq.w #1,d1
308308+ beq.s @strncpyx
309309+ clr.b (a0)+ ; zero end of string until count runs out
310310+ bra.s @strncpy2
311311+ }
312312+}
313313+314314+/*************************************************************************/
315315+316316+strpbrk()
317317+{
318318+ asm
319319+ {
320320+ move.l 4(a7),a0 ; a0 = s
321321+ move.l 8(a7),d1 ; d1 = set
322322+ moveq #0,d0
323323+strpbrk1:
324324+ tst.b (a0) ; *s zero?
325325+ beq.s @strpbrkx
326326+ move.l d1,a1 ; t = set
327327+strpbrk2:
328328+ move.b (a1)+,d2
329329+ bne.s @strpbrk3
330330+ addq.l #1,a0 ; reached end of set
331331+ bra.s @strpbrk1 ; try next char in s
332332+strpbrk3:
333333+ cmp.b (a0),d2 ; *s == *t ?
334334+ bne.s @strpbrk2 ; if not, try next *t
335335+ move.l a0,d0 ; yes, return s
336336+strpbrkx:
337337+ return
338338+ }
339339+}
340340+341341+stpbrk() /* synonym for strpbrk */
342342+{
343343+ asm
344344+ {
345345+ jmp strpbrk
346346+ }
347347+}
348348+349349+/*************************************************************************/
350350+351351+strpos()
352352+{
353353+ asm
354354+ {
355355+ move.l 4(a7),a0
356356+ move.b 9(a7),d0
357357+strpos1:
358358+ move.b (a0)+,d1
359359+ bne.s @strpos2
360360+ tst.b d0 ; special case searching for 0
361361+ beq.s @strpos3
362362+ moveq #-1,d0 ; return -1 if not found
363363+ return
364364+strpos2:
365365+ cmp.b d0,d1
366366+ bne.s @strpos1 ; no match, try again
367367+strpos3:
368368+ move.l a0,d0 ; matched, return index into string
369369+ sub.l 4(a7),d0
370370+ subq.w #1,d0
371371+ return
372372+ }
373373+}
374374+375375+/*************************************************************************/
376376+377377+strrchr() /* return ptr to last occurrence of char */
378378+{
379379+ asm
380380+ {
381381+ move.l 4(a7),a0 ; in the string
382382+ move.b 9(a7),d1
383383+ moveq #1,d0
384384+strrchr1:
385385+ move.b (a0)+,d2
386386+ beq.s @strrchr3
387387+ cmp.b d1,d2
388388+ bne.s @strrchr1
389389+ move.l a0,d0 ; remember last occurrence + 1
390390+ bra.s @strrchr1
391391+strrchr3:
392392+ tst.b d1 ; special case searching for 0
393393+ bne.s @strrchr4
394394+ move.l a0,d0
395395+strrchr4:
396396+ subq.l #1,d0
397397+ return
398398+ }
399399+}
400400+401401+/*************************************************************************/
402402+403403+strrpbrk()
404404+{
405405+ asm
406406+ {
407407+ move.l 4(a7),a0
408408+ move.l 8(a7),d1
409409+ moveq #0,d0
410410+strrpbrk1:
411411+ tst.b (a0)
412412+ beq.s @strrpbrkx
413413+ move.l d1,a1
414414+strrpbrk2:
415415+ move.b (a1)+,d2
416416+ beq.s @strrpbrk3
417417+ cmp.b (a0),d2
418418+ bne.s @strrpbrk2
419419+ move.l a0,d0
420420+strrpbrk3:
421421+ addq.l #1,a0
422422+ bra.s @strrpbrk1
423423+strrpbrkx:
424424+ return
425425+ }
426426+}
427427+428428+/*************************************************************************/
429429+430430+strrpos()
431431+{
432432+ asm
433433+ {
434434+ move.l 4(a7),a0
435435+ move.l a0,a1
436436+ move.b 9(a7),d1
437437+ move.l a0,d0
438438+strrpos1:
439439+ move.b (a0)+,d2
440440+ beq.s @strrpos3
441441+ cmp.b d1,d2
442442+ bne.s @strrpos1
443443+ move.l a0,d0
444444+ bra.s @strrpos1
445445+strrpos3:
446446+ tst.b d1
447447+ bne.s @strrpos4
448448+ move.l a0,d0
449449+strrpos4:
450450+ sub.l a1,d0
451451+ subq.w #1,d0
452452+ return
453453+ }
454454+}
455455+456456+/*************************************************************************/
457457+458458+strspn() /* a0 = s, d1 = set, a1 = t */
459459+{
460460+ asm
461461+ {
462462+ move.l 4(a7),a0
463463+ move.l 8(a7),d1
464464+strspn1:
465465+ tst.b (a0) ; is *s zero?
466466+ beq.s @strspnx ; yes, exit
467467+ move.l d1,a1 ; t = set
468468+strspn2:
469469+ tst.b (a1) ; is *t zero?
470470+ beq.s @strspnx ; yes, exit since char must not be in set
471471+ cmpm.b (a0)+,(a1)+ ; is char in set?
472472+ subq.l #1,a0 ; no such inst as cmpm (a0),(a1)+
473473+ bne.s @strspn2 ; loop through contents of set
474474+strspn3:
475475+ addq.l #1,a0 ; yes, loop through for next char in s
476476+ bra.s @strspn1
477477+strspnx:
478478+ move.l a0,d0 ; subtract current pos from orig
479479+ sub.l 4(a7),d0 ; to get count
480480+ return
481481+ }
482482+}
483483+484484+stcis() /* synonym for strspn */
485485+{
486486+ asm
487487+ {
488488+ jmp strspn
489489+ }
490490+}
491491+492492+
+25
sources/time.h
···11+/* (C) Copyright 1986. THINK Technologies, Inc. All rights reserved. */
22+33+#ifndef _timeh_
44+#define _timeh_
55+66+typedef struct tm {
77+ int tm_sec;
88+ int tm_min;
99+ int tm_hour;
1010+ int tm_mday;
1111+ int tm_mon;
1212+ int tm_year;
1313+ int tm_wday;
1414+ int tm_yday;
1515+ int tm_isdst;
1616+} tm;
1717+1818+struct tm *gmtime();
1919+struct tm *localtime();
2020+char *ctime();
2121+char *asctime();
2222+unsigned long time();
2323+extern char *tzname[];
2424+2525+#endif
+15
sources/types.h
···11+/* (C) Copyright 1986. THINK Technologies, Inc. All rights reserved. */
22+33+44+typedef long time_t;
55+typedef long daddr_t;
66+typedef char *caddr_t;
77+typedef unsigned int uint;
88+typedef unsigned short ushort;
99+typedef ushort ino_t;
1010+typedef short cnt_t;
1111+typedef short dev_t;
1212+typedef long off_t;
1313+typedef long paddr_t;
1414+typedef long key_t;
1515+typedef int label_t[10];
+133
sources/unix main.c
···11+/*************************************************************************
22+ * *
33+ * Module: unix main.c *
44+ * Programmer: Steve Adams *
55+ * *
66+ * (C) Copyright 1985, THINK Technologies, Inc. All rights reserved. *
77+ * *
88+ * Alternate main program to handle Unix command lines under Lightspeed *
99+ * C. The user is prompted for the command line on program entry. The *
1010+ * line is disected and placed in an "argv" array up to a maximum of *
1111+ * MAX_ARGS entries. I/O redirection is also supported, as follows: *
1212+ * *
1313+ * > redirects stdout to following file name *
1414+ * < redirects stdin to following file name *
1515+ * >> redirects stderr to following file name *
1616+ * *
1717+ * File names following a redirection may be immediately after the *
1818+ * redirector, or at what appears to be the next argument. If a file *
1919+ * open error occurs, then the program calls "SysBeep" and exits to the *
2020+ * shell. *
2121+ * *
2222+ * TO USE: change the "main" function in you application to "_main" and *
2323+ * include this file in your project. *
2424+ * *
2525+ *************************************************************************/
2626+2727+2828+#include <stdio.h>
2929+#include <ctype.h>
3030+3131+#define MAX_ARGS 50
3232+3333+#ifndef true
3434+#define true 1
3535+#define false 0
3636+#endif
3737+3838+static int argc = 1; /* final argument count */
3939+static char *argv[MAX_ARGS] = { "" }; /* array of pointers */
4040+static char command[256]; /* input line buffer */
4141+static int filename = false; /* TRUE iff file name */
4242+4343+4444+/*************************************************************************
4545+ * *
4646+ * Local routine to make a "beep" and exit to the shell. *
4747+ * *
4848+ *************************************************************************/
4949+5050+static void punt()
5151+ {
5252+ SysBeep( 5L );
5353+ ExitToShell();
5454+ }
5555+5656+5757+/*************************************************************************
5858+ * *
5959+ * Local routine to open a file in argv[--argc] after closing it's *
6060+ * previous existance. *
6161+ * *
6262+ *************************************************************************/
6363+6464+6565+static void openfile( file, mode )
6666+char *mode; /* mode for file open */
6767+FILE *file; /* file pointer to use */
6868+ {
6969+7070+ if ( (file = freopen( argv[--argc], mode, file ) ) <= (FILE *) NULL)
7171+ punt();
7272+ filename = false;
7373+ }
7474+7575+7676+/*************************************************************************
7777+ * *
7878+ * New main routine. Prompts for command line then calls user's main *
7979+ * now called "_main" with the argument list and redirected I/O. *
8080+ * *
8181+ *************************************************************************/
8282+8383+8484+void main()
8585+ {
8686+ char c; /* temp for EOLN check */
8787+ register char *cp; /* index in command line */
8888+ char *mode; /* local file mode */
8989+ FILE *file; /* file to change */
9090+ int i;
9191+9292+ printf( "Enter Unix command line:\n" );
9393+ gets( &command ); /* allow user to edit */
9494+ cp = &command[0]; /* start of buffer */
9595+ argv[0] = ""; /* program name is NULL */
9696+ while (argc < MAX_ARGS)
9797+ { /* up to MAX_ARGS entries */
9898+ while (isspace( *cp++ ));
9999+ if ( !*--cp )
100100+ break;
101101+ else if ( *cp == '<' )
102102+ { /* redirect stdin */
103103+ cp++;
104104+ file = stdin;
105105+ mode = "r";
106106+ filename = true;
107107+ }
108108+ else if ( *cp == '>' )
109109+ {
110110+ mode = "w";
111111+ filename = true;
112112+ if (*++cp == '>')
113113+ {
114114+ file = stderr;
115115+ cp++;
116116+ }
117117+ else
118118+ file = stdout;
119119+ }
120120+ else
121121+ { /* either an argument or a filename */
122122+ argv[argc++] = cp;
123123+ while ( *++cp && !isspace( *cp ) );
124124+ c = *cp;
125125+ *cp++ = '\0';
126126+ if (filename)
127127+ openfile( file, mode );
128128+ if (!c)
129129+ break;
130130+ }
131131+ }
132132+ _main( argc, argv );
133133+ }
···11+/*
22+ Unix/Lattice string parsing functions for Lightspeed.
33+44+ This library implements the string based parsing routines.
55+66+ Routines defined in this module:
77+ stcarg - get an argument
88+ stpcm - unanchored pattern match
99+ stpcma - anchored pattern match
1010+ stpsym - get a symbol from a string
1111+ stptok - get a token from a string
1212+1313+1414+ (C) Copyright 1986 THINK Technologies, Inc. All rights reserved.
1515+*/
1616+1717+#include "strings.h"
1818+1919+2020+/*
2121+ Scan string S until a character in B is found. If none is found, then a
2222+ zero is returned, otherwise the number of characters before the break
2323+ character is returned. Quoted strings and literals are skipped. Also,
2424+ the backslash is recognized as an escape character.
2525+2626+ Clarification: if no match in B is found, the value returned is the
2727+ length of the string. If the first character matches, then the value
2828+ returned would be zero. The value returned can be used as an index
2929+ into the string (starting from 0) which points to the break character,
3030+ or is equal to the length of the string if there is no break character.
3131+*/
3232+#line 0 stcarg
3333+int stcarg( s, b )
3434+char *b; /* break char set */
3535+register char *s; /* source string */
3636+{
3737+register char c; /* string terminator */
3838+register char *t; /* break set temporary */
3939+register char *s0 = s; /* original value of s */
4040+4141+ while ( *s )
4242+ if ( *s == '"' || *s == '\'')
4343+ {
4444+ for (c = *s++; (*s) && (*s != c); s++)
4545+ ;
4646+ s++;
4747+ }
4848+ else
4949+ if ( *s == '\\' ) s++;
5050+ else
5151+ {
5252+ for (t = b; (*t) && (*s != *t); t++ )
5353+ ;
5454+5555+ if ( *t ) break;
5656+5757+ s++;
5858+ }
5959+6060+ return( s-s0 );
6161+}
6262+6363+6464+/* Scan string S for first substring that matches the pattern in P. If a
6565+ pattern is found, then *Q is set to point to the start of the substring,
6666+ and it's length is returned. If the string is not found, then the length
6767+ returned is zero, and Q is unchanged.
6868+6969+*/
7070+#line 0 stcmp
7171+int stcpm( s, p, q )
7272+char *p; /* pattern string */
7373+char **q; /* points to matched string */
7474+register char *s; /* source string */
7575+{
7676+ register int i;
7777+7878+ while ( *s )
7979+ if ( (i = stcpma( s, p )) )
8080+ {
8181+ *q = s;
8282+ return( i );
8383+ }
8484+ else
8585+ s++;
8686+ return( 0 );
8787+}
8888+8989+9090+/* Determine if string S starts with the pattern indicated in P. If it does,
9191+ it indicates the number of characters matched from the pattern. If not,
9292+ it returns zero.
9393+*/
9494+#line 0 stcpma
9595+int stcpma( string, pattern )
9696+register char *pattern; /* pattern to match */
9797+register char *string; /* character to match */
9898+{
9999+ register char c; /* current pattern char */
100100+ char *start = string; /* start of input string */
101101+102102+103103+ while ( *pattern )
104104+ if ( *pattern == '?' )
105105+ {
106106+ string++;
107107+ pattern++;
108108+ }
109109+ else
110110+ {
111111+ c = *pattern++;
112112+ if ( c == '\\' )
113113+ {
114114+ switch (*pattern)
115115+ {
116116+ case '*':
117117+ case '+':
118118+ case '?':
119119+ c = *pattern++;
120120+ break;
121121+ default:
122122+ continue;
123123+ }
124124+ }
125125+126126+ if ( *pattern == '*' )
127127+ { /* matches 0 .. n of C */
128128+ pattern++;
129129+ while ( *string == c )
130130+ string++;
131131+ }
132132+ else if ( *pattern == '+' )
133133+ { /* matches 1 .. n of C */
134134+ pattern++;
135135+ if ( *string == c )
136136+ while ( *string == c )
137137+ string++;
138138+ else
139139+ break;
140140+ }
141141+ else if ( c == *string )
142142+ string++;
143143+ else
144144+ break;
145145+ }
146146+ return( string - start );
147147+}
148148+149149+150150+/*
151151+ Return pointer to next symbol in input string. A valid symbol starts
152152+ with a letter and is alphanumeric after that. Leading white space is not
153153+ skipped. If no symbol is found, S is returned, and SYM has a NULL as the
154154+ first byte. SYM is always NULL terminated.
155155+*/
156156+#line 0 stpsym
157157+char *stpsym( s, sym, symlen )
158158+register char *s; /* pointer to input string */
159159+register char *sym; /* pointer to output string */
160160+register int symlen; /* sizeof( sym ) */
161161+{
162162+ if ( (*s >= 'a' && *s <= 'z') || (*s >= 'A' && *s <= 'Z') )
163163+ while ( (*s >= 'a' && *s <= 'z') || (*s >= 'A' && *s <= 'Z') ||
164164+ (*s >= '0' && *s <= '9' ) )
165165+ {
166166+ if (symlen > 1)
167167+ {
168168+ symlen--;
169169+ *sym++ = *s;
170170+ }
171171+ s++;
172172+ }
173173+ *sym = '\0';
174174+ return( s );
175175+}
176176+177177+/* duplicated here from strings.c for self-containment of unix strings */
178178+179179+static int strcspn() /* a0 = s, a1 = set, a2 = t */
180180+{
181181+ asm
182182+ {
183183+ movem.l 4(a7),a0-a1
184184+strcspn1:
185185+ tst.b (a0) ; is *s zero?
186186+ beq.s @strcspnx ; yes, exit
187187+ move.l a1,a2 ; t = set
188188+strcspn2:
189189+ tst.b (a2) ; is *t zero?
190190+ beq.s @strcspn3 ; yes, try next *s
191191+ cmpm.b (a0)+,(a2)+ ; is char in set?
192192+ subq.l #1,a0 ; no such inst as cmpm (a0),(a2)+
193193+ beq.s @strcspnx ; yes, exit
194194+ bra.s @strcspn2
195195+strcspn3:
196196+ addq.l #1,a0 ; yes, loop through for next char in s
197197+ bra.s @strcspn1
198198+strcspnx:
199199+ move.l a0,d0 ; subtract current pos from orig
200200+ sub.l 4(a7),d0 ; to get count
201201+ return
202202+ }
203203+}
204204+205205+static char *strncpy()
206206+{
207207+ asm
208208+ {
209209+ movem.l 4(a7),a0-a1
210210+ move.l a0,d0
211211+ move.w 12(a7),d1
212212+ bgt.s @strncpy1
213213+strncpyx:
214214+ return
215215+strncpy1:
216216+ move.b (a1)+,(a0)+
217217+ beq.s @strncpy2 ; if zero byte, see if we need to fill
218218+ subq.w #1,d1
219219+ bgt.s @strncpy1 ; is count exhausted?
220220+ beq.s @strncpyx ; yes, quit now
221221+strncpy2:
222222+ subq.w #1,d1
223223+ beq.s @strncpyx
224224+ clr.b (a0)+ ; zero end of string until count runs out
225225+ bra.s @strncpy2
226226+ }
227227+}
228228+229229+230230+/*
231231+ Return the next token from S in TOK. The break characters for the ending
232232+ of token are in BRK. Leading whitespace is not skipped. If no token is
233233+ found, then S is returned. TOK is always NULL terminated.
234234+*/
235235+#line 0 stptok
236236+char *stptok( s, tok, toklen, brk )
237237+char *brk; /* pointer to break string */
238238+char *s; /* pointer to input string */
239239+char *tok; /* pointer to output string */
240240+int toklen; /* sizeof( tok ) */
241241+{
242242+ register int i;
243243+244244+ i = strcspn( s, brk );
245245+ strncpy( tok, s, i = i < toklen ? i : toklen - 1 );
246246+ tok[i] = '\0';
247247+ return( s + i );
248248+}
···11+/* (C) Copyright 1986. THINK Technologies, Inc. All rights reserved. */
22+33+44+#ifndef _ctypeh_
55+#include "ctype.h"
66+#endif
77+88+#line 0 atoi
99+1010+int atoi(s)
1111+register char *s;
1212+{
1313+register char signflag = 0;
1414+register int r=0;
1515+1616+ while (isspace(*s)) s++;
1717+1818+ if (*s=='-')
1919+ {
2020+ signflag = 1;
2121+ s++;
2222+ }
2323+ else
2424+ if (*s=='+') s++;
2525+2626+ while (isdigit(*s))
2727+ r = r * 10 + (*s++ - '0');
2828+2929+ return (signflag?-r:r);
3030+}
3131+3232+3333+#line 0 atol
3434+3535+long atol( s )
3636+register char *s;
3737+{
3838+register char signflag = 0;
3939+register long r=0;
4040+4141+ while (isspace(*s)) s++;
4242+4343+ if (*s=='-')
4444+ {
4545+ signflag = 1;
4646+ s++;
4747+ }
4848+ else
4949+ if (*s=='+') s++;
5050+5151+ while (isdigit(*s))
5252+ r = r * 10 + (*s++ - '0');
5353+5454+ return (signflag?-r:r);
5555+}
+46
sources/unixexec.c
···11+/* (C) Copyright 1986. THINK Technologies, Inc. All rights reserved. */
22+33+/* This module implements abbreviated versions of execl, execv, execle,
44+ and execve. It seems that the args should do something, however
55+ nothing is done with them here. These are implemented purely as a
66+ starting point for those applications which need to do transfers to
77+ other applications. */
88+99+char *CtoPstr();
1010+1111+1212+#line 0 execl
1313+1414+execl(path, arg)
1515+char *path, *arg;
1616+{ /* designed for launching application with arg0, arg1, ..., argn */
1717+1818+ Launch(0, CtoPstr(path));
1919+}
2020+2121+#line 0 execv
2222+2323+execv(path, argv)
2424+char *path, *argv[];
2525+{
2626+ Launch(0, CtoPstr(path));
2727+}
2828+2929+#line 0 execle
3030+3131+execle(path, arg)
3232+char *path, *arg;
3333+{
3434+ /* launch application with arg0, arg1, ..., argn, 0, env */
3535+3636+ Launch(0, CtoPstr(path));
3737+}
3838+3939+#line 0 execve
4040+4141+execve(path, argv, envp)
4242+char *path, *argv[], *envp[];
4343+{
4444+ Launch(0, CtoPstr(path));
4545+}
4646+
···11+/* (C) Copyright 1986. THINK Technologies, Inc. All rights reserved. */
22+33+/* This module implements an abbreviated version of signal() and its
44+ related functions */
55+66+#ifndef _unixh_
77+#include "unix.h"
88+#endif
99+1010+extern int errno;
1111+extern int (*_key_int_sig_func_)();
1212+1313+static void *sigptr[_SIGMAX+1]; /* array of signal pointers, initially 0 */
1414+static char _initsigterm = 0; /* flag for special SIGTERM set up */
1515+1616+#define AutoInt7 (*(long*) 0x7C)
1717+#define ROMBase (*(long*) 0x2AE)
1818+#define MaskPtr (*(long*) 0x31A)
1919+2020+#line 0 bugout
2121+2222+static void bugout()
2323+{
2424+ /* call debugger if loaded, then (or otherwise) depart */
2525+2626+ if ((AutoInt7 & MaskPtr) < ROMBase)
2727+ DebugStr("\pSIGDFL exit!");
2828+2929+ ExitToShell();
3030+}
3131+3232+#line 0 dosigterm
3333+3434+static void dosigterm()
3535+{register void (*calledfunc)() = sigptr[SIGTERM];
3636+3737+ /* if non-zero, call this procedure on exit from application */
3838+3939+ if (calledfunc)
4040+ (*calledfunc)(SIGTERM);
4141+}
4242+4343+4444+#line 0 signal
4545+4646+int (*signal(sig, func))()
4747+int sig;
4848+int (*func)();
4949+{
5050+int (*_last_sig_func_)();
5151+5252+ /* SIGINT is presently supported as a special case for trapping ^c
5353+ and ^. (where ^ means the command (fan) key. ^c and ^. are
5454+ therefore invisible to the application and are swallowed when the
5555+ interrupt procedure is called. This was done so lots of unix
5656+ code would not get dragged in for those just using stdio. */
5757+5858+ switch (sig)
5959+ {
6060+ case SIGINT:
6161+6262+ _last_sig_func_= _key_int_sig_func_;
6363+6464+ /* see if user wants to cause an exit on SIGINT */
6565+6666+ if ((long)func == SIG_DFL)
6767+ _key_int_sig_func_ = (void*) bugout;
6868+ else
6969+ if ((long)func == SIG_IGN)
7070+ _key_int_sig_func_ = 0; /* eliminate any set function */
7171+ else
7272+ _key_int_sig_func_ = func; /* set up "catch" function */
7373+7474+ return (_last_sig_func_); /* return last catch function */
7575+7676+ case SIGTERM:
7777+7878+ /* enable sending a last signal on application termination */
7979+8080+ if (!_initsigterm)
8181+ {
8282+ _initsigterm = 1;
8383+ onexit(dosigterm);
8484+ }
8585+ default:
8686+ if ((sig > 0) && (sig <= _SIGMAX))
8787+ {
8888+ _last_sig_func_ = sigptr[sig];
8989+9090+ /* see if user wants to cause an exit on signal */
9191+9292+ if ((long)func == SIG_DFL)
9393+ sigptr[sig] = (void*) bugout;
9494+ else
9595+ if ((long)func == SIG_IGN)
9696+ sigptr[sig] = 0; /* eliminate any set function */
9797+ else
9898+ sigptr[sig] = func; /* set up "catch" function */
9999+100100+ return (_last_sig_func_); /* return last catch function */
101101+ }
102102+103103+ if (sig == 0) return (0);
104104+105105+ /* signal value out of range */
106106+107107+ errno = EINVAL;
108108+ return ((void*)-1);
109109+ }
110110+}
111111+112112+#line 0 kill
113113+114114+kill(pid, sig)
115115+int pid, sig;
116116+{
117117+ if ((sig > _SIGMAX) || (sig < 0))
118118+ {
119119+ /* signal value out of range */
120120+ errno = EINVAL;
121121+ return (-1);
122122+ }
123123+124124+ if ((pid == getpid()) || (pid <= 0))
125125+ {register void (*calledfunc)() = sigptr[sig];
126126+127127+ if (sig)
128128+ {
129129+ /* send a signal to ourself! */
130130+131131+ sigptr[sig] = (void*) SIG_DFL;
132132+133133+ if (calledfunc)
134134+ (*calledfunc)(sig);
135135+ }
136136+137137+ return (0);
138138+ }
139139+140140+ errno = ESRCH; /* no such process */
141141+ return (-1);
142142+}
143143+
+58
sources/unixst2d.c
···11+/* (C) Copyright 1986. THINK Technologies, Inc. All rights reserved. */
22+33+44+static stc_d(out, in, outlen, signflag)
55+register char *out;
66+register unsigned int in;
77+register int outlen;
88+int signflag;
99+{
1010+char revnum [8];
1111+register int i=0;
1212+register char *out0 = out;
1313+1414+ if (outlen<=0) return (0);
1515+1616+ if (in == 0) revnum[i++]=0;
1717+ else
1818+ while (in)
1919+ {
2020+ revnum[i++] = in - (in/10)*10;
2121+ in /= 10;
2222+ }
2323+2424+ if (signflag)
2525+ {
2626+ *out++ = '-';
2727+ outlen--;
2828+ }
2929+3030+ for (; i && outlen; i--, outlen--)
3131+ *out++ = revnum[i-1] + '0';
3232+3333+ *out = '\0';
3434+3535+ return (out-out0);
3636+3737+}
3838+3939+#line 0 stci_d
4040+4141+stci_d(out, in, outlen)
4242+char *out;
4343+int in;
4444+int outlen;
4545+{
4646+ return (stc_d(out, (in>=0?in:-in), outlen, in<0));
4747+}
4848+4949+#line 0 stcu_d
5050+5151+stcu_d(out, in, outlen)
5252+char *out;
5353+unsigned int in;
5454+int outlen;
5555+{
5656+ return (stc_d(out, in, outlen, 0));
5757+}
5858+