osaparseaete.c

Go to the documentation of this file.
00001 
00002 /*  $Id: osaparseaete.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 "strings.h"
00032 #include "osaparseaete.h"
00033 
00034 
00035 static byte *aete;
00036 
00037 
00038 static void grabbytes (long ctbytes, void *pbytes) {
00039     
00040     BlockMove (aete, pbytes, ctbytes);
00041     
00042     aete += ctbytes;
00043     } /*grabbytes*/
00044 
00045 
00046 static short getshort (void) {
00047     
00048     short n;
00049     
00050     grabbytes (2, &n);
00051     
00052     return (n);
00053     } /*getshort*/
00054 
00055 
00056 static void getstring (bigstring bs) {
00057     
00058     grabbytes (1, bs);
00059     
00060     grabbytes (stringlength (bs), bs + 1);
00061     } /*getstring*/
00062 
00063 
00064 static OSType getstring4 (void) {
00065     
00066     OSType x;
00067     
00068     grabbytes (4, &x);
00069     
00070     return (x);
00071     } /*getstring4*/
00072 
00073 
00074 static void getname (bigstring bsname) {
00075     
00076     short ixspace = 1;
00077     
00078     getstring (bsname);
00079     
00080     alllower (bsname);
00081     
00082     while (scanstring (chspace, bsname, &ixspace)) {
00083         
00084         deletestring (bsname, ixspace, 1);
00085         
00086         if (ixspace > stringlength (bsname))
00087             break;
00088         
00089         bsname [ixspace] = toupper (bsname [ixspace]);
00090         }
00091     } /*getname*/
00092 
00093 
00094 static void skipstring (void) {
00095     
00096     bigstring bs;
00097     
00098     getstring (bs);
00099     } /*skipstring*/
00100 
00101 
00102 static void skipbytes (short n) {
00103     
00104     aete += n;
00105     } /*skipbytes*/
00106 
00107 
00108 static void align (void) {
00109     
00110     if (odd ((long) aete))
00111         ++aete;
00112     } /*align*/
00113 
00114 
00115 static boolean parseParams (AEKeyword eventkey, bigstring bsparam) {
00116     
00117     short ctparams = getshort ();
00118     OSType key;
00119     short ctremaining = ctparams;
00120     short flags;
00121     
00122     while (--ctremaining >= 0) {
00123         
00124         getname (bsparam); // param name
00125         
00126         align ();
00127         
00128         key = getstring4 ();
00129         
00130         skipbytes (4); // param type
00131         
00132         skipstring ();
00133         
00134         align ();
00135         
00136         flags = getshort (); // param flags
00137         
00138         if (key == eventkey) { /*the one caller seeks*/
00139             
00140             if ((ctparams == 1) && (flags >= 0)) /*only extra param, not optional*/
00141                 setemptystring (bsparam);
00142             
00143             return (true);
00144             }
00145         }
00146     
00147     setemptystring (bsparam);
00148     
00149     return (false);
00150     } /*parseParams*/
00151 
00152 
00153 static boolean parseEvents (AEEventClass eventclass, AEEventID eventid, bigstring bsevent) {
00154     
00155     /*
00156     2.1b2 dmb: when event is found, return just before parsing parameters, so 
00157     their position in the aete can be saved & restored
00158     */
00159     
00160     short ctevents = getshort ();
00161     OSType class, id, paramtype;
00162     bigstring bsparam;
00163     
00164     while (--ctevents >= 0) {
00165         
00166         getname (bsevent);
00167         
00168         skipstring (); // comment
00169         
00170         align ();
00171         
00172         class = getstring4 ();
00173         
00174         id = getstring4 ();
00175         
00176         skipbytes (4); // reply type
00177         
00178         skipstring (); // reply description
00179         
00180         align ();
00181         
00182         skipbytes (2); // flags
00183         
00184         paramtype = getstring4 (); // direct param type
00185         
00186         skipstring (); // reply description
00187         
00188         align ();
00189         
00190         skipbytes (2); // reply flags
00191         
00192         if ((class == eventclass) && (id == eventid))
00193             return (true);
00194         
00195         parseParams (0, bsparam);
00196         }
00197     
00198     setemptystring (bsevent);
00199     
00200     return (false);
00201     } /*parseEvents*/
00202 
00203 
00204 static void parseProperties (void) {
00205     
00206     short ctproperties = getshort ();
00207     bigstring bs;
00208     OSType prop;
00209     
00210     while (--ctproperties >= 0) {
00211         
00212         getname (bs); //property name
00213         
00214         align ();
00215         
00216         prop = getstring4 ();
00217         
00218         skipbytes (4); // property class
00219         
00220         getstring (bs); // property description
00221         
00222         align ();
00223         
00224         skipbytes (2);
00225         }
00226     } /*parseProperties*/
00227 
00228 
00229 static void parseElements (void) {
00230     
00231     short ctelements = getshort ();
00232     OSType elem;
00233     
00234     while (--ctelements >= 0) {
00235         
00236         short ctkeyforms;
00237         
00238         elem = getstring4 ();
00239         
00240         ctkeyforms = getshort ();
00241         
00242         while (--ctkeyforms >= 0)
00243             skipbytes (4); // ignore it
00244         }
00245     } /*parseElements*/
00246 
00247 
00248 static void parseClasses (void) {
00249     
00250     short ctclasses = getshort ();
00251     OSType class;
00252     bigstring bsclass;
00253     
00254     while (--ctclasses >= 0) {
00255         
00256         getname (bsclass);
00257         
00258         align ();
00259         
00260         class = getstring4 ();
00261         
00262         skipstring (); // the class description
00263         
00264         align ();
00265         
00266         parseProperties ();
00267         
00268         parseElements ();
00269         }
00270     } /*parseClasses*/
00271 
00272 
00273 static void parseComparisonOps (void) {
00274     
00275     short ctcomparisons = getshort ();
00276     
00277     while (--ctcomparisons >= 0) {
00278         
00279         skipstring ();
00280         
00281         align ();
00282         
00283         skipbytes (4);
00284         
00285         skipstring ();
00286         
00287         align ();
00288         }
00289     } /*parseComparisonOps*/
00290 
00291 
00292 static void parseEnumerators (void) {
00293     
00294     short ctenumerators = getshort ();
00295     bigstring bsname;
00296     OSType id;
00297     
00298     while (--ctenumerators >= 0) {
00299         
00300         getname (bsname);
00301         
00302         align ();
00303         
00304         id = getstring4 ();
00305         
00306         skipstring ();
00307         
00308         align ();
00309         }
00310     } /*parseEnumerators*/
00311 
00312 
00313 static void parseEnumerations (void) {
00314     
00315     short ctenumerations = getshort ();
00316     
00317     while (--ctenumerations >= 0) {
00318         
00319         skipbytes (4);
00320         
00321         parseEnumerators ();
00322         }
00323     } /*parseEnumerations*/
00324 
00325 
00326 boolean osaparseaeteparamlist (Handle haete, long offset, AEKeyword key, bigstring bsparamname) {
00327     
00328     /*
00329     a direct translation of the UserTalk "parseAete" script, except that 
00330     we're specifically seeking the name of the one event specified
00331     */
00332     
00333     if (haete == nil)
00334         return (false);
00335     
00336     aete = (byte *) *haete + offset;
00337     
00338     return (parseParams (key, bsparamname));
00339     } /*osaparseaete*/
00340 
00341 
00342 boolean osaparseaete (Handle haete, AEEventClass class, AEEventID id, bigstring bseventname, long *paramoffset) {
00343     
00344     /*
00345     a direct translation of the UserTalk "parseAete" script, except that 
00346     we're specifically seeking the name of the one event specified
00347     */
00348     
00349     short ctsuites;
00350     OSType suitecode;
00351     
00352     if (haete == nil)
00353         return (false);
00354     
00355     aete = (byte *) *haete;
00356     
00357     skipbytes (6); // skip up to suite array
00358     
00359     ctsuites = getshort ();
00360     
00361     while (--ctsuites >= 0) {
00362         
00363         skipstring (); // name of the suite
00364         
00365         skipstring (); // description
00366         
00367         align ();
00368         
00369         suitecode = getstring4 ();
00370         
00371         skipbytes (4); // skip up to event array
00372         
00373         if (parseEvents (class, id, bseventname)) {
00374             
00375             *paramoffset = aete - (byte *) *haete;
00376             
00377             return (true);
00378             }
00379         
00380         if (suitecode == class)
00381             break;
00382         
00383         if (ctsuites == 0) // no point in parsing remainder
00384             break;
00385         
00386         parseClasses ();
00387         
00388         parseComparisonOps ();
00389         
00390         parseEnumerations ();
00391         }
00392     
00393     return (false);
00394     } /*osaparseaete*/
00395 
00396 
00397 

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