oprefcon.c

Go to the documentation of this file.
00001 
00002 /*  $Id: oprefcon.c 1254 2006-04-12 20:27:14Z 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 "shell.rsrc.h"
00032 #include "shell.h"
00033 #include "cursor.h"
00034 #include "font.h"
00035 #include "langinternal.h"
00036 #include "kb.h"
00037 #include "memory.h"
00038 #include "op.h"
00039 #include "opinternal.h"
00040 #include "lang.h" /*7.0b4 PBS*/
00041 
00042 
00043 extern boolean tablevaltotable (tyvaluerecord val, hdlhashtable *htable, hdlhashnode hnode);
00044 
00045 extern void pullstringvalue (const tyvaluerecord *v, bigstring bsval);
00046 
00047 boolean opsetrefcon (hdlheadrecord hnode, ptrvoid pdata, long lendata) {
00048     
00049     /*
00050     each node in the structure can have a handle linked into it through the hrefcon
00051     field.  the application can allocate and access this handle himself, or use these
00052     routines.  when the structure is saved (oppack), the handle is saved with the
00053     node, and restored when the outline is unpacked.
00054     
00055     7/21/92 dmb: make sure the refcon is _exactly_ the right size, not any bigger
00056     */
00057     
00058     Handle hrefcon = (**hnode).hrefcon;
00059     long len = lendata;
00060     
00061     if (hrefcon == nil) { /*never been set before*/
00062         
00063         Handle hnew;
00064         
00065         //if (!newclearhandle (len, &hnew))
00066         if (!newfilledhandle (pdata, len, &hnew)) // 7.31.97 dmb
00067             return (false);
00068             
00069         (**hnode).hrefcon = hrefcon = hnew;
00070         
00071         return (true);
00072         }
00073     
00074     if (gethandlesize (hrefcon) != len) { /*not the right size for the data*/
00075         
00076         if (!sethandlesize (hrefcon, len))
00077             return (false);
00078         }
00079         
00080     moveleft (pdata, *hrefcon, len);
00081     
00082     return (true);
00083     } /*opsetrefcon*/
00084     
00085     
00086 boolean opgetrefcon (hdlheadrecord hnode, ptrvoid pdata, long lendata) {
00087     
00088     /*
00089     get the refcon data from the indicated node.  always returns true -- if there
00090     isn't enough data in the refcon field, just fill pdata with the indicated 
00091     number of 0's.
00092     
00093     10/23/90 dmb: if the refcon field is nil, return false (but still fill pdata 
00094     with zeros).  many callers expect this.
00095     */
00096     
00097     Handle hrefcon;
00098     long lenrefcon;
00099 
00100     // kw - 2006-01-19 - after crash - was "Handle hrefcon = (**hnode).hrefcon;"
00101     if (hnode != nil)
00102         hrefcon = (**hnode).hrefcon;
00103 
00104     lenrefcon = gethandlesize (hrefcon); /*handles nil*/
00105     
00106     if (lenrefcon < lendata) /*not enough data, make sure it's all zero*/
00107         clearbytes (pdata, lendata);
00108     
00109     if (hrefcon == nil)
00110         return (false);
00111     
00112     if (lenrefcon > lendata) /*somehow there's more data available than caller wants*/
00113         lenrefcon = lendata;
00114     
00115     moveleft (*hrefcon, pdata, lenrefcon);
00116     
00117     return (true);
00118     } /*opgetrefcon*/
00119     
00120     
00121 void opemptyrefcon (hdlheadrecord hnode) {
00122     
00123     if ((**hnode).hrefcon == nil) /*nothing to do*/
00124         return;
00125         
00126     opdirtyoutline ();
00127         
00128     disposehandle ((**hnode).hrefcon);
00129     
00130     (**hnode).hrefcon = nil;
00131     } /*opemptyrefcon*/
00132     
00133     
00134 boolean ophasrefcon (hdlheadrecord hnode) {
00135     
00136     return ((**hnode).hrefcon != nil);
00137     } /*ophasrefcon*/
00138 
00139 
00140 boolean opattributesgetoneattribute (hdlheadrecord hnode, bigstring bsattname, tyvaluerecord *val) {
00141     
00142     /*
00143     7.0b16 PBS: get one value from a packed attributes table.
00144     */
00145     
00146     tyvaluerecord vattributes;
00147     tyvaluerecord v;
00148     hdlhashtable htable;
00149     hdlhashnode hn = nil;
00150     hdlhashnode hnatt;
00151     boolean fl = false;
00152 
00153     disablelangerror ();
00154     
00155     if (!opattributesgetpackedtablevalue (hnode, &vattributes))
00156         
00157         return (false);
00158     
00159     if (!tablevaltotable (vattributes, &htable, hn))
00160         
00161         goto exit;
00162     
00163     if (hashtablelookup (htable, bsattname, &v, &hnatt)) {
00164     
00165         copyvaluerecord (v, val);
00166         
00167         disposevaluerecord (v, false);
00168         
00169         exemptfromtmpstack (val);
00170 
00171         fl = true;
00172         } /*if*/
00173     
00174     exit:
00175     
00176     disposevaluerecord (vattributes, false);
00177     
00178     enablelangerror ();
00179     
00180     return (fl);    
00181     } /*opattributesgetoneattribute*/
00182 
00183 
00184 boolean opattributesgetpackedtablevalue (hdlheadrecord hnode, tyvaluerecord *val) {
00185     
00186     /*
00187     7.0b16 PBS: get the table packed as a binary in a headline's refcon.
00188     */
00189     
00190     Handle hrefcon = (**hnode).hrefcon;
00191     tyvaluerecord linkedval;
00192     boolean fl = false;
00193     
00194     if (!ophasrefcon (hnode)) {/*if no refcon, no attributes*/
00195     
00196         langerrormessage (BIGSTRING ("\x39""Can't get attributes because this headline has no refcon."));
00197         
00198         goto exit1;
00199         }
00200     
00201     if (!langunpackvalue (hrefcon, &linkedval)) { /*try to unpack the refcon*/
00202         
00203         langerrormessage (BIGSTRING ("\x3e""Can't get attributes because of an error unpacking the refcon."));
00204 
00205         goto exit1;
00206         }
00207     
00208     if (linkedval.valuetype != binaryvaluetype) { /*must be a binary*/
00209         
00210         langerrormessage (BIGSTRING ("\x3e""Can't get attributes because the refcon is not of binary type."));
00211 
00212         goto exit2;
00213         }
00214     
00215     if (!langunpackvalue (linkedval.data.binaryvalue, val)) { /*it's a packed binary: unpack it.*/
00216         
00217         langerrormessage (BIGSTRING ("\x3e""Can't get attributes because of an error unpacking the refcon."));
00218 
00219         goto exit2;
00220         }
00221     
00222     fl = true;
00223 
00224     exit2:
00225     
00226     disposevaluerecord (linkedval, false);
00227     
00228     exit1:
00229     
00230     return (fl);
00231     } /*opattributesgetpackedtable*/
00232 
00233 
00234 boolean opattributesgettypestring (hdlheadrecord hnode, bigstring bstype) {
00235     
00236     /*
00237     7.0b4 PBS: Get the node type of a headline.
00238     Unpack the refcon, look in the table for a type attribute, set bstype
00239     equal to that string.
00240     
00241     7.0b14 PBS: Fixed memory leaks.
00242     */
00243     
00244     Handle hrefcon = (**hnode).hrefcon;
00245     tyvaluerecord linkedval;
00246     tyvaluerecord val;
00247     hdlhashtable htable;
00248     hdlhashnode hn = nil;
00249     hdlhashnode hnheadlinetype;
00250     tyvaluerecord valheadlinetype;
00251     boolean fl = false;
00252     
00253     disablelangerror ();
00254 
00255     if (!ophasrefcon (hnode)) //if no refcon, not attributes
00256     
00257         goto exit3;
00258 
00259     if (!langunpackvalue (hrefcon, &linkedval)) //try to unpack the refcon
00260     
00261         goto exit3;
00262     
00263     if (linkedval.valuetype != binaryvaluetype) //must be a binary
00264         
00265         goto exit2;
00266     
00267     if (!langunpackvalue (linkedval.data.binaryvalue, &val)) //it's a packed binary: unpack it.
00268         
00269         goto exit2;
00270     
00271     if (val.valuetype != externalvaluetype) //it must be a table
00272         
00273         goto exit1;
00274     
00275     if (!tablevaltotable (val, &htable, hn))
00276         
00277         goto exit1;
00278     
00279     if (hashtablelookup (htable, BIGSTRING ("\x04""type"), &valheadlinetype, &hnheadlinetype)) {
00280     
00281         pullstringvalue (&valheadlinetype, bstype);
00282         
00283         fl = true;
00284         } /*if*/
00285     
00286     exit1: /*7.0b14 PBS: fix memory leaks*/
00287     
00288     disposevaluerecord (val, false);
00289     
00290     exit2:
00291     
00292     disposevaluerecord (linkedval, false);
00293     
00294     exit3:
00295     
00296     enablelangerror ();
00297 
00298     return (fl);
00299     } /*opattributesgettypestring*/
00300 
00301 
00302 

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