iowaparser.c

Go to the documentation of this file.
00001 
00002 /*  $Id: iowaparser.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 #include <appletfrontier.h>
00034 #include "iowaparser.h"
00035 
00036 
00037 #define translateids false /*set true to allow filtering of id's thru the translator script*/
00038 
00039 
00040 static Handle groupvalue;
00041 
00042 
00043 static boolean groupvaluevisit (hdlobject h) {
00044 
00045     Handle hvalue;
00046     
00047     if (!callspeaksforgroup (h)) /*keep visiting*/
00048         return (true);
00049         
00050     if (!(**h).objectflag) /*keep visiting*/
00051         return (true);
00052     
00053     getobjectvalue (h, &hvalue); 
00054     
00055     if (!newtexthandle ("\p", &groupvalue))  /*dmb 1.0b21: use curly quotes*/
00056         goto error;
00057         
00058     if (!pushhandleonhandle (hvalue, groupvalue))
00059         goto error;
00060         
00061     if (!pushtexthandle ("\p", groupvalue))
00062         goto error;
00063 
00064     return (false); /*stop visiting*/
00065     
00066     error:
00067     
00068     disposehandle (groupvalue);
00069     
00070     groupvalue = nil;
00071     
00072     return (false);
00073     } /*groupvaluevisit*/
00074     
00075     
00076 static boolean getgroupvalue (hdlobject hobj, Handle *hvalue) {
00077     
00078     /*
00079     return the value of the first radio button in the group that's on.
00080     */
00081     
00082     groupvalue = nil;
00083     
00084     visitobjects ((**hobj).childobjectlist, &groupvaluevisit);
00085     
00086     if (groupvalue == nil) 
00087         return (false);
00088     
00089     *hvalue = groupvalue;
00090     
00091     pushtemphandle (groupvalue);
00092     
00093     return (true);
00094     } /*getgroupvalue*/
00095     
00096     
00097 static boolean getvalueforscript (hdlobject hself, bigstring bsname, Handle *hvalue) {
00098     
00099     hdlobject hobj;
00100     
00101     /*check it against SELF -- new in 1.0b15*/ {
00102         
00103         if (hself != nil) {
00104         
00105             bigstring bsupper;
00106             
00107             copystring (bsname, bsupper);
00108             
00109             allupper (bsupper);
00110             
00111             if (equalstrings (bsupper, "\pSELF")) {
00112                 
00113                 bigstring bs, bsobjectname;
00114                 
00115                 copystring ("\p", bs); /*dmb 1.0b21: use curly quotes*/
00116                 
00117                 getobjectnamestring (hself, bsobjectname);
00118                 
00119                 pushstring (bsobjectname, bs);
00120                 
00121                 pushstring ("\p", bs);
00122                 
00123                 if (!newtexthandle (bs, hvalue))
00124                     return (false);
00125                 
00126                 pushtemphandle (*hvalue);
00127                 
00128                 return (true);
00129                 }
00130             }
00131         }
00132     
00133     if (!lookupname (bsname, &hobj)) {
00134     
00135         if (!newtexthandle (bsname, hvalue))
00136             return (false);
00137             
00138         pushtemphandle (*hvalue);
00139         
00140         return (true);
00141         }
00142         
00143     switch ((**hobj).objecttype) {
00144         
00145         case grouptype:
00146             return (getgroupvalue (hobj, hvalue));
00147             
00148         default: 
00149             return (callgetvalue (hobj, hvalue));
00150         } /*switch*/
00151     } /*getvalueforscript*/
00152     
00153     
00154 static boolean isfirstidchar (char ch) {
00155     
00156     /*
00157     return true if the character could be the start of an identifier.
00158     */
00159     
00160     if ((ch >= 'a') && (ch <= 'z'))
00161         return (true);
00162         
00163     if ((ch >= 'A') && (ch <= 'Z'))
00164         return (true);
00165     
00166     if (ch == '_')
00167         return (true);
00168         
00169     return (false);
00170     } /*isfirstidchar*/
00171     
00172     
00173 static boolean issubsequentidchar (char ch) {
00174     
00175     if (isfirstidchar (ch))
00176         return (true);
00177     
00178     if ((ch >= '0') && (ch <= '9'))
00179         return (true);
00180         
00181     if (ch == '.') /*DW 4/11/93*/
00182         return (true);
00183         
00184     return (false);
00185     } /*issubsequentidchar*/
00186     
00187     
00188 boolean preparseScript (hdlobject hself, Handle script, Handle *returns) {
00189     
00190     /*
00191     preparsing means replacing all references to named card objects
00192     with the values of those objects.
00193     
00194     dmb 1.0b20 - fixed memory trashing bug when substituting a value
00195     that is shorter than the name it replaces
00196     */
00197     
00198     Handle scriptcopy;
00199     long ixscript;
00200     long len;
00201     long ix;
00202     short lenname, lenvalue;
00203     bigstring bsname;
00204     long newlen;
00205     Handle hvalue;
00206     char ch;
00207     
00208     if (!copyhandle (script, &scriptcopy)) /*work with a copy*/
00209         return (false);
00210     
00211     ixscript = 0;
00212     
00213     len = GetHandleSize (scriptcopy);
00214     
00215     while (true) {
00216     
00217         if (ixscript >= len)
00218             break;
00219             
00220         ch = (*scriptcopy) [ixscript];
00221         
00222         if (ch == '"') {
00223             
00224             while (true) {
00225                 
00226                 ixscript++;
00227             
00228                 if (ixscript >= len)
00229                     break;
00230                     
00231                 if ((*scriptcopy) [ixscript] == '"') {
00232                     
00233                     ixscript++;
00234                     
00235                     break;
00236                     }
00237                 } /*while*/
00238                 
00239             continue;
00240             }
00241         
00242         if (ch == '\'') {
00243             
00244             while (true) {
00245                 
00246                 ixscript++;
00247             
00248                 if (ixscript >= len)
00249                     break;
00250                     
00251                 if ((*scriptcopy) [ixscript] == '\'') {
00252                     
00253                     ixscript++;
00254                     
00255                     break;
00256                     }
00257                 } /*while*/
00258                 
00259             continue;
00260             }
00261         
00262         if (!isfirstidchar (ch)) {
00263     
00264             ixscript++;
00265         
00266             continue;
00267             }
00268         
00269         ix = ixscript + 1;
00270         
00271         while (true) { 
00272             
00273             if (ix < len) {
00274             
00275                 if (issubsequentidchar ((*scriptcopy) [ix])) {
00276             
00277                     ix++;
00278                 
00279                     continue;
00280                     }
00281                 }
00282                 
00283             lenname = ix - ixscript;
00284             
00285             setstringlength (bsname, lenname);
00286             
00287             moveleft (&(*scriptcopy) [ixscript], &bsname [1], lenname);
00288             
00289             if (!getvalueforscript (hself, bsname, &hvalue)) {
00290                 
00291                 ixscript = ix;
00292                 
00293                 break;
00294                 }
00295             
00296             lenvalue = GetHandleSize (hvalue);
00297             
00298             newlen = ixscript + lenvalue + len - ix;
00299             
00300             if (newlen > len) { /*dmb 1.0b20*/
00301                 
00302                 if (!sethandlesize (scriptcopy, newlen)) {
00303                 
00304                     disposetemphandle (hvalue);
00305                     
00306                     disposehandle (scriptcopy);
00307                     
00308                     return (false);
00309                     }
00310                 }
00311             
00312             BlockMoveData (&(*scriptcopy) [ix], &(*scriptcopy) [ixscript + lenvalue], len - ix);
00313             
00314             BlockMoveData (*hvalue, &(*scriptcopy) [ixscript], lenvalue);
00315             
00316             /*
00317             SetHandleSize (scriptcopy, newlen);
00318             
00319             moveleft (&(*scriptcopy) [ix], &(*scriptcopy) [ixscript], len - ix);
00320             
00321             moveright (&(*scriptcopy) [ixscript], &(*scriptcopy) [ixscript + lenvalue], len - ix);
00322             
00323             moveleft (*hvalue, &(*scriptcopy) [ixscript], lenvalue);
00324             */
00325             
00326             disposetemphandle (hvalue);
00327             
00328             len = newlen;
00329             
00330             ixscript += lenvalue;
00331             
00332             break;
00333             } /*while*/
00334         } /*while*/
00335     
00336     sethandlesize (scriptcopy, len); /*dmb 1.0b20 - shrink to fit now, if necessary*/
00337     
00338     *returns = scriptcopy;
00339     
00340     return (true);
00341     } /*preparseScript*/
00342     
00343 

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