langstartup.c

Go to the documentation of this file.
00001 
00002 /*  $Id: langstartup.c 1332 2006-04-24 22:28:36Z sethdill $    */
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 "memory.h"
00032 #include "file.h"
00033 #include "ops.h"
00034 #include "strings.h"
00035 #include "shellhooks.h"
00036 #include "langexternal.h"
00037 #include "langinternal.h"
00038 #include "langtokens.h"
00039 #include "tableinternal.h"
00040 #include "tableverbs.h"
00041 #include "tablestructure.h"
00042 #include "resources.h"
00043 #include "WinSockNetEvents.h"
00044 #include "sysshellcall.h" /* 2006-03-09 aradke: unixshellcall moved from CallMachOFramework.h */
00045 #include "byteorder.h"  /* 2006-04-16 aradke: swap byte-order in loadfunctionprocessor */
00046 
00047 
00048 #define str_isPike              BIGSTRING ("\x06" "isPike")
00049 #define str_isOpmlEditor        BIGSTRING ("\x0c" "isOpmlEditor")    /* 2005-04-06 dluebbert */
00050 #define str_isFrontier          BIGSTRING ("\x0a" "isFrontier")      /* 2005-04-06 dluebbert */
00051 #define str_isRadio             BIGSTRING ("\x07" "isRadio")
00052 #define str_isMac               BIGSTRING ("\x05" "isMac")
00053 #define str_isMacOsClassic      BIGSTRING ("\x0e" "isMacOsClassic") /* 2004-11-19 creedon */
00054 #define str_isServer            BIGSTRING ("\x08" "isServer") /* 2004-11-19 creedon */
00055 #define str_isWindows           BIGSTRING ("\x09" "isWindows")
00056 #define str_osFlavor            BIGSTRING ("\x08" "osFlavor")
00057 #define str_osMajorVersion      BIGSTRING ("\x0e" "osMajorVersion")
00058 #define str_osMinorVersion      BIGSTRING ("\x0e" "osMinorVersion")
00059 #define str_osPointVersion      BIGSTRING ("\x0e" "osPointVersion") /* 2004-11-19 creedon */
00060 #define str_osBuildNumber       BIGSTRING ("\x0d" "osBuildNumber")
00061 #define str_osVersionString     BIGSTRING ("\x0f" "osVersionString")
00062 #define str_osFullNameForDisplay    BIGSTRING ("\x14" "osFullNameForDisplay")
00063 #define str_winServicePackNumber    BIGSTRING ("\x14" "winServicePackNumber")
00064 #define str_isCarbon                BIGSTRING ("\x08" "isCarbon")
00065 #define str_maxTcpConnections       BIGSTRING ("\x11" "maxTcpConnections")
00066 
00067 
00068 void initsegment (void) {
00069     
00070     } /*initsegment*/
00071 
00072 
00073 static boolean newfunctionprocessor (bigstring bsname, langvaluecallback valuecallback, boolean flwindow, hdlhashtable *htable) {
00074     
00075     /*
00076     each of the external function processors register with the system by calling
00077     this routine.  we create a new hashtable in the EFP table, and return a
00078     handle to the new table.  we also link in a callback routine that processes the
00079     verbs for this EFP.  flwindow is also recorded -- it says whether or not
00080     the EFP requires a window be open in order for one of its verbs to be
00081     executed.
00082     
00083     6/1/93 dmb: flwindow parameter is now real. when true, the valuecallback must
00084     respond to being called with a nil parameter list by determining whether or not 
00085     a specific verb requires Frontier to be the current process.
00086     */
00087     
00088     register hdlhashtable ht;
00089     
00090     if (!tablenewsystemtable (efptable, bsname, htable))
00091         return (false);
00092     
00093     ht = *htable; /*copy into register*/
00094     
00095     (**ht).flverbsrequirewindow = flwindow;
00096     
00097     (**ht).valueroutine = valuecallback;
00098     
00099     return (true);
00100     } /*newfunctionprocessor*/
00101 
00102 
00103 static boolean hashinsertcstring (bigstring bs, const tyvaluerecord *v) {
00104 
00105     convertcstring (bs);
00106 
00107     return (hashinsert (bs, *v));
00108     } /*hashinsertcstring*/
00109 
00110 
00111 static boolean langaddcstringkeyword (bigstring bs, short tokennumber) {
00112     
00113     tyvaluerecord val;
00114     
00115     initvalue (&val, tokenvaluetype);
00116     
00117     val.data.tokenvalue = (short) tokennumber;
00118     
00119     return (hashinsertcstring (bs, &val));
00120     } /*langaddcstringkeyword*/
00121     
00122 
00123 boolean langaddkeyword (bigstring bs, short tokennumber) {
00124     
00125     tyvaluerecord val;
00126     
00127     initvalue (&val, tokenvaluetype);
00128     
00129     val.data.tokenvalue = (short) tokennumber;
00130     
00131     return (hashinsert (bs, val));
00132     } /*langaddkeyword*/
00133     
00134 /*
00135 boolean langaddkeywordlist (hdlhashtable htable, byte * bskeywords[], short ctkeywords) {
00136     
00137     register short i;
00138     register boolean fl = true;
00139     
00140     pushhashtable (htable); 
00141     
00142     for (i = 0;  fl && (i < ctkeywords);  i++)
00143         fl = langaddkeyword ((ptrstring) bskeywords [i], i);
00144     
00145     pophashtable ();
00146     
00147     return (fl);
00148     } /%langaddkeywordlist%/
00149 */
00150 
00151 boolean loadfunctionprocessor (short id, langvaluecallback valuecallback) {
00152     
00153     /*
00154     2.1b5 dmb: having learning that our use of lots of string literals, and 
00155     hence the "Seperate STRS" option in Think C was making us victim of an 
00156     '040 instruction cache bug in Think C's run-time implementation of same, 
00157     it's time to create the kernel tables directly from resources.  that's 
00158     what this routine does.
00159     
00160     2006-04-16 aradke: swap byte-order on Intel Macs
00161     */
00162     
00163     bigstring bsname;
00164     hdlhashtable htable;
00165     short flwindow;
00166     long ix = 0;
00167     Handle hefps;
00168     short ctefps;
00169     short ctverbs;
00170     short ixverb = 0;
00171     boolean fl = true;
00172     
00173 #ifdef MACVERSION
00174     hefps = getresourcehandle ('EFP#', id);
00175 #endif
00176 #ifdef WIN95VERSION
00177     hefps = getresourcehandle ('EFP_', id);
00178 #endif
00179     
00180     assert (hefps != nil);
00181     
00182     if (hefps == nil)
00183         return (false);
00184     
00185     if (!loadfromhandle (hefps, &ix, 2, &ctefps))
00186         return (false);
00187     
00188     reztomemshort (ctefps);
00189     
00190     while (--ctefps >= 0) {
00191         
00192         copyrezstring (BIGSTRING (*hefps + ix), bsname);
00193         
00194         ix += stringsize (bsname);
00195         
00196         if (!loadfromhandle (hefps, &ix, 2, &flwindow))
00197             return (false);
00198         
00199         reztomemshort (flwindow);
00200         
00201         if (!newfunctionprocessor (bsname, valuecallback, (boolean) flwindow, &htable))
00202             return (false);
00203         
00204         if (!loadfromhandle (hefps, &ix, 2, &ctverbs))
00205             return (false);
00206         
00207         reztomemshort (ctverbs);
00208         
00209         pushhashtable (htable); 
00210         
00211         while (--ctverbs >= 0 && fl) {
00212             
00213             copyrezstring (BIGSTRING (*hefps + ix), bsname);
00214             
00215             ix += stringsize (bsname);
00216             
00217             fl = langaddkeyword ((ptrstring) bsname, ixverb++);
00218             }
00219         
00220         pophashtable ();
00221         }
00222 
00223     releaseresourcehandle (hefps);
00224     
00225     return (fl);
00226     } /*loadfunctionprocessor*/
00227 
00228 
00229 static boolean initenvironment (hdlhashtable ht) {
00230 
00231     #ifdef MACVERSION
00232     
00233         bigstring bsversion, bsos; /* 2004-11-19 creedon - added bsos*/
00234         boolean isMacOsClassic, isServer; /* 2004-11-19 creedon */
00235         unsigned long x;
00236         
00237         #if TARGET_API_MAC_CARBON == 1 /*PBS 7.028: system.environment.isCarbon*/
00238         
00239             /* 2004-11-19 creedon - added hcommand, hreturn, bs, response */
00240             Handle hcommand, hreturn;
00241             bigstring bs;
00242             UInt32 response;
00243             OSErr err;
00244         
00245         #endif
00246         
00247         gestalt (gestaltSystemVersion, (long *)(&x));
00248         
00249         langassignbooleanvalue (ht, str_isMac, true);
00250         
00251         langassignbooleanvalue (ht, str_isWindows, false);
00252         
00253         //langassignstringvalue (ht, str_osFlavor, zerostring);
00254         
00255         langassignlongvalue (ht, str_osMajorVersion, bcdtolong (x >> 8)); /* 2004-11-19 creedon - convert from bcd for correct display on Mac OS X */ 
00256         
00257         langassignlongvalue (ht, str_osMinorVersion, (x & 0x00f0) >> 4);
00258 
00259         langassignlongvalue (ht, str_osPointVersion, x & 0x0f); /* 2004-11-19 creedon */        
00260         getsystemversionstring (bsversion, nil);
00261         
00262         langassignstringvalue (ht, str_osVersionString, bsversion);
00263 
00264         /* langassignstringvalue (ht, str_osFullNameForDisplay, "\x09" "Macintosh"); 2004-11-19 creedon - moved to later in code*/
00265         
00266         #if TARGET_API_MAC_CARBON == 1 /*PBS 7.028: system.environment.isCarbon*/
00267 
00268             langassignbooleanvalue (ht, str_isCarbon, true);
00269             
00270             /* 2004-11-19 creedon - get mac os build number, full display name, is server*/
00271 
00272             /* get mac os build number */
00273  
00274             newtexthandle ("\psw_vers -buildVersion", &hcommand);
00275             
00276             newemptyhandle (&hreturn);
00277             
00278             unixshellcall (hcommand, hreturn);
00279             
00280             texthandletostring (hreturn, bs);
00281             
00282             sethandlesize (hreturn, 0);
00283             
00284             setstringlength (bs, stringlength (bs) - 1);
00285             
00286             langassignstringvalue (ht, str_osBuildNumber, bs); /* get mac os build number */
00287 
00288             /* get os full display name */
00289 
00290             copystring ((unsigned char *)"sw_vers -productName", bs); 
00291 
00292             sethandlecontents (bs, stringsize (bs), hcommand);
00293 
00294             unixshellcall (hcommand, hreturn);
00295 
00296             texthandletostring (hreturn, bsos);
00297 
00298             setstringlength (bsos, stringlength (bsos) - 1); /* get os full display name */
00299             
00300             disposehandle (hcommand);
00301             disposehandle (hreturn); /* get mac os build number and full display name*/
00302             
00303             /* 2004-11-19 creedon - is mac os classic */
00304             /* This needs to be checked on Mac OS Classic as well as Mac OS 9 proper. */
00305             
00306             err = gestalt (gestaltMacOSCompatibilityBoxAttr, (long *)(&response));
00307             
00308             if ((err == noErr) && ((response & (1 << gestaltMacOSCompatibilityBoxPresent)) != 0))
00309                 isMacOsClassic = true;
00310             else
00311                 isMacOsClassic = false;
00312             
00313             /* 2004-11-19 creedon - is server */
00314             
00315             if (equalstrings (bsos, "\pMac OS X Server"))
00316                 isServer = true;
00317             else
00318                 isServer = false; /* is server */
00319 
00320         #else
00321             
00322             langassignbooleanvalue (ht, str_isCarbon, false);
00323 
00324             copystring (BIGSTRING ("\x06" "Mac OS"), bsos); /* 2004-11-19 creedon - Mac OS, used to be Macintosh*/ 
00325             
00326             isMacOsClassic = true; /* 2004-11-19 creedon */
00327             
00328             isServer = false; /* 2004-11-19 creedon */
00329             
00330         #endif
00331         
00332         langassignbooleanvalue (ht, str_isMacOsClassic, isMacOsClassic); /* 2004-11-19 creedon */
00333         
00334         langassignstringvalue (ht, str_osFullNameForDisplay, bsos); /* 2004-11-19 creedon - changed "\x06" "Mac OS" to bsos. a calculated value */
00335         
00336         langassignbooleanvalue (ht, str_isServer, isServer); /* 2004-11-19 creedon */
00337         
00338     #endif
00339 
00340     #ifdef WIN95VERSION
00341     
00342         bigstring bsversion, bsservicepack, bsos;
00343         boolean isServer; /* 2004-11-19 creedon */
00344         byte bsflavor [4];
00345         OSVERSIONINFO osinfo;
00346 
00347         osinfo.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
00348         
00349         GetVersionEx (&osinfo);
00350         
00351         copystring (BIGSTRING ("\x08" "Windows "), bsos);
00352         
00353         langassignbooleanvalue (ht, str_isMac, false);
00354         
00355         langassignbooleanvalue (ht, str_isWindows, true);
00356         
00357         if (osinfo.dwPlatformId == VER_PLATFORM_WIN32_NT) {
00358             copystring (BIGSTRING ("\x02" "NT"), bsflavor);
00359             
00360             isServer = true; /* 2004-11-19 creedon */
00361             }
00362         else {
00363             
00364             if (osinfo.dwBuildNumber == 0)
00365                 copystring (BIGSTRING ("\x02" "95"), bsflavor);
00366             else
00367                 copystring (BIGSTRING ("\x02" "98"), bsflavor);
00368             
00369             isServer = false; /* 2004-11-19 creedon */
00370             }
00371         
00372         pushstring (bsflavor, bsos);
00373         
00374         langassignstringvalue (ht, str_osFlavor, bsflavor);
00375         
00376         langassignlongvalue (ht, str_osMajorVersion, osinfo.dwMajorVersion);
00377         
00378         langassignlongvalue (ht, str_osMinorVersion, LOWORD(osinfo.dwMinorVersion));
00379         
00380         langassignlongvalue (ht, str_osBuildNumber, LOWORD(osinfo.dwBuildNumber));
00381         
00382         getsystemversionstring (bsversion, bsservicepack);
00383         
00384         langassignstringvalue (ht, str_osVersionString, bsversion);
00385         
00386         langassignstringvalue (ht, str_winServicePackNumber, bsservicepack);
00387         
00388         langassignstringvalue (ht, str_osFullNameForDisplay, bsos);
00389         
00390         langassignbooleanvalue (ht, str_isCarbon, false); /*7.0b28: isCarbon is false on Windows.*/
00391         
00392         langassignbooleanvalue (ht, str_isMacOsClassic, false); /* 2006-02-18 aradke */
00393         
00394         langassignbooleanvalue (ht, str_isServer, isServer); /* 2004-11-19 creedon */
00395 
00396     #endif
00397 
00398     langassignlongvalue (ht, str_maxTcpConnections, maxconnections); /*7.0b37 PBS: max TCP connections*/
00399     
00400     #ifdef PIKE
00401     #ifndef OPMLEDITOR
00402         langassignbooleanvalue (ht, str_isPike, true);
00403 
00404         langassignbooleanvalue (ht, str_isRadio, true); /*7.0b37 PBS: system.environment.isRadio*/
00405         langassignbooleanvalue (ht, str_isOpmlEditor, false); /*2005-04-06 dluebbert: system.environment.isOPML*/
00406         langassignbooleanvalue (ht, str_isFrontier, false); /*2005-04-06 dluebbert: system.environment.isFrontier*/
00407     #else // OPMLEDITOR
00408         langassignbooleanvalue (ht, str_isPike, false);
00409 
00410         langassignbooleanvalue (ht, str_isRadio, false); /*7.0b37 PBS: system.environment.isRadio*/
00411         langassignbooleanvalue (ht, str_isOpmlEditor, true); /*2005-04-06 dluebbert: system.environment.isOPML*/
00412         langassignbooleanvalue (ht, str_isFrontier, false); /*2005-04-06 dluebbert: system.environment.isFrontier*/
00413     #endif // OPMLEDITOR
00414         
00415     #else 
00416         langassignbooleanvalue (ht, str_isPike, false);
00417 
00418         langassignbooleanvalue (ht, str_isRadio, false); /*7.0b37 PBS: system.environment.isRadio*/
00419         langassignbooleanvalue (ht, str_isOpmlEditor, false); /*2005-04-06 dluebbert: system.environment.isOPML*/
00420         langassignbooleanvalue (ht, str_isFrontier, true); /*2005-04-06 dluebbert: system.environment.isFrontier*/
00421     #endif 
00422 
00423         return (true);
00424     } /*initenvironment*/
00425 
00426 
00427 static boolean initCharsetsTable (hdlhashtable cSetsTable)
00428 {
00429 #if MACVERSION
00430     OSStatus err;
00431     ItemCount ct, actual_ct, i;
00432     
00433     err = TECCountAvailableTextEncodings( &ct );
00434     if ( err != noErr ) {
00435         return (true);  // don't kill the whole startup
00436     }
00437     
00438     TextEncoding enc, encOut;
00439     TextEncoding availEncodings[ ct ];
00440     bigstring ianaName, displayName;
00441     unsigned long lenDisplayName;
00442     RegionCode reg;
00443     
00444     err = TECGetAvailableTextEncodings ( availEncodings, ct, &actual_ct );
00445     if ( err != noErr )
00446         return (true);  // we don't want to kill the whole startup here
00447     
00448     for ( i = 0; i < actual_ct; i++ ) {
00449         enc = availEncodings[ i ];
00450         
00451         /*
00452             get the internet "iana" name for the encoding
00453         */
00454         err = TECGetTextEncodingInternetName( enc, ianaName );
00455         if ( err != noErr )
00456             continue;
00457         
00458         /*
00459             now convert the "iana" name back into the canonical encoding value
00460             (more than one encoding will point to the same iana name, 
00461             this makes sure that we use the right one)
00462         */
00463         err = TECGetTextEncodingFromInternetName( &enc, ianaName );
00464         if ( err != noErr )
00465             continue;
00466         
00467         /*
00468             get the encoding's display name, which is the value of the table cell
00469         */
00470         err = GetTextEncodingName( enc, kTextEncodingFullName, verUS, kTextEncodingMacRoman, 255, &lenDisplayName, &reg, &encOut, (TextPtr) displayName + 1 );
00471         if ( err != noErr )
00472             continue;
00473         
00474         displayName[ 0 ] = (unsigned char) lenDisplayName;
00475         
00476         langassignstringvalue( cSetsTable, ianaName, displayName );
00477     }
00478     
00479     return (true);
00480     
00481 #endif
00482 
00483 #if WIN95VERSION
00484     HRESULT err;
00485     IMultiLanguage2 * pMultiLanguage;
00486     IEnumCodePage * pEnumCodePage;
00487     UINT i, cnum = 0;
00488     MIMECPINFO cpInfo;
00489     long ccpInfo;
00490     bigstring ianaName, displayName;
00491 
00492     initCOM();
00493 
00494     err = CoCreateInstance(
00495             &CLSID_CMultiLanguage, 
00496             NULL,
00497             CLSCTX_INPROC_SERVER,
00498             &IID_IMultiLanguage2,
00499             (void **) &pMultiLanguage );
00500 
00501     if ( FAILED( err ) )
00502         goto done;
00503 
00504     err = pMultiLanguage->lpVtbl->EnumCodePages(
00505         pMultiLanguage,
00506         0,  // MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_VALID | MIMECONTF_MIME_LATEST
00507         9,  /* LANGID. I'm totally guessing that 0 means "all", here. -- smd */
00508         (IEnumCodePage **) &pEnumCodePage );
00509     
00510     if ( FAILED( err ) )
00511         goto done;
00512 
00513     pMultiLanguage->lpVtbl->GetNumberOfCodePageInfo( pMultiLanguage, &cnum );
00514     
00515     // pcpInfo = (PMIMECPINFO)CoTaskMemAlloc( sizeof(MIMECPINFO) );
00516 
00517     for ( i = 0; i < cnum; i++ )
00518     {
00519         err = pEnumCodePage->lpVtbl->Next( pEnumCodePage, 1, &cpInfo, &ccpInfo );
00520 
00521         if ( SUCCEEDED( err ) && ( ccpInfo != 0 ) )
00522         {
00523             if ( copyWideToPString( cpInfo.wszWebCharset, ianaName )
00524                 && copyWideToPString( cpInfo.wszDescription, displayName ) )
00525                 langassignstringvalue( cSetsTable, ianaName, displayName );
00526                 //langassignlongvalue( cSetsTable, ianaName, cpInfo.uiCodePage );
00527         }
00528     }
00529 
00530     pEnumCodePage->lpVtbl->Release( pEnumCodePage );
00531     pMultiLanguage->lpVtbl->Release( pMultiLanguage );
00532     // CoTaskMemFree( (LPVOID) pcpInfo );
00533 
00534 done:
00535     return (true);
00536     
00537 #endif  
00538     } /* initCharsetsTable */
00539 
00540 
00541 boolean inittablestructure (void) {
00542     
00543     /*
00544     do this just after you initialize lang.c.  
00545     
00546     we build the initial structure of hashtables for CanCoon.
00547     
00548     5.1.4 dmb: do the environmenttable
00549     */
00550     
00551     hdlhashtable htable; 
00552     
00553     if (!newhashtable (&htable)) /*this is where everything starts*/
00554         return (false);
00555     
00556     pushhashtable (htable); /*set lang.c global*/
00557     
00558     // do the compiler table
00559     
00560     if (!tablenewsystemtable (htable, nameinternaltable, &internaltable))
00561         goto error;
00562     
00563     if (!tablenewsystemtable (internaltable, nameefptable, &efptable))
00564         goto error;
00565     
00566     if (!tablenewsystemtable (internaltable, namelangtable, &langtable))
00567         goto error;
00568     
00569     if (!tablenewsystemtable (internaltable, namestacktable, &runtimestacktable))
00570         goto error;
00571     
00572     if (!tablenewsystemtable (internaltable, namesemaphoretable, &semaphoretable))
00573         goto error;
00574     
00575     #if threadverbs
00576         if (!tablenewsystemtable (internaltable, namethreadtable, &threadtable))
00577             goto error;
00578     #endif
00579         
00580     #ifdef version42orgreater
00581         if (!tablenewsystemtable (internaltable, namefilewindowtable, &filewindowtable))
00582             goto error;
00583     #endif
00584     
00585     // now do the environment table
00586     
00587     if (!tablenewsystemtable (htable, nameenvironmenttable, &environmenttable))
00588         goto error;
00589     
00590     if (!initenvironment (environmenttable))
00591         goto error;
00592     
00593     // and now the charsets table
00594     
00595     if (!tablenewsystemtable (htable, namecharsetstable, &charsetstable))
00596         goto error;
00597     
00598     initCharsetsTable (charsetstable);  /* don't die if the charsets can't be initialized */
00599     
00600     pophashtable ();
00601     
00602     return (true);
00603     
00604     error:
00605     
00606     pophashtable ();
00607     
00608     disposehashtable (htable, false);
00609     
00610     internaltable = efptable = langtable = runtimestacktable = semaphoretable = threadtable = filewindowtable = environmenttable = nil;
00611     
00612     return (false);
00613     } /*inittablestructure*/
00614 
00615 
00616 static boolean langaddnilconst (bigstring bs) {
00617     
00618     tyvaluerecord val;
00619     
00620     initvalue (&val, novaluetype);
00621     
00622     return (hashinsertcstring (bs, &val));
00623     } /*langaddnilconst*/
00624 
00625 
00626 static boolean langaddlongconst (bigstring bs, long x) {
00627     
00628     tyvaluerecord val;
00629     
00630     setlongvalue (x, &val);
00631     
00632     return (hashinsertcstring (bs, &val));
00633     } /*langaddlongconst*/
00634 
00635 
00636 static boolean langaddstringconst (bigstring bs, bigstring x) {
00637     
00638     tyvaluerecord val;
00639     
00640     setstringvalue (x, &val);
00641     
00642     if (!hashinsertcstring (bs, &val))
00643         return (false);
00644     
00645     exemptfromtmpstack (&val);
00646     
00647     return (true);
00648     } /*langaddstringconst*/
00649 
00650 
00651 #if 0
00652 
00653 static boolean langaddintconst (bigstring bs, short x) {
00654     
00655     tyvaluerecord val;
00656     
00657     setintvalue (x, &val);
00658     
00659     return (hashinsertcstring (bs, &val));
00660     } /*langaddintconst*/
00661 
00662 #endif
00663     
00664 
00665 static boolean langadddirectionconst (bigstring bs, tydirection x) {
00666     
00667     tyvaluerecord val;
00668     
00669     setdirectionvalue (x, &val);
00670     
00671     return (hashinsertcstring (bs, &val));
00672     } /*langadddirectionconst*/
00673 
00674 
00675 static boolean langaddbooleanconst (bigstring bs, boolean x) {
00676     
00677     tyvaluerecord val;
00678     
00679     setbooleanvalue (x, &val);
00680     
00681     return (hashinsert (bs, val));
00682     } /*langaddbooleanconst*/
00683 
00684 
00685 static boolean langaddtypeconst (bigstring bs, tyvaluetype x) {
00686     
00687     tyvaluerecord val;
00688     
00689     setostypevalue (langgettypeid (x), &val);
00690     
00691     return (hashinsert (bs, val));
00692     } /*langaddtypeconst*/
00693 
00694 
00695 #define add(x,y) if (!langaddcstringkeyword ((ptrstring) x, y)) return (false)
00696 
00697 #define addnil(x) if (!langaddnilconst ((ptrstring) x)) return (false)
00698 
00699 #define addlong(x,y) if (!langaddlongconst ((ptrstring) x, y)) return (false)
00700 
00701 #define addint(x,y) if (!langaddintconst ((ptrstring) x, y)) return (false)
00702 
00703 #define adddirection(x,y) if (!langadddirectionconst ((ptrstring) x, y)) return (false)
00704 
00705 #define addboolean(x,y) if (!langaddbooleanconst ((ptrstring) x, y)) return (false)
00706 
00707 #define addtype(x,y) if (!langaddtypeconst ((ptrstring) x, y)) return (false)
00708 
00709 #define addstring(x,y) if (!langaddstringconst ((ptrstring) x, y)) return (false)
00710 
00711 
00712 static boolean langinitconsttable (void) {
00713     
00714     /*
00715     2.1b1 dmb: added shortType as a special case; redundant with intType, 
00716     but more consistent with user termiology
00717     
00718     2.1b2 dmb: added nil constant
00719     */
00720     
00721     tyvaluetype type;
00722     bigstring bs;
00723     
00724     if (!tablenewsystemtable (langtable, (ptrstring) "\x09" "constants", &hconsttable))
00725         return (false);
00726         
00727     pushhashtable (hconsttable); /*converted to constants by the scanner*/
00728     
00729     addnil ("nil");
00730     
00731     addlong ("infinity", longinfinity);
00732     
00733     adddirection ("up", up);
00734     
00735     adddirection ("down", down);
00736     
00737     adddirection ("left", left);
00738     
00739     adddirection ("right", right);
00740     
00741     adddirection ("flatup", flatup);
00742     
00743     adddirection ("flatdown", flatdown);
00744     
00745     adddirection ("nodirection", nodirection);
00746     
00747     adddirection ("pageup", pageup);
00748     
00749     adddirection ("pagedown", pagedown);
00750     
00751     adddirection ("pageleft", pageleft);
00752     
00753     adddirection ("pageright", pageright);
00754     
00755     addboolean (bstrue, (boolean) true);
00756     
00757     addboolean (bsfalse, (boolean) false);
00758     
00759     for (type = novaluetype; type < ctvaluetypes; type++)
00760         
00761         switch (type) {
00762             
00763             case olddoublevaluetype: /*don't define constants for these types*/
00764             case externalvaluetype:
00765             
00766             #ifndef fliowa
00767             
00768             case headvaluetype:
00769             
00770             #endif
00771             
00772             case oldstringvaluetype: /*8/13*/
00773             case passwordvaluetype: /*9/17*/
00774             case unused2valuetype:
00775                 break;
00776             
00777             default:
00778                 langgettypestring (type, bs);
00779                 
00780                 lastword (bs, chspace, bs);
00781                 
00782                 pushstring ((ptrstring) "\x04Type", bs);
00783                 
00784                 addtype (bs, type);
00785                 
00786                 break;
00787             }
00788     
00789     addtype (BIGSTRING ("\x09shortType"), intvaluetype); /*special case to match coercion verb*/
00790     
00791     addstring ("machinePPC", machinePPC);
00792     addstring ("machine68K", machine68K);
00793     addstring ("machineX86", machinex86);
00794     
00795     addstring ("osMacOS", osMacOS);
00796     //Code change by Timothy Paustian Tuesday, July 11, 2000 9:41:39 PM
00797     //We add a detection for the carbon environment
00798     addstring("osMacCn", osCarbon);
00799     addstring ("osWin95", osWin95);
00800     addstring ("osWinNT", osWinNT);
00801     
00802     pophashtable ();
00803     
00804     return (true);
00805     } /*langinitconsttable*/
00806 
00807 
00808 static boolean langinitbuiltintable (void) {
00809     
00810     if (!tablenewsystemtable (langtable, (ptrstring) "\x08" "builtins", &hbuiltinfunctions))
00811         return (false);
00812     
00813     pushhashtable (hbuiltinfunctions); /*converted to function ops by the parser*/
00814     
00815     add ("appleevent", appleeventfunc);
00816     
00817     add ("complexevent", complexeventfunc);
00818     
00819     add ("finderevent", findereventfunc);
00820     
00821     add ("tableevent", tableeventfunc);
00822     
00823     add ("objspec", objspecfunc);
00824     
00825     add ("setobj", setobjspecfunc);
00826     
00827     add ("pack", packfunc);
00828     
00829     add ("unpack", unpackfunc);
00830     
00831     add ("defined", definedfunc);
00832     
00833     add ("typeof", typeoffunc);
00834     
00835     add ("sizeof", sizeoffunc);
00836     
00837     add ("nameof", nameoffunc);
00838     
00839     add ("parentof", parentoffunc);
00840 
00841     add ("indexof", indexoffunc);
00842     
00843     add ("gestalt", gestaltfunc);
00844     
00845     add ("syscrash", syscrashfunc);
00846     
00847     #if !flruntime
00848     
00849     add ("myMoof", myMooffunc);
00850     
00851     #endif
00852     
00853     pophashtable ();
00854     
00855     return (true);
00856     } /*langinitbuiltintable*/
00857 
00858 
00859 static boolean langinitkeywordtable (void) {
00860     
00861     /*
00862     3/6/92 dmb: added "with" token
00863     */
00864     
00865     if (!tablenewsystemtable (langtable, (ptrstring) "\x08" "keywords", &hkeywordtable))
00866         return (false);
00867     
00868     pushhashtable (hkeywordtable); /*converted to tokens by the scanner*/
00869     
00870     add ("equals", equalsfunc);
00871     
00872     add ("notequals", notequalsfunc);
00873     
00874     add ("greaterthan", greaterthanfunc);
00875     
00876     add ("lessthan", lessthanfunc);
00877     
00878     add ("not", notfunc);
00879     
00880     add ("and", andfunc);
00881     
00882     add ("or", orfunc);
00883     
00884     add ("beginswith", beginswithfunc);
00885     
00886     add ("endswith", endswithfunc);
00887     
00888     add ("contains", containsfunc);
00889     
00890     add ("loop", loopfunc);
00891     
00892     add ("fileloop", fileloopfunc);
00893     
00894     add ("while", whilefunc);
00895     
00896     add ("in", infunc);
00897     
00898     add ("break", breakfunc);
00899     
00900     add ("continue", continuefunc);
00901     
00902     add ("return", returnfunc);
00903     
00904     add ("if", iffunc);
00905     
00906     add ("then", thenfunc);
00907     
00908     add ("else", elsefunc);
00909     
00910     add ("bundle", bundlefunc);
00911     
00912     add ("local", localfunc);
00913     
00914     add ("on", onfunc);
00915     
00916     add ("case", casefunc);
00917     
00918     add ("kernel", kernelfunc);
00919     
00920     add ("for", forfunc);
00921     
00922     add ("to", tofunc);
00923     
00924     add ("downto", downtofunc);
00925     
00926     add ("with", withfunc);
00927     
00928     add ("try", tryfunc);
00929     
00930     pophashtable ();
00931     
00932     return (true);
00933     } /*langinitkeywordtable*/
00934 
00935 
00936 static boolean langinstallresources (void) {
00937     
00938     if (!langinitconsttable ())
00939         return (false);
00940     
00941     if (!langinitbuiltintable ())
00942         return (false);
00943     
00944     if (!langinitkeywordtable ())
00945         return (false);
00946     
00947     return (true);
00948     } /*langinstallresources*/
00949 
00950 
00951 boolean langinitverbs (void) {
00952     
00953     if (!langinstallresources ())
00954         return (false);
00955     
00956     return (langinitbuiltins ());
00957     } /*langinitverbs*/
00958 
00959 boolean initlang (void) {
00960 
00961     shellpushmemoryhook (&hashflushcache);
00962     
00963     langcallbacks.symbolchangedcallback = (langsymbolchangedcallback) &truenoop; 
00964     
00965     langcallbacks.symbolunlinkingcallback = (langtablenodecallback) &truenoop;
00966     
00967     langcallbacks.symboldeletedcallback = (langaddresscallback) &truenoop;
00968     
00969     langcallbacks.symbolinsertedcallback = (langsymbolinsertedcallback) &truenoop;
00970     
00971     langcallbacks.comparenodescallback = (langcomparenodescallback) &falsenoop;
00972         
00973     langcallbacks.debuggercallback = (langtreenodecallback) &truenoop;
00974     
00975     langcallbacks.debugerrormessagecallback = (langerrormessagecallback) &truenoop;
00976     
00977     langcallbacks.scriptkilledcallback = (langbooleancallback) &falsenoop;
00978     
00979     newclearhandle (longsizeof (tyerrorstack), (Handle *) &langcallbacks.scripterrorstack);
00980     
00981     /* 4.1b4 dmb: no longer push this be default. langrun now does it.
00982     langpusherrorcallback (nil, 0L);
00983     */
00984     
00985     /*
00986     langcallbacks.scripterrorcallback = &truenoop;
00987     
00988     langcallbacks.scripterrorrefcon = (long) 0;
00989     */
00990     
00991     langcallbacks.scriptcompilecallback = (langhashnodetreenodecallback) &falsenoop;
00992     
00993     langcallbacks.backgroundtaskcallback = (langbooleancallback) &truenoop;
00994     
00995     langcallbacks.pushtablecallback = (langtablerefcallback) &langdefaultpushtable;
00996     
00997     langcallbacks.poptablecallback = (langtablecallback) &langdefaultpoptable;
00998     
00999     langcallbacks.pushsourcecodecallback = (langsourcecodecallback) &truenoop;
01000     
01001     langcallbacks.popsourcecodecallback = (langvoidcallback) &truenoop;
01002     
01003     langcallbacks.saveglobalscallback = (langvoidcallback) &truenoop;
01004     
01005     langcallbacks.restoreglobalscallback = (langvoidcallback) &truenoop;
01006     
01007     langcallbacks.errormessagecallback = (langerrormessagecallback) &truenoop;
01008     
01009     langcallbacks.errormessagerefcon = nil;
01010     
01011     langcallbacks.clearerrorcallback = (langvoidcallback) &truenoop;
01012     
01013     langcallbacks.msgverbcallback = (langverbcallback) &truenoop;
01014     
01015     langcallbacks.codereplacedcallback = (langtreenodescallback) &truenoop;
01016     
01017     langcallbacks.idvaluecallback = nil;
01018     
01019     langcallbacks.partialeventloopcallback = (langshortcallback) &falsenoop;
01020     
01021     langcallbacks.processeventcallback = (langeventcallback) &falsenoop; /*4.1b13 dmb - new*/
01022     
01023     if (!newclearhandle (longsizeof (tytablestack), (Handle *) &hashtablestack))
01024         return (false);
01025     
01026     return (true);
01027     } /*initlang*/
01028 
01029 

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