langcallbacks.c

Go to the documentation of this file.
00001 
00002 /*  $Id: langcallbacks.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 "lang.h"
00033 #include "langinternal.h"
00034 #include "shell.h"
00035 #include "memory.h"
00036 
00037 
00038 /*
00039 jackets around routines that are implemented as callbacks.
00040 */
00041 
00042 
00043 boolean flerrorscriptrunning = false;
00044 
00045 
00046 boolean langpushlocalchain (hdlhashtable *htable) {
00047     
00048     /*
00049     9/23/91 dmb: to clean up langfunccall, we've distributed magictable 
00050     handling around so that a locals table can be created and populated 
00051     without actually pushing it into the local chain.  our task here is 
00052     simply to make sure that it's consumed, whether or not an error occurs.
00053     */
00054     
00055     register boolean fl;
00056     
00057     fl = (*langcallbacks.pushtablecallback) (htable);
00058     
00059     /*stacktracer (hashgetstackdepth ());*/ /*debugging code*/
00060     
00061     if (hmagictable != nil) { /*make sure we've consumed any magic, even on error*/
00062         
00063         disposehashtable (hmagictable, false);
00064         
00065         hmagictable = nil;
00066         }
00067     
00068     return (fl);
00069     } /*langpushlocalchain*/
00070     
00071     
00072 boolean langpoplocalchain (hdlhashtable hcheck) {
00073     
00074     register hdlhashtable ht = currenthashtable;
00075     register boolean fl;
00076     
00077     assert (hcheck == ht);
00078     
00079     fl = (*langcallbacks.poptablecallback) (ht);
00080     
00081     /*stacktracer (hashgetstackdepth ());*/ /*debugging code*/
00082     
00083     return (fl);
00084     } /*langpoplocalchain*/
00085     
00086 
00087 boolean langbackgroundtask (boolean flresting) {
00088     
00089     /*
00090     a jacket around the running of background tasks -- we must save and restore
00091     some globals on the C stack, otherwise things break!
00092     
00093     1/18/93 dmb: added flresting parameter
00094     */
00095     
00096     boolean fl;
00097     
00098     #ifdef fldebug
00099     
00100     boolean flsavedbreak;
00101     
00102     flsavedbreak = flbreak;
00103     
00104     #endif
00105     
00106     fl = (*langcallbacks.backgroundtaskcallback) (flresting);
00107     
00108     assert (flbreak == flsavedbreak); /*restore globals*/
00109     
00110     return (fl);
00111     } /*langbackgroundtask*/
00112 
00113 
00114 boolean languserescaped (boolean flchecknow) {
00115     
00116     /*
00117     9/27/92 dmb: added flichecknow parameter
00118     */
00119     
00120     return ((*langcallbacks.scriptkilledcallback) (flchecknow));
00121     } /*languserescaped*/
00122 
00123 
00124 boolean langdebuggercall (hdltreenode hnode) {
00125     
00126     /*
00127     if we return false, it's a signal to the caller to exit without an error
00128     dialog.  the user has decided to stop running the current script.
00129     
00130     there didn't seem to be a better place to explain why we don't break at
00131     compound lines -- like the ones which contain loop, if, fileloop, etc.
00132     
00133     this is why: the compiler doesn't generate an accurate line number for
00134     these.  the line number is the first one after the closing right curly
00135     bracket.  if the debugger stopped on an if, it would put the cursor on
00136     the first statement after the if!  this is fine for error reporting,
00137     but is not too useful for debugging.  so we have a rule, the cursor
00138     only stops on "meaty" lines, ones which actually do some command or
00139     arithmetic.  not controlling the flow of the program.  of course it's
00140     easy to discern the flow from where the cursor ends up.
00141     
00142     1/18/91 dmb: parser modifications now generate accurate line numbers 
00143     for everything except modules.
00144     
00145     2/13/91 dmb: don't debug noops, localops, bundleops
00146     
00147     7/29/91 dmb: save and restore flreturn & flbreak, just like backgroundtask
00148     
00149     5/20/92 dmb: leave it up to the callback to decide which lines are "meaty".  
00150     pass the node itself to the callback instead of the line & character.
00151     */
00152     
00153     register hdltreenode h = hnode;
00154     boolean fl;
00155     boolean flsavedcontinue;
00156     
00157     flsavedcontinue = flcontinue;
00158     
00159     fl = (*langcallbacks.debuggercallback) (h);
00160     
00161     assert (flcontinue == flsavedcontinue); /****should be able to nuke this stuff*/
00162     
00163     return (fl);
00164     } /*langdebuggercall*/
00165 
00166 
00167 boolean langsaveglobals (void) {
00168     
00169     return ((*langcallbacks.saveglobalscallback) ());
00170     } /*langsaveglobals*/
00171 
00172 
00173 boolean langrestoreglobals (void) {
00174     
00175     return ((*langcallbacks.restoreglobalscallback) ());
00176     } /*langrestoreglobals*/
00177 
00178 
00179 boolean langpushsourcecode (hdlhashtable htable, hdlhashnode hnode, bigstring bs) {
00180 
00181     return ((*langcallbacks.pushsourcecodecallback) (htable, hnode, bs));
00182     } /*langpushsourcecode*/
00183 
00184 
00185 boolean langpopsourcecode (void) {
00186 
00187     return ((*langcallbacks.popsourcecodecallback) ());
00188     } /*langpopsourcecode*/
00189 
00190 
00191 #if 0
00192 
00193 boolean langgetsourcecodeaddress (hdlhashtable *htable, bigstring bsname) {
00194     
00195     register hdlerrorstack hs = langcallbacks.scripterrorstack;
00196     tyerrorrecord errorrecord = (**hs).stack [(**hs).toperror - 1];
00197     
00198     return ((*errorrecord.errorcallback) (errorrecord.errorrefcon, 0, 0, htable, bsname));
00199     } /*langgetsourcecodeaddress*/
00200 
00201 #endif
00202 
00203 boolean langerrormessage (bigstring bs) {
00204     
00205     /*
00206     10/31/91 dmb: experimented with calling local "error" routine on all 
00207     errors.  it's quickly becoming apparant that this is not a generally safe 
00208     thing to do, and that certain classes of errors must not trigger this 
00209     call (compiler errors, for example).  If we want to support this in the 
00210     future, a more formal mechanism should be developed.
00211     
00212     4.1b3 dmb: added call to new langseterrorcallbackline for stack tracing (on error)
00213     */
00214     
00215     if (!langerrorenabled ())
00216         return (true);
00217     
00218     if (fllangerror) /*one message per script*/
00219         return (true);
00220     
00221     fllangerror = true; /*only display once for each script*/
00222     
00223     #ifdef flnewfeatures    // flstacktrace
00224     
00225     langseterrorcallbackline ();
00226     
00227     #endif
00228     
00229     if (!(*langcallbacks.debugerrormessagecallback) (bs, langcallbacks.errormessagerefcon))
00230         return (false);
00231     
00232     return ((*langcallbacks.errormessagecallback) (bs, langcallbacks.errormessagerefcon));
00233     } /*langerrormessage*/
00234 
00235 
00236 boolean langerrorclear (void) {
00237     
00238     fllangerror = false;
00239     
00240     return ((*langcallbacks.clearerrorcallback) ());
00241     } /*langerrorclear*/
00242 
00243 
00244 boolean langcompilescript (hdlhashnode hnode, hdltreenode *hcode) {
00245     
00246     return ((*langcallbacks.scriptcompilecallback) (hnode, hcode));
00247     } /*langcompilescript*/
00248 
00249 
00250 void langsymbolchanged (hdlhashtable htable, const bigstring bs, hdlhashnode hnode, boolean flvalue) {
00251     
00252     /*
00253     5.1.5b15 dmb: call callback first, so it can tell if table was already dirty
00254     */
00255 
00256 #ifdef fltracklocaladdresses
00257 
00258     if (flvalue) {
00259 
00260         hdlhashnode hn = hnode;
00261         
00262         if ((hn != nil && hn != HNoNode) || hashtablelookupnode (htable, bs, &hn)) {
00263 
00264             hashunregisteraddressnode (hn);
00265 
00266             hashregisteraddressnode (htable, hn);
00267             }
00268         }
00269 
00270 #endif
00271 
00272     (*langcallbacks.symbolchangedcallback) (htable, bs, hnode, flvalue);
00273     
00274     dirtyhashtable (htable);
00275     } /*langsymbolchanged*/
00276 
00277 /*
00278 void langsymbolprechange (hdlhashtable htable, const bigstring bs, hdlhashnode hnode, boolean flvalue) {
00279     
00280     (*langcallbacks.symbolprechangecallback) (htable, bs, hnode, flvalue);
00281 
00282     }*/ /*langsymbolprechange*/
00283 
00284 
00285 void langsymbolinserted (hdlhashtable htable, const bigstring bsname, hdlhashnode hnode) {
00286 
00287 #ifdef fltracklocaladdresses    
00288     hashregisteraddressnode (htable, hnode);
00289 #endif
00290 
00291     (*langcallbacks.symbolinsertedcallback) (htable, bsname, hnode);
00292 
00293     } /*langsymbolinserted*/
00294 
00295 
00296 void langsymbolunlinking (hdlhashtable htable, hdlhashnode hnode) {
00297     
00298     (*langcallbacks.symbolunlinkingcallback) (htable, hnode);
00299 
00300     } /*langsymbolunlinking*/
00301 
00302 
00303 void langsymboldeleted (hdlhashtable htable, const bigstring bsname) {
00304 
00305     (*langcallbacks.symboldeletedcallback) (htable, bsname);
00306 
00307     } /*langsymboldeleted*/
00308 
00309 
00310 boolean langpartialeventloop (short desiredevents) {
00311     
00312     return ((*langcallbacks.partialeventloopcallback) (desiredevents));
00313     } /*langpartialeventloop*/
00314 
00315 
00316 
00317 

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