summaryrefslogtreecommitdiff
path: root/sys/mac
diff options
context:
space:
mode:
Diffstat (limited to 'sys/mac')
-rw-r--r--sys/mac/MacAE.c58
-rw-r--r--sys/mac/MacCommandWin.c764
-rw-r--r--sys/mac/MacCommandWin.h17
-rw-r--r--sys/mac/MacDrag.h3
-rw-r--r--sys/mac/MacFileUtils.c81
-rw-r--r--sys/mac/MacFileUtils.h3
-rw-r--r--sys/mac/MacGlobals.h50
-rw-r--r--sys/mac/MacHandleEv.c64
-rw-r--r--sys/mac/MacHandleEv.h3
-rw-r--r--sys/mac/README.txt55
-rw-r--r--sys/mac/macaboutbox.c123
-rw-r--r--sys/mac/macaboutbox.h3
-rw-r--r--sys/mac/macdrag.c161
-rw-r--r--sys/mac/macfun.c222
-rw-r--r--sys/mac/macint.c521
-rw-r--r--sys/mac/macint.h166
-rw-r--r--sys/mac/macptrs.h52
-rw-r--r--sys/mac/macstuff.c226
-rw-r--r--sys/mac/macstuff.h7
-rw-r--r--sys/mac/sndsystem.h2
-rw-r--r--sys/mac/switches.h58
-rw-r--r--sys/mac/system.lsp107
-rw-r--r--sys/mac/xlextstart.c1
23 files changed, 2747 insertions, 0 deletions
diff --git a/sys/mac/MacAE.c b/sys/mac/MacAE.c
new file mode 100644
index 0000000..34b9224
--- /dev/null
+++ b/sys/mac/MacAE.c
@@ -0,0 +1,58 @@
+/* Handle required apple events -EAD */
+
+#include <Files.h>
+#include <string.h>
+#include <AppleEvents.h>
+#include "macstuff.h"
+#include "MacCommandWin.h"
+#include "MacFileUtils.h"
+//#include "MiscellaneousUtilities.h"
+
+#define TEXTREC (*hTERec) // the command
+extern TEHandle hTERec; // window text record
+
+
+//=========================================================================
+// Handle quit apple event
+//=========================================================================
+
+pascal OSErr AEQuit (AppleEvent *theAppleEvent, AppleEvent *theReply, long Refcon)
+{
+ osfinish();
+}
+
+//=========================================================================
+// Handle Open Document apple event by trying to load it.
+//=========================================================================
+extern xlload (char *, int, int);
+extern xlabort(char *);
+
+pascal OSErr AEOpenFiles(AppleEvent *theAppleEvent, AppleEvent *theReply,
+ long Refcon)
+{
+ AEDescList docList;
+ AEKeyword keywd;
+ DescType returnedType;
+ Size actualSize;
+ long itemsInList;
+ FSSpec theSpec;
+ CInfoPBRec pb;
+ Str255 name;
+ short i;
+
+ if (AEGetParamDesc(theAppleEvent, keyDirectObject, typeAEList, &docList) !=
+ noErr) return;
+ if (AECountItems (&docList, &itemsInList) != noErr) return;
+
+ SetSelection (TEXTREC->teLength, TEXTREC->teLength);
+ for (i = 1; i <= itemsInList; i++) {
+ AEGetNthPtr (&docList, i, typeFSS, &keywd, &returnedType,
+ (Ptr) &theSpec, sizeof(theSpec), &actualSize);
+
+ GetFullPath(&theSpec, name);
+ P2CStr(name); // was: pstrterm(name);
+ if (xlload ((char *)name + 1, 1, 0) == 0) xlabort ("load error");
+ }
+ macputs ("> ");
+ PrepareForInput ();
+}
diff --git a/sys/mac/MacCommandWin.c b/sys/mac/MacCommandWin.c
new file mode 100644
index 0000000..c3336aa
--- /dev/null
+++ b/sys/mac/MacCommandWin.c
@@ -0,0 +1,764 @@
+//=============================================================================
+// All command window updates, input, etc happen here -EAD
+//=============================================================================
+#include <Controls.h>
+/* #include <ControlDefinitions.h> */
+#include <Events.h>
+#include <Fonts.h>
+#include <MacWindows.h>
+#include "MacGlobals.h"
+#include "macint.h"
+#include <ctype.h>
+#define NIL ((void *) 0)
+
+//=============================================================================
+// local variables
+//=============================================================================
+
+ControlHandle vScroll;
+int cursorPos; /* the cursor's position on the line */
+short linesInView; /* how many lines are in the window */
+int cmdStart; /* where (in text record) the current command starts */
+TextStyle textStyle[2]; /* styles: bold for user input, plain for output */
+/* output is buffered */
+Handle hOutputBuffer = NULL;
+enum currentStyle { plainStyle, boldStyle } currentStyle;
+
+static void GoStartOfLine (void);
+static void GoEndOfLine (void);
+static void GoBackOneWord (void);
+static void GoForwardOneWord (void);
+
+//=============================================================================
+// static void DoScrollBar (ControlHandle control, short change)
+//=============================================================================
+/* keep track of the user as he fiddles with the scroll bar */
+/* This routine is called while the user has the mouse down. */
+/* It makes sure the thumb isn't dragged out-of-bounds. */
+//=============================================================================
+
+static void DoScrollBar (ControlHandle control, short change) {
+ short value = GetControlValue (control), max = GetControlMaximum (control);
+ long newval = value + change; /* this is a long in case we try to go past MAX_INT */
+ if (newval < 0) newval = 0; else if (newval > max) newval = max;
+ SetControlValue (control, (short) newval);
+ if (newval != value) TEScroll (0, (short) (value - newval) * LINEHEIGHT, hTERec);
+}
+
+//=============================================================================
+// pascal Boolean ScrollClickLoop (void)
+//=============================================================================
+//
+//=============================================================================
+
+pascal Boolean ScrollClickLoop (void) {
+ Rect tempRect;
+ Point mouse;
+ GrafPtr oldPort;
+ RgnHandle oldClip;
+ short amount = 0;
+
+ if (FrontWindow () != gCommandWin) return false;
+
+ GetPort (&oldPort);
+ SetPort (gCommandWin);
+ GetClip (oldClip = NewRgn ());
+ SetRect (&tempRect, INT_MIN, INT_MIN, INT_MAX, INT_MAX);
+ ClipRect (&tempRect);
+
+ GetMouse (&mouse);
+ if (mouse.v < TEXTREC->viewRect.top) DoScrollBar (vScroll, -1);
+ else if (mouse.v > TEXTREC->viewRect.bottom) DoScrollBar (vScroll, 1);
+
+ SetClip (oldClip);
+ DisposeRgn (oldClip);
+ SetPort (oldPort);
+ return true;
+}
+
+//=============================================================================
+// static pascal void ScrollProc (ControlHandle control, short thePart)
+//=============================================================================
+// for clicks in the scroll bar or arrows; update the window properly
+//=============================================================================
+
+pascal void ScrollProc (ControlHandle control, short thePart) {
+ short amount;
+ WindowPtr window;
+
+ if (!thePart) return;
+ window = (*control)->contrlOwner;
+ switch (thePart) {
+ case kControlUpButtonPart: amount = -1; break;
+ case kControlDownButtonPart: amount = 1; break;
+ case kControlPageUpPart: amount = -linesInView; break;
+ case kControlPageDownPart: amount = linesInView; break;
+ }
+ DoScrollBar (control, amount);
+}
+
+//=============================================================================
+// Rect SetTERect (void)
+//=============================================================================
+// set the dimensions of the text record in its window
+//=============================================================================
+
+Rect SetTERect (void) {
+ Rect teRect = gCommandWin->portRect;
+ teRect.right -= SCROLLER_WIDTH;
+ InsetRect (&teRect, TEXT_MARGIN, TEXT_MARGIN);
+ linesInView = (teRect.bottom - teRect.top) / LINEHEIGHT;
+ teRect.bottom = teRect.top + linesInView * LINEHEIGHT; /* round off */
+ return teRect;
+}
+
+//=============================================================================
+// static void AdjustCursor (EventRecord *theEvent)
+//=============================================================================
+// make the pointer an I-beam iff it's in the text window
+//=============================================================================
+
+void AdjustCursor (Point theLoc, RgnHandle theRgn)
+{
+ RgnHandle arrowRgn, iBeamRgn, hiliteRgn, tempRgn;
+ Rect theRect;
+ Point thePoint;
+
+ if (gInBackground)
+ return;
+
+ arrowRgn = NewRgn();
+ SetRectRgn(arrowRgn, -32767, -32767, 32767, 32767);
+
+// GlobalToLocal ((theLoc); ???
+
+ if (gCommandWin == FrontWindow () ) {
+ SetPort(gCommandWin);
+ iBeamRgn = NewRgn();
+ hiliteRgn = NewRgn();
+
+ theRect = TEXTREC->viewRect;
+ LocalToGlobal((Point *)&(theRect.top));
+ LocalToGlobal((Point *)&(theRect.bottom));
+ RectRgn(iBeamRgn, &theRect);
+
+ TEGetHiliteRgn(hiliteRgn, hTERec);
+ thePoint.h = thePoint.v = 0;
+ LocalToGlobal(&thePoint);
+ OffsetRgn(hiliteRgn, thePoint.h, thePoint.v);
+
+ DiffRgn(arrowRgn, hiliteRgn, arrowRgn);
+ DiffRgn(arrowRgn, iBeamRgn, arrowRgn);
+
+ DiffRgn(iBeamRgn, hiliteRgn, iBeamRgn);
+
+ if (PtInRgn(theLoc, iBeamRgn)) {
+ SetCursor(*GetCursor(iBeamCursor));
+ CopyRgn(iBeamRgn, theRgn);
+ } else if (PtInRgn(theLoc, hiliteRgn)) {
+ SetCursor(&qd.arrow);
+ CopyRgn(hiliteRgn, theRgn);
+ } else {
+ SetCursor(&qd.arrow);
+ CopyRgn(arrowRgn, theRgn);
+ }
+
+ DisposeRgn(iBeamRgn);
+ DisposeRgn(hiliteRgn);
+
+ } else {
+ SetCursor(&qd.arrow);
+ CopyRgn(arrowRgn, theRgn);
+ }
+
+ DisposeRgn(arrowRgn);
+}
+
+
+
+//=============================================================================
+// static void SetScrollRect (void)
+//=============================================================================
+// Set Scroll bar rec size
+//=============================================================================
+
+void SetScrollRect (void) {
+ /* set the dimensions of the scroll bar in its window */
+
+// This change fixes the double flash on window resize -EAD
+
+// MoveControl (vScroll, commandWin->portRect.right - SCROLLER_WIDTH, -1);
+// SizeControl (vScroll, SCROLLER_WIDTH + 1,
+// (commandWin->portRect.bottom - commandWin->portRect.top) - (SCROLLER_WIDTH - 2));
+ (*vScroll)->contrlRect.left = gCommandWin->portRect.right - SCROLLER_WIDTH;
+ (*vScroll)->contrlRect.top = -1;
+ (*vScroll)->contrlRect.right = gCommandWin->portRect.right + 1;
+ (*vScroll)->contrlRect.bottom = gCommandWin->portRect.bottom - (SCROLLER_WIDTH - 1);
+
+}
+
+//=============================================================================
+// static void AdjustScrollBar (void)
+//=============================================================================
+// Set the thumb on scrollbar
+//=============================================================================
+
+static void AdjustScrollBar (void) {
+ /* adjust the scroll bar to match the position of the text view */
+ short oldval = GetControlValue (vScroll), oldmax = GetControlMaximum (vScroll);
+ short value, max;
+ short test;
+
+ max = TEXTREC->nLines - linesInView;
+ if ((TEXTREC->teLength > 0) && (*(*TEXTREC->hText + TEXTREC->teLength - 1) == '\r')) max++;
+ if (max < 0) max = 0;
+ if (max != oldmax) SetControlMaximum (vScroll, max);
+ value = (short)((TEXTREC->viewRect.top - TEXTREC->destRect.top) / LINEHEIGHT);
+// value = roundup ((TEXTREC->viewRect.top - TEXTREC->destRect.top) / LINEHEIGHT);
+ if (value < 0) value = 0; else if (value > max) value = max;
+ if (value != oldval) SetControlValue (vScroll, value);
+}
+
+static short roundup (float x) { /* a kludge to round up a float to an int */
+ if (((int) x) != ((int) (x += 0.5))) x += 0.5;
+ return (int) x;
+}
+
+//=============================================================================
+// void DoKeyPress (EventRecord *theEvent)
+//=============================================================================
+// Hanlde Keyboard Input
+//=============================================================================
+
+void DoKeyPress (EventRecord *theEvent) {
+ short whatKey = theEvent->message & charCodeMask;
+ if (theEvent->modifiers & cmdKey) {
+ long choice;
+ AdjustMenus ();
+ if (choice = MenuKey (theEvent->message)) DoMenu (choice);
+ else if (((whatKey == 'w') || (whatKey == 'W')) && (FrontWindow () == gGraphicsWin))
+ HideGrafWin ();
+ else if (whatKey == LEFTARROW) GoStartOfLine ();
+ else if (whatKey == RIGHTARROW) GoEndOfLine ();
+ else if (whatKey == UPARROW) DoScrollBar (vScroll, - linesInView);
+ else if (whatKey == DOWNARROW) DoScrollBar (vScroll, linesInView);
+ }
+ else if (theEvent->modifiers & optionKey) {
+ if (whatKey == LEFTARROW) GoBackOneWord ();
+ else if (whatKey == RIGHTARROW) GoForwardOneWord ();
+ }
+ else switch (whatKey) {
+ case PAGEUP: DoScrollBar (vScroll, -linesInView); break;
+ case PAGEDN: DoScrollBar (vScroll, linesInView); break;
+ case HOMEKEY: DoScrollBar (vScroll, INT_MIN); break;
+ case ENDKEY: DoScrollBar (vScroll, INT_MAX); break;
+ case FNKEY: break;
+ case HELPKEY: break;
+ default: recentChar = theEvent->message & charCodeMask;
+ }
+}
+
+//=============================================================================
+// static void DrawOnlyGrowIcon (WindowPtr window)
+//=============================================================================
+// draw growbox on command window with no scoll bars
+//=============================================================================
+
+static void DrawOnlyGrowIcon (WindowPtr window)
+{
+ RgnHandle saveRgn;
+ Rect growRect;
+
+ growRect = window->portRect;
+ growRect.top = growRect.bottom - SCROLLER_WIDTH;
+ growRect.left = growRect.right - SCROLLER_WIDTH;
+ GetClip (saveRgn = NewRgn ());
+ ClipRect (&growRect);
+ DrawGrowIcon (window);
+ SetClip (saveRgn);
+ DisposeRgn (saveRgn);
+}
+
+//=============================================================================
+// void SetSelection (short start, short end)
+//=============================================================================
+// set text selection in the command window
+//=============================================================================
+
+void SetSelection (short start, short end) {
+ TEXTREC->clikStuff = 255; /* to make sure the caret appears at the start of a line when it should */
+ /* see tech note "TextEdit EOL Ambiguity" for more information */
+ TESetSelect (start, end, hTERec);
+}
+
+//=============================================================================
+// static void CancelFlash (void)
+//=============================================================================
+// cancel the matching-paren flashing
+//=============================================================================
+
+static void CancelFlash (void) {
+ if (flashTime) {
+ flashTime = 0;
+ SetSelection (cursorBeforeFlash, cursorBeforeFlash);
+ }
+}
+
+//=============================================================================
+// static void StopPasting (void)
+//=============================================================================
+// clean up after finishing a paste
+//=============================================================================
+
+void StopPasting (void) {
+ pastedLength = 0;
+ if (pastedTextH) {
+ DisposeHandle (pastedTextH);
+ pastedTextH = NULL;
+ }
+}
+
+//=============================================================================
+// static void DoStyle (int whatStyle)
+//=============================================================================
+// set the text to a certain style
+//=============================================================================
+
+static void DoStyle (int whatStyle) {
+ TESetStyle (doFace, &(textStyle[whatStyle]), false, hTERec);
+}
+
+//=============================================================================
+// static void FlushOutput (void)
+//=============================================================================
+// clear out the output buffer, dumping its contents to the window
+//=============================================================================
+
+void FlushOutput (void) {
+ short totalLines, scrollAmount, max;
+
+ if (outputBufferLength == 0) return;
+ CancelFlash ();
+ DoStyle (plainStyle);
+ HLock (hOutputBuffer);
+ TEInsert (*hOutputBuffer, outputBufferLength, hTERec);
+ HUnlock (hOutputBuffer);
+ outputBufferLength = 0;
+
+ if (TEXTREC->teLength > SCROLLBACK_THRESHHOLD) {
+ /* make sure TE record isn't too long */
+#ifdef ORIGINALCODE
+ /* I replaced this because Nyquist was crashing after the
+ buffer got filled. The replacement below is simpler and
+ eliminates the crashes, although it probably could cause
+ problems by clearing the selection.
+ */
+ int i = 1, newLength;
+ TEPtr textPtr;
+ while ((TEXTREC->teLength - TEXTREC->lineStarts[i]) >
+ (SCROLLBACK_THRESHHOLD - DELETE_BLOCK)) i++;
+ i = TEXTREC->lineStarts[i];
+ newLength = TEXTREC->teLength - i;
+ textPtr = (TEPtr)(*(TEXTREC->hText));
+ BlockMoveData ((Ptr)((long)textPtr + i), textPtr, newLength);
+ SetHandleSize (TEXTREC->hText, newLength);
+ TEXTREC->destRect.top += LINEHEIGHT;
+ TECalText (hTERec);
+ TEUpdate (&(TEXTREC->viewRect), hTERec);
+#else
+ /* find the line start after DELETE_BLOCK */
+ int i = 1;
+ while (TEXTREC->lineStarts[i] < DELETE_BLOCK) i++;
+ TESetSelect(0, TEXTREC->lineStarts[i], hTERec);
+ TEDelete(hTERec);
+ /* after deletion, put cursor back at end of buffer */
+ TESetSelect(TEXTREC->teLength, TEXTREC->teLength, hTERec);
+#endif
+ }
+ TESelView (hTERec);
+ AdjustScrollBar ();
+}
+
+//=============================================================================
+// void PrepareForInput (void)
+//=============================================================================
+// get ready to take input
+//=============================================================================
+
+void PrepareForInput (void) {
+ FlushOutput ();
+ cmdStart = TEXTREC->selStart;
+}
+
+//=============================================================================
+// static void DeleteRange (void)
+//=============================================================================
+// delete the selected range of text, updating cmdStart as necessary
+//=============================================================================
+
+void DeleteRange (void) {
+ if (TEXTREC->selEnd <= cmdStart) return;
+ if (TEXTREC->selStart < cmdStart) SetSelection (cmdStart, TEXTREC->selEnd);
+ TEDelete (hTERec);
+}
+
+//=============================================================================
+// static void CopyThisLineToEnd (void)
+//=============================================================================
+// copy the line the caret is on to the end
+//=============================================================================
+
+static void CopyThisLineToEnd (void) {
+ char *buffer;
+ short b, i, caretOffset;
+
+ /* first find out exactly where it starts */
+ i = TEXTREC->nLines-1; /* first find which line */
+ while (TEXTREC->selStart < TEXTREC->lineStarts[i]) i--;
+ while ((i > 0) && ((*(TEXTREC->hText))[TEXTREC->lineStarts[i]-1] != '\r'))
+ i--; /* for wrapped lines */
+ i = TEXTREC->lineStarts[i]; /* now zero in on the exact character where it begins */
+ while ((TEXTCHAR(i) >= '0') && (TEXTCHAR(i) <= '9')) i++; /* skip error level */
+ if ((TEXTCHAR(i) == '>') && (TEXTCHAR(i+1) == ' ')) i+=2; /* get rid of leading prompt */
+
+ caretOffset = TEXTREC->selStart - i; /* how many characters in is the caret? */
+
+ /* now put the line into the buffer */
+ b = 0;
+ while ((TEXTCHAR(i+b) != '\r') && (i+b < TEXTREC->teLength)) b++; /* find the end of the line */
+ buffer = (char *) NewPtr (b);
+ BlockMoveData (*TEXTREC->hText + i, buffer, b);
+ buffer[b] = '\0';
+
+ /* delete whatever's already on the last line */
+ SetSelection (cmdStart, TEXTREC->teLength);
+ TEDelete (hTERec);
+
+ DoStyle (boldStyle);
+ TEInsert (buffer, b, hTERec);
+ DisposePtr (buffer);
+
+ if (caretOffset < 0) caretOffset = b;
+ SetSelection (cmdStart + caretOffset, cmdStart + caretOffset);
+}
+
+//=============================================================================
+// Next four functions possition cursor in text
+//=============================================================================
+
+static void GoStartOfLine (void) {
+ short whichLine = TEXTREC->nLines - 1; /* look for the caret; start at the end and go up */
+ while (TEXTREC->lineStarts[whichLine] > TEXTREC->selStart) whichLine--;
+ SetSelection (TEXTREC->lineStarts[whichLine], TEXTREC->lineStarts[whichLine]);
+ AdjustScrollBar ();
+}
+
+static void GoEndOfLine (void) {
+ short whichLine = TEXTREC->nLines - 1; /* look for the caret; start at the end and go up */
+ while (TEXTREC->lineStarts[whichLine] > TEXTREC->selStart) whichLine--;
+ if (whichLine == TEXTREC->nLines - 1)
+ SetSelection (TEXTREC->teLength, TEXTREC->teLength);
+ else SetSelection (TEXTREC->lineStarts[whichLine+1] - 1, TEXTREC->lineStarts[whichLine+1] - 1);
+ AdjustScrollBar ();
+}
+
+static void GoBackOneWord (void) {
+ short i = TEXTREC->selStart;
+ while ((i > 0) && !isalnum (TEXTCHAR(i-1))) i--;
+ while ((i > 0) && isalnum (TEXTCHAR(i-1))) i--;
+ SetSelection (i, i);
+}
+
+static void GoForwardOneWord (void) {
+ short i = TEXTREC->selStart;
+ while ((i < TEXTREC->teLength) && !isalnum (TEXTCHAR(i))) i++;
+ while ((i < TEXTREC->teLength) && isalnum (TEXTCHAR(i))) i++;
+ SetSelection (i, i);
+}
+
+
+//=============================================================================
+// static void EditFreely (void)
+//=============================================================================
+// Enter text into the command windows
+//=============================================================================
+
+static void EditFreely (void) {
+ Boolean done;
+ do {
+ done = false;
+ DoEvent ();
+ if (pastedLength > 0) { /* if there is still text to paste, paste it */
+ int i = 0;
+ CancelFlash ();
+ if (TEXTREC->selStart < cmdStart) StopPasting ();
+ else {
+ while ((i < pastedLength) && (((char *)(*pastedTextH))[i] != '\r')) i++;
+ DoStyle (boldStyle);
+ TEInsert (*pastedTextH, i, hTERec);
+ AdjustScrollBar ();
+ if (i < pastedLength) { /* we were stopped by a carriage return, so eat it */
+ i++;
+ done = true;
+ }
+ pastedLength -= i;
+ if (pastedLength > 0) {
+ BlockMoveData ((Ptr)((long)(*pastedTextH) + i), *pastedTextH, pastedLength);
+ SetHandleSize (pastedTextH, pastedLength);
+ } else StopPasting ();
+ }
+ }
+ else if (recentChar) { /* if the last event got us a character, process it */
+ int i;
+ Boolean wasOnLastLine;
+ CancelFlash ();
+
+ if ((TEXTREC->selEnd <= cmdStart) && (TEXTREC->selStart != TEXTREC->selEnd)) continue;
+ if (TEXTREC->selStart < cmdStart) SetSelection (cmdStart, TEXTREC->selEnd);
+ wasOnLastLine = (TEXTREC->selStart >= cmdStart);
+
+ if ((recentChar & 0xfc) == 0x1c) { /* was this an arrow key? */
+ TEXTREC->clikStuff = 255; /* to make sure the caret appears where it should */
+ TEKey (recentChar, hTERec);
+ AdjustScrollBar ();
+ continue;
+ }
+ if (!wasOnLastLine) CopyThisLineToEnd ();
+ switch (recentChar) {
+ case FWDDEL:
+ if (TEXTREC->selStart != TEXTREC->selEnd) DeleteRange ();
+ else if ((TEXTREC->selStart >= cmdStart) && (TEXTREC->selStart < TEXTREC->teLength)) {
+ TEDeactivate (hTERec);
+ SetSelection (TEXTREC->selStart, TEXTREC->selStart + 1);
+ TEDelete (hTERec);
+ if (FrontWindow () == gCommandWin) TEActivate (hTERec);
+ }
+ break;
+ case CLRKEY:
+ if (TEXTREC->selStart != TEXTREC->selEnd) DeleteRange ();
+ break;
+ case DELETE:
+ if (TEXTREC->selStart != TEXTREC->selEnd) DeleteRange ();
+ else if (TEXTREC->selStart > cmdStart) {
+ TEXTREC->clikStuff = 255; /* to make sure the caret appears where it should */
+ TEKey (DELETE, hTERec);
+ }
+ break;
+ case RETURN:
+ if (wasOnLastLine) done = true;
+ break;
+ case ENTER: /* ENTER ends command no matter what */
+ done = true;
+ break;
+ default:
+ DoStyle (boldStyle);
+ TEXTREC->clikStuff = 255; /* to make sure the caret appears where it should */
+ TEKey (recentChar, hTERec);
+ if ((recentChar == ')') && (TEXTREC->selStart > cmdStart)) {
+ short parenCount = -1;
+ Boolean inQuotes = false;
+ i = TEXTREC->selStart - 1;
+ while ((--i >= cmdStart) && (parenCount != 0))
+ switch ((*TEXTREC->hText)[i]) {
+ case DBLQUOTE: inQuotes = !inQuotes; break;
+ case '(': if (!inQuotes) parenCount++; break;
+ case ')': if (!inQuotes) parenCount--; break;
+ }
+ if (parenCount == 0) {
+ cursorBeforeFlash = TEXTREC->selStart;
+ SetSelection (i+1, i+2); /* flash the matching open-paren */
+ flashTime = 10;
+ }
+ } else if ((recentChar == DBLQUOTE) && (TEXTREC->selStart > cmdStart)) {
+ i = TEXTREC->selStart - 1;
+ while ((--i >= cmdStart) && ((*TEXTREC->hText)[i] != DBLQUOTE)) ;
+ if ((*TEXTREC->hText)[i] == DBLQUOTE) {
+ cursorBeforeFlash = TEXTREC->selStart;
+ SetSelection (i, i+1); /* flash the matching double-quote */
+ flashTime = 10;
+ }
+ }
+ }
+ AdjustScrollBar ();
+ }
+ } while (!done);
+}
+
+char *macgets (void) {
+ /* retrieve a typed character */
+ /* Note that this uses some extensive (and clever, if I may say so myself) buffering. */
+ int i, b, bufSize;
+ char *ptr, *buffer;
+ Boolean done, onLastLine;
+
+ PrepareForInput ();
+ do { /* repeat until a full expression has been typed */
+ EditFreely (); /* allow free editing for a while */
+
+ /* Now, we have a complete command to parse, if and only if: */
+ /* - the cursor was on the last line when the user pressed Return or Enter, and */
+ /* - the user either pressed Enter, or else every '(' since the beginning */
+ /* of the command is matched by a ')'. */
+ /* Quoting is watched for. ( ") is not a complete expression. */
+
+ done = true;
+ if (TEXTREC->selStart != TEXTREC->teLength) /* if we're not at the end already */
+ SetSelection (TEXTREC->teLength, TEXTREC->teLength); /* send cursor to end */
+ TEXTREC->clikStuff = 255; /* to make sure the caret appears where it should */
+ TEKey ('\r', hTERec);
+
+ /* check and see if we've completed the command yet */
+ if (recentChar != ENTER) {
+ Boolean inQuotes = false;
+ short parenCount = 0;
+ for (i = cmdStart; i < TEXTREC->teLength; i++)
+ switch ((*TEXTREC->hText)[i]) {
+ case DBLQUOTE: inQuotes = !inQuotes; break;
+ case '(': if (!inQuotes) parenCount++; break;
+ case ')': if (!inQuotes) parenCount--; break;
+ }
+ if ((parenCount > 0) || inQuotes) done = false;
+ }
+
+ AdjustScrollBar ();
+ } while (!done);
+
+ /* put the entire command into the buffer, and return it */
+ bufSize = TEXTREC->teLength - cmdStart;
+ buffer = (char *) NewPtr (bufSize + 1);
+ BlockMoveData (*TEXTREC->hText + cmdStart, buffer, bufSize);
+ buffer[bufSize] = '\0';
+ return buffer;
+}
+
+void macputc (int ch) {
+ /* put a char into the output buffer, and flush the buffer if necessary */
+ switch (ch) {
+ case '\t':
+ do { macputc (' '); } while (cursorPos & 7);
+ break;
+ case DELETE:
+ if (cursorPos) cursorPos--; /* and fall through to default */
+ default:
+ if (outputBufferLength == MAX_BUF) FlushOutput ();
+ if (ch == '\n') {
+ cursorPos = 0;
+ (*hOutputBuffer)[outputBufferLength++] = '\r';
+ } else {
+ cursorPos++;
+ (*hOutputBuffer)[outputBufferLength++] = ch;
+ }
+ }
+}
+
+void macputs (char *s) {
+ /* for completeness */
+ while (*s) macputc (*s++);
+}
+
+void scrflush (void) {
+ extern void osflush (void);
+ /* clear out everything */
+ FlushOutput ();
+ osflush ();
+}
+
+void scrclear (void) {
+ /* clear text window -- not implemented */
+}
+
+//=============================================================================
+// static void UpdateCmdWindow (void)
+//=============================================================================
+// main command window update procedure
+//=============================================================================
+
+
+void UpdateCmdWindow (void) {
+ long textBottom;
+ Rect tempRect;
+
+ InvalRect (&(gCommandWin->portRect));
+ BeginUpdate (gCommandWin);
+ BlockMoveData(&(gCommandWin->portRect), &tempRect, sizeof(Rect));
+ tempRect.right -= SCROLLER_WIDTH;
+ EraseRect (&tempRect);
+ if (gCommandWinResized) {
+ TEXTREC->viewRect = SetTERect ();
+ TEXTREC->destRect.right = TEXTREC->viewRect.right;
+ TECalText (hTERec);
+ SetScrollRect ();
+ gCommandWinResized = false;
+ }
+ DrawOnlyGrowIcon (gCommandWin);
+ FlushOutput ();
+
+ TEXTREC->viewRect = SetTERect (); /* adjust for possible change in height of status line */
+
+ textBottom = TEXTREC->destRect.top + (TEXTREC->nLines * LINEHEIGHT);
+ if (TEXTREC->destRect.top > TEXTREC->viewRect.top)
+ TEScroll (0, (TEXTREC->viewRect.top - TEXTREC->destRect.top), hTERec);
+
+ if (TEXTREC->destRect.top < TEXTREC->viewRect.top) { /* make sure we don't get fractions of lineheights */
+ int amountOffTheTop = TEXTREC->viewRect.top - TEXTREC->destRect.top;
+ if (amountOffTheTop % LINEHEIGHT) TEScroll (0, amountOffTheTop % LINEHEIGHT, hTERec);
+ }
+ TEUpdate (&(TEXTREC->viewRect), hTERec);
+ AdjustScrollBar ();
+ UpdateControls (gCommandWin, gCommandWin->visRgn);
+ EndUpdate (gCommandWin);
+}
+
+void ActivateCmdWindow(void)
+{
+ TEActivate (hTERec);
+ HiliteControl (vScroll, 0);
+ DrawOnlyGrowIcon (gCommandWin);
+}
+
+void DeactivateCmdWindow(void)
+{
+ TEDeactivate (hTERec);
+ HiliteControl (vScroll, 255);
+ DrawOnlyGrowIcon (gCommandWin);
+}
+
+void InitalizeCmdWindow(void)
+{
+
+ /* setup the font, size and writing mode for the command window */
+ TextFont (kFontIDMonaco);
+ TextSize (9);
+ TextFace (0);
+ TextMode (srcCopy);
+ textStyle[plainStyle].tsFace = 0;
+ textStyle[boldStyle].tsFace = bold;
+
+ currentStyle = plainStyle;
+
+ { /* set up scroll bar */
+ Rect scrollRect;
+ vScroll = NewControl (gCommandWin, &scrollRect, "\p", 0, 0, 0, 0, scrollBarProc, 0L);
+ SetScrollRect ();
+ ShowControl (vScroll);
+ }
+
+ { /* set up command text record */
+ Rect teRect = SetTERect ();
+ hTERec = (TEHandle)TEStyleNew (&teRect, &teRect);
+ TECalText (hTERec);
+ TEAutoView (true, hTERec);
+ TESetClickLoop (uppScrollClickLoop, hTERec);
+ TEActivate (hTERec);
+ }
+
+ hOutputBuffer = NewHandle (MAX_BUF); /* a handle to a buffer for text to be displayed */
+}
+
+void CleanupCmdWindow(void)
+{
+ StopPasting ();
+ CloseWindow (gCommandWin);
+ TEDispose (hTERec);
+ DisposeHandle (hOutputBuffer);
+}
diff --git a/sys/mac/MacCommandWin.h b/sys/mac/MacCommandWin.h
new file mode 100644
index 0000000..20b7775
--- /dev/null
+++ b/sys/mac/MacCommandWin.h
@@ -0,0 +1,17 @@
+/* MacCommandWin.h -- headers for more mac stuff */
+
+void SetSelection (short start, short end);
+void macputc(int ch);
+void macputs(char *s);
+void PrepareForInput(void);
+void InitalizeCmdWindow(void);
+void UpdateCmdWindow(void);
+void StopPasting(void);
+void DeleteRange(void);
+void scrflush(void);
+void SetScrollRect(void);
+void AdjustCursor(Point theLoc, RgnHandle theRgn);
+void DoKeyPress(EventRecord *theEvent);
+void ActivateCmdWindow(void);
+void DeactivateCmdWindow(void);
+void CleanupCmdWindow(void);
diff --git a/sys/mac/MacDrag.h b/sys/mac/MacDrag.h
new file mode 100644
index 0000000..15a48ca
--- /dev/null
+++ b/sys/mac/MacDrag.h
@@ -0,0 +1,3 @@
+/* MacDrag.h -- drag text */
+
+Boolean DragText(EventRecord *ev);
diff --git a/sys/mac/MacFileUtils.c b/sys/mac/MacFileUtils.c
new file mode 100644
index 0000000..dae8ea4
--- /dev/null
+++ b/sys/mac/MacFileUtils.c
@@ -0,0 +1,81 @@
+// Routines that deal with some mac file system stuff -EAD
+
+#include <Files.h>
+#include <TextUtils.h>
+#include <string.h>
+//#include "MiscellaneousUtilities.h"
+
+//=========================================================================
+// Function prototypes
+//=========================================================================
+
+void set_mac_file_type(char *filename);
+void GetFullPath(FSSpec *theSpec, StringPtr theName);
+void PathNameFromDirID(long dirID, short vRefNum, StringPtr fullPathName);
+
+
+
+//=========================================================================
+// Set the output soundfile type and creator
+//=========================================================================
+
+void set_mac_file_type(char *filename)
+{
+ Str255 fName;
+ FSSpec fSpec;
+ FInfo fFInfo;
+
+ fFInfo.fdType = 'AIFF';
+ fFInfo.fdCreator = 'Sd2a';
+
+ BlockMoveData(filename, &fName[1], 256);
+ fName[0] = strlen(filename);
+ FSMakeFSSpec(0, 0, fName, &fSpec);
+ FSpSetFInfo(&fSpec, &fFInfo);
+}
+
+//==================================================================================================================================
+// void GetFullPath(FSSpec *theSpec, StringPtr theName)
+//==================================================================================================================================
+// Extracts the full pathname for the file pointed to by theSpec and returns it in theName.
+//==================================================================================================================================
+
+void GetFullPath(FSSpec *theSpec, StringPtr theName)
+{
+ *theName = 0;
+ if (theSpec->parID != 1) PathNameFromDirID(theSpec->parID, theSpec->vRefNum, theName);
+ // was: pstrcat(theName, theSpec->name);
+ strcat(P2CStr(theName), P2CStr(theSpec->name));
+ C2PStr((char *) theName);
+ C2PStr((char *) theSpec->name);
+ //pstrcat(theName, "\p:");
+ theName[*theName + 1] = 0;
+}
+
+//==================================================================================================================================
+// void PathNameFromDirID(long dirID, short vRefNum, StringPtr fullPathName)
+//==================================================================================================================================
+// Given a vRefNum and a directory ID, creates a full path specification.
+//==================================================================================================================================
+
+void PathNameFromDirID(long dirID, short vRefNum, StringPtr fullPathName)
+{
+ Str255 directoryName;
+ DirInfo block;
+ OSErr err;
+ fullPathName[0] = 0;
+ block.ioDrDirID = block.ioDrParID = dirID;
+ block.ioNamePtr = directoryName;
+ do {
+ block.ioVRefNum = vRefNum;
+ block.ioFDirIndex = -1;
+ block.ioDrDirID = block.ioDrParID;
+ err = PBGetCatInfo((CInfoPBPtr)&block, false);
+ //pstrcat(directoryName, (StringPtr)"\p:");
+ //pstrinsert(fullPathName, directoryName);
+ strcat(P2CStr(directoryName), ":");
+ strcat((char *) directoryName, (char *) fullPathName);
+ strcpy((char *)fullPathName, (char *) directoryName);
+ } while (block.ioDrDirID != 2);
+ C2PStr((char *) fullPathName);
+}
diff --git a/sys/mac/MacFileUtils.h b/sys/mac/MacFileUtils.h
new file mode 100644
index 0000000..581ff07
--- /dev/null
+++ b/sys/mac/MacFileUtils.h
@@ -0,0 +1,3 @@
+/* MacFileUtils.h -- more mac stuff */
+
+void GetFullPath(FSSpec *theSpec, StringPtr theName);
diff --git a/sys/mac/MacGlobals.h b/sys/mac/MacGlobals.h
new file mode 100644
index 0000000..e0c8573
--- /dev/null
+++ b/sys/mac/MacGlobals.h
@@ -0,0 +1,50 @@
+// Window pointers
+
+extern WindowPtr gCommandWin, gGraphicsWin;
+
+extern Boolean gCommandWinResized;
+
+
+
+// Menu Handles
+
+extern MenuHandle appleMenu, fileMenu, editMenu, controlMenu;
+
+
+
+// The command window text handle
+
+extern TEHandle hTERec;
+
+#define TEXTREC (*hTERec)
+
+#define TEXTCHAR(i) ((*(TEXTREC->hText))[i])
+
+
+
+// more comand window text stuff
+
+extern CharsHandle pastedTextH; /* a handle to pasted text */
+
+extern int pastedLength; /* how many chars there are in the paste buffer */
+
+extern int outputBufferLength;
+
+extern Rect dragRect, sizeRect;
+
+extern int flashTime, cursorBeforeFlash;
+
+extern char recentChar; /* the last character typed */
+
+
+
+// Allocate space for UPPs
+
+extern ControlActionUPP uppScrollProc;
+
+extern TEClickLoopUPP uppScrollClickLoop;
+
+
+
+extern Boolean gInBackground;
+
diff --git a/sys/mac/MacHandleEv.c b/sys/mac/MacHandleEv.c
new file mode 100644
index 0000000..d6516c0
--- /dev/null
+++ b/sys/mac/MacHandleEv.c
@@ -0,0 +1,64 @@
+#include <MacTypes.h>
+#include <Quickdraw.h>
+#include <Windows.h>
+#include <Controls.h>
+#include <ToolUtils.h>
+#include "macint.h"
+
+extern WindowPtr gCommandWin, gGraphicsWin;
+extern Boolean gCommandWinResized;
+extern Rect dragRect, sizeRect;
+
+//=============================================================================
+// Hanlde Mouse Down Events
+//=============================================================================
+
+void DoMouseDown (EventRecord *theEvent) {
+ WindowPtr whichWindow;
+ short int thePart = FindWindow (theEvent->where, &whichWindow);
+
+ switch (thePart) {
+ case inSysWindow:
+ SystemClick (theEvent, whichWindow);
+ break;
+ case inDrag:
+ DragWindow (whichWindow, theEvent->where, &dragRect);
+ break;
+ case inMenuBar: {
+ long choice;
+ AdjustMenus ();
+ choice = MenuSelect (theEvent->where);
+ if (choice) DoMenu (choice);
+ break;
+ }
+ case inGoAway:
+ if ((whichWindow == gGraphicsWin)
+ && (TrackGoAway (whichWindow, theEvent->where)))
+ HideGrafWin ();
+ break;
+ case inContent:
+ if ((FrontWindow () == gCommandWin) && (whichWindow == gCommandWin))
+ DoContent (theEvent);
+ else SelectWindow (whichWindow);
+ break;
+ case inGrow:
+ case inZoomIn:
+ case inZoomOut: {
+ long newSize;
+ GrafPtr oldPort;
+ if (thePart == inGrow) newSize = GrowWindow (whichWindow, theEvent->where, &sizeRect);
+ if (((thePart == inGrow) && newSize)
+ || ((thePart != inGrow) && TrackBox (whichWindow, theEvent->where, thePart))) {
+ GetPort (&oldPort);
+ SetPort (whichWindow);
+ EraseRect (&whichWindow->portRect);
+ if (thePart == inGrow) SizeWindow (whichWindow, LoWord (newSize), HiWord (newSize), -1);
+ else ZoomWindow (whichWindow, thePart, 0);
+ gCommandWinResized = true;
+ InvalRect (&whichWindow->portRect);
+ SetPort (oldPort);
+ }
+ break;
+ }
+ }
+}
diff --git a/sys/mac/MacHandleEv.h b/sys/mac/MacHandleEv.h
new file mode 100644
index 0000000..73eff48
--- /dev/null
+++ b/sys/mac/MacHandleEv.h
@@ -0,0 +1,3 @@
+/* MacHandelEv.h -- event handlers */
+
+void DoMouseDown(EventRecord *theEvent);
diff --git a/sys/mac/README.txt b/sys/mac/README.txt
new file mode 100644
index 0000000..bf634d9
--- /dev/null
+++ b/sys/mac/README.txt
@@ -0,0 +1,55 @@
+README.txt -- information on Nyquist for Mac OS X
+
+Installation
+------------
+The simplest way to install and run Nyquist is to get the pre-compiled
+NyquistIDE application, which includes executables, documentation, and
+libraries all in one package.
+
+You will probably run Nyquist using the NyquistIDE application, but
+you can also run nyquist from the command line. The executable is
+located in
+
+ NyquistIDE.app/Contents/Resources/Java/ny
+
+To run from the command line, you will need to set the XLISPPATH
+environment variable using this command line (if you use the C shell,
+e.g. csh):
+
+ setenv XLISPPATH `pwd`/runtime:`pwd`/lib
+
+If you use the bash shell, use:
+
+ export XLISPPATH=`pwd`/runtime:`pwd`/lib
+
+Note that this sets XLISPPATH in the environment of the current
+command line shell. If you exit the shell or switch to another shell,
+the XLISPPATH variable will not be set. Your shell reads an
+initialization file when it starts. You can add the XLISPPATH
+initialization command to this file if you want the variable to be set
+automatically in every instance of your command line shell.
+
+On the topic of the XLISPPATH, note that this variable is set by
+NyquistIDE when running with that application, overriding any other
+value. You can extend the search path by creating the file xlisppath
+in the same directory as the nyquist executable ny. The xlisppath file
+should have colon-separated paths on a single line of text.
+
+You can also build Nyquist from sources, as described below.
+
+
+How To Build Nyquist on Mac OS X
+--------------------------------
+You need to install Xcode, Apple's free software development system
+for OS X.
+
+The project file is in nyquist/macosxproject/nyquist.xcodeproj
+
+To build Nyquist or NyquistIDE:
+ - Open nyquist.xcodeproj in Xcode
+ - Set the active target to "Nyquist" or "NyquistIDE"
+ - Click on "build active target"
+ - ny or NyquistIDE will be produced in MacOSXProject/build/
+
+
+
diff --git a/sys/mac/macaboutbox.c b/sys/mac/macaboutbox.c
new file mode 100644
index 0000000..8acdbf4
--- /dev/null
+++ b/sys/mac/macaboutbox.c
@@ -0,0 +1,123 @@
+/* macaboutbox.c - Display the "about box" of the application. */
+/* Written by Brian Kendig. */
+/* The functions here are only used by macint.c. */
+
+//#include <THINK.h>
+#include <Dialogs.h>
+#include <Fonts.h>
+#include <Menus.h>
+#include <Quickdraw.h>
+#include <Resources.h>
+#include <ToolUtils.h>
+#include <Traps.h>
+#include <Windows.h>
+#include "macint.h"
+#define NIL ((void *) 0)
+
+static DialogPtr aboutBox;
+extern Boolean hasColorQD;
+
+static enum {
+ theOKButton = 1,
+ theOKOutline = 2,
+ theIcon = 3,
+ theName = 4,
+ theAboutText = 5,
+ theCopyright = 6
+} ;
+
+pascal void DrawOKOutline (WindowPtr dialogWindow, short theItem) {
+ PenState oldPen;
+ short iType;
+ Handle iHandle;
+ Rect iRect;
+
+ GetPenState (&oldPen);
+ PenNormal ();
+ PenSize (3,3);
+
+ GetDialogItem (aboutBox, theOKButton, &iType, &iHandle, &iRect);
+ InsetRect (&iRect, -4, -4);
+ FrameRoundRect (&iRect, 16, 16);
+
+ SetPenState (&oldPen);
+}
+
+pascal void DrawIcon (WindowPtr dialogWindow, short theItem) {
+ short iType;
+ Handle iHandle;
+ Rect iRect;
+
+ GetDialogItem (aboutBox, theIcon, &iType, &iHandle, &iRect);
+ PlotIcon (&iRect, GetResource ('ICN#', 128));
+}
+
+pascal void DrawName (WindowPtr dialogWindow, short theItem) {
+ short iType;
+ Handle iHandle;
+ Rect iRect;
+ Str255 string;
+
+ TextFont (kFontIDHelvetica);
+ TextSize (24);
+ TextFace (0);
+ GetDialogItem (aboutBox, theName, &iType, &iHandle, &iRect);
+ GetIndString (string, STRINGS_RES, 1);
+ TETextBox (string+1, string[0], &iRect, teFlushLeft);
+}
+
+pascal void DrawAboutText (WindowPtr dialogWindow, short theItem) {
+ short iType;
+ Handle iHandle;
+ Rect iRect;
+ Str255 string;
+
+ TextFont (kFontIDMonaco);
+ TextSize (9);
+ TextFace (0);
+ GetDialogItem (aboutBox, theAboutText, &iType, &iHandle, &iRect);
+ GetIndString (string, STRINGS_RES, 2);
+ TETextBox (string+1, string[0], &iRect, teFlushLeft);
+}
+
+pascal void DrawCopyright (WindowPtr dialogWindow, short theItem) {
+ short iType;
+ Handle iHandle;
+ Rect iRect;
+ Str255 string;
+
+ TextFont (systemFont);
+ TextSize (12);
+ TextFace (0);
+ GetDialogItem (aboutBox, theCopyright, &iType, &iHandle, &iRect);
+ GetIndString (string, STRINGS_RES, 3);
+ TETextBox (string+1, string[0], &iRect, teFlushLeft);
+}
+
+void DoAboutBox (void) {
+ short itemType, itemHit = 0;
+ Handle itemHandle;
+ Rect aboutRect;
+ short width, hight;
+ PicHandle aboutPict;
+
+ aboutPict = GetPicture(ABOUT_PICT);
+ aboutRect = (*aboutPict)->picFrame;
+ width = aboutRect.right - aboutRect.left;
+ hight = aboutRect.bottom - aboutRect.top;
+
+ aboutBox = GetNewDialog (ABOUT_BOX, NIL, (WindowPtr) -1);
+ SizeWindow(aboutBox, width, hight, false);
+
+ ShowWindow (aboutBox);
+ SetPort(aboutBox);
+ DrawPicture(aboutPict, &(*aboutPict)->picFrame);
+
+ //itemHit = 0;
+ //while (itemHit != ok) ModalDialog (NIL, &itemHit);
+ while (!Button());
+
+ DisposeDialog (aboutBox);
+
+ FlushEvents(everyEvent, 0); // dmazzoni
+}
diff --git a/sys/mac/macaboutbox.h b/sys/mac/macaboutbox.h
new file mode 100644
index 0000000..76f699a
--- /dev/null
+++ b/sys/mac/macaboutbox.h
@@ -0,0 +1,3 @@
+/* macaboutbox.h -- header for about box implementation */
+
+void DoAboutBox(void);
diff --git a/sys/mac/macdrag.c b/sys/mac/macdrag.c
new file mode 100644
index 0000000..559a278
--- /dev/null
+++ b/sys/mac/macdrag.c
@@ -0,0 +1,161 @@
+#include <Drag.h>
+#include <Errors.h>
+#include <TextEdit.h>
+#include <QuickDraw.h>
+
+extern TEHandle hTERec;
+// Handle drag from newswatcher -EAD
+
+/*----------------------------------------------------------------------------
+ DragText
+
+ Drag selected text.
+
+ Entry: ev = pointer to mouse down event record.
+ where = location of mouse down event in local coords.
+ theTE = handle to TextEdit record.
+
+ Exit: function result = error code.
+ *dragged =
+ true if text was dragged.
+ false if mouse down was not over text selection, or
+ user did not move the mouse before releasing the
+ mouse button.
+ *trashed = true if text was dragged to trash.
+----------------------------------------------------------------------------*/
+extern RgnHandle rgn;
+//extern EventRecord theEvent;
+
+Boolean DragText (EventRecord *ev)
+{
+ DragReference dragRef;
+ OSErr err = noErr;
+ Boolean haveDragRef = false;
+ Handle hText;
+ RgnHandle dragRgn, tempRgn;
+ short selStart, selEnd;
+ char state;
+ Point theLoc;
+ GrafPtr curPort;
+
+// if (!PtInTEHiliteRgn(where, hTERec)) return noErr;
+ if (!WaitMouseMoved(ev->where)) return noErr;
+
+ GetPort(&curPort);
+
+ CopyRgn(rgn, dragRgn = NewRgn());
+ SetPt(&theLoc, 0, 0);
+ LocalToGlobal(&theLoc);
+ OffsetRgn(dragRgn, theLoc.h, theLoc.v);
+
+ hText = (**hTERec).hText;
+ selStart = (**hTERec).selStart;
+ selEnd = (**hTERec).selEnd;
+
+ err = NewDrag(&dragRef);
+ if (err != noErr) goto exit;
+ haveDragRef = true;
+ state = HGetState(hText);
+ HLock(hText);
+ err = AddDragItemFlavor(dragRef, 1, 'TEXT', *hText + selStart, selEnd - selStart, 0);
+ HSetState(hText, state);
+ if (err != noErr) goto exit;
+// dragRgn = NewRgn();
+// err = TEGetHiliteRgn(dragRgn, hTERec);
+// if (err != noErr) goto exit;
+// LocalToGlobalRgn(dragRgn);
+// OutlineRegion(dragRgn);
+ SetDragItemBounds(dragRef, 1, &(**dragRgn).rgnBBox);
+ tempRgn = NewRgn();
+ CopyRgn(dragRgn, tempRgn);
+ InsetRgn(tempRgn, 1, 1);
+ DiffRgn(dragRgn, tempRgn, dragRgn);
+ DisposeRgn(tempRgn);
+
+ err = TrackDrag(dragRef, ev, dragRgn);
+ if (err != noErr && err != userCanceledErr) goto exit;
+ //*trashed = DragTargetWasTrash(dragRef);
+// DisposeRgn(dragRgn);
+
+ DisposeDrag(dragRef);
+ return true;
+
+exit:
+
+ if (haveDragRef) DisposeDrag(dragRef);
+// if (dragRgn != nil) DisposeRgn(dragRgn);
+ return false;
+}
+
+
+
+/*----------------------------------------------------------------------------
+ LocalToGlobalRgn
+
+ Convert a region from local to global coordinates.
+
+ Entry: rgn = handle to region.
+----------------------------------------------------------------------------*/
+
+void LocalToGlobalRgn (RgnHandle rgn)
+{
+ Point where;
+
+ SetPt(&where, 0, 0);
+ LocalToGlobal(&where);
+ OffsetRgn(rgn, where.h, where.v);
+}
+
+/*----------------------------------------------------------------------------
+ OutlineRegion
+
+ Change a region into a tracing of its border which is appropriate
+ for normal dragging.
+
+ Entry: theRgn = handle to region.
+
+ Exit: Region changed to outline of region.
+
+ From Apple "HFS Drag Sample" sample code.
+----------------------------------------------------------------------------*/
+
+void OutlineRegion (RgnHandle theRgn)
+{
+ RgnHandle tempRgn;
+
+ tempRgn = NewRgn();
+ CopyRgn(theRgn, tempRgn);
+ InsetRgn(tempRgn, 1, 1);
+ DiffRgn(theRgn, tempRgn, theRgn);
+ DisposeRgn(tempRgn);
+}
+
+/*----------------------------------------------------------------------------
+ PtInTEHiliteRgn
+
+ Determine whether or not a point is in the current TextEdit hilite
+ region.
+
+ Entry: where = point in local coords.
+ theTE = handle to TextEdit record.
+
+ Exit: function result = true if point is in the hilite region.
+----------------------------------------------------------------------------*/
+
+Boolean PtInTEHiliteRgn (Point where, TEHandle theTE)
+{
+ Boolean result = false;
+ RgnHandle rgn = nil;
+ OSErr err = noErr;
+
+ //if (!HaveTEGetHiliteRgn()) return false;
+ rgn = NewRgn();
+ err = TEGetHiliteRgn(rgn, theTE);
+ if (err != noErr) goto exit;
+ result = PtInRgn(where, rgn);
+
+exit:
+
+ if (rgn != nil) DisposeRgn(rgn);
+ return result;
+}
diff --git a/sys/mac/macfun.c b/sys/mac/macfun.c
new file mode 100644
index 0000000..e92461d
--- /dev/null
+++ b/sys/mac/macfun.c
@@ -0,0 +1,222 @@
+/* macfun.c - macintosh user interface functions for xlisp */
+/* Written by Brian Kendig. */
+
+#include <Quickdraw.h>
+#include <Windows.h>
+#include <Memory.h>
+#include "xlisp.h"
+#include "macint.h"
+
+/* externals */
+extern WindowPtr gCommandWin, gGraphicsWin;
+extern Boolean hasColorQD;
+extern unsigned long startupTicks;
+extern void ShowGrafWin (void);
+
+unsigned long ticks_per_second (void) { return 60; }
+unsigned long run_tick_count (void) { return ((unsigned long) TickCount ()) - startupTicks; }
+unsigned long real_tick_count (void) { return (unsigned long) TickCount (); }
+
+LVAL xrealtime (void) { return cvfixnum ((FIXTYPE)real_tick_count()); } /* get-internal-real-time */
+LVAL xruntime (void) { return cvfixnum ((FIXTYPE)run_tick_count()); } /* get-internal-run-time */
+LVAL xtime (void) { return cvfixnum ((FIXTYPE)real_tick_count()); } /* time */
+
+/* get an integer parameter */
+LOCAL int getNumber () {
+ LVAL num = xlgafixnum ();
+ return ((int) getfixnum (num));
+}
+
+/* handle commands that require integer arguments */
+LOCAL LVAL GrafCmd (char funct, int nArgs) {
+ short x, y, z;
+ if (nArgs > 0) x = getNumber ();
+ if (nArgs > 1) y = getNumber ();
+ if (nArgs > 2) z = getNumber ();
+ xllastarg ();
+ SetPort (gGraphicsWin);
+ switch (funct) {
+ case 'G': ShowGrafWin (); break;
+ case 'g': HideGrafWin (); break;
+ case 'x': EraseRect (&gGraphicsWin->portRect); break;
+ case 's': ShowPen (); break;
+ case 'h': HidePen (); break;
+ case 'd': PenMode (x); break;
+ case 'M': Move (x, y); break;
+ case 'm': MoveTo (x, y); break;
+ case 'L': Line (x, y); break;
+ case 'l': LineTo (x, y); break;
+ case 'S': PenSize (x, y); break;
+ case 'p': PenNormal (); break;
+ case 'c':
+ if (hasColorQD) {
+ RGBColor col; col.red = x; col.green = y; col.blue = z;
+ RGBForeColor (&col);
+ } break;
+ }
+ SetPort (gCommandWin);
+ return NIL;
+}
+
+LVAL xshowgraphics (void) { return GrafCmd ('G', 0); } /* show graphics win */
+LVAL xhidegraphics (void) { return GrafCmd ('g', 0); } /* hide graphics win */
+LVAL xcleargraphics (void) { return GrafCmd ('x', 0); } /* clear graphics win */
+LVAL xshowpen (void) { return GrafCmd ('s', 0); } /* show the pen */
+LVAL xhidepen (void) { return GrafCmd ('h', 0); } /* hide the pen */
+LVAL xpenmode (void) { return GrafCmd ('d', 1); } /* set the pen mode */
+LVAL xmove (void) { return GrafCmd ('M', 2); } /* move pen in a specified direction */
+LVAL xmoveto (void) { return GrafCmd ('m', 2); } /* move pen to a screen location */
+LVAL xdraw (void) { return GrafCmd ('L', 2); } /* draw a line in a specified direction */
+LVAL xdrawto (void) { return GrafCmd ('l', 2); } /* draw a line to a screen location */
+LVAL xpensize (void) { return GrafCmd ('S', 2); } /* set the pen size */
+LVAL xpennormal (void) { return GrafCmd ('p', 0); } /* set the pen to normal */
+LVAL xcolor (void) { return GrafCmd ('c', 3); } /* set RGB color of pen */
+
+
+LVAL xgetpen (void) { /* get the pen position */
+ LVAL val;
+ Point p;
+ xllastarg ();
+ SetPort ((GrafPtr)gGraphicsWin);
+ GetPen (&p);
+ SetPort (gCommandWin);
+ xlsave1 (val);
+ val = consa (NIL);
+ rplaca (val,cvfixnum ((FIXTYPE)p.h));
+ rplacd (val,cvfixnum ((FIXTYPE)p.v));
+ xlpop ();
+ return val;
+}
+
+LVAL xpenpat (void) { /* set the pen pattern */
+ LVAL plist;
+ Pattern pat;
+ int i;
+ plist = xlgalist ();
+ xllastarg ();
+ for (i = 0; i < 8 && consp (plist); ++i, plist = cdr (plist))
+// if (fixp (car (plist))) pat[i] = getfixnum (car (plist));
+ SetPort ((GrafPtr)gGraphicsWin);
+ PenPat (&pat);
+ SetPort (gCommandWin);
+ return NIL;
+}
+
+
+/* The functions below are not yet implemented. */
+
+LVAL xtool (void) { /* call the toolbox */
+ int trap = getNumber ();
+ LVAL val;
+
+/* asm {
+ move.l args(A6),D0
+ beq L2
+ L1: move.l D0,A0
+ move.l 2(A0),A1
+ move.w 4(A1),-(A7)
+ move.l 6(A0),D0
+ bne L1
+ L2: lea L3,A0
+ move.w trap(A6),(A0)
+ L3: dc.w 0xA000
+ clr.l val(A6)
+ }
+
+ return val; */
+ return cvfixnum ((FIXTYPE) trap);
+}
+
+LVAL xtool16 (void) { /* call the toolbox with a 16 bit result */
+ int trap = getNumber ();
+ int val;
+
+/* asm {
+ clr.w -(A7)
+ move.l args(A6), D0
+ beq L2
+ L1: move.l D0, A0
+ move.l 2(A0), A1
+ move.w 4(A1), -(A7)
+ move.l 6(A0), D0
+ bne L1
+ L2: lea L3, A0
+ move.w trap(A6), (A0)
+ L3: dc.w 0xA000
+ move.w (A7)+, val(A6)
+ }
+
+ return cvfixnum ((FIXTYPE) val); */
+ return cvfixnum ((FIXTYPE) trap);
+}
+
+LVAL xtool32 (void) { /* call the toolbox with a 32 bit result */
+ int trap = getNumber ();
+ long val;
+
+/* asm {
+ clr.l -(A7)
+ move.l args(A6),D0
+ beq L2
+ L1: move.l D0,A0
+ move.l 2(A0),A1
+ move.w 4(A1),-(A7)
+ move.l 6(A0),D0
+ bne L1
+ L2: lea L3,A0
+ move.w trap(A6),(A0)
+ L3: dc.w 0xA000
+ move.l (A7)+,val(A6)
+ }
+
+ return cvfixnum ((FIXTYPE) val); */
+ return cvfixnum ((FIXTYPE) trap);
+}
+
+LVAL xnewhandle (void) { /* allocate a new handle */
+ LVAL num = xlgafixnum ();
+ long size = getfixnum (num);
+ xllastarg ();
+ return cvfixnum ((FIXTYPE) NewHandle (size));
+}
+
+LVAL xnewptr (void) { /* allocate memory */
+ LVAL num = xlgafixnum ();
+ long size = getfixnum (num);
+ xllastarg ();
+ return cvfixnum ((FIXTYPE) NewPtr (size));
+}
+
+LVAL xhiword (void) { /* return the high order 16 bits of an integer */
+ unsigned int val = (unsigned int) (getNumber () >> 16);
+ xllastarg ();
+ return cvfixnum ((FIXTYPE) val);
+}
+
+LVAL xloword (void) { /* return the low order 16 bits of an integer */
+ unsigned int val = (unsigned int) getNumber ();
+ xllastarg ();
+ return cvfixnum ((FIXTYPE) val);
+}
+
+LVAL xrdnohang (void) { /* get the next character in the look-ahead buffer */
+ int ch = 0;
+ xllastarg ();
+/* if ((ch = scrnextc ()) == EOF) return NIL; */
+ return cvfixnum ((FIXTYPE) ch);
+}
+
+void ossymbols (void) { /* ossymbols - enter important symbols */
+ LVAL sym;
+
+ /* setup globals for the window handles */
+ sym = xlenter ("*COMMAND-WINDOW*");
+ setvalue (sym, cvfixnum ((FIXTYPE) gCommandWin));
+ sym = xlenter ("*GRAPHICS-WINDOW*");
+ setvalue (sym, cvfixnum ((FIXTYPE) gGraphicsWin));
+}
+
+void xoserror (char *msg) { /* do nothing */ }
+
+LVAL xsystem (V) { return NIL; }
+LVAL xgetkey (V) { return NIL; }
diff --git a/sys/mac/macint.c b/sys/mac/macint.c
new file mode 100644
index 0000000..bd76af8
--- /dev/null
+++ b/sys/mac/macint.c
@@ -0,0 +1,521 @@
+/* macint.c - macintosh interface routines for xlisp 2.1e */
+/* Written by Brian Kendig. */
+/* The functions here are only called by macstuff.c. */
+
+#include <Events.h>
+#include <Gestalt.h>
+#include <Memory.h>
+#include <Menus.h>
+#include <Events.h>
+#include <Quickdraw.h>
+#include <StandardFile.h>
+#include <TextEdit.h>
+#include <ToolUtils.h>
+#include <Traps.h>
+#include <Windows.h>
+#include <Controls.h>
+/* #include <ControlDefinitions.h> */
+#include <SIOUX.h>
+#include <AppleEvents.h>
+#include "macint.h"
+/* #define FALSE 0
+#define TRUE 1 */
+#define NIL ((void *) 0)
+
+
+#include "MacCommandWin.h"
+#include "macaboutbox.h"
+#include "MacDrag.h"
+#include "MacHandleEv.h"
+#include "macstuff.h"
+#include "stdio.h"
+#define TEXTREC (*hTERec) /* the command window text record */
+#define TEXTCHAR(i) ((*(TEXTREC->hText))[i])
+
+// Struct for apple event handling
+typedef struct AEventList {
+ AEEventClass evclass;
+ AEEventID evid;
+ void *handler;
+ long refcon;
+} AEventList, *AEventListPtr;
+
+//===========================================================================
+// GLOBALS DEFINED HERE USE MacGlobals.h FOR ACCESS
+//===========================================================================
+
+// Menu handles
+MenuHandle appleMenu, fileMenu, editMenu, controlMenu;
+
+/* command and graphics windows */
+WindowPtr gCommandWin, gGraphicsWin;
+WindowRecord commandWinRec, bwGraphicsWinRec;
+CWindowRecord colorGraphicsWinRec;
+Boolean gGraphicsShown, gCommandWinResized = false;
+
+// Screen size stuff
+Rect dragRect, sizeRect;
+int screenWidth, screenHeight; /* screen dimensions */
+int sHorizontal, sVertical, sWidth, sHeight; /* command win, split screen */
+int gHorizontal, gVertical, gWidth, gHeight; /* graphics win, split screen */
+
+// The Text handle
+TEHandle hTERec;
+
+/* output is buffered */
+//Handle hOutputBuffer = NULL;
+int outputBufferLength = 0;
+
+// Allocate space for UPPs
+ControlActionUPP uppScrollProc;
+TEClickLoopUPP uppScrollClickLoop;
+//AEEventHandlerUPP uppAEOpenFiles, uppAEQuit;
+
+// Text related globals
+CharsHandle pastedTextH = NULL; /* a handle to pasted text */
+int pastedLength = 0; /* how many chars there are in the paste buffer */
+int flashTime = 0, cursorBeforeFlash; /* for flashing cursor when parens match */
+char recentChar; /* the last character typed */
+RgnHandle gMouseRgn; // holds current mouse regin
+
+/* miscellaneous stuff */
+Boolean gInBackground; /* are we in background or not */
+int wneImplemented;
+unsigned long startupTicks;
+Boolean hasColorQD;
+
+short howManyFiles = 0, whichFile = 0; /* keep track of files opened from Finder */
+
+
+// Prototypes
+static pascal OSErr AEQuit (AppleEvent *theAppleEvent, AppleEvent *theReply, long Refcon);
+static pascal OSErr AEOpenFiles (AppleEvent *theAppleEvent, AppleEvent *theReply, long Refcon);
+pascal Boolean ScrollClickLoop (void);
+pascal void ScrollProc (ControlHandle control, short thePart);
+Rect SetTERect (void);
+void FlushOutput (void);
+
+void ShowGrafWin (void) {
+ /* make the graphics window visible */
+ ShowWindow (gGraphicsWin);
+ SelectWindow (gGraphicsWin);
+ SetMenuItemText (controlMenu, SHOW_GRAPHICS, "\pHide Graphics");
+ //AdjustCursor ();
+ gGraphicsShown = true;
+}
+
+void HideGrafWin (void) {
+ /* hide the graphics window */
+ HideWindow (gGraphicsWin);
+ SetMenuItemText (controlMenu, SHOW_GRAPHICS, "\pShow Graphics");
+ gGraphicsShown = false;
+}
+
+
+static void UpdateGraphWindow ()
+{
+ BeginUpdate (gGraphicsWin);
+ EndUpdate (gGraphicsWin);
+}
+void InitMac (void) {
+// { /* set up memory properly */
+// int i;
+ // fix this later. -EAD
+ //if (DefltStack < STACKMIN) SetApplLimit (CurStackBase - STACKMIN);
+// MaxApplZone ();
+// for (i = 0; i < MASTERS; i++) MoreMasters ();
+// }
+ AEventListPtr theAppleEvent;
+ AEventList theEventList[] = {
+ { kCoreEventClass, kAEOpenDocuments, AEOpenFiles, 0 },
+ { kCoreEventClass, kAEQuitApplication, AEQuit, 0 },
+ { 0, 0, nil, 0 }
+ };
+ int i;
+
+ /* do all the necessary initialization mumbo-jumbo */
+ if (StackSpace() < STACKMIN)
+ SetApplLimit(GetApplLimit() - STACKMIN);
+ MaxApplZone();
+ /* printf("New StackSpace %lx GetApplLimit %lx\n",
+ StackSpace(), GetApplLimit()); */
+ for (i = 0; i < MASTERS; i++) MoreMasters ();
+ /* getchar(); */
+
+ /* initialize the toolbox */
+ InitGraf (&qd.thePort);
+ InitFonts ();
+ FlushEvents (everyEvent, 0);
+ InitWindows ();
+ InitMenus ();
+ TEInit ();
+ InitDialogs (NIL);
+ InitCursor ();
+
+ // Setup Callbacks
+ uppScrollClickLoop = NewTEClickLoopProc(ScrollClickLoop);
+ uppScrollProc = NewControlActionProc(ScrollProc);
+
+ // Handlers for core apple events
+ for (theAppleEvent = theEventList; theAppleEvent->handler; theAppleEvent++)
+ if (AEInstallEventHandler(theAppleEvent->evclass, theAppleEvent->evid, NewAEEventHandlerProc((ProcPtr)theAppleEvent->handler),
+ theAppleEvent->refcon, 0) != noErr);
+
+ // Set up the SIOUX window
+ SIOUXSettings.initializeTB = FALSE; //Toolbox is alread inited
+ SIOUXSettings.setupmenus = FALSE; //keep the csound menus
+ SIOUXSettings.autocloseonquit = TRUE; //close sioux without asking for save
+ SIOUXSettings.showstatusline = FALSE; //no status line
+ SIOUXSettings.asktosaveonclose = FALSE; //don't ask to save
+ SIOUXSettings.toppixel = 40;
+ SIOUXSettings.leftpixel = 5;
+
+ /* see if we have WaitNextEvent and Color Quickdraw */
+ wneImplemented = (NGetTrapAddress (_WaitNextEvent, ToolTrap) != NGetTrapAddress (_Unimplemented, ToolTrap));
+ if (NGetTrapAddress ((short) Gestalt, ToolTrap) != NGetTrapAddress (_Unimplemented, ToolTrap)) {
+ long returnCode;
+ OSErr err = Gestalt (gestaltQuickdrawVersion, &returnCode);
+ hasColorQD = ((err == noErr) && (returnCode >= gestalt8BitQD));
+ } else hasColorQD = false;
+
+ { /* set up menus */
+ Handle theMenuBar = GetNewMBar (MBAR_RES);
+ SetMenuBar (theMenuBar);
+ appleMenu = (MenuHandle)GetMenuHandle (APPLE_MENU_RES);
+ fileMenu = (MenuHandle)GetMenuHandle (FILE_MENU_RES);
+ editMenu = (MenuHandle)GetMenuHandle (EDIT_MENU_RES);
+ controlMenu = (MenuHandle)GetMenuHandle (CONTROL_MENU_RES);
+ AppendResMenu (appleMenu, 'DRVR');
+ DrawMenuBar ();
+ }
+
+ /* get the size of the main screen */
+ screenWidth = qd.screenBits.bounds.right - qd.screenBits.bounds.left;
+ screenHeight = qd.screenBits.bounds.bottom - qd.screenBits.bounds.top;
+
+ /* compute the size of the graphics window in split-screen mode */
+ gHorizontal = SCREEN_MARGIN;
+ gVertical = MBAR_HEIGHT + TITLEBAR_HEIGHT - 1;
+ gWidth = screenWidth - (SCREEN_MARGIN * 2);
+ gHeight = GRAFWIN_HEIGHT;
+
+ /* compute the size of the command window in split-screen mode */
+ sHorizontal = SCREEN_MARGIN;
+ sVertical = MBAR_HEIGHT + TITLEBAR_HEIGHT - 1 + SCREEN_MARGIN + GRAFWIN_HEIGHT;
+ sWidth = screenWidth - (SCREEN_MARGIN * 2);
+ sHeight = screenHeight - MBAR_HEIGHT - TITLEBAR_HEIGHT - (SCREEN_MARGIN * 2) - GRAFWIN_HEIGHT - 1;
+
+ /* set up size and drag rects */
+ dragRect = (*GetGrayRgn ())->rgnBBox;
+// dragRect.left += DRAG_THRESHOLD;
+// dragRect.right -= DRAG_THRESHOLD;
+// dragRect.bottom -= DRAG_THRESHOLD;
+ sizeRect.top = MIN_WIN_HEIGHT;
+ sizeRect.left = MIN_WIN_WIDTH;
+ sizeRect.bottom = qd.screenBits.bounds.bottom - qd.screenBits.bounds.top;
+ sizeRect.right = qd.screenBits.bounds.right - qd.screenBits.bounds.left;
+
+ /* create the command window */
+ gCommandWin = GetNewWindow (CWINRES, &commandWinRec, (WindowPtr) -1L);
+ SetPort (gCommandWin);
+
+ /* create the graphics window */
+ if (hasColorQD) gGraphicsWin = GetNewCWindow (GWINRES, &colorGraphicsWinRec, (WindowPtr) -1L);
+ else gGraphicsWin = GetNewWindow (GWINRES, &bwGraphicsWinRec, (WindowPtr) -1L);
+
+ startupTicks = TickCount (); /* take note of what time we're starting up */
+
+ // Create mouse regin
+ gMouseRgn = NewRgn();
+
+ // Initalize some command window stuff
+ InitalizeCmdWindow();
+
+ // Turn on text outlineing
+ TEFeatureFlag(teFOutlineHilite, teBitSet, hTERec);
+
+ HideGrafWin ();
+
+ { /* see if the user launched the app by opening text files from the Finder */
+ short doWhat;\
+// call to CountAppFiles was commented out, but that left doWhat uninitialized
+// RBD added this ifdef, I wonder where CountAppFiles came from?
+#ifdef CountAppFilesDefined
+ CountAppFiles (&doWhat, &howManyFiles);
+ if (doWhat != appOpen) howManyFiles = 0;
+#else
+ howManyFiles = 0;
+#endif
+ }
+
+ UpdateCmdWindow ();
+
+}
+
+
+
+static void DoAppleMenu (int theItem) {
+ switch (theItem) {
+ case ABOUT_ITEM:
+ DoAboutBox ();
+ break;
+ default: {
+ Str255 name;
+ GetMenuItemText (appleMenu, theItem, name);
+ OpenDeskAcc (name);
+ break;
+ }
+ }
+}
+/* this should really be in a header for MacFileUtils.c */
+void GetFullPath(FSSpec *theSpec, StringPtr theName);
+
+
+static void DoFileMenu (int theItem) {
+ extern xlload (char *, int, int);
+ extern xlabort(char *);
+ extern xlisp_wrapup (void);
+ StandardFileReply theFile;
+
+ SFTypeList fileTypes;
+ Point pt = { 100, 100 };
+
+ fileTypes[0] = 'TEXT';
+ switch (theItem) {
+ case LOAD:
+ case LOAD_NOISILY:
+ StopPasting ();
+ StandardGetFile(NIL, 1, fileTypes, &theFile);
+ if (theFile.sfGood) {
+ Str255 theFullPath;
+ short wdRefNum;
+
+ OSErr err;
+ HiliteMenu (0);
+
+ err = OpenWD(theFile.sfFile.vRefNum, theFile.sfFile.parID, 'Nyqu', &wdRefNum);
+ err = SetVol(NIL, wdRefNum);
+ SetSelection (TEXTREC->teLength, TEXTREC->teLength); /* send cursor to end */
+
+ GetFullPath(&theFile.sfFile, theFullPath);
+ P2CStr(theFullPath);
+
+ if ((xlload((char *) theFullPath, 1, (theItem == LOAD_NOISILY))) == 0) {
+ xlabort("load error");
+ }
+ macputs ("> ");
+ PrepareForInput ();
+ }
+ break;
+ case QUIT:
+ xlisp_wrapup ();
+ }
+}
+
+static void DoEditMenu (int theItem) {
+ if (SystemEdit (theItem-1) == false)
+ switch (theItem) {
+ case CUT: case COPY:
+ if (ZeroScrap () == noErr) {
+ TECopy (hTERec); /* after copying, export the TE scrap */
+ if (TEToScrap () != noErr) ZeroScrap ();
+ }
+ if (theItem == CUT) DeleteRange ();
+ break;
+ case PASTE: {
+ long scrapOffset;
+ if (pastedTextH) DisposeHandle (pastedTextH);
+ pastedTextH = (CharsHandle) NewHandle (0);
+ pastedLength = GetScrap (pastedTextH, 'TEXT', &scrapOffset);
+ if (pastedLength < 0) pastedLength = 0; /* error */
+ else {
+ SetHandleSize (pastedTextH, pastedLength + 1);
+ HLock (pastedTextH);
+ ((char *)(*pastedTextH))[pastedLength] = '\0';
+ HUnlock (pastedTextH);
+ }
+ } /* and fall through ... */
+ case CLEAR:
+ DeleteRange ();
+ break;
+ }
+}
+
+static void DoControlMenu (int theItem) {
+ extern xlbreak (char *, char *);
+ extern char *s_unbound;
+ extern xlcontinue (void);
+ extern xlcleanup (void);
+ extern xlabort (char *);
+ extern xltoplevel (void);
+
+ scrflush ();
+ HiliteMenu (0);
+ switch (theItem) {
+ case BREAK: StopPasting (); xlbreak ("user break", s_unbound); PrepareForInput (); break;
+ case CONTINUE: StopPasting (); xlcontinue (); PrepareForInput (); break;
+ case CLEAN_UP: StopPasting (); xlcleanup (); PrepareForInput (); break;
+ case CANCEL_INPUT: StopPasting (); xlabort ("input canceled"); PrepareForInput (); break;
+ case TOP_LEVEL: StopPasting (); xltoplevel (); PrepareForInput (); break;
+ case SHOW_GRAPHICS:
+ if (gGraphicsShown) HideGrafWin ();
+ else ShowGrafWin ();
+ break;
+ case SPLIT_SCREEN:
+ MoveWindow (gCommandWin, sHorizontal, sVertical, -1);
+ SizeWindow (gCommandWin, sWidth, sHeight, -1);
+ InvalRect (&gCommandWin->portRect);
+ SetTERect ();
+ SetScrollRect ();
+ ShowGrafWin ();
+ MoveWindow (gGraphicsWin, gHorizontal, gVertical, -1);
+ SizeWindow (gGraphicsWin, gWidth, gHeight, -1);
+ break;
+ }
+}
+
+void DoMenu (long choice) {
+ int theMenu = HiWord (choice), theItem = LoWord (choice);
+
+ HiliteMenu (theMenu);
+ switch (theMenu) {
+ case APPLE_MENU_RES: DoAppleMenu (theItem); break;
+ case FILE_MENU_RES: DoFileMenu (theItem); break;
+ case EDIT_MENU_RES: DoEditMenu (theItem); break;
+ case CONTROL_MENU_RES: DoControlMenu (theItem); break;
+ }
+ HiliteMenu (0);
+}
+
+void AdjustMenus (void) {
+ /* turn the stuff in the Edit menu on and off as necessary */
+ long temp;
+ DisableItem (editMenu, UNDO);
+ if (TEXTREC->selStart != TEXTREC->selEnd) {
+ EnableItem (editMenu, CUT);
+ EnableItem (editMenu, COPY);
+ EnableItem (editMenu, CLEAR);
+ } else {
+ DisableItem (editMenu, CUT);
+ DisableItem (editMenu, COPY);
+ DisableItem (editMenu, CLEAR);
+ }
+ if (GetScrap (NIL, 'TEXT', &temp) > 0) EnableItem (editMenu, PASTE);
+ else DisableItem (editMenu, PASTE);
+}
+
+RgnHandle rgn = nil;
+
+void DoContent (EventRecord *theEvent) {
+ /* handle a click in a window's content region */
+ ControlHandle theScrollBar;
+ GrafPtr oldPort;
+ int scrollValue;
+ Point mouse = theEvent->where;
+ int thePart;
+// RgnHandle rgn = nil;
+
+ GetPort (&oldPort);
+ SetPort (gCommandWin);
+ GlobalToLocal (&mouse);
+
+ // Get Selected text
+ rgn = NewRgn();
+ TEGetHiliteRgn(rgn, hTERec);
+
+ if (thePart = FindControl (mouse, gCommandWin, &theScrollBar)) {
+ switch (thePart) {
+ case kControlUpButtonPart:
+ case kControlDownButtonPart:
+ case kControlPageUpPart:
+ case kControlPageDownPart:
+ scrollValue = TrackControl (theScrollBar, mouse, uppScrollProc);
+ break;
+ case kControlIndicatorPart:
+ scrollValue = GetControlValue (theScrollBar);
+ thePart = TrackControl (theScrollBar, mouse, NIL);
+ if (thePart) {
+ scrollValue -= GetControlValue (theScrollBar);
+ if (scrollValue) TEScroll (0, scrollValue * LINEHEIGHT, hTERec);
+ }
+ break;
+ }
+ } else if (PtInRgn(mouse, rgn)) {
+ if (!DragText(theEvent)) {
+ TEClick(mouse, false, hTERec);
+ }
+ } else if (PtInRect (mouse, &(TEXTREC->viewRect))) {
+ TEClick (mouse, (theEvent->modifiers & shiftKey) != 0, hTERec);
+ }
+ SetPort (oldPort);
+ DisposeRgn(rgn);
+}
+
+
+void DoEvent (void) {
+ EventRecord theEvent;
+
+ if ((flashTime) && (--flashTime == 0)) SetSelection (cursorBeforeFlash, cursorBeforeFlash);
+ if (outputBufferLength) FlushOutput ();
+ if (FrontWindow () == gCommandWin) TEIdle (hTERec);
+ recentChar = '\0';
+
+ if (WaitNextEvent (everyEvent, &theEvent, 0, gMouseRgn)) {
+
+ AdjustCursor (theEvent.where, gMouseRgn);
+
+ switch (theEvent.what) {
+ case kHighLevelEvent:
+ AEProcessAppleEvent(&theEvent);
+ break;
+ case mouseDown:
+ DoMouseDown (&theEvent);
+ break;
+ case keyDown:
+ case autoKey:
+ DoKeyPress (&theEvent);
+ break;
+ case activateEvt: {
+ WindowPtr whichWindow = (WindowPtr)theEvent.message;
+ SetPort (whichWindow);
+ if (whichWindow == gCommandWin) {
+ if ((theEvent.modifiers & activeFlag) == 1) {
+ ActivateCmdWindow();
+ } else {
+ DeactivateCmdWindow();
+ }
+ }
+ break;
+ }
+ case updateEvt: {
+ if ((WindowPtr)theEvent.message == gCommandWin) UpdateCmdWindow ();
+ if ((WindowPtr)theEvent.message == gGraphicsWin) UpdateGraphWindow ();
+ break;
+ }
+ case osEvt:
+ if (((theEvent.message >> 24) & 0xff) == suspendResumeMessage) {
+ if (theEvent.message & resumeFlag) {
+ gInBackground = false;
+ if (FrontWindow () == gCommandWin) {
+ ActivateCmdWindow();
+ }
+ } else {
+ gInBackground = true;
+ if (FrontWindow () == gCommandWin) {
+ SetPort (gCommandWin);
+ DeactivateCmdWindow();
+ }
+ }
+ }
+ break;
+
+ }
+ }
+ AdjustCursor (theEvent.where, gMouseRgn);
+}
+
+void MacWrapUp (void) {
+ /* take everything down in preparation for quitting */
+ CleanupCmdWindow();
+ CloseWindow (gGraphicsWin);
+}
diff --git a/sys/mac/macint.h b/sys/mac/macint.h
new file mode 100644
index 0000000..6092e67
--- /dev/null
+++ b/sys/mac/macint.h
@@ -0,0 +1,166 @@
+#define INT_MAX +32767
+
+#define INT_MIN -32767
+
+/* resource id's */
+
+#define CWINRES 400
+
+#define GWINRES 401
+
+#define MBAR_RES 400
+
+#define APPLE_MENU_RES 400
+
+#define FILE_MENU_RES 401
+
+#define EDIT_MENU_RES 402
+
+#define CONTROL_MENU_RES 403
+
+#define STRINGS_RES 400
+
+
+
+/* Apple menu */
+
+#define ABOUT_ITEM 1
+
+#define ABOUT_BOX 400
+
+#define ABOUT_PICT 400
+
+
+
+/* File menu */
+
+#define LOAD 1
+
+#define LOAD_NOISILY 2
+
+#define QUIT 4
+
+
+
+/* Edit menu */
+
+#define UNDO 1
+
+#define CUT 3
+
+#define COPY 4
+
+#define PASTE 5
+
+#define CLEAR 6
+
+
+
+/* Control menu */
+
+#define BREAK 1
+
+#define CONTINUE 2
+
+#define CLEAN_UP 3
+
+#define CANCEL_INPUT 4
+
+#define TOP_LEVEL 5
+
+#define SHOW_GRAPHICS 7
+
+#define SPLIT_SCREEN 8
+
+
+
+/* window sizing/dragging stuff */
+
+#define DRAG_THRESHOLD 8
+
+#define MIN_WIN_HEIGHT 80
+
+#define MIN_WIN_WIDTH 120
+
+
+
+#define MAX_BUF 250 /* max chars in output buffer */
+
+#define SCROLLBACK_THRESHHOLD 30000 /* max chars kept in window */
+
+#define DELETE_BLOCK 10000 /* how many chars to delete when threshhold reached */
+
+
+
+#define LINEHEIGHT 11 /* height in pixels of 9-point Geneva, the font used */
+
+#define STACKMIN 400000 /* amout of memory for application stack */
+
+#define MASTERS 3 /* arbitrary -- how many times to call MoreMasters() */
+
+
+
+/* key codes */
+
+#define RETURN 0x0d
+
+#define ENTER 0x03
+
+#define DELETE 0x08
+
+#define FWDDEL 0x7F
+
+#define CLRKEY 0x1b
+
+#define PAGEUP 0x0b
+
+#define PAGEDN 0x0c
+
+#define HOMEKEY 0x01
+
+#define ENDKEY 0x04
+
+#define HELPKEY 0x05
+
+#define FNKEY 0x10
+
+#define LEFTARROW 0x1c
+
+#define RIGHTARROW 0x1d
+
+#define UPARROW 0x1e
+
+#define DOWNARROW 0x1f
+
+#define DBLQUOTE '\"'
+
+
+
+/* useful definitions */
+
+#define MBAR_HEIGHT 20
+
+#define TITLEBAR_HEIGHT 20
+
+#define SCROLLER_WIDTH 15
+
+#define SCREEN_MARGIN 2
+
+#define TEXT_MARGIN 4
+
+#define GRAFWIN_HEIGHT 232
+
+void AdjustMenus(void);
+
+void DoMenu(long choice);
+
+void HideGrafWin(void);
+
+void DoContent(EventRecord *theEvent);
+
+void InitMac(void);
+
+void MacWrapUp(void);
+
+
+void DoEvent (void);
diff --git a/sys/mac/macptrs.h b/sys/mac/macptrs.h
new file mode 100644
index 0000000..4dad03a
--- /dev/null
+++ b/sys/mac/macptrs.h
@@ -0,0 +1,52 @@
+{ "HIDEPEN", S, xhidepen }, /* 300 */
+
+{ "SHOWPEN", S, xshowpen }, /* 301 */
+
+{ "GETPEN", S, xgetpen }, /* 302 */
+
+{ "PENSIZE", S, xpensize }, /* 303 */
+
+{ "PENMODE", S, xpenmode }, /* 304 */
+
+{ "PENPAT", S, xpenpat }, /* 305 */
+
+{ "PENNORMAL", S, xpennormal }, /* 306 */
+
+{ "MOVETO", S, xmoveto }, /* 307 */
+
+{ "MOVE", S, xmove }, /* 308 */
+
+{ "LINETO", S, xdrawto }, /* 309 */
+
+{ "LINE", S, xdraw }, /* 310 */
+
+{ "SHOW-GRAPHICS", S, xshowgraphics }, /* 311 */
+
+{ "HIDE-GRAPHICS", S, xhidegraphics }, /* 312 */
+
+{ "CLEAR-GRAPHICS", S, xcleargraphics }, /* 313 */
+
+{ "TOOLBOX", S, xtool }, /* 314 */
+
+{ "TOOLBOX-16", S, xtool16 }, /* 315 */
+
+{ "TOOLBOX-32", S, xtool32 }, /* 316 */
+
+{ "NEWHANDLE", S, xnewhandle }, /* 317 */
+
+{ "NEWPTR", S, xnewptr }, /* 318 */
+
+{ "HIWORD", S, xhiword }, /* 319 */
+
+{ "LOWORD", S, xloword }, /* 320 */
+
+{ "READ-CHAR-NO-HANG", S, xrdnohang }, /* 321 */
+
+
+
+/* not implemented - take a look at code in directory "sys:mac:old" */
+
+/*{ "COMMAND-POINT-SIZE", S, xptsize }, 322 */
+
+
+
diff --git a/sys/mac/macstuff.c b/sys/mac/macstuff.c
new file mode 100644
index 0000000..99ecad8
--- /dev/null
+++ b/sys/mac/macstuff.c
@@ -0,0 +1,226 @@
+/* macstuff.c - macintosh interface routines for xlisp */
+/* Written by Brian Kendig. */
+/* This file contains the stuff that the other xlisp files call directly. */
+
+#include "cext.h"
+#include <stdio.h>
+#include <stdarg.h>
+#include <QuickDraw.h> /* for Random */
+#include <Memory.h> /* for DisposePtr */
+#include <SegLoad.h> /* for ExitToShell */
+#include "xlisp.h"
+#include <string.h>
+#include "macint.h"
+#include "MacCommandWin.h"
+#define DELETE 0x08
+
+/* externals */
+extern FILE *tfp; /* transcript file pointer */
+extern int cursorPos;
+extern char *macgets (void);
+
+/* local variables */
+int lposition;
+static char *linebuf = NULL, *lineptr;
+static int numChars;
+
+/* system-dependent variable definitions */
+static const char os_pathchar = ':';
+static const char os_sepchar = ',';
+
+
+int isascii (char c) { return 1; } /* every char is an ascii char, isn't it? */
+
+void osinit (char *banner) {
+ int i;
+ char version[] = "\nMacintosh interface by Brian Kendig, Erik A. Dahl, and Dominic Mazzoni.\n";
+ InitMac (); /* initialize the mac interface routines */
+ lposition = 0; /* initialize the line editor */
+ for (i = 0; banner[i] != '\0'; i++) macputc (banner[i]);
+ for (i = 0; version[i] != '\0'; i++) macputc (version[i]);
+}
+
+FILE *osaopen (char *name, char *mode) {
+ return fopen (name, mode);
+}
+
+FILE *osbopen (char *name, char *mode) {
+ FILE *f;
+ char nmode[4];
+ strcpy (nmode, mode); strcat (nmode, "b");
+ f = fopen(name, nmode);
+ return f;
+}
+
+int osclose (FILE *fp) { return (fclose (fp)); }
+int osaputc (int ch, FILE *fp) { return (putc (ch, fp)); }
+int osbputc (int ch, FILE *fp) { return (putc (ch, fp)); }
+
+/* osagetc - get a character from an ascii file */
+int osagetc(fp)
+ FILE *fp;
+{
+ return (getc(fp));
+}
+
+int ostgetc (void) {
+ int i;
+
+ if (numChars <= 0) { /* get some more */
+ if (linebuf) DisposePtr (linebuf);
+ linebuf = macgets ();
+ i = 0;
+ while (linebuf[i] != '\0') i++;
+ numChars = i;
+ if (tfp) for (i = 0; i < numChars; i++) osaputc (linebuf[i], tfp);
+ lineptr = linebuf;
+ }
+ numChars--;
+ if (*lineptr == '\r') {
+ lineptr++;
+ return '\n';
+ } else return (*lineptr++);
+}
+
+void ostputc (int ch) {
+ macputc (ch);
+ if (tfp) osaputc (ch, tfp);
+}
+
+void osflush (void) {
+ lineptr = linebuf;
+ numChars = 0;
+ lposition = 0;
+}
+
+void oscheck (void) { DoEvent (); }
+
+void oserror (char *msg) {
+ char line[100], *p;
+ sprintf (line,"error: %s\n",msg);
+ for (p = line; *p != '\0'; ++p) ostputc (*p);
+}
+
+void osfinish(void) {
+ /* dispose of everything... */
+ if (linebuf) DisposePtr(linebuf);
+ portaudio_exit();
+ MacWrapUp ();
+ ExitToShell ();
+}
+
+#define GPRINTF_MESSAGE_LEN 500
+
+/* nyquist_printf -- system independent version of printf */
+/*
+ * this function prints to console like printf, but using GUI
+ * rather than stdio when appropriate.
+ *
+ */
+void nyquist_printf(char *format, ...)
+{
+ char temp[GPRINTF_MESSAGE_LEN];
+ va_list pvar;
+ char *p = temp;
+ va_start(pvar, format);
+ vsnprintf(temp, GPRINTF_MESSAGE_LEN, format, pvar);
+ va_end(pvar);
+ while (*p) ostputc(*p++);
+}
+
+int renamebackup (char *filename) { return 0; }
+
+static FSSpec prefsFSSpec;
+static int need_preferences_file = false;
+static char xlisp_path[1024]; /* cache for the path */
+static int valid_xlisp_path = false;
+
+/* xsetupconsole -- used to configure window in Win32 version */
+LVAL xsetupconsole() { return NIL; }
+
+
+/* this should really be in a header for MacFileUtils.c */
+void GetFullPath(FSSpec *theSpec, StringPtr theName);
+
+
+void get_xlisp_path(char *p, long p_max, int *prefs_found)
+{
+ Str63 fileName = "\pXLisp Preferences";
+ SInt16 foundPrefVRefNum = 0;
+ SInt32 foundPrefDirID = 0;
+ OSErr err = noErr;
+ *p = 0; /* initialize to empty string */
+ *prefs_found = false;
+ /* if we find path in the cache, copy and return */
+ if (valid_xlisp_path) {
+ *prefs_found = true;
+ strcpy(p, xlisp_path + 10); /* remember, path has XLISPPATH= at head */
+ return;
+ }
+ /* if we've been here before, do not try opening again */
+ if (need_preferences_file) return;
+ err = FindFolder(kOnSystemDisk, kPreferencesFolderType,
+ kDontCreateFolder, &foundPrefVRefNum,
+ &foundPrefDirID);
+ if (err == noErr) {
+ err = FSMakeFSSpec(foundPrefVRefNum, foundPrefDirID,
+ fileName, &prefsFSSpec);
+ *prefs_found = (err == noErr);
+ need_preferences_file = !*prefs_found;
+ }
+ if (*prefs_found) {
+ FILE *pf;
+ GetFullPath(&prefsFSSpec, (StringPtr) xlisp_path);
+ P2CStr((StringPtr) xlisp_path);
+ pf = fopen(xlisp_path, "r");
+ if (!pf) {
+ return; /* problem opening the path */
+ }
+ while (fgets(xlisp_path, 1023, pf)) {
+ if (strncmp(xlisp_path, "XLISPPATH=", 10) == 0) {
+ valid_xlisp_path = true;
+ xlisp_path[strlen(xlisp_path) - 1] = 0; /* trim newline */
+ strcpy(p, xlisp_path + 10);
+ break;
+ }
+ }
+ fclose(pf);
+ }
+}
+
+
+/* this is called when we load a file -- if need_preference_file,
+ * we will build a preference file and insert the path of the file
+ * we just opened, assuming it will tell us where to find init.lsp
+ */
+void setup_preferences(char *filename)
+{
+ if (need_preferences_file) {
+ unsigned char prefname[256];
+ FILE *pf;
+ char *cp;
+ int len = 0;
+ GetFullPath(&prefsFSSpec, prefname);
+ need_preferences_file = false;
+ P2CStr(prefname);
+ /* we expect file-not-found error, path is valid */
+ pf = fopen((char *) prefname, "w");
+ if (pf == NULL) return;
+ cp = strrchr((char *) filename, ':');
+ if (cp == NULL) return;
+ cp[1] = 0;
+ /* now, filename is the path. If filename ends in runtime, this
+ * is probably the standard nyquist runtime folder. We should put
+ * the nyquist lib folder on the path too.
+ */
+ len = cp + 1 - filename;
+ if (len >= 9 &&
+ strcmp(filename + len - 9, ":runtime:") == 0) {
+ filename[len - 8] = 0;
+ fprintf(pf, "XLISPPATH=%sruntime:,%slib:\n", filename, filename);
+ } else {
+ fprintf(pf, "XLISPPATH=%s\n", filename);
+ }
+ fclose(pf);
+ }
+}
diff --git a/sys/mac/macstuff.h b/sys/mac/macstuff.h
new file mode 100644
index 0000000..29b9b32
--- /dev/null
+++ b/sys/mac/macstuff.h
@@ -0,0 +1,7 @@
+/* macstuff.h -- header for mac-specific functions */
+
+void osfinish(void);
+/* put searchpath into p, prefs_found tells if preference file exists */
+void get_xlisp_path(char *p, long p_max, int *prefs_found);
+void setup_preferences(char *filename);
+
diff --git a/sys/mac/sndsystem.h b/sys/mac/sndsystem.h
new file mode 100644
index 0000000..f34ea83
--- /dev/null
+++ b/sys/mac/sndsystem.h
@@ -0,0 +1,2 @@
+#include "sndmac.h"
+
diff --git a/sys/mac/switches.h b/sys/mac/switches.h
new file mode 100644
index 0000000..c5a8e58
--- /dev/null
+++ b/sys/mac/switches.h
@@ -0,0 +1,58 @@
+/* switches.h for Macintosh */
+
+/* CHANGE LOG
+ * --------------------------------------------------------------------
+ * 28Apr03 dm major reorganization of conditional compilation in Nyquist
+ */
+
+
+#define HAS_STDLIB_H 1
+#undef HAS_SYS_TYPES_H
+#undef HAS_SYS_STAT_H
+#define HAS_STAT_H 1
+#undef HAS_MALLOC_H
+
+#define HAS_GETTIMEOFDAY 1
+
+#undef READ_LINE
+
+#define XL_BIG_ENDIAN 1
+#undef XL_LITTLE_ENDIAN
+
+#define USE_RAND 1
+#undef USE_RANDOM
+
+/* define this to be printf, or define your own fn of the form
+ void nyquist_printf(char *format, ...);
+ (for a GUI)
+*/
+void nyquist_printf(char *format, ...);
+
+#define NEED_ULONG 1
+#define NEED_USHORT 1
+#define NEED_BYTE 1
+
+#define NEED_ROUND 1
+
+#undef NEED_DEFINE_MALLOC
+
+/* explicitly choose a platform */
+#undef UNIX
+#undef WINDOWS
+#undef MICROSOFT
+#undef DOS
+#define MACINTOSH 1
+
+#define BUFFERED_SYNCHRONOUS_INPUT 1
+#define SPACE_FOR_PLAY 10000
+#define MAX_CHANNELS 16
+
+/* this will enable code to read midi files, etc. */
+#define CMTSTUFF 1
+
+/* NYQUIST tells some CMT code that we're really in
+ * XLISP and NYQUIST
+ */
+#define NYQUIST 1
+
+#include "swlogic.h"
diff --git a/sys/mac/system.lsp b/sys/mac/system.lsp
new file mode 100644
index 0000000..ea65573
--- /dev/null
+++ b/sys/mac/system.lsp
@@ -0,0 +1,107 @@
+; system.lsp -- machine/system-dependent definitions
+; Macintosh
+
+(setf ny:bigendianp t)
+
+;; note that *default-sf-format* is used below by
+;; compute-default-sound-file
+(if (not (boundp '*default-sf-format*))
+ (setf *default-sf-format* snd-head-AIFF))
+
+;; note that compute-default-sound-file uses *default-sf-format*,
+;; so be sure to set *default-sf-format* first (this was just done)
+(if (not (boundp '*default-sound-file*))
+ (compute-default-sound-file))
+
+ (if (not (boundp '*default-sf-dir*))
+ (setf *default-sf-dir* ""))
+
+(if (not (boundp '*default-sf-mode*))
+ (setf *default-sf-mode* snd-mode-pcm))
+
+(if (not (boundp '*default-sf-bits*))
+ (setf *default-sf-bits* 16))
+
+(if (not (boundp '*default-plot-file*))
+ (setf *default-plot-file* "points.dat"))
+
+; turn off switch to play sound as it is computed
+(setf *soundenable* T)
+
+; local definition for play
+(defmacro play (expr)
+ `(s-save-autonorm ,expr NY:ALL *default-sound-file* :play *soundenable*))
+
+(defun r ()
+ (s-save (s-read *default-sound-file*) NY:ALL "" :play t)
+)
+
+; PLAY-FILE -- play a file
+(defun play-file (name)
+ (s-save (s-read name) NY:ALL "" :play t))
+
+; FULL-NAME-P -- test if file name is a full path or relative path
+;
+; (otherwise the *default-sf-dir* will be prepended
+;
+(defun full-name-p (filename)
+ (eq (char filename 0) #\:))
+
+(setf *file-separator* #\:)
+
+; save the standard function to write points to a file
+;
+;(setfn s-plot-points s-plot)
+
+(defun array-max-abs (points)
+ (let ((m 0.0))
+ (dotimes (i (length points))
+ (setf m (max m (abs (aref points i)))))
+ m))
+
+(setf graph-width 800)
+(setf graph-height 220)
+
+
+(defun s-plot (snd &optional (n 800))
+ (show-graphics)
+ (clear-graphics)
+ (cond ((soundp snd)
+ (s-plot-2 snd n (/ graph-height 2) graph-height nil))
+ (t
+ (let ((gh (/ graph-height (length snd)))
+ hs)
+ (dotimes (i (length snd))
+ (setf hs (s-plot-2 (aref snd i) n (+ (/ gh 2) (* i gh)) gh hs)))))))
+
+
+(defun s-plot-2 (snd n y-offset graph-height horizontal-scale)
+ (prog ((points (snd-samples snd n))
+ maxpoint horizontal-scale vertical-scale)
+ (setf maxpoint (array-max-abs points))
+ (moveto 0 y-offset)
+ (lineto graph-width y-offset)
+ (moveto 0 y-offset)
+ (cond ((null horizontal-scale)
+ (setf horizontal-scale (/ (float graph-width) (length points)))))
+ (setf vertical-scale (- (/ (float graph-height) 2 maxpoint)))
+ (dotimes (i (length points))
+ (lineto (truncate (* horizontal-scale i))
+ (+ y-offset (truncate (* vertical-scale (aref points i))))))
+ (format t "X Axis: ~A to ~A (seconds)\n" (snd-t0 snd) (/ (length points) (snd-srate snd)))
+ (format t "Y Axis: ~A to ~A\n" (- maxpoint) maxpoint)
+ (format t "~A samples plotted.\n" (length points))
+ (return horizontal-scale)
+ ))
+
+
+
+
+; S-EDIT - run the audio editor on a sound
+;
+;(defmacro s-edit (&optional expr)
+; `(prog ()
+; (if ,expr (s-save ,expr 1000000000 *default-sound-file*))
+; (system (format nil "audio_editor ~A &"
+; (soundfilename *default-sound-file*)))))
+
diff --git a/sys/mac/xlextstart.c b/sys/mac/xlextstart.c
new file mode 100644
index 0000000..be321fe
--- /dev/null
+++ b/sys/mac/xlextstart.c
@@ -0,0 +1 @@
+/* nothing to do */