00001 /*
00002 This product contains certain software code or other information
00003 ("AT&T Software") proprietary to AT&T Corp. ("AT&T"). The AT&T
00004 Software is provided to you "AS IS". YOU ASSUME TOTAL RESPONSIBILITY
00005 AND RISK FOR USE OF THE AT&T SOFTWARE. AT&T DOES NOT MAKE, AND
00006 EXPRESSLY DISCLAIMS, ANY EXPRESS OR IMPLIED WARRANTIES OF ANY KIND
00007 WHATSOEVER, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
00008 MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, WARRANTIES OF
00009 TITLE OR NON-INFRINGEMENT OF ANY INTELLECTUAL PROPERTY RIGHTS, ANY
00010 WARRANTIES ARISING BY USAGE OF TRADE, COURSE OF DEALING OR COURSE OF
00011 PERFORMANCE, OR ANY WARRANTY THAT THE AT&T SOFTWARE IS "ERROR FREE" OR
00012 WILL MEET YOUR REQUIREMENTS.
00013
00014 Unless you accept a license to use the AT&T Software, you shall not
00015 reverse compile, disassemble or otherwise reverse engineer this
00016 product to ascertain the source code for any AT&T Software.
00017
00018 (c) AT&T Corp. All rights reserved. AT&T is a registered trademark of AT&T Corp.
00019
00020 ***********************************************************************
00021
00022 History:
00023
00024 24/11/99 - initial release by Hartmut Liefke, liefke@seas.upenn.edu
00025 Dan Suciu, suciu@research.att.com
00026 */
00027
00028 //*****************************************************************
00029 //*****************************************************************
00030
00031 // This module implements the error handling. An error message
00032 // is one line and several error messages can be stored together
00033 // Then, an exception can be raised and all error messages
00034 // are printed through 'PrintErrorMsg()'.
00035
00036 #include <stdio.h>
00037 #include <string.h>
00038
00039 #include "Error.hpp"
00040
00041 #define ERRMSG_MAXLEN 512 // The maximum length of all error
00042 // messages together
00043
00044 struct ErrLine
00045 {
00046 ErrLine *next;
00047 char line[1];
00048 };
00049
00050 ErrLine *curerrline=NULL;
00051
00052 char errmsg[ERRMSG_MAXLEN+1];
00053 char *curptr=errmsg;
00054 int errstrlen;
00055 char *msgptr=errmsg+ERRMSG_MAXLEN-1;
00056
00057 void Error(char *str,int len)
00058 // Starts a new error msg
00059 {
00060 if((curptr-errmsg)+sizeof(ErrLine)+len+1>ERRMSG_MAXLEN)
00061 return;
00062
00063 ((ErrLine *)curptr)->next=curerrline;
00064 curerrline=(ErrLine *)curptr;
00065
00066 memcpy(curerrline+1,str,len);
00067 ((char *)(curerrline+1))[len]=0;
00068
00069 curptr+=sizeof(ErrLine)+len+1;
00070 }
00071
00072 void Error(char *str)
00073 // Starts a new error msg (with '\0' at the end)
00074 {
00075 Error(str,strlen(str));
00076 }
00077
00078 void ErrorCont(char *str,int len)
00079 // Continues the current error msg
00080 {
00081 curptr--;
00082 if((curptr-errmsg)+len+1>ERRMSG_MAXLEN)
00083 return;
00084
00085 memcpy(curptr,str,len);
00086 curptr[len]=0;
00087
00088 curptr+=len+1;
00089 }
00090
00091 void ErrorCont(char *str)
00092 // Continues the current error msg
00093 {
00094 ErrorCont(str,strlen(str));
00095 }
00096
00097 void PrintErrorMsg()
00098 // Prints the current error messsages
00099 {
00100 while(curerrline!=NULL)
00101 {
00102 printf("%s\n",(char *)(curerrline+1));
00103 curerrline=curerrline->next;
00104 }
00105
00106 curptr=errmsg;
00107 msgptr=errmsg+ERRMSG_MAXLEN-1;
00108 }
00109
00110 // A global exception that we use to exit the program
00111 XMillException e;
00112
00113 void Exit()
00114 {
00115 // PrintErrorMsg();
00116 throw &e;
00117 }
1.2.11.1 written by Dimitri van Heesch,
© 1997-2001