1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845
|
/* $Id: mac.c,v 1.3 2000/12/18 21:01:50 airwin Exp $
$Log: mac.c,v $
Revision 1.3 2000/12/18 21:01:50 airwin
Change to new style plplot/*.h header file locations.
Revision 1.2 2000/05/12 18:05:32 furnish
Imported latest Mac port work by Rob Managan.
* Revision 1.1 1995/04/11 09:39:13 mjl
* Mac port, contributed by Mark Franz.
*
*
*/
/*
Rect PlotRect = {40, 10, 540, 510};
MaxApplZone();
for (i = 0; i < 12; i++)
MoreMasters();
mac_plot_area(&PlotRect);
*/
/* mac.c
Adapted from bgivga.c
MArk Franz
24-Mar-95
A driver for Macintosh
Compile this with MetroWerks C/C++
*/
#include "plplot/plplotP.h"
#include <stdio.h>
#include <stdlib.h>
#include "plplot/drivers.h"
#include "plplot/mac.h"
#define MAC_XMAX 400
#define MAC_YMAX 400
#define MAC_XOFFSET 20
#define NIL NULL
#define Max_Mac_Windows 8
// Plot menu
#define plotM 1000
#define PlotCopy 1
#define PlotSave 2
#define PlotContinue 4
Str255 MAC_WINDOW_TITLE = "\pPlot ";
Str255 tempWTitle;
RgnHandle fillRegion;
static int Max_Mac_Windows_Used;
static WindowPtr plotWindow[Max_Mac_Windows];
static PicHandle plotPicture[Max_Mac_Windows];
static Handle saveMBar, myMBar;
static MenuHandle myMenu;
RGBColor rgbColor;
long PICTCount;
short globalRef;
short plotActive = 0;
PicHandle newPICTHand;
short plotWidth = MAC_XMAX;
short plotHeight = MAC_YMAX;
static GrafPtr savedPort;
static Rect boundsRect = {40, 10, MAC_YMAX+40, MAC_XMAX+10};
/*----------------------------------------------------------------------*\
* mac_init()
*
* Initialize device.
\*----------------------------------------------------------------------*/
void
plD_init_mac1(PLStream *pls)
{
Max_Mac_Windows_Used = 1;
init_mac(pls);
}
void
plD_init_mac8(PLStream *pls)
{
Max_Mac_Windows_Used = 8;
init_mac(pls);
}
void
init_mac(PLStream *pls)
{
int i;
for(i = 0; i < Max_Mac_Windows_Used; i++)
{
plotWindow[i] = NULL;
plotPicture[i] = NULL;
}
plotActive = -1;
fprintf(stderr, "Macintosh Window\n"); // This is here just to
// make sure Menus drawn
SetUpMenu();
pls->termin = 1; /* is an interactive terminal */
pls->icol0 = 1;
pls->icol1 = 1;
pls->width = 1;
pls->bytecnt = 0;
pls->page = 0;
pls->dev_fill0 = 1; /* supports hardware solid fills */
pls->dev_fill1 = 0;
// pls->plbuf_write = 1; /* Activate plot buffer */
pls->graphx = GRAPHICS_MODE;
if (!pls->colorset)
pls->color = 1;
/* Set up device parameters */
plP_setpxl(2.83465, 2.83465); /* Pixels/mm. */
plP_setphy((PLINT) 0, (PLINT) (boundsRect.right-boundsRect.left),
(PLINT) 0, (PLINT) (boundsRect.bottom-boundsRect.top));
}
/*----------------------------------------------------------------------*\
* mac_line()
*
* Draw a line in the current color from (x1,y1) to (x2,y2).
\*----------------------------------------------------------------------*/
void
plD_line_mac(PLStream *pls, short x1a, short y1a, short x2a, short y2a)
{
int y1, y2 ;
GetPort(&savedPort);
SetPort(plotWindow[plotActive]);
y1 = (boundsRect.bottom-boundsRect.top) - y1a;
y2 = (boundsRect.bottom-boundsRect.top) - y2a;
MoveTo(x1a, y1);
LineTo(x2a, y2);
SetPort(savedPort);
}
/*----------------------------------------------------------------------*\
* mac_polyline()
*
* Draw a polyline in the current color.
\*----------------------------------------------------------------------*/
void
plD_polyline_mac(PLStream *pls, short *xa, short *ya, PLINT npts)
{
PLINT i;
GetPort(&savedPort);
SetPort(plotWindow[plotActive]);
for (i = 0; i < npts - 1; i++)
plD_line_mac(pls, xa[i], ya[i], xa[i + 1], ya[i + 1]);
SetPort(savedPort);
}
/*----------------------------------------------------------------------*\
* mac_eop()
*
* End of page.
\*----------------------------------------------------------------------*/
void
plD_eop_mac(PLStream *pls)
{
Rect myRect;
GetPort(&savedPort);
SetPort(plotWindow[plotActive]);
ClosePicture();
DrawPicture(plotPicture[plotActive],&plotWindow[plotActive]->portRect);
if(pls->termin == 1)
{
if(plotWindow[plotActive] !=NULL) // added subscript for current window RAM 10/14/96
{
GetWTitle(plotWindow[plotActive], tempWTitle);
SetWTitle(plotWindow[plotActive], "\pHit any key to continue.");
InvalRect(&plotWindow[plotActive]->portRect);
AdjustMenu();
if (Max_Mac_Windows_Used != 1)
{
while(!MAC_event(pls));
SetWTitle(plotWindow[plotActive], tempWTitle);
}
// RestoreMenu();
}
}
else
{
if(plotPicture[plotActive] != NULL)
{
AdjustMenu();
myRect=plotWindow[plotActive]->portRect;
DrawPicture(plotPicture[plotActive],&myRect);
// RestoreMenu();
}
}
SetPort(savedPort);
}
/*----------------------------------------------------------------------*\
* mac_bop()
*
* Set up for the next page.
\*----------------------------------------------------------------------*/
void
plD_bop_mac(PLStream *pls)
{
RGBColor backGround;
Str255 numberAsString;
Str255 currentTitle;
pls->page++;
plotActive++;
if(plotActive == Max_Mac_Windows_Used)
plotActive =0;
if (plotWindow[plotActive] == NULL) // Get a window handle
{
boundsRect.top = 40+plotActive*20; // Set the inital window location
boundsRect.left = (plotActive+1)*10;
boundsRect.right = plotWidth+(plotActive+1)*10;
boundsRect.bottom = plotHeight+40+plotActive*20;
plotWindow[plotActive] = NewCWindow(NULL, &boundsRect,"\p ", FALSE,
documentProc, (void *)-1L, FALSE, 0L);
}
currentTitle[0]=0;
NumToString(pls->page, numberAsString);
CopyPStrings(currentTitle, MAC_WINDOW_TITLE);
CatenatePStrings(currentTitle, numberAsString);
SetWTitle(plotWindow[plotActive], currentTitle);
boundsRect = plotWindow[plotActive]->portRect; // Get current window location
GetPort(&savedPort);
SetPort(plotWindow[plotActive]);
SetWRefCon(plotWindow[plotActive], (long)( plotActive ) ); // Save the window number
EraseRect(&plotWindow[plotActive]->portRect);
ShowWindow(plotWindow[plotActive]);
SelectWindow(plotWindow[plotActive]); // RAM 10/9/96
if(plotPicture[plotActive] != NULL) // Make sure the associated Picture is free
{
SetWindowPic(plotWindow[plotActive], NULL);
KillPicture(plotPicture[plotActive]);
plotPicture[plotActive]=NULL;
}
plotPicture[plotActive]=OpenPicture(&(((GrafPtr) plotWindow[plotActive])->portRect));
TextFont(kFontIDMonaco);
TextSize(9);
TextFace(normal);
PenNormal();
// Paint the Background - use plscolbg(r,g,b) function
backGround.red = 257*plsc->cmap0[0].r;
backGround.green = 257*plsc->cmap0[0].g;
backGround.blue = 257*plsc->cmap0[0].b;
RGBForeColor( &backGround );
PaintRect(&plotWindow[plotActive]->portRect);
// Make sure the colors are set correctly for the beginning of the plot
rgbColor.red = 257*plsc->curcolor.r;
rgbColor.green = 257*plsc->curcolor.g;
rgbColor.blue = 257*plsc->curcolor.b;
RGBForeColor( &rgbColor );
SetPort(savedPort);
}
/*----------------------------------------------------------------------*\
* mac_tidy()
*
* Close graphics file or otherwise clean up.
\*----------------------------------------------------------------------*/
void
plD_tidy_mac(PLStream *pls)
{
short i;
GetPort(&savedPort);
SetPort(plotWindow[plotActive]);
// AdjustMenu();
// while(!MAC_event(pls)); // Wait for one last time
// RestoreMenu();
for(i = 0; i < Max_Mac_Windows_Used; i++)
{
if(plotWindow[i] != NULL )
DisposeWindow(plotWindow[i]);
}
SetPort(savedPort);
}
/*----------------------------------------------------------------------*\
* plD_state_mac()
*
* Handle change in PLStream state (color, pen width, fill attribute, etc).
\*----------------------------------------------------------------------*/
void
plD_state_mac(PLStream *pls, PLINT op)
{
GetPort(&savedPort);
SetPort(plotWindow[plotActive]);
switch (op) {
case PLSTATE_WIDTH:
if (pls->width < 1 || pls->width > 10)
pls->width=9;
PenSize((short) pls->width, (short) pls->width);
break;
case PLSTATE_CMAP0:
case PLSTATE_CMAP1:
; // Not sure what to do here since colors are used differently
break;
case PLSTATE_COLOR1:
case PLSTATE_COLOR0:
rgbColor.red = 257*plsc->curcolor.r;
rgbColor.green = 257*plsc->curcolor.g;
rgbColor.blue = 257*plsc->curcolor.b;
RGBForeColor( &rgbColor );
break;
case PLSTATE_FILL:
; // TBD: Need to set fill at some point in future
break;
}
SetPort(savedPort);
}
/*----------------------------------------------------------------------*\
* mac_text()
*
* Switch to text mode.
\*----------------------------------------------------------------------*/
void
mac_text(PLStream *pls)
{
}
/*----------------------------------------------------------------------*\
* mac_esc()
*
* Escape function.
*
* Functions:
*
* PLESC_EH Handle pending events
* PLESC_EXPOSE Force an expose
* PLESC_FILL Fill polygon
* PLESC_FLUSH Flush X event buffer
* PLESC_GETC Get coordinates upon mouse click
* PLESC_REDRAW Force a redraw
* PLESC_RESIZE Force a resize
\*----------------------------------------------------------------------*/
void
plD_esc_mac(PLStream *pls, PLINT op, void *ptr)
{
int i;
GetPort(&savedPort);
SetPort(plotWindow[plotActive]);
switch (op)
{
case PLESC_EXPOSE: /* handle window expose */
break;
case PLESC_RESIZE: /* handle window resize */
break;
case PLESC_REDRAW: /* handle window redraw */
break;
case PLESC_TEXT: /* switch to text screen */
break;
case PLESC_GRAPH: /* switch to graphics screen */
break;
case PLESC_FILL: /* fill polygon */
OpenRgn(); // Start a Region for a fill
for (i = 0; i < pls->dev_npts - 1; i++)
{
plD_line_mac(pls, pls->dev_x[i], pls->dev_y[i],
pls->dev_x[i + 1], pls->dev_y[i + 1]);
}
CloseRgn(fillRegion); // Close the region
PaintRgn(fillRegion); // Now Paint it
break;
case PLESC_DI: /* handle DI command */
break;
case PLESC_FLUSH: /* flush output */
break;
case PLESC_EH: /* handle Window events */
break;
case PLESC_GETC: /* get cursor position */
break;
case PLESC_SWIN: /* set window parameters */
break;
}
SetPort(savedPort);
}
/*----------------------------------------------------------------------*\
* mac_esc()
*
* Escape function.
\*----------------------------------------------------------------------*/
//private functions
static unsigned char MAC_event(PLStream *pls)
{
EventRecord theEvent;
WindowPtr whichWindow;
Rect dragRect, growRect;
int i, growResult;
short newWidth, newHeight;
SystemTask();
if (GetNextEvent(everyEvent, &theEvent))
switch (theEvent.what)
{
case mouseDown:
switch(FindWindow(theEvent.where,&whichWindow))
{
case inSysWindow:
SystemClick(&theEvent,whichWindow);
break;
case inContent:
return TRUE;
break;
case inDrag:
SetRect(&dragRect,4,24,qd.screenBits.bounds.right-4,qd.screenBits.bounds.bottom-4);
DragWindow(whichWindow,theEvent.where, &dragRect);
break;
case inGrow:
SetRect(&growRect,128,128,32767,32767);
growResult = GrowWindow(whichWindow,theEvent.where, &growRect);
if (growResult != 0)
{
newWidth = LoWord(growResult);
newHeight = HiWord(growResult);
ResizeWin(pls, whichWindow,newWidth,newHeight);
}
break;
case inMenuBar:
AdjustMenu();
HiliteMenu(0);
return doMenuCommand(MenuSelect(theEvent.where));
break;
};
break;
case keyDown:
case autoKey:
if ((theEvent.modifiers & cmdKey) != 0)
{
AdjustMenu();
HiliteMenu(0);
return doMenuCommand(MenuKey(theEvent.message & charCodeMask));
}
else
HiliteMenu(0);
return TRUE;
break;
case updateEvt: // Update a window
whichWindow = (WindowPtr)theEvent.message;
i = GetWRefCon(whichWindow);
if (i >= 0 && i < Max_Mac_Windows_Used)
{
BeginUpdate(plotWindow[i]);
GetPort(&savedPort);
SetPort(plotWindow[i]);
DrawPicture(plotPicture[i],&plotWindow[i]->portRect);
SetPort(savedPort);
EndUpdate(plotWindow[i]);
}
break;
case activateEvt:
// InvalRect(&plotWindow[plotActive]->portRect);
break;
}
return FALSE;
}
void ResizeWin( PLStream *pls,
WindowPtr whichWindow,
short newWidth,
short newHeight)
{
int i, myWindow = Max_Mac_Windows_Used;
i = GetWRefCon(whichWindow);
if (i >= 0 && i < Max_Mac_Windows_Used)
{
myWindow = i;
}
if (Max_Mac_Windows_Used == myWindow)
return;
SizeWindow(whichWindow, newWidth, newHeight, true);
InvalRect(&whichWindow->portRect); // make sure whole window is redrawn in the update
if (myWindow == plotActive)
{
plotWidth = newWidth;
plotHeight = newHeight;
plP_setphy((PLINT) 0, (PLINT) (newWidth), (PLINT) 0, (PLINT) (newHeight));
}
}
unsigned char doMenuCommand(long mCmd)
{
unsigned char result=FALSE;
int item,menu;
// Str255 daName;
// short daRefNum;
item=LoWord(mCmd);
menu=HiWord(mCmd);
switch(menu)
{
case plotM:
switch(item)
{
case PlotCopy:
doCopy();
result = FALSE;
break;
case PlotSave:
PutPictToFile();
result = FALSE;
break;
case PlotContinue:
result = TRUE;
break;
}
break;
}
HiliteMenu(0);
AdjustMenu();
return result;
}
/**************************** doCopy *************************/
void doCopy()
{
short frontWindow;
WindowPtr tempWindow;
tempWindow = FrontWindow();
frontWindow = (short) GetWRefCon(tempWindow); // Get the window number
ZeroScrap();
HLock((Handle) plotPicture[frontWindow]);
PutScrap(GetHandleSize((Handle)plotPicture[frontWindow]) ,'PICT', *plotPicture[frontWindow]);
HUnlock((Handle) plotPicture[frontWindow]);
}
/**************************** SetUpMenu *************************/
void SetUpMenu(void)
{
saveMBar=GetMenuBar();
// ClearMenuBar();
// myMenu=NewMenu(appleM,"\p\024");
// AppendMenu(myMenu, "\pAbout\311");
// InsertMenu(myMenu,0);
// AddResMenu(GetMHandle(appleM), 'DRVR'); /* add DA names to Apple menu */
myMenu=NewMenu(plotM,"\pPLplot");
AppendMenu(myMenu, "\pCopy To Clipboard/C;Save To File/S;(-;Continue/G");
InsertMenu(myMenu,0);
DrawMenuBar();
myMBar=GetMenuBar();
}
void AdjustMenu(void)
{
SetMenuBar(myMBar);
DrawMenuBar();
}
void RestoreMenu(void)
{
SetMenuBar(saveMBar);
DrawMenuBar();
DisposeMenu(myMenu);
DisposeHandle(myMBar);
DisposeHandle(saveMBar);
}
// routines to create PICT file.
/*------ PutPictToFile ----------------------------------------------------------------------------*/
//void PutPictToFile(PicHandle thePicture)
void PutPictToFile(void)
{
SFReply tr;
short fRefNum, count;
long inOutCount;
Point where;
unsigned char header[512];
OSErr myError;
short frontWindow;
Str255 tempTitle;
frontWindow = (short) GetWRefCon(FrontWindow()); // Get the window number
if(frontWindow != plotActive)
GetWTitle(plotWindow[frontWindow], tempTitle);
else
BlockMove(tempWTitle, tempTitle, (long) tempWTitle[0]+1);
for (count = 0; count < 512; count++)
header[count] = 0x00;
where.h=100; where.v=50; /* where the Standard File dialog window goes */
SFPutFile( where, "\pSave PICT as:", tempTitle, NULL, &tr );
if ( tr.good ) {
myError = Create(tr.fName, tr.vRefNum, 'CDrw', 'PICT');
if (myError == dupFNErr)
{
myError = FSDelete(tr.fName,tr.vRefNum);
myError = Create(tr.fName, tr.vRefNum, 'CDrw', 'PICT');
} /* this is quick 'n' dirty or there'd
be more robust handling here */
myError = FSOpen( tr.fName, tr.vRefNum, &fRefNum );
if ( myError == noErr )
{
inOutCount = 512;
myError = FSWrite(fRefNum, &inOutCount, header); /* write the header */
HLock((Handle)plotPicture[frontWindow]);
if (myError == noErr)
{ /* don't write if error the first time */
inOutCount = GetHandleSize((Handle)plotPicture[frontWindow]);
myError = FSWrite(fRefNum,&inOutCount,*plotPicture[frontWindow]);
}
FSClose( fRefNum ); /* close it */
HUnlock((Handle)plotPicture[frontWindow]);
}
}
}
/**************************** DoAbout *************************/
void
DoAbout( Str255 s )
{
#define BASE_RES_ID 400
#define NIL_POINTER 0L
ParamText( s, "\p", "\p", "\p" );
NoteAlert( BASE_RES_ID, NIL_POINTER );
}
/**************************** DoAbout *************************/
// Routine to place the plot area on the screen ---
// Defualt: boundsRect = {50, 10, 650, 610}
//
// This utility will not allow plot to be smaller than 200 x 200
// or larger than 600 x 600
void
mac_plot_area(Rect *plotArea)
{
// Limits set by Screenbits -- Comemnted out
// plotArea->left = (plotArea->left > 10) ? plotArea->left : 10;
// plotArea->top = (plotArea->top > 40) ? plotArea->top : 40;
// plotArea->right= (plotArea->right > qd.screenBits.bounds.right) ?
// qd.screenBits.bounds.right-10 : plotArea->right;
// plotArea->bottom= (plotArea->bottom > qd.screenBits.bounds.bottom) ?
// qd.screenBits.bounds.bottom-10 : plotArea->bottom;
// XMAX and YMAX limits
//
plotArea->left = (plotArea->left > 10) ? plotArea->left : 10;
plotArea->top = (plotArea->top > 40) ? plotArea->top : 40;
plotArea->right= (plotArea->right > plotArea->left+MAC_XMAX) ?
plotArea->left+MAC_XMAX : plotArea->right;
plotArea->bottom= (plotArea->bottom > plotArea->top+MAC_YMAX) ?
plotArea->top+MAC_YMAX : plotArea->bottom;
// Make sure it's at least 200 x 200 as minimum
if(plotArea->right-plotArea->left < 200)
plotArea->right = plotArea->left+200;
if(plotArea->bottom-plotArea->top < 200)
plotArea->bottom = plotArea->top+200;
SetRect(&boundsRect, plotArea->left, plotArea->top, plotArea->right, plotArea->bottom);
plotWidth = plotArea->right - plotArea->left;
plotHeight = plotArea->bottom - plotArea->top;
}
/*******************************************************************************
CatenatePStrings
Catenate two Pascal strings by attaching the second string on the end of
the first string. If you are running under MPW 3.2 or later, you can
simply use the PLCatenate library routine instead.
*******************************************************************************/
void
CatenatePStrings(Str255 targetStr, Str255 appendStr)
{
short appendLen;
/* Figure out number of bytes to copy, up to 255 */
appendLen = MIN(appendStr[0], 255 - targetStr[0]);
if (appendLen > 0) {
BlockMove(appendStr+1, targetStr+targetStr[0]+1, (long) appendLen);
targetStr[0] += appendLen;
}
}
/*******************************************************************************
CopyPStrings
Copies two Pascal strings by attaching the second string on the end of
the first string. If you are running under MPW 3.2 or later, you can
simply use the PLCatenate library routine instead.
*******************************************************************************/
void
CopyPStrings(Str255 targetStr, Str255 appendStr)
{
// short appendLen;
/* Figure out number of bytes to copy, up to 255 */
BlockMove(appendStr, targetStr, (long) appendStr[0]+1);
// targetStr[0];
}
/*--------------------------------------------------------------------------*\
* FILE *plMacLibOpen(fn)
*
* Return file pointer to lib file.
* Locations checked:
* In the system Preferences folder we check for
* the lib folder or a plplot_lib folder. The latter may be an alias
\*--------------------------------------------------------------------------*/
#include <Folders.h>
#include <Files.h>
//#include <MoreFilesExtras.h>
//#include <FSpCompat.h>
#include <FSp_fopen.h>
FILE *plMacLibOpen(char *fn)
{
FILE *file;
char *fs = NULL;
OSErr anErr;
short prefVRefNum;
long prefDirID;
FSSpec FSlibFileDir, FSlibFile;
Boolean resolveAliasChains=TRUE, targetIsFolder, wasAliased;
/* find the preferences folder */
anErr = FindFolder( kOnSystemDisk, 'pref', kDontCreateFolder , &prefVRefNum, &prefDirID);
// first see if the plplot_lib folder is here; alias or not
anErr = FSMakeFSSpec(prefVRefNum, prefDirID, "\pplplot_lib", &FSlibFileDir);
if ( (anErr == noErr) && (FSlibFileDir.parID == 0) )
FSlibFileDir.parID = fsRtParID;
// if it is an alias get what it points to!
anErr = ResolveAliasFile(&FSlibFileDir, resolveAliasChains, &targetIsFolder, &wasAliased);
// make FSSpec for file within the directory ; 1st construct the relative filename
// then make the FSSpec; then open it!
plGetName("", p2cstr(FSlibFileDir.name), fn, &fs);
anErr = FSMakeFSSpec(FSlibFileDir.vRefNum, FSlibFileDir.parID, c2pstr(fs), &FSlibFile);
if ( (anErr == noErr) && (FSlibFile.parID == 0) )
FSlibFile.parID = fsRtParID;
file = FSp_fopen(&FSlibFile, "rb");
/* if (file != NULL)
{
free_mem(fs);
return (file);
}
*/
free_mem(fs);
return (file);
}
|