static boolean customiconload (bigstring bsiconname, short *rnum) { // // 2006-06-18 creedon: FSRef-ized // // 7.0b9 PBS: Open a resource file just once, store info about it, so it doesn't have to be opened for each rendering. // bigstring bsappearancefolder = "\x0a" "Appearance"; bigstring bsiconsfolder = "\x05" "Icons"; tyfilespec programfilespec, appfolderfilespec, appearancefolder, iconsfolder, iconfilespec; short r, ixcurricon; if (ixnexticon >= maxcustomicontypes) return (false); // limit reached // get app filespec getapplicationfilespec (nil, &programfilespec); macgetfilespecparent(&programfilespec, &appfolderfilespec); //PBS 8 Sep 2010: need parent folder of app before getting Appearance folder // get Appearances folder if (macgetfilespecchildfrombigstring (&appfolderfilespec, bsappearancefolder, &appearancefolder) != noErr) return (false); // get Icons folder if (macgetfilespecchildfrombigstring (&appearancefolder, bsiconsfolder, &iconsfolder) != noErr) return (false); // get icon file if (macgetfilespecchildfrombigstring (&iconsfolder, bsiconname, &iconfilespec) != noErr) return (false); if (!openresourcefile (&iconfilespec, &r, resourcefork)) return (false); if (r == -1) return (false); *rnum = r; ixcurricon = ixnexticon; ixnexticon++; alllower (bsiconname); copystring (bsiconname, icontypes [ixcurricon].bstype); icontypes [ixcurricon].rnum = r; return (true); } // customiconload
void initfsdefault (void) { // // 2010-01-24 creedon: assign fsdefault the path that the application is // in, not the path of the application itself, // restoring previous behavior, fix for problem with // relative paths not working // // 2006-06-18 creedon: FSRef-ized // // 2005-07-18 creedon, karstenw: created // #ifdef MACVERSION getapplicationfilespec ( nil, &fsdefault ); macgetfilespecparent ( &fsdefault, &fsdefault ); #endif } /* initfsdefault */
static void ccdrawfrontiericon (Rect rcicn, boolean flpressed) { // // 2006-07-12 creedon: FSRef-ized // // 7.0b53 PBS: draw an OS X style icon // #ifdef MACVERSION IconRef iconref; tyfilespec programfspec; short label; OSErr err; Rect r = rcicn; FSSpec fs; getapplicationfilespec (nil, &programfspec); err = macgetfsspec (&programfspec, &fs); if (GetIconRefFromFile (&fs, &iconref, &label) == noErr) { err = PlotIconRef (&r, kAlignAbsoluteCenter, flpressed? kTransformSelected : 0, kIconServicesNormalUsageFlag, iconref); ReleaseIconRef (iconref); if (err == noErr) return; } // if #endif // MACVERSION ploticonresource ( &rcicn, kAlignAbsoluteCenter, flpressed ? kTransformSelected : 0, idfrontiericon ); } // ccdrawfrontiericon
boolean sysinitverbs (void) { getapplicationfilespec (nil, &programfspec); launchcallbacks.waitcallback = &shellsysverbwaitroutine; if (!loadfunctionprocessor (idsysverbs, &sysfunctionvalue)) return (false); if (!loadfunctionprocessor (idlaunchverbs, &launchfunctionvalue)) return (false); if (!loadfunctionprocessor (idclipboardverbs, &clipboardfunctionvalue)) return (false); if (!loadfunctionprocessor (idfrontierverbs, &frontierfunctionvalue)) return (false); if (!loadfunctionprocessor (idthreadverbs, &threadfunctionvalue)) return (false); return (true); } // sysinitverbs
short __assert (char *expr, char *file, short line) { /* On OS X, DebugStr output gets automatically rerouted to stderr which in turn gets logged to console.log, viewable via Console.app. 2003-05-26 AR: Include date/time, app name, and app version. */ static boolean flnorentry = false; short day, month, year, hour, minute, second; tyfilespec myfspec; bigstring bs, bslogstamp, bsline, bsfile, bsmessage; if (flnorentry) return (0); flnorentry = true; /*get timestamp*/ secondstodatetime (timenow (), &day, &month, &year, &hour, &minute, &second); numbertostring ((long) year, bs); pushstring (bs, bslogstamp); pushchar ('-', bslogstamp); numbertostring ((long) month, bs); padwithzeros (bs, 2); pushstring (bs, bslogstamp); pushchar ('-', bslogstamp); numbertostring ((long) day, bs); padwithzeros (bs, 2); pushstring (bs, bslogstamp); pushchar (' ', bslogstamp); numbertostring ((long) hour, bs); padwithzeros (bs, 2); pushstring (bs, bslogstamp); pushchar (':', bslogstamp); numbertostring ((long) minute, bs); padwithzeros (bs, 2); pushstring (bs, bslogstamp); pushchar (':', bslogstamp); numbertostring ((long) second, bs); padwithzeros (bs, 2); pushstring (bs, bslogstamp); pushchar (' ', bslogstamp); /*get filespec for app*/ getapplicationfilespec (nil, &myfspec); pushstring (fsname (&myfspec), bslogstamp); pushchar (' ', bslogstamp); /*get version of app*/ filegetprogramversion (bs); pushchar ('(', bslogstamp); pushstring (bs, bslogstamp); pushchar (')', bslogstamp); /*get file name*/ moveleft (file, bsfile, (long) lenbigstring); convertcstring (bsfile); /*get line number*/ numbertostring ((long) line, bsline); /*ouput message*/ parsedialogstring ( "\p\r^0: Assertion failed in file ^1, at line ^2.\r", bslogstamp, bsfile, bsline, nil, bsmessage); DebugStr (bsmessage); /*send message to stderr*/ flnorentry = false; return (0); } /*__assert*/
static boolean sysfunctionvalue (short token, hdltreenode hparam1, tyvaluerecord *vreturned, bigstring bserror) { // // 2006-06-28 creedon: for Mac, FSRef-ized // // 5.0b16 dmb: undo that change. it affect performance adversely if many threads do it. // // 5.0b12 dmb: in systemtaskfunc, set flresting to false to make sure we don't slow down too much // // 1/18/93 dmb: in systemtaskfunc, don't call processyield directly; use langbackgroundtask // // 8/11/92 dmb: make apprunningfunc accept a string or an ostype // // 5/20/92 dmb: do processyield directly on systemtaskfunc // // 2/12/92 dmb: do partialeventloop on systemtask & bringapptofrontfunc // register tyvaluerecord *v = vreturned; setbooleanvalue (false, v); /*assume the worst*/ switch (token) { /*these verbs don't need any special globals pushed*/ case systemversionfunc: { bigstring bs; getsystemversionstring (bs, nil); if (!langcheckparamcount (hparam1, 0)) return (false); return (setstringvalue (bs, v)); } case systemtaskfunc: if (!langcheckparamcount (hparam1, 0)) /*shouldn't have any parameters*/ return (false); shellsysverbwaitroutine (); /* if (!processyield ()) return (false); */ if (!langbackgroundtask (true)) return (false); (*v).data.flvalue = true; return (true); case browsenetworkfunc: #ifdef MACVERSION return (langipcbrowsenetwork (hparam1, v)); #endif #ifdef WIN95VERSION #pragma message ("WIN95: browsenetworkfunc - not yet implemented!") break; #endif case apprunningfunc: { OSType appid; bigstring bsapp; tyvaluerecord val; flnextparamislast = true; /* if (!getostypevalue (hparam1, 1, &appid)) return (false); (*v).data.flvalue = findrunningapplication (&appid, nil); */ if (!getparamvalue (hparam1, 1, &val)) return (false); if (val.valuetype == ostypevaluetype) { setemptystring (bsapp); appid = val.data.ostypevalue; } else { if (!coercetostring (&val)) return (false); pullstringvalue (&val, bsapp); if (!stringtoostype (bsapp, &appid)) appid = 0; } (*v).data.flvalue = findrunningapplication (&appid, bsapp, nil); return (true); } case frontappfunc: { bigstring bs; if (!langcheckparamcount (hparam1, 0)) return (false); if (!getfrontapplication (bs, false)) return (false); return (setstringvalue (bs, v)); } case bringapptofrontfunc: { bigstring bs; flnextparamislast = true; if (!getstringvalue (hparam1, 1, bs)) return (false); (*v).data.flvalue = activateapplication (bs); return (true); } case countappsfunc: if (!langcheckparamcount (hparam1, 0)) return (false); return (setlongvalue (countapplications (), v)); case getnthappfunc: { short n; bigstring bs; if (!getintvalue (hparam1, 1, &n)) return (false); if (!getnthapplication (n, bs)) setemptystring (bs); return (setstringvalue (bs, v)); } case getapppathfunc: { bigstring bs; tyfilespec fs; flnextparamislast = true; if ( ! getstringvalue ( hparam1, 1, bs ) ) return ( false ); if ( ! getapplicationfilespec ( bs, &fs ) ) // 2006-02-17 aradke: initializes fs even if it fails setemptystring (bs); return ( setfilespecvalue ( &fs, v ) ); } case memavailfunc: { unsigned long memavail; #ifdef WIN95VERSION MEMORYSTATUS meminfo; meminfo.dwLength = sizeof (MEMORYSTATUS); GlobalMemoryStatus (&meminfo); memavail = meminfo.dwAvailVirtual; #endif #ifdef MACVERSION memavail = TempFreeMem(); #endif if (!langcheckparamcount (hparam1, 0)) /*shouldn't have any parameters*/ return (false); return (setlongvalue (memavail, v)); } case machinefunc: #ifdef MACVERSION //Code change by Timothy Paustian Friday, June 16, 2000 3:13:09 PM //Changed to Opaque call for Carbon //Carbon only runs on PPC #if TARGET_API_MAC_CARBON return (setstringvalue (machinePPC, v)); #else #if GENERATINGPOWERPC return (setstringvalue (machinePPC, v)); #endif #if GENERATING68K return (setstringvalue (machine68K, v)); #endif #endif #endif #ifdef WIN95VERSION return (setstringvalue (machinex86, v)); #endif break; case osfunc: return (sysos (v)); break; #ifdef WIN95VERSION case getenvironmentvariablefunc: { bigstring bsenvname; bigstring buf; DWORD res; flnextparamislast = true; if (!getstringvalue (hparam1, 1, bsenvname)) return (false); nullterminate(bsenvname); res = GetEnvironmentVariable (stringbaseaddress(bsenvname), stringbaseaddress(buf), sizeof(buf)-2); if (res > sizeof(buf) - 2) { return (setbooleanvalue (false, v)); //safety valve } setstringlength (buf, res); return (setstringvalue (buf, v)); } break; case setenvironmentvariablefunc: { bigstring bsenvname; bigstring bsenvval; bigstring bserror, bserror2; boolean res; if (!getstringvalue (hparam1, 1, bsenvname)) return (false); flnextparamislast = true; if (!getstringvalue (hparam1, 2, bsenvval)) return (false); nullterminate(bsenvname); nullterminate(bsenvval); res = SetEnvironmentVariable (stringbaseaddress(bsenvname), stringbaseaddress(bsenvval)); if (res) { return (setbooleanvalue (true, v)); } getsystemerrorstring (GetLastError(), bserror); nullterminate(bserror); wsprintf (bserror2, "Can't set environment variable \"%s\" to \"%s\" because %s", stringbaseaddress (bsenvname), stringbaseaddress (bsenvval), stringbaseaddress (bserror)); setstringlength (bserror2, strlen(stringbaseaddress(bserror2))); shellerrormessage (bserror2); return (setbooleanvalue (false, v)); } break; #endif #if TARGET_API_MAC_CARBON == 1 case unixshellcommandfunc: { /*7.0b51 PBS: call shell on OS X*/ Handle hcommand, hreturn; flnextparamislast = true; if (!getexempttextvalue (hparam1, 1, &hcommand)) return (false); newemptyhandle (&hreturn); if (!unixshellcall (hcommand, hreturn)) { disposehandle (hreturn); disposehandle (hcommand); return (false); } /*if*/ disposehandle (hcommand); return (setheapvalue (hreturn, stringvaluetype, v)); } #endif #ifdef WIN95VERSION case winshellcommandfunc: { Handle hcommand; Handle houttext = nil; Handle herrtext = nil; long exitcode = 0; tyaddress adrexitcode, adrstderr; short ctconsumed = 1; short ctpositional = 1; boolean flneedexitcode, flneedstderr; tyvaluerecord val; if (!getexempttextvalue (hparam1, 1, &hcommand)) return (false); if (!getoptionaladdressparam (hparam1, &ctconsumed, &ctpositional, "\x0b" "adrExitCode", &adrexitcode.ht, adrexitcode.bs)) return (false); flnextparamislast = true; if (!getoptionaladdressparam (hparam1, &ctconsumed, &ctpositional, "\x0b" "adrStdErr", &adrstderr.ht, adrstderr.bs)) return (false); flneedexitcode = (adrexitcode.ht != nil) || !isemptystring (adrexitcode.bs); flneedstderr = (adrstderr.ht != nil) || !isemptystring (adrstderr.bs); newemptyhandle (&houttext); if (flneedstderr) newemptyhandle (&herrtext); if (!winshellcall (hcommand, houttext, herrtext, (flneedexitcode ? &exitcode : nil))) { disposehandle (houttext); disposehandle (herrtext); disposehandle (hcommand); return (false); } /*if*/ disposehandle (hcommand); if (flneedexitcode) { setlongvalue (exitcode, &val); if (!langsetsymboltableval (adrexitcode.ht, adrexitcode.bs, val)) return (false); } if (flneedstderr) { setheapvalue (herrtext, stringvaluetype, &val); if (!langsetsymboltableval (adrstderr.ht, adrstderr.bs, val)) return (false); exemptfromtmpstack (&val); } return (setheapvalue (houttext, stringvaluetype, v)); } #endif //WIN95VERSION default: break; } getstringlist (langerrorlist, unimplementedverberror, bserror); return (false); } /*sysfunctionvalue*/