opvalidate.c

Go to the documentation of this file.
00001 
00002 /*  $Id: opvalidate.c 1260 2006-04-13 06:13:10Z 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 "strings.h"
00032 #include "shell.h"
00033 #include "op.h"
00034 #include "opinternal.h"
00035 
00036 
00037 
00038 #define invalid(h) {getheadstring (h,bs);shellinternalerror(idinvalidoutline, bs);return(false);}
00039 
00040 
00041 static boolean opvalidtree (hdlheadrecord hnode, long *ptrexpansioncount) {
00042     
00043     bigstring bs;
00044     hdlheadrecord h, hdown, hparent;
00045     
00046     if ((**hnode).flexpanded)
00047         *ptrexpansioncount += opgetnodelinecount (hnode);
00048     
00049     hparent = hnode;
00050     
00051     h = (**hnode).headlinkright;
00052     
00053     if (h == hnode) 
00054         return (true);
00055     
00056     if ((**h).headlinkup != h) /*up pointer doesn't point at himself*/
00057         invalid (h);
00058         
00059     if ((**h).appbit4) /*there should be a callback here doing this*/
00060         invalid (h);
00061         
00062     while (true) {
00063         
00064         if ((**h).headlinkleft != hparent) /*we don't point at the right parent*/
00065             invalid (h);
00066             
00067         if (!opvalidtree (h, ptrexpansioncount)) /*recurse*/
00068             return (false);
00069             
00070         hdown = (**h).headlinkdown;
00071         
00072         if (hdown == h) /*cool, he's the last guy at the level*/
00073             return (true);
00074         
00075         if ((**hdown).headlinkup != h) /*guy down from us doesn't point up back at us*/
00076             invalid (h);
00077             
00078         h = hdown; /*advance to next guy*/
00079         } /*while*/
00080     } /*opvalidtree*/
00081     
00082     
00083 boolean opvalidate (hdloutlinerecord houtline) {
00084     
00085     /*
00086     bullshit detector -- if there's anything wrong with the given outline
00087     structure, ie any redundant information doesn't agree, we break into the
00088     debugger with an appropriate message.
00089     */
00090     
00091     bigstring bs;
00092     hdlheadrecord hsummit, h, hdown;
00093     hdloutlinerecord ho;
00094     boolean fl;
00095     long ctexpanded;
00096     
00097     ho = houtline;
00098     
00099     if (ho == nil)
00100         return (true);
00101     
00102     hsummit = (**ho).hsummit;
00103     
00104     h = hsummit;
00105         
00106     if ((**h).headlinkup != h) /*first guy doesn't point up at himself*/
00107         invalid (h);
00108         
00109     while (true) { /*check all level 0 guys for proper structure*/
00110     
00111         if ((**h).headlevel != 0) /*a level-0 guy who isn't level 0*/
00112             invalid (h);
00113             
00114         if ((**h).headlinkleft != h) /*a level-0 guy that doesn't point left at himself*/
00115             invalid (h);
00116             
00117         hdown = (**h).headlinkdown; /*advance to next guy*/
00118         
00119         if (hdown == h) /*reached the last guy*/
00120             goto L1;
00121         
00122         if ((**hdown).headlinkup != h) /*guy down from h doesn't point up at h*/
00123             invalid (h);
00124             
00125         h = hdown;
00126         } /*while*/
00127     
00128     L1: /*passed the level-0 test*/
00129     
00130     h = hsummit;
00131     
00132     ctexpanded = 0;
00133     
00134     while (true) {
00135         
00136         oppushoutline (ho);
00137         
00138         fl = opvalidtree (h, &ctexpanded);
00139         
00140         oppopoutline ();
00141         
00142         if (!fl)
00143             return (false);
00144             
00145         if (!opchasedown (&h))
00146             goto L2;
00147         } /*while*/
00148         
00149     L2: /*passed the level-1 test*/
00150     
00151     if (ctexpanded != (**ho).ctexpanded) {
00152     
00153         shellinternalerror(idinvalidoutline, BIGSTRING ("\x15" "expansion count error"));
00154         
00155         (**ho).ctexpanded = ctexpanded; /*once is enough for this message*/
00156 
00157         return (false); /* 6.2b10 AR */
00158         }
00159         
00160     return (true);
00161     } /*opvalidate*/
00162     
00163     

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