iowavalidate.c

Go to the documentation of this file.
00001 
00002 /*  $Id: iowavalidate.c 355 2005-01-11 22:48:55Z andreradke $    */
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 "shelltypes.h"
00032 #include "iowacore.h"
00033 
00034 #ifndef macBirdRuntime
00035 
00036     #include <applet.h>
00037 
00038 #endif
00039 
00040 
00041 static void __getmessage (bigstring bsin, bigstring bsout) {
00042     
00043     copystring ("\pFailed validation check: ", bsout);
00044     
00045     pushstring (bsin, bsout);
00046     } /*__getmessage*/
00047     
00048     
00049 #define invalid(bs) {bigstring bsout; __getmessage (bs, bsout); DebugStr (bs); return (false);}
00050 
00051 
00052 static hdlobject hcheck;
00053 
00054 
00055 static boolean checkobjectnamevisit (hdlobject h) {
00056     
00057     if (h != hcheck) {
00058     
00059         if (equalhandles ((**hcheck).objectname, (**h).objectname))
00060             invalid ("\ptwo objects have the same name");
00061         }
00062     
00063     return (true); /*keep visiting*/
00064     } /*checkobjectnamevisit*/
00065     
00066 
00067 static void checkobjectname (hdlobject h) {
00068     
00069     if ((**iowadata).runmode) /*a lot of older cards have objects without names*/
00070         return;
00071         
00072     hcheck = h;
00073     
00074     visitobjects ((**iowadata).objectlist, &checkobjectnamevisit);
00075     } /*checkobjectname*/
00076     
00077     
00078 static boolean validateobjectlist (hdlobject hlist) {
00079     
00080     hdlobject h = hlist;
00081     
00082     while (h != nil) {
00083         
00084         if ((**h).owningcard != iowadata)
00085             invalid ("\powningcard is incorrect");
00086             
00087         if (!(**iowadata).runmode) { /*a lot of older cards have objects without names*/
00088         
00089             if ((**h).objectname == nil)
00090                 invalid ("\pall objects must have names");
00091             }
00092             
00093         checkobjectname (h);
00094             
00095         /*check recalcstatus, limited set of possible values*/ {
00096             
00097             short x = (**h).objectrecalcstatus;
00098             
00099             if ((x < neverrecalc) || (x > timerecalc))
00100                 invalid ("\pobjectrecalcstatus is out of range");
00101                 
00102             if ((x != timerecalc) && ((**h).objectrecalcperiod != 0))
00103                 invalid ("\pobjectrecalcperiod is not 0");
00104             }
00105             
00106         /*check that the waste array is all zero*/ {
00107             
00108             short i;
00109             
00110             for (i = 0; i < sizeof ((**h).waste); i++)
00111                 if ((**h).waste [i] != 0)
00112                     invalid ("\pnon-zero waste item");
00113             }
00114             
00115         switch ((**h).objecttype) {
00116             
00117             case grouptype:
00118                 if ((**h).childobjectlist == nil)
00119                     invalid ("\pchild list shouldn't be nil");
00120                     
00121                 if ((**h).childobjectlist == h)
00122                     invalid ("\pcircular child list");
00123                     
00124                 validateobjectlist ((**h).childobjectlist);
00125                                 
00126                 break;
00127                 
00128             default: {
00129                 bigstring errorstring;
00130                 
00131                 setstringlength (errorstring, 0);
00132                 
00133                 if (!calldebug (h, errorstring))
00134                     invalid (errorstring);
00135                 
00136                 break;
00137                 }
00138             } /*switch*/
00139                         
00140         if ((**h).nextobject == h)
00141             invalid ("\pcircular list");
00142             
00143         h = (**h).nextobject;
00144         } /*while*/
00145     
00146     return (true);
00147     } /*validateobjectlist*/
00148     
00149     
00150 static boolean validateruntimecard (void) {
00151     
00152     return (true);
00153     } /*validateruntimecard*/
00154     
00155     
00156 static boolean validateeditedcard (void) {
00157     
00158     #ifndef macBirdRuntime /*it has no app.xxx record*/
00159     
00160         /*should really be in applet toolkit*/ {
00161             
00162             WindowPtr w = (**app.appwindow).macwindow;
00163             
00164             if ((hdlappwindow) GetWRefCon (w) != app.appwindow)
00165                 invalid ("\papplet toolkit structure is kablooey");
00166             }
00167         
00168         if (iowadata != (hdlcard) (**app.appwindow).appdata)
00169             invalid ("\piowadata and the appwindow don't agree");
00170         
00171         if ((**iowadata).runmode)
00172             invalid ("\pflrunmode is wrong");
00173     
00174     #endif
00175     
00176     return (true);
00177     } /*validateeditedcard*/
00178     
00179     
00180 boolean iowavalidate (boolean flruntimecard) {
00181     
00182     /*
00183     you can call this when you think all the iowa globals are set
00184     correctly. we look at everything, and try to find a problem.
00185     
00186     you tell us whether or not you think the current card is running
00187     or being edited.
00188     
00189     1.0b24 dmb: don't do any validating if we're not a debug build
00190     */
00191     
00192     #ifdef fldebug
00193         
00194         if (iowadata == nil)
00195             invalid ("\piowadata == nil");
00196             
00197         validateobjectlist ((**iowadata).objectlist);
00198         {
00199         CGrafPtr    thePort;
00200         #if TARGET_API_MAC_CARBON == 1
00201         thePort = GetQDGlobalsThePort();
00202         #else
00203         thePort = quickdrawglobal (thePort);
00204         #endif
00205         
00206         if (thePort != (CGrafPtr) (**iowadata).drawwindow)  /*dmb 1.31.96: use quickdrawglobal*/
00207             invalid ("\pdrawing into the wrong port");
00208         }
00209         #ifdef iowaRuntimeInApp 
00210             if (flruntimecard) 
00211                 validateruntimecard ();
00212             else 
00213                 validateeditedcard ();
00214         #else
00215             #ifdef iowaRuntime
00216                 validateruntimecard ();
00217             #else
00218                 validateeditedcard ();
00219             #endif
00220         #endif
00221     
00222     #endif
00223     
00224     return (true);
00225     } /*iowavalidate*/
00226 
00227 
00228 
00229 

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