G:/ScriptBasic/source/report.c

Go to the documentation of this file.
00001 /*
00002 FILE:   report.c
00003 HEADER: report.h
00004 
00005 --GNU LGPL
00006 This library is free software; you can redistribute it and/or
00007 modify it under the terms of the GNU Lesser General Public
00008 License as published by the Free Software Foundation; either
00009 version 2.1 of the License, or (at your option) any later version.
00010 
00011 This library is distributed in the hope that it will be useful,
00012 but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 Lesser General Public License for more details.
00015 
00016 You should have received a copy of the GNU Lesser General Public
00017 License along with this library; if not, write to the Free Software
00018 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 
00020 TO_HEADER:
00021 
00022 typedef char *ReportMessage(char *Language, int ErrorCode);
00023 
00024 typedef void ReportFunction(void *, // a pointer that the system passes to the report function
00025                             char *, // the file name, where the error has happened
00026                             long,   // line number where the error has happened
00027                             unsigned int,    // the code of the error
00028                             int,    // severity of the error
00029                             int *,  // error counter
00030                             char *,  // a single, language independant string parameter for the message
00031                             unsigned long * // a pointer to flag bits
00032                             );
00033 
00034 typedef ReportFunction *pReportFunction;
00035 
00036 // the different error severities
00037 
00038 enum {
00039   REPORT_INFO = 0,
00040   REPORT_WARNING,
00041   REPORT_ERROR,
00042   REPORT_FATAL,
00043   REPORT_INTERNAL
00044   };
00045 
00046 #define REPORT_F_CGI  0x00000001
00047 #define REPORT_F_FRST 0x00000002 // zero on the first call and it is set to 1 later
00048 
00049 */
00050 
00051 #include <stdio.h>
00052 #include <string.h>
00053 
00054 #include "report.h"
00055 #include "errcodes.h"
00056 
00057 /*POD
00058 
00059 This file contains a simple error report handling function that prints the error to the standard error.
00060 
00061 This is a default reporting function used by most variations of ScriptBasic. However some variations
00062 like the ISAPI one needs to implements a function having the same interface.
00063 
00064 CUT*/
00065 
00066 /*POD
00067 =H report_report()
00068 
00069 This function implements the default error reporting function for both run-time and parse time errors and
00070 warnings.
00071 
00072 /*FUNCTION*/
00073 void report_report(void *filepointer,
00074                    char *FileName,
00075                    long LineNumber,
00076                    unsigned int iErrorCode,
00077                    int iErrorSeverity,
00078                    int *piErrorCounter,
00079                    char *szErrorString,
00080                    unsigned long *fFlags
00081   ){
00082 /*noverbatim
00083 Aguments:
00084 =itemize
00085 
00086 =item T<filepointer> is a T<void *> pointer. The default value of this pointer is T<stderr> unless the
00087 variation sets it different. This implementation uses this pointer as a T<FILE *> pointer. Other implementations
00088 of this function may use it for any other purpose so long as long the usage of this pointer fits the variation.
00089 
00090 =item T<FileName> is the name of the source file where the error was detected. This parameter is T<NULL> in case of
00091 a run-time error. The reporting function is encouraged to display this information for the user.
00092 
00093 =item T<LineNumber> is the line number within the source file where the error has happened. This parameter is valid
00094 only in case the parameter T<FileName> is not T<NULL>
00095 
00096 =item T<iErrorCode> is the error code.
00097 
00098 =item T<iErrorSeverity> should define the severity of the error. It can be
00099 T<REPORT_INFO>,
00100 T<REPORT_WARNING>,
00101 T<REPORT_ERROR>,
00102 T<REPORT_FATAL>,
00103 T<REPORT_INTERNAL>.
00104 Whenever the error severity is above the warning level the T<*piErrorCounter> has to be incremented.
00105 
00106 =item T<piErrorCounter> points to an T<int> counter that counts the number of errors. If there are errors
00107 during syntax analysis the ScriptBasic interpreter stops its execution before starting execution.
00108 
00109 =item T<szErrorString> is an optional error parameter string and not the displayable error message.
00110 The error message is stored in the global constant array T<en_error_messages>. This string may
00111 contain a T<%s> control referring to the error parameter string.
00112 
00113 =item T<fFlags> is an T<unsigned long> bit field. The bits currently used are:
00114 T<REPORT_F_CGI> is set if the error is to be reported as a CGI script. See the code for more details.
00115 T<REPORT_F_FRST> is reset when the report function is called first time and is set by the report function. 
00116 This allows the report function to report a header in case it needs.
00117 Other bits are reserved for later use.
00118 
00119 =noitemize
00120 CUT*/
00121 
00122   if( ((*fFlags) & REPORT_F_CGI) && !((*fFlags) & REPORT_F_FRST) ){
00123     fprintf((FILE *)filepointer,"Status: 200 OK\nContent-Type: text/html\n\n"
00124                                 "<HTML><HEAD>\n"
00125                                 "<title>Error page, syntax error</title>\n"
00126                                 "</HEAD><BODY>\n"
00127                                 "<H1>Error has happened in the code</H1>"
00128                                 "<pre>\n");
00129     }
00130 
00131   if( szErrorString && strlen(szErrorString) > 80 )szErrorString[79] = (char)0;
00132 
00133   if( iErrorSeverity >= REPORT_ERROR && piErrorCounter )(*piErrorCounter)++;
00134 
00135   if( FileName )fprintf((FILE*)filepointer,"%s(%ld):",FileName,LineNumber);
00136   fprintf((FILE *)filepointer,(iErrorCode < MAX_ERROR_CODE ? " error &H%x:" : " error 0x%08x:"),iErrorCode);
00137   if( iErrorCode >= MAX_ERROR_CODE )iErrorCode = COMMAND_ERROR_EXTENSION_SPECIFIC;
00138   if( szErrorString ){
00139     fprintf((FILE*)filepointer,en_error_messages[iErrorCode],szErrorString);
00140     fprintf((FILE*)filepointer,"\n");
00141     }else
00142     fprintf((FILE *)filepointer,"%s\n",en_error_messages[iErrorCode]);
00143   *fFlags |= REPORT_F_FRST;
00144   }

Generated on Sun Mar 12 23:56:31 2006 for ScriptBasic by  doxygen 1.4.6-NO