assert.c

Go to the documentation of this file.
00001 
00002 /*  $Id: assert.c 630 2006-03-12 18:19:40Z 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 #if 0   /* 2006-03-12 aradke: completely disabled, rely on C lib to handle assert() */
00032 
00033 #ifdef fldebug
00034 
00035 #ifdef MACVERSION
00036 
00037     #include "memory.h"
00038     #include "strings.h"
00039     #include "ops.h"
00040     #include "shell.h"
00041 
00042 #if TARGET_API_MAC_CARBON
00043     #include "file.h"
00044     #include "launch.h"
00045     #include "timedate.h"
00046 #endif
00047 
00048 
00049 #if 0 //TARGET_API_MAC_CARBON   /* 2004-10-23 aradke: rely on Debugging.h instead */
00050 
00051     short __assert (char *expr, char *file, short line) {
00052     
00053         /*
00054         On OS X, DebugStr output gets automatically rerouted to stderr
00055         which in turn gets logged to console.log, viewable via Console.app.
00056         
00057         2003-05-26 AR: Include date/time, app name, and app version.
00058         */
00059         
00060         static boolean flnorentry = false;
00061         short day, month, year, hour, minute, second;
00062         tyfilespec myfspec;
00063         bigstring bs, bslogstamp, bsline, bsfile, bsmessage;
00064         
00065         if (flnorentry)
00066             return (0);
00067         
00068         flnorentry = true;
00069         
00070         /*get timestamp*/
00071         
00072         secondstodatetime (timenow (), &day, &month, &year, &hour, &minute, &second);
00073         
00074         numbertostring ((long) year, bs);
00075         
00076         pushstring (bs, bslogstamp);
00077         
00078         pushchar ('-', bslogstamp);
00079         
00080         numbertostring ((long) month, bs);
00081         
00082         padwithzeros (bs, 2);
00083         
00084         pushstring (bs, bslogstamp);
00085         
00086         pushchar ('-', bslogstamp);
00087         
00088         numbertostring ((long) day, bs);
00089         
00090         padwithzeros (bs, 2);
00091         
00092         pushstring (bs, bslogstamp);
00093         
00094         pushchar (' ', bslogstamp);
00095         
00096         numbertostring ((long) hour, bs);
00097         
00098         padwithzeros (bs, 2);
00099         
00100         pushstring (bs, bslogstamp);
00101         
00102         pushchar (':', bslogstamp);
00103         
00104         numbertostring ((long) minute, bs);
00105         
00106         padwithzeros (bs, 2);
00107         
00108         pushstring (bs, bslogstamp);
00109         
00110         pushchar (':', bslogstamp);
00111         
00112         numbertostring ((long) second, bs);
00113         
00114         padwithzeros (bs, 2);
00115         
00116         pushstring (bs, bslogstamp);
00117         
00118         pushchar (' ', bslogstamp);
00119 
00120         /*get filespec for app*/
00121  
00122         getapplicationfilespec (nil, &myfspec);
00123         
00124         pushstring (fsname (&myfspec), bslogstamp);
00125         
00126         pushchar (' ', bslogstamp);
00127         
00128         /*get version of app*/
00129         
00130         filegetprogramversion (bs);
00131         
00132         pushchar ('(', bslogstamp);
00133         
00134         pushstring (bs, bslogstamp);
00135         
00136         pushchar (')', bslogstamp);
00137         
00138         /*get file name*/
00139         
00140         moveleft (file, bsfile, (long) lenbigstring);
00141         
00142         convertcstring (bsfile);
00143         
00144         /*get line number*/
00145         
00146         numbertostring ((long) line, bsline);
00147         
00148         /*ouput message*/
00149         
00150         parsedialogstring (
00151                 "\p\r^0: Assertion failed in file ^1, at line ^2.\r",
00152                 bslogstamp, bsfile, bsline, nil,
00153                 bsmessage);
00154                 
00155         DebugStr (bsmessage);
00156         
00157         /*send message to stderr*/
00158         
00159         flnorentry = false;
00160 
00161         return (0);
00162     } /*__assert*/
00163 
00164 #endif  /*TARGET_API_MAC_CARBON*/
00165 
00166 #if TARGET_API_MAC_OS8
00167         
00168     short __assert (char *expr, char *file, short line) {
00169 
00170         bigstring bsfile, bsline, bsmessage;
00171         static boolean flnorentry = false;
00172         
00173         if (flnorentry)
00174             return (0);
00175         
00176         flnorentry = true;
00177         
00178         moveleft (file, bsfile, (long) lenbigstring);
00179         
00180         convertcstring (bsfile);
00181         
00182         numbertostring ((long) line, bsline);
00183         
00184         parsedialogstring (
00185                 "\pAssertion failed in file ^0, at line ^1.",
00186                 bsfile, bsline, nil, nil,
00187                 bsmessage);
00188         
00189         DebugStr (bsmessage);
00190         
00191         flnorentry = false;
00192 
00193         return (0);
00194     } /*__assert*/
00195 
00196 #endif  /*TARGET_API_MAC_OS8*/
00197 
00198 #endif  /*MACVERSION*/
00199     
00200 
00201 #ifdef WIN95VERSION
00202 
00203     #include "threads.h"
00204     #include <stdio.h>
00205 
00206     #ifdef _MSC_VER     /* 2002-11-09 AR: use _assert from debug version of Microsoft C runtime library*/
00207 
00208         #include <assert.h>
00209         #include "threads.h"
00210 
00211         short __assert (char *expr, char *file, short line) {
00212             
00213             #ifdef _DEBUG
00214 
00215                 static boolean flnorentry = false;
00216                 
00217                 if (flnorentry)
00218                     return (0);
00219                 
00220                 flnorentry = true;
00221 
00222                 releasethreadglobals ();
00223                 
00224                 _assert (expr, file, line);
00225 
00226                 grabthreadglobals ();
00227 
00228                 flnorentry = false;
00229 
00230             #endif  /*_DEBUG*/
00231 
00232             return (0);
00233             } /*__assert*/
00234 
00235     #endif  /* _MSC_VER */
00236 
00237     #ifdef __MWERKS__       /* 2002-11-09 AR: put up MessageBox with Cancel button to abort application */
00238 
00239         short __assert (char *expr, char *file, short line) {
00240         
00241             #ifdef _DEBUG
00242 
00243                 static boolean flnorentry = false;
00244                 char buf[4096];
00245                 int itemnum;
00246                 
00247                 if (flnorentry)
00248                     return (0);
00249                 
00250                 flnorentry = true;
00251 
00252                 sprintf(buf,"Assertion failed in %s, at line %d.\n\nExpression: %s\n\n", file, line, expr);
00253                 
00254                 //releasethreadglobals ();  /* 2002-11-10 AR: other threads should not continue running if we hit an assertion failure */
00255                 
00256                 itemnum = MessageBox (hwndMDIClient, buf, "Assertion Failure", MB_ABORTRETRYIGNORE | MB_ICONSTOP | MB_APPLMODAL);
00257 
00258                 //grabthreadglobals ();
00259 
00260                 flnorentry = false;
00261                 
00262                 if (itemnum == IDABORT)
00263                     abort();
00264 
00265                 if (itemnum == IDRETRY) {
00266                 
00267                     if (IsDebuggerPresent ())
00268                         OutputDebugString (buf);
00269                     
00270                     DebugBreak();
00271                     }
00272 
00273             #endif  /*_DEBUG*/
00274 
00275             return (0);
00276             } /*__assert*/
00277 
00278     #endif  /*__MWERKS__*/
00279 
00280 #endif  /*WIN95VERSION*/
00281 
00282 #endif  /*fldebug*/
00283 
00284 #endif

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