landreturn.c

Go to the documentation of this file.
00001 
00002 /*  $Id: landreturn.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 "landinternal.h"
00032 
00033 
00034 /*
00035 landreturn.c -- these routines can be called by a client application to return
00036 a value after processing a verb record.  to support a synchronous call, the client
00037 must return some value -- if nothing is obvious, just return a boolean true.
00038 
00039 you can return multiple values.  when we get the first return value, we empty out 
00040 the verb's parameter list.  all returned values are pushed just like normal 
00041 parameters, and are returned to the calling application by landsendreturnvalues 
00042 when the verb handler returns control to the userland api
00043 */
00044 
00045 
00046 
00047 
00048 pascal boolean landstartreturn (hdlverbrecord hverb) {
00049     
00050     /*
00051     make sure that the original parameters are cleared out of the 
00052     verb handle so that return values can be pushed.  note that it's
00053     ok to call this more than once -- it will only do something the 
00054     first time.
00055     */
00056     
00057     register hdlverbrecord hv = hverb;
00058     
00059     if ((**hv).verbtoken != returntoken) {
00060         
00061         (**hv).verbtoken = returntoken;
00062         }
00063     
00064     return (true);
00065     } /*landstartreturn*/
00066 
00067 
00068 pascal boolean landreturnboolean (hdlverbrecord hverb, Boolean x) {
00069     
00070     unsigned char flg;
00071     
00072     flg = bitboolean (x);
00073     
00074     landstartreturn (hverb);
00075     
00076     return (landpushparam (hverb, booleantype, nil, &flg, longsizeof (flg), returnedvaluekey));
00077     } /*landreturnboolean*/
00078 
00079 
00080 pascal boolean landreturnlong (hdlverbrecord hverb, long x) {
00081     
00082     landstartreturn (hverb);
00083     
00084     return (landpushlongparam (hverb, x, returnedvaluekey));
00085     } /*landreturnlong*/
00086     
00087 
00088 pascal boolean landreturnstring (hdlverbrecord hverb, bigstring bs) {
00089     
00090     landstartreturn (hverb);
00091     
00092     return (landpushstringparam (hverb, bs, returnedvaluekey));
00093     } /*landreturnstring*/
00094 
00095 
00096 pascal boolean landreturnbinary (hdlverbrecord hverb, Handle x) {
00097     
00098     landstartreturn (hverb);
00099     
00100     return (landpushparam (hverb, binarytype, x, nil, 0L, returnedvaluekey));
00101     } /*landreturnbinary*/
00102 
00103 
00104 pascal boolean landreturnerror (hdlverbrecord hverb, short iderror) {
00105     
00106     /*
00107     our client has a problem processing the indicated verb record.  we return info
00108     about the error to the calling program.
00109     
00110     if it's a scripting system, the error might be displayed in a scripting error
00111     dialog, with a pointer to the offending line.
00112     
00113     10/31/90 DW: we're also using this as an opportunity to test the new toolkit 
00114     feature that allows multiple returned values.  we return the string as the 
00115     primary value, but we also provide the index into the string list as an id for 
00116     the error.
00117     
00118     11/6/90 dmb: now use landstartreturn to return multiple values. also, use Apple's 
00119     keys for error values.
00120     
00121     1/28/92 dmb: convert Toolkit errors to standard Mac errors; only push error number/
00122     string params if it's not a standard error.
00123     
00124     4/13/93 dmb: don't push any AE params for standard Mac errors.  fixes a bug in 
00125     Runtime's handling of send-to-self events that are handled by a system event handler.
00126     
00127     3.0.1b1 dmb: for error ids greater than the land errors, the string list is 
00128     used. the string list no longer needs to have strings for the land errors, 
00129     because we never use them. also, we push errAEEventFailed into the reply, 
00130     not the iderror
00131     */
00132     
00133     register hdllandglobals hg = landgetglobals ();
00134     bigstring bs;
00135     OSErr errcode;
00136     
00137     landstartreturn (hverb);
00138     
00139     switch (iderror) {
00140     
00141         case nosuchparamerror:
00142             errcode = errAEDescNotFound; break;
00143     
00144         case wrongtypeerror:
00145             errcode = errAEWrongDataType; break;
00146         
00147         case undefinedverberror:
00148             errcode = errAEEventNotHandled; break;
00149         
00150         case nohandlererror:
00151             errcode = errAEEventNotHandled; break;
00152         
00153         case outofmemoryerror:
00154             errcode = memFullErr; break;
00155         
00156         case usercancellederror:
00157             errcode = userCanceledErr; break;
00158         
00159         default:
00160             GetIndString (bs, (**hg).iderrorlist, iderror);
00161             
00162             landpushintparam (hverb, errAEEventFailed, errornumberkey);
00163             
00164             landpushstringparam (hverb, bs, errorstringkey);
00165             
00166             errcode = errAEEventFailed;
00167         }
00168     
00169     landseterror (errcode);
00170     
00171     return (true);
00172     } /*landreturnerror*/
00173 
00174 

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