home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / PROG / MISC / XLSP21TC.ZIP / XLISP.MAC / text0000.txt < prev   
Encoding:
Text File  |  1991-04-14  |  27.5 KB  |  1,377 lines

  1. In article <2091@cunixc.cc.columbia.edu>, puglia@cunixc.cc.columbia.edu (Paul Puglia) writes:
  2. > How does you build xscheme on a macintosh ? I have a copy of 
  3. > the xscheme sources compiles fine on a unix machine, and works
  4. > great on a pc with turbo c.  When I tried to compile it on a 
  5. > friends mac II using his copy of lightspeed c. I have no luck. 
  6. > Could someone please describe the procedure to compile this program, and
  7. > comment on if anything else is need to compile xscheme. I know that you 
  8. > need some resource to compile xlisp on a mac. Do you need the same sort of 
  9. > stuff for xscheme
  10. > Thanks in advance
  11. > Paul Puglia
  12. > Dept of Civil Engineering 
  13. > Columbia University
  14.  
  15.  
  16.  
  17. Porting Xlisp/XScheme:
  18.  
  19. Awhile back, while I was taking an AI course, I was spending a lot of time
  20. trekking to campus and using their LISP system.  To avoid travel time (and
  21. to work on LISP at any hour I wanted), I got into porting XLisp. In looking at 
  22. the code, I'd say XLisp and XScheme are two of the most portable C programs
  23. I have ever seen.  Now, I've spent most of my time on XLisp, so your
  24. mileage may vary, but...
  25.  
  26. XLisp seems to place most Operating System (OS)-dependent features in 
  27. separate files, named dosstuff.c, osptrs.h, osdefs.h.  On UNIX, the "stuff:
  28. file is called unixstuf.c and on the Mac its called macstuff.c (all file
  29. names are <= 8 chars for MS-DOS).  The mac version also has a resource
  30. compiler file (that is, a file you run through the resource compiler to
  31. generate a resource file).
  32.  
  33. I assume (hope) XScheme is similiar.  Below, I placed all my Mac-related
  34. files from XLisp (2.0, I think).  The XScheme stuff should be similiar.
  35. I hope these help.  (Note: I don't have the full sources around now, just
  36. the Mac and UNIX-specific files.)  (Note2: Two extra files, macfun.c and
  37. macinit.c are below, its been so long that I'm not sure if these are extras
  38. or necessary--Sorry.)
  39.  
  40. I'm placing these files here in hopes they can help you with your porting.  I
  41. do know that binary executable versions of XScheme are available on the
  42. BIX bulletin board (Byte magazine Information eXchange)--see Byte mag
  43. for details.  Getting the binaries would solve all the Mac porting
  44. problems in one fell swoop.
  45.  
  46. Anyway, hope this helps,
  47. -Eric
  48.  
  49.  
  50. ======================== macfun.c =============================================
  51.  
  52. /* macfun.c - macintosh user interface functions for xlisp */
  53.  
  54. #include <Quickdraw.h>
  55. #include <WindowMgr.h>
  56. #include <MemoryMgr.h>
  57. #include "xlisp.h"
  58.  
  59. /* external variables */
  60. extern GrafPtr cwindow,gwindow;
  61.  
  62. /* forward declarations */
  63. FORWARD LVAL do_0();
  64. FORWARD LVAL do_1();
  65. FORWARD LVAL do_2();
  66.  
  67. /* xptsize - set the command window point size */
  68. LVAL xptsize()
  69. {
  70.     LVAL val;
  71.     val = xlgafixnum();
  72.     xllastarg();
  73.     TextSize((int)getfixnum(val));
  74.     InvalRect(&cwindow->portRect);
  75.     SetupScreen();
  76.     return (NIL);
  77. }
  78.  
  79. /* xhidepen - hide the pen */
  80. LVAL xhidepen()
  81. {
  82.     return (do_0('H'));
  83. }
  84.  
  85. /* xshowpen - show the pen */
  86. LVAL xshowpen()
  87. {
  88.     return (do_0('S'));
  89. }
  90.  
  91. /* xgetpen - get the pen position */
  92. LVAL xgetpen()
  93. {
  94.     LVAL val;
  95.     Point p;
  96.     xllastarg();
  97.     SetPort(gwindow);
  98.     GetPen(&p);
  99.     SetPort(cwindow);
  100.     xlsave1(val);
  101.     val = consa(NIL);
  102.     rplaca(val,cvfixnum((FIXTYPE)p.h));
  103.     rplacd(val,cvfixnum((FIXTYPE)p.v));
  104.     xlpop();
  105.     return (val);
  106. }
  107.  
  108. /* xpenmode - set the pen mode */
  109. LVAL xpenmode()
  110. {
  111.     return (do_1('M'));
  112. }
  113.  
  114. /* xpensize - set the pen size */
  115. LVAL xpensize()
  116. {
  117.     return (do_2('S'));
  118. }
  119.  
  120. /* xpenpat - set the pen pattern */
  121. LVAL xpenpat()
  122. {
  123.     LVAL plist;
  124.     char pat[8],i;
  125.     plist = xlgalist();
  126.     xllastarg();
  127.     for (i = 0; i < 8 && consp(plist); ++i, plist = cdr(plist))
  128.     if (fixp(car(plist)))
  129.         pat[i] = getfixnum(car(plist));
  130.     SetPort(gwindow);
  131.     PenPat(pat);
  132.     SetPort(cwindow);
  133.     return (NIL);
  134. }
  135.  
  136. /* xpennormal - set the pen to normal */
  137. LVAL xpennormal()
  138. {
  139.     xllastarg();
  140.     SetPort(gwindow);
  141.     PenNormal();
  142.     SetPort(cwindow);
  143.     return (NIL);
  144. }
  145.  
  146. /* xmoveto - Move to a screen location */
  147. LVAL xmoveto()
  148. {
  149.     return (do_2('m'));
  150. }
  151.  
  152. /* xmove - Move in a specified direction */
  153. LVAL xmove()
  154. {
  155.     return (do_2('M'));
  156. }
  157.  
  158. /* xlineto - draw a Line to a screen location */
  159. LVAL xlineto()
  160. {
  161.     return (do_2('l'));
  162. }
  163.  
  164. /* xline - draw a Line in a specified direction */
  165. LVAL xline()
  166. {
  167.     return (do_2('L'));
  168. }
  169.  
  170. /* xshowgraphics - show the graphics window */
  171. LVAL xshowgraphics()
  172. {
  173.     xllastarg();
  174.     scrsplit(1);
  175.     return (NIL);
  176. }
  177.  
  178. /* xhidegraphics - hide the graphics window */
  179. LVAL xhidegraphics()
  180. {
  181.     xllastarg();
  182.     scrsplit(0);
  183.     return (NIL);
  184. }
  185.  
  186. /* xcleargraphics - clear the graphics window */
  187. LVAL xcleargraphics()
  188. {
  189.     xllastarg();
  190.     SetPort(gwindow);
  191.     EraseRect(&gwindow->portRect);
  192.     SetPort(cwindow);
  193.     return (NIL);
  194. }
  195.  
  196. /* do_0 - Handle commands that require no arguments */
  197. LOCAL LVAL do_0(fcn)
  198.   int fcn;
  199. {
  200.     xllastarg();
  201.     SetPort(gwindow);
  202.     switch (fcn) {
  203.     case 'H':    HidePen(); break;
  204.     case 'S':    ShowPen(); break;
  205.     }
  206.     SetPort(cwindow);
  207.     return (NIL);
  208. }
  209.  
  210. /* do_1 - Handle commands that require one integer argument */
  211. LOCAL LVAL do_1(fcn)
  212.   int fcn;
  213. {
  214.     int x;
  215.     x = getnumber();
  216.     xllastarg();
  217.     SetPort(gwindow);
  218.     switch (fcn) {
  219.     case 'M':    PenMode(x); break;
  220.     }
  221.     SetPort(cwindow);
  222.     return (NIL);
  223. }
  224.  
  225. /* do_2 - Handle commands that require two integer arguments */
  226. LOCAL LVAL do_2(fcn)
  227.   int fcn;
  228. {
  229.     int h,v;
  230.     h = getnumber();
  231.     v = getnumber();
  232.     xllastarg();
  233.     SetPort(gwindow);
  234.     switch (fcn) {
  235.     case 'l':    LineTo(h,v); break;
  236.     case 'L':    Line(h,v);   break;
  237.     case 'm':   MoveTo(h,v); break;
  238.     case 'M':    Move(h,v);   break;
  239.     case 'S':    PenSize(h,v);break;
  240.     }
  241.     SetPort(cwindow);
  242.     return (NIL);
  243. }
  244.  
  245. /* getnumber - get an integer parameter */
  246. LOCAL int getnumber()
  247. {
  248.     LVAL num;
  249.     num = xlgafixnum();
  250.     return ((int)getfixnum(num));
  251. }
  252.  
  253. /* xtool - call the toolbox */
  254. LVAL xtool()
  255. {
  256.     LVAL val;
  257.     int trap;
  258.  
  259.     trap = getnumber();
  260. /*
  261.  
  262.     asm {
  263.     move.l    args(A6),D0
  264.     beq    L2
  265. L1:    move.l    D0,A0
  266.     move.l    2(A0),A1
  267.     move.w    4(A1),-(A7)
  268.     move.l    6(A0),D0
  269.     bne    L1
  270. L2:    lea    L3,A0
  271.     move.w    trap(A6),(A0)
  272. L3:    dc.w    0xA000
  273.     clr.l    val(A6)
  274.     }
  275. */
  276.  
  277.     return (val);
  278. }
  279.  
  280. /* xtool16 - call the toolbox with a 16 bit result */
  281. LVAL xtool16()
  282. {
  283.     int trap,val;
  284.  
  285.     trap = getnumber();
  286. /*
  287.  
  288.     asm {
  289.     clr.w    -(A7)
  290.     move.l    args(A6),D0
  291.     beq    L2
  292. L1:    move.l    D0,A0
  293.     move.l    2(A0),A1
  294.     move.w    4(A1),-(A7)
  295.     move.l    6(A0),D0
  296.     bne    L1
  297. L2:    lea    L3,A0
  298.     move.w    trap(A6),(A0)
  299. L3:    dc.w    0xA000
  300.     move.w    (A7)+,val(A6)
  301.     }
  302. */
  303.  
  304.     return (cvfixnum((FIXTYPE)val));
  305. }
  306.  
  307. /* xtool32 - call the toolbox with a 32 bit result */
  308. LVAL xtool32()
  309. {
  310.     int trap;
  311.     long val;
  312.  
  313.     trap = getnumber();
  314. /*
  315.  
  316.     asm {
  317.     clr.l    -(A7)
  318.     move.l    args(A6),D0
  319.     beq    L2
  320. L1:    move.l    D0,A0
  321.     move.l    2(A0),A1
  322.     move.w    4(A1),-(A7)
  323.     move.l    6(A0),D0
  324.     bne    L1
  325. L2:    lea    L3,A0
  326.     move.w    trap(A6),(A0)
  327. L3:    dc.w    0xA000
  328.     move.l    (A7)+,val(A6)
  329.     }
  330. */
  331.  
  332.     return (cvfixnum((FIXTYPE)val));
  333. }
  334.  
  335. /* xnewhandle - allocate a new handle */
  336. LVAL xnewhandle()
  337. {
  338.     LVAL num;
  339.     long size;
  340.     num = xlgafixnum(); size = getfixnum(num);
  341.     xllastarg();
  342.     return (cvfixnum((FIXTYPE)NewHandle(size)));
  343. }
  344.  
  345. /* xnewptr - allocate memory */
  346. LVAL xnewptr()
  347. {
  348.     LVAL num;
  349.     long size;
  350.     num = xlgafixnum(); size = getfixnum(num);
  351.     xllastarg();
  352.     return (cvfixnum((FIXTYPE)NewPtr(size)));
  353. }
  354.     
  355. /* xhiword - return the high order 16 bits of an integer */
  356. LVAL xhiword()
  357. {
  358.     unsigned int val;
  359.     val = (unsigned int)(getnumber() >> 16);
  360.     xllastarg();
  361.     return (cvfixnum((FIXTYPE)val));
  362. }
  363.  
  364. /* xloword - return the low order 16 bits of an integer */
  365. LVAL xloword()
  366. {
  367.     unsigned int val;
  368.     val = (unsigned int)getnumber();
  369.     xllastarg();
  370.     return (cvfixnum((FIXTYPE)val));
  371. }
  372.  
  373. /* xrdnohang - get the next character in the look-ahead buffer */
  374. LVAL xrdnohang()
  375. {
  376.     int ch;
  377.     xllastarg();
  378.     if ((ch = scrnextc()) == EOF)
  379.     return (NIL);
  380.     return (cvfixnum((FIXTYPE)ch));
  381. }
  382.  
  383. /* ossymbols - enter important symbols */
  384. ossymbols()
  385. {
  386.     LVAL sym;
  387.  
  388.     /* setup globals for the window handles */
  389.     sym = xlenter("*COMMAND-WINDOW*");
  390.     setvalue(sym,cvfixnum((FIXTYPE)cwindow));
  391.     sym = xlenter("*GRAPHICS-WINDOW*");
  392.     setvalue(sym,cvfixnum((FIXTYPE)gwindow));
  393. }
  394.  
  395.  
  396. ======================== macint.c =============================================
  397.  
  398. /* macint.c - macintosh interface routines for xlisp */
  399.  
  400. #include <MacTypes.h>
  401. #include <Quickdraw.h>  
  402. #include <WindowMgr.h>
  403. #include <EventMgr.h>
  404. #include <DialogMgr.h>
  405. #include <MenuMgr.h>
  406. #include <PackageMgr.h>
  407. #include <StdFilePkg.h>
  408. #include <MemoryMgr.h>
  409. #include <DeskMgr.h>
  410. #include <FontMgr.h>
  411. #include <ControlMgr.h>
  412. #include <SegmentLdr.h>
  413. #include <FileMgr.h>
  414.  
  415. /* program limits */
  416. #define SCRH        40    /* maximum screen height */
  417. #define SCRW        100    /* maximum screen width */
  418. #define CHARMAX     100    /* maximum number of buffered characters */
  419. #define TIMEON        40    /* cursor on time */
  420. #define TIMEOFF        20    /* cursor off time */
  421.  
  422. /* useful definitions */
  423. #define MenuBarHeight    20
  424. #define TitleBarHeight    20
  425. #define SBarWidth    16
  426. #define MinWidth    80
  427. #define MinHeight    40
  428. #define ScreenMargin    2
  429. #define TextMargin    4
  430. #define GHeight        232
  431.  
  432. /* menu id's */
  433. #define appleID        1
  434. #define fileID        256
  435. #define editID        257
  436. #define controlID    258
  437.  
  438. /* externals */
  439. extern char *s_unbound;
  440. extern char *PtoCstr();
  441.  
  442. /* screen dimensions */
  443. int screenWidth;
  444. int screenHeight;
  445.  
  446. /* command window (normal screen) */
  447. int nHorizontal,nVertical,nWidth,nHeight;
  448.  
  449. /* command window (split screen) */
  450. int sHorizontal,sVertical,sWidth,sHeight;
  451.  
  452. /* graphics window */
  453. int gHorizontal,gVertical,gWidth,gHeight;
  454.  
  455. /* menu handles */
  456. MenuHandle appleMenu;
  457. MenuHandle fileMenu;
  458. MenuHandle editMenu;
  459. MenuHandle controlMenu;
  460.  
  461. /* misc variables */
  462. OSType filetypes[] = { 'TEXT' };
  463.  
  464. /* font information */
  465. int tmargin,lmargin;
  466. int xinc,yinc;
  467.  
  468. /* command window */
  469. WindowRecord cwrecord;
  470. WindowPtr cwindow;
  471.  
  472. /* graphics window */
  473. WindowRecord gwrecord;
  474. WindowPtr gwindow;
  475.  
  476. /* window mode */
  477. int splitmode;
  478.  
  479. /* cursor variables */
  480. long cursortime;
  481. int cursorstate;
  482. int x,y;
  483.  
  484. /* screen buffer */
  485. char screen[SCRH*SCRW],*topline,*curline;
  486. int scrh,scrw;
  487.  
  488. /* type ahead buffer */
  489. char charbuf[CHARMAX],*inptr,*outptr;
  490. int charcnt;
  491.  
  492. macinit()
  493. {
  494.     /* initialize the toolbox */
  495.     InitGraf(&thePort);
  496.     InitFonts();
  497.     InitWindows();
  498.     InitMenus();
  499.     TEInit();
  500.     InitDialogs(0L);
  501.     InitCursor();
  502.  
  503.     /* setup the menu bar */
  504.     SetupMenus();
  505.  
  506.     /* get the size of the screen */
  507.     screenWidth  = screenBits.bounds.right  - screenBits.bounds.left;
  508.     screenHeight = screenBits.bounds.bottom - screenBits.bounds.top;
  509.  
  510.     /* Create the graphics and control windows */
  511.     gwindow = GetNewWindow(129,&gwrecord,-1L);
  512.     cwindow = GetNewWindow(128,&cwrecord,-1L);
  513.  
  514.     /* establish the command window as the current port */
  515.     SetPort(cwindow);
  516.  
  517.     /* compute the size of the normal command window */
  518.     nHorizontal = ScreenMargin;
  519.     nVertical = MenuBarHeight + TitleBarHeight + ScreenMargin - 2;
  520.     nWidth = screenWidth - (ScreenMargin * 2) - 1;
  521.     nHeight = screenHeight - MenuBarHeight - TitleBarHeight - (ScreenMargin * 2);
  522.  
  523.     /* compute the size of the split command window */
  524.     sHorizontal = nHorizontal;
  525.     sVertical = nVertical + GHeight + 1;
  526.     sWidth = nWidth;
  527.     sHeight = nHeight - GHeight - 1;
  528.  
  529.     /* compute the size of the graphics window */
  530.     gHorizontal = nHorizontal;
  531.     gVertical = MenuBarHeight + ScreenMargin;
  532.     gWidth = screenWidth - (ScreenMargin * 2);
  533.     gHeight = GHeight;
  534.  
  535.     /* move and size the graphics window */
  536.     MoveWindow(gwindow,gHorizontal,gVertical,0);
  537.     SizeWindow(gwindow,gWidth,gHeight,0);
  538.  
  539.     /* setup the font, size and writing mode for the command window */
  540.     TextFont(monaco); TextSize(9); TextMode(srcCopy);
  541.  
  542.     /* setup command mode */
  543.     scrsplit(FALSE);
  544.  
  545.     /* disable the Cursor */
  546.     cursorstate = -1;
  547.  
  548.     /* setup the input ring buffer */
  549.     inptr = outptr = charbuf;
  550.     charcnt = 0;
  551.     
  552.     /* lock the font in memory */
  553.     SetFontLock(-1);
  554. }
  555.  
  556. SetupMenus()
  557. {
  558.     appleMenu = GetMenu(appleID);    /* setup the apple menu */
  559.     AddResMenu(appleMenu,'DRVR');
  560.     InsertMenu(appleMenu,0);
  561.     fileMenu = GetMenu(fileID);        /* setup the file menu */
  562.     InsertMenu(fileMenu,0);
  563.     editMenu = GetMenu(editID);        /* setup the edit menu */
  564.     InsertMenu(editMenu,0);
  565.     controlMenu = GetMenu(controlID);    /* setup the control menu */
  566.     InsertMenu(controlMenu,0);
  567.     DrawMenuBar();
  568. }
  569.  
  570. int scrgetc()
  571. {
  572.     CursorOn();
  573.     while (charcnt == 0)
  574.     DoEvent();
  575.     CursorOff();
  576.     return (scrnextc());
  577. }
  578.  
  579. int scrnextc()
  580. {
  581.     int ch;
  582.     if (charcnt > 0) {
  583.     ch = *outptr++; charcnt--;
  584.     if (outptr >= &charbuf[CHARMAX])
  585.         outptr = charbuf;
  586.     }
  587.     else {
  588.     charcnt = 0;
  589.     ch = -1;
  590.     }
  591.     return (ch);
  592. }
  593.  
  594. scrputc(ch)
  595.   int ch;
  596. {
  597.     switch (ch) {
  598.     case '\r':
  599.     x = 0;
  600.     break;
  601.     case '\n':
  602.     nextline(&curline);
  603.     if (++y >= scrh) {
  604.         y = scrh - 1;
  605.         scrollup();
  606.     }
  607.     break;
  608.     case '\t':
  609.     do { scrputc(' '); } while (x & 7);
  610.     break;
  611.     case '\010':
  612.     if (x) x--;
  613.     break;
  614.     default:
  615.     if (ch >= 0x20 && ch < 0x7F) {
  616.         scrposition(x,y);
  617.         DrawChar(ch);
  618.         curline[x] = ch;
  619.         if (++x >= scrw) {
  620.         nextline(&curline);
  621.         if (++y >= scrh) {
  622.             y = scrh - 1;
  623.             scrollup();
  624.         }
  625.         x = 0;
  626.         }
  627.     }
  628.     break;
  629.     }
  630. }
  631.  
  632. scrdelete()
  633. {
  634.     scrputc('\010');
  635.     scrputc(' ');
  636.     scrputc('\010');
  637. }
  638.  
  639. scrclear()
  640. {
  641.     curline = screen;
  642.     for (y = 0; y < SCRH; y++)
  643.     for (x = 0; x < SCRW; x++)
  644.         *curline++ = ' ';
  645.     topline = curline = screen;
  646.     x = y = 0;
  647. }
  648.  
  649. scrflush()
  650. {
  651.     inptr = outptr = charbuf;
  652.     charcnt = -1;
  653.     osflush();
  654. }
  655.  
  656. scrposition(x,y)
  657.   int x,y;
  658. {
  659.     MoveTo((x * xinc) + lmargin,(y * yinc) + tmargin);
  660. }
  661.  
  662. DoEvent()
  663. {
  664.     EventRecord myEvent;
  665.     
  666.     SystemTask();
  667.     CursorUpdate();
  668.  
  669.     while (GetNextEvent(everyEvent,&myEvent))
  670.     switch (myEvent.what) {
  671.         case mouseDown:
  672.         DoMouseDown(&myEvent);
  673.         break;
  674.         case keyDown:
  675.         case autoKey:
  676.         DoKeyPress(&myEvent);
  677.         break;
  678.         case activateEvt:
  679.         DoActivate(&myEvent);
  680.         break;
  681.         case updateEvt:
  682.         DoUpdate(&myEvent);
  683.         break;
  684.         }
  685. }
  686.  
  687. DoMouseDown(myEvent)
  688.   EventRecord *myEvent;
  689. {
  690.     WindowPtr whichWindow;
  691.  
  692.     switch (FindWindow(myEvent->where,&whichWindow)) {
  693.     case inMenuBar:
  694.     DoMenuClick(myEvent);
  695.     break;
  696.     case inSysWindow:
  697.     SystemClick(myEvent,whichWindow);
  698.     break;
  699.     case inDrag:
  700.     DoDrag(myEvent,whichWindow);
  701.     break;
  702.     case inGoAway:
  703.     DoGoAway(myEvent,whichWindow);
  704.     break;
  705.     case inGrow:
  706.     DoGrow(myEvent,whichWindow);
  707.     break;
  708.     case inContent:
  709.     DoContent(myEvent,whichWindow);
  710.     break;
  711.     }
  712. }
  713.  
  714. DoMenuClick(myEvent)
  715.   EventRecord *myEvent;
  716. {
  717.     long choice;
  718.     if (choice = MenuSelect(myEvent->where))
  719.     DoCommand(choice);
  720. }
  721.  
  722. DoDrag(myEvent,whichWindow)
  723.   EventRecord *myEvent;
  724.   WindowPtr whichWindow;
  725. {
  726.     Rect dragRect;
  727.     SetRect(&dragRect,0,MenuBarHeight,screenWidth,screenHeight);
  728.     InsetRect(&dragRect,ScreenMargin,ScreenMargin);
  729.     DragWindow(whichWindow,myEvent->where,&dragRect);
  730. }
  731.  
  732. DoGoAway(myEvent,whichWindow)
  733.   EventRecord *myEvent;
  734.   WindowPtr whichWindow;
  735. {
  736.     if (TrackGoAway(whichWindow,myEvent->where))
  737.     wrapup();
  738. }
  739.  
  740. DoGrow(myEvent,whichWindow)
  741.   EventRecord *myEvent;
  742.   WindowPtr whichWindow;
  743. {
  744.     Rect sizeRect;
  745.     long newSize;
  746.     if (whichWindow != FrontWindow() && whichWindow != gwindow)
  747.     SelectWindow(whichWindow);
  748.     else {
  749.     SetRect(&sizeRect,MinWidth,MinHeight,screenWidth,screenHeight-MenuBarHeight);
  750.     newSize = GrowWindow(whichWindow,myEvent->where,&sizeRect);
  751.     if (newSize) {
  752.         EraseRect(&whichWindow->portRect);
  753.         SizeWindow(whichWindow,LoWord(newSize),HiWord(newSize),-1);
  754.         InvalRect(&whichWindow->portRect);
  755.         SetupScreen();
  756.         scrflush();
  757.     }
  758.     }
  759. }
  760.  
  761. DoContent(myEvent,whichWindow)
  762.   EventRecord *myEvent;
  763.   WindowPtr whichWindow;
  764. {
  765.     if (whichWindow != FrontWindow() && whichWindow != gwindow)
  766.     SelectWindow(whichWindow);
  767. }
  768.  
  769. DoKeyPress(myEvent)
  770.   EventRecord *myEvent;
  771. {
  772.     long choice;
  773.     
  774.     if (FrontWindow() == cwindow) {
  775.     if (myEvent->modifiers & 0x100) {
  776.         if (choice = MenuKey((char)myEvent->message))
  777.         DoCommand(choice);
  778.     }
  779.     else {
  780.         if (charcnt < CHARMAX) {
  781.         *inptr++ = myEvent->message & 0xFF; charcnt++;
  782.         if (inptr >= &charbuf[CHARMAX])
  783.             inptr = charbuf;
  784.         }
  785.     }
  786.     }
  787. }
  788.  
  789. DoActivate(myEvent)
  790.   EventRecord *myEvent;
  791. {
  792.     WindowPtr whichWindow;
  793.     whichWindow = (WindowPtr)myEvent->message;
  794.     SetPort(whichWindow);
  795.     if (whichWindow == cwindow)
  796.     DrawGrowIcon(whichWindow);
  797. }
  798.  
  799. DoUpdate(myEvent)
  800.   EventRecord *myEvent;
  801. {
  802.     WindowPtr whichWindow;
  803.     GrafPtr savePort;
  804.     GetPort(&savePort);
  805.     whichWindow = (WindowPtr)myEvent->message;
  806.     SetPort(whichWindow);
  807.     BeginUpdate(whichWindow);
  808.     EraseRect(&whichWindow->portRect);
  809.     if (whichWindow == cwindow) {
  810.     DrawGrowIcon(whichWindow);
  811.     RedrawScreen();
  812.     }
  813.     EndUpdate(whichWindow);
  814.     SetPort(savePort);
  815. }
  816.  
  817. DoCommand(choice)
  818.   long choice;
  819. {
  820.     int theMenu,theItem;
  821.     
  822.     /* decode the menu choice */
  823.     theMenu = HiWord(choice);
  824.     theItem = LoWord(choice);
  825.     
  826.     CursorOff();
  827.     HiliteMenu(theMenu);
  828.     switch (theMenu) {
  829.     case appleID:
  830.     DoAppleMenu(theItem);
  831.     break;
  832.     case fileID:
  833.     DoFileMenu(theItem);
  834.     break;
  835.     case editID:
  836.     DoEditMenu(theItem);
  837.     break;
  838.     case controlID:
  839.     DoControlMenu(theItem);
  840.     break;
  841.     }
  842.     HiliteMenu(0);
  843.     CursorOn();
  844. }
  845.  
  846. pascal aboutfilter(theDialog,theEvent,itemHit)
  847.   DialogPtr theDialog; EventRecord *theEvent; int *itemHit;
  848. {
  849.     return (theEvent->what == mouseDown ? -1 : 0);
  850. }
  851.  
  852. DoAppleMenu(theItem)
  853.   int theItem;
  854. {
  855.     DialogRecord mydialog;
  856.     char name[256];
  857.     GrafPtr gp;
  858.     int n;
  859.  
  860.     switch (theItem) {
  861.     case 1:
  862.     GetNewDialog(129,&mydialog,-1L);
  863.     ModalDialog(aboutfilter,&n);
  864.     CloseDialog(&mydialog);
  865.     break;
  866.     default:
  867.     GetItem(appleMenu,theItem,name);
  868.     GetPort(&gp);
  869.     OpenDeskAcc(name);
  870.     SetPort(gp);
  871.     break;
  872.     }
  873. }
  874.  
  875. pascal int filefilter(pblock)
  876.   ParmBlkPtr pblock;
  877. {
  878.     unsigned char *p; int len;
  879.     p = pblock->fileParam.ioNamePtr; len = *p++ &0xFF;
  880.     return (len >= 4 && strncmp(p+len-4,".lsp",4) == 0 ? 0 : -1);
  881. }
  882.  
  883. DoFileMenu(theItem)
  884.   int theItem;
  885. {
  886.     SFReply loadfile;
  887.     Point p;
  888.  
  889.     switch (theItem) {
  890.     case 1:    /* load */
  891.     case 2:    /* load noisily */
  892.     p.h = 100; p.v = 100;
  893.     SFGetFile(p,"\P",filefilter,-1,filetypes,0L,&loadfile);
  894.     if (loadfile.good) {
  895.         HiliteMenu(0);
  896.         SetVol(0L,loadfile.vRefNum);
  897.         if (xlload(PtoCstr(loadfile.fName),1,(theItem == 1 ? 0 : 1)))
  898.         scrflush();
  899.         else
  900.         xlabort("load error");
  901.     }
  902.     break;
  903.     case 4:    /* quit */
  904.     wrapup();
  905.     }
  906. }
  907.  
  908. DoEditMenu(theItem)
  909.   int theItem;
  910. {
  911.     switch (theItem) {
  912.     case 1:    /* undo */
  913.     case 3:    /* cut */
  914.     case 4:    /* copy */
  915.     case 5:    /* paste */
  916.     case 6:    /* clear */
  917.     SystemEdit(theItem-1);
  918.     break;
  919.     }
  920. }
  921.  
  922. DoControlMenu(theItem)
  923.   int theItem;
  924. {
  925.     scrflush();
  926.     HiliteMenu(0);
  927.     switch (theItem) {
  928.     case 1:    /* break */
  929.     xlbreak("user break",s_unbound);
  930.     break;
  931.     case 2:    /* continue */
  932.     xlcontinue();
  933.     break;
  934.     case 3:    /* clean-up error */
  935.     xlcleanup();
  936.     break;
  937.     case 4:    /* Cancel input */
  938.     xlabort("input canceled");
  939.     break;
  940.     case 5:    /* Top Level */
  941.     xltoplevel();
  942.     break;
  943.     case 7:    /* split screen */
  944.     scrsplit(splitmode ? FALSE : TRUE);
  945.     break;
  946.     }
  947. }
  948.  
  949. scrsplit(split)
  950.   int split;
  951. {
  952.     ShowHide(cwindow,0);
  953.     if (split) {
  954.     CheckItem(controlMenu,7,-1);
  955.     ShowHide(gwindow,-1);
  956.     MoveWindow(cwindow,sHorizontal,sVertical,-1);
  957.     SizeWindow(cwindow,sWidth,sHeight,-1);
  958.     InvalRect(&cwindow->portRect);
  959.     SetupScreen();
  960.     }
  961.     else {
  962.     CheckItem(controlMenu,7,0);
  963.     ShowHide(gwindow,0);
  964.     MoveWindow(cwindow,nHorizontal,nVertical,-1);
  965.     SizeWindow(cwindow,nWidth,nHeight,-1);
  966.     InvalRect(&cwindow->portRect);
  967.     SetupScreen();
  968.     }
  969.     ShowHide(cwindow,-1);
  970.     splitmode = split;
  971. }
  972.  
  973. SetupScreen()
  974. {
  975.     FontInfo info;
  976.     Rect *pRect;
  977.  
  978.     /* get font information */
  979.     GetFontInfo(&info);
  980.  
  981.     /* compute the top and bottom margins */
  982.     tmargin = TextMargin + info.ascent;
  983.     lmargin = TextMargin;
  984.  
  985.     /* compute the x and y increments */
  986.     xinc = info.widMax;
  987.     yinc = info.ascent + info.descent + info.leading;
  988.  
  989.     /* compute the character dimensions of the screen */
  990.     pRect = &cwindow->portRect;
  991.     scrh = (pRect->bottom - (2 * TextMargin) - (SBarWidth - 1)) / yinc;
  992.     if (scrh > SCRH) scrh = SCRH;
  993.     scrw = (pRect->right - (2 * TextMargin) - (SBarWidth - 1)) / xinc;
  994.     if (scrw > SCRW) scrw = SCRW;
  995.     
  996.     /* clear the screen */
  997.     scrclear();
  998. }
  999.  
  1000. CursorUpdate()
  1001. {
  1002.     if (cursorstate != -1)
  1003.     if (cursortime < TickCount()) {
  1004.         scrposition(x,y);
  1005.         if (cursorstate) {
  1006.         DrawChar(' ');
  1007.         cursortime = TickCount() + TIMEOFF;
  1008.         cursorstate = 0;
  1009.         }
  1010.         else {
  1011.         DrawChar('_');
  1012.         cursortime = TickCount() + TIMEON;
  1013.         cursorstate = 1;
  1014.         }
  1015.     }
  1016. }
  1017.  
  1018. CursorOn()
  1019. {
  1020.     cursortime = TickCount();
  1021.     cursorstate = 0;
  1022. }
  1023.  
  1024. CursorOff()
  1025. {
  1026.     if (cursorstate == 1) {
  1027.     scrposition(x,y);
  1028.     DrawChar(' ');
  1029.     }
  1030.     cursorstate = -1;
  1031. }
  1032.  
  1033. RedrawScreen()
  1034. {
  1035.     char *Line; int y;
  1036.     Line = topline;
  1037.     for (y = 0; y < scrh; y++) {
  1038.     scrposition(0,y);
  1039.     DrawText(Line,0,scrw);
  1040.     nextline(&Line);
  1041.     }
  1042. }
  1043.  
  1044. nextline(pline)
  1045.   char **pline;
  1046. {
  1047.     if ((*pline += SCRW) >= &screen[SCRH*SCRW])
  1048.     *pline = screen;
  1049. }
  1050.  
  1051. scrollup()
  1052. {
  1053.     RgnHandle updateRgn;
  1054.     Rect rect;
  1055.     int x;
  1056.     updateRgn = NewRgn();
  1057.     rect = cwindow->portRect;
  1058.     rect.bottom -= SBarWidth - 1;
  1059.     rect.right -= SBarWidth - 1;
  1060.     ScrollRect(&rect,0,-yinc,updateRgn);
  1061.     DisposeRgn(updateRgn);
  1062.     for (x = 0; x < SCRW; x++)
  1063.     topline[x] = ' ';
  1064.     nextline(&topline);
  1065. }
  1066.  
  1067. ======================== macstuff.c ==========================================
  1068.  
  1069. /* macstuff.c - macintosh interface routines for xlisp */
  1070.  
  1071. #include <stdio.h>
  1072.  
  1073. /* program limits */
  1074. #define LINEMAX     200    /* maximum line length */
  1075.  
  1076. /* externals */
  1077. extern FILE *tfp;
  1078. extern int x;
  1079.  
  1080. /* local variables */
  1081. static char linebuf[LINEMAX+1],*lineptr;
  1082. static int linepos[LINEMAX],linelen;
  1083. static long rseed = 1L;
  1084.  
  1085. osinit(name)
  1086.   char *name;
  1087. {
  1088.     /* initialize the mac interface routines */
  1089.     macinit();
  1090.  
  1091.     /* initialize the line editor */
  1092.     linelen = 0;
  1093. }
  1094.  
  1095. osfinish()
  1096. {
  1097. }
  1098.  
  1099. oserror(msg)
  1100. {
  1101.     char line[100],*p;
  1102.     sprintf(line,"error: %s\n",msg);
  1103.     for (p = line; *p != '\0'; ++p)
  1104.     ostputc(*p);
  1105. }
  1106.  
  1107. int osrand(n)
  1108.   int n;
  1109. {
  1110.     long k1;
  1111.     
  1112.     /* make sure we don't get stuck at zero */
  1113.     if (rseed == 0L) rseed = 1L;
  1114.     
  1115.     /* algorithm taken from Dr. Dobbs Journal, November 1985, Page 91 */
  1116.     k1 = rseed / 127773L;
  1117.     if ((rseed = 16807L * (rseed - k1 * 127773L) - k1 * 2836L) < 0L)
  1118.     rseed += 2147483647L;
  1119.     
  1120.     /* return a random number between 0 and n-1 */
  1121.     return ((int)(rseed % (long)n));
  1122. }
  1123.  
  1124. FILE *osaopen(name,mode)
  1125.   char *name,*mode;
  1126. {
  1127.     return (fopen(name,mode));
  1128. }
  1129.  
  1130. FILE *osbopen(name,mode)
  1131.   char *name,*mode;
  1132. {
  1133.     char nmode[4];
  1134.     strcpy(nmode,mode); strcat(nmode,"b");
  1135.     return (fopen(name,nmode));
  1136. }
  1137.  
  1138. int osclose(fp)
  1139.   FILE *fp;
  1140. {
  1141.     return (fclose(fp));
  1142. }
  1143.  
  1144. int osagetc(fp)
  1145.   FILE *fp;
  1146. {
  1147.     return (getc(fp));
  1148. }
  1149.  
  1150. int osbgetc(fp)
  1151.   FILE *fp;
  1152. {
  1153.     return (getc(fp));
  1154. }
  1155.  
  1156. int osaputc(ch,fp)
  1157.   int ch; FILE *fp;
  1158. {
  1159.     return (putc(ch,fp));
  1160. }
  1161.  
  1162. int osbputc(ch,fp)
  1163.   int ch; FILE *fp;
  1164. {
  1165.     return (putc(ch,fp));
  1166. }
  1167.  
  1168. int ostgetc()
  1169. {
  1170.     int ch,i;
  1171.  
  1172.     if (linelen--) return (*lineptr++);
  1173.     linelen = 0;
  1174.     while ((ch = scrgetc()) != '\r')
  1175.     switch (ch) {
  1176.     case EOF:
  1177.         return (ostgetc());
  1178.     case '\010':
  1179.         if (linelen > 0) {
  1180.         linelen--;
  1181.         while (x > linepos[linelen])
  1182.             scrdelete();
  1183.         }
  1184.         break;
  1185.     default:
  1186.         if (linelen < LINEMAX) {
  1187.             linebuf[linelen] = ch;
  1188.         linepos[linelen] = x;
  1189.         linelen++;
  1190.         }
  1191.         scrputc(ch);
  1192.         break;
  1193.     }
  1194.     linebuf[linelen++] = '\n';
  1195.     scrputc('\r'); scrputc('\n');
  1196.     if (tfp)
  1197.     for (i = 0; i < linelen; ++i)
  1198.         osaputc(linebuf[i],tfp);
  1199.     lineptr = linebuf; linelen--;
  1200.     return (*lineptr++);
  1201. }
  1202.  
  1203. int ostputc(ch)
  1204.   int ch;
  1205. {
  1206.     if (ch == '\n')
  1207.     scrputc('\r');
  1208.     scrputc(ch);
  1209.     if (tfp)
  1210.     osaputc(ch,tfp);
  1211.     return (1);
  1212. }
  1213.  
  1214. osflush()
  1215. {
  1216.     lineptr = linebuf;
  1217.     linelen = 0;
  1218. }
  1219.  
  1220. oscheck()
  1221. {
  1222.     DoEvent();
  1223. }
  1224.  
  1225.  
  1226. =========================== osdefs.h =====================================
  1227.  
  1228. extern LVAL xptsize(),
  1229.         xhidepen(),xshowpen(),xgetpen(),xpensize(),xpenmode(),
  1230.             xpenpat(),xpennormal(),xmoveto(),xmove(),xlineto(),xline(),
  1231.         xshowgraphics(),xhidegraphics(),xcleargraphics(),
  1232.         xtool(),xtool16(),xtool32(),xnewhandle(),xnewptr(),
  1233.         xhiword(),xloword(),xrdnohang();
  1234.  
  1235. =========================== osptrs.h =====================================
  1236.  
  1237. {    "HIDEPEN",            S, xhidepen        }, /* 300 */
  1238. {    "SHOWPEN",            S, xshowpen        }, /* 301 */
  1239. {    "GETPEN",            S, xgetpen        }, /* 302 */
  1240. {    "PENSIZE",            S, xpensize        }, /* 303 */
  1241. {    "PENMODE",            S, xpenmode        }, /* 304 */
  1242. {    "PENPAT",            S, xpenpat        }, /* 305 */
  1243. {    "PENNORMAL",            S, xpennormal        }, /* 306 */
  1244. {    "MOVETO",            S, xmoveto        }, /* 307 */
  1245. {    "MOVE",                S, xmove        }, /* 308 */
  1246. {    "LINETO",            S, xlineto        }, /* 309 */
  1247. {    "LINE",                S, xline        }, /* 310 */
  1248. {    "SHOW-GRAPHICS",        S, xshowgraphics    }, /* 311 */
  1249. {    "HIDE-GRAPHICS",        S, xhidegraphics    }, /* 312 */
  1250. {    "CLEAR-GRAPHICS",        S, xcleargraphics    }, /* 313 */
  1251. {    "TOOLBOX",            S, xtool        }, /* 314 */
  1252. {    "TOOLBOX-16",            S, xtool16        }, /* 315 */
  1253. {    "TOOLBOX-32",            S, xtool32        }, /* 316 */
  1254. {    "NEWHANDLE",            S, xnewhandle        }, /* 317 */
  1255. {    "NEWPTR",            S, xnewptr        }, /* 318 */
  1256. {    "HIWORD",            S, xhiword        }, /* 319 */
  1257. {    "LOWORD",            S, xloword        }, /* 320 */
  1258. {    "READ-CHAR-NO-HANG",        S, xrdnohang        }, /* 321 */
  1259. {    "COMMAND-POINT-SIZE",        S, xptsize        }, /* 322 */
  1260.  
  1261.  
  1262. ======================== Xlisp.Rsrc ==========================================
  1263.  
  1264. XLisp.Rsrc
  1265.  
  1266. TYPE WIND
  1267.   ,128
  1268. XLISP version 2.0
  1269. 41 4 339 508
  1270. InVisible GoAway
  1271. 0
  1272. 0
  1273.  
  1274. TYPE WIND
  1275.   ,129
  1276. Graphics Window
  1277. 22 4 254 508
  1278. InVisible NoGoAway
  1279. 2
  1280. 0
  1281.  
  1282. TYPE DLOG
  1283.   ,129
  1284. About XLISP
  1285. 50 100 290 395
  1286. Visible NoGoAway
  1287. 3
  1288. 0
  1289. 129
  1290.  
  1291. TYPE DITL
  1292.   ,129
  1293. 9
  1294.  
  1295. staticText
  1296. 20 20 40 275
  1297. XLISP v2.0, February 6, 1988
  1298.  
  1299. staticText
  1300. 40 20 60 275
  1301. Copyright (c) 1988, by David Betz
  1302.  
  1303. staticText
  1304. 60 20 80 275
  1305. All Rights Reserved
  1306.  
  1307. staticText
  1308. 90 20 110 275
  1309. Author contact information:
  1310.  
  1311. staticText
  1312. 110 40 130 275
  1313. David Betz
  1314.  
  1315. staticText
  1316. 130 40 150 275
  1317. 127 Taylor Road
  1318.  
  1319. staticText
  1320. 150 40 170 275
  1321. Peterborough, NH  03458
  1322.  
  1323. staticText
  1324. 170 40 190 275
  1325. (603) 924-6936
  1326.  
  1327. staticText
  1328. 200 20 220 275
  1329. Portions Copyright Think Technologies
  1330.  
  1331. TYPE MENU
  1332.   ,1
  1333. \14
  1334. About XLISP
  1335. (-
  1336.  
  1337. TYPE MENU
  1338.   ,256
  1339. File
  1340. Load.../L
  1341. Load Noisily.../N
  1342. (-
  1343. Quit/Q
  1344.  
  1345. TYPE MENU
  1346.   ,257
  1347. Edit
  1348. Undo/Z
  1349. (-
  1350. Cut/X
  1351. Copy/C
  1352. Paste/V
  1353. Clear
  1354.  
  1355. TYPE MENU
  1356.   ,258
  1357. Control
  1358. Break/B
  1359. Continue/P
  1360. Clean Up Error/G
  1361. Cancel Input/U
  1362. Top Level/T
  1363. (-
  1364. Split Screen/S
  1365.  
  1366.  
  1367. ======================== Alles ist gemacht  ==================================
  1368.  
  1369.  
  1370. -- 
  1371. Eric F. Johnson, Boulware Technologies, Inc. 
  1372. 415 W. Travelers Trail, Burnsville, MN 55337 USA.  Phone: +1 612-894-0313. 
  1373. erc@pai.mn.org    - or -   bungia!pai!erc
  1374. (We have a very dumb mailer, so please send a bang-!-style return address.)
  1375.  
  1376.  
  1377.