landops.c

Go to the documentation of this file.
00001 
00002 /*  $Id: landops.c 1186 2006-04-03 13:06:44Z hasseily $    */
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 "landinternal.h"
00032 
00033 
00034 #ifndef fljustfrontier
00035 
00036 boolean landlockhandle (Handle hlock) {
00037     
00038     register Handle h = hlock;
00039     
00040     if (h == nil)
00041         return (false);
00042         
00043     HLock (h);
00044     
00045     return (true);
00046     } /*landlockhandle*/
00047     
00048     
00049 boolean landunlockhandle (Handle hunlock) {
00050     
00051     register Handle h = hunlock;
00052     
00053     if (h == nil)
00054         return (false);
00055         
00056     HUnlock (h);
00057     
00058     return (true);
00059     } /*landunlockhandle*/
00060 
00061 
00062 landmoveleft (void *psource, void *pdest, long length) {
00063     
00064     /*
00065     do a mass memory move with the left edge leading.  good for closing
00066     up a gap in a buffer, among other thingsÉ
00067     */
00068     
00069     register byte *ps, *pd;
00070     register long ctloops;
00071     
00072     ctloops = length;
00073     
00074     if (ctloops > 0) {
00075     
00076         ps = psource; /*copy into a register*/
00077     
00078         pd = pdest; /*copy into a register*/
00079     
00080         while (ctloops--) *pd++ = *ps++;
00081         }
00082     } /*landmoveleft*/
00083     
00084 
00085 landclearbytes (void *pclear, long ctclear) {
00086     
00087     /*
00088     fill memory with 0's.
00089     */
00090     
00091     memset (pclear, 0, ctclear);
00092     } /*landclearbytes*/
00093     
00094 
00095 land4bytestostring (long bytes, bigstring bs) {
00096     
00097     setstringlength (bs, 4);
00098     
00099     landmoveleft (&bytes, &bs [1], 4L);
00100     } /*land4bytestostring*/
00101 
00102 
00103 landsetcursortype (short newcursor) {
00104 
00105     register CursHandle hcursor;
00106 
00107     if (newcursor == 0) {
00108         
00109         SetCursor (&quickdrawglobal (arrow));
00110 
00111         return;
00112         }
00113 
00114     hcursor = GetCursor (newcursor);
00115     
00116     if (hcursor != nil)
00117         SetCursor (*hcursor);
00118     } /*landsetcursortype*/
00119 
00120 
00121 landcopystring (bssource, bsdest) bigstring bssource, bsdest; {
00122 
00123     /*
00124     create a copy of bssource in bsdest.  copy the length byte and
00125     all the characters in the source string.
00126 
00127     assume the strings are pascal strings, with the length byte in
00128     the first character of the string.
00129     */
00130     
00131     register short i, len;
00132     
00133     len = (short) bssource [0];
00134     
00135     for (i = 0; i <= len; i++) 
00136         bsdest [i] = bssource [i];
00137     } /*landcopystring*/
00138 
00139 
00140 landcopyheapstring (hdlbigstring hsource, bigstring bsdest) {
00141     
00142     landcopystring (*hsource, bsdest);
00143     } /*landcopyheapstring*/
00144 
00145 
00146 boolean landpushstring (bigstring bssource, bigstring bsdest) {
00147 
00148     /*
00149     insert the source string at the end of the destination string.
00150     
00151     assume the strings are pascal strings, with the length byte in
00152     the first character of the string.
00153     */
00154     
00155     register short lensource = stringlength (bssource);
00156     register short lendest = stringlength (bsdest);
00157     register byte *psource, *pdest;
00158     
00159     if ((lensource + lendest) > lenbigstring)
00160         return (false);
00161         
00162     pdest = (byte *) bsdest + lendest + 1;
00163     
00164     psource = (byte *) bssource + 1;
00165     
00166     bsdest [0] += (byte) lensource;
00167     
00168     while (lensource--) *pdest++ = *psource++;
00169 
00170     return (true);
00171     } /*landpushstring*/
00172     
00173     
00174 boolean landpushlong (long x, bigstring bs) {
00175     
00176     bigstring bslong;
00177     
00178     NumToString (x, bslong);
00179     
00180     return (landpushstring (bslong, bs));
00181     } /*landpushlong*/
00182     
00183 
00184 boolean landequalstrings (bigstring bs1, bigstring bs2) {
00185 
00186     /*
00187     return true if the two strings (pascal type, with length-byte) are
00188     equal.  return false otherwise.
00189     */
00190     
00191     register ptrbyte p1 = (ptrbyte) bs1, p2 = (ptrbyte) bs2;
00192     register short ct = *p1 + 1;
00193     
00194     while (ct--) 
00195         
00196         if (*p1++ != *p2++)
00197         
00198             return (false);
00199         
00200     return (true); /*loop terminated*/
00201     } /*landequalstrings*/
00202 
00203 
00204 boolean landnewfilledhandle (void *pdata, long size, Handle *hnew) {
00205     
00206     /*
00207     create a new handle of the indicated size, filled with the indicated data.
00208     
00209     return false if the allocation failed.
00210     */
00211     
00212     register Handle h;
00213 
00214     h = *hnew = NewHandle (size);
00215 
00216     if (h == nil)
00217         return (false);
00218 
00219     landmoveleft (pdata, *h, size);
00220     
00221     return (true);
00222     } /*landnewfilledhandle*/
00223     
00224 
00225 landdisposehandle (Handle h) {
00226     
00227     /*
00228     our own bottleneck for this built-in.  we don't require type coercion
00229     and we check if its nil.
00230     */
00231     
00232     if (h != nil)
00233         DisposHandle (h);
00234     } /*landdisposehandle*/
00235 
00236 
00237 hdlbigstring landnewstring (bigstring bs) {
00238     
00239     return (NewString (bs));
00240     } /*landnewstring*/
00241     
00242 
00243 boolean landenlargehandle (Handle hgrow, long ctgrow, void *newdata) {
00244     
00245     /*
00246     make the handle big enough to hold the new data, and move the new data in
00247     at the end of the newly enlarged handle.
00248     */
00249     
00250     register Handle h = hgrow;
00251     register long ct = ctgrow;
00252     register ptrbyte p = newdata;
00253     register long origsize;
00254     
00255     origsize = GetHandleSize (h);
00256     
00257     SetHandleSize (h, origsize + ct);
00258         
00259     if (MemError () != noErr)
00260         return (false);
00261         
00262     landmoveleft (p, *h + origsize, ct);
00263     
00264     return (true);
00265     } /*landenlargehandle*/ 
00266     
00267     
00268 boolean landshrinkhandle (Handle h, long ct) {
00269     
00270     /*
00271     make the handle smaller -- by ct bytes.
00272     */
00273     
00274     SetHandleSize (h, GetHandleSize (h) - ct);
00275     
00276     return (MemError () == noErr);
00277     } /*landshrinkhandle*/
00278     
00279     
00280 boolean landloadfromhandle (hload, ixload, ctload, pdata) Handle hload; long *ixload, ctload; void *pdata; {
00281     
00282     /*
00283     copy the next ctload bytes from hload into pdata and increment the index.
00284     
00285     return false if there aren't enough bytes.
00286     
00287     start ixload at 0.
00288     */
00289     
00290     register Handle h = hload;
00291     register ptrbyte p = pdata;
00292     register long ct = ctload;
00293     register long ix = *ixload;
00294     register long size;
00295     
00296     size = GetHandleSize (h);
00297     
00298     if ((ix + ct) > size) /*asked for more bytes than there are*/
00299         return (false); 
00300         
00301     landmoveleft (*h + ix, p, ct); /*copy out of the handle*/
00302     
00303     *ixload = ix + ct; /*increment the index into the handle*/
00304     
00305     return (true);
00306     } /*landloadfromhandle*/
00307 
00308 
00309 boolean landloadfromhandletohandle (Handle hload, long *ixload, long ctload, Handle *hnew) {
00310     
00311     /*
00312     load from the source handle, creating a new handle to hold the loaded stuff.
00313     */
00314     
00315     register Handle h;
00316     
00317     h = NewHandle (ctload);
00318 
00319     if (h == nil)
00320         return (false);
00321     
00322     if (!landloadfromhandle (hload, ixload, ctload, *h)) {
00323         
00324         landdisposehandle (h);
00325 
00326         return (false);
00327         }
00328     
00329     *hnew = h;
00330     
00331     return (true);
00332     } /*landloadfromhandletohandle*/
00333 
00334 
00335 boolean landcopyhandle (horig, hcopy) Handle horig, *hcopy; {
00336     
00337     register Handle h;
00338     register long ctbytes;
00339     
00340     ctbytes = GetHandleSize (horig);
00341     
00342     h = NewHandle (ctbytes);
00343     
00344     if (h == nil)
00345         return (false);
00346         
00347     landmoveleft (*horig, *h, ctbytes);
00348     
00349     *hcopy = h;
00350     
00351     return (true);
00352     } /*landcopyhandle*/
00353 
00354 
00355 boolean landnewclearhandle (long ctbytes, Handle *hreturned) {
00356     
00357     register long ct = ctbytes;
00358     register Handle h;
00359     
00360     *hreturned = h = NewHandle (ct);
00361     
00362     if (h == nil) 
00363         return (false);
00364         
00365     landclearbytes (*h, ct);
00366     
00367     *hreturned = h;
00368     
00369     return (true);
00370     } /*landnewclearhandle*/
00371 
00372 
00373 long landgethandlesize (Handle h) {
00374     
00375     return (GetHandleSize (h));
00376     } /*landgethandlesize*/
00377     
00378     
00379 boolean landnewemptyhandle (Handle *h) {
00380     
00381     return (landnewclearhandle (0L, h));
00382     } /*landnewemptyhandle*/
00383 
00384 
00385 boolean landsurrenderprocessor (EventRecord *ev) {
00386     
00387     WaitNextEvent (nullEvent, ev, 1, nil);
00388     
00389     return (true);
00390     } /*landsurrenderprocessor*/
00391 
00392 #endif
00393 
00394 boolean landbreakembrace (EventRecord *ev) {
00395     
00396     register hdllandglobals hg = landgetglobals ();
00397     
00398     return ((*(**hg).breakembraceroutine) (ev));
00399     
00400     /*
00401     return (landnoparamcallback ((**hg).breakembraceroutine));
00402     */
00403     } /*landbreakembrace*/
00404 
00405 
00406 boolean landgetappcreator (OSType *creator) {
00407     
00408     /*
00409     get the 4-character creator identifier for the application we're running 
00410     inside of.
00411     */
00412     
00413     ProcessSerialNumber psn;
00414     ProcessInfoRec info;
00415     
00416     #ifdef flnewfeatures
00417     
00418         psn.highLongOfPSN = 0;
00419         
00420         psn.lowLongOfPSN =  kCurrentProcess;
00421 
00422     #else
00423     
00424         GetCurrentProcess (&psn);
00425     
00426     #endif
00427     
00428     info.processInfoLength = (long) sizeof (info);
00429     
00430     info.processName = nil;
00431     
00432     info.processAppSpec = nil;
00433     
00434     GetProcessInformation (&psn, &info);
00435     
00436     *creator = info.processSignature;
00437     
00438     return (true);
00439     } /*landgetappcreator*/
00440 
00441 
00442 
00443 

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