mac.c

Go to the documentation of this file.
00001 
00002 /*  $Id: mac.c 1201 2006-04-05 22:31:38Z karstenw $    */
00003 
00004 /******************************************************************************
00005 
00006     UserLand Frontier(tm) -- High performance Web content management,
00007     object database, system-level and Internet scripting environment,
00008     including source code editing and debugging.
00009 
00010     Copyright (C) 1992-2004 UserLand Software, Inc.
00011 
00012     This program is free software; you can redistribute it and/or modify
00013     it under the terms of the GNU General Public License as published by
00014     the Free Software Foundation; either version 2 of the License, or
00015     (at your option) any later version.
00016 
00017     This program is distributed in the hope that it will be useful,
00018     but WITHOUT ANY WARRANTY; without even the implied warranty of
00019     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020     GNU General Public License for more details.
00021 
00022     You should have received a copy of the GNU General Public License
00023     along with this program; if not, write to the Free Software
00024     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025 
00026 ******************************************************************************/
00027 
00028 #include "frontier.h"
00029 #include "standard.h"
00030 
00031 #include "mac.h"
00032 #include "memory.h"
00033 #include "strings.h"
00034 
00035 
00036 #include "error.h"
00037 #define kNumberOfMasters 128
00038 
00039 long    gSystemVersion;
00040 boolean gHasColorQD;
00041 boolean gCanUseNavServ;
00042 
00043 tymemoryconfig macmemoryconfig;
00044 
00045 
00046 boolean initmacintosh (void) {
00047     
00048     /*
00049     the magic stuff that every Macintosh application needs to do 
00050     before doing anything else.
00051     
00052     4/24/91 dmb: added memory config resource stuff
00053     
00054     3.0.4 dmb: use LMGetCurStackBase, not CurStackBase global
00055     
00056     3.0.4 dmb: pass 0L to InitDialogs
00057     */
00058     
00059     register short i;
00060     register hdlmemoryconfig h;
00061     register long ctbytes;
00062     //Code change by Timothy Paustian Thursday, June 8, 2000 3:45:13 PM
00063     //
00064     #if TARGET_API_MAC_CARBON == 0
00065     long ctstack;
00066     #endif
00067     long ctheap, ctcode;
00068     short ctmasters;
00069     
00070     h = (hdlmemoryconfig) Get1Resource ('MCFG', 1);
00071     
00072     if (h == nil)
00073         clearbytes (&macmemoryconfig, sizeof (macmemoryconfig));
00074     else
00075         macmemoryconfig = **h;
00076     
00077     //Code change by Timothy Paustian Saturday, June 3, 2000 10:13:20 PM
00078     //Changed to Opaque call for Carbon
00079     //we don't need this in carbon.
00080     #if TARGET_API_MAC_CARBON == 0
00081     if (h != nil) { /*first check stack size*/
00082         
00083         ctbytes = (**h).minstacksize;
00084         
00085         ctstack = LMGetCurStackBase () - GetApplLimit (); /*current stack size*/
00086         
00087         if (ctbytes > ctstack)
00088             SetApplLimit (LMGetCurStackBase () - ctbytes);
00089         }
00090     MaxApplZone ();
00091     
00092     #endif
00093 
00094     
00095     
00096     if (h != nil) { /*check heap size and master pointers*/
00097         
00098         ctbytes = (**h).minheapsize;
00099         
00100         //Code change by Timothy Paustian Thursday, June 8, 2000 3:04:31 PM
00101         //Changed to Opaque call for Carbon
00102         //This is meaningless for OS X since it has unlimited memory.
00103         
00104         #if TARGET_API_MAC_CARBON == 1
00105         //we need to do somethings else. FreeMem is going to return some large value
00106         //of all the available system memory
00107         //This whole thing is pointless. We can get as much memory as we need.
00108 
00109             #pragma unused (ctmasters)
00110             #pragma unused (ctcode)
00111             #pragma unused (ctheap)
00112         
00113         #else
00114 
00115         ctheap = FreeMem ();
00116         
00117         if (ctbytes > ctheap) {
00118             
00119             return (false);
00120             }
00121         
00122         ctbytes = (**h).avghandlesize;
00123         
00124         ctcode = (**h).reserveforcode;
00125         
00126         if ((ctbytes > 0) && (ctheap > ctcode)) {
00127             
00128             ctmasters = ((ctheap - ctcode) / ctbytes) / kNumberOfMasters;
00129             
00130             ctmasters = min (ctmasters, 1024);  /*7.1b37 PBS: You'd think 1024 calls would be enough. With large memory alottments on Mac
00131                                                 Classic, we're calling MoreMasters in excess of 20,000 times. That makes the app take
00132                                                 a minute or so to start up! So instead I've chosen an arbitrary limit.*/
00133                                       
00134             for (i = 1; i < ctmasters; i++) 
00135                 MoreMasters ();
00136             }
00137         #endif
00138 
00139         ReleaseResource ((Handle) h); /*we're done with it*/
00140         }
00141     
00142     //Code change by Timothy Paustian Thursday, June 8, 2000 3:21:06 PM
00143     //Changed to Opaque call for Carbon
00144     //we don't need this initialization in carbon
00145     #if TARGET_API_MAC_CARBON == 0
00146     InitGraf (&qd.thePort);
00147     
00148     InitFonts ();
00149     
00150     FlushEvents (everyEvent, 0);
00151     
00152     InitWindows ();
00153     
00154     InitMenus ();
00155     
00156     TEInit ();
00157     
00158     InitDialogs (0L);
00159     #endif
00160 
00161     
00162     InitCursor ();
00163     //Code change by Timothy Paustian Thursday, June 8, 2000 3:22:57 PM
00164     //Changed to Opaque call for Carbon
00165     //this is obsolete, we should be using gestalt for this.
00166     
00167     {   
00168         long quickDrawFeatures;
00169         OSErr theErr = Gestalt(gestaltSystemVersion, &gSystemVersion);
00170         if(oserror(theErr))
00171             ExitToShell();
00172 
00173         theErr = Gestalt(gestaltQuickdrawFeatures, &quickDrawFeatures);
00174         
00175         if(oserror(theErr))
00176             ExitToShell();
00177         gHasColorQD = (quickDrawFeatures & (1 << gestaltHasColor));
00178         //Nav services has to be present and we want the 1.1 or greater version.
00179         gCanUseNavServ = (NavServicesAvailable() && (NavLibraryVersion() >= 0x01108000));
00180     }
00181     
00182     
00183     //SysEnvirons (1, &macworld);
00184     
00185     //gee I bet this isn't required anymore either.
00186     for (i = 1; i <= 5; i++) { /*register with Multifinder*/
00187         
00188         EventRecord ev;
00189         
00190         EventAvail (everyEvent, &ev); /*see TN180 -- splash screen*/
00191         } /*for*/
00192     
00193     #if TARGET_API_MAC_CARBON == 1
00194     
00195         RegisterAppearanceClient ();
00196         
00197     #endif
00198     
00199     return (true);
00200     } /*initmacintosh*/
00201 
00202 
00203 #ifdef flsystem6
00204 
00205 short countinitialfiles (void) {
00206 
00207     short message, ctfiles;
00208     
00209     CountAppFiles (&message, &ctfiles);
00210     
00211     if (message == 0)
00212         return (ctfiles);
00213         
00214     return (0);
00215     } /*countinitialfiles*/
00216     
00217     
00218 void getinitialfile (short ix, bigstring fname, short *vnum) {
00219 
00220     AppFile appfilerecord;
00221 
00222     GetAppFiles (ix, &appfilerecord);
00223     
00224     copystring (appfilerecord.fName, fname);
00225     
00226     *vnum = appfilerecord.vRefNum;
00227     } /*getinitialfile*/
00228 
00229 #endif
00230 
00231 #if 0
00232 
00233 boolean installgestaltfunction (void) {
00234     
00235     Handle hgdef;
00236     ProcPtr x;
00237     
00238     hgdef = GetResource ('GDEF', idgestaltfunction);
00239     
00240     if (hgdef == nil) /*didn't find gestalt definition function*/
00241         return (false);
00242     
00243     x = (ProcPtr) *hgdef;
00244     
00245     if (NewGestalt (idgestaltselector, x) != noErr) {
00246         
00247         if (ReplaceGestalt (idgestaltselector, x, &x) != noErr) {
00248             
00249             ReleaseResource (hgdef);
00250             
00251             return (false);
00252             }
00253         }
00254     
00255     DetachResource (hgdef);
00256     
00257     return (true);
00258     } /*installgestaltfunction*/
00259 
00260 #endif
00261 
00262 
00263 
00264 #if TARGET_API_MAC_CARBON
00265 
00266 void WriteToConsole (char *s)
00267 {
00268 
00269     CFShow(CFStringCreateWithCString(NULL,s,kCFStringEncodingMacRoman));
00270         
00271 }
00272 
00273 void DoErrorAlert(OSStatus status, CFStringRef errorFormatString)
00274 {   
00275     CFStringRef formatStr = NULL, printErrorMsg = NULL;
00276     SInt16      alertItemHit = 0;
00277     Str255      stringBuf;
00278 
00279     if ((status != noErr) && (status != 2))           
00280     {
00281         formatStr =  CFCopyLocalizedString (errorFormatString, NULL);   
00282         if (formatStr != NULL)
00283         {
00284             printErrorMsg = CFStringCreateWithFormat(
00285                                                      NULL,
00286                                                      NULL,
00287                                                      formatStr,
00288                                                      status);
00289             if (printErrorMsg != NULL)
00290             {
00291                 if (CFStringGetPascalString (
00292                                              printErrorMsg,
00293                                              stringBuf,
00294                                              sizeof(stringBuf),
00295                                              GetApplicationTextEncoding()))
00296                 {
00297                     StandardAlert(kAlertStopAlert, stringBuf, NULL, NULL, &alertItemHit);
00298                 }
00299                 CFRelease (printErrorMsg);                     
00300             }
00301             CFRelease (formatStr);                             
00302         }
00303     }
00304 }
00305     
00306 #endif
00307 

Generated on Wed May 31 18:19:54 2006 for frontierkernel 10.1.10a by  doxygen 1.4.6