home *** CD-ROM | disk | FTP | other *** search
- /*
- File: WriteLineWindow.c
-
- Copyright: © 1991-1994 by Apple Computer, Inc.
- All rights reserved.
-
- Part of the AOCE Sample SMSAM Package. Consult the license
- which came with this software for your specific legal rights.
-
- */
-
-
-
- #ifndef __TYPES__
- #include <Types.h>
- #endif
-
- #ifndef __MENUS__
- #include <Menus.h>
- #endif
-
- #ifndef __WINDOWS__
- #include <Windows.h>
- #endif
-
- #ifndef __WRITELINEWINDOW__
- #include "WriteLineWindow.h"
- #endif
-
- #ifndef __MEMORY__
- #include <Memory.h>
- #endif
-
- #ifndef __LIMITS__
- #include <Limits.h>
- #endif
-
- #ifndef __PLSTRINGFUNCS__
- #ifndef THINK_CPLUS
- #include <PLStringFuncs.h>
- #else
- #include "PLStringFuncs.h"
- #endif
- #endif
-
- #ifndef __SYSEQU__
- #include <SysEqu.h>
- #endif
-
- #ifndef __ERRORS__
- #include <Errors.h>
- #endif
-
- #ifndef __EVENTS__
- #include <Events.h>
- #endif
-
- #ifndef __OSEVENTS__
- #include <OSEvents.h>
- #endif
-
- #ifndef __STDIO__
- #include <stdio.h>
- #endif
-
- /***********************************|****************************************/
-
-
- const short kWWHMargin = 5;
- const short kWWVMargin = 10;
- const short kForceDepth = 16;
-
- enum { forceUnchanged, forceOn, forceOff };
-
- const short CODEV = 1; //console device number
-
- typedef struct ForceState {
- Boolean toWindow;
- Boolean toFile;
- } ForceState;
-
- /***********************************|****************************************/
-
- WindowPtr gDebugWindowPtr;
- short gLines;
- short gPerLine; //number of characters per line
- long gTotal; //number of characters in all lines together
- char** gText; //the ring buffer: blanks pad each line to 80 chars
- long** gLineLens; /*# of real characters in each line; (*gLinesLens)^[0]
- is # of characters in the line that begins with
- (*gText)^[0]*/
-
- long gFirst; //where in the ring buffer the top line starts
- long gLast; //where in the ring buffer the bottom line starts
- short gPos; //number of characters so far in the bottom line
-
- short gHeight; //font height
- short gLnAscent; //font ascent
- short gWidMax; //font char width (must be monospaced)
- ControlHandle gSBars[2]; //the window scroll bars
- Point gScrollOffset; //the position to which we are scrolled
- Point gViewSize; //total view size
- Point gEndOfText; //the pen position after drawing all the lines
-
- Rect gStdDrag;
- Rect gStdSize;
- VHSelect gOrthogonal[2];
- WindowRecord gWRec;
- RgnHandle gARgn;
-
- Boolean gGotRefNum;
- short gRefNum; //refNum for redirect output
- short gVRefNum; //likewise, vrefNum
-
- ForceState gForceStack[kForceDepth];
- short gForcePtr;
-
- char* gHexStr = "0123456789abcdef";
-
- Boolean gScrollWindowWhenTextIsAdded ;
- Boolean gWrToWindow = false;
- Boolean gWrToFile = false;
-
-
- /***********************************|****************************************/
-
- void WWInstall(void);
- long WWBaseLine(short ln);
- void WWDoScrolling(void);
- void WWFlushOutputFile(void);
- void WWNewLine(void);
- void WWTrackScroll(ControlHandle aControl, short partCode);
- void WWShowPoint(Point pt);
-
- /***********************************|****************************************/
-
- #pragma segment WWSeg
- RgnHandle GetSaveVisRgn(void)
- {
- const long addr = 0x09F2;
-
- return * (RgnHandle *) addr;
- }
-
- #pragma segment WWSeg
- VHSelect LongerSide(Rect& r)
- {
- if ((r.bottom - r.top) >= (r.left - r.right))
- return v;
- else
- return h;
- }
-
-
- #pragma segment WWSeg
- void WindowFocus(void)
- {
- SetPort(gDebugWindowPtr);
- SetOrigin(0, 0);
- ClipRect(&qd.thePort->portRect);
- }
-
-
- #pragma segment WWSeg
- void ContentFocus(void)
- { Rect r;
-
- SetPort(gDebugWindowPtr);
- SetOrigin(gScrollOffset.h, gScrollOffset.v);
- r = qd.thePort->portRect;
- r.right = r.right - 15;
- r.bottom = r.bottom - 15;
- ClipRect(&r);
- }
-
-
- #pragma segment WWInit
- void WWInit(short numLines, short numCharsPerLine)
- {
- gDebugWindowPtr = NULL;
-
- gGotRefNum = false;
- gWrToWindow = true;
- gWrToFile = true;
- gScrollWindowWhenTextIsAdded = false;
- WWInstall();
-
- gForcePtr = 0;
-
- gLines = numLines;
- gPerLine = numCharsPerLine;
- gTotal = gLines * gPerLine;
-
- gText = (char **) NewHandleClear(gTotal);
- if (gText == NULL)
- {
- DebugStr ("\pNot enough memory to allocate the Debug Window''s Line Array: " );
- return ;
- }
-
- gLineLens = (long **) NewHandleClear (gLines*sizeof(long));
- if (gLineLens == NULL)
- {
- DisposeHandle(Handle(gText));
- DebugStr ("\pNot enough memory to allocate the Debug Window''s LineLen Array: ");
- return;
- }
-
- gFirst = 0;
- gLast = gTotal - gPerLine;
- gPos = 0;
-
- gOrthogonal[v] = h;
- gOrthogonal[h] = v;
- }
-
-
- #pragma segment WWInit
- void WWNew(Rect bounds, Str255 windowTitle, Boolean goAway, Boolean visible, short outputFont, short outputSize)
- { FontInfo fInfo;
- GrafPtr savePort;
-
- GetPort(&savePort);
- if (gDebugWindowPtr == NULL)
- {
- gDebugWindowPtr = NewWindow(nil, &bounds, windowTitle, visible, documentProc, (WindowPtr) -1, goAway, 0);
-
- SetRect(&gStdDrag, 4, 24, qd.screenBits.bounds.right - 4, qd.screenBits.bounds.bottom - 4); //this is suggested in Inside Macintosh
- SetRect(&gStdSize, 20, 20, qd.screenBits.bounds.right, qd.screenBits.bounds.bottom - 20); //arbitrary Minimum size; Maximum size is screen
-
- gARgn = NewRgn();
-
- SetPt(&gEndOfText, kWWHMargin, (short) WWBaseLine(gLines));
-
- SetPort(gDebugWindowPtr);
- TextFont(outputFont);
- TextSize(outputSize);
- GetFontInfo(&fInfo);
-
- gHeight = fInfo.ascent + fInfo.descent + fInfo.leading;
- gLnAscent = fInfo.ascent;
- gWidMax = fInfo.widMax;
- SetPt(&gViewSize, (2 * kWWHMargin) + (gPerLine * fInfo.widMax), (2 * kWWVMargin) + (gHeight * gLines));
-
- //scroll bars
- for ( VHSelect vhs = v; vhs <= h; ++ vhs ) {
- gSBars[vhs] = NewControl(gDebugWindowPtr, &gDebugWindowPtr->portRect, "\p", false, 0, 0, 1, scrollBarProc, 0);
- }
-
- gScrollOffset.v = gScrollOffset.h = 0;
-
- //put the scroll bars in the right place
- WWGrown();
-
- //force an update
- WWUpdateEvent();
-
- //scroll to the end, in case there is some information that needs to be displayed
- SetCtlValue(gSBars[v], LONG_MAX);
- WWDoScrolling();
- }
- SetPort(savePort);
- }
-
- #pragma segment WWInit
- void WWNewDefault(void)
- { Rect aRect;
- Str255 title ;
-
- SetRect (&aRect, 16, 40, 16+6*80+16, 40+12*36);
- PLstrcpy ( title, (StringPtr) CurApName );
- PLstrcat ( title, "\p Debug Window");
-
- WWNew (aRect, title, true, true, 1, 9);
- }
-
-
-
- #pragma segment WWSeg
- void WWActivateEvent(short modifiers)
- { Rect r;
- GrafPtr savePort;
-
- GetPort(&savePort);
-
- WindowFocus();
-
- r = qd.thePort->portRect;
-
- if ( modifiers & 0x01 )
- {
- ShowControl ( gSBars[v] );
- ShowControl ( gSBars[h] );
- }
- else
- {
- HideControl ( gSBars[v] );
- HideControl ( gSBars[h] );
- }
-
- DrawGrowIcon(gDebugWindowPtr);
-
- SetPort(savePort);
- }
-
-
- #pragma segment WWSeg
- void WWAddText(Ptr textBuf, long byteCount)
- {
- char const BS = 8;
- Boolean gotEOL;
- QDByte b;
- Ptr startPtr;
- long startCount;
- PenState ps;
- GrafPtr savePort;
- Boolean deleted;
- Rect r;
-
- long count;
- long filePos ;
-
- if (gWrToFile)
- if (gGotRefNum)
- {
- count = byteCount;
- if ( FSWrite(gRefNum, &count, textBuf) != noErr )
- {
- }
- if ( GetFPos (gRefNum, &filePos) == noErr)
- if ( SetEOF (gRefNum, filePos) == noErr )
- WWFlushOutputFile();
- }
-
- if (gWrToWindow)
- {
- if (gDebugWindowPtr != NULL)
- GetPort(&savePort);
-
- deleted = false;
-
- while ( byteCount > 0){
- gotEOL = false;
- startPtr = textBuf;
- startCount = byteCount;
-
- while ( (byteCount > 0) && (gPos < gPerLine) && (!gotEOL)){
- b = (*QDPtr(textBuf));
- byteCount = byteCount - 1;
- textBuf = Ptr(((long)textBuf) + 1);
-
- if (b == '\n')
- gotEOL = true;
- else if (b != BS)
- {
- (*gText)[gLast+gPos++] = b;
- gPos = gPos + 1;
- }
- else if (gPos > 0) // Backspace -- don't backspace past beginning of line!
- {
- SetRect(&r, gEndOfText.h - gWidMax, gEndOfText.v - gLnAscent, gEndOfText.h, gEndOfText.v + gHeight - gLnAscent);
- gEndOfText.h = gEndOfText.h - gWidMax;
-
- if (gDebugWindowPtr != NULL)
- {
- ContentFocus();
- EraseRect(&r);
- }
-
- gPos--;
- deleted = true;
- }
- else
- deleted = true;
- }
-
- if (!deleted && (gDebugWindowPtr != NULL))
- {
- ContentFocus();
- MoveTo(gEndOfText.h, gEndOfText.v);
- DrawText(QDPtr(startPtr), 0, (short) (startCount - byteCount - gotEOL) );
- GetPenState(&ps);
- gEndOfText = ps.pnLoc;
- }
-
- if ((gPos >= gPerLine) || gotEOL)
- {
- (*gLineLens)[gLast / gPerLine] = gPos; //remember # characters in this line
-
- WWNewLine();
- if ((byteCount > 0) && (!gotEOL))
- {
- (*gText)[gLast] = '…';
- gPos = 1;
- }
- }
- }
-
- (*gLineLens)[gLast / gPerLine] = gPos;
-
- if (gDebugWindowPtr != NULL)
- SetPort(savePort);
- }
- }
-
- void WWFlushOutputFile(void)
- {
- if ( gWrToFile )
- { ParamBlockRec pb;
-
- pb.ioParam.ioRefNum = gRefNum;
-
- PBFlushFileSync(&pb);
- }
- }
-
-
- #pragma segment WWSeg
- long WWBaseLine(short ln)
- {
- return kWWVMargin + (ln - 1) * gHeight;
- }
-
-
- #pragma segment WWSeg
- void WWDoScrolling(void)
- { Point newOffset;
- Point delta;
-
- newOffset.v = GetCtlValue(gSBars[v]);
- delta.v = gScrollOffset.v - newOffset.v;
- newOffset.h = GetCtlValue(gSBars[h]);
- delta.h = gScrollOffset.h - newOffset.h;
-
- if ((delta.h != 0) || (delta.v != 0))
- {
- ContentFocus();
-
- ScrollRect(&qd.thePort->portRect, delta.h, delta.v, gARgn);
- gScrollOffset = newOffset;
-
- InvalRgn(gARgn);
-
- WWUpdateEvent();
- }
- }
-
-
- #pragma segment WWSeg
- void WWDraw(void)
- {
- short y;
- long start;
- long line;
- PenState ps;
-
- y = kWWVMargin; //initial y corodinate
-
- start = gFirst; //offset to first character of next line to draw
- line = start / gPerLine; //index into gLineLens array for next line to draw; always start / gPerLine
-
- for ( short i = 1; i <= gLines; ++i )
- {
- MoveTo(kWWHMargin, y);
-
- HLock(Handle(gText));
- DrawText(QDPtr((*gText)), (short) start, (short) (*gLineLens)[line]);
- HUnlock(Handle(gText));
-
- y += gHeight;
- start = start + gPerLine;
- line++;
-
- if (start == gTotal)
- {
- start = line = 0;
- }
- }
-
- GetPenState(&ps); //remember position of last character drawn
- gEndOfText = ps.pnLoc;
- }
-
-
- #pragma segment WWSeg
- void WWEndForce(void)
- {
- if (gForcePtr > 0)
- {
- gWrToWindow = gForceStack[gForcePtr].toWindow;
- gWrToFile = gForceStack[gForcePtr].toFile;
- gForcePtr--;
- }
- }
-
-
- #pragma segment WWSeg
- void WWForceOutput(short wrToWindow, short wrToFile)
- {
- if (gForcePtr < kForceDepth)
- {
- gForcePtr++;
-
- gForceStack[gForcePtr].toWindow = gWrToWindow;
- gForceStack[gForcePtr].toFile = gWrToFile;
-
- if (wrToWindow != forceUnchanged)
- gWrToWindow = wrToWindow == forceOn;
-
- if (wrToFile != forceUnchanged )
- gWrToFile = wrToFile == forceOn;
- }
- }
-
-
- #pragma segment WWSeg
- void WWGrown(void)
- { Rect r;
- ControlHandle anSBar;
- short newMax;
- GrafPtr savePort;
-
- GetPort(&savePort);
-
- WindowFocus();
- SetRect (&r, 0, 0, 0, 0 );
- ClipRect(&r);
-
- for (VHSelect vhs = v; vhs <= h; ++vhs )
- {
- anSBar = gSBars[vhs];
-
- r = qd.thePort->portRect;
-
- // Calculate new position of scroll bar
- (( short *) &r.top)[vhs] = (( short *) &r.top)[vhs] - 1;
- (( short *) &r.top)[gOrthogonal[vhs]] = (( short *) &r.bottom)[gOrthogonal[vhs]] - 15;
- (( short *) &r.bottom)[vhs] = (( short *) &r.bottom)[vhs] - 14;
- (( short *) &r.bottom)[gOrthogonal[vhs]] = (( short *) &r.top)[gOrthogonal[vhs]] + 16;
-
- //Move the scroll bar
- MoveControl(anSBar, r.left, r.top);
- SizeControl(anSBar, r.right-r.left, r.bottom-r.top);
-
- if ( vhs == v )
- newMax = gViewSize.v - (r.bottom - r.top);
- else
- newMax = gViewSize.h - (r.right - r.left );
-
- if (newMax < 0)
- newMax = 0;
- SetCtlMax(anSBar, newMax);
- }
-
- WWInvalGrowBox();
-
- WWDoScrolling(); //in case we are showing too much white space
-
- SetPort(savePort);
- }
-
-
- #pragma segment WWSeg
- void WWInvalGrowBox(void)
- { Rect r;
-
- r = qd.thePort->portRect;
- r.top = r.bottom - 15;
- r.left = r.right - 15;
-
- InvalRect(&r);
- }
-
-
- #pragma segment WWSeg
- void WWMouseDown(short where, Point pt, short modifiers)
- { GrafPtr savePort;
- ((void*) &modifiers);
-
- GetPort(&savePort);
-
- switch (where) {
- case inDrag:
- DragWindow(gDebugWindowPtr, pt, &gStdDrag);
- break;
-
- case inGrow:
- WindowFocus();
-
- long growResult = GrowWindow(gDebugWindowPtr, pt, &gStdSize);
- if (growResult != 0)
- { short newH = (short) (growResult & 0xffff );
- short newV = (short) (growResult >> 16);
- WWInvalGrowBox();
- SizeWindow(gDebugWindowPtr, newH, newV, true);
- WWGrown();
- }
- break;
-
- case inGoAway:
- if (TrackGoAway(gDebugWindowPtr, pt))
- HideWindow(gDebugWindowPtr);
- break;
-
- case inContent:
- if (gDebugWindowPtr == FrontWindow())
- {
- WindowFocus();
- GlobalToLocal(&pt);
-
- ControlHandle whichControl;
- long partCode = FindControl(pt, gDebugWindowPtr, &whichControl);
- switch (partCode)
- {
- case inUpButton:
- case inDownButton:
- case inPageUp:
- case inPageDown:
- partCode = TrackControl(whichControl, pt, (ProcPtr) &WWTrackScroll);
- break;
-
- case inThumb:
- partCode = TrackControl(whichControl, pt, NULL);
- WWDoScrolling();
- break;
-
- case 0:
- break;
- }
- }
- else
- SelectWindow(gDebugWindowPtr);
-
- break;
- }
-
- SetPort(savePort);
- }
-
-
- #pragma segment WWSeg
- void WWNewLine(void)
- { GrafPtr savePort;
- Point pt;
- Rect r;
-
- GetPort(&savePort);
-
- SetPt(&pt, kWWHMargin, gEndOfText.v);
-
- if ( gScrollWindowWhenTextIsAdded )
- WWShowPoint(pt);
-
- gLast = gFirst;
- gPos = 0;
- (*gLineLens)[gLast / gPerLine] = gPos; //remember # characters in new line
-
- gFirst = gFirst + gPerLine;
- if (gFirst == gTotal)
- gFirst = 0;
-
- SetPt(&gEndOfText, kWWHMargin, (short) WWBaseLine(gLines));
-
- if ( gDebugWindowPtr )
- {
- ContentFocus();
-
- SetRect(&r, kWWHMargin, kWWVMargin - gLnAscent, gViewSize.h, gEndOfText.v + gHeight - gLnAscent);
- ScrollRect(&r, 0, -gHeight, gARgn);
- InvalRgn(gARgn);
-
- WWUpdateEvent();
- }
-
- SetPort(savePort);
- }
-
-
- OSErr WWRedirect(short vRefNum, long dirID, Str255 fileNameBase)
- { OSErr err;
- Boolean append;
- long x;
-
- if (gGotRefNum)
- {
- // Truncate the file to current position
- err = GetFPos(gRefNum, &x);
- err = SetEOF(gRefNum, x);
-
- if (FSClose(gRefNum) != noErr) /*??? error closing file ???*/;
- if (FlushVol(NULL, gVRefNum) != noErr) /*??? Another fine mess ???*/;
- gGotRefNum = false;
- }
-
- Str255 fileName;
- PLstrcpy ( fileName, fileNameBase );
-
- append = false;
-
- if (PLstrlen(fileName) > 0 )
- {
- err = HCreate(vRefNum, dirID, fileName, 'MACA', 'TEXT');
-
- if ((err == noErr) || (err == dupFNErr))
- {
- err = HOpen(vRefNum, dirID, fileName, fsRdWrPerm, &gRefNum);
- gVRefNum = vRefNum;
-
- gGotRefNum = err == noErr;
-
- if (gGotRefNum)
- if (append)
- {
- err = GetEOF(gRefNum, &x);
- err = SetFPos(gRefNum, fsFromStart, x);
- }
- else
- err = SetEOF (gRefNum, 0);
- else
- err = noErr;
- }
- }
- return noErr;
- }
-
- void WWScroll(short howManyLines)
- { short val;
- GrafPtr savePort;
-
- GetPort(&savePort);
- val = GetCtlValue(gSBars[v]);
- if (((howManyLines < 0) && (val > GetCtlMin(gSBars[v]))) ||
- ((howManyLines > 0) && (val < GetCtlMax(gSBars[v]))))
- {
- SetCtlValue(gSBars[v], val + howManyLines * gHeight);
- WWDoScrolling();
- }
- SetPort(savePort);
- }
-
-
- void WWShowPoint(Point pt)
- { Point minToSee;
- short deltaCd;
-
- if (gDebugWindowPtr != NULL)
- {
- WindowFocus();
-
- SetPt(&minToSee, 50, gHeight);
-
- // the following code is actually better than writing a loop with VHSelect
- deltaCd = pt.v + minToSee.v - (qd.thePort->portRect.bottom - 15 + gScrollOffset.v);
- if (deltaCd <= 0)
- {
- deltaCd = pt.v - minToSee.v - (qd.thePort->portRect.top + gScrollOffset.v);
- if (deltaCd >= 0)
- deltaCd = 0;
- }
- SetCtlValue(gSBars[v], GetCtlValue(gSBars[v]) + deltaCd);
-
- deltaCd = pt.h + minToSee.h - (qd.thePort->portRect.right - 15 + gScrollOffset.h);
- if (deltaCd <= 0)
- {
- deltaCd = pt.h - minToSee.h - (qd.thePort->portRect.left + gScrollOffset.h);
- if (deltaCd >= 0)
- deltaCd = 0;
- }
- SetCtlValue(gSBars[h], GetCtlValue(gSBars[h]) + deltaCd);
-
- WWDoScrolling();
- }
- }
-
-
- #pragma segment WWSeg
- void WWTrackScroll(ControlHandle aControl, short partCode)
- { Boolean up;
- short ctlValue;
- VHSelect vhs;
- Rect r;
- short delta;
-
- if (partCode != 0)
- {
- up = (partCode == inUpButton) || (partCode == inPageUp);
- ctlValue = GetCtlValue(aControl);
-
- //avoid flicker in setting thumb, if (user tries to scroll past end
- if ((up && (ctlValue > GetCtlMin(aControl))) ||
- (!up && (ctlValue < GetCtlMax(aControl))))
- {
- r = (*aControl)->contrlRect; //heap may compact when we call LongerSide
- vhs = LongerSide(r); //this tells us which way we are scrolling
-
- if ((partCode == inPageUp) || (partCode == inPageDown))
- if ( vhs == v )
- delta = gDebugWindowPtr->portRect.bottom - gDebugWindowPtr->portRect.top;
- else
- delta = gDebugWindowPtr->portRect.right - gDebugWindowPtr->portRect.left;
- else
- delta = gHeight;
-
- if (up)
- delta = - delta;
-
- SetCtlValue(aControl, ctlValue + delta);
- WWDoScrolling();
-
- WindowFocus();
- }
- }
- }
-
-
- #pragma segment WWSeg
- void WWUpdateEvent(void)
- { GrafPtr savePort;
- RgnHandle saveSaveVisRgn;
- RgnHandle saveVisRgn;
-
- if ((gDebugWindowPtr != NULL) &&
- (!EmptyRgn( ((WindowPeek)gDebugWindowPtr)->port.visRgn)))
- {
- GetPort(&savePort);
-
- saveSaveVisRgn = NewRgn();
- saveVisRgn = GetSaveVisRgn();
-
- CopyRgn(saveVisRgn, saveSaveVisRgn);
-
- BeginUpdate(gDebugWindowPtr);
-
- WindowFocus();
-
- EraseRect(&qd.thePort->portRect);
-
- DrawGrowIcon(gDebugWindowPtr);
- DrawControls(gDebugWindowPtr);
-
- ContentFocus();
- WWDraw();
-
- EndUpdate(gDebugWindowPtr);
-
- CopyRgn(saveSaveVisRgn, saveVisRgn);
- DisposeRgn(saveSaveVisRgn);
-
- SetPort(savePort);
- }
- }
-
-
- #pragma segment WWSeg
- char WWReadCh(void)
- { GrafPtr savePort;
- char ch;
- EventRecord anEvent;
- Rect r;
-
- GetPort(&savePort);
-
- ContentFocus();
-
- SetRect(&r, gEndOfText.h, gEndOfText.v - gLnAscent, gEndOfText.h + gWidMax, gEndOfText.v + gHeight - gLnAscent);
-
- FillRect(&r, &qd.black);
- while ( GetOSEvent(keyDownMask+autoKeyMask, &anEvent))
- ;
- EraseRect(&r);
-
- ch = char(((anEvent.message) & charCodeMask));
-
- SetPort(savePort);
-
- return ch;
- }
-
-
- #pragma segment WWSeg
- long WWReadLn(Ptr buffer, short byteCount)
- {
- const char CR = 13;
- const char BS = 8;
-
- short len = 0;
- char ch;
- do {
- ch = WWReadCh();
- if (ch != BS )
- {
- WWAddText(&ch, 1);
- buffer[len++] = ch;
- }
- else if (len > 0)
- {
- WWAddText(&ch, 1);
- buffer[--len] = ' ';
- }
- } while ( ! ( (ch==CR) || (len == byteCount)) );
-
- return len;
- }
-
-
- void IDUWritelnWindow(void) //Writeln UWritelnWindow's compile time.
- {
- // Writeln('UWritelnWindow of ', COMPDATE, ' & ', COMPTIME);
- }
-
-
- long wwFAccess(Ptr fName, long opCode, long arg );
- long wwClose(long refNum);
- long wwRead(long fdesc, long bufp, long count );
- long wwWrite(long fdesc, long bufP, long count);
- long wwIoctl(long fdesc, long request, long arg );
-
- long _addDevHandler( long slot, Ptr dvName, ProcPtr dvFAccess, ProcPtr dvClose, ProcPtr dvRead, ProcPtr dvWrite, ProcPtr dvIoctl );
-
- void WWInstall(void)
- { long slot = _addDevHandler(CODEV, 0,
- (ProcPtr) wwFAccess, (ProcPtr) wwClose, (ProcPtr) wwRead, (ProcPtr) wwWrite, (ProcPtr) wwIoctl );
-
- setvbuf ( stdout, nil, 64, 100 );
- }
-
-
- /*
- -- Paul's Writeln routines ----------------------------------------------------------------
- */
- Boolean WWEvent(EventRecord& event )
- {
- WindowPtr WindowPointedTo; //window where the mouse is
- Point MouseLoc;
- short WindoPart; //component of window where mouse is
-
- switch ( event.what )
- {
- case mouseDown:
- {
- MouseLoc = event.where;
- WindoPart = FindWindow(MouseLoc, &WindowPointedTo);
-
- if ( (WindowPointedTo == gDebugWindowPtr))
- {
- if (WindowPointedTo != FrontWindow())
- SelectWindow(WindowPointedTo);
- else
- WWMouseDown(WindoPart, MouseLoc, event.modifiers);
- return true;
- }
- }
- break;
-
- case activateEvt:
- if (WindowPtr(event.message) == gDebugWindowPtr)
- {
- WWActivateEvent(event.modifiers);
- return true;
- }
- break;
-
- case updateEvt:
- if (WindowPtr(event.message) == gDebugWindowPtr)
- {
- WWUpdateEvent();
- return true;
- }
- break;
- }
- } //WWEvent
-
- /*
- -- end Writeln routines ------------------------------------------------------------
- */
-
- /*
- -- Keith's WriteLineWindow routines --------------------------------------------------
- */
- #if 0
-
- void WWAddDate(void)
- VAR
- long dateTime ;
- Str255 tempStr255 ;
- {
- GetDateTime (dateTime);
- IUDateString(dateTime, shortDate, tempStr255);
- write (tempStr255, ' ');
- }
-
- void WWAddTime(void)
- VAR
- long dateTime ;
- Str255 tempStr255 ;
- {
- GetDateTime (dateTime);
- IUTimeString(dateTime, true, tempStr255);
- write (tempStr255, ' ');
- }
-
- void WWAddDateTime(void)
- {
- WWAddDate();
- WWAddTime();
- }
- #endif
-
- void WWAddEncodedText (Ptr dataPtr, long size)
- {
- for ( short index = 0; index < size; ++index )
- {
- char c = dataPtr[index];
- switch ( c )
- {
- case 0: case 128: c = 'ø'; break;
- case 8: case 136: c = 'Δ'; break;
-
- case 10: case 138: c = '◊'; break;
- case 13: case 141: c = '¬'; break;
- case 222: c = '∞'; break;
- }
- WWAddText ( &c, 1 );
- }
- }
-
- inline long IntegerMax (long a, long b )
- {
- return ( a > b ) ? a : b;
- }
-
- Str255& NumToHexStringF(long theNumber)
- { Str255 returnStr;
-
- returnStr[0] = sprintf ((char*) &returnStr[1], "%8x", theNumber );
-
- return returnStr;
- }
-
- /***********************************|****************************************/
-
- void WWAddHexData (Ptr dataPtr, short dataSize )
- {
- long index ;
- Str255 result ;
- short len ;
- char byte ;
-
- if ( !dataPtr )
- {
- DebugStr ("\pNo data dump, NULL data ptr");
- return;
- }
-
- if ( dataSize <= 0 )
- {
- DebugStr ("\pNo data dump, datesize <= 0");
- return;
- }
-
- long offset = 0;
-
- while (offset < dataSize)
- {
- #if 0
- WWAddText (
- write ( NumToHexStringF (offset), ':');
-
- // Put it into a Str255 because it's faster to add one string to the window than it is to add 16
- result = '';
- for index = 0 to 15
- do
- if offset + index < dataSize
- then
- begin
- len = length(result);
- byte = BytePtr(((long)dataPtr)+offset+index)^;
- result[len+1] = gHexStr[ ((byte) >> 4)];
- result[len+2] = gHexStr[ ((byte) & 0xF)];
- result[len+3] = ' ';
- //$PUSH*/ /*$R-*/ result[0] = ((char)(len + 3)); /*$POP
- end
- else
- begin
- result[len+1] = ' ';
- result[len+2] = ' ';
- result[len+3] = ' ';
- //$PUSH*/ /*$R-*/ result[0] = ((char)(len + 3)); /*$POP
- end();
- write (result, '| ');
-
- WWAddEncodedText ( Ptr(((long)dataPtr)+offset), IntegerMax(dataSize - offset, 16));
-
- offset = offset + 16;
- #endif
- }
- }
-
- void WWShowWindow(void)
- {
- ShowWindow (gDebugWindowPtr);
- }